nx 23.2.0-beta.7 → 23.2.0-beta.8

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 (130) hide show
  1. package/dist/bin/init-local.js +3 -5
  2. package/dist/release/changelog-renderer/index.js +4 -5
  3. package/dist/src/adapter/ngcli-adapter.js +60 -1
  4. package/dist/src/command-line/completion/command-object.js +7 -12
  5. package/dist/src/command-line/configure-ai-agents/configure-ai-agents.js +17 -23
  6. package/dist/src/command-line/generate/generate.js +35 -35
  7. package/dist/src/command-line/import/import.js +18 -40
  8. package/dist/src/command-line/init/ai-agent-prompts.js +5 -11
  9. package/dist/src/command-line/init/command-object.js +4 -2
  10. package/dist/src/command-line/init/implementation/add-nx-to-monorepo.js +12 -32
  11. package/dist/src/command-line/init/implementation/add-nx-to-nest.js +8 -21
  12. package/dist/src/command-line/init/implementation/add-nx-to-npm-repo.js +8 -21
  13. package/dist/src/command-line/init/implementation/angular/index.js +6 -15
  14. package/dist/src/command-line/init/init-v1.js +8 -18
  15. package/dist/src/command-line/init/init-v2.js +26 -56
  16. package/dist/src/command-line/migrate/agentic/definitions.js +35 -8
  17. package/dist/src/command-line/migrate/agentic/handoff-gitignore.d.ts +22 -3
  18. package/dist/src/command-line/migrate/agentic/handoff-gitignore.js +13 -10
  19. package/dist/src/command-line/migrate/agentic/handoff.d.ts +3 -1
  20. package/dist/src/command-line/migrate/agentic/handoff.js +4 -2
  21. package/dist/src/command-line/migrate/agentic/run-step.js +1 -0
  22. package/dist/src/command-line/migrate/agentic/runner.js +24 -24
  23. package/dist/src/command-line/migrate/agentic/select.js +20 -30
  24. package/dist/src/command-line/migrate/agentic/types.d.ts +19 -3
  25. package/dist/src/command-line/migrate/agentic/types.js +13 -4
  26. package/dist/src/command-line/migrate/command-object.d.ts +3 -0
  27. package/dist/src/command-line/migrate/command-object.js +13 -0
  28. package/dist/src/command-line/migrate/execute-migration.d.ts +14 -0
  29. package/dist/src/command-line/migrate/execute-migration.js +30 -9
  30. package/dist/src/command-line/migrate/migrate-analytics.d.ts +28 -0
  31. package/dist/src/command-line/migrate/migrate-analytics.js +51 -1
  32. package/dist/src/command-line/migrate/migrate-commits.d.ts +8 -2
  33. package/dist/src/command-line/migrate/migrate-commits.js +66 -19
  34. package/dist/src/command-line/migrate/migrate-config.d.ts +4 -2
  35. package/dist/src/command-line/migrate/migrate-config.js +12 -4
  36. package/dist/src/command-line/migrate/migrate.d.ts +9 -2
  37. package/dist/src/command-line/migrate/migrate.js +179 -56
  38. package/dist/src/command-line/migrate/multi-major.js +7 -10
  39. package/dist/src/command-line/migrate/resolve-package-version.js +4 -8
  40. package/dist/src/command-line/migrate/run/agent-output.d.ts +20 -0
  41. package/dist/src/command-line/migrate/run/agent-output.js +65 -0
  42. package/dist/src/command-line/migrate/run/index.d.ts +7 -0
  43. package/dist/src/command-line/migrate/run/index.js +19 -1
  44. package/dist/src/command-line/migrate/run/orchestrator.d.ts +20 -0
  45. package/dist/src/command-line/migrate/run/orchestrator.js +1200 -0
  46. package/dist/src/command-line/migrate/run/run-id.d.ts +16 -0
  47. package/dist/src/command-line/migrate/run/run-id.js +56 -0
  48. package/dist/src/command-line/migrate/run/run-state.d.ts +157 -0
  49. package/dist/src/command-line/migrate/run/run-state.js +438 -0
  50. package/dist/src/command-line/migrate/run/state-lock.d.ts +25 -0
  51. package/dist/src/command-line/migrate/run/state-lock.js +76 -0
  52. package/dist/src/command-line/migrate/run/state-machine.d.ts +84 -0
  53. package/dist/src/command-line/migrate/run/state-machine.js +315 -0
  54. package/dist/src/command-line/migrate/run/util.d.ts +58 -0
  55. package/dist/src/command-line/migrate/run/util.js +139 -7
  56. package/dist/src/command-line/migrate/run/worker.d.ts +1 -0
  57. package/dist/src/command-line/migrate/run/worker.js +308 -45
  58. package/dist/src/command-line/migrate/safe-prompt.d.ts +14 -26
  59. package/dist/src/command-line/migrate/safe-prompt.js +32 -43
  60. package/dist/src/command-line/migrate/step-actions.d.ts +5 -0
  61. package/dist/src/command-line/migrate/step-actions.js +12 -0
  62. package/dist/src/command-line/migrate/text.d.ts +18 -0
  63. package/dist/src/command-line/migrate/text.js +26 -0
  64. package/dist/src/command-line/migrate/version-skew-guard.d.ts +6 -4
  65. package/dist/src/command-line/migrate/version-skew-guard.js +34 -14
  66. package/dist/src/command-line/nx-cloud/connect/connect-to-nx-cloud.js +16 -20
  67. package/dist/src/command-line/release/changelog.js +6 -17
  68. package/dist/src/command-line/release/plan.js +15 -28
  69. package/dist/src/command-line/release/release.js +6 -17
  70. package/dist/src/command-line/release/utils/remote-release-clients/github.js +16 -22
  71. package/dist/src/command-line/release/utils/remote-release-clients/gitlab.js +13 -22
  72. package/dist/src/command-line/release/utils/resolve-semver-specifier.js +19 -41
  73. package/dist/src/command-line/release/version/resolve-current-version.js +7 -10
  74. package/dist/src/core/graph/main.js +1 -1
  75. package/dist/src/devkit-internals.d.ts +2 -0
  76. package/dist/src/devkit-internals.js +12 -4
  77. package/dist/src/migrations/update-23-2-0/set-cache-on-executor-target-defaults.d.ts +12 -0
  78. package/dist/src/migrations/update-23-2-0/set-cache-on-executor-target-defaults.js +250 -0
  79. package/dist/src/migrations/update-23-2-0/set-cache-on-executor-target-defaults.md +50 -0
  80. package/dist/src/native/nx.wasm32-wasi.debug.wasm +0 -0
  81. package/dist/src/native/nx.wasm32-wasi.wasm +0 -0
  82. package/dist/src/plugins/js/lock-file/bun-parser.js +43 -10
  83. package/dist/src/project-graph/utils/project-configuration/target-normalization.js +128 -2
  84. package/dist/src/tasks-runner/run-command.js +17 -32
  85. package/dist/src/tasks-runner/task-env.js +5 -2
  86. package/dist/src/tasks-runner/utils.js +2 -6
  87. package/dist/src/utils/analytics-prompt.js +4 -7
  88. package/dist/src/utils/exit-codes.d.ts +9 -0
  89. package/dist/src/utils/exit-codes.js +19 -0
  90. package/dist/src/utils/fileutils.d.ts +5 -0
  91. package/dist/src/utils/fileutils.js +7 -2
  92. package/dist/src/utils/git-utils.d.ts +33 -2
  93. package/dist/src/utils/git-utils.js +156 -8
  94. package/dist/src/utils/long-running-target.d.ts +10 -0
  95. package/dist/src/utils/long-running-target.js +19 -0
  96. package/dist/src/utils/min-release-age/behavior/bun.js +7 -11
  97. package/dist/src/utils/min-release-age/behavior/npm.js +5 -2
  98. package/dist/src/utils/min-release-age/packument.js +1 -1
  99. package/dist/src/utils/nx-console-prompt.js +3 -6
  100. package/dist/src/utils/package-manager-config/bunfig.d.ts +14 -0
  101. package/dist/src/utils/package-manager-config/bunfig.js +49 -0
  102. package/dist/src/utils/package-manager-config/npmrc.d.ts +23 -0
  103. package/dist/src/utils/package-manager-config/npmrc.js +124 -0
  104. package/dist/src/utils/package-manager-config/pnpm-config.d.ts +17 -0
  105. package/dist/src/utils/package-manager-config/pnpm-config.js +60 -0
  106. package/dist/src/utils/package-manager.d.ts +21 -2
  107. package/dist/src/utils/package-manager.js +244 -47
  108. package/dist/src/utils/params.d.ts +7 -1
  109. package/dist/src/utils/params.js +64 -6
  110. package/dist/src/utils/prompt-helpers.d.ts +53 -0
  111. package/dist/src/utils/prompt-helpers.js +111 -0
  112. package/dist/src/utils/provenance.js +6 -14
  113. package/dist/src/utils/registry-config/bun.d.ts +2 -0
  114. package/dist/src/utils/registry-config/bun.js +257 -0
  115. package/dist/src/utils/registry-config/index.d.ts +13 -0
  116. package/dist/src/utils/registry-config/index.js +102 -0
  117. package/dist/src/utils/registry-config/pnpm.d.ts +2 -0
  118. package/dist/src/utils/registry-config/pnpm.js +1551 -0
  119. package/dist/src/utils/registry-config/utils.d.ts +195 -0
  120. package/dist/src/utils/registry-config/utils.js +496 -0
  121. package/dist/src/utils/registry-config/yarn-berry.d.ts +2 -0
  122. package/dist/src/utils/registry-config/yarn-berry.js +612 -0
  123. package/dist/src/utils/registry-config/yarn-classic.d.ts +2 -0
  124. package/dist/src/utils/registry-config/yarn-classic.js +1001 -0
  125. package/dist/src/utils/safe-spawn.d.ts +24 -0
  126. package/dist/src/utils/safe-spawn.js +104 -0
  127. package/migrations.json +6 -0
  128. package/package.json +17 -13
  129. package/dist/src/utils/min-release-age/npmrc.d.ts +0 -15
  130. package/dist/src/utils/min-release-age/npmrc.js +0 -45
