@depup/nx 23.1.2-depup.1 → 23.2.0-depup.0

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 (296) hide show
  1. package/README.md +7 -6
  2. package/changes.json +12 -8
  3. package/dist/bin/init-local.js +3 -5
  4. package/dist/bin/nx.js +1 -0
  5. package/dist/src/adapter/ngcli-adapter.js +60 -1
  6. package/dist/src/ai/constants.d.ts +15 -0
  7. package/dist/src/ai/constants.js +17 -1
  8. package/dist/src/ai/set-up-ai-agents/set-up-ai-agents.js +57 -9
  9. package/dist/src/ai/utils.d.ts +13 -0
  10. package/dist/src/ai/utils.js +29 -0
  11. package/dist/src/analytics/analytics.js +2 -4
  12. package/dist/src/command-line/completion/command-object.js +7 -12
  13. package/dist/src/command-line/configure-ai-agents/configure-ai-agents.js +42 -31
  14. package/dist/src/command-line/format/format.js +84 -101
  15. package/dist/src/command-line/generate/generate.js +35 -35
  16. package/dist/src/command-line/import/import.js +29 -38
  17. package/dist/src/command-line/init/ai-agent-prompts.js +5 -11
  18. package/dist/src/command-line/init/command-object.js +4 -2
  19. package/dist/src/command-line/init/configure-plugins.js +4 -1
  20. package/dist/src/command-line/init/implementation/add-nx-to-monorepo.js +12 -32
  21. package/dist/src/command-line/init/implementation/add-nx-to-nest.js +17 -21
  22. package/dist/src/command-line/init/implementation/add-nx-to-npm-repo.js +8 -21
  23. package/dist/src/command-line/init/implementation/add-nx-to-turborepo.js +3 -17
  24. package/dist/src/command-line/init/implementation/angular/index.js +10 -15
  25. package/dist/src/command-line/init/implementation/angular/legacy-angular-versions.js +2 -0
  26. package/dist/src/command-line/init/implementation/angular/standalone-workspace.js +8 -2
  27. package/dist/src/command-line/init/implementation/check-compatible-with-plugins.js +2 -0
  28. package/dist/src/command-line/init/implementation/dot-nx/add-nx-scripts.js +5 -0
  29. package/dist/src/command-line/init/implementation/format.d.ts +18 -0
  30. package/dist/src/command-line/init/implementation/format.js +114 -0
  31. package/dist/src/command-line/init/implementation/utils.js +8 -8
  32. package/dist/src/command-line/init/init-v1.js +15 -18
  33. package/dist/src/command-line/init/init-v2.js +77 -66
  34. package/dist/src/command-line/migrate/agentic/definitions.js +36 -9
  35. package/dist/src/command-line/migrate/agentic/handoff-gitignore.d.ts +37 -22
  36. package/dist/src/command-line/migrate/agentic/handoff-gitignore.js +30 -39
  37. package/dist/src/command-line/migrate/agentic/handoff.d.ts +7 -7
  38. package/dist/src/command-line/migrate/agentic/handoff.js +13 -10
  39. package/dist/src/command-line/migrate/agentic/print-dropped-agent-context.d.ts +7 -12
  40. package/dist/src/command-line/migrate/agentic/print-dropped-agent-context.js +7 -0
  41. package/dist/src/command-line/migrate/agentic/run-step.d.ts +10 -0
  42. package/dist/src/command-line/migrate/agentic/run-step.js +1 -0
  43. package/dist/src/command-line/migrate/agentic/runner.js +24 -24
  44. package/dist/src/command-line/migrate/agentic/select.d.ts +10 -2
  45. package/dist/src/command-line/migrate/agentic/select.js +30 -32
  46. package/dist/src/command-line/migrate/agentic/types.d.ts +33 -3
  47. package/dist/src/command-line/migrate/agentic/types.js +35 -0
  48. package/dist/src/command-line/migrate/command-object.d.ts +6 -0
  49. package/dist/src/command-line/migrate/command-object.js +19 -1
  50. package/dist/src/command-line/migrate/execute-migration.d.ts +28 -9
  51. package/dist/src/command-line/migrate/execute-migration.js +112 -27
  52. package/dist/src/command-line/migrate/migrate-analytics.d.ts +35 -0
  53. package/dist/src/command-line/migrate/migrate-analytics.js +64 -0
  54. package/dist/src/command-line/migrate/migrate-commits.d.ts +38 -8
  55. package/dist/src/command-line/migrate/migrate-commits.js +130 -15
  56. package/dist/src/command-line/migrate/migrate-config.d.ts +13 -12
  57. package/dist/src/command-line/migrate/migrate-config.js +22 -14
  58. package/dist/src/command-line/migrate/migrate-output.d.ts +45 -7
  59. package/dist/src/command-line/migrate/migrate-output.js +52 -8
  60. package/dist/src/command-line/migrate/migrate-ui-api.d.ts +2 -1
  61. package/dist/src/command-line/migrate/migrate-ui-api.js +16 -7
  62. package/dist/src/command-line/migrate/migrate.d.ts +24 -55
  63. package/dist/src/command-line/migrate/migrate.js +553 -226
  64. package/dist/src/command-line/migrate/migration-shape.d.ts +8 -0
  65. package/dist/src/command-line/migrate/multi-major.js +7 -10
  66. package/dist/src/command-line/migrate/resolve-package-version.js +4 -8
  67. package/dist/src/command-line/migrate/run/agent-output.d.ts +20 -0
  68. package/dist/src/command-line/migrate/run/agent-output.js +65 -0
  69. package/dist/src/command-line/migrate/run/index.d.ts +9 -0
  70. package/dist/src/command-line/migrate/run/index.js +23 -0
  71. package/dist/src/command-line/migrate/run/orchestrator.d.ts +20 -0
  72. package/dist/src/command-line/migrate/run/orchestrator.js +1200 -0
  73. package/dist/src/command-line/migrate/run/run-id.d.ts +16 -0
  74. package/dist/src/command-line/migrate/run/run-id.js +56 -0
  75. package/dist/src/command-line/migrate/run/run-state.d.ts +157 -0
  76. package/dist/src/command-line/migrate/run/run-state.js +438 -0
  77. package/dist/src/command-line/migrate/run/state-lock.d.ts +25 -0
  78. package/dist/src/command-line/migrate/run/state-lock.js +76 -0
  79. package/dist/src/command-line/migrate/run/state-machine.d.ts +84 -0
  80. package/dist/src/command-line/migrate/run/state-machine.js +315 -0
  81. package/dist/src/command-line/migrate/run/util.d.ts +59 -0
  82. package/dist/src/command-line/migrate/run/util.js +148 -0
  83. package/dist/src/command-line/migrate/run/worker.d.ts +16 -0
  84. package/dist/src/command-line/migrate/run/worker.js +682 -0
  85. package/dist/src/command-line/migrate/run-migration-process.js +6 -5
  86. package/dist/src/command-line/migrate/safe-prompt.d.ts +14 -26
  87. package/dist/src/command-line/migrate/safe-prompt.js +32 -43
  88. package/dist/src/command-line/migrate/sort-migrations.d.ts +16 -0
  89. package/dist/src/command-line/migrate/sort-migrations.js +32 -0
  90. package/dist/src/command-line/migrate/step-actions.d.ts +5 -0
  91. package/dist/src/command-line/migrate/step-actions.js +12 -0
  92. package/dist/src/command-line/migrate/text.d.ts +18 -0
  93. package/dist/src/command-line/migrate/text.js +26 -0
  94. package/dist/src/command-line/migrate/version-skew-guard.d.ts +60 -0
  95. package/dist/src/command-line/migrate/version-skew-guard.js +175 -0
  96. package/dist/src/command-line/nx-cloud/connect/connect-to-nx-cloud.js +16 -20
  97. package/dist/src/command-line/nx-cloud/start-nx-agents/command-object.d.ts +2 -0
  98. package/dist/src/command-line/nx-cloud/start-nx-agents/command-object.js +16 -0
  99. package/dist/src/command-line/nx-cloud/start-nx-agents/start-nx-agents.d.ts +4 -0
  100. package/dist/src/command-line/nx-cloud/start-nx-agents/start-nx-agents.js +13 -0
  101. package/dist/src/command-line/nx-commands.js +26 -24
  102. package/dist/src/command-line/release/changelog.js +6 -17
  103. package/dist/src/command-line/release/plan.js +15 -28
  104. package/dist/src/command-line/release/publish.js +5 -0
  105. package/dist/src/command-line/release/release.js +6 -17
  106. package/dist/src/command-line/release/utils/release-graph.d.ts +1 -0
  107. package/dist/src/command-line/release/utils/release-graph.js +10 -2
  108. package/dist/src/command-line/release/utils/remote-release-clients/github.js +10 -22
  109. package/dist/src/command-line/release/utils/remote-release-clients/gitlab.js +13 -22
  110. package/dist/src/command-line/release/utils/resolve-semver-specifier.js +19 -41
  111. package/dist/src/command-line/release/version/resolve-current-version.js +7 -10
  112. package/dist/src/command-line/release/version.js +2 -2
  113. package/dist/src/command-line/reset/reset.js +17 -15
  114. package/dist/src/command-line/yargs-utils/shared-options.d.ts +1 -1
  115. package/dist/src/command-line/yargs-utils/shared-options.js +3 -1
  116. package/dist/src/config/misc-interfaces.d.ts +19 -7
  117. package/dist/src/core/graph/main.js +1 -1
  118. package/dist/src/core/graph/styles.js +1 -1
  119. package/dist/src/daemon/client/client.d.ts +2 -7
  120. package/dist/src/daemon/client/client.js +113 -28
  121. package/dist/src/daemon/client/daemon-environment.d.ts +35 -0
  122. package/dist/src/daemon/client/daemon-environment.js +106 -6
  123. package/dist/src/daemon/client/daemon-socket-messenger.d.ts +1 -1
  124. package/dist/src/daemon/client/daemon-socket-messenger.js +8 -3
  125. package/dist/src/daemon/is-v8-serializer-enabled.d.ts +2 -2
  126. package/dist/src/daemon/is-v8-serializer-enabled.js +2 -2
  127. package/dist/src/daemon/message-types/daemon-message.d.ts +2 -1
  128. package/dist/src/daemon/message-types/daemon-message.js +25 -2
  129. package/dist/src/daemon/sandbox-socket-hint.d.ts +27 -0
  130. package/dist/src/daemon/sandbox-socket-hint.js +136 -0
  131. package/dist/src/daemon/server/client-socket-context.d.ts +1 -1
  132. package/dist/src/daemon/server/client-socket-context.js +2 -3
  133. package/dist/src/daemon/server/dotenv-graph-changes.d.ts +97 -0
  134. package/dist/src/daemon/server/dotenv-graph-changes.js +284 -0
  135. package/dist/src/daemon/server/handle-client-env.d.ts +8 -0
  136. package/dist/src/daemon/server/handle-client-env.js +92 -0
  137. package/dist/src/daemon/server/handle-outputs-changes.d.ts +10 -0
  138. package/dist/src/daemon/server/handle-outputs-changes.js +86 -0
  139. package/dist/src/daemon/server/project-graph-incremental-recomputation.d.ts +21 -0
  140. package/dist/src/daemon/server/project-graph-incremental-recomputation.js +159 -6
  141. package/dist/src/daemon/server/server.js +36 -72
  142. package/dist/src/daemon/server/shutdown-utils.d.ts +1 -1
  143. package/dist/src/daemon/server/shutdown-utils.js +2 -2
  144. package/dist/src/daemon/socket-utils.d.ts +26 -7
  145. package/dist/src/daemon/socket-utils.js +45 -31
  146. package/dist/src/daemon/tmp-dir.d.ts +10 -0
  147. package/dist/src/daemon/tmp-dir.js +21 -37
  148. package/dist/src/devkit-internals.d.ts +20 -9
  149. package/dist/src/devkit-internals.js +49 -6
  150. package/dist/src/executors/run-commands/running-tasks.js +46 -29
  151. package/dist/src/generators/internal-utils/{format-changed-files-with-prettier-if-available.d.ts → format-changed-files.d.ts} +6 -6
  152. package/dist/src/generators/internal-utils/format-changed-files.js +163 -0
  153. package/dist/src/generators/testing-utils/create-tree-with-empty-workspace.d.ts +15 -0
  154. package/dist/src/generators/testing-utils/create-tree-with-empty-workspace.js +21 -3
  155. package/dist/src/migrations/update-15-0-0/prefix-outputs.js +2 -2
  156. package/dist/src/migrations/update-16-0-0/remove-nrwl-cli.js +2 -2
  157. package/dist/src/migrations/update-16-0-0/update-depends-on-to-tokens.js +2 -2
  158. package/dist/src/migrations/update-16-0-0/update-nx-cloud-runner.js +2 -2
  159. package/dist/src/migrations/update-16-2-0/remove-run-commands-output-path.js +2 -2
  160. package/dist/src/migrations/update-17-0-0/rm-default-collection-npm-scope.js +2 -2
  161. package/dist/src/migrations/update-17-0-0/use-minimal-config-for-tasks-runner-options.js +2 -2
  162. package/dist/src/migrations/update-17-2-0/move-default-base.js +2 -2
  163. package/dist/src/migrations/update-18-0-0/disable-crystal-for-existing-workspaces.js +2 -2
  164. package/dist/src/migrations/update-19-2-4/set-project-name.js +2 -2
  165. package/dist/src/migrations/update-20-0-0/move-use-daemon-process.js +2 -2
  166. package/dist/src/migrations/update-20-0-1/use-legacy-cache.js +2 -2
  167. package/dist/src/migrations/update-21-0-0/release-changelog-config-changes.js +2 -2
  168. package/dist/src/migrations/update-21-0-0/release-version-config-changes.js +2 -2
  169. package/dist/src/migrations/update-21-0-0/remove-custom-tasks-runner.js +2 -2
  170. package/dist/src/migrations/update-21-0-0/remove-legacy-cache.js +2 -2
  171. package/dist/src/migrations/update-22-0-0/consolidate-release-tag-config.js +2 -2
  172. package/dist/src/migrations/update-22-0-0/release-version-config-changes.js +2 -2
  173. package/dist/src/migrations/update-22-2-0/add-self-healing-to-gitignore.js +2 -2
  174. package/dist/src/migrations/update-22-6-0/add-claude-settings-local-to-git-ignore.js +2 -2
  175. package/dist/src/migrations/update-22-6-0/add-claude-worktrees-to-git-ignore.js +2 -2
  176. package/dist/src/migrations/update-22-7-0/add-polygraph-to-git-ignore.js +2 -2
  177. package/dist/src/migrations/update-23-0-0/add-migrate-runs-to-git-ignore.js +2 -2
  178. package/dist/src/migrations/update-23-2-0/set-cache-on-executor-target-defaults.js +2 -2
  179. package/dist/src/native/index.d.ts +7 -3
  180. package/dist/src/native/nx.wasm32-wasi.debug.wasm +0 -0
  181. package/dist/src/native/nx.wasm32-wasi.wasm +0 -0
  182. package/dist/src/nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud.js +3 -3
  183. package/dist/src/nx-cloud/utilities/url-shorten.d.ts +1 -4
  184. package/dist/src/nx-cloud/utilities/url-shorten.js +9 -8
  185. package/dist/src/plugins/js/lock-file/lock-file.d.ts +46 -4
  186. package/dist/src/plugins/js/lock-file/lock-file.js +192 -15
  187. package/dist/src/plugins/js/lock-file/npm-parser.js +10 -3
  188. package/dist/src/plugins/js/lock-file/pnpm-parser.js +356 -62
  189. package/dist/src/plugins/js/lock-file/project-graph-pruning.d.ts +25 -1
  190. package/dist/src/plugins/js/lock-file/project-graph-pruning.js +78 -4
  191. package/dist/src/plugins/js/lock-file/pruned-output.d.ts +330 -0
  192. package/dist/src/plugins/js/lock-file/pruned-output.js +1441 -0
  193. package/dist/src/plugins/js/lock-file/utils/pnpm-normalizer.d.ts +1 -0
  194. package/dist/src/plugins/js/lock-file/utils/pnpm-normalizer.js +6 -5
  195. package/dist/src/plugins/js/utils/register.d.ts +11 -0
  196. package/dist/src/plugins/js/utils/register.js +40 -6
  197. package/dist/src/project-graph/plugins/get-plugins.d.ts +27 -1
  198. package/dist/src/project-graph/plugins/get-plugins.js +110 -5
  199. package/dist/src/project-graph/plugins/isolation/enabled.js +1 -4
  200. package/dist/src/project-graph/plugins/isolation/isolated-plugin.d.ts +16 -0
  201. package/dist/src/project-graph/plugins/isolation/isolated-plugin.js +69 -11
  202. package/dist/src/project-graph/plugins/isolation/messaging.js +1 -3
  203. package/dist/src/project-graph/plugins/isolation/plugin-worker.js +23 -2
  204. package/dist/src/project-graph/project-graph.js +27 -2
  205. package/dist/src/project-graph/utils/project-configuration/project-nodes-manager.d.ts +7 -0
  206. package/dist/src/project-graph/utils/project-configuration/project-nodes-manager.js +14 -6
  207. package/dist/src/project-graph/utils/project-configuration/target-defaults.js +47 -21
  208. package/dist/src/tasks-runner/is-tui-enabled.js +3 -1
  209. package/dist/src/tasks-runner/life-cycle.d.ts +2 -2
  210. package/dist/src/tasks-runner/life-cycle.js +2 -2
  211. package/dist/src/tasks-runner/life-cycles/performance-report.d.ts +12 -0
  212. package/dist/src/tasks-runner/life-cycles/performance-report.js +62 -3
  213. package/dist/src/tasks-runner/life-cycles/static-run-many-terminal-output-life-cycle.d.ts +26 -1
  214. package/dist/src/tasks-runner/life-cycles/static-run-many-terminal-output-life-cycle.js +99 -5
  215. package/dist/src/tasks-runner/life-cycles/static-run-one-terminal-output-life-cycle.d.ts +26 -0
  216. package/dist/src/tasks-runner/life-cycles/static-run-one-terminal-output-life-cycle.js +113 -17
  217. package/dist/src/tasks-runner/pseudo-ipc.js +14 -13
  218. package/dist/src/tasks-runner/pseudo-terminal.d.ts +17 -3
  219. package/dist/src/tasks-runner/pseudo-terminal.js +22 -10
  220. package/dist/src/tasks-runner/run-command.js +32 -39
  221. package/dist/src/tasks-runner/running-tasks/batch-process.d.ts +55 -0
  222. package/dist/src/tasks-runner/running-tasks/batch-process.js +161 -8
  223. package/dist/src/tasks-runner/task-env.d.ts +25 -0
  224. package/dist/src/tasks-runner/task-env.js +39 -0
  225. package/dist/src/tasks-runner/task-orchestrator.d.ts +68 -0
  226. package/dist/src/tasks-runner/task-orchestrator.js +159 -8
  227. package/dist/src/utils/analytics-enabled.d.ts +7 -0
  228. package/dist/src/utils/analytics-enabled.js +11 -0
  229. package/dist/src/utils/analytics-prompt.js +4 -7
  230. package/dist/src/utils/cache-directory.d.ts +62 -3
  231. package/dist/src/utils/cache-directory.js +276 -25
  232. package/dist/src/utils/catalog/bun-manager-utils.d.ts +8 -0
  233. package/dist/src/utils/catalog/bun-manager-utils.js +174 -0
  234. package/dist/src/utils/catalog/bun-manager.d.ts +28 -0
  235. package/dist/src/utils/catalog/bun-manager.js +130 -0
  236. package/dist/src/utils/catalog/index.d.ts +1 -1
  237. package/dist/src/utils/catalog/index.js +1 -1
  238. package/dist/src/utils/catalog/manager-factory.js +3 -0
  239. package/dist/src/utils/catalog/manager-utils.d.ts +8 -1
  240. package/dist/src/utils/catalog/manager-utils.js +9 -4
  241. package/dist/src/utils/catalog/manager.d.ts +13 -1
  242. package/dist/src/utils/catalog/manager.js +30 -0
  243. package/dist/src/utils/catalog/pnpm-manager.d.ts +2 -1
  244. package/dist/src/utils/catalog/pnpm-manager.js +3 -0
  245. package/dist/src/utils/catalog/types.d.ts +4 -0
  246. package/dist/src/utils/catalog/yarn-manager.d.ts +6 -2
  247. package/dist/src/utils/catalog/yarn-manager.js +23 -32
  248. package/dist/src/utils/child-process.d.ts +31 -1
  249. package/dist/src/utils/child-process.js +103 -0
  250. package/dist/src/utils/chunkify.d.ts +7 -1
  251. package/dist/src/utils/chunkify.js +10 -3
  252. package/dist/src/utils/consume-messages-from-socket.d.ts +42 -7
  253. package/dist/src/utils/consume-messages-from-socket.js +273 -38
  254. package/dist/src/utils/db-connection.js +8 -16
  255. package/dist/src/utils/exit-codes.d.ts +9 -0
  256. package/dist/src/utils/exit-codes.js +19 -0
  257. package/dist/src/utils/formatters/index.d.ts +13 -0
  258. package/dist/src/utils/formatters/index.js +74 -0
  259. package/dist/src/utils/formatters/oxfmt.d.ts +32 -0
  260. package/dist/src/utils/formatters/oxfmt.js +764 -0
  261. package/dist/src/utils/formatters/prettier.d.ts +26 -0
  262. package/dist/src/utils/formatters/prettier.js +201 -0
  263. package/dist/src/utils/formatters/shared.d.ts +5 -0
  264. package/dist/src/utils/formatters/shared.js +8 -0
  265. package/dist/src/utils/git-utils.d.ts +38 -2
  266. package/dist/src/utils/git-utils.js +422 -19
  267. package/dist/src/utils/has-nx-js-plugin.d.ts +1 -1
  268. package/dist/src/utils/has-nx-js-plugin.js +1 -1
  269. package/dist/src/utils/ignore.d.ts +47 -5
  270. package/dist/src/utils/ignore.js +93 -11
  271. package/dist/src/utils/kill-child-on-host-exit.d.ts +7 -0
  272. package/dist/src/utils/kill-child-on-host-exit.js +42 -0
  273. package/dist/src/utils/nx-console-prompt.js +3 -6
  274. package/dist/src/utils/nx-tmp-dir.d.ts +5 -0
  275. package/dist/src/utils/nx-tmp-dir.js +7 -2
  276. package/dist/src/utils/output.d.ts +153 -0
  277. package/dist/src/utils/output.js +289 -5
  278. package/dist/src/utils/owned-private-dir.d.ts +13 -0
  279. package/dist/src/utils/owned-private-dir.js +39 -0
  280. package/dist/src/utils/package-json.d.ts +2 -0
  281. package/dist/src/utils/package-manager.js +17 -7
  282. package/dist/src/utils/params.d.ts +7 -1
  283. package/dist/src/utils/params.js +64 -6
  284. package/dist/src/utils/permission-errors.d.ts +11 -0
  285. package/dist/src/utils/permission-errors.js +17 -0
  286. package/dist/src/utils/plugins/core-plugins.js +4 -0
  287. package/dist/src/utils/prompt-helpers.d.ts +53 -0
  288. package/dist/src/utils/prompt-helpers.js +111 -0
  289. package/dist/src/utils/socket-refused-exit-code.d.ts +15 -0
  290. package/dist/src/utils/socket-refused-exit-code.js +18 -0
  291. package/dist/src/utils/write-formatted-json-file.d.ts +3 -2
  292. package/dist/src/utils/write-formatted-json-file.js +5 -4
  293. package/package.json +33 -24
  294. package/dist/src/generators/internal-utils/format-changed-files-with-prettier-if-available.js +0 -88
  295. package/dist/src/utils/is-using-prettier.d.ts +0 -3
  296. package/dist/src/utils/is-using-prettier.js +0 -62
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BunCatalogManager = void 0;
4
+ const manager_1 = require("./manager");
5
+ const bun_manager_utils_1 = require("./bun-manager-utils");
6
+ const BUN_CATALOG_FILENAME = 'package.json';
7
+ /**
8
+ * Bun-specific catalog manager implementation.
9
+ *
10
+ * Bun declares catalogs in the root package.json `catalog`/`catalogs` fields,
11
+ * either at the top level or nested under the object form of `workspaces`.
12
+ * Unlike pnpm, the name "default" is not special: `catalog:` resolves only
13
+ * against `catalog`, and `catalog:default` against `catalogs.default`.
14
+ */
15
+ class BunCatalogManager {
16
+ constructor() {
17
+ this.name = 'bun';
18
+ this.catalogProtocol = 'catalog:';
19
+ // Parsed fs-root definitions, cached per pass. See readBunCatalogDefinitions.
20
+ this.definitionsByRoot = new Map();
21
+ }
22
+ isCatalogReference(version) {
23
+ return version.startsWith(this.catalogProtocol);
24
+ }
25
+ parseCatalogReference(version) {
26
+ if (!this.isCatalogReference(version)) {
27
+ return null;
28
+ }
29
+ const catalogName = version.substring(this.catalogProtocol.length).trim();
30
+ // Only an empty/whitespace name selects the default catalog; "default" is
31
+ // a regular named catalog in bun.
32
+ const isDefault = !catalogName;
33
+ return {
34
+ catalogName: isDefault ? undefined : catalogName,
35
+ isDefaultCatalog: isDefault,
36
+ };
37
+ }
38
+ getCatalogDefinitionFilePaths() {
39
+ return [BUN_CATALOG_FILENAME];
40
+ }
41
+ getCatalogDefinitions(treeOrRoot) {
42
+ return (0, bun_manager_utils_1.readBunCatalogDefinitions)(BUN_CATALOG_FILENAME, treeOrRoot, this.definitionsByRoot);
43
+ }
44
+ resolveCatalogReference(treeOrRoot, packageName, version) {
45
+ const catalogRef = this.parseCatalogReference(version);
46
+ if (!catalogRef) {
47
+ return null;
48
+ }
49
+ const catalogDefs = this.getCatalogDefinitions(treeOrRoot);
50
+ if (!catalogDefs) {
51
+ return null;
52
+ }
53
+ let catalogToUse;
54
+ if (catalogRef.isDefaultCatalog) {
55
+ catalogToUse = catalogDefs.catalog;
56
+ }
57
+ else if (catalogRef.catalogName) {
58
+ catalogToUse = catalogDefs.catalogs?.[catalogRef.catalogName];
59
+ }
60
+ return catalogToUse?.[packageName] || null;
61
+ }
62
+ getCatalogReferencesForPackage(treeOrRoot, packageName) {
63
+ return (0, manager_1.collectCatalogReferencesForPackage)(this, treeOrRoot, packageName);
64
+ }
65
+ validateCatalogReference(treeOrRoot, packageName, version) {
66
+ const catalogRef = this.parseCatalogReference(version);
67
+ if (!catalogRef) {
68
+ throw new Error(`Invalid catalog reference syntax: "${version}". Expected format: "catalog:" or "catalog:name"`);
69
+ }
70
+ const catalogDefs = this.getCatalogDefinitions(treeOrRoot);
71
+ if (!catalogDefs) {
72
+ throw new Error((0, manager_1.formatCatalogError)(`Cannot get Bun catalog definitions. No catalog defined in ${BUN_CATALOG_FILENAME}.`, [
73
+ `Add a "catalog" or "catalogs" field to ${BUN_CATALOG_FILENAME} in your workspace root`,
74
+ ]));
75
+ }
76
+ let catalogToUse;
77
+ if (catalogRef.isDefaultCatalog) {
78
+ catalogToUse = catalogDefs.catalog;
79
+ if (!catalogToUse) {
80
+ const availableCatalogs = Object.keys(catalogDefs.catalogs || {});
81
+ const suggestions = [
82
+ `Define a default catalog in ${BUN_CATALOG_FILENAME} under the "catalog" key`,
83
+ ];
84
+ if (availableCatalogs.length > 0) {
85
+ suggestions.push(`Or select from the available named catalogs: ${availableCatalogs
86
+ .map((c) => `"catalog:${c}"`)
87
+ .join(', ')}`);
88
+ }
89
+ throw new Error((0, manager_1.formatCatalogError)(`No default catalog defined in ${BUN_CATALOG_FILENAME}`, suggestions));
90
+ }
91
+ }
92
+ else if (catalogRef.catalogName) {
93
+ catalogToUse = catalogDefs.catalogs?.[catalogRef.catalogName];
94
+ if (!catalogToUse) {
95
+ const availableCatalogs = Object.keys(catalogDefs.catalogs || {});
96
+ const suggestions = [
97
+ `Define the catalog in ${BUN_CATALOG_FILENAME} under the "catalogs" key`,
98
+ ];
99
+ if (availableCatalogs.length > 0) {
100
+ suggestions.push(`Or select from the available named catalogs: ${availableCatalogs
101
+ .map((c) => `"catalog:${c}"`)
102
+ .join(', ')}`);
103
+ }
104
+ if (catalogDefs.catalog) {
105
+ suggestions.push(`Or use the default catalog ("catalog:")`);
106
+ }
107
+ throw new Error((0, manager_1.formatCatalogError)(`Catalog "${catalogRef.catalogName}" not found in ${BUN_CATALOG_FILENAME}`, suggestions));
108
+ }
109
+ }
110
+ if (!catalogToUse[packageName]) {
111
+ const catalogName = catalogRef.isDefaultCatalog
112
+ ? 'default catalog ("catalog")'
113
+ : `catalog '${catalogRef.catalogName}'`;
114
+ const availablePackages = Object.keys(catalogToUse);
115
+ const suggestions = [
116
+ `Add "${packageName}" to ${catalogName} in ${BUN_CATALOG_FILENAME}`,
117
+ ];
118
+ if (availablePackages.length > 0) {
119
+ suggestions.push(`Or select from the available packages in ${catalogName}: ${availablePackages
120
+ .map((p) => `"${p}"`)
121
+ .join(', ')}`);
122
+ }
123
+ throw new Error((0, manager_1.formatCatalogError)(`Package "${packageName}" not found in ${catalogName}`, suggestions));
124
+ }
125
+ }
126
+ updateCatalogVersions(treeOrRoot, updates) {
127
+ (0, bun_manager_utils_1.updateBunCatalogVersionsInFile)(BUN_CATALOG_FILENAME, treeOrRoot, updates);
128
+ }
129
+ }
130
+ exports.BunCatalogManager = BunCatalogManager;
@@ -4,7 +4,7 @@ import type { CatalogManager } from './manager';
4
4
  import { getCatalogManager } from './manager-factory';
