diff --git a/docs/generated/packages/angular/executors/ng-packagr-lite.json b/docs/generated/packages/angular/executors/ng-packagr-lite.json index 5a6b2543c78dd..306a1c5092183 100644 --- a/docs/generated/packages/angular/executors/ng-packagr-lite.json +++ b/docs/generated/packages/angular/executors/ng-packagr-lite.json @@ -43,7 +43,7 @@ "updateBuildableProjectDepsInPackageJson": { "type": "boolean", "description": "Whether to update the buildable project dependencies in the build output package.json.", - "default": true + "default": false }, "buildableProjectDepsInPackageJsonType": { "type": "string", diff --git a/docs/generated/packages/angular/executors/package.json b/docs/generated/packages/angular/executors/package.json index 2efc57dc3abc4..a6cbc49aa14f9 100644 --- a/docs/generated/packages/angular/executors/package.json +++ b/docs/generated/packages/angular/executors/package.json @@ -46,7 +46,7 @@ "updateBuildableProjectDepsInPackageJson": { "type": "boolean", "description": "Whether to update the buildable project dependencies in the build output package.json.", - "default": true + "default": false }, "buildableProjectDepsInPackageJsonType": { "type": "string", diff --git a/docs/generated/packages/js/executors/swc.json b/docs/generated/packages/js/executors/swc.json index 48bec366c3f6f..1578c85eb9da6 100644 --- a/docs/generated/packages/js/executors/swc.json +++ b/docs/generated/packages/js/executors/swc.json @@ -98,7 +98,7 @@ "updateBuildableProjectDepsInPackageJson": { "type": "boolean", "description": "Whether to update the buildable project dependencies in the build output package.json.", - "default": true + "default": false }, "buildableProjectDepsInPackageJsonType": { "type": "string", diff --git a/docs/generated/packages/js/executors/tsc.json b/docs/generated/packages/js/executors/tsc.json index a0f26a4878d02..61f9e1b61d88a 100644 --- a/docs/generated/packages/js/executors/tsc.json +++ b/docs/generated/packages/js/executors/tsc.json @@ -98,7 +98,7 @@ "updateBuildableProjectDepsInPackageJson": { "type": "boolean", "description": "Whether to update the buildable project dependencies in the build output package.json.", - "default": true + "default": false }, "buildableProjectDepsInPackageJsonType": { "type": "string", diff --git a/docs/generated/packages/rollup/executors/rollup.json b/docs/generated/packages/rollup/executors/rollup.json index 1db6a873ceb85..0034da2d0f532 100644 --- a/docs/generated/packages/rollup/executors/rollup.json +++ b/docs/generated/packages/rollup/executors/rollup.json @@ -84,7 +84,7 @@ "updateBuildableProjectDepsInPackageJson": { "type": "boolean", "description": "Update buildable project dependencies in `package.json`.", - "default": true + "default": false }, "buildableProjectDepsInPackageJsonType": { "type": "string", diff --git a/e2e/js/src/js-swc.test.ts b/e2e/js/src/js-swc.test.ts index 502abcf3ffaba..f07b82f080ca8 100644 --- a/e2e/js/src/js-swc.test.ts +++ b/e2e/js/src/js-swc.test.ts @@ -91,7 +91,9 @@ describe('js e2e', () => { return json; }); - runCLI(`build ${lib} --generateLockfile=true`); + runCLI( + `build ${lib} --generateLockfile=true --updateBuildableProjectDepsInPackageJson` + ); checkFilesExist( `dist/libs/${lib}/package.json`, `dist/libs/${lib}/${ diff --git a/e2e/js/src/js-tsc.test.ts b/e2e/js/src/js-tsc.test.ts index 7c33ab06a7837..3494742bc2c64 100644 --- a/e2e/js/src/js-tsc.test.ts +++ b/e2e/js/src/js-tsc.test.ts @@ -129,9 +129,7 @@ describe('js e2e', () => { return json; }); - runCLI(`build ${lib}`); - - const rootPackageJson = readJson(`package.json`); + runCLI(`build ${lib} --updateBuildableProjectDepsInPackageJson`); expect(readJson(`dist/libs/${lib}/package.json`)).toHaveProperty( '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 expect(readJson(`dist/libs/${lib}/package.json`).dependencies).toEqual({ diff --git a/e2e/react-core/src/react-package.test.ts b/e2e/react-core/src/react-package.test.ts index 17f33f546e70e..6042f542cddd5 100644 --- a/e2e/react-core/src/react-package.test.ts +++ b/e2e/react-core/src/react-package.test.ts @@ -129,7 +129,7 @@ describe('Build React libraries and apps', () => { /* * 2. With dependencies */ - runCLI(`build ${parentLib}`); + runCLI(`build ${parentLib} --updateBuildableProjectDepsInPackageJson`); checkFilesExist(`dist/libs/${parentLib}/index.js`); diff --git a/packages/angular/migrations.json b/packages/angular/migrations.json index 7c696d62d6a52..3cfcbaa2da113 100644 --- a/packages/angular/migrations.json +++ b/packages/angular/migrations.json @@ -263,6 +263,12 @@ }, "description": "Update the @angular/cli package version to ~16.1.0.", "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": { diff --git a/packages/angular/src/executors/ng-packagr-lite/schema.json b/packages/angular/src/executors/ng-packagr-lite/schema.json index 2a769f6bfdb06..2051bb28a8e0a 100644 --- a/packages/angular/src/executors/ng-packagr-lite/schema.json +++ b/packages/angular/src/executors/ng-packagr-lite/schema.json @@ -40,7 +40,7 @@ "updateBuildableProjectDepsInPackageJson": { "type": "boolean", "description": "Whether to update the buildable project dependencies in the build output package.json.", - "default": true + "default": false }, "buildableProjectDepsInPackageJsonType": { "type": "string", diff --git a/packages/angular/src/executors/package/schema.json b/packages/angular/src/executors/package/schema.json index 8b48557b25ba4..1279a11875937 100644 --- a/packages/angular/src/executors/package/schema.json +++ b/packages/angular/src/executors/package/schema.json @@ -40,7 +40,7 @@ "updateBuildableProjectDepsInPackageJson": { "type": "boolean", "description": "Whether to update the buildable project dependencies in the build output package.json.", - "default": true + "default": false }, "buildableProjectDepsInPackageJsonType": { "type": "string", diff --git a/packages/angular/src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps.spec.ts b/packages/angular/src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps.spec.ts new file mode 100644 index 0000000000000..cc0f0378242ae --- /dev/null +++ b/packages/angular/src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps.spec.ts @@ -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); + }); +}); diff --git a/packages/angular/src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps.ts b/packages/angular/src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps.ts new file mode 100644 index 0000000000000..09e5f6c9cc4d5 --- /dev/null +++ b/packages/angular/src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps.ts @@ -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); +} diff --git a/packages/js/migrations.json b/packages/js/migrations.json index 8e3618d770e4b..9f0ced6950a75 100644 --- a/packages/js/migrations.json +++ b/packages/js/migrations.json @@ -41,6 +41,12 @@ "version": "16.0.0-beta.1", "description": "Replace @nrwl/js with @nx/js", "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": { diff --git a/packages/js/src/executors/swc/schema.json b/packages/js/src/executors/swc/schema.json index dc8bfc12303c6..6b356438d8d1b 100644 --- a/packages/js/src/executors/swc/schema.json +++ b/packages/js/src/executors/swc/schema.json @@ -69,7 +69,7 @@ "updateBuildableProjectDepsInPackageJson": { "type": "boolean", "description": "Whether to update the buildable project dependencies in the build output package.json.", - "default": true + "default": false }, "buildableProjectDepsInPackageJsonType": { "type": "string", diff --git a/packages/js/src/executors/tsc/schema.json b/packages/js/src/executors/tsc/schema.json index 9a8cc6557b78c..03078862a882d 100644 --- a/packages/js/src/executors/tsc/schema.json +++ b/packages/js/src/executors/tsc/schema.json @@ -57,7 +57,7 @@ "updateBuildableProjectDepsInPackageJson": { "type": "boolean", "description": "Whether to update the buildable project dependencies in the build output package.json.", - "default": true + "default": false }, "buildableProjectDepsInPackageJsonType": { "type": "string", diff --git a/packages/js/src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps.spec.ts b/packages/js/src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps.spec.ts new file mode 100644 index 0000000000000..07caa361d79f4 --- /dev/null +++ b/packages/js/src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps.spec.ts @@ -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); + }); +}); diff --git a/packages/js/src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps.ts b/packages/js/src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps.ts new file mode 100644 index 0000000000000..5273b2a748520 --- /dev/null +++ b/packages/js/src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps.ts @@ -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); +} diff --git a/packages/rollup/migrations.json b/packages/rollup/migrations.json index eb151def3ad9b..cfd0ba1e6e6fe 100644 --- a/packages/rollup/migrations.json +++ b/packages/rollup/migrations.json @@ -17,6 +17,12 @@ "version": "16-3-3-beta.0", "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" + }, + "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": {} diff --git a/packages/rollup/src/executors/rollup/schema.json b/packages/rollup/src/executors/rollup/schema.json index bbd35b6a81c22..c30f11f6d18c8 100644 --- a/packages/rollup/src/executors/rollup/schema.json +++ b/packages/rollup/src/executors/rollup/schema.json @@ -92,7 +92,7 @@ "updateBuildableProjectDepsInPackageJson": { "type": "boolean", "description": "Update buildable project dependencies in `package.json`.", - "default": true + "default": false }, "buildableProjectDepsInPackageJsonType": { "type": "string", diff --git a/packages/rollup/src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps.spec.ts b/packages/rollup/src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps.spec.ts new file mode 100644 index 0000000000000..0d244a11a33ec --- /dev/null +++ b/packages/rollup/src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps.spec.ts @@ -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); + }); +}); diff --git a/packages/rollup/src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps.ts b/packages/rollup/src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps.ts new file mode 100644 index 0000000000000..e3377e89e2f7d --- /dev/null +++ b/packages/rollup/src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps.ts @@ -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); +}