Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@nx/devkit

Package Overview
Dependencies
Maintainers
5
Versions
1805
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nx/devkit - npm Package Compare versions

Comparing version
22.7.2
to
22.7.3
+2
-2
package.json
{
"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.`);
}
});
}