nx 23.2.0-beta.1 → 23.2.0-beta.11

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 (369) hide show
  1. package/README.md +2 -2
  2. package/dist/bin/init-local.js +3 -5
  3. package/dist/bin/nx.js +2 -0
  4. package/dist/release/changelog-renderer/index.js +4 -5
  5. package/dist/release/index.d.ts +1 -1
  6. package/dist/src/adapter/ngcli-adapter.js +60 -1
  7. package/dist/src/ai/set-up-ai-agents/set-up-ai-agents.js +35 -15
  8. package/dist/src/analytics/analytics.d.ts +6 -0
  9. package/dist/src/analytics/analytics.js +16 -10
  10. package/dist/src/analytics/index.d.ts +1 -1
  11. package/dist/src/analytics/index.js +2 -1
  12. package/dist/src/command-line/add/add.js +5 -0
  13. package/dist/src/command-line/affected/affected.js +1 -0
  14. package/dist/src/command-line/completion/command-object.js +7 -12
  15. package/dist/src/command-line/configure-ai-agents/configure-ai-agents.js +19 -25
  16. package/dist/src/command-line/format/format.js +84 -101
  17. package/dist/src/command-line/generate/generate.js +35 -35
  18. package/dist/src/command-line/graph/graph.d.ts +1 -0
  19. package/dist/src/command-line/graph/graph.js +15 -6
  20. package/dist/src/command-line/import/import.js +30 -40
  21. package/dist/src/command-line/init/ai-agent-prompts.js +5 -11
  22. package/dist/src/command-line/init/command-object.js +4 -2
  23. package/dist/src/command-line/init/configure-plugins.js +4 -1
  24. package/dist/src/command-line/init/implementation/add-nx-to-monorepo.js +12 -32
  25. package/dist/src/command-line/init/implementation/add-nx-to-nest.js +17 -21
  26. package/dist/src/command-line/init/implementation/add-nx-to-npm-repo.js +8 -21
  27. package/dist/src/command-line/init/implementation/add-nx-to-turborepo.js +3 -17
  28. package/dist/src/command-line/init/implementation/angular/index.js +10 -15
  29. package/dist/src/command-line/init/implementation/angular/integrated-workspace.js +2 -5
  30. package/dist/src/command-line/init/implementation/angular/legacy-angular-versions.js +5 -0
  31. package/dist/src/command-line/init/implementation/angular/standalone-workspace.js +8 -2
  32. package/dist/src/command-line/init/implementation/check-compatible-with-plugins.js +2 -0
  33. package/dist/src/command-line/init/implementation/dot-nx/add-nx-scripts.js +9 -1
  34. package/dist/src/command-line/init/implementation/format.d.ts +18 -0
  35. package/dist/src/command-line/init/implementation/format.js +114 -0
  36. package/dist/src/command-line/init/implementation/utils.js +8 -0
  37. package/dist/src/command-line/init/init-v1.js +15 -18
  38. package/dist/src/command-line/init/init-v2.js +40 -57
  39. package/dist/src/command-line/migrate/agentic/definitions.js +36 -9
  40. package/dist/src/command-line/migrate/agentic/handoff-gitignore.d.ts +37 -22
  41. package/dist/src/command-line/migrate/agentic/handoff-gitignore.js +30 -39
  42. package/dist/src/command-line/migrate/agentic/handoff.d.ts +7 -7
  43. package/dist/src/command-line/migrate/agentic/handoff.js +13 -10
  44. package/dist/src/command-line/migrate/agentic/print-dropped-agent-context.d.ts +7 -12
  45. package/dist/src/command-line/migrate/agentic/print-dropped-agent-context.js +7 -0
  46. package/dist/src/command-line/migrate/agentic/run-step.d.ts +10 -0
  47. package/dist/src/command-line/migrate/agentic/run-step.js +1 -0
  48. package/dist/src/command-line/migrate/agentic/runner.js +24 -24
  49. package/dist/src/command-line/migrate/agentic/select.d.ts +10 -2
  50. package/dist/src/command-line/migrate/agentic/select.js +30 -32
  51. package/dist/src/command-line/migrate/agentic/types.d.ts +33 -3
  52. package/dist/src/command-line/migrate/agentic/types.js +35 -0
  53. package/dist/src/command-line/migrate/command-object.d.ts +6 -0
  54. package/dist/src/command-line/migrate/command-object.js +19 -1
  55. package/dist/src/command-line/migrate/execute-migration.d.ts +28 -9
  56. package/dist/src/command-line/migrate/execute-migration.js +112 -27
  57. package/dist/src/command-line/migrate/migrate-analytics.d.ts +35 -0
  58. package/dist/src/command-line/migrate/migrate-analytics.js +64 -0
  59. package/dist/src/command-line/migrate/migrate-commits.d.ts +38 -8
  60. package/dist/src/command-line/migrate/migrate-commits.js +130 -15
  61. package/dist/src/command-line/migrate/migrate-config.d.ts +13 -12
  62. package/dist/src/command-line/migrate/migrate-config.js +22 -14
  63. package/dist/src/command-line/migrate/migrate-output.d.ts +45 -7
  64. package/dist/src/command-line/migrate/migrate-output.js +52 -8
  65. package/dist/src/command-line/migrate/migrate-ui-api.d.ts +2 -1
  66. package/dist/src/command-line/migrate/migrate-ui-api.js +16 -7
  67. package/dist/src/command-line/migrate/migrate.d.ts +28 -68
  68. package/dist/src/command-line/migrate/migrate.js +657 -293
  69. package/dist/src/command-line/migrate/migration-shape.d.ts +8 -0
  70. package/dist/src/command-line/migrate/multi-major.js +7 -10
  71. package/dist/src/command-line/migrate/resolve-package-version.js +4 -8
  72. package/dist/src/command-line/migrate/run/agent-output.d.ts +20 -0
  73. package/dist/src/command-line/migrate/run/agent-output.js +65 -0
  74. package/dist/src/command-line/migrate/run/index.d.ts +9 -0
  75. package/dist/src/command-line/migrate/run/index.js +23 -0
  76. package/dist/src/command-line/migrate/run/orchestrator.d.ts +20 -0
  77. package/dist/src/command-line/migrate/run/orchestrator.js +1200 -0
  78. package/dist/src/command-line/migrate/run/run-id.d.ts +16 -0
  79. package/dist/src/command-line/migrate/run/run-id.js +56 -0
  80. package/dist/src/command-line/migrate/run/run-state.d.ts +157 -0
  81. package/dist/src/command-line/migrate/run/run-state.js +438 -0
  82. package/dist/src/command-line/migrate/run/state-lock.d.ts +25 -0
  83. package/dist/src/command-line/migrate/run/state-lock.js +76 -0
  84. package/dist/src/command-line/migrate/run/state-machine.d.ts +84 -0
  85. package/dist/src/command-line/migrate/run/state-machine.js +315 -0
  86. package/dist/src/command-line/migrate/run/util.d.ts +59 -0
  87. package/dist/src/command-line/migrate/run/util.js +148 -0
  88. package/dist/src/command-line/migrate/run/worker.d.ts +16 -0
  89. package/dist/src/command-line/migrate/run/worker.js +682 -0
  90. package/dist/src/command-line/migrate/run-migration-process.js +6 -5
  91. package/dist/src/command-line/migrate/safe-prompt.d.ts +14 -26
  92. package/dist/src/command-line/migrate/safe-prompt.js +32 -43
  93. package/dist/src/command-line/migrate/sort-migrations.d.ts +16 -0
  94. package/dist/src/command-line/migrate/sort-migrations.js +32 -0
  95. package/dist/src/command-line/migrate/step-actions.d.ts +5 -0
  96. package/dist/src/command-line/migrate/step-actions.js +12 -0
  97. package/dist/src/command-line/migrate/text.d.ts +18 -0
  98. package/dist/src/command-line/migrate/text.js +26 -0
  99. package/dist/src/command-line/migrate/version-skew-guard.d.ts +60 -0
  100. package/dist/src/command-line/migrate/version-skew-guard.js +175 -0
  101. package/dist/src/command-line/nx-cloud/connect/connect-to-nx-cloud.js +17 -21
  102. package/dist/src/command-line/nx-cloud/connect/view-logs.js +2 -0
  103. package/dist/src/command-line/nx-cloud/start-nx-agents/command-object.d.ts +2 -0
  104. package/dist/src/command-line/nx-cloud/start-nx-agents/command-object.js +16 -0
  105. package/dist/src/command-line/nx-cloud/start-nx-agents/start-nx-agents.d.ts +4 -0
  106. package/dist/src/command-line/nx-cloud/start-nx-agents/start-nx-agents.js +13 -0
  107. package/dist/src/command-line/nx-commands.js +26 -24
  108. package/dist/src/command-line/release/changelog.js +11 -17
  109. package/dist/src/command-line/release/index.d.ts +1 -1
  110. package/dist/src/command-line/release/plan.js +15 -28
  111. package/dist/src/command-line/release/publish.js +5 -0
  112. package/dist/src/command-line/release/release.js +6 -17
  113. package/dist/src/command-line/release/utils/git.js +1 -1
  114. package/dist/src/command-line/release/utils/release-graph.d.ts +18 -0
  115. package/dist/src/command-line/release/utils/release-graph.js +81 -21
  116. package/dist/src/command-line/release/utils/remote-release-clients/github.js +17 -23
  117. package/dist/src/command-line/release/utils/remote-release-clients/gitlab.js +14 -23
  118. package/dist/src/command-line/release/utils/resolve-semver-specifier.js +19 -41
  119. package/dist/src/command-line/release/version/release-group-processor.d.ts +24 -0
  120. package/dist/src/command-line/release/version/release-group-processor.js +80 -6
  121. package/dist/src/command-line/release/version/resolve-current-version.js +7 -10
  122. package/dist/src/command-line/release/version/version-actions.d.ts +27 -2
  123. package/dist/src/command-line/release/version/version-actions.js +9 -1
  124. package/dist/src/command-line/release/version.js +10 -6
  125. package/dist/src/command-line/reset/reset.js +6 -1
  126. package/dist/src/command-line/run/run-one.js +1 -0
  127. package/dist/src/command-line/run-many/run-many.js +1 -0
  128. package/dist/src/command-line/show/show-target/inputs.js +50 -153
  129. package/dist/src/command-line/show/show-target/outputs.js +48 -173
  130. package/dist/src/command-line/show/show-target/utils.d.ts +28 -0
  131. package/dist/src/command-line/show/show-target/utils.js +83 -3
  132. package/dist/src/command-line/watch/watch.js +13 -0
  133. package/dist/src/command-line/yargs-utils/shared-options.d.ts +2 -2
  134. package/dist/src/command-line/yargs-utils/shared-options.js +3 -1
  135. package/dist/src/config/misc-interfaces.d.ts +19 -7
  136. package/dist/src/config/nx-json.d.ts +4 -2
  137. package/dist/src/core/graph/main.js +1 -1
  138. package/dist/src/core/graph/styles.js +1 -1
  139. package/dist/src/daemon/client/client.d.ts +52 -1
  140. package/dist/src/daemon/client/client.js +160 -36
  141. package/dist/src/daemon/client/daemon-environment.d.ts +17 -0
  142. package/dist/src/daemon/client/daemon-environment.js +110 -2
  143. package/dist/src/daemon/client/daemon-socket-messenger.js +4 -0
  144. package/dist/src/daemon/message-types/daemon-message.d.ts +32 -0
  145. package/dist/src/daemon/message-types/daemon-message.js +25 -0
  146. package/dist/src/daemon/server/file-watching/file-watcher-sockets.d.ts +5 -0
  147. package/dist/src/daemon/server/file-watching/file-watcher-sockets.js +16 -0
  148. package/dist/src/daemon/server/handle-tasks-execution-hooks.d.ts +1 -1
  149. package/dist/src/daemon/server/latest-nx.js +5 -2
  150. package/dist/src/daemon/server/server.js +31 -4
  151. package/dist/src/daemon/server/shutdown-utils.d.ts +5 -0
  152. package/dist/src/daemon/server/shutdown-utils.js +11 -4
  153. package/dist/src/daemon/socket-utils.d.ts +1 -0
  154. package/dist/src/daemon/socket-utils.js +24 -3
  155. package/dist/src/daemon/tmp-dir.d.ts +43 -3
  156. package/dist/src/daemon/tmp-dir.js +437 -15
  157. package/dist/src/devkit-internals.d.ts +106 -8
  158. package/dist/src/devkit-internals.js +225 -7
  159. package/dist/src/executors/run-commands/running-tasks.js +46 -29
  160. package/dist/src/generators/internal-utils/format-changed-files.d.ts +24 -0
  161. package/dist/src/generators/internal-utils/format-changed-files.js +163 -0
  162. package/dist/src/generators/testing-utils/create-tree-with-empty-workspace.d.ts +15 -0
  163. package/dist/src/generators/testing-utils/create-tree-with-empty-workspace.js +21 -3
  164. package/dist/src/generators/tree.d.ts +4 -2
  165. package/dist/src/hasher/check-task-files.d.ts +86 -0
  166. package/dist/src/hasher/check-task-files.js +378 -0
  167. package/dist/src/migrations/update-15-0-0/prefix-outputs.js +2 -2
  168. package/dist/src/migrations/update-16-0-0/remove-nrwl-cli.js +2 -2
  169. package/dist/src/migrations/update-16-0-0/update-depends-on-to-tokens.js +2 -2
  170. package/dist/src/migrations/update-16-0-0/update-nx-cloud-runner.js +2 -2
  171. package/dist/src/migrations/update-16-2-0/remove-run-commands-output-path.js +2 -2
  172. package/dist/src/migrations/update-17-0-0/rm-default-collection-npm-scope.js +2 -2
  173. package/dist/src/migrations/update-17-0-0/use-minimal-config-for-tasks-runner-options.js +2 -2
  174. package/dist/src/migrations/update-17-2-0/move-default-base.js +2 -2
  175. package/dist/src/migrations/update-18-0-0/disable-crystal-for-existing-workspaces.js +2 -2
  176. package/dist/src/migrations/update-19-2-4/set-project-name.js +2 -2
  177. package/dist/src/migrations/update-20-0-0/move-use-daemon-process.js +2 -2
  178. package/dist/src/migrations/update-20-0-1/use-legacy-cache.js +2 -2
  179. package/dist/src/migrations/update-21-0-0/release-changelog-config-changes.js +2 -2
  180. package/dist/src/migrations/update-21-0-0/release-version-config-changes.js +2 -2
  181. package/dist/src/migrations/update-21-0-0/remove-custom-tasks-runner.js +2 -2
  182. package/dist/src/migrations/update-21-0-0/remove-legacy-cache.js +2 -2
  183. package/dist/src/migrations/update-22-0-0/consolidate-release-tag-config.js +2 -2
  184. package/dist/src/migrations/update-22-0-0/release-version-config-changes.js +2 -2
  185. package/dist/src/migrations/update-22-2-0/add-self-healing-to-gitignore.js +2 -2
  186. package/dist/src/migrations/update-22-6-0/add-claude-settings-local-to-git-ignore.js +2 -2
  187. package/dist/src/migrations/update-22-6-0/add-claude-worktrees-to-git-ignore.js +2 -2
  188. package/dist/src/migrations/update-22-7-0/add-polygraph-to-git-ignore.js +2 -2
  189. package/dist/src/migrations/update-23-0-0/add-migrate-runs-to-git-ignore.js +2 -2
  190. package/dist/src/migrations/update-23-2-0/set-cache-on-executor-target-defaults.d.ts +12 -0
  191. package/dist/src/migrations/update-23-2-0/set-cache-on-executor-target-defaults.js +250 -0
  192. package/dist/src/migrations/update-23-2-0/set-cache-on-executor-target-defaults.md +50 -0
  193. package/dist/src/native/index.d.ts +37 -4
  194. package/dist/src/native/index.js +71 -28
  195. package/dist/src/native/native-bindings.js +3 -0
  196. package/dist/src/native/native-file-cache-location.d.ts +17 -1
  197. package/dist/src/native/native-file-cache-location.js +86 -12
  198. package/dist/src/native/nx.wasm32-wasi.debug.wasm +0 -0
  199. package/dist/src/native/nx.wasm32-wasi.wasm +0 -0
  200. package/dist/src/nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud.js +3 -3
  201. package/dist/src/nx-cloud/utilities/get-cloud-options.js +5 -2
  202. package/dist/src/nx-cloud/utilities/onboarding.js +5 -2
  203. package/dist/src/nx-cloud/utilities/url-shorten.d.ts +1 -4
  204. package/dist/src/nx-cloud/utilities/url-shorten.js +9 -8
  205. package/dist/src/plugins/js/lock-file/bun-parser.js +43 -10
  206. package/dist/src/plugins/js/lock-file/lock-file.d.ts +46 -4
  207. package/dist/src/plugins/js/lock-file/lock-file.js +192 -15
  208. package/dist/src/plugins/js/lock-file/pnpm-parser.js +420 -64
  209. package/dist/src/plugins/js/lock-file/project-graph-pruning.d.ts +25 -1
  210. package/dist/src/plugins/js/lock-file/project-graph-pruning.js +92 -12
  211. package/dist/src/plugins/js/lock-file/pruned-output.d.ts +330 -0
  212. package/dist/src/plugins/js/lock-file/pruned-output.js +1441 -0
  213. package/dist/src/plugins/js/lock-file/utils/pnpm-normalizer.d.ts +1 -0
  214. package/dist/src/plugins/js/lock-file/utils/pnpm-normalizer.js +9 -5
  215. package/dist/src/plugins/js/project-graph/affected/npm-packages.js +51 -20
  216. package/dist/src/plugins/js/project-graph/build-dependencies/target-project-locator.js +14 -4
  217. package/dist/src/project-graph/affected/affected-project-graph-models.d.ts +1 -1
  218. package/dist/src/project-graph/affected/affected-project-graph.d.ts +1 -1
  219. package/dist/src/project-graph/affected/affected-project-graph.js +2 -2
  220. package/dist/src/project-graph/affected/locators/project-glob-changes.js +5 -2
  221. package/dist/src/project-graph/build-project-graph.js +7 -1
  222. package/dist/src/project-graph/error-types.d.ts +12 -1
  223. package/dist/src/project-graph/error-types.js +27 -2
  224. package/dist/src/project-graph/plugins/isolation/isolated-plugin.d.ts +1 -0
  225. package/dist/src/project-graph/plugins/isolation/isolated-plugin.js +18 -1
  226. package/dist/src/project-graph/plugins/isolation/messaging.d.ts +16 -3
  227. package/dist/src/project-graph/plugins/isolation/messaging.js +3 -0
  228. package/dist/src/project-graph/plugins/isolation/plugin-worker.js +58 -8
  229. package/dist/src/project-graph/plugins/loaded-nx-plugin.js +1 -0
  230. package/dist/src/project-graph/project-graph.js +23 -0
  231. package/dist/src/project-graph/utils/project-configuration/name-substitution-manager.d.ts +1 -0
  232. package/dist/src/project-graph/utils/project-configuration/name-substitution-manager.js +16 -2
  233. package/dist/src/project-graph/utils/project-configuration/project-nodes-manager.d.ts +12 -8
  234. package/dist/src/project-graph/utils/project-configuration/project-nodes-manager.js +30 -21
  235. package/dist/src/project-graph/utils/project-configuration/source-maps.d.ts +12 -5
  236. package/dist/src/project-graph/utils/project-configuration/source-maps.js +21 -7
  237. package/dist/src/project-graph/utils/project-configuration/target-defaults.d.ts +1 -1
  238. package/dist/src/project-graph/utils/project-configuration/target-defaults.js +26 -27
  239. package/dist/src/project-graph/utils/project-configuration/target-merging.js +50 -8
  240. package/dist/src/project-graph/utils/project-configuration/target-normalization.js +149 -6
  241. package/dist/src/project-graph/utils/project-configuration/utils.d.ts +15 -0
  242. package/dist/src/project-graph/utils/project-configuration/utils.js +42 -6
  243. package/dist/src/project-graph/utils/project-configuration-utils.d.ts +15 -12
  244. package/dist/src/project-graph/utils/project-configuration-utils.js +79 -99
  245. package/dist/src/tasks-runner/is-tui-enabled.js +3 -1
  246. package/dist/src/tasks-runner/life-cycle.d.ts +2 -2
  247. package/dist/src/tasks-runner/life-cycle.js +2 -2
  248. package/dist/src/tasks-runner/life-cycles/performance-report.d.ts +12 -0
  249. package/dist/src/tasks-runner/life-cycles/performance-report.js +62 -3
  250. package/dist/src/tasks-runner/life-cycles/static-run-many-terminal-output-life-cycle.d.ts +26 -1
  251. package/dist/src/tasks-runner/life-cycles/static-run-many-terminal-output-life-cycle.js +99 -5
  252. package/dist/src/tasks-runner/life-cycles/static-run-one-terminal-output-life-cycle.d.ts +26 -0
  253. package/dist/src/tasks-runner/life-cycles/static-run-one-terminal-output-life-cycle.js +113 -17
  254. package/dist/src/tasks-runner/pseudo-terminal.d.ts +17 -3
  255. package/dist/src/tasks-runner/pseudo-terminal.js +22 -10
  256. package/dist/src/tasks-runner/run-command.js +28 -35
  257. package/dist/src/tasks-runner/running-tasks/batch-process.d.ts +55 -0
  258. package/dist/src/tasks-runner/running-tasks/batch-process.js +161 -8
  259. package/dist/src/tasks-runner/task-env.d.ts +9 -0
  260. package/dist/src/tasks-runner/task-env.js +31 -4
  261. package/dist/src/tasks-runner/task-orchestrator.d.ts +72 -1
  262. package/dist/src/tasks-runner/task-orchestrator.js +182 -18
  263. package/dist/src/tasks-runner/utils.js +2 -6
  264. package/dist/src/utils/acknowledge-build-scripts.js +7 -5
  265. package/dist/src/utils/analytics-enabled.d.ts +7 -0
  266. package/dist/src/utils/analytics-enabled.js +11 -0
  267. package/dist/src/utils/analytics-prompt.d.ts +0 -6
  268. package/dist/src/utils/analytics-prompt.js +4 -58
  269. package/dist/src/utils/assert-workspace-validity.js +7 -2
  270. package/dist/src/utils/catalog/bun-manager-utils.d.ts +8 -0
  271. package/dist/src/utils/catalog/bun-manager-utils.js +174 -0
  272. package/dist/src/utils/catalog/bun-manager.d.ts +28 -0
  273. package/dist/src/utils/catalog/bun-manager.js +130 -0
  274. package/dist/src/utils/catalog/index.d.ts +1 -1
  275. package/dist/src/utils/catalog/index.js +1 -1
  276. package/dist/src/utils/catalog/manager-factory.js +3 -0
  277. package/dist/src/utils/catalog/manager-utils.d.ts +8 -1
  278. package/dist/src/utils/catalog/manager-utils.js +9 -4
  279. package/dist/src/utils/catalog/manager.d.ts +13 -1
  280. package/dist/src/utils/catalog/manager.js +30 -0
  281. package/dist/src/utils/catalog/pnpm-manager.d.ts +2 -1
  282. package/dist/src/utils/catalog/pnpm-manager.js +3 -0
  283. package/dist/src/utils/catalog/types.d.ts +4 -0
  284. package/dist/src/utils/catalog/yarn-manager.d.ts +6 -2
  285. package/dist/src/utils/catalog/yarn-manager.js +23 -32
  286. package/dist/src/utils/child-process.d.ts +31 -1
  287. package/dist/src/utils/child-process.js +103 -0
  288. package/dist/src/utils/chunkify.d.ts +7 -1
  289. package/dist/src/utils/chunkify.js +10 -3
  290. package/dist/src/utils/exit-codes.d.ts +9 -0
  291. package/dist/src/utils/exit-codes.js +19 -0
  292. package/dist/src/utils/fileutils.d.ts +5 -0
  293. package/dist/src/utils/fileutils.js +7 -2
  294. package/dist/src/utils/formatters/index.d.ts +13 -0
  295. package/dist/src/utils/formatters/index.js +74 -0
  296. package/dist/src/utils/formatters/oxfmt.d.ts +32 -0
  297. package/dist/src/utils/formatters/oxfmt.js +764 -0
  298. package/dist/src/utils/formatters/prettier.d.ts +26 -0
  299. package/dist/src/utils/formatters/prettier.js +201 -0
  300. package/dist/src/utils/formatters/shared.d.ts +5 -0
  301. package/dist/src/utils/formatters/shared.js +8 -0
  302. package/dist/src/utils/git-utils.d.ts +48 -2
  303. package/dist/src/utils/git-utils.js +220 -14
  304. package/dist/src/utils/git-worktrees.d.ts +30 -0
  305. package/dist/src/utils/git-worktrees.js +212 -0
  306. package/dist/src/utils/has-nx-js-plugin.d.ts +1 -1
  307. package/dist/src/utils/has-nx-js-plugin.js +1 -1
  308. package/dist/src/utils/ignore.d.ts +170 -1
  309. package/dist/src/utils/ignore.js +263 -11
  310. package/dist/src/utils/kill-child-on-host-exit.d.ts +7 -0
  311. package/dist/src/utils/kill-child-on-host-exit.js +42 -0
  312. package/dist/src/utils/long-running-target.d.ts +10 -0
  313. package/dist/src/utils/long-running-target.js +19 -0
  314. package/dist/src/utils/min-release-age/behavior/bun.js +7 -11
  315. package/dist/src/utils/min-release-age/behavior/npm.js +5 -2
  316. package/dist/src/utils/min-release-age/packument.js +1 -1
  317. package/dist/src/utils/nx-console-prompt.js +3 -6
  318. package/dist/src/utils/nx-tmp-dir.d.ts +18 -0
  319. package/dist/src/utils/nx-tmp-dir.js +40 -0
  320. package/dist/src/utils/output.d.ts +153 -0
  321. package/dist/src/utils/output.js +289 -5
  322. package/dist/src/utils/owned-private-dir.d.ts +132 -0
  323. package/dist/src/utils/owned-private-dir.js +323 -0
  324. package/dist/src/utils/package-json.d.ts +2 -0
  325. package/dist/src/utils/package-json.js +11 -7
  326. package/dist/src/utils/package-manager-config/bunfig.d.ts +14 -0
  327. package/dist/src/utils/package-manager-config/bunfig.js +49 -0
  328. package/dist/src/utils/package-manager-config/npmrc.d.ts +23 -0
  329. package/dist/src/utils/package-manager-config/npmrc.js +124 -0
  330. package/dist/src/utils/package-manager-config/pnpm-config.d.ts +17 -0
  331. package/dist/src/utils/package-manager-config/pnpm-config.js +60 -0
  332. package/dist/src/utils/package-manager.d.ts +23 -2
  333. package/dist/src/utils/package-manager.js +262 -42
  334. package/dist/src/utils/params.d.ts +7 -1
  335. package/dist/src/utils/params.js +64 -6
  336. package/dist/src/utils/plugins/core-plugins.js +4 -0
  337. package/dist/src/utils/prompt-helpers.d.ts +53 -0
  338. package/dist/src/utils/prompt-helpers.js +111 -0
  339. package/dist/src/utils/provenance.js +6 -14
  340. package/dist/src/utils/registry-config/bun.d.ts +2 -0
  341. package/dist/src/utils/registry-config/bun.js +257 -0
  342. package/dist/src/utils/registry-config/index.d.ts +13 -0
  343. package/dist/src/utils/registry-config/index.js +102 -0
  344. package/dist/src/utils/registry-config/pnpm.d.ts +2 -0
  345. package/dist/src/utils/registry-config/pnpm.js +1551 -0
  346. package/dist/src/utils/registry-config/utils.d.ts +195 -0
  347. package/dist/src/utils/registry-config/utils.js +496 -0
  348. package/dist/src/utils/registry-config/yarn-berry.d.ts +2 -0
  349. package/dist/src/utils/registry-config/yarn-berry.js +612 -0
  350. package/dist/src/utils/registry-config/yarn-classic.d.ts +2 -0
  351. package/dist/src/utils/registry-config/yarn-classic.js +1001 -0
  352. package/dist/src/utils/safe-spawn.d.ts +24 -0
  353. package/dist/src/utils/safe-spawn.js +104 -0
  354. package/dist/src/utils/shell-quoting.d.ts +15 -0
  355. package/dist/src/utils/shell-quoting.js +35 -0
  356. package/dist/src/utils/wait-for-socket-connection.d.ts +11 -0
  357. package/dist/src/utils/wait-for-socket-connection.js +14 -8
  358. package/dist/src/utils/workspace-id.d.ts +20 -0
  359. package/dist/src/utils/workspace-id.js +54 -0
  360. package/dist/src/utils/write-formatted-json-file.d.ts +3 -2
  361. package/dist/src/utils/write-formatted-json-file.js +5 -4
  362. package/migrations.json +6 -0
  363. package/package.json +29 -19
  364. package/dist/src/generators/internal-utils/format-changed-files-with-prettier-if-available.d.ts +0 -19
  365. package/dist/src/generators/internal-utils/format-changed-files-with-prettier-if-available.js +0 -81
  366. package/dist/src/utils/is-using-prettier.d.ts +0 -3
  367. package/dist/src/utils/is-using-prettier.js +0 -62
  368. package/dist/src/utils/min-release-age/npmrc.d.ts +0 -15
  369. package/dist/src/utils/min-release-age/npmrc.js +0 -45
