-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(gradle): fix gradle exclude src/test (#26741)
<!-- 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` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## 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 #
- Loading branch information
Showing
5 changed files
with
110 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
packages/gradle/src/migrations/19-4-1/change-regex-test-production.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { Tree, readNxJson } from '@nx/devkit'; | ||
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; | ||
import update from './change-regex-test-production'; | ||
|
||
describe('change-regex-test-production', () => { | ||
let tree: Tree; | ||
|
||
beforeAll(() => { | ||
tree = createTreeWithEmptyWorkspace(); | ||
}); | ||
|
||
it('should not add to the namedInputs if it does not exist', async () => { | ||
tree.write( | ||
'nx.json', | ||
JSON.stringify({ namedInputs: {}, plugins: ['@nx/gradle'] }) | ||
); | ||
update(tree); | ||
expect(readNxJson(tree)).toMatchInlineSnapshot(` | ||
{ | ||
"namedInputs": {}, | ||
"plugins": [ | ||
"@nx/gradle", | ||
], | ||
} | ||
`); | ||
}); | ||
|
||
it('should not add to the namedInputs production if it is empty', async () => { | ||
tree.write( | ||
'nx.json', | ||
JSON.stringify({ | ||
namedInputs: { production: [] }, | ||
plugins: ['@nx/gradle'], | ||
}) | ||
); | ||
update(tree); | ||
expect(readNxJson(tree)).toMatchInlineSnapshot(` | ||
{ | ||
"namedInputs": { | ||
"production": [], | ||
}, | ||
"plugins": [ | ||
"@nx/gradle", | ||
], | ||
} | ||
`); | ||
}); | ||
|
||
it('should remove !{projectRoot}/test/**/* from the namedInputs production', async () => { | ||
tree.write( | ||
'nx.json', | ||
JSON.stringify({ | ||
namedInputs: { production: ['!{projectRoot}/test/**/*'] }, | ||
plugins: ['@nx/gradle'], | ||
}) | ||
); | ||
update(tree); | ||
expect(readNxJson(tree)).toMatchInlineSnapshot(` | ||
{ | ||
"namedInputs": { | ||
"production": [ | ||
"!{projectRoot}/src/test/**/*", | ||
], | ||
}, | ||
"plugins": [ | ||
"@nx/gradle", | ||
], | ||
} | ||
`); | ||
}); | ||
}); |
19 changes: 19 additions & 0 deletions
19
packages/gradle/src/migrations/19-4-1/change-regex-test-production.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Tree, readNxJson, updateNxJson } from '@nx/devkit'; | ||
import { hasGradlePlugin } from '../../utils/has-gradle-plugin'; | ||
|
||
// This function changes !{projectRoot}/test/**/* in nx.json for production to !{projectRoot}/src/test/**/* | ||
export default function update(tree: Tree) { | ||
if (!hasGradlePlugin(tree)) { | ||
return; | ||
} | ||
const nxJson = readNxJson(tree); | ||
if (!nxJson) { | ||
return; | ||
} | ||
const production = nxJson.namedInputs?.production; | ||
if (production?.includes('!{projectRoot}/test/**/*')) { | ||
production[production.indexOf('!{projectRoot}/test/**/*')] = | ||
'!{projectRoot}/src/test/**/*'; | ||
updateNxJson(tree, nxJson); | ||
} | ||
} |