5
5
  export { type CatalogManager, getCatalogManager };
6
6
  /**
7
- * Dereferences a pnpm/yarn catalog reference to a concrete version spec. Returns
7
+ * Dereferences a pnpm/yarn/bun catalog reference to a concrete version spec. Returns
8
8
  * the input unchanged when it is not a catalog reference (or no catalog manager
9
9
  * applies). Throws when the reference cannot be resolved.
10
10
  */
@@ -9,7 +9,7 @@ const workspace_root_1 = require("../workspace-root");
9
9
  const manager_factory_1 = require("./manager-factory");
10
10
  Object.defineProperty(exports, "getCatalogManager", { enumerable: true, get: function () { return manager_factory_1.getCatalogManager; } });
11
11
  /**
12
- * Dereferences a pnpm/yarn catalog reference to a concrete version spec. Returns
12
+ * Dereferences a pnpm/yarn/bun catalog reference to a concrete version spec. Returns
13
13
  * the input unchanged when it is not a catalog reference (or no catalog manager
14
14
  * applies). Throws when the reference cannot be resolved.
15
15
  */
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getCatalogManager = getCatalogManager;
4
4
  const package_manager_1 = require("../package-manager");
5
+ const bun_manager_1 = require("./bun-manager");
5
6
  const pnpm_manager_1 = require("./pnpm-manager");