@@ -7,16 +7,13 @@ exports.resolveInclude = resolveInclude;
7
7
  exports.parseMigrationsOptions = parseMigrationsOptions;
8
8
  exports.createFetcher = createFetcher;
9
9
  exports.generateMigrationsJsonAndUpdatePackageJson = generateMigrationsJsonAndUpdatePackageJson;
10
- exports.resolveAgenticRunId = resolveAgenticRunId;
11
10
  exports.formatSkippedPromptsNextStep = formatSkippedPromptsNextStep;
12
- exports.resolveCreateCommits = resolveCreateCommits;
13
- exports.confirmCommitsOnDefaultBranch = confirmCommitsOnDefaultBranch;
14
- exports.resolveShouldRunValidation = resolveShouldRunValidation;
15
11
  exports.executeMigrations = executeMigrations;
12
+ exports.isRunPhaseInvocation = isRunPhaseInvocation;
16
13
  exports.migrate = migrate;
14
+ exports.readLocalNxVersion = readLocalNxVersion;
17
15
  exports.runMigration = runMigration;
18
16
  exports.resolveMigrationForRun = resolveMigrationForRun;
19
- exports.resolveDocumentationFileToWorkspacePath = resolveDocumentationFileToWorkspacePath;
20
17
  exports.nxCliPath = nxCliPath;
