Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): fix "migrate-to-inputs" migration #16145

Merged
merged 2 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 124 additions & 0 deletions packages/nx/src/migrations/update-15-0-0/migrate-to-inputs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,130 @@ describe('15.0.0 migration (migrate-to-inputs)', () => {
const updatedWorkspace = readNxJson(tree);
expect(updatedWorkspace.namedInputs).not.toBeDefined();
});

it('should not override production inputs when migrating "implicitDependencies"', async () => {
updateNxJson(tree, {
namedInputs: {
default: ['{projectRoot}/**/*', 'sharedGlobals'],
production: [
'default',
'!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)',
'!{projectRoot}/tsconfig.spec.json',
'!{projectRoot}/jest.config.[jt]s',
'!{projectRoot}/.eslintrc.json',
],
sharedGlobals: ['{workspaceRoot}/nx.json'],
},
implicitDependencies: {
'.eslintrc.json': '*',
},
});
await migrateToInputs(tree);

const updated = readNxJson(tree);

expect(updated.implicitDependencies).toBeUndefined();
expect(updated).toMatchInlineSnapshot(`
Object {
"namedInputs": Object {
"default": Array [
"{projectRoot}/**/*",
"sharedGlobals",
],
"production": Array [
"default",
"!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)",
"!{projectRoot}/tsconfig.spec.json",
"!{projectRoot}/jest.config.[jt]s",
"!{projectRoot}/.eslintrc.json",
],
"sharedGlobals": Array [
"{workspaceRoot}/nx.json",
],
},
}
`);
});

it('should only preppend "default" to production inputs if missing when migrating "implicitDependencies"', async () => {
updateNxJson(tree, {
namedInputs: {
default: ['{projectRoot}/**/*', 'sharedGlobals'],
production: [
'!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)',
'!{projectRoot}/tsconfig.spec.json',
'!{projectRoot}/jest.config.[jt]s',
'!{projectRoot}/.eslintrc.json',
],
sharedGlobals: ['{workspaceRoot}/nx.json'],
},
implicitDependencies: {
'.eslintrc.json': '*',
},
});
await migrateToInputs(tree);

const updated = readNxJson(tree);

expect(updated.implicitDependencies).toBeUndefined();
expect(updated).toMatchInlineSnapshot(`
Object {
"namedInputs": Object {
"default": Array [
"{projectRoot}/**/*",
"sharedGlobals",
],
"production": Array [
"default",
"!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)",
"!{projectRoot}/tsconfig.spec.json",
"!{projectRoot}/jest.config.[jt]s",
"!{projectRoot}/.eslintrc.json",
],
"sharedGlobals": Array [
"{workspaceRoot}/nx.json",
],
},
}
`);
});

it('should not modify production inputs if "default" is missing when migrating "implicitDependencies"', async () => {
updateNxJson(tree, {
namedInputs: {
production: [
'!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)',
'!{projectRoot}/tsconfig.spec.json',
'!{projectRoot}/jest.config.[jt]s',
'!{projectRoot}/.eslintrc.json',
],
sharedGlobals: ['{workspaceRoot}/nx.json'],
},
implicitDependencies: {
'.eslintrc.json': '*',
},
});
await migrateToInputs(tree);

const updated = readNxJson(tree);

expect(updated.implicitDependencies).toBeUndefined();
expect(updated).toMatchInlineSnapshot(`
Object {
"namedInputs": Object {
"production": Array [
"!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)",
"!{projectRoot}/tsconfig.spec.json",
"!{projectRoot}/jest.config.[jt]s",
"!{projectRoot}/.eslintrc.json",
],
"sharedGlobals": Array [
"{workspaceRoot}/nx.json",
],
},
}
`);
});
});

describe('15.0.0 migration (migrate-to-inputs) (v1)', () => {
Expand Down
11 changes: 10 additions & 1 deletion packages/nx/src/migrations/update-15-0-0/migrate-to-inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,16 @@ export default async function (tree: Tree) {
sharedGlobals: [],
production: ['default'],
};
nxJson.namedInputs.production = ['default'];
if (nxJson.namedInputs.default) {
if (!nxJson.namedInputs.production) {
nxJson.namedInputs.production = ['default'];
} else if (!nxJson.namedInputs.production.includes('default')) {
nxJson.namedInputs.production = [
'default',
...nxJson.namedInputs.production,
];
}
}

if (isBuildATarget(tree)) {
nxJson.targetDefaults ??= {};
Expand Down