@nx/devkit
Advanced tools
+2
-2
| { | ||
| "name": "@nx/devkit", | ||
| "version": "22.7.2", | ||
| "version": "22.7.3", | ||
| "private": false, | ||
@@ -42,3 +42,3 @@ "description": "The Nx Devkit is used to customize Nx for different technologies and use cases. It contains many utility functions for reading and writing files, updating configuration, working with Abstract Syntax Trees(ASTs), and more. Learn more about [extending Nx by leveraging the Nx Devkit](https://nx.dev/extending-nx/intro/getting-started) on our docs.", | ||
| "jest": "30.3.0", | ||
| "nx": "22.7.2" | ||
| "nx": "22.7.3" | ||
| }, | ||
@@ -45,0 +45,0 @@ "peerDependencies": { |
| import { Tree } from 'nx/src/devkit-exports'; | ||
| export declare function replaceNrwlPackageWithNxPackage(tree: Tree, oldPackageName: string, newPackageName: string): void; | ||
| //# sourceMappingURL=replace-package.d.ts.map |
| {"version":3,"file":"replace-package.d.ts","sourceRoot":"","sources":["../../../../../packages/devkit/src/utils/replace-package.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,IAAI,EAIL,MAAM,uBAAuB,CAAC;AAM/B,wBAAgB,+BAA+B,CAC7C,IAAI,EAAE,IAAI,EACV,cAAc,EAAE,MAAM,EACtB,cAAc,EAAE,MAAM,GACrB,IAAI,CAQN"} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.replaceNrwlPackageWithNxPackage = replaceNrwlPackageWithNxPackage; | ||
| const devkit_exports_1 = require("nx/src/devkit-exports"); | ||
| const visit_not_ignored_files_1 = require("../generators/visit-not-ignored-files"); | ||
| const path_1 = require("path"); | ||
| const binary_extensions_1 = require("./binary-extensions"); | ||
| function replaceNrwlPackageWithNxPackage(tree, oldPackageName, newPackageName) { | ||
| replacePackageInDependencies(tree, oldPackageName, newPackageName); | ||
| replacePackageInProjectConfigurations(tree, oldPackageName, newPackageName); | ||
| replacePackageInNxJson(tree, oldPackageName, newPackageName); | ||
| replaceMentions(tree, oldPackageName, newPackageName); | ||
| } | ||
| function replacePackageInDependencies(tree, oldPackageName, newPackageName) { | ||
| (0, visit_not_ignored_files_1.visitNotIgnoredFiles)(tree, '.', (path) => { | ||
| if ((0, path_1.basename)(path) !== 'package.json') { | ||
| return; | ||
| } | ||
| try { | ||
| (0, devkit_exports_1.updateJson)(tree, path, (packageJson) => { | ||
| for (const deps of [ | ||
| packageJson.dependencies ?? {}, | ||
| packageJson.devDependencies ?? {}, | ||
| packageJson.peerDependencies ?? {}, | ||
| packageJson.optionalDependencies ?? {}, | ||
| ]) { | ||
| if (oldPackageName in deps) { | ||
| deps[newPackageName] = deps[oldPackageName]; | ||
| delete deps[oldPackageName]; | ||
| } | ||
| } | ||
| return packageJson; | ||
| }); | ||
| } | ||
| catch (e) { | ||
| console.warn(`Could not replace ${oldPackageName} with ${newPackageName} in ${path}.`); | ||
| } | ||
| }); | ||
| } | ||
| function replacePackageInProjectConfigurations(tree, oldPackageName, newPackageName) { | ||
| const projects = (0, devkit_exports_1.getProjects)(tree); | ||
| for (const [projectName, projectConfiguration] of projects) { | ||
| let needsUpdate = false; | ||
| for (const [targetName, targetConfig] of Object.entries(projectConfiguration.targets ?? {})) { | ||
| if (!targetConfig.executor) { | ||
| continue; | ||
| } | ||
| const [pkg, executorName] = targetConfig.executor.split(':'); | ||
| if (pkg === oldPackageName) { | ||
| needsUpdate = true; | ||
| projectConfiguration.targets[targetName].executor = | ||
| newPackageName + ':' + executorName; | ||
| } | ||
| } | ||
| for (const [collection, collectionDefaults] of Object.entries(projectConfiguration.generators ?? {})) { | ||
| if (collection === oldPackageName) { | ||
| needsUpdate = true; | ||
| projectConfiguration.generators[newPackageName] = collectionDefaults; | ||
| delete projectConfiguration.generators[collection]; | ||
| } | ||
| } | ||
| if (needsUpdate) { | ||
| (0, devkit_exports_1.updateProjectConfiguration)(tree, projectName, projectConfiguration); | ||
| } | ||
| } | ||
| } | ||
| function replacePackageInNxJson(tree, oldPackageName, newPackageName) { | ||
| if (!tree.exists('nx.json')) { | ||
| return; | ||
| } | ||
| const nxJson = (0, devkit_exports_1.readNxJson)(tree); | ||
| let needsUpdate = false; | ||
| for (const [targetName, targetConfig] of Object.entries(nxJson.targetDefaults ?? {})) { | ||
| if (!targetConfig.executor) { | ||
| continue; | ||
| } | ||
| const [pkg, executorName] = targetConfig.executor.split(':'); | ||
| if (pkg === oldPackageName) { | ||
| needsUpdate = true; | ||
| nxJson.targetDefaults[targetName].executor = | ||
| newPackageName + ':' + executorName; | ||
| } | ||
| } | ||
| for (const [collection, collectionDefaults] of Object.entries(nxJson.generators ?? {})) { | ||
| if (collection === oldPackageName) { | ||
| needsUpdate = true; | ||
| nxJson.generators[newPackageName] = collectionDefaults; | ||
| delete nxJson.generators[collection]; | ||
| } | ||
| } | ||
| if (needsUpdate) { | ||
| (0, devkit_exports_1.updateNxJson)(tree, nxJson); | ||
| } | ||
| } | ||
| function replaceMentions(tree, oldPackageName, newPackageName) { | ||
| (0, visit_not_ignored_files_1.visitNotIgnoredFiles)(tree, '.', (path) => { | ||
| if ((0, binary_extensions_1.isBinaryPath)(path)) { | ||
| return; | ||
| } | ||
| const ignoredFiles = [ | ||
| 'yarn.lock', | ||
| 'package-lock.json', | ||
| 'pnpm-lock.yaml', | ||
| 'bun.lockb', | ||
| 'bun.lock', | ||
| 'CHANGELOG.md', | ||
| ]; | ||
| if (ignoredFiles.includes((0, path_1.basename)(path))) { | ||
| return; | ||
| } | ||
| try { | ||
| const contents = tree.read(path).toString(); | ||
| if (!contents.includes(oldPackageName)) { | ||
| return; | ||
| } | ||
| tree.write(path, contents.replace(new RegExp(oldPackageName, 'g'), newPackageName)); | ||
| } | ||
| catch { | ||
| // Its **probably** ok, contents can be null if the file is too large or | ||
| // there was an access exception. | ||
| devkit_exports_1.logger.warn(`An error was thrown when trying to update ${path}. If you believe the migration should have updated it, be sure to review the file and open an issue.`); | ||
| } | ||
| }); | ||
| } |
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 8 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 8 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
286562
-1.97%174
-1.69%6117
-2.02%