Skip to content

feat(core)!: remove legacy cache flag from nx.json #30787

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

Merged
merged 5 commits into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
22 changes: 22 additions & 0 deletions docs/generated/devkit/Migration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Type alias: Migration

Ƭ **Migration**: (`tree`: [`Tree`](../../devkit/documents/Tree)) => `void` \| `Promise`\<`void`\> \| `string`[] \| `Promise`\<`string`[]\>

Represents a migration that is executed when running `nx migrate`.

Returning a string[] from the migration function will be interpreted as
a list of next steps to be displayed to the user.

#### Type declaration

▸ (`tree`): `void` \| `Promise`\<`void`\> \| `string`[] \| `Promise`\<`string`[]\>

##### Parameters

| Name | Type |
| :----- | :------------------------------------ |
| `tree` | [`Tree`](../../devkit/documents/Tree) |

##### Returns

`void` \| `Promise`\<`void`\> \| `string`[] \| `Promise`\<`string`[]\>
9 changes: 0 additions & 9 deletions docs/generated/devkit/NxJsonConfiguration.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ Nx.json configuration
- [tui](../../devkit/documents/NxJsonConfiguration#tui): Object
- [useDaemonProcess](../../devkit/documents/NxJsonConfiguration#usedaemonprocess): boolean
- [useInferencePlugins](../../devkit/documents/NxJsonConfiguration#useinferenceplugins): boolean
- [useLegacyCache](../../devkit/documents/NxJsonConfiguration#uselegacycache): boolean
- [workspaceLayout](../../devkit/documents/NxJsonConfiguration#workspacelayout): Object

## Properties
Expand Down Expand Up @@ -321,14 +320,6 @@ Set this to false to disable adding inference plugins when generating new projec

---

### useLegacyCache

• `Optional` **useLegacyCache**: `boolean`

Use the legacy file system cache instead of the db cache

---

### workspaceLayout

• `Optional` **workspaceLayout**: `Object`
Expand Down
1 change: 1 addition & 0 deletions docs/generated/devkit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ It only uses language primitives and immutable objects
- [Hasher](../../devkit/documents/Hasher)
- [ImplicitDependency](../../devkit/documents/ImplicitDependency)
- [ImplicitDependencyEntry](../../devkit/documents/ImplicitDependencyEntry)
- [Migration](../../devkit/documents/Migration)
- [NxPlugin](../../devkit/documents/NxPlugin)
- [NxPluginV2](../../devkit/documents/NxPluginV2)
- [PackageManager](../../devkit/documents/PackageManager)
Expand Down
13 changes: 0 additions & 13 deletions docs/generated/devkit/Workspace.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ use ProjectsConfigurations or NxJsonConfiguration
- [tui](../../devkit/documents/Workspace#tui): Object
- [useDaemonProcess](../../devkit/documents/Workspace#usedaemonprocess): boolean
- [useInferencePlugins](../../devkit/documents/Workspace#useinferenceplugins): boolean
- [useLegacyCache](../../devkit/documents/Workspace#uselegacycache): boolean
- [version](../../devkit/documents/Workspace#version): number
- [workspaceLayout](../../devkit/documents/Workspace#workspacelayout): Object

Expand Down Expand Up @@ -441,18 +440,6 @@ Set this to false to disable adding inference plugins when generating new projec

---

### useLegacyCache

• `Optional` **useLegacyCache**: `boolean`

Use the legacy file system cache instead of the db cache

#### Inherited from

[NxJsonConfiguration](../../devkit/documents/NxJsonConfiguration).[useLegacyCache](../../devkit/documents/NxJsonConfiguration#uselegacycache)

---

### version

• **version**: `number`
Expand Down
20 changes: 20 additions & 0 deletions docs/generated/manifests/nx-api.json
Original file line number Diff line number Diff line change
Expand Up @@ -3364,6 +3364,26 @@
}
},
"migrations": {
"/nx-api/nx/migrations/remove-legacy-cache": {
"description": "Removes the legacy cache configuration from nx.json",
"file": "generated/packages/nx/migrations/remove-legacy-cache.json",
"hidden": false,
"name": "remove-legacy-cache",
"version": "21.0.0-beta.8",
"originalFilePath": "/packages/nx",
"path": "/nx-api/nx/migrations/remove-legacy-cache",
"type": "migration"
},
"/nx-api/nx/migrations/remove-custom-tasks-runner": {
"description": "Removes the legacy cache configuration from nx.json",
"file": "generated/packages/nx/migrations/remove-custom-tasks-runner.json",
"hidden": false,
"name": "remove-custom-tasks-runner",
"version": "21.0.0-beta.8",
"originalFilePath": "/packages/nx",
"path": "/nx-api/nx/migrations/remove-custom-tasks-runner",
"type": "migration"
},
"/nx-api/nx/migrations/release-version-config-changes": {
"description": "Updates release version config based on the breaking changes in Nx v21",
"file": "generated/packages/nx/migrations/release-version-config-changes.json",
Expand Down
20 changes: 20 additions & 0 deletions docs/generated/packages-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -3340,6 +3340,26 @@
}
],
"migrations": [
{
"description": "Removes the legacy cache configuration from nx.json",
"file": "generated/packages/nx/migrations/remove-legacy-cache.json",
"hidden": false,
"name": "remove-legacy-cache",
"version": "21.0.0-beta.8",
"originalFilePath": "/packages/nx",
"path": "nx/migrations/remove-legacy-cache",
"type": "migration"
},
{
"description": "Removes the legacy cache configuration from nx.json",
"file": "generated/packages/nx/migrations/remove-custom-tasks-runner.json",
"hidden": false,
"name": "remove-custom-tasks-runner",
"version": "21.0.0-beta.8",
"originalFilePath": "/packages/nx",
"path": "nx/migrations/remove-custom-tasks-runner",
"type": "migration"
},
{
"description": "Updates release version config based on the breaking changes in Nx v21",
"file": "generated/packages/nx/migrations/release-version-config-changes.json",
Expand Down
1 change: 1 addition & 0 deletions docs/generated/packages/devkit/documents/nx_devkit.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ It only uses language primitives and immutable objects
- [Hasher](../../devkit/documents/Hasher)
- [ImplicitDependency](../../devkit/documents/ImplicitDependency)
- [ImplicitDependencyEntry](../../devkit/documents/ImplicitDependencyEntry)
- [Migration](../../devkit/documents/Migration)
- [NxPlugin](../../devkit/documents/NxPlugin)
- [NxPluginV2](../../devkit/documents/NxPluginV2)
- [PackageManager](../../devkit/documents/PackageManager)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "remove-custom-tasks-runner",
"version": "21.0.0-beta.8",
"description": "Removes the legacy cache configuration from nx.json",
"implementation": "/packages/nx/src/migrations/update-21-0-0/remove-custom-tasks-runner.ts",
"aliases": [],
"hidden": false,
"path": "/packages/nx",
"schema": null,
"type": "migration",
"examplesFile": "#### Remove Custom Tasks Runners\n\nRemoves `tasksRunnerOptions` entries from `nx.json` that contain custom tasks runners. In Nx 21, custom tasks runners are no longer functional. See /deprecated/custom-tasks-runner for more information.\n\n#### Sample Code Changes\n\nRemoves custom task runner configuration from `nx.json`.\n\n{% tabs %}\n{% tab label=\"Before\" %}\n\n```json {% fileName=\"nx.json\" %}\n{\n \"targetDefaults\": {},\n \"tasksRunnerOptions\": {\n \"default\": {\n \"runner\": \"custom-task-runner\"\n }\n }\n}\n```\n\n{% /tab %}\n{% tab label=\"After\" %}\n\n```json {% fileName=\"nx.json\" %}\n{\n \"targetDefaults\": {}\n}\n```\n\n{% /tab %}\n{% /tabs %}\n"
}
12 changes: 12 additions & 0 deletions docs/generated/packages/nx/migrations/remove-legacy-cache.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "remove-legacy-cache",
"version": "21.0.0-beta.8",
"description": "Removes the legacy cache configuration from nx.json",
"implementation": "/packages/nx/src/migrations/update-21-0-0/remove-legacy-cache.ts",
"aliases": [],
"hidden": false,
"path": "/packages/nx",
"schema": null,
"type": "migration",
"examplesFile": "#### Use Legacy Cache\n\nRemoves `useLegacyCache` from `nx.json` as it is no longer functional in Nx 21\n\n#### Sample Code Changes\n\n{% tabs %}\n{% tab label=\"Before\" %}\n\n```json {% fileName=\"nx.json\" %}\n{\n \"targetDefaults\": {},\n \"useLegacyCache\": true\n}\n```\n\n{% /tab %}\n{% tab label=\"After\" %}\n\n```json {% fileName=\"nx.json\" %}\n{\n \"targetDefaults\": {}\n}\n```\n\n{% /tab %}\n{% /tabs %}\n"
}
10 changes: 10 additions & 0 deletions packages/nx/migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@
"version": "21.0.0-beta.1",
"description": "Updates release version config based on the breaking changes in Nx v21",
"implementation": "./src/migrations/update-21-0-0/release-version-config-changes"
},
"remove-legacy-cache": {
"version": "21.0.0-beta.8",
"description": "Removes the legacy cache configuration from nx.json",
"implementation": "./src/migrations/update-21-0-0/remove-legacy-cache"
},
"remove-custom-tasks-runner": {
"version": "21.0.0-beta.8",
"description": "Removes the legacy cache configuration from nx.json",
"implementation": "./src/migrations/update-21-0-0/remove-custom-tasks-runner"
}
}
}
19 changes: 10 additions & 9 deletions packages/nx/src/command-line/migrate/migrate-ui-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,16 @@ export async function runSingleMigration(
// 2. Bundled into Console, so the version is fixed to what we build Console with.
const updatedMigrateModule = await import('./migrate.js');

const fileChanges = await updatedMigrateModule.runNxOrAngularMigration(
workspacePath,
migration,
false,
configuration.createCommits,
configuration.commitPrefix || 'chore: [nx migration] ',
undefined,
true
);
const { changes: fileChanges } =
await updatedMigrateModule.runNxOrAngularMigration(
workspacePath,
migration,
false,
configuration.createCommits,
configuration.commitPrefix || 'chore: [nx migration] ',
undefined,
true
);

const gitRefAfter = execSync('git rev-parse HEAD', {
cwd: workspacePath,
Expand Down
46 changes: 34 additions & 12 deletions packages/nx/src/command-line/migrate/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1474,18 +1474,19 @@ export async function executeMigrations(
logger.info(`- ${m.package}: ${m.name} (${m.description})`)
);
logger.info(`---------------------------------------------------------\n`);

const allNextSteps: string[] = [];
for (const m of sortedMigrations) {
logger.info(`Running migration ${m.package}: ${m.name}`);
try {
const changes = await runNxOrAngularMigration(
const { changes, nextSteps } = await runNxOrAngularMigration(
root,
m,
isVerbose,
shouldCreateCommits,
commitPrefix,
() => changedDepInstaller.installDepsIfChanged()
);
allNextSteps.push(...nextSteps);
if (changes.length === 0) {
migrationsWithNoChanges.push(m);
}
Expand All @@ -1502,7 +1503,7 @@ export async function executeMigrations(
changedDepInstaller.installDepsIfChanged();
}

return migrationsWithNoChanges;
return { migrationsWithNoChanges, nextSteps: allNextSteps };
}

class ChangedDepInstaller {
Expand Down Expand Up @@ -1533,7 +1534,7 @@ export async function runNxOrAngularMigration(
commitPrefix: string,
installDepsIfChanged?: () => void,
handleInstallDeps = false
): Promise<FileChange[]> {
): Promise<{ changes: FileChange[]; nextSteps: string[] }> {
if (!installDepsIfChanged) {
const changedDepInstaller = new ChangedDepInstaller(root);
installDepsIfChanged = () => changedDepInstaller.installDepsIfChanged();
Expand All @@ -1543,19 +1544,20 @@ export async function runNxOrAngularMigration(
root
);
let changes: FileChange[] = [];
let nextSteps: string[] = [];
if (!isAngularMigration(collection, migration.name)) {
changes = await runNxMigration(
({ nextSteps, changes } = await runNxMigration(
root,
collectionPath,
collection,
migration.name
);
));

logger.info(`Ran ${migration.name} from ${migration.package}`);
logger.info(` ${migration.description}\n`);
if (changes.length < 1) {
logger.info(`No changes were made\n`);
return [];
return { changes, nextSteps };
}

logger.info('Changes:');
Expand All @@ -1576,7 +1578,7 @@ export async function runNxOrAngularMigration(
logger.info(` ${migration.description}\n`);
if (!madeChanges) {
logger.info(`No changes were made\n`);
return [];
return { changes, nextSteps };
}

logger.info('Changes:');
Expand Down Expand Up @@ -1608,7 +1610,7 @@ export async function runNxOrAngularMigration(
installDepsIfChanged();
}

return changes;
return { changes, nextSteps };
}

async function runMigrations(
Expand Down Expand Up @@ -1662,7 +1664,7 @@ async function runMigrations(
version: string;
}[] = readJsonFile(join(root, opts.runMigrations)).migrations;

const migrationsWithNoChanges = await executeMigrations(
const { migrationsWithNoChanges, nextSteps } = await executeMigrations(
root,
migrations,
isVerbose,
Expand All @@ -1679,6 +1681,12 @@ async function runMigrations(
title: `No changes were made from running '${opts.runMigrations}'. This workspace is up to date!`,
});
}
if (nextSteps.length > 0) {
output.log({
title: `Some migrations have additional information, see below.`,
bodyLines: nextSteps.map((line) => `- ${line}`),
});
}
}

function getStringifiedPackageJsonDeps(root: string): string {
Expand Down Expand Up @@ -1712,11 +1720,18 @@ async function runNxMigration(
process.env.NX_VERBOSE_LOGGING === 'true',
`migration ${collection.name}:${name}`
);
await fn(host, {});
let nextSteps = await fn(host, {});
// This accounts for migrations that mistakenly return a generator callback
// from a migration. We've never executed these, so its not a breaking change that
// we don't call them now... but currently shipping a migration with one wouldn't break
// the migrate flow, so we are being cautious.
if (!isStringArray(nextSteps)) {
nextSteps = [];
}
host.lock();
const changes = host.listChanges();
flushChanges(root, changes);
return changes;
return { changes, nextSteps };
}

export async function migrate(
Expand Down Expand Up @@ -1905,3 +1920,10 @@ const getNgCompatLayer = (() => {
return _ngCliAdapter;
};
})();

function isStringArray(value: unknown): value is string[] {
if (!Array.isArray(value)) {
return false;
}
return value.every((v) => typeof v === 'string');
}
10 changes: 8 additions & 2 deletions packages/nx/src/command-line/repair/repair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ export async function repair(
);

const migrations = [...nxMigrations, ...extraMigrations];
const migrationsThatMadeNoChanges = await executeMigrations(
const { migrationsWithNoChanges, nextSteps } = await executeMigrations(
process.cwd(),
migrations,
args.verbose,
false,
''
);

if (migrationsThatMadeNoChanges.length < migrations.length) {
if (migrationsWithNoChanges.length < migrations.length) {
output.success({
title: `Successfully repaired your configuration. This workspace is up to date!`,
});
Expand All @@ -42,5 +42,11 @@ export async function repair(
title: `No changes were necessary. This workspace is up to date!`,
});
}
if (nextSteps.length) {
output.log({
title: 'Some repairs have additional information, see below.',
bodyLines: nextSteps.map((line) => ` - ${line}`),
});
}
});
}
2 changes: 1 addition & 1 deletion packages/nx/src/command-line/report/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ export async function getReportData(): Promise<ReportData> {
}
}

let cache = dbCacheEnabled(nxJson)
let cache = dbCacheEnabled()
? {
max:
nxJson.maxCacheSize !== undefined
Expand Down
Loading