fix(gradle): add namedInputs to nx.json in gradle init (#23152)
<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> ## Current Behavior <!-- This is the behavior we have today --> ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #
This commit is contained in:
parent
bacdc799b4
commit
11f30f638f
@ -11,63 +11,122 @@ describe('@nx/gradle:init', () => {
|
||||
tree.write('settings.gradle', '');
|
||||
});
|
||||
|
||||
it('should add the plugin', async () => {
|
||||
await initGenerator(tree, {
|
||||
skipFormat: true,
|
||||
skipPackageJson: false,
|
||||
describe('plugin', () => {
|
||||
it('should add the plugin', async () => {
|
||||
await initGenerator(tree, {
|
||||
skipFormat: true,
|
||||
skipPackageJson: false,
|
||||
});
|
||||
const nxJson = readNxJson(tree);
|
||||
expect(nxJson.plugins).toMatchInlineSnapshot(`
|
||||
[
|
||||
{
|
||||
"options": {
|
||||
"buildTargetName": "build",
|
||||
"classesTargetName": "classes",
|
||||
"testTargetName": "test",
|
||||
},
|
||||
"plugin": "@nx/gradle",
|
||||
},
|
||||
]
|
||||
`);
|
||||
});
|
||||
|
||||
it('should not overwrite existing plugins', async () => {
|
||||
updateNxJson(tree, {
|
||||
plugins: ['foo'],
|
||||
});
|
||||
await initGenerator(tree, {
|
||||
skipFormat: true,
|
||||
skipPackageJson: false,
|
||||
});
|
||||
const nxJson = readNxJson(tree);
|
||||
expect(nxJson.plugins).toMatchInlineSnapshot(`
|
||||
[
|
||||
"foo",
|
||||
{
|
||||
"options": {
|
||||
"buildTargetName": "build",
|
||||
"classesTargetName": "classes",
|
||||
"testTargetName": "test",
|
||||
},
|
||||
"plugin": "@nx/gradle",
|
||||
},
|
||||
]
|
||||
`);
|
||||
});
|
||||
|
||||
it('should not add plugin if already in array', async () => {
|
||||
updateNxJson(tree, {
|
||||
plugins: ['@nx/gradle'],
|
||||
});
|
||||
await initGenerator(tree, {
|
||||
skipFormat: true,
|
||||
skipPackageJson: false,
|
||||
});
|
||||
const nxJson = readNxJson(tree);
|
||||
expect(nxJson.plugins).toMatchInlineSnapshot(`
|
||||
[
|
||||
"@nx/gradle",
|
||||
]
|
||||
`);
|
||||
});
|
||||
const nxJson = readNxJson(tree);
|
||||
expect(nxJson.plugins).toMatchInlineSnapshot(`
|
||||
[
|
||||
{
|
||||
"options": {
|
||||
"buildTargetName": "build",
|
||||
"classesTargetName": "classes",
|
||||
"testTargetName": "test",
|
||||
},
|
||||
"plugin": "@nx/gradle",
|
||||
},
|
||||
]
|
||||
`);
|
||||
});
|
||||
|
||||
it('should not overwrite existing plugins', async () => {
|
||||
updateNxJson(tree, {
|
||||
plugins: ['foo'],
|
||||
describe('namedInputs', () => {
|
||||
it('should add the namedInputs', async () => {
|
||||
await initGenerator(tree, {
|
||||
skipFormat: true,
|
||||
skipPackageJson: false,
|
||||
});
|
||||
const nxJson = readNxJson(tree);
|
||||
expect(nxJson.namedInputs).toMatchInlineSnapshot(`
|
||||
{
|
||||
"default": [
|
||||
"{projectRoot}/**/*",
|
||||
],
|
||||
"production": [
|
||||
"default",
|
||||
"!{projectRoot}/test/**/*",
|
||||
],
|
||||
}
|
||||
`);
|
||||
});
|
||||
await initGenerator(tree, {
|
||||
skipFormat: true,
|
||||
skipPackageJson: false,
|
||||
});
|
||||
const nxJson = readNxJson(tree);
|
||||
expect(nxJson.plugins).toMatchInlineSnapshot(`
|
||||
[
|
||||
"foo",
|
||||
{
|
||||
"options": {
|
||||
"buildTargetName": "build",
|
||||
"classesTargetName": "classes",
|
||||
"testTargetName": "test",
|
||||
},
|
||||
"plugin": "@nx/gradle",
|
||||
},
|
||||
]
|
||||
`);
|
||||
});
|
||||
|
||||
it('should not add plugin if already in array', async () => {
|
||||
updateNxJson(tree, {
|
||||
plugins: ['@nx/gradle'],
|
||||
it('should not overwrite existing namedInputs', async () => {
|
||||
updateNxJson(tree, {
|
||||
namedInputs: {
|
||||
default: ['foo'],
|
||||
production: [
|
||||
'bar',
|
||||
'!{projectRoot}/cypress/**/*',
|
||||
'!{projectRoot}/**/*.cy.[jt]s?(x)',
|
||||
'!{projectRoot}/cypress.config.[jt]s',
|
||||
'!{projectRoot}/test/**/*',
|
||||
],
|
||||
},
|
||||
});
|
||||
await initGenerator(tree, {
|
||||
skipFormat: true,
|
||||
skipPackageJson: false,
|
||||
});
|
||||
const nxJson = readNxJson(tree);
|
||||
expect(nxJson.namedInputs).toMatchInlineSnapshot(`
|
||||
{
|
||||
"default": [
|
||||
"foo",
|
||||
"{projectRoot}/**/*",
|
||||
],
|
||||
"production": [
|
||||
"bar",
|
||||
"!{projectRoot}/cypress/**/*",
|
||||
"!{projectRoot}/**/*.cy.[jt]s?(x)",
|
||||
"!{projectRoot}/cypress.config.[jt]s",
|
||||
"!{projectRoot}/test/**/*",
|
||||
"default",
|
||||
],
|
||||
}
|
||||
`);
|
||||
});
|
||||
await initGenerator(tree, {
|
||||
skipFormat: true,
|
||||
skipPackageJson: false,
|
||||
});
|
||||
const nxJson = readNxJson(tree);
|
||||
expect(nxJson.plugins).toMatchInlineSnapshot(`
|
||||
[
|
||||
"@nx/gradle",
|
||||
]
|
||||
`);
|
||||
});
|
||||
});
|
||||
|
||||
@ -30,6 +30,7 @@ export async function initGenerator(tree: Tree, options: InitGeneratorSchema) {
|
||||
}
|
||||
|
||||
addPlugin(tree);
|
||||
updateNxJsonConfiguration(tree);
|
||||
addProjectReportToBuildGradle(tree);
|
||||
|
||||
if (!options.skipFormat) {
|
||||
@ -93,4 +94,21 @@ allprojects {
|
||||
}
|
||||
}
|
||||
|
||||
function updateNxJsonConfiguration(tree: Tree) {
|
||||
const nxJson = readNxJson(tree);
|
||||
|
||||
if (!nxJson.namedInputs) {
|
||||
nxJson.namedInputs = {};
|
||||
}
|
||||
const defaultFilesSet = nxJson.namedInputs.default ?? [];
|
||||
nxJson.namedInputs.default = Array.from(
|
||||
new Set([...defaultFilesSet, '{projectRoot}/**/*'])
|
||||
);
|
||||
const productionFileSet = nxJson.namedInputs.production ?? [];
|
||||
nxJson.namedInputs.production = Array.from(
|
||||
new Set([...productionFileSet, 'default', '!{projectRoot}/test/**/*'])
|
||||
);
|
||||
updateNxJson(tree, nxJson);
|
||||
}
|
||||
|
||||
export default initGenerator;
|
||||
|
||||
@ -200,6 +200,8 @@ function createInputsMap(
|
||||
? ['production', '^production']
|
||||
: ['default', '^default'],
|
||||
test: ['default', namedInputs?.production ? '^production' : '^default'],
|
||||
classes: ['default', '^default'],
|
||||
classes: namedInputs?.production
|
||||
? ['production', '^production']
|
||||
: ['default', '^default'],
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user