@@ -1,16 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MIGRATE_RUNS_RELATIVE_DIR = void 0;
3
+ exports.HANDOFFS_DIR_NAME = exports.MIGRATE_RUNS_RELATIVE_DIR = void 0;
4
4
  exports.isHandoffGitignoreMigration = isHandoffGitignoreMigration;
5
5
  /**
6
- * Workspace-relative directory holding all migrate-run scratch (handoff
7
- * files). Shared by the run-dir layout in `handoff.ts` and the agent
8
- * permission rules in `definitions.ts` so the pre-authorized write scope
6
+ * Workspace-relative directory holding all migrate-run scratch: a run
7
+ * directory per run id. Shared by the run-dir layout in `handoff.ts` and the
8
+ * agent permission rules in `definitions.ts` so the pre-authorized write scope
9
9
  * can't drift from the actual layout. It lives here so `definitions.ts`,
10
10
  * loaded whenever the agentic flow is resolved, doesn't pull in the handoff
11
11
  * runtime for the path alone.
12
12
  */
13
13
  exports.MIGRATE_RUNS_RELATIVE_DIR = '.nx/migrate-runs';
14
+ /**
15
+ * The one subtree of a run directory an agent writes: its handoff files.
16
+ * Everything beside it is state Nx owns and reads back, the orchestrator's
17
+ * run state and plan snapshots included, so the pre-authorized write scope
18
+ * stops at this segment. Package names make up the rest of a handoff path,
19
+ * so without it they would occupy the run directory's top level and leave Nx
20
+ * no name it could add there safely.
21
+ */
22
+ exports.HANDOFFS_DIR_NAME = 'handoffs';
14
23
  /**
15
24
  * Composite identity of the v23 migration that adds `.nx/migrate-runs` to
16
25
  * `.gitignore`. Hard-coded because the agentic preflight is a deliberate
@@ -1,5 +1,6 @@
1
1
  import { CommandModule } from 'yargs';
2
2
  import type { AgenticArg } from './agentic/select';
3
+ import { type StepAction } from './step-actions';
3
4
  export declare const yargsMigrateCommand: CommandModule;
4
5
  export declare const yargsInternalMigrateCommand: CommandModule;
5
6
  export declare const DEFAULT_MIGRATION_COMMIT_PREFIX = "chore: [nx migration] ";
@@ -18,6 +19,8 @@ export interface MigrateArgs {
18
19
  packageAndVersion?: string;
19
20
  runMigrations?: string;
20
21
  runMigration?: string;
22
+ runId?: string;
23
+ stepAction?: StepAction;
21
24
  include?: MigrateInclude;
22
25
  /**
23
26
  * nx.json `migrate.include` default. Consumed by `resolveInclude` only when the
@@ -6,6 +6,7 @@ const handle_import_1 = require("../../utils/handle-import");
6
6
  const documentation_1 = require("../yargs-utils/documentation");
7
7
  const shared_options_1 = require("../yargs-utils/shared-options");
8
8
  const cli_args_1 = require("./agentic/cli-args");
9
+ const step_actions_1 = require("./step-actions");
9
10
  exports.yargsMigrateCommand = {
10
11
  command: 'migrate [packageAndVersion]',
11
12
  describe: `Creates a migrations file or runs migrations from the migrations file.
@@ -56,6 +57,18 @@ function withMigrationOptions(yargs) {
56
57
  .option('runMigration', {
57
58
  describe: "Run a single migration from migrations.json by id. The id is '<package>:<name>'; a bare '<name>' is accepted when it matches exactly one migration. A name that contains ':' must use the full '<package>:<name>' form.",
58
59
  type: 'string',
60
+ })
61
+ .option('runId', {
62
+ // Hidden with the orchestrator itself.
63
+ describe: 'The orchestrated migrate run to record a single migration into, or to reconcile when given without --run-migration.',
64
+ type: 'string',
65
+ hidden: true,
66
+ })
67
+ .option('stepAction', {
68
+ describe: 'How an orchestrated reconcile resolves its single failed or died step.',
69
+ choices: step_actions_1.STEP_ACTIONS,
70
+ type: 'string',
71
+ hidden: true,
59
72
  })
60
73
  .option('ifExists', {
61
74
  describe: `Run migrations only if the migrations file exists, if not continues successfully.`,
@@ -28,8 +28,15 @@ export declare class ChangedDepInstaller {
28
28
  private readonly rerunCommand?;
29
29
  private initialDeps;
30
30
  private _skippedInstall;
31
+ private _installed;
31
32
  constructor(root: string, shouldSkipInstall?: boolean, rerunCommand?: string);
32
33
  get skippedInstall(): boolean;
34
+ /**
35
+ * Whether an install actually ran. Distinct from `!skippedInstall`, which is
36
+ * only about the skip-install flag: dependencies that never changed leave
37
+ * both false.
38
+ */
39
+ get installed(): boolean;
33
40
  installDepsIfChanged(): Promise<void>;