21
18
  const tslib_1 = require("tslib");
22
19
  const pc = tslib_1.__importStar(require("picocolors"));
@@ -31,9 +28,9 @@ const util_1 = require("util");
31
28
  const fileutils_1 = require("../../utils/fileutils");
32
29
  const tar_1 = require("../../utils/tar");
33
30
  const write_formatted_json_file_1 = require("../../utils/write-formatted-json-file");
31
+ const shell_quoting_1 = require("../../utils/shell-quoting");
34
32
  const logger_1 = require("../../utils/logger");
35
33
  const git_utils_1 = require("../../utils/git-utils");
36
- const command_line_utils_1 = require("../../utils/command-line-utils");
37
34
  const package_json_1 = require("../../utils/package-json");
38
35
  const package_manager_1 = require("../../utils/package-manager");
39
36
  const errors_1 = require("../../utils/min-release-age/errors");
@@ -50,7 +47,7 @@ const configuration_1 = require("../../config/configuration");
50
47
  const child_process_2 = require("../../utils/child-process");
51
48
  const client_1 = require("../../daemon/client/client");
52
49
  const nx_cloud_utils_1 = require("../../utils/nx-cloud-utils");
53
- const format_changed_files_with_prettier_if_available_1 = require("../../generators/internal-utils/format-changed-files-with-prettier-if-available");
50
+ const format_changed_files_1 = require("../../generators/internal-utils/format-changed-files");
54
51
  const provenance_1 = require("../../utils/provenance");
55
52
  const catalog_1 = require("../../utils/catalog");
56
53
  const migrate_analytics_1 = require("./migrate-analytics");
@@ -58,7 +55,6 @@ const multi_major_1 = require("./multi-major");
58
55
  const prompt_files_1 = require("./prompt-files");
59
56
  const command_object_1 = require("./command-object");
60
57
  const migrate_config_1 = require("./migrate-config");
61
- const handoff_gitignore_1 = require("./agentic/handoff-gitignore");
62
58
  const migrate_commits_1 = require("./migrate-commits");
63
59
  const migrate_output_1 = require("./migrate-output");
64
60
  const migration_shape_1 = require("./migration-shape");
