fix(core): fix "migrate-to-inputs" migration (#16145)
This commit is contained in:
parent
5afb5fc8fd
commit
aaa1113ab0
@ -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)', () => {
|
||||
|
||||
@ -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 ??= {};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user