nx 23.2.0-beta.0 → 23.2.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/dist/bin/nx.js +1 -1
  2. package/dist/src/command-line/init/ai-agent-prompts.d.ts +1 -1
  3. package/dist/src/command-line/init/ai-agent-prompts.js +7 -6
  4. package/dist/src/command-line/init/command-object.js +10 -2
  5. package/dist/src/command-line/migrate/execute-migration.d.ts +72 -0
  6. package/dist/src/command-line/migrate/execute-migration.js +389 -0
  7. package/dist/src/command-line/migrate/migrate-ui-api.js +17 -12
  8. package/dist/src/command-line/migrate/migrate.d.ts +1 -45
  9. package/dist/src/command-line/migrate/migrate.js +13 -375
  10. package/dist/src/command-line/release/utils/release-graph.d.ts +2 -2
  11. package/dist/src/command-line/release/utils/shared.d.ts +2 -2
  12. package/dist/src/commands-runner/create-command-graph.js +5 -0
  13. package/dist/src/config/nx-json.d.ts +1 -1
  14. package/dist/src/core/graph/main.js +1 -1
  15. package/dist/src/generators/utils/nx-json.js +13 -3
  16. package/dist/src/native/nx.wasm32-wasi.debug.wasm +0 -0
  17. package/dist/src/native/nx.wasm32-wasi.wasm +0 -0
  18. package/dist/src/project-graph/file-utils.js +6 -1
  19. package/dist/src/tasks-runner/life-cycles/performance-analysis.d.ts +9 -4
  20. package/dist/src/tasks-runner/life-cycles/performance-life-cycle.js +5 -4
  21. package/dist/src/tasks-runner/life-cycles/performance-report.d.ts +16 -8
  22. package/dist/src/tasks-runner/life-cycles/performance-report.js +55 -27
  23. package/dist/src/utils/command-line-utils.js +30 -20
  24. package/dist/src/utils/git-revision.d.ts +12 -0
  25. package/dist/src/utils/git-revision.js +25 -0
  26. package/dist/src/utils/package-manager.js +6 -2
  27. package/package.json +11 -11
package/dist/bin/nx.js CHANGED
@@ -258,7 +258,7 @@ function warnIfUsingOutdatedGlobalInstall(globalNxVersion, localNxVersion) {
258
258
  `Your repository uses a higher version of Nx (${localNxVersion}) than your global CLI version (${globalNxVersion})`,
259
259
  ]
260
260
  : [];