@@ -69,6 +65,11 @@ Object.defineProperty(exports, "filterDowngradedUpdates", { enumerable: true, ge
69
65
  const version_utils_1 = require("./version-utils");
70
66
  Object.defineProperty(exports, "normalizeVersion", { enumerable: true, get: function () { return version_utils_1.normalizeVersion; } });
71
67
  const execute_migration_1 = require("./execute-migration");
68
+ const step_actions_1 = require("./step-actions");
69
+ const sort_migrations_1 = require("./sort-migrations");
70
+ const inception_1 = require("./agentic/inception");
71
+ const version_skew_guard_1 = require("./version-skew-guard");
72
+ const versions_1 = require("../../utils/versions");
72
73
  tslib_1.__exportStar(require("./execute-migration"), exports);
73
74
  const execAsync = (0, util_1.promisify)(child_process_1.exec);
74
75
  function formatCommandFailure(command, error) {
@@ -112,6 +113,8 @@ class Migrator {
112
113
  this.packageUpdates = {};
113
114
  this.collectedVersions = {};
114
115
  this.promptAnswers = {};
116
+ this.pendingPackageJsonUpdates = new Map();
117
+ this.appliedPackageJsonUpdates = new Set();
115
118
  if ((opts.include === 'required' || opts.include === 'optional') &&
116
119
  !opts.requiredPackages) {
117
120
  throw new Error(`Error: 'requiredPackages' is required when 'include' is '${opts.include}'.`);
@@ -139,6 +142,7 @@ class Migrator {
139
142
  version: targetVersion,
140
143
  addToPackageJson: false,
141
144
  });
145
+ await this.applyPendingPackageJsonUpdates();
142
146
  this.applyIncludeFilter();
143
147
  const { migrations, promptContents } = await this.createMigrateJson();
144
148
  return {
@@ -184,29 +188,66 @@ class Migrator {
184
188
  for (const packageToCheck of packagesToCheck) {
185
189
  const filteredUpdates = {};
186
190
  for (const [packageUpdateKey, packageUpdate] of Object.entries(packageToCheck.updates)) {
187
- if (this.areRequirementsMet(packageUpdate.requires) &&
188
- !this.areIncompatiblePackagesPresent(packageUpdate.incompatibleWith) &&
189
- (!this.interactive ||
190
- (await this.runPackageJsonUpdatesConfirmationPrompt(packageUpdate, packageUpdateKey, packageToCheck.package)))) {
191
- const updateEntries = Object.entries(packageUpdate.packages);
192
- // Validate all up front so invalid metadata fails fast, before any
193
- // resolution does I/O.
194
- for (const [name, update] of updateEntries) {
195
- this.validatePackageUpdateVersion(packageToCheck.package, name, update);
196
- }
197
- // Resolve serially: resolution can prompt (pnpm strict cooldown) and
198
- // append to minimumReleaseAgeExclude, so a serial loop avoids
199
- // overlapping prompts and keeps packageUpdates ordering stable.
200
- for (const [name, update] of updateEntries) {
201
- const resolvedUpdate = {
202
- ...update,
203
- version: await this.resolveVersionForCascade(name, update.version),
204
- };
205
- filteredUpdates[name] = resolvedUpdate;
206
- this.packageUpdates[name] = resolvedUpdate;
207
- }
191
+ Object.assign(filteredUpdates, await this.applyPackageJsonUpdate(packageToCheck.package, packageUpdateKey, packageUpdate));
192
+ }
193
+ await Promise.all(Object.entries(filteredUpdates).map(([name, update]) => this.buildPackageJsonUpdates(name, update)));
194
+ }
195
+ }
196
+ async applyPackageJsonUpdate(sourcePackage, packageUpdateKey, packageUpdate) {
197
+ const appliedKey = JSON.stringify([sourcePackage, packageUpdateKey]);
198
+ if (this.appliedPackageJsonUpdates.has(appliedKey)) {
199
+ this.pendingPackageJsonUpdates.delete(appliedKey);
200
+ return {};
201
+ }
202
+ if (!this.areRequirementsMet(packageUpdate.requires) ||
203
+ this.areIncompatiblePackagesPresent(packageUpdate.incompatibleWith)) {
204
+ this.pendingPackageJsonUpdates.set(appliedKey, {
205
+ package: sourcePackage,
206
+ key: packageUpdateKey,
207
+ update: packageUpdate,
208
+ });
209
+ return {};
210
+ }
211
+ this.pendingPackageJsonUpdates.delete(appliedKey);
212
+ if (this.interactive &&
213
+ !(await this.runPackageJsonUpdatesConfirmationPrompt(packageUpdate, packageUpdateKey, sourcePackage))) {
214
+ return {};
215
+ }
216
+ this.appliedPackageJsonUpdates.add(appliedKey);
217
+ const updateEntries = Object.entries(packageUpdate.packages);
218
+ // Validate all up front so invalid metadata fails fast, before any
219
+ // resolution does I/O.
220
+ for (const [name, update] of updateEntries) {
221
+ this.validatePackageUpdateVersion(sourcePackage, name, update);
222
+ }
223
+ const filteredUpdates = {};
224
+ // Resolve serially: resolution can prompt (pnpm strict cooldown) and append
225
+ // to minimumReleaseAgeExclude, so a serial loop avoids overlapping prompts
226
+ // and keeps packageUpdates ordering stable.
227
+ for (const [name, update] of updateEntries) {
228
+ const resolvedUpdate = {
229
+ ...update,
230
+ version: await this.resolveVersionForCascade(name, update.version),
231
+ };
232
+ this.addPackageUpdate(name, resolvedUpdate);
233
+ filteredUpdates[name] = this.packageUpdates[name];
234
+ }
235
+ return filteredUpdates;
236
+ }
237
+ async applyPendingPackageJsonUpdates() {
238
+ while (this.pendingPackageJsonUpdates.size) {
239
+ let applied = false;
240
+ const filteredUpdates = {};
241
+ for (const pending of [...this.pendingPackageJsonUpdates.values()]) {
242
+ const updates = await this.applyPackageJsonUpdate(pending.package, pending.key, pending.update);
243
+ if (Object.keys(updates).length) {
244
+ applied = true;
245
+ Object.assign(filteredUpdates, updates);
208
246
  }
209
247
  }
248
+ if (!applied) {
249
+ return;
250
+ }
210
251
  await Promise.all(Object.entries(filteredUpdates).map(([name, update]) => this.buildPackageJsonUpdates(name, update)));
211
252
  }
212
253
  }
@@ -410,7 +451,7 @@ class Migrator {
410
451
  }
411
452
  addPackageUpdate(name, packageUpdate) {
412
453
  if (!this.packageUpdates[name] ||
413
- this.gt(packageUpdate.version, this.packageUpdates[name].version)) {
454
+ !this.lt(packageUpdate.version, this.packageUpdates[name].version)) {
414
455
  this.packageUpdates[name] = packageUpdate;
415
456
  }
416
457
  }
@@ -476,17 +517,14 @@ class Migrator {
476
517
  // a same prompt was already answered, skip
477
518
  return Promise.resolve(false);
478
519
  }
479
- const promptConfig = {
480
- name: 'shouldApply',
481
- type: 'confirm',
482
- message: packageUpdate['x-prompt'],
520
+ // No footer slot, so the docs link is appended to the message.
521
+ const detailsLink = packageName.startsWith('@nx/')
522
+ ? pc.dim(`\n View migration details at https://nx.dev/nx-api/${packageName.replace('@nx/', '')}#${packageUpdateKey.replace(/[-\.]/g, '')}packageupdates`)
523
+ : '';
524
+ return await (0, safe_prompt_1.migrateConfirm)({
525
+ message: `${packageUpdate['x-prompt']}${detailsLink}`,
483
526
  initial: true,
484
- };
485
- if (packageName.startsWith('@nx/')) {
486
- // @ts-expect-error -- enquirer types aren't correct, footer does exist
487
- promptConfig.footer = () => pc.dim(` View migration details at https://nx.dev/nx-api/${packageName.replace('@nx/', '')}#${packageUpdateKey.replace(/[-\.]/g, '')}packageupdates`);
488
- }
489
- return await (0, safe_prompt_1.migratePrompt)([promptConfig]).then(({ shouldApply }) => {
527
+ }).then((shouldApply) => {
490
528
  this.promptAnswers[promptKey] = shouldApply;
491
529
  if (!shouldApply &&
492
530
  (!this.minVersionWithSkippedUpdates ||
@@ -587,8 +625,8 @@ async function resolveInclude(include, context, configuredInclude) {
587
625
  }
588
626
  const choices = [
589
627
  {
590
- name: 'required',
591
- message: 'Required only (the target package and the packages it ships with)',
628
+ value: 'required',
629
+ label: 'Required only (the target package and the packages it ships with)',
592
630
  },
593
631
  ];
594
632
  // `--interactive` keeps the legacy x-prompt flow, which the `optional` value
@@ -597,8 +635,8 @@ async function resolveInclude(include, context, configuredInclude) {
597
635
  !context.hasExcludeAppliedMigrations &&
598
636
  context.interactive !== true) {
599
637
  choices.push({
600
- name: 'optional',
601
- message: 'Optional only (the dependency updates those packages recommend)',
638
+ value: 'optional',
639
+ label: 'Optional only (the dependency updates those packages recommend)',
602
640
  });
603
641
  }
604
642
  if (!(0, safe_prompt_1.canPrompt)(context.interactive)) {
@@ -606,12 +644,10 @@ async function resolveInclude(include, context, configuredInclude) {
606
644
  return 'all';
607
645
  }
608
646
  choices.push({
609
- name: 'all',
610
- message: 'All (required and optional)',
647
+ value: 'all',
648
+ label: 'All (required and optional)',
611
649
  });
612
- const { include: selected } = await (0, safe_prompt_1.migratePrompt)({
613
- type: 'select',
614
- name: 'include',
650
+ const selected = await (0, safe_prompt_1.migrateChoice)({
615
651
  message: 'Which packages would you like to migrate?',
616
652
  choices,
617
653
  });
@@ -671,6 +707,75 @@ async function parseTargetPackageAndVersion(args) {
671
707
  return { targetPackage: args, targetVersion: 'latest' };
672
708
  }
673
709
  async function parseMigrationsOptions(options, fetch) {
710
+ // A run recorded or reconciled via `--run-id` is driven by the outer agent;
711
+ // spawning another agent from it would double-drive the run. Only the
712
+ // explicit "on" values conflict; the nx.json default is ignored for
713
+ // `--run-id` invocations instead.
714
+ if (options.runId !== undefined &&
715
+ options.agentic !== undefined &&
716
+ options.agentic !== false) {
717
+ throw new Error(`Error: '--agentic' cannot be combined with '--run-id'.`);
718
+ }
719
+ if (options.runMigration !== undefined) {
720
+ if (options.runMigration === '') {
721
+ throw new Error(`Error: '--run-migration' requires a migration id, e.g. '--run-migration=@nx/js:my-migration'.`);
722
+ }
723
+ if (options.runId === '') {
724
+ throw new Error(`Error: '--run-id' requires the id of the migrate run to record into.`);
725
+ }
726
+ if (options.stepAction !== undefined) {
727
+ throw new Error(`Error: '--step-action' cannot be combined with '--run-migration'. It applies to an orchestrated reconcile ('--run-id' without '--run-migration').`);
728
+ }
729
+ if (options.runMigrations !== undefined) {
730
+ throw new Error(`Error: '--run-migration' (run a single migration) cannot be combined with '--run-migrations' (run the whole migrations file).`);
731
+ }
732
+ if (options.include) {
733
+ throw new Error(`Error: '--run-migration' cannot be combined with '--include'.`);
734
+ }
735
+ if (options.multiMajorMode) {
736
+ throw new Error(`Error: '--run-migration' cannot be combined with '--multi-major-mode'.`);
737
+ }
738
+ // `--if-exists` only applies to a whole-file run, so an explicit "on"
739
+ // conflicts. Its yargs default (false) is always present and is tolerated.
740
+ if (options.ifExists === true) {
741
+ throw new Error(`Error: '--run-migration' cannot be combined with '--if-exists'.`);
742
+ }
743
+ return {
744
+ type: 'runSingleMigration',
745
+ runMigration: options.runMigration,
746
+ runId: options.runId,
747
+ agentic: options.agentic,
748
+ validate: options.validate,
749
+ interactive: options.interactive,
750
+ };
751
+ }
752
+ if (options.runId !== undefined) {
753
+ // Empty '--run-id' is an error on every path.
754
+ if (options.runId === '') {
755
+ throw new Error(`Error: '--run-id' requires the id of the migrate run to record into.`);
756
+ }
757
+ if (options.runMigrations !== undefined) {
758
+ throw new Error(`Error: '--run-id' (reconcile an orchestrated run) cannot be combined with '--run-migrations' (run the whole migrations file).`);
759
+ }
760
+ // A bare '--run-id' reconciles the run it names. Ungated, unlike init:
761
+ // the id has to name a run directory that exists, and only a gated init
762
+ // ever creates one.
763
+ // yargs' choices already reject bad CLI values; this guards programmatic
764
+ // callers, where silently dropping the action would reconcile without it.
765
+ if (options.stepAction !== undefined && !(0, step_actions_1.isStepAction)(options.stepAction)) {
766
+ throw new Error(`Error: '--step-action' must be one of ${step_actions_1.STEP_ACTIONS.join(', ')}.`);
767
+ }
768
+ return {
769
+ type: 'orchestratorReconcile',
770
+ runId: options.runId,
771
+ ...(options.stepAction !== undefined
772
+ ? { stepAction: options.stepAction }
773
+ : {}),
774
+ };
775
+ }
776
+ if (options.stepAction !== undefined) {
777
+ throw new Error(`Error: '--step-action' requires '--run-id'.`);
778
+ }
674
779
  if (options.runMigrations === '') {
675
780
  options.runMigrations = 'migrations.json';
676
781
  }
@@ -1047,6 +1152,15 @@ function createFetcher(pmc) {
1047
1152
  migrationsCache[packageName + '-' + packageVersion] = migrations;
1048
1153
  }
1049
1154
  migrations = fetchMigrations(packageName, packageVersion, setCache).then((result) => {
1155
+ // An exact requested version must come back verbatim; a mismatch means
1156
+ // a config surface (registry proxy, override, cooldown gate) silently
1157
+ // substituted another version, which would corrupt the whole plan.
1158
+ if ((0, semver_1.valid)(packageVersion) &&
1159
+ result.version &&
1160
+ result.version !== packageVersion) {
1161
+ throw new Error(`Fetching ${packageName}@${packageVersion} resolved to version ${result.version}. ` +
1162
+ `Check for registry, override, or minimum-release-age configuration that hides the requested version.`);
1163
+ }
1050
1164
  if (result.schematics) {
1051
1165
  result.generators = { ...result.schematics, ...result.generators };
1052
1166
  delete result.schematics;
@@ -1086,8 +1200,30 @@ async function getPackageMigrationsUsingRegistry(packageName, packageVersion) {
1086
1200
  // try to obtain the migrations from the registry directly
1087
1201
  return await downloadPackageMigrationsFromRegistry(packageName, packageVersion, migrationsConfig);
1088
1202
  }
1203
+ // Matched exactly: a hostname that merely contains one of these is a different
1204
+ // registry. registry.yarnpkg.com is npmjs' CNAME, so it serves the same
1205
+ // metadata; the two loopback literals are the spellings of a local registry
1206
+ // that the substring below cannot reach, since neither contains "localhost".
1207
+ const FULL_METADATA_REGISTRIES = [
1208
+ 'registry.npmjs.org',
1209
+ 'registry.yarnpkg.com',
1210
+ '127.0.0.1',
1211
+ '[::1]',
1212
+ ];
1213
+ // Matched as substrings, since neither names a single host: a local registry
1214
+ // can sit on a subdomain of localhost, and an Artifactory instance is
1215
+ // identified only by that word appearing somewhere in its hostname.
1216
+ const FULL_METADATA_REGISTRY_MARKERS = [
1217
+ 'localhost',
1218
+ 'artifactory',
1219
+ ];
1089
1220
  async function getPackageMigrationsConfigFromRegistry(packageName, packageVersion) {
1090
- const result = await (0, package_manager_1.packageRegistryView)(packageName, packageVersion, 'nx-migrations ng-update dist --json');
1221
+ const result = await (0, package_manager_1.packageRegistryView)(packageName, packageVersion, [
1222
+ 'nx-migrations',
1223
+ 'ng-update',
1224
+ 'dist',
1225
+ '--json',
1226
+ ]);
1091
1227
  if (!result) {
1092
1228
  return null;
1093
1229
  }
@@ -1095,9 +1231,10 @@ async function getPackageMigrationsConfigFromRegistry(packageName, packageVersio
1095
1231
  if (!json['nx-migrations'] && !json['ng-update']) {
1096
1232
  const registry = new node_url_1.URL('dist' in json ? json.dist.tarball : json.tarball)
1097
1233
  .hostname;
1098
- // Registries other than npmjs and the local registry may not support full metadata via npm view
1099
- // so throw error so that fetcher falls back to getting config via install
1100
- if (!['registry.npmjs.org', 'localhost', 'artifactory'].some((v) => registry.includes(v))) {
1234
+ // Other registries may not support full metadata via npm view; throw to
1235
+ // trigger the install fallback.
1236
+ if (!FULL_METADATA_REGISTRIES.includes(registry) &&
1237
+ !FULL_METADATA_REGISTRY_MARKERS.some((v) => registry.includes(v))) {
1101
1238
  throw new Error(`Getting migration config from registry is not supported from ${registry}`);
1102
1239
  }
1103
1240
  }
@@ -1107,7 +1244,13 @@ async function downloadPackageMigrationsFromRegistry(packageName, packageVersion
1107
1244
  const { dir, cleanup } = (0, package_manager_1.createTempNpmDirectory)();
1108
1245
  let result;
1109
1246
  try {
1110
- const { tarballPath } = await (0, package_manager_1.packageRegistryPack)(dir, packageName, packageVersion);
1247
+ const { tarballPath } = await (0, package_manager_1.packageRegistryPack)(dir, packageName, packageVersion,
1248
+ // packageVersion is exact and already resolved through the workspace
1249
+ // package manager's min-release-age policy by the fetcher. In an npm
1250
+ // workspace the pack gate IS that policy, so leave it enforcing; for
1251
+ // other package managers npm's gate is foreign config with no
1252
+ // exclusions and would wrongly re-judge the vetted version.
1253
+ { bypassMinReleaseAge: (0, package_manager_1.detectPackageManager)() !== 'npm' });
1111
1254
  const fullTarballPath = (0, path_1.join)(dir, tarballPath);
1112
1255
  let migrations;
1113
1256
  try {
@@ -1284,7 +1427,7 @@ async function formatCatalogDefinitionFiles(manager, root) {
1284
1427
  content: (0, fs_1.readFileSync)(absolutePath, 'utf-8'),
1285
1428
  };
1286
1429
  });
1287
- const results = await (0, format_changed_files_with_prettier_if_available_1.formatFilesWithPrettierIfAvailable)(catalogDefinitionFiles.map(({ path, content }) => ({ path, content })), root, { silent: true });
1430
+ const results = await (0, format_changed_files_1.formatFileContents)(catalogDefinitionFiles.map(({ path, content }) => ({ path, content })), root, { silent: true });
1288
1431
  for (const { path, absolutePath, content } of catalogDefinitionFiles) {
1289
1432
  (0, fs_1.writeFileSync)(absolutePath, results.has(path) ? results.get(path) : content, { encoding: 'utf-8' });
1290
1433
  }
@@ -1578,136 +1721,22 @@ function showConnectToCloudMessage() {
1578
1721
  return false;
1579
1722
  }
1580
1723
  }
1581
- function resolveAgenticRunId(migrations) {
1582
- return (0, semver_1.rsort)(migrations.map((m) => (0, version_utils_1.normalizeVersion)(m.version)))[0];
1583
- }
1584
1724
  function formatSkippedPromptsNextStep(skipped) {
1585
1725
  return [
1586
1726
  'Some prompt migrations were skipped. Review and apply each of the following prompt files to the workspace, in the listed order:',
1587
1727
  ...skipped.map((m) => ` - ${m.prompt}`),
1588
1728
  ].join('\n');
1589
1729
  }
1590
- /**
1591
- * Resolves the effective `--create-commits` state once the agentic flow has
1592
- * been resolved. The agent's outer prompt only embeds the impl-phase file list
1593
- * when per-migration commits isolate each migration's diff, so the diff-context
1594
- * flag returned here gates that section.
1595
- */
1596
- function resolveCreateCommits(args) {
1597
- const { createCommits, agenticKind, isGitRepo, commitPrefixIsCustom } = args;
1598
- // Explicit `--create-commits` without git is a hard error — the user asked
1599
- // for something we cannot deliver.
1600
- if (createCommits === true && !isGitRepo) {
1601
- return {
1602
- effective: false,
1603
- agenticHasDiffContext: false,
1604
- error: '`--create-commits` requires a git repository. Run `git init` first, or omit the flag.',
1605
- };
1606
- }
1607
- if (agenticKind === 'enabled') {
1608
- if (createCommits === false) {
1609
- return {
1610
- effective: false,
1611
- agenticHasDiffContext: false,
1612
- 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." +
1613
- (commitPrefixIsCustom
1614
- ? ' Note: the custom --commit-prefix value will have no effect because commits are disabled.'
1615
- : ''),
1616
- };
1617
- }
1618
- // Without git we cannot soft-force commits the user didn't explicitly
1619
- // opt into. Degrade rather than error: continue the agentic run, but
1620
- // without per-file diff context (which depends on per-migration commits).
1621
- if (!isGitRepo) {
1622
- return {
1623
- effective: false,
1624
- agenticHasDiffContext: false,
1625
- warning: '`--agentic` enables per-migration commits by default, but the workspace is not a git repository. Continuing without commits — the agent will not receive per-file diff context. Run `git init` to enable.' +
1626
- (commitPrefixIsCustom
1627
- ? ' The custom --commit-prefix value will have no effect.'
1628
- : ''),
1629
- };
1630
- }
1631
- return { effective: true, agenticHasDiffContext: true };
1632
- }
1633
- // Commits aren't enabled here. A custom prefix only reaches this path via
1634
- // nx.json (e.g. `migrate.commitPrefix` + `migrate.agentic` when the agentic
1635
- // flow resolves to disabled); surface that it has no effect rather than
1636
- // dropping it silently.
1637
- return {
1638
- effective: createCommits === true,
1639
- agenticHasDiffContext: false,
1640
- warning: commitPrefixIsCustom && createCommits !== true
1641
- ? 'A custom migrate commit prefix is configured, but commits are not enabled for this run, so it has no effect. Set `migrate.createCommits` to `true` (or pass `--create-commits`) to create a commit per migration.'
1642
- : undefined,
1643
- };
1644
- }
1645
- /**
1646
- * Confirms before creating per-migration commits while the user sits on the
1647
- * repository's default branch, so migrations don't silently commit there (most
1648
- * relevant since `--agentic` enables commits by default). Only the default
1649
- * branch triggers a prompt; a detached HEAD, a different branch, or an
1650
- * unresolved default branch all proceed untouched. Callers gate this on
1651
- * commits being effective and prompting being possible, so non-interactive
1652
- * runs (CI, `--no-interactive`) never reach here.
1653
- */
1654
- async function confirmCommitsOnDefaultBranch(args) {
1655
- const { currentBranch, defaultBranch } = args;
1656
- if (!currentBranch || !defaultBranch || currentBranch !== defaultBranch) {
1657
- return true;
1658
- }
1659
- const { proceed } = await (0, safe_prompt_1.migratePrompt)([
1660
- {
1661
- name: 'proceed',
1662
- type: 'confirm',
1663
- message: `You're on the default branch '${currentBranch}'. nx migrate will create a commit for each migration on this branch. Continue?`,
1664
- initial: false,
1665
- },
1666
- ]);
1667
- return proceed;
1668
- }
1669
- /**
1670
- * Resolves whether the framework-owned generic-validation agent step should run
1671
- * after generator-only migrations.
1672
- *
1673
- * Default-on when the agentic flow resolved to `enabled`; silently ignored
1674
- * otherwise (no warning emitted) — `--validate` requires an active agent
1675
- * session by definition. An explicit `--no-validate` (`validate === false`)
1676
- * opts out even when agentic is enabled.
1677
- */
1678
- function resolveShouldRunValidation(args) {
1679
- return args.validate !== false && args.agenticKind === 'enabled';
1680
- }
1681
1730
  async function executeMigrations(root, migrations, isVerbose, shouldCreateCommits, commitPrefix, shouldSkipInstall = false, agentic, agenticHasDiffContext = false, shouldRunValidation = false) {
1682
1731
  const changedDepInstaller = new execute_migration_1.ChangedDepInstaller(root, shouldSkipInstall);
1683
1732
  const migrationsWithNoChanges = [];
1684
- const sortedMigrations = migrations.sort((a, b) => {
1685
- // Under `--agentic`, hoist the v23 migration that ignores
1686
- // `.nx/migrate-runs` to position 0 so its .gitignore update lands
1687
- // before any per-migration commit absorbs the run's handoff scratch.
1688
- // See `agentic/handoff-gitignore.ts` for the full rationale and the
1689
- // inline-fallback path that covers intra-pre-v23 agentic runs.
1690
- if (agentic?.kind === 'enabled') {
1691
- if ((0, handoff_gitignore_1.isHandoffGitignoreMigration)(a))
1692
- return -1;
1693
- if ((0, handoff_gitignore_1.isHandoffGitignoreMigration)(b))
1694
- return 1;
1695
- }
1696
- // special case for the split configuration migration to run first
1697
- if (a.name === '15-7-0-split-configuration-into-project-json-files') {
1698
- return -1;
1699
- }
1700
- if (b.name === '15-7-0-split-configuration-into-project-json-files') {
1701
- return 1;
1702
- }
1703
- return (0, semver_1.lt)((0, version_utils_1.normalizeVersion)(a.version), (0, version_utils_1.normalizeVersion)(b.version))
1704
- ? -1
1705
- : 1;
1733
+ const sortedMigrations = (0, sort_migrations_1.sortMigrations)(migrations, {
1734
+ hoistHandoffGitignore: agentic?.kind === 'enabled',
1706
1735
  });
1707
1736
  // Lazy-load the agentic chain so non-agentic runs don't pay its startup cost.
1708
1737
  let agenticRun;
1709
1738
  if (agentic?.kind === 'enabled' && sortedMigrations.length > 0) {
1710
- const { initRunDir } = require('./agentic/handoff');
1739
+ const { initRunDir, resolveAgenticRunId } = require('./agentic/handoff');
1711
1740
  const { runAgenticPromptStep } = require('./agentic/run-step');
1712
1741
  agenticRun = {
1713
1742
  agentic,
@@ -1795,6 +1824,23 @@ async function executeMigrations(root, migrations, isVerbose, shouldCreateCommit
1795
1824
  // as a commit failure.
1796
1825
  return { kind: 'none' };
1797
1826
  }
1827
+ // Records what a migration's deterministic phase produced. A migration that
1828
+ // changed nothing must not attempt a commit: the absorbing `git add -A`
1829
+ // would build a commit subject naming this no-op migration even though its
1830
+ // content is entirely prior pending diffs, confusing `git log` / `git blame`
1831
+ // attribution. Pending stays pending and the next change-producing migration
1832
+ // absorbs it.
1833
+ async function commitOrRecordNoChanges(m, madeChanges) {
1834
+ if (!madeChanges) {
1835
+ migrationsWithNoChanges.push(m);
1836
+ return { kind: 'none' };
1837
+ }
1838
+ const commit = await attemptMigrationCommit(m);
1839
+ if (commit.kind === 'landed' && commit.sha) {
1840
+ logger_1.logger.info(pc.dim(`Committed as ${commit.sha}`));
1841
+ }
1842
+ return commit;
1843
+ }
1798
1844
  const totalMigrations = sortedMigrations.length;
1799
1845
  let migrationIndex = 0;
1800
1846
  for (const m of sortedMigrations) {
@@ -1815,6 +1861,11 @@ async function executeMigrations(root, migrations, isVerbose, shouldCreateCommit
1815
1861
  const { resolvedCollection, documentationPath } = resolveMigrationForRun(root, m, !!agenticRun);
1816
1862
  let outcome;
1817
1863
  let commit = { kind: 'none' };
1864
+ // Set when the migration returned `skipAgentic: true` and something was
1865
+ // actually waived, so the end-of-run recaps can report it. A hybrid's
1866
+ // prompt is owed in every agentic mode, so waiving it always counts; a
1867
+ // generator-only migration only counts when validation would have run.
1868
+ let waivedAgenticStep = false;
1818
1869
  if ((0, migration_shape_1.isPromptOnlyMigration)(m)) {
1819
1870
  if (agenticRun) {
1820
1871
  inAgenticStep = true;
@@ -1839,10 +1890,19 @@ async function executeMigrations(root, migrations, isVerbose, shouldCreateCommit
1839
1890
  }
1840
1891
  }
1841
1892
  else if ((0, migration_shape_1.isHybridMigration)(m)) {
1842
- const { changes, nextSteps, agentContext, logs, madeChanges } = await (0, execute_migration_1.runNxOrAngularMigration)(root, m, isVerbose,
1893
+ const { changes, nextSteps, agentContext, skipAgentic, logs, madeChanges, } = await (0, execute_migration_1.runNxOrAngularMigration)(root, m, isVerbose,
1843
1894
  /* captureGeneratorOutput: */ !!agenticRun, resolvedCollection);
1844
1895
  migrationEmittedNextSteps.push(...nextSteps);
1845
- if (agenticRun) {
1896
+ if (skipAgentic) {
1897
+ // The generator reported the prompt half unnecessary, so nothing is
1898
+ // owed: no agent run, and no next-steps entry telling the user to
1899
+ // run the prompt themselves. Runs in all three agentic modes.
1900
+ (0, migrate_output_1.logWaivedAgenticStep)(m, agentContext);
1901
+ waivedAgenticStep = true;
1902
+ commit = await commitOrRecordNoChanges(m, madeChanges);
1903
+ outcome = madeChanges ? 'applied' : 'no-changes';
1904
+ }
1905
+ else if (agenticRun) {
1846
1906
  // Install any deps the deterministic phase added/bumped before the
1847
1907
  // agent runs — the prompt half may depend on them being present in
1848
1908
  // node_modules.
@@ -1881,21 +1941,7 @@ async function executeMigrations(root, migrations, isVerbose, shouldCreateCommit
1881
1941
  printDroppedAgentContext({ migration: m, agentContext });
1882
1942
  }
1883
1943
  skippedPrompts.push(m);
1884
- if (!madeChanges) {
1885
- migrationsWithNoChanges.push(m);
1886
- }
1887
- // Only attempt a commit when this migration's deterministic
1888
- // phase actually produced changes. Otherwise the absorbing
1889
- // `git add -A` would build a commit subject naming this no-op
1890
- // migration even though its content is entirely prior pending
1891
- // diffs — confusing `git log` / `git blame` attribution. Pending
1892
- // stays pending and the next change-producing migration absorbs.
1893
- if (madeChanges) {
1894
- commit = await attemptMigrationCommit(m);
1895
- }
1896
- if (commit.kind === 'landed' && commit.sha) {
1897
- logger_1.logger.info(pc.dim(`Committed as ${commit.sha}`));
1898
- }
1944
+ commit = await commitOrRecordNoChanges(m, madeChanges);
1899
1945
  outcome = 'deferred';
1900
1946
  }
1901
1947
  }
@@ -1903,10 +1949,14 @@ async function executeMigrations(root, migrations, isVerbose, shouldCreateCommit
1903
1949
  // Defer commit until validation succeeds; failed validation leaves
1904
1950
  // changes uncommitted in the working tree for the user to review.
1905
1951
  const validationRun = agenticRun && shouldRunValidation ? agenticRun : undefined;
1906
- const { changes, nextSteps, agentContext, logs, madeChanges } = await (0, execute_migration_1.runNxOrAngularMigration)(root, m, isVerbose,
1952
+ const { changes, nextSteps, agentContext, skipAgentic, logs, madeChanges, } = await (0, execute_migration_1.runNxOrAngularMigration)(root, m, isVerbose,
1907
1953
  /* captureGeneratorOutput: */ !!validationRun, resolvedCollection);
1908
1954
  migrationEmittedNextSteps.push(...nextSteps);
1909
- const canRunValidation = !!validationRun && changes.length > 0;
1955
+ // Whether a validation step was on the table at all. `skipAgentic`
1956
+ // waives nothing when it wasn't, so the whole waived path hangs off
1957
+ // this, not just the log line.
1958
+ const validationApplies = !!validationRun && changes.length > 0;
1959
+ const canRunValidation = validationApplies && !skipAgentic;
1910
1960
  if (canRunValidation) {
1911
1961
  // Install any deps the deterministic phase added/bumped before the
1912
1962
  // validation agent runs — the agent may run tasks that need them.
@@ -1937,22 +1987,17 @@ async function executeMigrations(root, migrations, isVerbose, shouldCreateCommit
1937
1987
  outcome = 'applied';
1938
1988
  }
1939
1989
  else {
1940
- // Inner validation step didn't run. Surface `agentContext` under
1941
- // `inside-agent` so the outer driving agent can ingest it.
1942
- if (printDroppedAgentContext && agentContext.length > 0) {
1943
- printDroppedAgentContext({ migration: m, agentContext });
1944
- }
1945
- if (!madeChanges) {
1946
- migrationsWithNoChanges.push(m);
1947
- outcome = 'no-changes';
1990
+ if (skipAgentic && validationApplies) {
1991
+ (0, migrate_output_1.logWaivedAgenticStep)(m, agentContext);
1992
+ waivedAgenticStep = true;
1948
1993
  }
1949
- else {
1950
- commit = await attemptMigrationCommit(m);
1951
- if (commit.kind === 'landed' && commit.sha) {
1952
- logger_1.logger.info(pc.dim(`Committed as ${commit.sha}`));
1953
- }
1954
- outcome = 'applied';
1994
+ else if (printDroppedAgentContext && agentContext.length > 0) {
1995
+ // Inner validation step didn't run. Surface `agentContext` under
1996
+ // `inside-agent` so the outer driving agent can ingest it.
1997
+ printDroppedAgentContext({ migration: m, agentContext });
1955
1998
  }
1999
+ commit = await commitOrRecordNoChanges(m, madeChanges);
2000
+ outcome = madeChanges ? 'applied' : 'no-changes';
1956
2001
  }
1957
2002
  }
1958
2003
  outcomes.push({
@@ -1960,6 +2005,7 @@ async function executeMigrations(root, migrations, isVerbose, shouldCreateCommit
1960
2005
  status: 'completed',
1961
2006
  kind: outcome,
1962
2007
  commit,
2008
+ waivedAgenticStep,
1963
2009
  });
1964
2010
  logger_1.logger.info('');
1965
2011
  }
@@ -2022,7 +2068,7 @@ async function executeMigrations(root, migrations, isVerbose, shouldCreateCommit
2022
2068
  await installDepsIfChanged();
2023
2069
  }
2024
2070
  if (changedDepInstaller.skippedInstall) {
2025
- logSkippedPostMigrationInstall(root);
2071
+ (0, execute_migration_1.logSkippedPostMigrationInstall)(root);
2026
2072
  }
2027
2073
  // Combined-view next-steps array kept for back-compat with repair.ts, which
2028
2074
  // consumes the single `nextSteps` field.
@@ -2038,6 +2084,7 @@ async function executeMigrations(root, migrations, isVerbose, shouldCreateCommit
2038
2084
  skippedPrompts,
2039
2085
  migrationEmittedNextSteps,
2040
2086
  committedShasCount: (0, migrate_output_1.countLandedCommits)(outcomes),
2087
+ waivedAgenticStepsCount: (0, migrate_output_1.countWaivedAgenticSteps)(outcomes),
2041
2088
  // Migrations whose commits failed and never got absorbed by a later
2042
2089
  // commit. The caller surfaces them so a successful run doesn't claim
2043
2090
  // "up to date" while leaving uncommitted diffs in the working tree.
@@ -2045,13 +2092,18 @@ async function executeMigrations(root, migrations, isVerbose, shouldCreateCommit
2045
2092
  retainedAtSuccess: (0, migrate_output_1.retainedMigrations)(outcomes).map((p) => `${p.package}: ${p.name}`),
2046
2093
  };
2047
2094
  }
2048
- function logSkippedPostMigrationInstall(root) {
2049
- const packageManager = (0, package_manager_1.detectPackageManager)(root);
2050
- const installCommand = (0, package_manager_1.getPackageManagerCommand)(packageManager, root).install;
2051
- output_1.output.warn({
2052
- title: 'Migrations updated your dependencies, but the install was skipped',
2053
- bodyLines: [`Run "${installCommand}" to install the updated dependencies.`],
2054
- });
2095
+ // nx is located at spawn time, after the gated pre-install, so the child runs
2096
+ // the bytes that install put in place.
2097
+ function handOffToLocalNx(args) {
2098
+ const exitCode = runOrReturnExitCode(() => (0, child_process_2.runNxArgvSync)(['migrate', ...args], {
2099
+ stdio: ['inherit', 'inherit', 'inherit'],
2100
+ env: {
2101
+ ...process.env,
2102
+ NX_MIGRATE_SKIP_INSTALL: 'true',
2103
+ NX_MIGRATE_USE_LOCAL: 'true',
2104
+ },
2105
+ }));
2106
+ return exitCode !== 0 ? exitCode : undefined;
2055
2107
  }
2056
2108
  async function runMigrations(root, opts, args, isVerbose, shouldCreateCommits, commitPrefix, shouldSkipInstall = false) {
2057
2109
  if (!shouldSkipInstall && !process.env.NX_MIGRATE_SKIP_INSTALL) {
@@ -2060,18 +2112,7 @@ async function runMigrations(root, opts, args, isVerbose, shouldCreateCommits, c
2060
2112
  if (!__dirname.startsWith(workspace_root_1.workspaceRoot)) {
2061
2113
  // we are running from a temp installation with nx latest, switch to running
2062
2114
  // from local installation
2063
- const exitCode = runOrReturnExitCode(() => (0, child_process_2.runNxSync)(`migrate ${args.join(' ')}`, {
2064
- stdio: ['inherit', 'inherit', 'inherit'],
2065
- env: {
2066
- ...process.env,
2067
- NX_MIGRATE_SKIP_INSTALL: 'true',
2068
- NX_MIGRATE_USE_LOCAL: 'true',
2069
- },
2070
- }));
2071
- if (exitCode !== 0) {
2072
- return exitCode;
2073
- }
2074
- return;
2115
+ return handOffToLocalNx(args);
2075
2116
  }
2076
2117
  const migrationsExists = (0, fileutils_1.fileExists)(opts.runMigrations);
2077
2118
  if (opts.ifExists && !migrationsExists) {
@@ -2083,12 +2124,53 @@ async function runMigrations(root, opts, args, isVerbose, shouldCreateCommits, c
2083
2124
  else if (!opts.ifExists && !migrationsExists) {
2084
2125
  throw new Error(`File '${opts.runMigrations}' doesn't exist, can't run migrations. Use flag --if-exists to run migrations only if the file exists`);
2085
2126
  }
2086
- const migrations = (0, fileutils_1.readJsonFile)((0, path_1.join)(root, opts.runMigrations)).migrations;
2127
+ const migrationsJson = (0, fileutils_1.readJsonFile)((0, path_1.join)(root, opts.runMigrations));
2128
+ const migrations = migrationsJson.migrations;
2129
+ // An outer agent drives the loop, so hand off to the orchestrator instead of
2130
+ // the classic loop: init either starts a fresh run or resumes an already-
2131
+ // active one. `--run-id` reconciles are dispatched separately and never
2132
+ // reach here.
2133
+ if (process.env.NX_MIGRATE_ORCHESTRATOR === 'true' && (0, inception_1.isInsideAgent)()) {
2134
+ // Orchestrated runs are agent-driven, so commits default on exactly as they
2135
+ // do under `--agentic=enabled`; the orchestrator replaces `resolveAgentic`.
2136
+ const { effective: effectiveCreateCommits, warning: createCommitsWarning, error: createCommitsError, } = (0, migrate_commits_1.resolveCreateCommits)({
2137
+ createCommits: shouldCreateCommits,
2138
+ mode: 'orchestrated',
2139
+ isGitRepo: (0, git_utils_1.isGitRepository)(root),
2140
+ commitPrefixIsCustom: commitPrefix !== command_object_1.DEFAULT_MIGRATION_COMMIT_PREFIX,
2141
+ });
2142
+ if (createCommitsError) {
2143
+ throw new Error(createCommitsError);
2144
+ }
2145
+ if (createCommitsWarning) {
2146
+ output_1.output.warn({ title: createCommitsWarning });
2147
+ }
2148
+ // The run commits on the user's behalf across many invocations, so the
2149
+ // default-branch confirmation belongs here, once, before any of them.
2150
+ if (effectiveCreateCommits &&
2151
+ (0, safe_prompt_1.canPrompt)(opts.interactive) &&
2152
+ !(await (0, migrate_commits_1.confirmMigrationCommitsOnDefaultBranch)(root, 'running migrations'))) {
2153
+ return;
2154
+ }
2155
+ const { packageJson: orchestratorNxPackageJson } = (0, package_json_1.readModulePackageJson)('nx', (0, installation_directory_1.getNxRequirePaths)(root));
2156
+ const { runOrchestratorInit } = require('./run');
2157
+ return await runOrchestratorInit({
2158
+ root,
2159
+ migrationsJson,
2160
+ createCommits: effectiveCreateCommits,
2161
+ commitPrefix,
2162
+ // The flag only, never NX_MIGRATE_SKIP_INSTALL: the wrapper's local
2163
+ // re-exec sets that env var for its own hop, and it says nothing about
2164
+ // what the user asked for.
2165
+ skipInstall: shouldSkipInstall,
2166
+ installedNxVersion: orchestratorNxPackageJson.version,
2167
+ });
2168
+ }
2087
2169
  (0, migrate_analytics_1.reportMigrateRunStart)({
2088
2170
  createCommits: shouldCreateCommits ?? false,
2089
2171
  migrationCount: migrations.length,
2090
2172
  });
2091
- const { resolveAgentic } = require('./agentic/select');
2173
+ const { resolveAgentic, resolveShouldRunValidation } = require('./agentic/select');
2092
2174
  let agentic;
2093
2175
  try {
2094
2176
  agentic = await resolveAgentic({
@@ -2101,9 +2183,9 @@ async function runMigrations(root, opts, args, isVerbose, shouldCreateCommits, c
2101
2183
  (0, migrate_analytics_1.reportMigrateRunError)({ code: 'agentic', error: e });
2102
2184
  throw e;
2103
2185
  }
2104
- const { effective: effectiveCreateCommits, agenticHasDiffContext, warning: createCommitsWarning, error: createCommitsError, } = resolveCreateCommits({
2186
+ const { effective: effectiveCreateCommits, agenticHasDiffContext, warning: createCommitsWarning, error: createCommitsError, } = (0, migrate_commits_1.resolveCreateCommits)({
2105
2187
  createCommits: shouldCreateCommits,
2106
- agenticKind: agentic.kind,
2188
+ mode: agentic.kind,
2107
2189
  isGitRepo: (0, git_utils_1.isGitRepository)(root),
2108
2190
  commitPrefixIsCustom: commitPrefix !== command_object_1.DEFAULT_MIGRATION_COMMIT_PREFIX,
2109
2191
  });
@@ -2113,24 +2195,10 @@ async function runMigrations(root, opts, args, isVerbose, shouldCreateCommits, c
2113
2195
  if (createCommitsWarning) {
2114
2196
  output_1.output.warn({ title: createCommitsWarning });
2115
2197
  }
2116
- if (effectiveCreateCommits && (0, safe_prompt_1.canPrompt)(opts.interactive)) {
2117
- const currentBranch = (0, git_utils_1.getGitCurrentBranch)(root);
2118
- // `getBaseRef` may carry an `origin/` prefix (set by the CI-workflow
2119
- // generator); compare against the local branch name.
2120
- const defaultBranch = (0, command_line_utils_1.getBaseRef)((0, configuration_1.readNxJson)(root)).replace(/^origin\//, '');
2121
- const proceed = await confirmCommitsOnDefaultBranch({
2122
- currentBranch,
2123
- defaultBranch,
2124
- });
2125
- if (!proceed) {
2126
- output_1.output.log({
2127
- title: `Skipped running migrations to avoid committing to the default branch '${currentBranch}'.`,
2128
- bodyLines: [
2129
- 'Switch to a different branch and re-run, or re-run and confirm to proceed.',
2130
- ],
2131
- });
2132
- return;
2133
- }
2198
+ if (effectiveCreateCommits &&
2199
+ (0, safe_prompt_1.canPrompt)(opts.interactive) &&
2200
+ !(await (0, migrate_commits_1.confirmMigrationCommitsOnDefaultBranch)(root, 'running migrations'))) {
2201
+ return;
2134
2202
  }
2135
2203
  const shouldRunValidation = resolveShouldRunValidation({
2136
2204
  validate: opts.validate,
@@ -2146,8 +2214,9 @@ async function runMigrations(root, opts, args, isVerbose, shouldCreateCommits, c
2146
2214
  (0, migrate_commits_1.commitCheckpointBeforeMigrations)(root, commitPrefix);
2147
2215
  }
2148
2216
  if (agentic.kind === 'enabled') {
2217
+ const { applyAgenticHandoffGitignoreFallback } = require('./agentic/handoff-gitignore');
2149
2218
  const { packageJson: nxPackageJson } = (0, package_json_1.readModulePackageJson)('nx', (0, installation_directory_1.getNxRequirePaths)(root));
2150
- await (0, handoff_gitignore_1.applyAgenticHandoffGitignoreFallback)({
2219
+ await applyAgenticHandoffGitignoreFallback({
2151
2220
  migrations,
2152
2221
  installedNxVersion: nxPackageJson.version,
2153
2222
  effectiveCreateCommits,
@@ -2155,7 +2224,7 @@ async function runMigrations(root, opts, args, isVerbose, shouldCreateCommits, c
2155
2224
  root,
2156
2225
  });
2157
2226
  }
2158
- const { migrationsWithNoChanges, skippedPromptsCount, notRunMigrationsCount, skippedPrompts, migrationEmittedNextSteps, committedShasCount, retainedAtSuccess, } = await executeMigrations(root, migrations, isVerbose, effectiveCreateCommits, commitPrefix, shouldSkipInstall, agentic, agenticHasDiffContext, shouldRunValidation);
2227
+ const { migrationsWithNoChanges, skippedPromptsCount, notRunMigrationsCount, skippedPrompts, migrationEmittedNextSteps, committedShasCount, waivedAgenticStepsCount, retainedAtSuccess, } = await executeMigrations(root, migrations, isVerbose, effectiveCreateCommits, commitPrefix, shouldSkipInstall, agentic, agenticHasDiffContext, shouldRunValidation);
2159
2228
  const ranWithChangesCount = migrations.length - notRunMigrationsCount - migrationsWithNoChanges.length;
2160
2229
  // The "applied" tally counts fully-completed migrations — those that
2161
2230
  // left no deferred work behind. Hybrid migrations whose prompt half was
@@ -2166,6 +2235,7 @@ async function runMigrations(root, opts, args, isVerbose, shouldCreateCommits, c
2166
2235
  appliedCount,
2167
2236
  committedShasCount,
2168
2237
  skippedPromptsCount,
2238
+ waivedAgenticStepsCount,
2169
2239
  insideAgent,
2170
2240
  });
2171
2241
  const tallyBody = tallyLine ? [tallyLine] : undefined;
@@ -2247,18 +2317,30 @@ async function runMigrations(root, opts, args, isVerbose, shouldCreateCommits, c
2247
2317
  appliedCount,
2248
2318
  });
2249
2319
  }
2320
+ function isRunPhaseInvocation(args) {
2321
+ return (args.runMigration !== undefined ||
2322
+ args.runId !== undefined ||
2323
+ args.stepAction !== undefined);
2324
+ }
2250
2325
  async function migrate(root, args, rawArgs) {
2251
2326
  await client_1.daemonClient.stop();
2252
2327
  return (0, handle_errors_1.handleErrors)(process.env.NX_VERBOSE_LOGGING === 'true', async () => {
2253
2328
  const mergedArgs = (0, migrate_config_1.applyNxJsonMigrateDefaults)(args, (0, configuration_1.readNxJson)().migrate);
2254
- (0, migrate_config_1.assertCommitPrefixHasCommits)(mergedArgs);
2329
+ // Run-phase invocations resolve their commit config downstream (run.json
2330
+ // for recorded runs, resolveCreateCommits for standalone), so this assert
2331
+ // must not fire for them; otherwise an nx.json prefix the whole-file run
2332
+ // legitimately uses would wedge every dispensed command.
2333
+ const runPhase = isRunPhaseInvocation(mergedArgs);
2334
+ if (!runPhase) {
2335
+ (0, migrate_config_1.assertCommitPrefixHasCommits)(mergedArgs);
2336
+ }
2255
2337
  // One fetcher (registry-first, install fallback) shared by the `--include`
2256
2338
  // eligibility gate and the migration cascade so package metadata is fetched
2257
2339
  // at most once per package/version.
2258
2340
  const fetch = createFetcher((0, package_manager_1.getPackageManagerCommand)());
2259
- // `--run-migrations` without a value parses as '' - undefined means the
2260
- // generate phase.
2261
- const isGenerateInvocation = mergedArgs['runMigrations'] === undefined;
2341
+ // `--run-migrations` without a value parses as '', so only undefined (and
2342
+ // no run-phase flag) means the generate phase.
2343
+ const isGenerateInvocation = mergedArgs['runMigrations'] === undefined && !runPhase;
2262
2344
  let opts;
2263
2345
  try {
2264
2346
  opts = await parseMigrationsOptions(mergedArgs, fetch);
@@ -2267,36 +2349,320 @@ async function migrate(root, args, rawArgs) {
2267
2349
  if (isGenerateInvocation) {
2268
2350
  (0, migrate_analytics_1.reportMigrateGenerateError)('resolve_version', e);
2269
2351
  }
2352
+ else if (runPhase) {
2353
+ (0, migrate_analytics_1.reportMigrateRunError)({ code: 'other', error: e });
2354
+ }
2270
2355
  throw e;
2271
2356
  }
2272
- if (opts.type === 'generateMigrations') {
2273
- await generateMigrationsJsonAndUpdatePackageJson(root, opts, fetch);
2357
+ switch (opts.type) {
2358
+ case 'generateMigrations':
2359
+ await generateMigrationsJsonAndUpdatePackageJson(root, opts, fetch);
2360
+ return;
2361
+ case 'runSingleMigration':
2362
+ try {
2363
+ return await runSingleMigrationFromCli(root, opts, rawArgs, mergedArgs);
2364
+ }
2365
+ catch (e) {
2366
+ // `runInstall` already logged the remediation; returning instead of
2367
+ // rethrowing keeps `handleErrors` from printing a stack over it.
2368
+ if (e instanceof execute_migration_1.NpmPeerDepsInstallError) {
2369
+ (0, migrate_analytics_1.reportMigrateRunError)({ code: 'npm_install', error: e });
2370
+ return 1;
2371
+ }
2372
+ (0, migrate_analytics_1.reportMigrateRunError)({ code: 'other', error: e });
2373
+ throw e;
2374
+ }
2375
+ case 'orchestratorReconcile':
2376
+ return await runOrchestratorReconcileFromCli(root, opts, rawArgs);
2377
+ case 'runMigrations':
2378
+ try {
2379
+ return await runMigrations(root, opts, rawArgs, mergedArgs['verbose'], mergedArgs['createCommits'], mergedArgs['commitPrefix'] ?? command_object_1.DEFAULT_MIGRATION_COMMIT_PREFIX, mergedArgs['skipInstall']);
2380
+ }
2381
+ catch (e) {
2382
+ if (e instanceof execute_migration_1.NpmPeerDepsInstallError) {
2383
+ (0, migrate_analytics_1.reportMigrateRunError)({ code: 'npm_install', error: e });
2384
+ return 1;
2385
+ }
2386
+ (0, migrate_analytics_1.reportMigrateRunError)({ code: 'other', error: e });
2387
+ throw e;
2388
+ }
2389
+ default: {
2390
+ // `unhandled: never` makes a new invocation type a compile error here
2391
+ // rather than a silent fall-through.
2392
+ const unhandled = opts;
2393
+ throw new Error(`Unhandled migrate invocation type: ${JSON.stringify(unhandled)}`);
2394
+ }
2395
+ }
2396
+ });
2397
+ }
2398
+ // Evaluated manifest code can throw any value: a null-prototype object defeats
2399
+ // String() (the Object.prototype.toString rung catches it), and a revoked
2400
+ // proxy defeats that too. Interpolating either in a catch would throw again
2401
+ // and escape the catch.
2402
+ function stringifyCaught(e) {
2403
+ try {
2404
+ return String(e);
2405
+ }
2406
+ catch {
2407
+ try {
2408
+ return Object.prototype.toString.call(e);
2409
+ }
2410
+ catch {
2411
+ return '<unprintable value>';
2274
2412
  }
2275
- else {
2276
- try {
2277
- return await runMigrations(root, opts, rawArgs, mergedArgs['verbose'], mergedArgs['createCommits'], mergedArgs['commitPrefix'] ?? command_object_1.DEFAULT_MIGRATION_COMMIT_PREFIX, mergedArgs['skipInstall']);
2413
+ }
2414
+ }
2415
+ // A resolver-based lookup (including `resolvePackageJsonWithoutCachePollution`,
2416
+ // which does defeat Node's package self-reference) is the wrong tool here:
2417
+ // resolvers fall back to NODE_PATH after the explicit paths, and NODE_PATH
2418
+ // names the temp installation when this runs there. The scan below reads its
2419
+ // candidate directories itself, so neither NODE_PATH nor self-reference can
2420
+ // reach it; `getNxBin` (utils/child-process.ts), which locates the nx the
2421
+ // hand-off spawns, avoids resolvers for the same reason, over a narrower set
2422
+ // of directories: it skips `.nx/installation`, declines a root without a
2423
+ // package.json, and stops at the nearest install rather than reading past an
2424
+ // unusable one. The PnP branch below stays bespoke either way: a resolver
2425
+ // cannot see into the zip cache without the PnP runtime.
2426
+ function readLocalNxVersion(root) {
2427
+ // A PnP manifest is consulted only when yarn drives the hand-off:
2428
+ // `getRunNxBaseCommand` builds the hand-off command through this same
2429
+ // detectPackageManager call (which answers from nx.json's
2430
+ // cli.packageManager first, before any lockfile), and yarn is the one
2431
+ // package manager that executes the manifest's nx. That mirror alone
2432
+ // cannot see a switch off yarn, because yarn.lock survives one and
2433
+ // outranks all but bun's lockfiles in the detection order, while .pnp.cjs
2434
+ // lingers only on a switch to another package manager (yarn removes it
2435
+ // when moving to node_modules linking). A rival lockfile beside the
2436
+ // manifest is therefore read as evidence of such a switch, though not
2437
+ // proof, since `pnpm install --lockfile-only` writes one without
2438
+ // installing: on a scan miss the manifest still answers rather than
2439
+ // failing the guards, and a rival install over a still-live PnP
2440
+ // workspace is read over the PnP nx the yarn spawn executes, because
2441
+ // preferring the manifest would judge the dead install that a completed
2442
+ // switch leaves behind and refuse persistently. The known misread left
2443
+ // is yarn classic driving a workspace with a leftover Berry manifest
2444
+ // and no other lockfile; telling the two yarns apart from disk is not
2445
+ // worth the fragility, and a `yarn node` runtime probe was rejected
2446
+ // because its stdout is forgeable through an inherited NODE_OPTIONS
2447
+ // preload and a hung descendant holding the output pipe outlives a
2448
+ // subprocess timeout on this synchronous path.
2449
+ const pnpManifest = ['.pnp.cjs', '.pnp.js']
2450
+ .map((f) => (0, path_1.join)(root, f))
2451
+ .find((f) => (0, fs_1.existsSync)(f));
2452
+ if (pnpManifest) {
2453
+ const competingLockfile = [
2454
+ 'package-lock.json',
2455
+ 'npm-shrinkwrap.json',
2456
+ 'pnpm-lock.yaml',
2457
+ 'bun.lockb',
2458
+ 'bun.lock',
2459
+ ].some((f) => (0, fs_1.existsSync)((0, path_1.join)(root, f)));
2460
+ if (competingLockfile) {
2461
+ const version = scanNodeModulesForNxVersion(root);
2462
+ if (version) {
2463
+ return version;
2278
2464
  }
2279
- catch (e) {
2280
- // The remediation guidance is already logged by `runInstall`; swallow
2281
- // the error here so `handleErrors` doesn't print a noisy stack after
2282
- // the friendly output.
2283
- if (e instanceof execute_migration_1.NpmPeerDepsInstallError) {
2284
- (0, migrate_analytics_1.reportMigrateRunError)({ code: 'npm_install', error: e });
2285
- return 1;
2465
+ }
2466
+ try {
2467
+ if ((0, package_manager_1.detectPackageManager)(root) === 'yarn') {
2468
+ // Compiled manually rather than required: a require would serve the
2469
+ // stale cached copy the runtime loaded at startup. new Function does
2470
+ // not strip a leading shebang like the CJS loader, so drop it here.
2471
+ const manifestModule = {
2472
+ exports: {},
2473
+ };
2474
+ new Function('module', 'exports', 'require', '__dirname', '__filename', (0, fs_1.readFileSync)(pnpManifest, 'utf-8').replace(/^#!.*/, ''))(manifestModule, manifestModule.exports, require, root, pnpManifest);
2475
+ const packageJsonPath = manifestModule.exports.resolveRequest('nx/package.json', (0, path_1.join)(root, 'package.json'));
2476
+ if (packageJsonPath) {
2477
+ // A resolving manifest names the install the yarn spawn runs, so
2478
+ // every branch below returns rather than falling through to the
2479
+ // ancestor scan.
2480
+ try {
2481
+ const { version } = (0, fileutils_1.readJsonFile)(packageJsonPath);
2482
+ if (typeof version === 'string') {
2483
+ logger_1.logger.verbose(`Read the workspace's nx version ${version} from '${packageJsonPath}'.`);
2484
+ return version;
2485
+ }
2486
+ logger_1.logger.verbose(`'${packageJsonPath}' does not declare a usable version.`);
2487
+ return undefined;
2488
+ }
2489
+ catch (readError) {
2490
+ // A zip-served path (installs with scripts disabled keep nx
2491
+ // zipped) cannot be read without the PnP runtime's zip fs, but
2492
+ // the manifest's own locator still names the version (e.g.
2493
+ // 'virtual:<hash>#npm:23.1.0').
2494
+ let version;
2495
+ try {
2496
+ const reference = manifestModule.exports.findPackageLocator?.(packageJsonPath)?.reference;
2497
+ version =
2498
+ typeof reference === 'string'
2499
+ ? reference.match(/npm:([^#:]+)/)?.[1]
2500
+ : undefined;
2501
+ }
2502
+ catch (locatorError) {
2503
+ logger_1.logger.verbose(`Could not read the nx locator from the PnP manifest '${pnpManifest}': ${stringifyCaught(locatorError)}`);
2504
+ }
2505
+ if (version && (0, semver_1.valid)(version)) {
2506
+ logger_1.logger.verbose(`Read the workspace's nx version ${version} from the locator in the PnP manifest '${pnpManifest}'.`);
2507
+ return version;
2508
+ }
2509
+ logger_1.logger.verbose(`Could not read the workspace's nx version through the PnP manifest '${pnpManifest}': ${stringifyCaught(readError)}`);
2510
+ return undefined;
2511
+ }
2286
2512
  }
2287
- (0, migrate_analytics_1.reportMigrateRunError)({ code: 'other', error: e });
2288
- throw e;
2289
2513
  }
2290
2514
  }
2515
+ catch (e) {
2516
+ // Degrade to the full scan: neither a failed detection nor an
2517
+ // unevaluable manifest can name the spawn's nx.
2518
+ logger_1.logger.verbose(`Could not read the workspace's nx version through the PnP manifest '${pnpManifest}': ${stringifyCaught(e)}`);
2519
+ }
2520
+ }
2521
+ return scanNodeModulesForNxVersion(root);
2522
+ }
2523
+ // The workspace's own install locations first (.nx/installation, root), then
2524
+ // ancestor directories: package-manager executable lookup ascends (npx and
2525
+ // bun always, pnpm and yarn inside an outer workspace) and hoisted layouts
2526
+ // install nx above the workspace root. `getNxBin` ascends too, so an ancestor
2527
+ // read here is usually the one the hand-off spawns. They diverge for a
2528
+ // `.nx/installation` workspace, which `getNxBin` declines, and where the only
2529
+ // nx found sits past the package manager's own lookup boundary and the spawn
2530
+ // has fallen back to that manager: yarn then reports "command not found"
2531
+ // while pnpm exec lands on an nx on PATH. The version read here is therefore
2532
+ // the readable answer, not necessarily the executed one.
2533
+ function scanNodeModulesForNxVersion(root) {
2534
+ const searchPaths = [...(0, installation_directory_1.getNxRequirePaths)(root)];
2535
+ for (let dir = (0, path_1.dirname)(root);; dir = (0, path_1.dirname)(dir)) {
2536
+ searchPaths.push(dir);
2537
+ if (dir === (0, path_1.dirname)(dir)) {
2538
+ break;
2539
+ }
2540
+ }
2541
+ return readNxVersionFromNodeModules(searchPaths);
2542
+ }
2543
+ function readNxVersionFromNodeModules(searchPaths) {
2544
+ for (const searchPath of searchPaths) {
2545
+ const packageJsonPath = (0, path_1.join)(searchPath, 'node_modules', 'nx', 'package.json');
2546
+ try {
2547
+ if ((0, fs_1.existsSync)(packageJsonPath)) {
2548
+ const { version } = (0, fileutils_1.readJsonFile)(packageJsonPath);
2549
+ if (typeof version === 'string') {
2550
+ logger_1.logger.verbose(`Resolved nx version ${version} from '${packageJsonPath}'.`);
2551
+ return version;
2552
+ }
2553
+ logger_1.logger.verbose(`'${packageJsonPath}' does not declare a usable version; continuing the search.`);
2554
+ }
2555
+ }
2556
+ catch (e) {
2557
+ logger_1.logger.verbose(`Could not read the workspace's installed nx version from '${packageJsonPath}': ${e}`);
2558
+ }
2559
+ }
2560
+ return undefined;
2561
+ }
2562
+ // Mirrors the local-nx hand-off of the other run paths so a reconcile always
2563
+ // executes against the workspace-local nx that owns the run state, never the
2564
+ // temp installation. Reconciles only read state and commit, so no install.
2565
+ async function runOrchestratorReconcileFromCli(root, opts, args) {
2566
+ if (!__dirname.startsWith(workspace_root_1.workspaceRoot)) {
2567
+ // The workspace-local nx we are about to hand off to must be new enough to
2568
+ // understand the new flags we forward to it.
2569
+ (0, version_skew_guard_1.assertWorkspaceNxSupportsNewMigrateFlags)({
2570
+ argv: args,
2571
+ readLocalNxVersion: () => readLocalNxVersion(root),
2572
+ });
2573
+ return handOffToLocalNx(args);
2574
+ }
2575
+ const { runOrchestratorReconcile } = require('./run');
2576
+ return runOrchestratorReconcile({
2577
+ root,
2578
+ runId: opts.runId,
2579
+ stepAction: opts.stepAction,
2580
+ });
2581
+ }
2582
+ // Keeps `--run-migration` behaving like `--run-migrations` when invoked from
2583
+ // a temp `nx@latest` install: same pre-install, same local-nx hand-off.
2584
+ async function runSingleMigrationFromCli(root, opts, args, mergedArgs) {
2585
+ const shouldSkipInstall = mergedArgs['skipInstall'] ?? false;
2586
+ // A recorded execution skips the pre-install: the run carries its own
2587
+ // install policy and its worker installs what the migration changed, so
2588
+ // paying for a full install ahead of every dispensed command would be
2589
+ // redundant.
2590
+ if (opts.runId === undefined &&
2591
+ !shouldSkipInstall &&
2592
+ !process.env.NX_MIGRATE_SKIP_INSTALL) {
2593
+ await (0, execute_migration_1.runInstall)(undefined, 'pre-migration', (0, execute_migration_1.formatSingleMigrationRerunCommand)(opts.runMigration));
2594
+ }
2595
+ if (!__dirname.startsWith(workspace_root_1.workspaceRoot)) {
2596
+ // Must stay after the pre-install: it reads the version that install may
2597
+ // have just updated, so checking earlier would falsely refuse a workspace
2598
+ // whose package.json bump was not installed yet.
2599
+ (0, version_skew_guard_1.assertWorkspaceNxSupportsNewMigrateFlags)({
2600
+ argv: args,
2601
+ // `workspaceRoot`, not `root`: the migrate flow's `root` is the
2602
+ // invocation directory, which may sit below the workspace the hand-off
2603
+ // resolves nx in.
2604
+ readLocalNxVersion: () => readLocalNxVersion(workspace_root_1.workspaceRoot),
2605
+ });
2606
+ return handOffToLocalNx(args);
2607
+ }
2608
+ // The worker resolves the agentic flow, the effective commit config, and
2609
+ // the default-branch confirmation itself; hand it the raw flags. Recorded
2610
+ // runs (--run-id) take their commit config from run.json instead.
2611
+ // Lazy-load run/ so plain migrate and repair runs don't pay for the agentic
2612
+ // selection chain its barrel pulls in eagerly.
2613
+ const { runSingleMigrationWorker } = require('./run');
2614
+ await runSingleMigrationWorker({
2615
+ root,
2616
+ runMigration: opts.runMigration,
2617
+ runId: opts.runId,
2618
+ agentic: opts.agentic,
2619
+ validate: opts.validate,
2620
+ createCommits: mergedArgs['createCommits'],
2621
+ commitPrefix: mergedArgs['commitPrefix'] ??
2622
+ command_object_1.DEFAULT_MIGRATION_COMMIT_PREFIX,
2623
+ interactive: opts.interactive,
2624
+ skipInstall: shouldSkipInstall,
2625
+ isVerbose: mergedArgs['verbose'] ?? false,
2291
2626
  });
2292
2627
  }
2293
2628
  async function runMigration() {
2294
2629
  return (0, handle_errors_1.handleErrors)(process.env.NX_VERBOSE_LOGGING === 'true', async () => {
2295
- const runLocalMigrate = () => runOrReturnExitCode(() => (0, child_process_2.runNxSync)(`_migrate ${process.argv.slice(3).join(' ')}`, {
2630
+ // Spawning `nx _migrate` re-resolves the workspace's nx, normally the
2631
+ // very installation running this code: bin/nx.ts delegated the outer
2632
+ // `migrate` command to it, while `_migrate` skips that delegation. A
2633
+ // new-flag invocation reaching this fallback therefore lands on an nx
2634
+ // that parsed the flags, so it needs no capability check. Two lookups
2635
+ // can still diverge from the running install, both properties of the
2636
+ // spawn machinery rather than of this fallback: a `.nx/installation`
2637
+ // beside a root package.json, and, once the spawn falls back to the
2638
+ // package manager, a lookup that misses the workspace install and lands
2639
+ // on an nx on PATH (pnpm exec).
2640
+ const forwardedArgv = process.argv.slice(3);
2641
+ const runLocalMigrate = () => runOrReturnExitCode(() => (0, child_process_2.runNxArgvSync)(['_migrate', ...forwardedArgv], {
2296
2642
  stdio: ['inherit', 'inherit', 'inherit'],
2297
2643
  }));
2298
- if (process.env.NX_USE_LOCAL !== 'true' &&
2644
+ if (!(0, version_skew_guard_1.targetsExistingRun)(process.argv.slice(3)) &&
2645
+ process.env.NX_USE_LOCAL !== 'true' &&
2299
2646
  process.env.NX_MIGRATE_USE_LOCAL === undefined) {
2647
+ // The version spec mirrors nxCliPath's; keep the two in sync.
2648
+ const cliVersionSpec = process.env.NX_MIGRATE_CLI_VERSION || 'latest';
2649
+ const target = await (0, version_skew_guard_1.resolveNewMigrateFlagsRunTarget)({
2650
+ argv: process.argv.slice(3),
2651
+ cliVersionSpec,
2652
+ fromEnvOverride: !!process.env.NX_MIGRATE_CLI_VERSION,
2653
+ ownNxVersion: versions_1.nxVersion,
2654
+ resolveVersion: (spec) =>
2655
+ // A probe must not prompt, write pnpm excludes, or install; a
2656
+ // minimum-release-age violation surfaces as a rejection and
2657
+ // routes local.
2658
+ (0, resolve_package_version_1.resolvePackageVersionRespectingMinReleaseAge)('nx', spec, {
2659
+ applySideEffects: false,
2660
+ }),
2661
+ readLocalNxVersion: () => readLocalNxVersion(workspace_root_1.workspaceRoot),
2662
+ });
2663
+ if (target === 'local-nx') {
2664
+ return runLocalMigrate();
2665
+ }
2300
2666
  const p = await nxCliPath();
2301
2667
  if (p === null) {
2302
2668
  return runLocalMigrate();
@@ -2307,10 +2673,26 @@ async function runMigration() {
2307
2673
  process.env.npm_config_registry.match(/^https:\/\/registry\.(npmjs\.org|yarnpkg\.com)/)) {
2308
2674
  delete process.env.npm_config_registry;
2309
2675
  }
2310
- return runOrReturnExitCode(() => (0, child_process_1.execSync)(`${p} _migrate ${process.argv.slice(3).join(' ')}`, {
2311
- stdio: ['inherit', 'inherit', 'inherit'],
2312
- windowsHide: true,
2313
- }));
2676
+ // Intentionally not the workspace's nx: `p` is an nx CLI freshly
2677
+ // installed into a temp dir by nxCliPath() (latest, or
2678
+ // NX_MIGRATE_CLI_VERSION), so migrations run with an up-to-date migrate
2679
+ // implementation. `p` is <tmpDir>/node_modules/.bin/nx, a shell shim;
2680
+ // spawning the entry point that install's own manifest names instead
2681
+ // keeps the forwarded argv out of a shell. That install declares nx
2682
+ // itself, so it is read without ascending: an nx above the temp dir is
2683
+ // one nothing asked for, and the shim below is the answer instead.
2684
+ const tempNxEntry = (0, child_process_2.readInstalledNxBin)((0, path_1.dirname)((0, path_1.dirname)((0, path_1.dirname)(p))));
2685
+ return runOrReturnExitCode(() => tempNxEntry
2686
+ ? (0, child_process_2.runNxArgvSync)(['_migrate', ...forwardedArgv], {
2687
+ stdio: ['inherit', 'inherit', 'inherit'],
2688
+ nxBin: tempNxEntry,
2689
+ })
2690
+ : (0, child_process_1.execSync)(`${(0, shell_quoting_1.quoteShellArg)(p)} _migrate ${forwardedArgv
2691
+ .map(shell_quoting_1.quoteShellArg)
2692
+ .join(' ')}`, {
2693
+ stdio: ['inherit', 'inherit', 'inherit'],
2694
+ windowsHide: true,
2695
+ }));
2314
2696
  }
2315
2697
  return runLocalMigrate();
2316
2698
  });
@@ -2346,7 +2728,7 @@ function resolveMigrationForRun(root, migration, resolveDocumentation) {
2346
2728
  let documentationPath;
2347
2729
  if (resolveDocumentation && migration.documentation) {
2348
2730
  documentationPath = resolvedCollection
2349
- ? resolveDocumentationFileToWorkspacePath(root, (0, path_1.dirname)(resolvedCollection.collectionPath), migration.documentation)
2731
+ ? (0, execute_migration_1.resolveDocumentationFileToWorkspacePath)(root, (0, path_1.dirname)(resolvedCollection.collectionPath), migration.documentation)
2350
2732
  : undefined;
2351
2733
  if (!documentationPath) {
2352
2734
  logger_1.logger.warn(`Could not resolve the "documentation" file "${migration.documentation}" declared for migration "${migration.package}: ${migration.name}". It will be skipped as additional context for the AI agent.`);
@@ -2354,24 +2736,6 @@ function resolveMigrationForRun(root, migration, resolveDocumentation) {
2354
2736
  }
2355
2737
  return { resolvedCollection, documentationPath };
2356
2738
  }
2357
- // Resolves a `documentation` path (relative to the package's migrations dir) to
2358
- // a workspace-relative path - or the absolute path when it resolves outside the
2359
- // workspace (unusual hoisted/symlinked layouts). The agent runs with cwd =
2360
- // workspace root, so the workspace-relative form is preferred. Returns
2361
- // undefined when the file can't be resolved.
2362
- function resolveDocumentationFileToWorkspacePath(root, migrationsDir, documentation) {
2363
- let documentationFile;
2364
- try {
2365
- documentationFile = require.resolve(documentation, {
2366
- paths: [migrationsDir],
2367
- });
2368
- }
2369
- catch {
2370
- return undefined;
2371
- }
2372
- const relativePath = (0, path_1.relative)(root, documentationFile);
2373
- return relativePath.startsWith('..') ? documentationFile : relativePath;
2374
- }
2375
2739
  async function nxCliPath(nxWorkspaceRoot) {
2376
2740
  const version = process.env.NX_MIGRATE_CLI_VERSION || 'latest';
2377
2741
  const isVerbose = process.env.NX_VERBOSE_LOGGING === 'true';
@@ -2422,7 +2786,7 @@ async function nxCliPath(nxWorkspaceRoot) {
2422
2786
  return (0, path_1.join)(tmpDir, `node_modules`, '.bin', 'nx');
2423
2787
  }
2424
2788
  catch (e) {
2425
- console.error(`Failed to install the ${version} version of the migration script. Using the current version.`);
2789
+ console.error(`Failed to install the ${version} version of the migration script. Falling back to the workspace's installed nx.`);
2426
2790
  if (isVerbose) {
2427
2791
  console.error(e);
2428
2792
  }