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
  • Loading branch information
leosvelperez committed Jul 3, 2023
1 parent 50d01d1 commit 78ca70a
Show file tree
Hide file tree
Showing 19 changed files with 393 additions and 10 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
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.5.0-beta.3",
"description": "Explicitly set 'updateBuildableProjectDepsInPackageJson' to 'true' in targets that rely on that value as the default.",
"factory": "./src/migrations/update-16-5-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.5.0-beta.3",
"description": "Explicitly set 'updateBuildableProjectDepsInPackageJson' to 'true' in targets that rely on that value as the default.",
"factory": "./src/migrations/update-16-5-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);
});
});
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/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);
}
6 changes: 6 additions & 0 deletions packages/rollup/migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.5.0-beta.3",
"description": "Explicitly set 'updateBuildableProjectDepsInPackageJson' to 'true' in targets that rely on that value as the default.",
"factory": "./src/migrations/update-16-5-0/explicitly-set-projects-to-update-buildable-deps"
}
},
"packageJsonUpdates": {}
Expand Down
2 changes: 1 addition & 1 deletion packages/rollup/src/executors/rollup/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
"updateBuildableProjectDepsInPackageJson": {
"type": "boolean",
"description": "Update buildable project dependencies in `package.json`.",
"default": true
"default": false
},
"buildableProjectDepsInPackageJsonType": {
"type": "string",
Expand Down
Loading

0 comments on commit 78ca70a

Please sign in to comment.