261
- bodyLines.push('For more information, see https://nx.dev/more-concepts/global-nx');
261
+ bodyLines.push('For more information, see https://nx.dev/docs/getting-started/installation#global-installation');
262
262
  output_1.output.warn({
263
263
  title: `It's time to update Nx 🎉`,
264
264
  bodyLines,
@@ -1,2 +1,2 @@
1
1
  import { Agent } from '../../ai/utils';
2
- export declare function determineAiAgents(aiAgents?: Agent[], interactive?: boolean): Promise<Agent[]>;
2
+ export declare function determineAiAgents(aiAgents?: (Agent | 'none')[], interactive?: boolean): Promise<Agent[]>;
@@ -8,16 +8,17 @@ const utils_1 = require("../../ai/utils");
8
8
  const detect_ai_agent_1 = require("../../ai/detect-ai-agent");
9
9
  const pc = tslib_1.__importStar(require("picocolors"));
10
10
  async function determineAiAgents(aiAgents, interactive) {
11
- if (interactive === false || (0, is_ci_1.isCI)()) {
12
- if (aiAgents) {
13
- return aiAgents;
11
+ if (aiAgents) {
12
+ const filtered = aiAgents.filter((a) => a !== 'none');
13
+ if (filtered.length > 0) {
14
+ return filtered;
14
15
  }
16
+ return [];
17
+ }
18
+ if (interactive === false || (0, is_ci_1.isCI)()) {
15
19
  const detected = (0, detect_ai_agent_1.detectAiAgent)();
16
20
  return detected ? [detected] : [];
17
21
  }
18
- if (aiAgents) {
19
- return aiAgents;
20
- }
21
22
  return await aiAgentsPrompt();
22
23
  }
23
24
  async function aiAgentsPrompt() {
@@ -64,8 +64,16 @@ async function withInitOptions(yargs) {
64
64
  .option('aiAgents', {
65
65
  type: 'array',
66
66
  string: true,
67
- description: 'List of AI agents to set up.',
68
- choices: ['claude', 'codex', 'copilot', 'cursor', 'gemini', 'opencode'],
67
+ description: 'List of AI agents to set up. Use "none" to skip.',
68
+ choices: [
69
+ 'claude',
70
+ 'codex',
71
+ 'copilot',
72
+ 'cursor',
73
+ 'gemini',
74
+ 'opencode',
75
+ 'none',
76
+ ],
69
77
  })
70
78
  .option('plugins', {
71
79
  type: 'string',
@@ -0,0 +1,72 @@
1
+ import { MigrationsJson } from '../../config/misc-interfaces';
2
+ import { FileChange } from '../../generators/tree';
3
+ import { ArrayPackageGroup, NxMigrationsConfiguration, PackageJson } from '../../utils/package-json';
4
+ interface PackageMigrationConfig extends NxMigrationsConfiguration {
5
+ packageJson: PackageJson;
6
+ packageGroup: ArrayPackageGroup;
7
+ }
8
+ export declare function readPackageMigrationConfig(packageName: string, dir: string): PackageMigrationConfig;
9
+ export declare function runInstall(nxWorkspaceRoot?: string, phase?: MigrationInstallPhase): Promise<void>;
10
+ export type MigrationInstallPhase = 'pre-migration' | 'post-migration';
11
+ export declare class NpmPeerDepsInstallError extends Error {
12
+ constructor();
13
+ }
14
+ /**
15
+ * Detects npm peer-dependency resolution failures. Keyed on the `ERESOLVE`
16
+ * error code, which npm consistently emits for this class of failure across
17
+ * v7+ (`npm ERR! code ERESOLVE` / `npm error code ERESOLVE`). Falls back to a
18
+ * small set of stable phrases in case the code line is missing from the
19
+ * captured output.
20
+ */
21
+ export declare function isNpmPeerDepsError(stderr: string): boolean;
22
+ export declare function logNpmPeerDepsError(phase: MigrationInstallPhase): void;
23
+ export declare class ChangedDepInstaller {
24
+ private readonly root;
25
+ private readonly shouldSkipInstall;
26
+ private initialDeps;
27
+ private _skippedInstall;
28
+ constructor(root: string, shouldSkipInstall?: boolean);
29
+ get skippedInstall(): boolean;
30
+ installDepsIfChanged(): Promise<void>;
31
+ }
32
+ export declare function runNxOrAngularMigration(root: string, migration: {
33
+ package: string;
34
+ name: string;
35
+ description?: string;
36
+ version: string;
37
+ }, isVerbose: boolean, captureGeneratorOutput?: boolean, resolvedCollection?: {
38
+ collection: MigrationsJson;
39
+ collectionPath: string;
40
+ }): Promise<{
41
+ changes: FileChange[];
42
+ nextSteps: string[];
43
+ agentContext: string[];
44
+ logs: string;
45
+ madeChanges: boolean;
46
+ }>;
47
+ export declare function getStringifiedPackageJsonDeps(root: string): string;
48
+ export declare function runNxMigration(root: string, collectionPath: string, collection: MigrationsJson, name: string, migrationVersion: string | undefined, captureGeneratorOutput: boolean): Promise<{
49
+ changes: FileChange[];
50
+ nextSteps: string[];
51
+ agentContext: string[];
52
+ logs: string;
53
+ }>;
54
+ export declare function parseMigrationReturn(value: unknown): {
55
+ nextSteps: string[];
56
+ agentContext: string[];
57
+ };
58
+ export declare function filterStrings(value: unknown): string[];
59
+ export declare function readMigrationCollection(packageName: string, root: string): {
60
+ collection: MigrationsJson;
61
+ collectionPath: string;
62
+ };
63
+ export declare function getImplementationPath(collection: MigrationsJson, collectionPath: string, name: string, migrationVersion?: string): {
64
+ path: string;
65
+ fnSymbol: string;
66
+ };
67
+ export declare class MigrationImplementationMissingError extends Error {
68
+ constructor(baseMessage: string, collectionPath: string, migrationVersion: string | undefined);
69
+ }
70
+ export declare function isAngularMigration(collection: MigrationsJson, name: string): import("../../config/misc-interfaces").MigrationsJsonEntry;
71
+ export declare const getNgCompatLayer: () => Promise<typeof import("../../adapter/ngcli-adapter")>;
72
+ export {};
@@ -0,0 +1,389 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getNgCompatLayer = exports.MigrationImplementationMissingError = exports.ChangedDepInstaller = exports.NpmPeerDepsInstallError = void 0;
4
+ exports.readPackageMigrationConfig = readPackageMigrationConfig;
5
+ exports.runInstall = runInstall;
6
+ exports.isNpmPeerDepsError = isNpmPeerDepsError;
7
+ exports.logNpmPeerDepsError = logNpmPeerDepsError;
8
+ exports.runNxOrAngularMigration = runNxOrAngularMigration;
9
+ exports.getStringifiedPackageJsonDeps = getStringifiedPackageJsonDeps;
10
+ exports.runNxMigration = runNxMigration;
11
+ exports.parseMigrationReturn = parseMigrationReturn;
12
+ exports.filterStrings = filterStrings;
13
+ exports.readMigrationCollection = readMigrationCollection;
14
+ exports.getImplementationPath = getImplementationPath;
15
+ exports.isAngularMigration = isAngularMigration;
16
+ const tslib_1 = require("tslib");
17
+ const pc = tslib_1.__importStar(require("picocolors"));
18
+ const child_process_1 = require("child_process");
19
+ const path_1 = require("path");
20
+ const semver_1 = require("semver");
21
+ const handle_import_1 = require("../../utils/handle-import");
22
+ const tree_1 = require("../../generators/tree");
23
+ const fileutils_1 = require("../../utils/fileutils");
24
+ const logger_1 = require("../../utils/logger");
25
+ const package_json_1 = require("../../utils/package-json");
26
+ const package_manager_1 = require("../../utils/package-manager");
27
+ const output_1 = require("../../utils/output");
28
+ const fs_1 = require("fs");
29
+ const installation_directory_1 = require("../../utils/installation-directory");
30
+ const project_graph_1 = require("../../project-graph/project-graph");
31
+ const version_utils_1 = require("./version-utils");
32
+ function readPackageMigrationConfig(packageName, dir) {
33
+ const { path: packageJsonPath, packageJson: json } = (0, package_json_1.readModulePackageJson)(packageName, (0, installation_directory_1.getNxRequirePaths)(dir));
34
+ const config = (0, package_json_1.readNxMigrateConfig)(json);
35
+ if (!config) {
36
+ return { packageJson: json, migrations: null, packageGroup: [] };
37
+ }
38
+ try {
39
+ const migrationFile = require.resolve(config.migrations, {
40
+ paths: [(0, path_1.dirname)(packageJsonPath)],
41
+ });
42
+ return {
43
+ packageJson: json,
44
+ migrations: migrationFile,
45
+ packageGroup: config.packageGroup,
46
+ supportsOptionalMigrations: config.supportsOptionalMigrations,
47
+ };
48
+ }
49
+ catch {
50
+ return {
51
+ packageJson: json,
52
+ migrations: null,
53
+ packageGroup: config.packageGroup,
54
+ supportsOptionalMigrations: config.supportsOptionalMigrations,
55
+ };
56
+ }
57
+ }
58
+ function runInstall(nxWorkspaceRoot, phase = 'pre-migration') {
59
+ const cwd = nxWorkspaceRoot ?? process.cwd();
60
+ const packageManager = (0, package_manager_1.detectPackageManager)(cwd);
61
+ const pmCommands = (0, package_manager_1.getPackageManagerCommand)(packageManager, cwd);
62
+ const installCommand = `${pmCommands.install} ${pmCommands.ignoreScriptsFlag ?? ''}`;
63
+ output_1.output.log({
64
+ title: `Running '${installCommand}' to make sure necessary packages are installed`,
65
+ });
66
+ return new Promise((resolve, reject) => {
67
+ // For npm, pipe stderr so we can detect peer dependency errors while still
68
+ // mirroring it live to the user's terminal. Other package managers inherit
69
+ // stderr directly since we don't need to inspect their output.
70
+ const shouldCaptureStderr = packageManager === 'npm';
71
+ const child = (0, child_process_1.spawn)(installCommand, {
72
+ shell: true,
73
+ stdio: ['inherit', 'inherit', shouldCaptureStderr ? 'pipe' : 'inherit'],
74
+ windowsHide: true,
75
+ cwd,
76
+ });
77
+ const stderrChunks = [];
78
+ child.stderr?.on('data', (chunk) => {
79
+ process.stderr.write(chunk);
80
+ stderrChunks.push(chunk);
81
+ });
82
+ child.on('error', reject);
83
+ child.on('close', (code) => {
84
+ if (code === 0) {
85
+ resolve();
86
+ return;
87
+ }
88
+ if (shouldCaptureStderr) {
89
+ const stderr = Buffer.concat(stderrChunks).toString().trim();
90
+ if (isNpmPeerDepsError(stderr)) {
91
+ // Log the remediation guidance here so every caller of `runInstall`
92
+ // (CLI migrate, `nx repair`, single-migration runner, etc.) surfaces
93
+ // it consistently. Top-level callers catch `NpmPeerDepsInstallError`
94
+ // and return a non-zero exit code without re-logging.
95
+ logNpmPeerDepsError(phase);
96
+ reject(new NpmPeerDepsInstallError());
97
+ return;
98
+ }
99
+ }
100
+ reject(new Error(`Command failed: ${installCommand}`));
101
+ });
102
+ });
103
+ }
104
+ class NpmPeerDepsInstallError extends Error {
105
+ constructor() {
106
+ super('npm install failed due to peer dependency conflicts.');
107
+ this.name = 'NpmPeerDepsInstallError';
108
+ }
109
+ }
110
+ exports.NpmPeerDepsInstallError = NpmPeerDepsInstallError;
111
+ /**
112
+ * Detects npm peer-dependency resolution failures. Keyed on the `ERESOLVE`
113
+ * error code, which npm consistently emits for this class of failure across
114
+ * v7+ (`npm ERR! code ERESOLVE` / `npm error code ERESOLVE`). Falls back to a
115
+ * small set of stable phrases in case the code line is missing from the
116
+ * captured output.
117
+ */
118
+ function isNpmPeerDepsError(stderr) {
119
+ if (/\bERESOLVE\b/.test(stderr)) {
120
+ return true;
121
+ }
122
+ const lowerStderr = stderr.toLowerCase();
123
+ return (lowerStderr.includes('unable to resolve dependency tree') ||
124
+ lowerStderr.includes('could not resolve dependency') ||
125
+ lowerStderr.includes('conflicting peer dependency'));
126
+ }
127
+ function logNpmPeerDepsError(phase) {
128
+ const peerDepsResolutionSteps = [
129
+ 'Recommended approaches (in order of preference):',
130
+ '',
131
+ '1. Use "overrides" in package.json to force compatible versions across the dependency tree.',
132
+ ' See https://docs.npmjs.com/cli/configuring-npm/package-json#overrides',
133
+ '2. Persist legacy peer deps resolution in the project ".npmrc":',
134
+ ' npm config set legacy-peer-deps=true --location=project',
135
+ ' (bypasses peer dependency resolution; use with caution)',
136
+ '3. As a last resort, force the installation by running "npm install --force".',
137
+ ' (does not persist and may produce broken installs)',
138
+ ];
139
+ const manualInstallHint = [
140
+ 'If you installed the dependencies manually, pass "--skip-install" to avoid re-installing them:',
141
+ ' nx migrate --run-migrations --skip-install',
142
+ ];
143
+ if (phase === 'pre-migration') {
144
+ output_1.output.error({
145
+ title: 'You need to resolve the peer dependency conflicts before the migration can continue',
146
+ bodyLines: [
147
+ ...peerDepsResolutionSteps,
148
+ '',
149
+ 'Once the conflicts are resolved, re-run the migrations:',
150
+ ' nx migrate --run-migrations',
151
+ '',
152
+ ...manualInstallHint,
153
+ ],
154
+ });
155
+ }
156
+ else {
157
+ output_1.output.error({
158
+ title: 'Some migrations have been applied, but installing the updated dependencies failed',
159
+ bodyLines: [
160
+ ...peerDepsResolutionSteps,
161
+ '',
162
+ 'Once the conflicts are resolved, run "npm install" to install the updated dependencies.',
163
+ 'If the migration was interrupted before completing, re-run the remaining migrations:',
164
+ ' nx migrate --run-migrations',
165
+ '',
166
+ ...manualInstallHint,
167
+ ],
168
+ });
169
+ }
170
+ }
171
+ class ChangedDepInstaller {
172
+ constructor(root, shouldSkipInstall = false) {
173
+ this.root = root;
174
+ this.shouldSkipInstall = shouldSkipInstall;
175
+ this._skippedInstall = false;
176
+ this.initialDeps = getStringifiedPackageJsonDeps(root);
177
+ }
178
+ get skippedInstall() {
179
+ return this._skippedInstall;
180
+ }
181
+ async installDepsIfChanged() {
182
+ const currentDeps = getStringifiedPackageJsonDeps(this.root);
183
+ if (this.initialDeps !== currentDeps) {
184
+ if (this.shouldSkipInstall) {
185
+ this._skippedInstall = true;
186
+ }
187
+ else {
188
+ await runInstall(this.root, 'post-migration');
189
+ }
190
+ }
191
+ this.initialDeps = currentDeps;
192
+ }
193
+ }
194
+ exports.ChangedDepInstaller = ChangedDepInstaller;
195
+ async function runNxOrAngularMigration(root, migration, isVerbose, captureGeneratorOutput = false, resolvedCollection) {
196
+ const { collection, collectionPath } = resolvedCollection ?? readMigrationCollection(migration.package, root);
197
+ let changes = [];
198
+ let nextSteps = [];
199
+ let agentContext = [];
200
+ let logs = '';
201
+ // Angular's `ngResult.changes` is synthesized from the schematic's
202
+ // DryRunEvent stream so Nx and Angular paths can share commit/validation
203
+ // gating via `changes.length > 0`.
204
+ let madeChanges = false;
205
+ logger_1.logger.info(pc.dim('→ Running generator…'));
206
+ if (!isAngularMigration(collection, migration.name)) {
207
+ ({ nextSteps, changes, agentContext, logs } = await runNxMigration(root, collectionPath, collection, migration.name, migration.version, captureGeneratorOutput));
208
+ madeChanges = changes.length > 0;
209
+ logger_1.logger.info(`Ran ${migration.name} from ${migration.package}`);
210
+ if (migration.description) {
211
+ logger_1.logger.info(` ${migration.description}`);
212
+ }
213
+ logger_1.logger.info('');
214
+ if (!madeChanges) {
215
+ logger_1.logger.info(`No changes were made\n`);
216
+ return { changes, nextSteps, agentContext, logs, madeChanges };
217
+ }
218
+ logger_1.logger.info('Changes:');
219
+ (0, tree_1.printChanges)(changes, ' ');
220
+ logger_1.logger.info('');
221
+ }
222
+ else {
223
+ const ngCliAdapter = await (0, exports.getNgCompatLayer)();
224
+ const migrationProjectGraph = await (0, project_graph_1.createProjectGraphAsync)();
225
+ const ngResult = await ngCliAdapter.runMigration(root, migration.package, migration.name, (0, project_graph_1.readProjectsConfigurationFromProjectGraph)(migrationProjectGraph).projects, isVerbose, migrationProjectGraph);
226
+ changes = ngResult.changes;
227
+ madeChanges = ngResult.madeChanges;
228
+ logs = ngResult.loggingQueue.join('\n');
229
+ logger_1.logger.info(`Ran ${migration.name} from ${migration.package}`);
230
+ if (migration.description) {
231
+ logger_1.logger.info(` ${migration.description}`);
232
+ }
233
+ logger_1.logger.info('');
234
+ if (!madeChanges) {
235
+ logger_1.logger.info(`No changes were made\n`);
236
+ return { changes, nextSteps, agentContext, logs, madeChanges };
237
+ }
238
+ logger_1.logger.info('Changes:');
239
+ ngResult.loggingQueue.forEach((log) => logger_1.logger.info(' ' + log));
240
+ logger_1.logger.info('');
241
+ }
242
+ return { changes, nextSteps, agentContext, logs, madeChanges };
243
+ }
244
+ function getStringifiedPackageJsonDeps(root) {
245
+ try {
246
+ const { dependencies, devDependencies } = (0, fileutils_1.readJsonFile)((0, path_1.join)(root, 'package.json'));
247
+ return JSON.stringify([dependencies, devDependencies]);
248
+ }
249
+ catch {
250
+ // We don't really care if the .nx/installation property changes,
251
+ // whenever nxw is invoked it will handle the dep updates.
252
+ return '';
253
+ }
254
+ }
255
+ async function runNxMigration(root, collectionPath, collection, name, migrationVersion, captureGeneratorOutput) {
256
+ const { path: implPath, fnSymbol } = getImplementationPath(collection, collectionPath, name, migrationVersion);
257
+ const fn = require(implPath)[fnSymbol];
258
+ const host = new tree_1.FsTree(root, process.env.NX_VERBOSE_LOGGING === 'true', `migration ${collection.name}:${name}`);
259
+ let result;
260
+ let logs = '';
261
+ if (captureGeneratorOutput) {
262
+ const { withGeneratorOutputCapture } = require('./agentic/capture-generator-output');
263
+ ({ result, logs } = await withGeneratorOutputCapture(() => fn(host, {})));
264
+ }
265
+ else {
266
+ result = await fn(host, {});
267
+ }
268
+ const { nextSteps, agentContext } = parseMigrationReturn(result);
269
+ host.lock();
270
+ const changes = host.listChanges();
271
+ (0, tree_1.flushChanges)(root, changes);
272
+ return { changes, nextSteps, agentContext, logs };
273
+ }
274
+ function parseMigrationReturn(value) {
275
+ if (Array.isArray(value)) {
276
+ return { nextSteps: filterStrings(value), agentContext: [] };
277
+ }
278
+ if (value && typeof value === 'object') {
279
+ const obj = value;
280
+ return {
281
+ nextSteps: filterStrings(obj.nextSteps),
282
+ agentContext: filterStrings(obj.agentContext),
283
+ };
284
+ }
285
+ // Catches `void`, mistakenly-returned generator callbacks, malformed values.
286
+ return { nextSteps: [], agentContext: [] };
287
+ }
288
+ // Bucket-level tolerance: a single non-string entry shouldn't discard the
289
+ // whole `nextSteps` / `agentContext` array. Migration authors occasionally
290
+ // push `null` / `undefined` / a number into the array; we drop the bad entries
291
+ // and keep the rest so end-of-run guidance isn't silently lost.
292
+ function filterStrings(value) {
293
+ if (!Array.isArray(value))
294
+ return [];
295
+ return value.filter((v) => typeof v === 'string');
296
+ }
297
+ function readMigrationCollection(packageName, root) {
298
+ const collectionPath = readPackageMigrationConfig(packageName, root).migrations;
299
+ const collection = (0, fileutils_1.readJsonFile)(collectionPath);
300
+ collection.name ??= packageName;
301
+ return {
302
+ collection,
303
+ collectionPath,
304
+ };
305
+ }
306
+ function getImplementationPath(collection, collectionPath, name, migrationVersion) {
307
+ const g = collection.generators?.[name] || collection.schematics?.[name];
308
+ if (!g) {
309
+ throw new MigrationImplementationMissingError(`Unable to determine implementation path for "${collectionPath}:${name}"`, collectionPath, migrationVersion);
310
+ }
311
+ const implRelativePathAndMaybeSymbol = g.implementation || g.factory;
312
+ const [implRelativePath, fnSymbol = 'default'] = implRelativePathAndMaybeSymbol.split('#');
313
+ let implPath;
314
+ try {
315
+ implPath = require.resolve(implRelativePath, {
316
+ paths: [(0, path_1.dirname)(collectionPath)],
317
+ });
318
+ }
319
+ catch (e) {
320
+ try {
321
+ // workaround for a bug in node 12
322
+ implPath = require.resolve(`${(0, path_1.dirname)(collectionPath)}/${implRelativePath}`);
323
+ }
324
+ catch {
325
+ throw new MigrationImplementationMissingError(`Could not resolve implementation for migration "${name}" from "${collectionPath}"`, collectionPath, migrationVersion ?? g.version);
326
+ }
327
+ }
328
+ return { path: implPath, fnSymbol };
329
+ }
330
+ class MigrationImplementationMissingError extends Error {
331
+ constructor(baseMessage, collectionPath, migrationVersion) {
332
+ super(buildMigrationMissingMessage(baseMessage, collectionPath, migrationVersion));
333
+ this.name = 'MigrationImplementationMissingError';
334
+ }
335
+ }
336
+ exports.MigrationImplementationMissingError = MigrationImplementationMissingError;
337
+ function buildMigrationMissingMessage(baseMessage, collectionPath, migrationVersion) {
338
+ if (!migrationVersion) {
339
+ return baseMessage;
340
+ }
341
+ try {
342
+ const packageJsonPath = (0, path_1.join)((0, path_1.dirname)(collectionPath), 'package.json');
343
+ if (!(0, fs_1.existsSync)(packageJsonPath)) {
344
+ return baseMessage;
345
+ }
346
+ const packageJson = (0, fileutils_1.readJsonFile)(packageJsonPath);
347
+ const installedVersion = packageJson.version;
348
+ if (installedVersion &&
349
+ (0, semver_1.lt)((0, version_utils_1.normalizeVersion)(installedVersion), (0, version_utils_1.normalizeVersion)(migrationVersion))) {
350
+ const packageManager = (0, package_manager_1.detectPackageManager)();
351
+ const pmc = (0, package_manager_1.getPackageManagerCommand)(packageManager);
352
+ const overrideFieldName = getOverrideFieldName(packageManager);
353
+ return (`${baseMessage}\n\n` +
354
+ `The installed version of "${packageJson.name}" is ${installedVersion}, ` +
355
+ `but this migration requires version ${migrationVersion}. ` +
356
+ `This likely means the package version is being held back by an ${overrideFieldName} ` +
357
+ `in your package.json. ` +
358
+ `Remove the ${overrideFieldName} and run "${pmc.install}" to install the correct version.`);
359
+ }
360
+ }
361
+ catch {
362
+ // Fall through to return the base message if we can't read package info
363
+ }
364
+ return baseMessage;
365
+ }
366
+ function getOverrideFieldName(packageManager) {
367
+ switch (packageManager) {
368
+ case 'pnpm':
369
+ return '"pnpm.overrides"';
370
+ case 'yarn':
371
+ return '"resolutions"';
372
+ case 'npm':
373
+ case 'bun':
374
+ return '"overrides"';
375
+ }
376
+ }
377
+ function isAngularMigration(collection, name) {
378
+ return !collection.generators?.[name] && collection.schematics?.[name];
379
+ }
380
+ exports.getNgCompatLayer = (() => {
381
+ let _ngCliAdapter;
382
+ return async function getNgCompatLayer() {
383
+ if (!_ngCliAdapter) {
384
+ _ngCliAdapter = await (0, handle_import_1.handleImport)('../../adapter/ngcli-adapter.js', __dirname);
385
+ require('../../adapter/compat');
386
+ }
387
+ return _ngCliAdapter;
388
+ };
389
+ })();
@@ -19,6 +19,7 @@ exports.stopMigration = stopMigration;
19
19
  const child_process_1 = require("child_process");
20
20
  const fs_1 = require("fs");
21
21
  const path_1 = require("path");
22
+ const git_revision_1 = require("../../utils/git-revision");
22
23
  const migrate_1 = require("./migrate");
23
24
  Object.defineProperty(exports, "isHybridMigration", { enumerable: true, get: function () { return migrate_1.isHybridMigration; } });
24
25
  Object.defineProperty(exports, "isPromptOnlyMigration", { enumerable: true, get: function () { return migrate_1.isPromptOnlyMigration; } });
@@ -51,6 +52,9 @@ function finishMigrationProcess(workspacePath, squashCommits, commitMessage) {
51
52
  const migrationsJsonPath = (0, path_1.join)(workspacePath, 'migrations.json');
52
53
  const parsedMigrationsJson = JSON.parse((0, fs_1.readFileSync)(migrationsJsonPath, 'utf-8'));
53
54
  const initialGitRef = parsedMigrationsJson['nx-console'].initialGitRef;
55
+ if (squashCommits && initialGitRef) {
56
+ (0, git_revision_1.assertValidGitSha)(initialGitRef.ref);
57
+ }
54
58
  if ((0, fs_1.existsSync)(migrationsJsonPath)) {
55
59
  (0, fs_1.rmSync)(migrationsJsonPath);
56
60
  }
@@ -59,24 +63,24 @@ function finishMigrationProcess(workspacePath, squashCommits, commitMessage) {
59
63
  encoding: 'utf-8',
60
64
  windowsHide: true,
61
65
  });
62
- (0, child_process_1.execSync)(`git commit -m "${commitMessage}" --no-verify`, {
63
- cwd: workspacePath,
64
- encoding: 'utf-8',
65
- windowsHide: true,
66
- });
66
+ commit(workspacePath, commitMessage);
67
67
  if (squashCommits && initialGitRef) {
68
- (0, child_process_1.execSync)(`git reset --soft ${initialGitRef.ref}`, {
69
- cwd: workspacePath,
70
- encoding: 'utf-8',
71
- windowsHide: true,
72
- });
73
- (0, child_process_1.execSync)(`git commit -m "${commitMessage}" --no-verify`, {
68
+ (0, child_process_1.execFileSync)('git', ['reset', '--soft', initialGitRef.ref], {
74
69
  cwd: workspacePath,
75
70
  encoding: 'utf-8',
76
71
  windowsHide: true,
77
72
  });
73
+ commit(workspacePath, commitMessage);
78
74
  }
79
75
  }
76
+ function commit(workspacePath, commitMessage) {
77
+ (0, child_process_1.execSync)('git commit --no-verify -F -', {
78
+ cwd: workspacePath,
79
+ encoding: 'utf-8',
80
+ windowsHide: true,
81
+ input: commitMessage,
82
+ });
83
+ }
80
84
  async function runSingleMigration(workspacePath, migration, configuration) {
81
85
  try {
82
86
  // Set current migration tracking
@@ -342,7 +346,8 @@ function undoMigration(workspacePath, id) {
342
346
  // `existing.ref` is the unmodified HEAD at run time, so `ref^` would
343
347
  // reset past unrelated history. Only flip the metadata to skipped.
344
348
  if (existing.changedFiles.length > 0) {
345
- (0, child_process_1.execSync)(`git reset --hard ${existing.ref}^`, {
349
+ (0, git_revision_1.assertValidGitSha)(existing.ref);
350
+ (0, child_process_1.execFileSync)('git', ['reset', '--hard', `${existing.ref}^`], {
346
351
  cwd: workspacePath,
347
352
  encoding: 'utf-8',
348
353
  windowsHide: true,
@@ -1,6 +1,5 @@
1
1
  import { MigrationsJson, PackageJsonUpdateForPackage as PackageUpdate } from '../../config/misc-interfaces';
2
2
  import { NxJsonConfiguration } from '../../config/nx-json';
3
- import { FileChange } from '../../generators/tree';
4
3
  import { ArrayPackageGroup, PackageJson } from '../../utils/package-json';
5
4
  import { PackageManagerCommands } from '../../utils/package-manager';
6
5
  import { type MigrateFetchStats, type MigrateMultiMajorChoice } from './migrate-analytics';
@@ -10,6 +9,7 @@ import type { ResolvedAgentic } from './agentic/types';
10
9
  import { isHybridMigration, isPromptOnlyMigration } from './migration-shape';
11
10
  import { filterDowngradedUpdates } from './update-filters';
12
11
  import { normalizeVersion } from './version-utils';
12
+ export * from './execute-migration';
13
13
  export { normalizeVersion };
14
14
  export interface ResolvedMigrationConfiguration extends MigrationsJson {
15
15
  packageGroup?: ArrayPackageGroup;
@@ -174,14 +174,6 @@ export declare function createFetcher(pmc: PackageManagerCommands): ((pkg: strin
174
174
  };
175
175
  export { filterDowngradedUpdates };
176
176
  export declare function generateMigrationsJsonAndUpdatePackageJson(root: string, opts: GenerateMigrations, fetch?: MigratorOptions['fetch']): Promise<void>;
177
- /**
178
- * Detects npm peer-dependency resolution failures. Keyed on the `ERESOLVE`
179
- * error code, which npm consistently emits for this class of failure across
180
- * v7+ (`npm ERR! code ERESOLVE` / `npm error code ERESOLVE`). Falls back to a
181
- * small set of stable phrases in case the code line is missing from the
182
- * captured output.
183
- */
184
- export declare function isNpmPeerDepsError(stderr: string): boolean;
185
177
  type ExecutableMigration = {
186
178
  package: string;
187
179
  name: string;
@@ -253,46 +245,10 @@ export declare function executeMigrations(root: string, migrations: ExecutableMi
253
245
  committedShasCount: number;
254
246
  retainedAtSuccess: string[];
255
247
  }>;
256
- export declare class ChangedDepInstaller {
257
- private readonly root;
258
- private readonly shouldSkipInstall;
259
- private initialDeps;
260
- private _skippedInstall;
261
- constructor(root: string, shouldSkipInstall?: boolean);
262
- get skippedInstall(): boolean;
263
- installDepsIfChanged(): Promise<void>;
264
- }
265
- export declare function runNxOrAngularMigration(root: string, migration: {
266
- package: string;
267
- name: string;
268
- description?: string;
269
- version: string;
270
- }, isVerbose: boolean, captureGeneratorOutput?: boolean, resolvedCollection?: {
271
- collection: MigrationsJson;
272
- collectionPath: string;
273
- }): Promise<{
274
- changes: FileChange[];
275
- nextSteps: string[];
276
- agentContext: string[];
277
- logs: string;
278
- madeChanges: boolean;
279
- }>;
280
- export declare function parseMigrationReturn(value: unknown): {
281
- nextSteps: string[];
282
- agentContext: string[];
283
- };
284
248
  export declare function migrate(root: string, args: {
285
249
  [k: string]: any;
286
250
  }, rawArgs: string[]): Promise<number>;
287
251
  export declare function runMigration(): Promise<number>;
288
- export declare function readMigrationCollection(packageName: string, root: string): {
289
- collection: MigrationsJson;
290
- collectionPath: string;
291
- };
292
- export declare function getImplementationPath(collection: MigrationsJson, collectionPath: string, name: string, migrationVersion?: string): {
293
- path: string;
294
- fnSymbol: string;
295
- };
296
252
  /**
297
253
  * Resolves a migration's collection once and derives everything the run loop
298
254
  * needs from that single read: the implementation context (`collection` +