Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): add migration to set useLegacyCache by default #28454

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(core): add migration to set useLegacyCache by default
  • Loading branch information
Cammisuli committed Oct 15, 2024
commit 22f93ad139a032c857c3c2281eada3411d9ebf87
5 changes: 5 additions & 0 deletions packages/nx/migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@
"version": "20.0.0-beta.7",
"description": "Migration for v20.0.0-beta.7",
"implementation": "./src/migrations/update-20-0-0/move-use-daemon-process"
},
"use-legacy-cache": {
"version": "20.0.1",
"description": "Set `useLegacyCache` to true for migrating workspaces",
"implementation": "./src/migrations/update-20-0-1/use-legacy-cache"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { createTreeWithEmptyWorkspace } from '../../generators/testing-utils/create-tree-with-empty-workspace';
import { Tree } from '../../generators/tree';

import update from './use-legacy-cache';
import { readNxJson, updateNxJson } from '../../generators/utils/nx-json';

describe('use legacy cache', () => {
let tree: Tree;

beforeEach(() => {
tree = createTreeWithEmptyWorkspace();
});

it('should add `useLegacyCache` on migrating workspaces that did not have `enableDbCache`', async () => {
await update(tree);

expect(readNxJson(tree)).toMatchInlineSnapshot(`
{
"affected": {
"defaultBase": "main",
},
"targetDefaults": {
"build": {
"cache": true,
},
"lint": {
"cache": true,
},
},
"useLegacyCache": true,
}
`);
});
it('should not add `useLegacyCache` on migrating workspaces that did have `enableDbCache`', async () => {
const nxJson = readNxJson(tree);
updateNxJson(tree, {
enableDbCache: true,
...nxJson,
} as any);

await update(tree);

expect(readNxJson(tree)).toMatchInlineSnapshot(`
{
"affected": {
"defaultBase": "main",
},
"targetDefaults": {
"build": {
"cache": true,
},
"lint": {
"cache": true,
},
},
}
`);
});
});
19 changes: 19 additions & 0 deletions packages/nx/src/migrations/update-20-0-1/use-legacy-cache.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Tree } from '../../generators/tree';
import { formatChangedFilesWithPrettierIfAvailable } from '../../generators/internal-utils/format-changed-files-with-prettier-if-available';
import { readNxJson, updateNxJson } from '../../generators/utils/nx-json';
import { NxJsonConfiguration } from '../../config/nx-json';

export default async function update(tree: Tree) {
const nxJson = readNxJson(tree) as NxJsonConfiguration;

// If workspaces had `enableDbCache` we can just delete the property as the db cache is enabled by default in nx v20
if ((nxJson as any).enableDbCache) {
delete (nxJson as any).enableDbCache;
} else {
nxJson.useLegacyCache = true;
}

updateNxJson(tree, nxJson);

await formatChangedFilesWithPrettierIfAvailable(tree);
}