6
7
  const yarn_manager_1 = require("./yarn-manager");
7
8
  /**
@@ -14,6 +15,8 @@ function getCatalogManager(workspaceRoot) {
14
15
  return new pnpm_manager_1.PnpmCatalogManager();
15
16
  case 'yarn':
16
17
  return new yarn_manager_1.YarnCatalogManager();
18
+ case 'bun':
19
+ return new bun_manager_1.BunCatalogManager();
17
20
  default:
18
21
  return null;
19
22
  }
@@ -5,4 +5,11 @@ export declare function updateCatalogVersionsInFile(filename: string, treeOrRoot
5
5
  packageName: string;
6
6
  version: string;
7
7
  catalogName?: string;
8
- }>): void;
8
+ }>, options?: {
9
+ /**
10
+ * Treat "default" as an alias for the `catalog` field and route default
11
+ * updates through a populated `catalogs.default` (pnpm semantics). When
12
+ * false, "default" is an ordinary named catalog (yarn semantics).
13
+ */
14
+ aliasDefaultCatalog?: boolean;
15
+ }): void;
@@ -136,7 +136,8 @@ function readCatalogDefinitions(filename, treeOrRoot, cache) {
136
136
  }
137
137
  return readCatalogConfigFromTree(filename, treeOrRoot);
