-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nx-micronaut): add migration to add
install
target in cacheabl…
…e operations
- Loading branch information
Showing
5 changed files
with
59 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"generators": { | ||
"add-install-to-cacheable-operations": { | ||
"version": "5.0.0", | ||
"description": "Add target to Nx cacheable operations", | ||
"implementation": "./src/migrations/add-install-to-cacheable-operations" | ||
} | ||
} | ||
} |
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
19 changes: 19 additions & 0 deletions
19
packages/nx-micronaut/src/migrations/add-install-to-cacheable-operations.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,19 @@ | ||
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; | ||
import { NxJsonConfiguration, Tree, readJson } from '@nx/devkit'; | ||
|
||
import update from './add-install-to-cacheable-operations'; | ||
|
||
describe('add-install-to-cacheable-operations migration', () => { | ||
let tree: Tree; | ||
|
||
beforeEach(() => { | ||
tree = createTreeWithEmptyWorkspace(); | ||
}); | ||
|
||
it('should run successfully', async () => { | ||
await update(tree); | ||
const nxJson = readJson<NxJsonConfiguration>(tree, 'nx.json'); | ||
expect(nxJson.targetDefaults['install'].cache).toBe(true) | ||
|
||
}); | ||
}); |
22 changes: 22 additions & 0 deletions
22
packages/nx-micronaut/src/migrations/add-install-to-cacheable-operations.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,22 @@ | ||
import { NxJsonConfiguration, Tree, formatFiles, readJson, writeJson } from '@nx/devkit'; | ||
|
||
export default async function update(host: Tree) { | ||
const nxJson = readJson<NxJsonConfiguration>(host, 'nx.json'); | ||
|
||
let cacheableOperationsPreNx17 = nxJson.tasksRunnerOptions?.['default']?.options?.cacheableOperations; | ||
|
||
if (cacheableOperationsPreNx17?.includes['install'] === false) { | ||
cacheableOperationsPreNx17 = [...cacheableOperationsPreNx17, 'install']; | ||
|
||
writeJson(host, 'nx.json', nxJson); | ||
} | ||
else { | ||
nxJson.targetDefaults ??= {}; | ||
nxJson.targetDefaults['install'] ??= {}; | ||
nxJson.targetDefaults['install'].cache ??= true; | ||
|
||
writeJson(host, 'nx.json', nxJson); | ||
} | ||
|
||
await formatFiles(host); | ||
} |