Skip to content

Commit

Permalink
feat(misc): change updateBuildableProjectDepsInPackageJson option def…
Browse files Browse the repository at this point in the history
…ault value to false (#17920)
  • Loading branch information
leosvelperez authored Jul 6, 2023
1 parent c6a0615 commit 64765eb
Show file tree
Hide file tree
Showing 22 changed files with 399 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion docs/generated/packages/angular/executors/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion docs/generated/packages/js/executors/swc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion docs/generated/packages/js/executors/tsc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion docs/generated/packages/rollup/executors/rollup.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"updateBuildableProjectDepsInPackageJson": {
"type": "boolean",
"description": "Update buildable project dependencies in `package.json`.",
"default": true
"default": false
},
"buildableProjectDepsInPackageJsonType": {
"type": "string",
Expand Down
4 changes: 3 additions & 1 deletion e2e/js/src/js-swc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}/${
Expand Down
6 changes: 2 additions & 4 deletions e2e/js/src/js-tsc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion e2e/react-core/src/react-package.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);

Expand Down
6 changes: 6 additions & 0 deletions packages/angular/migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/src/executors/ng-packagr-lite/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/src/executors/package/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
});
});
Original file line number Diff line number Diff line change
@@ -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);
}
6 changes: 6 additions & 0 deletions packages/js/migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion packages/js/src/executors/swc/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/js/src/executors/tsc/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
});
});
Loading

1 comment on commit 64765eb

@vercel
Copy link

@vercel vercel bot commented on 64765eb Jul 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-five.vercel.app
nx-dev-git-master-nrwl.vercel.app
nx-dev-nrwl.vercel.app
nx.dev

Please sign in to comment.