Skip to content

Commit

Permalink
feat(nx-micronaut): add migration to add install target in cacheabl…
Browse files Browse the repository at this point in the history
…e operations
  • Loading branch information
tinesoft committed Oct 22, 2023
1 parent 213720f commit c4ea7ab
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/nx-micronaut/migrations.json
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"
}
}
}
4 changes: 4 additions & 0 deletions packages/nx-micronaut/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"native"
],
"dependencies": {
"@nx/devkit": "17.0.1",
"@nxrocks/common-jvm": "*",
"node-fetch": "^2.6.12",
"enquirer": "^2.4.1",
Expand All @@ -38,5 +39,8 @@
"typings": "./src/index.d.ts",
"peerDependencies": {
"@nx/devkit": ">=17.0.0"
},
"nx-migrations": {
"migrations": "./migrations.json"
}
}
5 changes: 5 additions & 0 deletions packages/nx-micronaut/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
"input": "./packages/nx-micronaut",
"glob": "executors.json",
"output": "."
},
{
"input": "./packages/nx-micronaut",
"glob": "migrations.json",
"output": "."
}
]
}
Expand Down
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)

});
});
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);
}

0 comments on commit c4ea7ab

Please sign in to comment.