feat(misc): change updateBuildableProjectDepsInPackageJson option default value to false (#17920)

This commit is contained in:
Leosvel Pérez Espinosa 2023-07-06 09:06:48 +01:00 committed by GitHub
parent c6a0615fa5
commit 64765eb313
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 399 additions and 16 deletions

View File

@ -43,7 +43,7 @@
"updateBuildableProjectDepsInPackageJson": { "updateBuildableProjectDepsInPackageJson": {
"type": "boolean", "type": "boolean",
"description": "Whether to update the buildable project dependencies in the build output package.json.", "description": "Whether to update the buildable project dependencies in the build output package.json.",
"default": true "default": false
}, },
"buildableProjectDepsInPackageJsonType": { "buildableProjectDepsInPackageJsonType": {
"type": "string", "type": "string",

View File

@ -46,7 +46,7 @@
"updateBuildableProjectDepsInPackageJson": { "updateBuildableProjectDepsInPackageJson": {
"type": "boolean", "type": "boolean",
"description": "Whether to update the buildable project dependencies in the build output package.json.", "description": "Whether to update the buildable project dependencies in the build output package.json.",
"default": true "default": false
}, },
"buildableProjectDepsInPackageJsonType": { "buildableProjectDepsInPackageJsonType": {
"type": "string", "type": "string",

View File

@ -98,7 +98,7 @@
"updateBuildableProjectDepsInPackageJson": { "updateBuildableProjectDepsInPackageJson": {
"type": "boolean", "type": "boolean",
"description": "Whether to update the buildable project dependencies in the build output package.json.", "description": "Whether to update the buildable project dependencies in the build output package.json.",
"default": true "default": false
}, },
"buildableProjectDepsInPackageJsonType": { "buildableProjectDepsInPackageJsonType": {
"type": "string", "type": "string",

View File

@ -98,7 +98,7 @@
"updateBuildableProjectDepsInPackageJson": { "updateBuildableProjectDepsInPackageJson": {
"type": "boolean", "type": "boolean",
"description": "Whether to update the buildable project dependencies in the build output package.json.", "description": "Whether to update the buildable project dependencies in the build output package.json.",
"default": true "default": false
}, },
"buildableProjectDepsInPackageJsonType": { "buildableProjectDepsInPackageJsonType": {
"type": "string", "type": "string",

View File

@ -84,7 +84,7 @@
"updateBuildableProjectDepsInPackageJson": { "updateBuildableProjectDepsInPackageJson": {
"type": "boolean", "type": "boolean",
"description": "Update buildable project dependencies in `package.json`.", "description": "Update buildable project dependencies in `package.json`.",
"default": true "default": false
}, },
"buildableProjectDepsInPackageJsonType": { "buildableProjectDepsInPackageJsonType": {
"type": "string", "type": "string",

View File

@ -91,7 +91,9 @@ describe('js e2e', () => {
return json; return json;
}); });
runCLI(`build ${lib} --generateLockfile=true`); runCLI(
`build ${lib} --generateLockfile=true --updateBuildableProjectDepsInPackageJson`
);
checkFilesExist( checkFilesExist(
`dist/libs/${lib}/package.json`, `dist/libs/${lib}/package.json`,
`dist/libs/${lib}/${ `dist/libs/${lib}/${

View File

@ -129,9 +129,7 @@ describe('js e2e', () => {
return json; return json;
}); });
runCLI(`build ${lib}`); runCLI(`build ${lib} --updateBuildableProjectDepsInPackageJson`);
const rootPackageJson = readJson(`package.json`);
expect(readJson(`dist/libs/${lib}/package.json`)).toHaveProperty( expect(readJson(`dist/libs/${lib}/package.json`)).toHaveProperty(
'peerDependencies.tslib' 'peerDependencies.tslib'
@ -221,7 +219,7 @@ describe('package.json updates', () => {
`; `;
}); });
runCLI(`build ${lib}`); runCLI(`build ${lib} --updateBuildableProjectDepsInPackageJson`);
// Check that only 'react' exists, don't care about version // Check that only 'react' exists, don't care about version
expect(readJson(`dist/libs/${lib}/package.json`).dependencies).toEqual({ expect(readJson(`dist/libs/${lib}/package.json`).dependencies).toEqual({

View File

@ -129,7 +129,7 @@ describe('Build React libraries and apps', () => {
/* /*
* 2. With dependencies * 2. With dependencies
*/ */
runCLI(`build ${parentLib}`); runCLI(`build ${parentLib} --updateBuildableProjectDepsInPackageJson`);
checkFilesExist(`dist/libs/${parentLib}/index.js`); checkFilesExist(`dist/libs/${parentLib}/index.js`);

View File

@ -263,6 +263,12 @@
}, },
"description": "Update the @angular/cli package version to ~16.1.0.", "description": "Update the @angular/cli package version to ~16.1.0.",
"factory": "./src/migrations/update-16-4-0/update-angular-cli" "factory": "./src/migrations/update-16-4-0/update-angular-cli"
},
"explicitly-set-projects-to-update-buildable-deps": {
"cli": "nx",
"version": "16.6.0-beta.0",
"description": "Explicitly set 'updateBuildableProjectDepsInPackageJson' to 'true' in targets that rely on that value as the default.",
"factory": "./src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps"
} }
}, },
"packageJsonUpdates": { "packageJsonUpdates": {

View File

@ -40,7 +40,7 @@
"updateBuildableProjectDepsInPackageJson": { "updateBuildableProjectDepsInPackageJson": {
"type": "boolean", "type": "boolean",
"description": "Whether to update the buildable project dependencies in the build output package.json.", "description": "Whether to update the buildable project dependencies in the build output package.json.",
"default": true "default": false
}, },
"buildableProjectDepsInPackageJsonType": { "buildableProjectDepsInPackageJsonType": {
"type": "string", "type": "string",

View File

@ -40,7 +40,7 @@
"updateBuildableProjectDepsInPackageJson": { "updateBuildableProjectDepsInPackageJson": {
"type": "boolean", "type": "boolean",
"description": "Whether to update the buildable project dependencies in the build output package.json.", "description": "Whether to update the buildable project dependencies in the build output package.json.",
"default": true "default": false
}, },
"buildableProjectDepsInPackageJsonType": { "buildableProjectDepsInPackageJsonType": {
"type": "string", "type": "string",

View File

@ -0,0 +1,86 @@
import {
ProjectConfiguration,
Tree,
addProjectConfiguration,
readProjectConfiguration,
} from '@nx/devkit';
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import migration from './explicitly-set-projects-to-update-buildable-deps';
describe('explicitly-set-projects-to-update-buildable-deps migration', () => {
let tree: Tree;
beforeEach(() => {
tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
});
it.each([
'@nx/angular:ng-packagr-lite',
'@nrwl/angular:ng-packagr-lite',
'@nx/angular:package',
'@nrwl/angular:package',
])(
'should set updateBuildableProjectDepsInPackageJson option to "true" when not specified in target using "%s"',
async (executor) => {
addProjectConfiguration(tree, 'lib1', {
root: 'libs/lib1',
projectType: 'library',
targets: { build: { executor, options: {} } },
});
await migration(tree);
const project = readProjectConfiguration(tree, 'lib1');
expect(
project.targets.build.options.updateBuildableProjectDepsInPackageJson
).toBe(true);
}
);
it.each([
'@nx/angular:ng-packagr-lite',
'@nrwl/angular:ng-packagr-lite',
'@nx/angular:package',
'@nrwl/angular:package',
])(
'should not overwrite updateBuildableProjectDepsInPackageJson option when it is specified in target using "%s"',
async (executor) => {
addProjectConfiguration(tree, 'lib1', {
root: 'libs/lib1',
projectType: 'library',
targets: {
build: {
executor,
options: { updateBuildableProjectDepsInPackageJson: false },
},
},
});
await migration(tree);
const project = readProjectConfiguration(tree, 'lib1');
expect(
project.targets.build.options.updateBuildableProjectDepsInPackageJson
).toBe(false);
}
);
it('should not update targets using other executors', async () => {
const originalProjectConfig: ProjectConfiguration = {
root: 'libs/lib1',
projectType: 'library',
targets: {
build: {
executor: 'some-executor',
options: {},
},
},
};
addProjectConfiguration(tree, 'lib1', originalProjectConfig);
await migration(tree);
const project = readProjectConfiguration(tree, 'lib1');
expect(project.targets).toStrictEqual(originalProjectConfig.targets);
});
});

View File

@ -0,0 +1,44 @@
import {
formatFiles,
getProjects,
Tree,
updateProjectConfiguration,
} from '@nx/devkit';
const executors = new Set([
'@nx/angular:ng-packagr-lite',
'@nrwl/angular:ng-packagr-lite',
'@nx/angular:package',
'@nrwl/angular:package',
]);
export default async function (tree: Tree) {
const projects = getProjects(tree);
for (const [projectName, project] of projects) {
if (project.projectType !== 'library') {
continue;
}
let updated = false;
for (const [, target] of Object.entries(project.targets || {})) {
if (!executors.has(target.executor)) {
continue;
}
if (
target.options &&
target.options.updateBuildableProjectDepsInPackageJson === undefined
) {
target.options.updateBuildableProjectDepsInPackageJson = true;
updated = true;
}
}
if (updated) {
updateProjectConfiguration(tree, projectName, project);
}
}
await formatFiles(tree);
}

View File

@ -41,6 +41,12 @@
"version": "16.0.0-beta.1", "version": "16.0.0-beta.1",
"description": "Replace @nrwl/js with @nx/js", "description": "Replace @nrwl/js with @nx/js",
"implementation": "./src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages" "implementation": "./src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages"
},
"explicitly-set-projects-to-update-buildable-deps": {
"cli": "nx",
"version": "16.6.0-beta.0",
"description": "Explicitly set 'updateBuildableProjectDepsInPackageJson' to 'true' in targets that rely on that value as the default.",
"factory": "./src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps"
} }
}, },
"packageJsonUpdates": { "packageJsonUpdates": {

View File

@ -69,7 +69,7 @@
"updateBuildableProjectDepsInPackageJson": { "updateBuildableProjectDepsInPackageJson": {
"type": "boolean", "type": "boolean",
"description": "Whether to update the buildable project dependencies in the build output package.json.", "description": "Whether to update the buildable project dependencies in the build output package.json.",
"default": true "default": false
}, },
"buildableProjectDepsInPackageJsonType": { "buildableProjectDepsInPackageJsonType": {
"type": "string", "type": "string",

View File

@ -57,7 +57,7 @@
"updateBuildableProjectDepsInPackageJson": { "updateBuildableProjectDepsInPackageJson": {
"type": "boolean", "type": "boolean",
"description": "Whether to update the buildable project dependencies in the build output package.json.", "description": "Whether to update the buildable project dependencies in the build output package.json.",
"default": true "default": false
}, },
"buildableProjectDepsInPackageJsonType": { "buildableProjectDepsInPackageJsonType": {
"type": "string", "type": "string",

View File

@ -0,0 +1,76 @@
import {
ProjectConfiguration,
Tree,
addProjectConfiguration,
readProjectConfiguration,
} from '@nx/devkit';
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import migration from './explicitly-set-projects-to-update-buildable-deps';
describe('explicitly-set-projects-to-update-buildable-deps migration', () => {
let tree: Tree;
beforeEach(() => {
tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
});
it.each(['@nx/js:swc', '@nrwl/js:swc', '@nx/js:tsc', '@nrwl/js:tsc'])(
'should set updateBuildableProjectDepsInPackageJson option to "true" when not specified in target using "%s"',
async (executor) => {
addProjectConfiguration(tree, 'lib1', {
root: 'libs/lib1',
projectType: 'library',
targets: { build: { executor, options: {} } },
});
await migration(tree);
const project = readProjectConfiguration(tree, 'lib1');
expect(
project.targets.build.options.updateBuildableProjectDepsInPackageJson
).toBe(true);
}
);
it.each(['@nx/js:swc', '@nrwl/js:swc', '@nx/js:tsc', '@nrwl/js:tsc'])(
'should not overwrite updateBuildableProjectDepsInPackageJson option when it is specified in target using "%s"',
async (executor) => {
addProjectConfiguration(tree, 'lib1', {
root: 'libs/lib1',
projectType: 'library',
targets: {
build: {
executor,
options: { updateBuildableProjectDepsInPackageJson: false },
},
},
});
await migration(tree);
const project = readProjectConfiguration(tree, 'lib1');
expect(
project.targets.build.options.updateBuildableProjectDepsInPackageJson
).toBe(false);
}
);
it('should not update targets using other executors', async () => {
const originalProjectConfig: ProjectConfiguration = {
root: 'libs/lib1',
projectType: 'library',
targets: {
build: {
executor: 'some-executor',
options: {},
},
},
};
addProjectConfiguration(tree, 'lib1', originalProjectConfig);
await migration(tree);
const project = readProjectConfiguration(tree, 'lib1');
expect(project.targets).toStrictEqual(originalProjectConfig.targets);
});
});

View File

@ -0,0 +1,44 @@
import {
formatFiles,
getProjects,
Tree,
updateProjectConfiguration,
} from '@nx/devkit';
const executors = new Set([
'@nx/js:swc',
'@nrwl/js:swc',
'@nx/js:tsc',
'@nrwl/js:tsc',
]);
export default async function (tree: Tree) {
const projects = getProjects(tree);
for (const [projectName, project] of projects) {
if (project.projectType !== 'library') {
continue;
}
let updated = false;
for (const [, target] of Object.entries(project.targets || {})) {
if (!executors.has(target.executor)) {
continue;
}
if (
target.options &&
target.options.updateBuildableProjectDepsInPackageJson === undefined
) {
target.options.updateBuildableProjectDepsInPackageJson = true;
updated = true;
}
}
if (updated) {
updateProjectConfiguration(tree, projectName, project);
}
}
await formatFiles(tree);
}

View File

@ -17,6 +17,12 @@
"version": "16-3-3-beta.0", "version": "16-3-3-beta.0",
"description": "Add babelUpwardRootMode if not already defined", "description": "Add babelUpwardRootMode if not already defined",
"implementation": "./src/migrations/update-16-3-3-add-babel-upward-root-mode-flag/update-16-3-3-add-babel-upward-root-mode-flag" "implementation": "./src/migrations/update-16-3-3-add-babel-upward-root-mode-flag/update-16-3-3-add-babel-upward-root-mode-flag"
},
"explicitly-set-projects-to-update-buildable-deps": {
"cli": "nx",
"version": "16.6.0-beta.0",
"description": "Explicitly set 'updateBuildableProjectDepsInPackageJson' to 'true' in targets that rely on that value as the default.",
"factory": "./src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps"
} }
}, },
"packageJsonUpdates": {} "packageJsonUpdates": {}

View File

@ -92,7 +92,7 @@
"updateBuildableProjectDepsInPackageJson": { "updateBuildableProjectDepsInPackageJson": {
"type": "boolean", "type": "boolean",
"description": "Update buildable project dependencies in `package.json`.", "description": "Update buildable project dependencies in `package.json`.",
"default": true "default": false
}, },
"buildableProjectDepsInPackageJsonType": { "buildableProjectDepsInPackageJsonType": {
"type": "string", "type": "string",

View File

@ -0,0 +1,76 @@
import {
ProjectConfiguration,
Tree,
addProjectConfiguration,
readProjectConfiguration,
} from '@nx/devkit';
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import migration from './explicitly-set-projects-to-update-buildable-deps';
describe('explicitly-set-projects-to-update-buildable-deps migration', () => {
let tree: Tree;
beforeEach(() => {
tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
});
it.each(['@nx/rollup:rollup', '@nrwl/rollup:rollup'])(
'should set updateBuildableProjectDepsInPackageJson option to "true" when not specified in target using "%s"',
async (executor) => {
addProjectConfiguration(tree, 'lib1', {
root: 'libs/lib1',
projectType: 'library',
targets: { build: { executor, options: {} } },
});
await migration(tree);
const project = readProjectConfiguration(tree, 'lib1');
expect(
project.targets.build.options.updateBuildableProjectDepsInPackageJson
).toBe(true);
}
);
it.each(['@nx/js:swc', '@nrwl/js:swc', '@nx/js:tsc', '@nrwl/js:tsc'])(
'should not overwrite updateBuildableProjectDepsInPackageJson option when it is specified in target using "%s"',
async (executor) => {
addProjectConfiguration(tree, 'lib1', {
root: 'libs/lib1',
projectType: 'library',
targets: {
build: {
executor,
options: { updateBuildableProjectDepsInPackageJson: false },
},
},
});
await migration(tree);
const project = readProjectConfiguration(tree, 'lib1');
expect(
project.targets.build.options.updateBuildableProjectDepsInPackageJson
).toBe(false);
}
);
it('should not update targets using other executors', async () => {
const originalProjectConfig: ProjectConfiguration = {
root: 'libs/lib1',
projectType: 'library',
targets: {
build: {
executor: 'some-executor',
options: {},
},
},
};
addProjectConfiguration(tree, 'lib1', originalProjectConfig);
await migration(tree);
const project = readProjectConfiguration(tree, 'lib1');
expect(project.targets).toStrictEqual(originalProjectConfig.targets);
});
});

View File

@ -0,0 +1,39 @@
import {
formatFiles,
getProjects,
Tree,
updateProjectConfiguration,
} from '@nx/devkit';
const executors = new Set(['@nx/rollup:rollup', '@nrwl/rollup:rollup']);
export default async function (tree: Tree) {
const projects = getProjects(tree);
for (const [projectName, project] of projects) {
if (project.projectType !== 'library') {
continue;
}
let updated = false;
for (const [, target] of Object.entries(project.targets || {})) {
if (!executors.has(target.executor)) {
continue;
}
if (
target.options &&
target.options.updateBuildableProjectDepsInPackageJson === undefined
) {
target.options.updateBuildableProjectDepsInPackageJson = true;
updated = true;
}
}
if (updated) {
updateProjectConfiguration(tree, projectName, project);
}
}
await formatFiles(tree);
}