34
41
  }
35
42
  export declare function runNxOrAngularMigration(root: string, migration: {
@@ -45,6 +52,13 @@ export declare function runNxOrAngularMigration(root: string, migration: {
45
52
  logs: string;
46
53
  madeChanges: boolean;
47
54
  }>;
55
+ /**
56
+ * The workspace's declared dependencies, serialized for equality comparison,
57
+ * or `null` when package.json could not be read or parsed. Callers that
58
+ * persist the value across processes need that distinction: an unreadable
59
+ * package.json is not an empty dependency set.
60
+ */
61
+ export declare function readPackageJsonDeps(root: string): string | null;
48
62
  export declare function getStringifiedPackageJsonDeps(root: string): string;
49
63
  export declare function runNxMigration(root: string, collectionPath: string, collection: MigrationsJson, name: string, migrationVersion: string | undefined, captureGeneratorOutput: boolean): Promise<{
50
64
  changes: FileChange[];
@@ -8,6 +8,7 @@ exports.formatSingleMigrationRerunCommand = formatSingleMigrationRerunCommand;
8
8
  exports.logNpmPeerDepsError = logNpmPeerDepsError;
9
9
  exports.logSkippedPostMigrationInstall = logSkippedPostMigrationInstall;
10
10
  exports.runNxOrAngularMigration = runNxOrAngularMigration;
11
+ exports.readPackageJsonDeps = readPackageJsonDeps;
11
12
  exports.getStringifiedPackageJsonDeps = getStringifiedPackageJsonDeps;
12
13
  exports.runNxMigration = runNxMigration;
13
14
  exports.parseMigrationReturn = parseMigrationReturn;
@@ -25,6 +26,7 @@ const handle_import_1 = require("../../utils/handle-import");
25
26
  const tree_1 = require("../../generators/tree");
26
27
  const fileutils_1 = require("../../utils/fileutils");
27
28
  const logger_1 = require("../../utils/logger");
29
+ const text_1 = require("./text");
28
30
  const package_json_1 = require("../../utils/package-json");
29
31
  const package_manager_1 = require("../../utils/package-manager");
30
32
  const output_1 = require("../../utils/output");
@@ -199,11 +201,20 @@ class ChangedDepInstaller {
199
201
  this.shouldSkipInstall = shouldSkipInstall;
200
202
  this.rerunCommand = rerunCommand;
201
203
  this._skippedInstall = false;
204
+ this._installed = false;
202
205
  this.initialDeps = getStringifiedPackageJsonDeps(root);
203
206
  }
204
207
  get skippedInstall() {
205
208
  return this._skippedInstall;
206
209
  }
210
+ /**
211
+ * Whether an install actually ran. Distinct from `!skippedInstall`, which is
212
+ * only about the skip-install flag: dependencies that never changed leave
213
+ * both false.
214
+ */
215
+ get installed() {
216
+ return this._installed;
217
+ }
207
218
  async installDepsIfChanged() {
208
219
  const currentDeps = getStringifiedPackageJsonDeps(this.root);
209
220
  if (this.initialDeps !== currentDeps) {
@@ -212,6 +223,7 @@ class ChangedDepInstaller {
212
223
  }
213
224
  else {
214
225
  await runInstall(this.root, 'post-migration', this.rerunCommand);
226
+ this._installed = true;
215
227
  }
216
228
  }
217
229
  this.initialDeps = currentDeps;
@@ -235,9 +247,9 @@ async function runNxOrAngularMigration(root, migration, isVerbose, captureGenera
235
247
  ({ nextSteps, changes, agentContext, skipAgentic, logs } =
236
248
  await runNxMigration(root, collectionPath, collection, migration.name, migration.version, captureGeneratorOutput));
237
249
  madeChanges = changes.length > 0;
238
- logger_1.logger.info(`Ran ${migration.name} from ${migration.package}`);
250
+ logger_1.logger.info((0, text_1.singleLine)(`Ran ${migration.name} from ${migration.package}`));
239
251
  if (migration.description) {
240
- logger_1.logger.info(` ${migration.description}`);
252
+ logger_1.logger.info((0, text_1.singleLine)(` ${migration.description}`));
241
253
  }
242
254
  logger_1.logger.info('');
243
255
  if (!madeChanges) {
@@ -262,9 +274,9 @@ async function runNxOrAngularMigration(root, migration, isVerbose, captureGenera
262
274
  changes = ngResult.changes;
263
275
  madeChanges = ngResult.madeChanges;
264
276
  logs = ngResult.loggingQueue.join('\n');
265
- logger_1.logger.info(`Ran ${migration.name} from ${migration.package}`);
277
+ logger_1.logger.info((0, text_1.singleLine)(`Ran ${migration.name} from ${migration.package}`));
266
278
  if (migration.description) {
267
- logger_1.logger.info(` ${migration.description}`);
279
+ logger_1.logger.info((0, text_1.singleLine)(` ${migration.description}`));
268
280
  }
269
281
  logger_1.logger.info('');
270
282
  if (!madeChanges) {
@@ -279,22 +291,31 @@ async function runNxOrAngularMigration(root, migration, isVerbose, captureGenera
279
291
  };
280
292
  }
281
293
  logger_1.logger.info('Changes:');
282
- ngResult.loggingQueue.forEach((log) => logger_1.logger.info(' ' + log));
294
+ ngResult.loggingQueue.forEach((log) => logger_1.logger.info((0, text_1.singleLine)(' ' + log)));
283
295
  logger_1.logger.info('');
284
296
  }
285
297
  return { changes, nextSteps, agentContext, skipAgentic, logs, madeChanges };
286
298
  }
287
- function getStringifiedPackageJsonDeps(root) {
299
+ /**
300
+ * The workspace's declared dependencies, serialized for equality comparison,
301
+ * or `null` when package.json could not be read or parsed. Callers that
302
+ * persist the value across processes need that distinction: an unreadable
303
+ * package.json is not an empty dependency set.
304
+ */
305
+ function readPackageJsonDeps(root) {
288
306
  try {
289
307
  const { dependencies, devDependencies } = (0, fileutils_1.readJsonFile)((0, path_1.join)(root, 'package.json'));
290
308
  return JSON.stringify([dependencies, devDependencies]);
291
309
  }
292
310
  catch {
293
- // We don't really care if the .nx/installation property changes,
294
- // whenever nxw is invoked it will handle the dep updates.
295
- return '';
311
+ return null;
296
312
  }
297
313
  }
314
+ function getStringifiedPackageJsonDeps(root) {
315
+ // We don't really care if the .nx/installation property changes,
316
+ // whenever nxw is invoked it will handle the dep updates.
317
+ return readPackageJsonDeps(root) ?? '';
318
+ }
298
319
  async function runNxMigration(root, collectionPath, collection, name, migrationVersion, captureGeneratorOutput) {
299
320
  const { path: implPath, fnSymbol } = getImplementationPath(collection, collectionPath, name, migrationVersion);
300
321
  const fn = require(implPath)[fnSymbol];
@@ -67,12 +67,40 @@ export declare function reportMigrateRunError(opts: {
67
67
  migrationCount?: number;
68
68
  error?: unknown;
69
69
  }): void;
70
+ export declare function reportMigrateOrchestratorInit(opts: {
71
+ migrationCount: number;
72
+ createCommits: boolean;
73
+ }): void;
74
+ /**
75
+ * One event per orchestrator dispense. The `action` (dispense case) is a
76
+ * closed enum carried on a reused dimension, read conditioned on the event
77
+ * name (the same multiplexing pattern as {@link reportMigratePrompt});
78
+ * `attempt` rides the migration-count dimension.
79
+ */
80
+ export declare function reportMigrateOrchestratorDispense(opts: {
81
+ action: string;
82
+ attempt: number;
83
+ }): void;
84
+ /**
85
+ * Terminal funnel event. The two step tallies and the total dispense count
86
+ * ride reused numeric dimensions, read conditioned on the event name.
87
+ */
88
+ export declare function reportMigrateOrchestratorComplete(opts: {
89
+ completed: number;
90
+ skipped: number;
91
+ dispenseCount: number;
92
+ }): void;
70
93
  /**
71
94
  * Counts invocations, not completions: emitted as soon as the migration id
72
95
  * resolves, while the worker can still stop before running anything.
96
+ *
97
+ * An invocation recorded into an orchestrated run (`--run-id`) gets its own
98
+ * event name. Every other one keeps the name `--run-migration` shipped with,
99
+ * so that series stays continuous for users who never enable the orchestrator.
73
100
  */
74
101
  export declare function reportMigrateSingleMigrationInvocation(opts: {
75
102
  migrationType: 'generator' | 'prompt' | 'hybrid';
103
+ orchestrated: boolean;
76
104
  }): void;
77
105
  export declare function computeMajorsCrossed(installed: string | null | undefined, target: string | null | undefined): number | undefined;
78
106
  export declare function safeReport(emit: () => void): void;
@@ -11,6 +11,9 @@ exports.reportMigrateRunStart = reportMigrateRunStart;
11
11
  exports.hasMigrateRunStarted = hasMigrateRunStarted;
12
12
  exports.reportMigrateRunComplete = reportMigrateRunComplete;
13
13
  exports.reportMigrateRunError = reportMigrateRunError;
14
+ exports.reportMigrateOrchestratorInit = reportMigrateOrchestratorInit;
15
+ exports.reportMigrateOrchestratorDispense = reportMigrateOrchestratorDispense;
16
+ exports.reportMigrateOrchestratorComplete = reportMigrateOrchestratorComplete;
14
17
  exports.reportMigrateSingleMigrationInvocation = reportMigrateSingleMigrationInvocation;
15
18
  exports.computeMajorsCrossed = computeMajorsCrossed;
16
19
  exports.safeReport = safeReport;
@@ -181,15 +184,62 @@ function reportMigrateRunError(opts) {
181
184
  });
182
185
  });
183
186
  }
187
+ function reportMigrateOrchestratorInit(opts) {
188
+ safeReport(() => {
189
+ if (!analytics_1.customDimensions)
190
+ return;
191
+ (0, analytics_1.reportEvent)('migrate_orchestrator_init', {
192
+ [analytics_1.customDimensions.createCommits]: opts.createCommits,
193
+ [analytics_1.customDimensions.migrationCount]: opts.migrationCount,
194
+ });
195
+ });
196
+ }
197
+ /**
198
+ * One event per orchestrator dispense. The `action` (dispense case) is a
199
+ * closed enum carried on a reused dimension, read conditioned on the event
200
+ * name (the same multiplexing pattern as {@link reportMigratePrompt});
201
+ * `attempt` rides the migration-count dimension.
202
+ */
203
+ function reportMigrateOrchestratorDispense(opts) {
204
+ safeReport(() => {
205
+ if (!analytics_1.customDimensions)
206
+ return;
207
+ (0, analytics_1.reportEvent)('migrate_orchestrator_dispense', {
208
+ [analytics_1.customDimensions.promptChoice]: opts.action,
209
+ [analytics_1.customDimensions.migrationCount]: opts.attempt,
210
+ });
211
+ });
212
+ }
213
+ /**
214
+ * Terminal funnel event. The two step tallies and the total dispense count
215
+ * ride reused numeric dimensions, read conditioned on the event name.
216
+ */
217
+ function reportMigrateOrchestratorComplete(opts) {
218
+ safeReport(() => {
219
+ if (!analytics_1.customDimensions)
220
+ return;
221
+ (0, analytics_1.reportEvent)('migrate_orchestrator_complete', {
222
+ [analytics_1.customDimensions.appliedCount]: opts.completed,
223
+ [analytics_1.customDimensions.taskCount]: opts.skipped,
224
+ [analytics_1.customDimensions.migrationCount]: opts.dispenseCount,
225
+ });
226
+ });
227
+ }
184
228
  /**
185
229
  * Counts invocations, not completions: emitted as soon as the migration id
186
230
  * resolves, while the worker can still stop before running anything.
231
+ *
232
+ * An invocation recorded into an orchestrated run (`--run-id`) gets its own
233
+ * event name. Every other one keeps the name `--run-migration` shipped with,
234
+ * so that series stays continuous for users who never enable the orchestrator.
187
235
  */
188
236
  function reportMigrateSingleMigrationInvocation(opts) {
189
237
  safeReport(() => {
190
238
  if (!analytics_1.customDimensions)
191
239
  return;
192
- (0, analytics_1.reportEvent)('migrate_single_migration_invocation', {
240
+ (0, analytics_1.reportEvent)(opts.orchestrated
241
+ ? 'migrate_single_migration_recorded'
242
+ : 'migrate_single_migration_invocation', {
193
243
  [analytics_1.customDimensions.promptChoice]: opts.migrationType,
194
244
  });
195
245
  });
@@ -55,7 +55,7 @@ export declare function commitCheckpointBeforeMigrations(root: string, commitPre
55
55
  */
56
56
  export declare function resolveCreateCommits(args: {
57
57
  createCommits: boolean | undefined;
58
- agenticKind: ResolvedAgentic['kind'];
58
+ mode: ResolvedAgentic['kind'] | 'orchestrated';
59
59
  isGitRepo: boolean;
60
60
  commitPrefixIsCustom?: boolean;
61
61
  }): {
@@ -65,9 +65,15 @@ export declare function resolveCreateCommits(args: {
65
65
  error?: string;
66
66
  };
67
67
  /**
68
+ * Asks before a run starts committing on the workspace's default branch, and
69
+ * reports the decision when the answer is no. Returns whether to proceed.
70
+ *
68
71
  * Callers gate this on commits being effective and on prompting being
69
- * possible, so non-interactive runs (CI, `--no-interactive`) never reach here.
72
+ * possible, so non-interactive runs (CI, `--no-interactive`) never reach here;
73
+ * `confirmCommitsOnDefaultBranch` has no guard of its own and would block on a
74
+ * prompt nobody can answer.
70
75
  */
76
+ export declare function confirmMigrationCommitsOnDefaultBranch(root: string, whatWouldRun: 'running migrations' | 'running the migration'): Promise<boolean>;
71
77
  export declare function confirmCommitsOnDefaultBranch(args: {
72
78
  currentBranch: string | null;
73
79
  defaultBranch: string | null;
@@ -3,13 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.commitMigrationIfRequested = commitMigrationIfRequested;
4
4
  exports.commitCheckpointBeforeMigrations = commitCheckpointBeforeMigrations;
5
5
  exports.resolveCreateCommits = resolveCreateCommits;
6
+ exports.confirmMigrationCommitsOnDefaultBranch = confirmMigrationCommitsOnDefaultBranch;
6
7
  exports.confirmCommitsOnDefaultBranch = confirmCommitsOnDefaultBranch;
7
8
  const tslib_1 = require("tslib");
8
9
  const pc = tslib_1.__importStar(require("picocolors"));
10
+ const configuration_1 = require("../../config/configuration");
11
+ const command_line_utils_1 = require("../../utils/command-line-utils");
9
12
  const git_utils_1 = require("../../utils/git-utils");
10
13
  const logger_1 = require("../../utils/logger");
11
14
  const output_1 = require("../../utils/output");
15
+ const types_1 = require("./agentic/types");
12
16
  const safe_prompt_1 = require("./safe-prompt");
17
+ // `git add -A` captures an orchestrated run's scratch state whenever the
18
+ // ignore rule that normally hides it goes missing mid-run (a checkout, a
19
+ // .gitignore edit, or the migration's own changes).
20
+ const MIGRATE_COMMIT_EXCLUDES = [types_1.MIGRATE_RUNS_RELATIVE_DIR];
13
21
  /**
14
22
  * `pendingMigrations` are listed in the commit body so a `git log -p` reader
15
23
  * can see which earlier migrations' diffs this commit absorbed (their own
@@ -23,15 +31,16 @@ async function commitMigrationIfRequested(root, migration, shouldCreateCommits,
23
31
  if (!shouldCreateCommits)
24
32
  return { status: 'disabled' };
25
33
  await installDepsIfChanged();
26
- // Generator may have only touched gitignored paths, or the prompt half
27
- // made no change — log neutrally instead of as an error.
28
- if (!(0, git_utils_1.hasUncommittedChanges)(root)) {
34
+ // Generator may have only touched gitignored paths or the excluded scratch
35
+ // dir, or the prompt half made no change: log neutrally, not as an error.
36
+ // The probe excludes what the commit excludes, else the commit fails empty.
37
+ if (!(0, git_utils_1.hasUncommittedChanges)(root, MIGRATE_COMMIT_EXCLUDES)) {
29
38
  logger_1.logger.info(pc.dim(`- No changes to commit for ${migration.name}.`));
30
39
  return { status: 'no-changes' };
31
40
  }
32
41
  const commitMessage = buildCommitMessage(`${commitPrefix}${migration.name}`, pendingMigrations);
33
42
  try {
34
- const sha = (0, git_utils_1.tryCommitChanges)(commitMessage, root);
43
+ const sha = (0, git_utils_1.tryCommitChanges)(commitMessage, root, MIGRATE_COMMIT_EXCLUDES);
35
44
  if (sha)
36
45
  return { status: 'committed', sha };
37
46
  // null = commit landed but `git rev-parse HEAD` failed (see
@@ -74,10 +83,10 @@ function buildCommitMessage(subject, pendingMigrations) {
74
83
  * the working tree is already clean.
75
84
  */
76
85
  function commitCheckpointBeforeMigrations(root, commitPrefix) {
77
- if (!(0, git_utils_1.hasUncommittedChanges)(root))
86
+ if (!(0, git_utils_1.hasUncommittedChanges)(root, MIGRATE_COMMIT_EXCLUDES))
78
87
  return;
79
88
  try {
80
- const sha = (0, git_utils_1.tryCommitChanges)(`${commitPrefix}checkpoint before running migrations`, root);
89
+ const sha = (0, git_utils_1.tryCommitChanges)(`${commitPrefix}checkpoint before running migrations`, root, MIGRATE_COMMIT_EXCLUDES);
81
90
  if (sha) {
82
91
  logger_1.logger.info(pc.dim(`- Checkpoint commit created: ${sha}`));
83
92
  return;
@@ -108,7 +117,11 @@ function commitCheckpointBeforeMigrations(root, commitPrefix) {
108
117
  * pointing at git.
109
118
  */
110
119
  function resolveCreateCommits(args) {
111
- const { createCommits, agenticKind, isGitRepo, commitPrefixIsCustom } = args;
120
+ const { createCommits, mode, isGitRepo, commitPrefixIsCustom } = args;
121
+ // The orchestrator forces the agentic defaults without the `--agentic` flag,
122
+ // so its warnings must not name a flag the user never passed.
123
+ const orchestrated = mode === 'orchestrated';
124
+ const agenticKind = orchestrated ? 'enabled' : mode;
112
125
  if (createCommits === true && !isGitRepo) {
113
126
  return {
114
127
  effective: false,
@@ -121,7 +134,9 @@ function resolveCreateCommits(args) {
121
134
  return {
122
135
  effective: false,
123
136
  agenticHasDiffContext: false,
124
- warning: "--no-create-commits was passed alongside --agentic. Without per-migration commits, the agent can't isolate the current migration's changes from earlier migrations in this run. Drop --no-create-commits for accurate per-migration review." +
137
+ warning: (orchestrated
138
+ ? "--no-create-commits was passed, but orchestrated migrate runs create per-migration commits by default. Without them, the agent can't isolate the current migration's changes from earlier migrations in this run. Drop --no-create-commits for accurate per-migration review."
139
+ : "--no-create-commits was passed alongside --agentic. Without per-migration commits, the agent can't isolate the current migration's changes from earlier migrations in this run. Drop --no-create-commits for accurate per-migration review.") +
125
140
  (commitPrefixIsCustom
126
141
  ? ' Note: the custom --commit-prefix value will have no effect because commits are disabled.'
127
142
  : ''),
@@ -133,7 +148,9 @@ function resolveCreateCommits(args) {
133
148
  return {
134
149
  effective: false,
135
150
  agenticHasDiffContext: false,
136
- warning: '`--agentic` enables per-migration commits by default, but the workspace is not a git repository. Continuing without commits, so the agent will not receive per-file diff context. Run `git init` to enable.' +
151
+ warning: (orchestrated
152
+ ? 'Orchestrated migrate runs create per-migration commits by default, but the workspace is not a git repository. Continuing without commits, so the agent will not receive per-file diff context. Run `git init` to enable.'
153
+ : '`--agentic` enables per-migration commits by default, but the workspace is not a git repository. Continuing without commits, so the agent will not receive per-file diff context. Run `git init` to enable.') +
137
154
  (commitPrefixIsCustom
138
155
  ? ' The custom --commit-prefix value will have no effect.'
139
156
  : ''),
@@ -149,22 +166,52 @@ function resolveCreateCommits(args) {
149
166
  : undefined,
150
167
  };
151
168
  }
169
+ // The branch to hold `getBaseRef`'s value against. It may name a remote-tracking
170
+ // ref whose local counterpart drops the remote (the CI-workflow generator writes
171
+ // `origin/<branch>`), yet a local branch can be named `up/feature` while `up` is
172
+ // a remote, so an exact match wins before any stripping and the longest matching
173
+ // remote wins after. `origin` counts even undeclared: the generator assumes it.
174
+ function defaultBranchToCompare(baseRef, currentBranch, root) {
175
+ if (currentBranch === baseRef) {
176
+ return baseRef;
177
+ }
178
+ const remote = [...(0, git_utils_1.getGitRemoteNames)(root), 'origin']
179
+ .filter((name) => baseRef.startsWith(`${name}/`))
180
+ .sort((a, b) => b.length - a.length)[0];
181
+ return remote ? baseRef.slice(remote.length + 1) : baseRef;
182
+ }
152
183
  /**
184
+ * Asks before a run starts committing on the workspace's default branch, and
185
+ * reports the decision when the answer is no. Returns whether to proceed.
186
+ *
153
187
  * Callers gate this on commits being effective and on prompting being
154
- * possible, so non-interactive runs (CI, `--no-interactive`) never reach here.
188
+ * possible, so non-interactive runs (CI, `--no-interactive`) never reach here;
189
+ * `confirmCommitsOnDefaultBranch` has no guard of its own and would block on a
190
+ * prompt nobody can answer.
155
191
  */
192
+ async function confirmMigrationCommitsOnDefaultBranch(root, whatWouldRun) {
193
+ const currentBranch = (0, git_utils_1.getGitCurrentBranch)(root);
194
+ const proceed = await confirmCommitsOnDefaultBranch({
195
+ currentBranch,
196
+ defaultBranch: defaultBranchToCompare((0, command_line_utils_1.getBaseRef)((0, configuration_1.readNxJson)(root)), currentBranch, root),
197
+ });
198
+ if (!proceed) {
199
+ output_1.output.log({
200
+ title: `Skipped ${whatWouldRun} to avoid committing to the default branch '${currentBranch}'.`,
201
+ bodyLines: [
202
+ 'Switch to a different branch and re-run, or re-run and confirm to proceed.',
203
+ ],
204
+ });
205
+ }
206
+ return proceed;
207
+ }
156
208
  async function confirmCommitsOnDefaultBranch(args) {
157
209
  const { currentBranch, defaultBranch } = args;
158
210
  if (!currentBranch || !defaultBranch || currentBranch !== defaultBranch) {
159
211
  return true;
160
212
  }
161
- const { proceed } = await (0, safe_prompt_1.migratePrompt)([
162
- {
163
- name: 'proceed',
164
- type: 'confirm',
165
- message: `You're on the default branch '${currentBranch}'. nx migrate will create a commit for each migration on this branch. Continue?`,
166
- initial: false,
167
- },
168
- ]);
169
- return proceed;
213
+ return (0, safe_prompt_1.migrateConfirm)({
214
+ message: `You're on the default branch '${currentBranch}'. nx migrate will create a commit for each migration on this branch. Continue?`,
215
+ initial: false,
216
+ });
170
217
  }
@@ -8,8 +8,10 @@ import { type MigrateArgs } from './command-object';
8
8
  * Phase-aware so each option is only filled where it is consumed, and so a
9
9
  * config value never trips the mutually-exclusive-flag guards in
10
10
  * `parseMigrationsOptions`: `include` and `multiMajorMode` in the generate
11
- * phase only, `agentic` / `validate` / `createCommits` / `commitPrefix` when
12
- * running the whole migrations file or a single migration.
11
+ * phase only; `createCommits` / `commitPrefix` and `agentic` / `validate` when
12
+ * running the whole migrations file or a standalone single migration. A
13
+ * `--run-id` invocation takes none of them: a recorded run takes its commit
14
+ * config from run.json and is driven by the outer agent.
13
15
  *
14
16
  * `include` is carried as `includeFromConfig` so it is never mistaken for an
15
17
  * explicit `--include`: `resolveInclude` applies it only when the resolved
@@ -13,8 +13,10 @@ const MULTI_MAJOR_MODE_ENV = 'NX_MULTI_MAJOR_MODE';
13
13
  * Phase-aware so each option is only filled where it is consumed, and so a
14
14
  * config value never trips the mutually-exclusive-flag guards in
15
15
  * `parseMigrationsOptions`: `include` and `multiMajorMode` in the generate
16
- * phase only, `agentic` / `validate` / `createCommits` / `commitPrefix` when
17
- * running the whole migrations file or a single migration.
16
+ * phase only; `createCommits` / `commitPrefix` and `agentic` / `validate` when
17
+ * running the whole migrations file or a standalone single migration. A
18
+ * `--run-id` invocation takes none of them: a recorded run takes its commit
19
+ * config from run.json and is driven by the outer agent.
18
20
  *
19
21
  * `include` is carried as `includeFromConfig` so it is never mistaken for an
20
22
  * explicit `--include`: `resolveInclude` applies it only when the resolved
@@ -28,8 +30,14 @@ function applyNxJsonMigrateDefaults(args, migrateConfig, env = process.env) {
28
30
  // `--run-migrations` with no value is normalized to '' by yargs, so a defined
29
31
  // (even empty-string) value means we're in the run-migrations phase.
30
32
  const isRunMigrations = merged.runMigrations !== undefined;
31
- const isSingleMigration = merged.runMigration !== undefined;
32
- if (isRunMigrations || isSingleMigration) {
33
+ // A bare `--run-id` (orchestrated reconcile) must never take the
34
+ // generate-options overlay, which would leak `include` etc. from nx.json.
35
+ const isSingleMigration = merged.runMigration !== undefined || merged.runId !== undefined;
36
+ // Both overlays are for an invocation that decides these options for
37
+ // itself, which a `--run-id` invocation never does: the recorded worker and
38
+ // the reconcile both read the commit config from run.json, and overlaying
39
+ // `agentic` would trip the `--agentic`/`--run-id` parse conflict.
40
+ if ((isRunMigrations || isSingleMigration) && merged.runId === undefined) {
33
41
  if (merged.createCommits === undefined &&
34
42
  migrateConfig.createCommits !== undefined) {
35
43
  assertType(migrateConfig.createCommits, 'boolean', 'createCommits');
@@ -10,6 +10,7 @@ import type { ResolvedAgentic } from './agentic/types';
10
10
  import { isHybridMigration, isPromptOnlyMigration, type PlannedMigration } from './migration-shape';
11
11
  import { filterDowngradedUpdates } from './update-filters';
12
12
  import { normalizeVersion } from './version-utils';
13
+ import { type StepAction } from './step-actions';
13
14
  export * from './execute-migration';
14
15
  export { normalizeVersion };
15
16
  export interface ResolvedMigrationConfiguration extends MigrationsJson {
@@ -170,11 +171,17 @@ type RunMigrations = {
170
171
  type RunSingleMigration = {
171
172
  type: 'runSingleMigration';
172
173
  runMigration: string;
174
+ runId?: string;
173
175
  agentic: AgenticArg;
174
176
  validate?: boolean;
175
177
  interactive?: boolean;
176
178
  };
177
- export declare function parseMigrationsOptions(options: MigrateArgs, fetch?: MigratorOptions['fetch']): Promise<GenerateMigrations | RunMigrations | RunSingleMigration>;
179
+ type OrchestratorReconcile = {
180
+ type: 'orchestratorReconcile';
181
+ runId: string;
182
+ stepAction?: StepAction;
183
+ };
184
+ export declare function parseMigrationsOptions(options: MigrateArgs, fetch?: MigratorOptions['fetch']): Promise<GenerateMigrations | RunMigrations | RunSingleMigration | OrchestratorReconcile>;
178
185
  export declare function createFetcher(pmc: PackageManagerCommands): ((pkg: string, version: string) => Promise<ResolvedMigrationConfiguration>) & {
179
186
  stats?: MigrateFetchStats;
180
187
  };
@@ -193,7 +200,7 @@ export declare function executeMigrations(root: string, migrations: PlannedMigra
193
200
  waivedAgenticStepsCount: number;
194
201
  retainedAtSuccess: string[];
195
202
  }>;
196
- export declare function isSingleMigrationInvocation(args: Pick<MigrateArgs, 'runMigration'>): boolean;
203
+ export declare function isRunPhaseInvocation(args: Pick<MigrateArgs, 'runMigration' | 'runId' | 'stepAction'>): boolean;
197
204
  export declare function migrate(root: string, args: {
198
205
  [k: string]: any;
199
206
  }, rawArgs: string[]): Promise<number>;