138
138
  }
139
- function updateCatalogVersionsInFile(filename, treeOrRoot, updates) {
139
+ function updateCatalogVersionsInFile(filename, treeOrRoot, updates, options) {
140
+ const aliasDefaultCatalog = options?.aliasDefaultCatalog ?? true;
140
141
  let checkExists;
141
142
  let readYaml;
142
143
  let writeYaml;
@@ -194,13 +195,17 @@ function updateCatalogVersionsInFile(filename, treeOrRoot, updates) {
194
195
  let hasChanges = false;
195
196
  for (const update of updates) {
196
197
  const { packageName, version, catalogName } = update;
197
- const normalizedCatalogName = catalogName === 'default' ? undefined : catalogName;
198
+ const normalizedCatalogName = aliasDefaultCatalog && catalogName === 'default'
199
+ ? undefined
200
+ : catalogName;
198
201
  let targetPath;
199
202
  if (!normalizedCatalogName) {
200
203
  // An empty `catalog:` placeholder must not claim the default route
201
204
  // when `catalogs.default` is populated; that would create a
202
- // duplicate-default config rejected by pnpm.
203
- if (isMapAt(doc, ['catalog'])) {
205
+ // duplicate-default config rejected by pnpm. Without the alias,
206
+ // "default" is an ordinary named catalog and the default route is
207
+ // always the `catalog` field.
208
+ if (!aliasDefaultCatalog || isMapAt(doc, ['catalog'])) {
204
209
  targetPath = ['catalog', packageName];
205
210
  }
206
211
  else if (existsAt(doc, ['catalogs', 'default'])) {
@@ -1,6 +1,12 @@
1
1
  import type { Tree } from '../../generators/tree';
2
- import type { CatalogDefinitions, CatalogReference } from './types';
2
+ import type { CatalogDefinitions, CatalogReference, CatalogReferenceMatch } from './types';
3
3
  export declare function formatCatalogError(error: string, suggestions: string[]): string;
4
+ /**
5
+ * Shared implementation of getCatalogReferencesForPackage: enumerates the
6
+ * default and named catalog references and keeps those the manager resolves,
7
+ * so per-manager default-catalog semantics apply without duplication.
8
+ */
9
+ export declare function collectCatalogReferencesForPackage(manager: CatalogManager, treeOrRoot: Tree | string, packageName: string): CatalogReferenceMatch[];
4
10
  /**
5
11
  * Interface for catalog managers that handle package manager-specific catalog implementations.
6
12
  */
@@ -19,6 +25,12 @@ export interface CatalogManager {
19
25
  */
20
26
  resolveCatalogReference(workspaceRoot: string, packageName: string, version: string): string | null;
21
27
  resolveCatalogReference(tree: Tree, packageName: string, version: string): string | null;
28
+ /**
29
+ * Get every catalog reference that resolves to a version for a package,
30
+ * following the package manager's own default-catalog semantics.
31
+ */
32
+ getCatalogReferencesForPackage(workspaceRoot: string, packageName: string): CatalogReferenceMatch[];
33
+ getCatalogReferencesForPackage(tree: Tree, packageName: string): CatalogReferenceMatch[];
22
34
  /**
23
35
  * Check that a catalog reference is valid.
24
36
  */
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.formatCatalogError = formatCatalogError;
4
+ exports.collectCatalogReferencesForPackage = collectCatalogReferencesForPackage;
4
5
  function formatCatalogError(error, suggestions) {
5
6
  let message = error;
6
7
  if (suggestions.length > 0) {
@@ -11,3 +12,32 @@ function formatCatalogError(error, suggestions) {
11
12
  }
12
13
  return message;
13
14
  }
15
+ /**
16
+ * Shared implementation of getCatalogReferencesForPackage: enumerates the
17
+ * default and named catalog references and keeps those the manager resolves,
18
+ * so per-manager default-catalog semantics apply without duplication.
19
+ */
20
+ function collectCatalogReferencesForPackage(manager, treeOrRoot, packageName) {
21
+ // The overload pairs don't accept the Tree | string union directly.
22
+ const source = treeOrRoot;
23
+ const catalogDefs = manager.getCatalogDefinitions(source);
24
+ if (!catalogDefs) {
25
+ return [];
26
+ }
27
+ const catalogRefs = ['catalog:'];
28
+ for (const name of Object.keys(catalogDefs.catalogs ?? {})) {
29
+ // Skip names the manager treats as the default catalog (e.g. pnpm's
30
+ // "default") — already covered by the `catalog:` candidate.
31
+ if (!manager.parseCatalogReference(`catalog:${name}`)?.isDefaultCatalog) {
32
+ catalogRefs.push(`catalog:${name}`);
33
+ }
34
+ }
35
+ const matches = [];
36
+ for (const catalogRef of catalogRefs) {
37
+ const versionSpec = manager.resolveCatalogReference(source, packageName, catalogRef);
38
+ if (versionSpec) {
39
+ matches.push({ catalogRef, versionSpec });
40
+ }
41
+ }
42
+ return matches;
43
+ }
@@ -1,6 +1,6 @@
1
1
  import type { Tree } from '../../generators/tree';
2
2
  import { type CatalogManager } from './manager';
3
- import type { CatalogDefinitions, CatalogReference } from './types';
3
+ import type { CatalogDefinitions, CatalogReference, CatalogReferenceMatch } from './types';
4
4
  /**
5
5
  * PNPM-specific catalog manager implementation
6
6
  */
@@ -13,6 +13,7 @@ export declare class PnpmCatalogManager implements CatalogManager {
13
13
  getCatalogDefinitionFilePaths(): string[];
14
14
  getCatalogDefinitions(treeOrRoot: Tree | string): CatalogDefinitions | null;
15
15
  resolveCatalogReference(treeOrRoot: Tree | string, packageName: string, version: string): string | null;
16
+ getCatalogReferencesForPackage(treeOrRoot: Tree | string, packageName: string): CatalogReferenceMatch[];
16
17
  validateCatalogReference(treeOrRoot: Tree | string, packageName: string, version: string): void;
17
18
  updateCatalogVersions(treeOrRoot: Tree | string, updates: Array<{
18
19
  packageName: string;
@@ -54,6 +54,9 @@ class PnpmCatalogManager {
54
54
  }
55
55
  return catalogToUse?.[packageName] || null;
56
56
  }
57
+ getCatalogReferencesForPackage(treeOrRoot, packageName) {
58
+ return (0, manager_1.collectCatalogReferencesForPackage)(this, treeOrRoot, packageName);
59
+ }
57
60
  validateCatalogReference(treeOrRoot, packageName, version) {
58
61
  const catalogRef = this.parseCatalogReference(version);
59
62
  if (!catalogRef) {
@@ -2,6 +2,10 @@ export interface CatalogReference {
2
2
  catalogName?: string;
3
3
  isDefaultCatalog: boolean;
4
4
  }
5
+ export interface CatalogReferenceMatch {
6
+ catalogRef: string;
7
+ versionSpec: string;
8
+ }
5
9
  export interface CatalogEntry {
6
10
  [packageName: string]: string;
7
11
  }
@@ -1,8 +1,11 @@
1
1
  import type { Tree } from '../../generators/tree';
2
2
  import { type CatalogManager } from './manager';
3
- import type { CatalogDefinitions, CatalogReference } from './types';
3
+ import type { CatalogDefinitions, CatalogReference, CatalogReferenceMatch } from './types';
4
4
  /**
5
- * Yarn Berry (v4+) catalog manager implementation
5
+ * Yarn Berry (v4.10+) catalog manager implementation.
6
+ *
7
+ * Unlike pnpm, the name "default" is not special: `catalog:` resolves only
8
+ * against `catalog`, and `catalog:default` against `catalogs.default`.
6
9
  */
7
10
  export declare class YarnCatalogManager implements CatalogManager {
8
11
  readonly name = "yarn";
@@ -13,6 +16,7 @@ export declare class YarnCatalogManager implements CatalogManager {
13
16
  getCatalogDefinitionFilePaths(): string[];
14
17
  getCatalogDefinitions(treeOrRoot: Tree | string): CatalogDefinitions | null;
15
18
  resolveCatalogReference(treeOrRoot: Tree | string, packageName: string, version: string): string | null;
19
+ getCatalogReferencesForPackage(treeOrRoot: Tree | string, packageName: string): CatalogReferenceMatch[];
16
20
  validateCatalogReference(treeOrRoot: Tree | string, packageName: string, version: string): void;
17
21
  updateCatalogVersions(treeOrRoot: Tree | string, updates: Array<{
18
22
  packageName: string;
@@ -5,7 +5,10 @@ const manager_1 = require("./manager");
5
5
  const manager_utils_1 = require("./manager-utils");
6
6
  const YARNRC_FILENAME = '.yarnrc.yml';
7
7
  /**
8
- * Yarn Berry (v4+) catalog manager implementation
8
+ * Yarn Berry (v4.10+) catalog manager implementation.
9
+ *
10
+ * Unlike pnpm, the name "default" is not special: `catalog:` resolves only
11
+ * against `catalog`, and `catalog:default` against `catalogs.default`.
9
12
  */
10
13
  class YarnCatalogManager {
11
14
  constructor() {
@@ -22,8 +25,9 @@ class YarnCatalogManager {
22
25
  return null;
23
26
  }
24
27
  const catalogName = version.substring(this.catalogProtocol.length);
25
- // Normalize both "catalog:" and "catalog:default" to the same representation
26
- const isDefault = !catalogName || catalogName === 'default';
28
+ // Only an empty name selects the default catalog; unlike pnpm, "default"
29
+ // is a regular named catalog in yarn.
30
+ const isDefault = !catalogName;
27
31
  return {
28
32
  catalogName: isDefault ? undefined : catalogName,
29
33
  isDefaultCatalog: isDefault,
@@ -46,14 +50,16 @@ class YarnCatalogManager {
46
50
  }
47
51
  let catalogToUse;
48
52
  if (catalogRef.isDefaultCatalog) {
49
- // Check both locations for default catalog
50
- catalogToUse = catalogDefs.catalog ?? catalogDefs.catalogs?.default;
53
+ catalogToUse = catalogDefs.catalog;
51
54
  }
52
55
  else if (catalogRef.catalogName) {
53
56
  catalogToUse = catalogDefs.catalogs?.[catalogRef.catalogName];
54
57
  }
55
58
  return catalogToUse?.[packageName] || null;
56
59
  }
60
+ getCatalogReferencesForPackage(treeOrRoot, packageName) {
61
+ return (0, manager_1.collectCatalogReferencesForPackage)(this, treeOrRoot, packageName);
62
+ }
57
63
  validateCatalogReference(treeOrRoot, packageName, version) {
58
64
  const catalogRef = this.parseCatalogReference(version);
59
65
  if (!catalogRef) {
@@ -65,13 +71,9 @@ class YarnCatalogManager {
65
71
  }
66
72
  let catalogToUse;
67
73
  if (catalogRef.isDefaultCatalog) {
68
- const hasCatalog = !!catalogDefs.catalog;
69
- const hasCatalogsDefault = !!catalogDefs.catalogs?.default;
70
- // Error if both defined
71
- if (hasCatalog && hasCatalogsDefault) {
72
- throw new Error("The 'default' catalog was defined multiple times. Use the 'catalog' field or 'catalogs.default', but not both.");
73
- }
74
- catalogToUse = catalogDefs.catalog ?? catalogDefs.catalogs?.default;
74
+ // Yarn's default catalog is only the `catalog` field; unlike pnpm,
75
+ // `catalogs.default` does not act as a fallback.
76
+ catalogToUse = catalogDefs.catalog;
75
77
  if (!catalogToUse) {
76
78
  const availableCatalogs = Object.keys(catalogDefs.catalogs || {});
77
79
  const suggestions = [
@@ -88,12 +90,7 @@ class YarnCatalogManager {
88
90
  else if (catalogRef.catalogName) {
89
91
  catalogToUse = catalogDefs.catalogs?.[catalogRef.catalogName];
90
92
  if (!catalogToUse) {
91
- const availableCatalogs = Object.keys(catalogDefs.catalogs || {}).filter((c) => c !== 'default');
92
- const defaultCatalog = !!catalogDefs.catalog
93
- ? 'catalog'
94
- : !catalogDefs.catalogs?.default
95
- ? 'catalogs.default'
96
- : null;
93
+ const availableCatalogs = Object.keys(catalogDefs.catalogs || {});
97
94
  const suggestions = [
98
95
  `Define the catalog in ${YARNRC_FILENAME} under the "catalogs" key`,
99
96
  ];
@@ -102,24 +99,16 @@ class YarnCatalogManager {
102
99
  .map((c) => `"catalog:${c}"`)
103
100
  .join(', ')}`);
104
101
  }
105
- if (defaultCatalog) {
106
- suggestions.push(`Or use the default catalog ("${defaultCatalog}")`);
102
+ if (catalogDefs.catalog) {
103
+ suggestions.push(`Or use the default catalog ("catalog:")`);
107
104
  }
108
105
  throw new Error((0, manager_1.formatCatalogError)(`Catalog "${catalogRef.catalogName}" not found in ${YARNRC_FILENAME}`, suggestions));
109
106
  }
110
107
  }
111
108
  if (!catalogToUse[packageName]) {
112
- let catalogName;
113
- if (catalogRef.isDefaultCatalog) {
114
- // Context-aware messaging based on which location exists
115
- const hasCatalog = !!catalogDefs.catalog;
116
- catalogName = hasCatalog
117
- ? 'default catalog ("catalog")'
118
- : 'default catalog ("catalogs.default")';
119
- }
120
- else {
121
- catalogName = `catalog '${catalogRef.catalogName}'`;
122
- }
109
+ const catalogName = catalogRef.isDefaultCatalog
110
+ ? 'default catalog ("catalog")'
111
+ : `catalog '${catalogRef.catalogName}'`;
123
112
  const availablePackages = Object.keys(catalogToUse);
124
113
  const suggestions = [
125
114
  `Add "${packageName}" to ${catalogName} in ${YARNRC_FILENAME}`,
@@ -133,7 +122,9 @@ class YarnCatalogManager {
133
122
  }
134
123
  }
135
124
  updateCatalogVersions(treeOrRoot, updates) {
136
- (0, manager_utils_1.updateCatalogVersionsInFile)(YARNRC_FILENAME, treeOrRoot, updates);
125
+ (0, manager_utils_1.updateCatalogVersionsInFile)(YARNRC_FILENAME, treeOrRoot, updates, {
126
+ aliasDefaultCatalog: false,
127
+ });
137
128
  }
138
129
  }
139
130
  exports.YarnCatalogManager = YarnCatalogManager;
@@ -1,7 +1,37 @@
1
- import { type ExecOptions, type ExecSyncOptions } from 'child_process';
1
+ import { type ExecOptions, type ExecSyncOptions, type SpawnSyncOptions } from 'child_process';
2
2
  import { PackageManagerCommands } from './package-manager';
3
3
  import { ChildProcess } from '../native';
4
4
  export declare function getRunNxBaseCommand(packageManagerCommand?: PackageManagerCommands, cwd?: string): string;
5
+ /**
6
+ * Locate an nx entry point to spawn for the workspace at `root`, so a caller
7
+ * can run it directly instead of going through a shell. `findInstalledNxBin`
8
+ * decides which one.
9
+ *
10
+ * Null means nothing may be spawned directly, leaving the caller to fall back
11
+ * to `getRunNxBaseCommand`. Null is therefore always safe: it costs the
12
+ * argument fidelity a direct spawn buys, never the ability to run.
13
+ */
14
+ export declare function getNxBin(root?: string): string | null;
15
+ /**
16
+ * The entry point the nx installed directly under `dir` names, with no ascent
17
+ * to `dir`'s ancestors. For an installation that declares nx itself, such as
18
+ * the temp CLI `nx migrate` builds, an ancestor's nx is never the right answer.
19
+ */
20
+ export declare function readInstalledNxBin(dir: string): string | null;
21
+ /**
22
+ * Run a nx command, passing the arguments through as an argv array.
23
+ *
24
+ * When `getNxBin` names an entry point, the child is spawned directly with no
25
+ * shell in between, so every argument reaches the child exactly as provided:
26
+ * shell metacharacters (`(`, `%`, `^`, spaces, quotes) are data, not syntax.
27
+ * Otherwise falls back to the package-manager + shell path, where every
28
+ * argument goes through `quoteShellArg` and the Windows limits it documents
29
+ * apply.
30
+ */
31
+ export declare function runNxArgvSync(argv: string[], options?: SpawnSyncOptions & {
32
+ cwd?: string;
33
+ nxBin?: string;
34
+ }): void;
5
35
  export declare function runNxSync(cmd: string, options?: ExecSyncOptions & {
6
36
  cwd?: string;
7
37
  packageManagerCommand?: PackageManagerCommands;
@@ -2,6 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PseudoTtyProcess = void 0;
4
4
  exports.getRunNxBaseCommand = getRunNxBaseCommand;
5
+ exports.getNxBin = getNxBin;
6
+ exports.readInstalledNxBin = readInstalledNxBin;
7
+ exports.runNxArgvSync = runNxArgvSync;
5
8
  exports.runNxSync = runNxSync;
6
9
  exports.runNxAsync = runNxAsync;
7
10
  const child_process_1 = require("child_process");
@@ -10,9 +13,14 @@ const path_1 = require("path");
10
13
  const package_manager_1 = require("./package-manager");
11
14
  const workspace_root_1 = require("./workspace-root");
12
15
  const exit_codes_1 = require("./exit-codes");
16
+ const fileutils_1 = require("./fileutils");
17
+ const shell_quoting_1 = require("./shell-quoting");
13
18
  function getRunNxBaseCommand(packageManagerCommand, cwd = process.cwd()) {
14
19
  if ((0, fs_1.existsSync)((0, path_1.join)(workspace_root_1.workspaceRoot, 'package.json'))) {
15
20
  if (!packageManagerCommand) {
21
+ // `readLocalNxVersion` (command-line/migrate/migrate.ts) mirrors this
22
+ // selector to predict which nx a spawn will run, for the workspaces
23
+ // `getNxBin` declines to resolve; keep the two in sync.
16
24
  const pm = (0, package_manager_1.detectPackageManager)(workspace_root_1.workspaceRoot);
17
25
  packageManagerCommand = (0, package_manager_1.getPackageManagerCommand)(pm, workspace_root_1.workspaceRoot);
18
26
  }
@@ -28,6 +36,101 @@ function getRunNxBaseCommand(packageManagerCommand, cwd = process.cwd()) {
28
36
  }
29
37
  }
30
38
  }
39
+ /**
40
+ * Locate an nx entry point to spawn for the workspace at `root`, so a caller
41
+ * can run it directly instead of going through a shell. `findInstalledNxBin`
42
+ * decides which one.
43
+ *
44
+ * Null means nothing may be spawned directly, leaving the caller to fall back
45
+ * to `getRunNxBaseCommand`. Null is therefore always safe: it costs the
46
+ * argument fidelity a direct spawn buys, never the ability to run.
47
+ */
48
+ function getNxBin(root = workspace_root_1.workspaceRoot) {
49
+ // A workspace with no root package.json runs nx through the `./nx` wrapper,
50
+ // which reinstalls `.nx/installation` whenever it drifts from nx.json's
51
+ // `installation.version`. Spawning the resolved entry point would skip that
52
+ // sync, and a migration is precisely when the version changes.
53
+ if (!(0, fs_1.existsSync)((0, path_1.join)(root, 'package.json'))) {
54
+ return null;
55
+ }
56
+ return findInstalledNxBin(root);
57
+ }
58
+ /**
59
+ * The entry point the nx installed directly under `dir` names, with no ascent
60
+ * to `dir`'s ancestors. For an installation that declares nx itself, such as
61
+ * the temp CLI `nx migrate` builds, an ancestor's nx is never the right answer.
62
+ */
63
+ function readInstalledNxBin(dir) {
64
+ const packageDir = (0, path_1.join)(dir, 'node_modules', 'nx');
65
+ const manifest = (0, path_1.join)(packageDir, 'package.json');
66
+ if (!(0, fs_1.existsSync)(manifest)) {
67
+ return null;
68
+ }
69
+ let bin;
70
+ try {
71
+ ({ bin } = (0, fileutils_1.readJsonFile)(manifest));
72
+ }
73
+ catch {
74
+ return null;
75
+ }
76
+ // npm accepts both the single-entry shorthand and the map form.
77
+ const entry = typeof bin === 'string' ? bin : bin?.nx;
78
+ return typeof entry === 'string' ? (0, path_1.join)(packageDir, entry) : null;
79
+ }
80
+ // Ascend to the nearest installed nx and take the entry point its `bin` field
81
+ // names, which is the file a package manager links into `node_modules/.bin`.
82
+ // Deliberately npx-shaped: npx and bun ascend unconditionally while pnpm and
83
+ // yarn stop at an outer workspace, so this can name an nx those two would
84
+ // decline to run.
85
+ //
86
+ // Deliberately not a resolver. Resolvers answer from NODE_PATH once their
87
+ // explicit paths miss, and `nxCliPath` (command-line/migrate/migrate.ts) points
88
+ // NODE_PATH at the temp installation before spawning it; they also answer
89
+ // through package self-reference, which hands back the running nx whatever
90
+ // `paths` they are given. Either one lets the temp installation hand off to
91
+ // itself, which for `--run-migrations` re-enters the same hand-off and respawns
92
+ // without end.
93
+ function findInstalledNxBin(root) {
94
+ for (let dir = root;; dir = (0, path_1.dirname)(dir)) {
95
+ // The nearest install wins, so an unusable manifest there ends the search
96
+ // rather than deferring to an ancestor.
97
+ if ((0, fs_1.existsSync)((0, path_1.join)(dir, 'node_modules', 'nx', 'package.json'))) {
98
+ return readInstalledNxBin(dir);
99
+ }
100
+ if (dir === (0, path_1.dirname)(dir)) {
101
+ return null;
102
+ }
103
+ }
104
+ }
105
+ /**
106
+ * Run a nx command, passing the arguments through as an argv array.
107
+ *
108
+ * When `getNxBin` names an entry point, the child is spawned directly with no
109
+ * shell in between, so every argument reaches the child exactly as provided:
110
+ * shell metacharacters (`(`, `%`, `^`, spaces, quotes) are data, not syntax.
111
+ * Otherwise falls back to the package-manager + shell path, where every
112
+ * argument goes through `quoteShellArg` and the Windows limits it documents
113
+ * apply.
114
+ */
115
+ function runNxArgvSync(argv, options) {
116
+ let { nxBin, ...spawnOptions } = options ?? {};
117
+ spawnOptions.cwd ??= process.cwd();
118
+ spawnOptions.windowsHide ??= true;
119
+ nxBin ??= getNxBin((0, workspace_root_1.workspaceRootInner)(spawnOptions.cwd, null) ?? workspace_root_1.workspaceRoot);
120
+ if (!nxBin) {
121
+ runNxSync(argv.map(shell_quoting_1.quoteShellArg).join(' '), spawnOptions);
122
+ return;
123
+ }
124
+ const result = (0, child_process_1.spawnSync)(process.execPath, [nxBin, ...argv], spawnOptions);
125
+ if (result.error) {
126
+ throw result.error;
127
+ }
128
+ if (result.status !== 0) {
129
+ const error = new Error(`Command failed: nx ${argv.join(' ')} (exit code ${result.status})`);
130
+ error.status = result.status ?? 1;
131
+ throw error;
132
+ }
133
+ }
31
134
  function runNxSync(cmd, options) {
32
135
  let { packageManagerCommand, ...execSyncOptions } = options ?? {};
33
136
  execSyncOptions.cwd ??= process.cwd();
@@ -1,4 +1,10 @@
1
- export declare function chunkify(target: string[], maxChunkLength?: number): string[][];
1
+ export declare function chunkify(target: string[], maxChunkLength?: number,
2
+ /**
3
+ * How long each entry will be once it reaches the command line. Callers that
4
+ * quote or escape afterwards pass that transformation's length here, so the
5
+ * chunk is sized against what is actually spawned rather than the raw string.
6
+ */
7
+ measure?: (item: string) => number): string[][];
2
8
  /**
3
9
  * Get the maximum length of a command-line argument string based on current platform
4
10
  *