@ohos-ports/nx 23.3.0-beta.3 → 24.0.2-beta.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 (301) hide show
  1. package/README.md +3 -6
  2. package/dist/bin/nx.js +2 -2
  3. package/dist/bin/post-install.js +5 -3
  4. package/dist/nx-cloud-internals.d.ts +1 -0
  5. package/dist/nx-cloud-internals.js +7 -1
  6. package/dist/src/adapter/ngcli-adapter.js +2 -2
  7. package/dist/src/ai/clone-ai-config-repo.js +49 -12
  8. package/dist/src/command-line/add/add.d.ts +2 -0
  9. package/dist/src/command-line/add/add.js +24 -6
  10. package/dist/src/command-line/affected/affected.js +2 -2
  11. package/dist/src/command-line/configure-ai-agents/configure-ai-agents.js +1 -13
  12. package/dist/src/command-line/graph/graph.js +38 -10
  13. package/dist/src/command-line/init/command-object.js +0 -12
  14. package/dist/src/command-line/init/implementation/add-nx-to-nest.js +21 -62
  15. package/dist/src/command-line/init/init-v2.js +1 -3
  16. package/dist/src/command-line/migrate/agentic/close-agent-session.d.ts +1 -1
  17. package/dist/src/command-line/migrate/agentic/close-agent-session.js +4 -3
  18. package/dist/src/command-line/migrate/agentic/definitions.d.ts +1 -3
  19. package/dist/src/command-line/migrate/agentic/definitions.js +5 -97
  20. package/dist/src/command-line/migrate/agentic/handoff-gitignore.d.ts +7 -45
  21. package/dist/src/command-line/migrate/agentic/handoff-gitignore.js +9 -51
  22. package/dist/src/command-line/migrate/agentic/handoff.d.ts +1 -43
  23. package/dist/src/command-line/migrate/agentic/handoff.js +3 -119
  24. package/dist/src/command-line/migrate/agentic/instruction-files.d.ts +0 -21
  25. package/dist/src/command-line/migrate/agentic/instruction-files.js +6 -27
  26. package/dist/src/command-line/migrate/agentic/master/run-master-session.d.ts +19 -1
  27. package/dist/src/command-line/migrate/agentic/master/run-master-session.js +88 -49
  28. package/dist/src/command-line/migrate/agentic/master/spawn-master.d.ts +1 -0
  29. package/dist/src/command-line/migrate/agentic/master/spawn-master.js +86 -24
  30. package/dist/src/command-line/migrate/agentic/print-dropped-agent-context.d.ts +2 -2
  31. package/dist/src/command-line/migrate/agentic/print-dropped-agent-context.js +2 -2
  32. package/dist/src/command-line/migrate/agentic/prompts/fragments.d.ts +1 -12
  33. package/dist/src/command-line/migrate/agentic/prompts/fragments.js +8 -17
  34. package/dist/src/command-line/migrate/agentic/prompts/shared-rendering.d.ts +0 -15
  35. package/dist/src/command-line/migrate/agentic/prompts/shared-rendering.js +3 -100
  36. package/dist/src/command-line/migrate/agentic/select.d.ts +12 -6
  37. package/dist/src/command-line/migrate/agentic/select.js +38 -8
  38. package/dist/src/command-line/migrate/agentic/types.d.ts +9 -68
  39. package/dist/src/command-line/migrate/agentic/types.js +6 -8
  40. package/dist/src/command-line/migrate/command-object.js +6 -10
  41. package/dist/src/command-line/migrate/execute-migration.d.ts +6 -6
  42. package/dist/src/command-line/migrate/execute-migration.js +25 -15
  43. package/dist/src/command-line/migrate/migrate-analytics.d.ts +18 -1
  44. package/dist/src/command-line/migrate/migrate-analytics.js +38 -0
  45. package/dist/src/command-line/migrate/migrate-commits.d.ts +29 -17
  46. package/dist/src/command-line/migrate/migrate-commits.js +86 -32
  47. package/dist/src/command-line/migrate/migrate-config.d.ts +6 -6
  48. package/dist/src/command-line/migrate/migrate-config.js +12 -6
  49. package/dist/src/command-line/migrate/migrate-output.d.ts +1 -6
  50. package/dist/src/command-line/migrate/migrate-output.js +1 -10
  51. package/dist/src/command-line/migrate/migrate.d.ts +6 -30
  52. package/dist/src/command-line/migrate/migrate.js +257 -255
  53. package/dist/src/command-line/migrate/resolve-package-version.d.ts +2 -4
  54. package/dist/src/command-line/migrate/resolve-package-version.js +2 -35
  55. package/dist/src/command-line/migrate/run/agent-output.d.ts +2 -0
  56. package/dist/src/command-line/migrate/run/agent-output.js +9 -0
  57. package/dist/src/command-line/migrate/run/broker.d.ts +14 -5
  58. package/dist/src/command-line/migrate/run/broker.js +69 -21
  59. package/dist/src/command-line/migrate/run/clean-retry.js +4 -2
  60. package/dist/src/command-line/migrate/run/existing-run-report.d.ts +1 -1
  61. package/dist/src/command-line/migrate/run/existing-run-report.js +7 -5
  62. package/dist/src/command-line/migrate/run/give-up.d.ts +4 -3
  63. package/dist/src/command-line/migrate/run/give-up.js +8 -5
  64. package/dist/src/command-line/migrate/run/index.d.ts +7 -5
  65. package/dist/src/command-line/migrate/run/index.js +16 -1
  66. package/dist/src/command-line/migrate/run/issues.js +7 -2
  67. package/dist/src/command-line/migrate/run/orchestrator.d.ts +61 -4
  68. package/dist/src/command-line/migrate/run/orchestrator.js +397 -133
  69. package/dist/src/command-line/migrate/run/run-state.d.ts +17 -1
  70. package/dist/src/command-line/migrate/run/run-state.js +41 -2
  71. package/dist/src/command-line/migrate/run/runbook.d.ts +1 -0
  72. package/dist/src/command-line/migrate/run/runbook.js +115 -18
  73. package/dist/src/command-line/migrate/run/state-lock.d.ts +29 -4
  74. package/dist/src/command-line/migrate/run/state-lock.js +102 -10
  75. package/dist/src/command-line/migrate/run/state-machine.js +4 -1
  76. package/dist/src/command-line/migrate/run/util.d.ts +7 -2
  77. package/dist/src/command-line/migrate/run/util.js +30 -3
  78. package/dist/src/command-line/migrate/run/worker.d.ts +1 -1
  79. package/dist/src/command-line/migrate/run/worker.js +252 -250
  80. package/dist/src/command-line/migrate/sort-migrations.d.ts +1 -7
  81. package/dist/src/command-line/migrate/sort-migrations.js +1 -12
  82. package/dist/src/command-line/nx-cloud/connect/connect-to-nx-cloud.js +17 -12
  83. package/dist/src/command-line/release/changelog.js +9 -6
  84. package/dist/src/command-line/release/config/config.d.ts +1 -0
  85. package/dist/src/command-line/release/config/config.js +48 -9
  86. package/dist/src/command-line/release/release.js +2 -2
  87. package/dist/src/command-line/release/utils/git.js +8 -7
  88. package/dist/src/command-line/release/utils/interpolate-release-config.d.ts +6 -0
  89. package/dist/src/command-line/release/utils/interpolate-release-config.js +39 -0
  90. package/dist/src/command-line/release/utils/release-graph.d.ts +5 -0
  91. package/dist/src/command-line/release/utils/release-graph.js +1 -0
  92. package/dist/src/command-line/release/utils/remote-release-clients/github.js +5 -6
  93. package/dist/src/command-line/release/utils/remote-release-clients/gitlab.js +5 -6
  94. package/dist/src/command-line/release/utils/resolve-changelog-renderer.js +2 -2
  95. package/dist/src/command-line/release/utils/shared.js +10 -10
  96. package/dist/src/command-line/release/utils/version-plan-utils.d.ts +3 -12
  97. package/dist/src/command-line/release/utils/version-plan-utils.js +33 -55
  98. package/dist/src/command-line/release/version/version-actions.js +2 -1
  99. package/dist/src/command-line/release/version.js +5 -2
  100. package/dist/src/command-line/repair/repair.js +1 -1
  101. package/dist/src/command-line/report/report.js +1 -1
  102. package/dist/src/command-line/reset/reset.js +58 -62
  103. package/dist/src/command-line/run/executor-utils.js +1 -0
  104. package/dist/src/command-line/run/run-one.d.ts +20 -1
  105. package/dist/src/command-line/run/run-one.js +153 -5
  106. package/dist/src/command-line/run/run.js +2 -1
  107. package/dist/src/command-line/show/projects.js +5 -3
  108. package/dist/src/command-line/show/show-target/info.d.ts +10 -1
  109. package/dist/src/command-line/show/show-target/info.js +100 -15
  110. package/dist/src/command-line/show/show-target/inputs.js +10 -2
  111. package/dist/src/command-line/show/show-target/utils.js +1 -0
  112. package/dist/src/command-line/watch/command-object.js +3 -22
  113. package/dist/src/command-line/watch/watch.d.ts +0 -7
  114. package/dist/src/command-line/watch/watch.js +1 -1
  115. package/dist/src/command-line/yargs-utils/shared-options.js +1 -1
  116. package/dist/src/config/misc-interfaces.d.ts +18 -0
  117. package/dist/src/config/nx-json.d.ts +22 -11
  118. package/dist/src/config/task-graph.d.ts +1 -1
  119. package/dist/src/config/workspace-json-project-json.d.ts +88 -0
  120. package/dist/src/core/graph/main.js +1 -1
  121. package/dist/src/core/graph/runtime.js +1 -1
  122. package/dist/src/core/graph/styles.css +1 -1
  123. package/dist/src/core/graph/styles.js +1 -1
  124. package/dist/src/daemon/client/client.d.ts +15 -0
  125. package/dist/src/daemon/client/client.js +181 -71
  126. package/dist/src/daemon/client/daemon-socket-messenger.d.ts +1 -1
  127. package/dist/src/daemon/client/daemon-socket-messenger.js +2 -2
  128. package/dist/src/daemon/server/client-socket-context.js +1 -1
  129. package/dist/src/daemon/server/handle-configure-ai-agents.js +2 -2
  130. package/dist/src/daemon/server/handle-process-in-background.js +21 -9
  131. package/dist/src/daemon/server/handle-select-affected-tasks.d.ts +2 -1
  132. package/dist/src/daemon/server/handle-select-affected-tasks.js +21 -13
  133. package/dist/src/daemon/server/native-js-loader.d.ts +1 -0
  134. package/dist/src/daemon/server/native-js-loader.js +21 -0
  135. package/dist/src/daemon/server/nx-console-operations.js +2 -2
  136. package/dist/src/daemon/server/project-graph-incremental-recomputation.js +4 -8
  137. package/dist/src/daemon/server/server.d.ts +2 -1
  138. package/dist/src/daemon/server/server.js +17 -4
  139. package/dist/src/daemon/server/shutdown-utils.js +1 -4
  140. package/dist/src/daemon/server/start.d.ts +1 -0
  141. package/dist/src/daemon/server/start.js +2 -0
  142. package/dist/src/daemon/socket-utils.d.ts +11 -9
  143. package/dist/src/daemon/socket-utils.js +31 -61
  144. package/dist/src/daemon/tmp-dir.d.ts +19 -14
  145. package/dist/src/daemon/tmp-dir.js +142 -354
  146. package/dist/src/devkit-exports.d.ts +9 -1
  147. package/dist/src/devkit-exports.js +12 -1
  148. package/dist/src/devkit-internals.d.ts +6 -5
  149. package/dist/src/devkit-internals.js +13 -4
  150. package/dist/src/executors/run-commands/run-commands.impl.d.ts +4 -2
  151. package/dist/src/executors/run-commands/run-commands.impl.js +53 -27
  152. package/dist/src/executors/run-commands/running-tasks.d.ts +13 -4
  153. package/dist/src/executors/run-commands/running-tasks.js +148 -95
  154. package/dist/src/executors/run-commands/schema.json +1 -1
  155. package/dist/src/hasher/check-task-files.js +5 -8
  156. package/dist/src/hasher/file-hasher.js +9 -7
  157. package/dist/src/hasher/hash-task.js +4 -0
  158. package/dist/src/hasher/native-task-hasher-impl.js +3 -1
  159. package/dist/src/hasher/task-hasher.d.ts +2 -0
  160. package/dist/src/hasher/task-hasher.js +4 -1
  161. package/dist/src/migrations/update-23-2-0/set-cache-on-executor-target-defaults.d.ts +1 -2
  162. package/dist/src/migrations/update-23-2-0/set-cache-on-executor-target-defaults.js +6 -11
  163. package/dist/src/migrations/update-23-2-0/set-cache-on-executor-target-defaults.md +2 -2
  164. package/dist/src/migrations/update-24-0-0/enable-legacy-affected.d.ts +4 -0
  165. package/dist/src/migrations/update-24-0-0/enable-legacy-affected.js +15 -0
  166. package/dist/src/migrations/update-24-0-0/enable-legacy-affected.md +30 -0
  167. package/dist/src/migrations/update-24-0-0/find-custom-hashers.d.ts +3 -0
  168. package/dist/src/migrations/update-24-0-0/find-custom-hashers.js +100 -0
  169. package/dist/src/migrations/update-24-0-0/find-custom-hashers.md +63 -0
  170. package/dist/src/migrations/update-24-0-0/move-custom-hashers-to-inputs.md +146 -0
  171. package/dist/src/migrations/update-24-0-0/rename-ultracache-ignore-options.d.ts +3 -0
  172. package/dist/src/migrations/update-24-0-0/rename-ultracache-ignore-options.js +130 -0
  173. package/dist/src/migrations/update-24-0-0/rename-ultracache-ignore-options.md +62 -0
  174. package/dist/src/native/assert-supported-platform.js +1 -1
  175. package/dist/src/native/index.d.ts +238 -18
  176. package/dist/src/native/index.js +6 -1
  177. package/dist/src/native/native-bindings.js +15 -6
  178. package/dist/src/native/nx.openharmony-arm64.node +0 -0
  179. package/dist/src/native/nx.wasi-browser.js +1 -0
  180. package/dist/src/native/nx.wasi.cjs +1 -0
  181. package/dist/src/native/nx.wasm32-wasi.debug.wasm +0 -0
  182. package/dist/src/native/nx.wasm32-wasi.wasm +0 -0
  183. package/dist/src/nx-cloud/update-manager.d.ts +14 -0
  184. package/dist/src/nx-cloud/update-manager.js +237 -50
  185. package/dist/src/plugins/js/lock-file/pnpm-parser.js +3 -4
  186. package/dist/src/plugins/js/lock-file/pruned-output.d.ts +2 -2
  187. package/dist/src/plugins/js/lock-file/pruned-output.js +4 -4
  188. package/dist/src/plugins/js/utils/register.js +9 -4
  189. package/dist/src/project-graph/affected/affected-tasks.d.ts +9 -6
  190. package/dist/src/project-graph/affected/affected-tasks.js +31 -7
  191. package/dist/src/project-graph/plugins/isolation/isolated-plugin.js +7 -0
  192. package/dist/src/project-graph/plugins/loaded-nx-plugin.js +49 -6
  193. package/dist/src/project-graph/utils/project-configuration/target-merging.js +1 -1
  194. package/dist/src/project-graph/utils/project-configuration/target-normalization.js +12 -133
  195. package/dist/src/project-graph/utils/project-configuration-utils.js +2 -2
  196. package/dist/src/project-graph/utils/retrieve-workspace-files.js +27 -6
  197. package/dist/src/tasks-runner/create-task-graph.d.ts +8 -7
  198. package/dist/src/tasks-runner/create-task-graph.js +50 -27
  199. package/dist/src/tasks-runner/default-tasks-runner.js +1 -1
  200. package/dist/src/tasks-runner/init-tasks-runner.js +116 -59
  201. package/dist/src/tasks-runner/life-cycle.d.ts +4 -1
  202. package/dist/src/tasks-runner/life-cycle.js +7 -0
  203. package/dist/src/tasks-runner/life-cycles/performance-analysis.d.ts +5 -2
  204. package/dist/src/tasks-runner/life-cycles/performance-analysis.js +13 -7
  205. package/dist/src/tasks-runner/life-cycles/performance-life-cycle.d.ts +4 -3
  206. package/dist/src/tasks-runner/life-cycles/performance-life-cycle.js +9 -2
  207. package/dist/src/tasks-runner/life-cycles/static-run-many-terminal-output-life-cycle.js +5 -2
  208. package/dist/src/tasks-runner/life-cycles/static-run-one-terminal-output-life-cycle.js +4 -1
  209. package/dist/src/tasks-runner/life-cycles/summary-terminal-output-life-cycle.js +5 -1
  210. package/dist/src/tasks-runner/pseudo-ipc.d.ts +1 -0
  211. package/dist/src/tasks-runner/pseudo-ipc.js +4 -0
  212. package/dist/src/tasks-runner/pseudo-terminal.d.ts +1 -1
  213. package/dist/src/tasks-runner/pseudo-terminal.js +2 -2
  214. package/dist/src/tasks-runner/readiness/executor-ready-signal.d.ts +7 -0
  215. package/dist/src/tasks-runner/readiness/executor-ready-signal.js +43 -0
  216. package/dist/src/tasks-runner/readiness/probes.d.ts +14 -0
  217. package/dist/src/tasks-runner/readiness/probes.js +101 -0
  218. package/dist/src/tasks-runner/readiness/ready-signal-server.d.ts +18 -0
  219. package/dist/src/tasks-runner/readiness/ready-signal-server.js +72 -0
  220. package/dist/src/tasks-runner/readiness/ready-signal.d.ts +33 -0
  221. package/dist/src/tasks-runner/readiness/ready-signal.js +92 -0
  222. package/dist/src/tasks-runner/readiness/ready-when.d.ts +84 -0
  223. package/dist/src/tasks-runner/readiness/ready-when.js +371 -0
  224. package/dist/src/tasks-runner/readiness/startup-host.d.ts +1 -0
  225. package/dist/src/tasks-runner/readiness/startup-host.js +32 -0
  226. package/dist/src/tasks-runner/run-command.d.ts +6 -2
  227. package/dist/src/tasks-runner/run-command.js +21 -31
  228. package/dist/src/tasks-runner/run-outcome.d.ts +16 -0
  229. package/dist/src/tasks-runner/run-outcome.js +39 -0
  230. package/dist/src/tasks-runner/running-tasks/batch-process.js +6 -0
  231. package/dist/src/tasks-runner/running-tasks/node-child-process.js +5 -4
  232. package/dist/src/tasks-runner/running-tasks/running-task.d.ts +1 -1
  233. package/dist/src/tasks-runner/task-env.d.ts +10 -0
  234. package/dist/src/tasks-runner/task-env.js +37 -5
  235. package/dist/src/tasks-runner/task-graph-utils.d.ts +9 -6
  236. package/dist/src/tasks-runner/task-graph-utils.js +17 -12
  237. package/dist/src/tasks-runner/task-orchestrator.d.ts +62 -18
  238. package/dist/src/tasks-runner/task-orchestrator.js +750 -150
  239. package/dist/src/tasks-runner/tasks-runner.d.ts +1 -1
  240. package/dist/src/tasks-runner/tasks-schedule.d.ts +18 -1
  241. package/dist/src/tasks-runner/tasks-schedule.js +63 -6
  242. package/dist/src/tasks-runner/tokens.d.ts +54 -0
  243. package/dist/src/tasks-runner/tokens.js +161 -0
  244. package/dist/src/tasks-runner/utils.d.ts +35 -6
  245. package/dist/src/tasks-runner/utils.js +149 -68
  246. package/dist/src/ultracache/ci-status.d.ts +24 -0
  247. package/dist/src/ultracache/ci-status.js +87 -0
  248. package/dist/src/ultracache/config.d.ts +3 -3
  249. package/dist/src/ultracache/config.js +4 -4
  250. package/dist/src/ultracache/fetch.d.ts +2 -0
  251. package/dist/src/ultracache/fetch.js +1 -0
  252. package/dist/src/ultracache/overrides.js +4 -0
  253. package/dist/src/utils/acknowledge-build-scripts.d.ts +34 -1
  254. package/dist/src/utils/acknowledge-build-scripts.js +171 -32
  255. package/dist/src/utils/child-process.js +2 -1
  256. package/dist/src/utils/find-matching-projects.js +9 -6
  257. package/dist/src/utils/git-utils.d.ts +12 -5
  258. package/dist/src/utils/git-utils.js +69 -11
  259. package/dist/src/utils/long-running-target.d.ts +1 -3
  260. package/dist/src/utils/long-running-target.js +1 -3
  261. package/dist/src/utils/nx-package-group.js +1 -1
  262. package/dist/src/utils/output.d.ts +4 -3
  263. package/dist/src/utils/output.js +4 -3
  264. package/dist/src/utils/owned-private-dir.d.ts +1 -17
  265. package/dist/src/utils/owned-private-dir.js +10 -62
  266. package/dist/src/utils/package-json.js +1 -1
  267. package/dist/src/utils/package-manager.d.ts +8 -0
  268. package/dist/src/utils/package-manager.js +65 -8
  269. package/dist/src/utils/perf-hooks.d.ts +1 -0
  270. package/dist/src/utils/plugins/core-plugins.js +5 -1
  271. package/dist/src/utils/progress-topics.d.ts +1 -0
  272. package/dist/src/utils/progress-topics.js +1 -0
  273. package/dist/src/utils/safe-spawn.js +1 -5
  274. package/dist/src/utils/shell-quoting.d.ts +8 -1
  275. package/dist/src/utils/shell-quoting.js +12 -1
  276. package/dist/src/utils/spawn-without-terminal.d.ts +27 -0
  277. package/dist/src/utils/spawn-without-terminal.js +110 -0
  278. package/dist/src/utils/string-similarity.d.ts +38 -0
  279. package/dist/src/utils/string-similarity.js +108 -0
  280. package/dist/src/utils/versions.js +1 -1
  281. package/migrations.json +20 -6
  282. package/package.json +15 -24
  283. package/schemas/migrations-schema.json +11 -0
  284. package/schemas/nx-schema.json +133 -11
  285. package/schemas/project-schema.json +114 -4
  286. package/dist/src/command-line/migrate/agentic/prompts/generic-validation.d.ts +0 -56
  287. package/dist/src/command-line/migrate/agentic/prompts/generic-validation.js +0 -67
  288. package/dist/src/command-line/migrate/agentic/prompts/hybrid-prompt-migration.d.ts +0 -49
  289. package/dist/src/command-line/migrate/agentic/prompts/hybrid-prompt-migration.js +0 -53
  290. package/dist/src/command-line/migrate/agentic/prompts/prompt-migration.d.ts +0 -26
  291. package/dist/src/command-line/migrate/agentic/prompts/prompt-migration.js +0 -27
  292. package/dist/src/command-line/migrate/agentic/prompts/system-prompt.d.ts +0 -70
  293. package/dist/src/command-line/migrate/agentic/prompts/system-prompt.js +0 -113
  294. package/dist/src/command-line/migrate/agentic/run-step.d.ts +0 -68
  295. package/dist/src/command-line/migrate/agentic/run-step.js +0 -148
  296. package/dist/src/command-line/migrate/agentic/runner.d.ts +0 -21
  297. package/dist/src/command-line/migrate/agentic/runner.js +0 -262
  298. package/dist/src/migrations/update-23-0-0/consolidate-release-tag-config.d.ts +0 -9
  299. package/dist/src/migrations/update-23-0-0/consolidate-release-tag-config.js +0 -18
  300. package/dist/src/tasks-runner/legacy-depends-on-warning.d.ts +0 -18
  301. package/dist/src/tasks-runner/legacy-depends-on-warning.js +0 -109
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NxCloudClientUnavailableError = exports.NxCloudEnterpriseOutdatedError = void 0;
4
4
  exports.verifyOrUpdateNxCloudClient = verifyOrUpdateNxCloudClient;
5
5
  exports.getBundleInstallDefaultLocation = getBundleInstallDefaultLocation;
6
+ exports.downloadAndExtractClientBundle = downloadAndExtractClientBundle;
6
7
  const tslib_1 = require("tslib");
7
8
  const fs_1 = require("fs");
8
9
  const zlib_1 = require("zlib");
@@ -16,6 +17,7 @@ const tar = tslib_1.__importStar(require("tar-stream"));
16
17
  const cache_directory_1 = require("../utils/cache-directory");
17
18
  const is_ci_1 = require("../utils/is-ci");
18
19
  const crypto_1 = require("crypto");
20
+ const native_1 = require("../native");
19
21
  const workspace_root_1 = require("../utils/workspace-root");
20
22
  class NxCloudEnterpriseOutdatedError extends Error {
21
23
  constructor(url) {
@@ -74,13 +76,13 @@ async function verifyOrUpdateNxCloudClient(options) {
74
76
  if (version === 'NX_ENTERPRISE_OUTDATED_IMAGE') {
75
77
  throw new NxCloudEnterpriseOutdatedError(apiUrl);
76
78
  }
77
- const fullPath = await downloadAndExtractClientBundle(httpClient, runnerBundleInstallDirectory, version, url);
78
- (0, debug_logger_1.debugLog)('Done: ', fullPath);
79
- const nxCloudClient = require(fullPath);
79
+ const installedBundle = await downloadAndExtractClientBundle(httpClient, version, url);
80
+ (0, debug_logger_1.debugLog)('Done: ', installedBundle.fullPath);
81
+ const nxCloudClient = require(installedBundle.fullPath);
80
82
  if (nxCloudClient.commands === undefined) {
81
83
  throw new NxCloudEnterpriseOutdatedError(apiUrl);
82
84
  }
83
- return { version, nxCloudClient };
85
+ return { version: installedBundle.version, nxCloudClient };
84
86
  }
85
87
  if (currentBundle === null) {
86
88
  throw new NxCloudClientUnavailableError();
@@ -114,6 +116,25 @@ function getBundleInstallDefaultLocation() {
114
116
  return (0, path_1.join)((0, is_ci_1.isCI)() ? (0, cache_directory_1.cacheDirectoryForWorkspace)(workspace_root_1.workspaceRoot) : cache_directory_1.cacheDir, 'cloud');
115
117
  }
116
118
  const runnerBundleInstallDirectory = getBundleInstallDefaultLocation();
119
+ // Control files live outside the install directory. Released nx versions load
120
+ // any directory there as a bundle, so they would `require` a state directory
121
+ // placed inside it.
122
+ const stateDirectory = (0, fs_1.existsSync)((0, path_1.join)(workspace_root_1.workspaceRoot, 'nx.json'))
123
+ ? (0, path_1.join)(cache_directory_1.workspaceDataDirectory, 'nx-cloud')
124
+ : `${runnerBundleInstallDirectory}-state`;
125
+ function ensureStateDirectory() {
126
+ (0, fs_1.mkdirSync)(stateDirectory, { recursive: true });
127
+ }
128
+ const downloadLockFilePath = (0, path_1.join)(stateDirectory, 'download.lock');
129
+ // The record lives beside the lockfile rather than inside it. Windows
130
+ // byte-range locks are mandatory and handle-scoped, so writing to a file this
131
+ // process holds an exclusive lock on fails with ERROR_LOCK_VIOLATION. It also
132
+ // matches the convention elsewhere in nx: project-graph.lock and run.json.lock
133
+ // are never written to.
134
+ const downloadRecordFilePath = (0, path_1.join)(stateDirectory, 'download.record');
135
+ // A version names a directory that is created and later deleted, so a value
136
+ // from the server must not be able to escape the install directory.
137
+ const VALID_BUNDLE_VERSION = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
117
138
  function getLatestInstalledRunnerBundle() {
118
139
  if (!(0, fs_1.existsSync)(runnerBundleInstallDirectory)) {
119
140
  (0, fs_1.mkdirSync)(runnerBundleInstallDirectory, { recursive: true });
@@ -121,7 +142,9 @@ function getLatestInstalledRunnerBundle() {
121
142
  try {
122
143
  const installedBundles = (0, fs_1.readdirSync)(runnerBundleInstallDirectory)
123
144
  .filter((potentialDirectory) => {
124
- return (0, fs_1.statSync)((0, path_1.join)(runnerBundleInstallDirectory, potentialDirectory)).isDirectory();
145
+ // '.tmp-*' directories are in-progress or crashed downloads
146
+ return (!potentialDirectory.startsWith('.') &&
147
+ (0, fs_1.statSync)((0, path_1.join)(runnerBundleInstallDirectory, potentialDirectory)).isDirectory());
125
148
  })
126
149
  .map((fileOrDirectory) => ({
127
150
  version: fileOrDirectory,
@@ -131,7 +154,13 @@ function getLatestInstalledRunnerBundle() {
131
154
  // No installed bundles
132
155
  return null;
133
156
  }
134
- return installedBundles[0];
157
+ // A contended install can leave several bundles on disk. The record names
158
+ // the directory an install last completed in, which is the one to run.
159
+ // Without a record the directory name is all there is to go on and is read
160
+ // as the version, which is right for a bundle an older nx installed and
161
+ // otherwise yields a version the server rejects, costing one more
162
+ // download.
163
+ return recordedBundle() ?? installedBundles[0];
135
164
  }
136
165
  catch (e) {
137
166
  console.log('Could not read runner bundle path:', e.message);
@@ -170,7 +199,7 @@ async function verifyCurrentBundle(httpClient, currentBundle) {
170
199
  });
171
200
  }
172
201
  function getLatestBundleVerificationTimestamp() {
173
- const lockfilePath = (0, path_1.join)(runnerBundleInstallDirectory, 'verify.lock');
202
+ const lockfilePath = (0, path_1.join)(stateDirectory, 'verify.lock');
174
203
  if ((0, fs_1.existsSync)(lockfilePath)) {
175
204
  const timestampAsString = (0, fs_1.readFileSync)(lockfilePath, 'utf-8');
176
205
  let timestampAsNumber;
@@ -185,7 +214,8 @@ function getLatestBundleVerificationTimestamp() {
185
214
  return null;
186
215
  }
187
216
  function writeBundleVerificationLock() {
188
- const lockfilePath = (0, path_1.join)(runnerBundleInstallDirectory, 'verify.lock');
217
+ const lockfilePath = (0, path_1.join)(stateDirectory, 'verify.lock');
218
+ ensureStateDirectory();
189
219
  (0, fs_1.writeFileSync)(lockfilePath, new Date().getTime().toString(), 'utf-8');
190
220
  }
191
221
  function getBundleContentHash(bundle) {
@@ -211,7 +241,118 @@ function hashDirectory(dir) {
211
241
  const combinedHashes = hashes.sort().join('');
212
242
  return (0, crypto_1.createHash)('sha256').update(combinedHashes).digest('hex');
213
243
  }
214
- async function downloadAndExtractClientBundle(httpClient, runnerBundleInstallDirectory, version, url) {
244
+ async function downloadAndExtractClientBundle(httpClient, version, url) {
245
+ // Parallel nx processes race to install bundles, possibly at different
246
+ // versions. The first to take the lock downloads; the rest wait and adopt
247
+ // its bundle when an install completed during the wait at the version the
248
+ // server asked them for. Otherwise they download their own as a contended
249
+ // install, which publishes its own directory and skips cleanup, so the
250
+ // holder's bundle stays on disk for the process running from it - at the
251
+ // same version as well as a different one. The flock is released by the
252
+ // kernel if the holder dies, so no stale-lock cleanup is needed. Under WASM
253
+ // the lock is unavailable and downloads run unserialized.
254
+ if (!VALID_BUNDLE_VERSION.test(version)) {
255
+ throw new Error(`Invalid Nx Cloud client bundle version: ${version}`);
256
+ }
257
+ const recordBeforeContending = readDownloadRecord();
258
+ const lock = !native_1.IS_WASM ? new native_1.FileLock(downloadLockFilePath) : null;
259
+ let locked = lock?.locked;
260
+ let contended = false;
261
+ while (locked) {
262
+ (0, debug_logger_1.debugLog)('Another process is downloading the client bundle, waiting for it to complete');
263
+ await lock.wait();
264
+ // The holder may be running from a bundle whose record predates this call,
265
+ // so the wait alone makes the install contended.
266
+ contended = true;
267
+ const installedBundle = bundleInstalledSince(recordBeforeContending);
268
+ if (installedBundle) {
269
+ if (installedBundle.version === version) {
270
+ (0, debug_logger_1.debugLog)('Using client bundle downloaded by another process: ', installedBundle.version);
271
+ return installedBundle;
272
+ }
273
+ (0, debug_logger_1.debugLog)('Another process installed a different bundle: ', installedBundle.version);
274
+ }
275
+ // The other process failed or installed an older version, so this process
276
+ // still needs to download.
277
+ locked = lock.check();
278
+ }
279
+ lock?.lock();
280
+ try {
281
+ // A process that acquired the lock between the check above and lock() may
282
+ // have completed an install already.
283
+ const installedBundle = bundleInstalledSince(recordBeforeContending);
284
+ if (installedBundle) {
285
+ if (installedBundle.version === version) {
286
+ (0, debug_logger_1.debugLog)('Using client bundle downloaded by another process: ', installedBundle.version);
287
+ return installedBundle;
288
+ }
289
+ // A different version means that process is running from a bundle this
290
+ // one must not delete.
291
+ contended = true;
292
+ (0, debug_logger_1.debugLog)('Another process installed a different bundle: ', installedBundle.version);
293
+ }
294
+ const fullPath = await downloadAndExtractBundle(httpClient, version, url, contended);
295
+ return { version, fullPath };
296
+ }
297
+ finally {
298
+ lock?.unlock();
299
+ }
300
+ }
301
+ // Records "<serverVersion> <directoryName>", written only once an install has
302
+ // COMPLETED. The directory is recorded separately because it cannot be derived
303
+ // from the version - every install publishes its own (see
304
+ // downloadAndExtractBundle), so several directories can carry the same
305
+ // version. That also makes every record distinct, so a waiter can tell "an
306
+ // install finished while I waited" from "this record is left over from a past
307
+ // run" by comparing the record it read before contending. Timestamps cannot
308
+ // answer that: filesystem mtime granularity is coarser than the race window.
309
+ function readDownloadRecord() {
310
+ try {
311
+ return (0, fs_1.readFileSync)(downloadRecordFilePath, 'utf-8').trim();
312
+ }
313
+ catch {
314
+ return '';
315
+ }
316
+ }
317
+ function writeDownloadRecord(version, directoryName) {
318
+ ensureStateDirectory();
319
+ (0, fs_1.writeFileSync)(downloadRecordFilePath, `${version} ${directoryName}`, 'utf-8');
320
+ }
321
+ /**
322
+ * The bundle the record names, if it is still on disk. A record whose second
323
+ * field does not name a live directory resolves to null and leaves selection
324
+ * on its fallback, which is what a one-field record or anything else
325
+ * unexpected in the file has to do.
326
+ */
327
+ function recordedBundle() {
328
+ const [version, directoryName] = readDownloadRecord().split(' ');
329
+ if (!version ||
330
+ !directoryName ||
331
+ !VALID_BUNDLE_VERSION.test(version) ||
332
+ !VALID_BUNDLE_VERSION.test(directoryName)) {
333
+ return null;
334
+ }
335
+ const fullPath = (0, path_1.join)(runnerBundleInstallDirectory, directoryName);
336
+ return (0, fs_1.existsSync)(fullPath) ? { version, fullPath } : null;
337
+ }
338
+ /**
339
+ * The bundle an install completed during this call, or null. Requires the
340
+ * record to have changed since `recordBefore` was read: a directory existing
341
+ * proves only that some earlier run left one there, and an install
342
+ * interrupted on a released nx leaves exactly that.
343
+ */
344
+ function bundleInstalledSince(recordBefore) {
345
+ return readDownloadRecord() === recordBefore ? null : recordedBundle();
346
+ }
347
+ async function downloadAndExtractBundle(httpClient, version, url, contended) {
348
+ // Every install publishes its own directory. Two processes can be asked for
349
+ // the same version while one of them is already running from a completed
350
+ // install of it, so replacing <installDir>/<version> in place would delete
351
+ // that bundle out from under it - and a holder loading its client in the gap
352
+ // fails with MODULE_NOT_FOUND, which drops the task runner to running
353
+ // without Nx Cloud. A directory nothing else has seen cannot be in use.
354
+ const bundleDirectoryName = `${version}-${(0, crypto_1.randomUUID)()}`;
355
+ const bundleExtractLocation = (0, path_1.join)(runnerBundleInstallDirectory, bundleDirectoryName);
215
356
  let resp;
216
357
  try {
217
358
  resp = await httpClient.get(url, {
@@ -222,53 +363,99 @@ async function downloadAndExtractClientBundle(httpClient, runnerBundleInstallDir
222
363
  console.error('Error while updating Nx Cloud client bundle');
223
364
  throw e;
224
365
  }
225
- const bundleExtractLocation = (0, path_1.join)(runnerBundleInstallDirectory, version);
226
- if (!(0, fs_1.existsSync)(bundleExtractLocation)) {
227
- (0, fs_1.mkdirSync)(bundleExtractLocation);
228
- }
229
- return new Promise((res, rej) => {
230
- const extract = tar.extract();
231
- extract.on('entry', function (headers, stream, next) {
232
- if (headers.type === 'directory') {
233
- const directoryPath = (0, path_1.join)(bundleExtractLocation, headers.name);
234
- if (!(0, fs_1.existsSync)(directoryPath)) {
235
- (0, fs_1.mkdirSync)(directoryPath, { recursive: true });
236
- }
237
- next();
238
- stream.resume();
239
- }
240
- else if (headers.type === 'file') {
241
- const outputFilePath = (0, path_1.join)(bundleExtractLocation, headers.name);
242
- const writeStream = (0, fs_1.createWriteStream)(outputFilePath);
243
- // Surface disk errors through the pipeline instead of crashing
244
- writeStream.on('error', (e) => extract.destroy(e));
245
- stream.pipe(writeStream);
246
- // Continue the tar stream after the write stream closes
247
- writeStream.on('close', () => {
366
+ // Extract into a temp directory and rename into place afterwards, so a
367
+ // failed or interrupted download never leaves a partial bundle at the
368
+ // path other processes require it from.
369
+ const tempExtractLocation = (0, path_1.join)(runnerBundleInstallDirectory, `.tmp-${version}-${process.pid}`);
370
+ (0, fs_1.mkdirSync)(tempExtractLocation, { recursive: true });
371
+ try {
372
+ await new Promise((res, rej) => {
373
+ const extract = tar.extract();
374
+ extract.on('entry', function (headers, stream, next) {
375
+ if (headers.type === 'directory') {
376
+ const directoryPath = (0, path_1.join)(tempExtractLocation, headers.name);
377
+ if (!(0, fs_1.existsSync)(directoryPath)) {
378
+ (0, fs_1.mkdirSync)(directoryPath, { recursive: true });
379
+ }
248
380
  next();
249
- });
250
- stream.resume();
251
- }
252
- });
253
- extract.on('finish', function () {
254
- removeOldClientBundles(version);
255
- writeBundleVerificationLock();
256
- res(bundleExtractLocation);
257
- });
258
- // pipeline propagates download/gunzip errors that .pipe() would leave
259
- // uncaught
260
- (0, stream_1.pipeline)(resp.data, (0, zlib_1.createGunzip)(), extract, (e) => {
261
- if (e)
262
- rej(e);
381
+ stream.resume();
382
+ }
383
+ else if (headers.type === 'file') {
384
+ const outputFilePath = (0, path_1.join)(tempExtractLocation, headers.name);
385
+ const writeStream = (0, fs_1.createWriteStream)(outputFilePath);
386
+ // Surface disk errors through the pipeline instead of crashing
387
+ writeStream.on('error', (e) => extract.destroy(e));
388
+ stream.pipe(writeStream);
389
+ // Continue the tar stream after the write stream closes
390
+ writeStream.on('close', () => {
391
+ next();
392
+ });
393
+ stream.resume();
394
+ }
395
+ else {
396
+ // Skipping the entry would publish an incomplete bundle.
397
+ extract.destroy(new Error(`Unsupported ${headers.type} entry in Nx Cloud client bundle: ${headers.name}`));
398
+ }
399
+ });
400
+ extract.on('finish', function () {
401
+ res();
402
+ });
403
+ // pipeline propagates download/gunzip errors that .pipe() would leave
404
+ // uncaught
405
+ (0, stream_1.pipeline)(resp.data, (0, zlib_1.createGunzip)(), extract, (e) => {
406
+ if (e)
407
+ rej(e);
408
+ });
263
409
  });
264
- });
410
+ (0, fs_1.renameSync)(tempExtractLocation, bundleExtractLocation);
411
+ // Recorded only now: the record is the signal that a bundle at this
412
+ // version was installed by this process, which is what lets a waiter
413
+ // adopt it instead of downloading again, and it carries the directory
414
+ // that selection has to load from.
415
+ writeDownloadRecord(version, bundleDirectoryName);
416
+ }
417
+ catch (e) {
418
+ (0, fs_1.rmSync)(tempExtractLocation, { recursive: true, force: true });
419
+ throw e;
420
+ }
421
+ // On a contended install another process may be running from any bundle on
422
+ // disk, now including one at this same version, so nothing here can be shown
423
+ // to be unused and collection waits for a later uncontended install. Repeat
424
+ // contention accumulates directories until one of those runs. Bounding that
425
+ // means knowing which bundles are still loaded, which nothing on disk
426
+ // records today.
427
+ if (!contended) {
428
+ removeOldClientBundles(bundleDirectoryName);
429
+ }
430
+ writeBundleVerificationLock();
431
+ return bundleExtractLocation;
265
432
  }
266
- function removeOldClientBundles(currentInstallVersion) {
433
+ function removeOldClientBundles(currentInstallDirectoryName) {
267
434
  const filesAndFolders = (0, fs_1.readdirSync)(runnerBundleInstallDirectory);
268
435
  for (let fileOrFolder of filesAndFolders) {
436
+ // A '.tmp-*' left by a crashed extract is reclaimed here, which is safe
437
+ // only because this runs after our own was renamed away and the download
438
+ // lock means no other process is extracting. Under WASM there is no lock,
439
+ // so a concurrent extract may still own that directory: leaving it costs
440
+ // disk, deleting it would fail that process's install.
441
+ if (fileOrFolder === currentInstallDirectoryName ||
442
+ (native_1.IS_WASM && fileOrFolder.startsWith('.tmp-'))) {
443
+ continue;
444
+ }
269
445
  const fileOrFolderPath = (0, path_1.join)(runnerBundleInstallDirectory, fileOrFolder);
270
- if (fileOrFolder !== currentInstallVersion) {
271
- (0, fs_1.rmSync)(fileOrFolderPath, { recursive: true });
446
+ // Another process's cleanup can remove an entry between the readdir above
447
+ // and these calls, so both tolerate it already being gone.
448
+ let isBundle;
449
+ try {
450
+ // Only directories are bundles. Files here, like the verify.lock a
451
+ // released nx writes, are left alone.
452
+ isBundle = (0, fs_1.statSync)(fileOrFolderPath).isDirectory();
453
+ }
454
+ catch {
455
+ continue;
456
+ }
457
+ if (isBundle) {
458
+ (0, fs_1.rmSync)(fileOrFolderPath, { recursive: true, force: true });
272
459
  }
273
460
  }
274
461
  }
@@ -438,7 +438,8 @@ function getDependencies(data, keyMap, isV5, ctx) {
438
438
  Object.keys(section).forEach((name) => {
439
439
  const versionRange = section[name];
440
440
  const version = parseBaseVersion(findVersion(versionRange, name, isV5), isV5);
441
- const target = ctx.externalNodes[`npm:${name}@${version}`] ||
441
+ const target = keyMap.get(versionRange)?.values().next().value ||
442
+ ctx.externalNodes[`npm:${name}@${version}`] ||
442
443
  ctx.externalNodes[`npm:${name}`];
443
444
  if (target) {
444
445
  const dep = {
@@ -603,9 +604,7 @@ function stringifyPnpmLockfile(graph, rootLockFileContent, packageJson, workspac
603
604
  // relocated at its synthesis site, which is why it is added afterwards: a
604
605
  // second pass over an already-relocated path cannot tell it apart from a
605
606
  // workspace path that genuinely starts with the shipped directory's name.
606
- // TODO(v24): throw on this collision like the colliding-patches case; today
607
- // the copied workspace module silently supersedes the file: dependency.
608
- (0, pruned_output_1.warnOnWorkspaceModulePathCollision)(snapshots, synthesizedModulePaths);
607
+ (0, pruned_output_1.assertNoWorkspaceModulePathCollision)(snapshots, synthesizedModulePaths);
609
608
  (0, pruned_output_1.containShippedLocalFilePaths)(output, synthesizedModulePaths);
610
609
  // Peers pnpm left out of the importer (autoInstallPeers off) still ship as
611
610
  // real dependencies, matching the copied manifest that moves every
@@ -148,12 +148,12 @@ export declare function normalizeLocalPathSpec(spec: string): string;
148
148
  */
149
149
  export declare function uncontainLocalPathSpec(spec: string): string;
150
150
  /**
151
- * Warns when a workspace directory occupies the output path of a copied
151
+ * Throws when a workspace directory occupies the output path of a copied
152
152
  * workspace module. Both spell `workspace_modules/<name>`, so no later pass can
153
153
  * tell them apart: the vendored source is read as the copied module and never
154
154
  * ships, leaving the lockfile pointing at a path the output does not carry.
155
155
  */
156
- export declare function warnOnWorkspaceModulePathCollision(sourcePackages: Record<string, unknown> | undefined, synthesizedModulePaths: ReadonlySet<string>): void;
156
+ export declare function assertNoWorkspaceModulePathCollision(sourcePackages: Record<string, unknown> | undefined, synthesizedModulePaths: ReadonlySet<string>): void;
157
157
  /**
158
158
  * Relocates every shippable non-workspace `file:` local-path reference in a
159
159
  * pruned lockfile (package keys, resolutions, and snapshot/importer dependency
@@ -11,7 +11,7 @@ exports.containLocalPath = containLocalPath;
11
11
  exports.uncontainLocalPath = uncontainLocalPath;
12
12
  exports.normalizeLocalPathSpec = normalizeLocalPathSpec;
13
13
  exports.uncontainLocalPathSpec = uncontainLocalPathSpec;
14
- exports.warnOnWorkspaceModulePathCollision = warnOnWorkspaceModulePathCollision;
14
+ exports.assertNoWorkspaceModulePathCollision = assertNoWorkspaceModulePathCollision;
15
15
  exports.containShippedLocalFilePaths = containShippedLocalFilePaths;
16
16
  exports.containShippedLocalLinkRefs = containShippedLocalLinkRefs;
17
17
  exports.getPrunedPnpmLocalPathArtifacts = getPrunedPnpmLocalPathArtifacts;
@@ -772,18 +772,18 @@ function containFileToken(token, synthesized) {
772
772
  : `${token.slice(0, pathStart)}${contained}`;
773
773
  }
774
774
  /**
775
- * Warns when a workspace directory occupies the output path of a copied
775
+ * Throws when a workspace directory occupies the output path of a copied
776
776
  * workspace module. Both spell `workspace_modules/<name>`, so no later pass can
777
777
  * tell them apart: the vendored source is read as the copied module and never
778
778
  * ships, leaving the lockfile pointing at a path the output does not carry.
779
779
  */
780
- function warnOnWorkspaceModulePathCollision(sourcePackages, synthesizedModulePaths) {
780
+ function assertNoWorkspaceModulePathCollision(sourcePackages, synthesizedModulePaths) {
781
781
  for (const snapshot of Object.values(sourcePackages ?? {})) {
782
782
  const directory = snapshot
783
783
  ?.resolution?.directory;
784
784
  if (typeof directory === 'string' &&
785
785
  synthesizedModulePaths.has((0, path_2.normalizePath)(directory))) {
786
- logger_1.logger.warn(`Local-path dependency "file:${directory}" sits where the pruned output copies a workspace module of the same name, so it cannot ship separately. Move it out of ${WORKSPACE_MODULES_DIR}/ to deploy it.`);
786
+ throw new Error(`Cannot prune pnpm lockfile: local-path dependency "file:${directory}" sits where the standalone output copies a workspace module of the same name. Move it out of ${WORKSPACE_MODULES_DIR}/ so they do not collide.`);
787
787
  }
788
788
  }
789
789
  }
@@ -744,12 +744,16 @@ function isNativeTypeStripError(err) {
744
744
  * Module resolution failures - typically a tsconfig path alias that hasn't
745
745
  * been registered yet, or a workspace lib not surfaced via package manager
746
746
  * symlinks. CJS uses `MODULE_NOT_FOUND`, ESM uses `ERR_MODULE_NOT_FOUND`.
747
+ * `ERR_PACKAGE_PATH_NOT_EXPORTED` covers a linked package shadowing a path
748
+ * alias for a subpath its `exports` doesn't list.
747
749
  */
748
750
  function isModuleNotFoundError(err) {
749
751
  if (!err || typeof err !== 'object')
750
752
  return false;
751
753
  const code = err.code;
752
- return code === 'MODULE_NOT_FOUND' || code === 'ERR_MODULE_NOT_FOUND';
754
+ return (code === 'MODULE_NOT_FOUND' ||
755
+ code === 'ERR_MODULE_NOT_FOUND' ||
756
+ code === 'ERR_PACKAGE_PATH_NOT_EXPORTED');
753
757
  }
754
758
  /**
755
759
  * A SyntaxError thrown while parsing a forced-CJS file (`.cts`/`.cjs`) as
@@ -1010,8 +1014,8 @@ function requireWithTsconfigFallback(filePath, tsConfigPath) {
1010
1014
  * - ESM-redispatch signals callers expect to handle
1011
1015
  * (`ERR_REQUIRE_ESM`, `ERR_REQUIRE_ASYNC_MODULE`)
1012
1016
  * - plain module-resolution failures (`MODULE_NOT_FOUND`,
1013
- * `ERR_MODULE_NOT_FOUND`) - disabling strip-types doesn't fix a missing
1014
- * module, the hint just misleads.
1017
+ * `ERR_MODULE_NOT_FOUND`, `ERR_PACKAGE_PATH_NOT_EXPORTED`) - disabling
1018
+ * strip-types doesn't fix a missing module, the hint just misleads.
1015
1019
  */
1016
1020
  function augmentLoadFailure(filePath, err) {
1017
1021
  if (!(err instanceof Error))
@@ -1020,7 +1024,8 @@ function augmentLoadFailure(filePath, err) {
1020
1024
  if (code === 'ERR_REQUIRE_ESM' ||
1021
1025
  code === 'ERR_REQUIRE_ASYNC_MODULE' ||
1022
1026
  code === 'MODULE_NOT_FOUND' ||
1023
- code === 'ERR_MODULE_NOT_FOUND') {
1027
+ code === 'ERR_MODULE_NOT_FOUND' ||
1028
+ code === 'ERR_PACKAGE_PATH_NOT_EXPORTED') {
1024
1029
  return err;
1025
1030
  }
1026
1031
  if (err.message.includes(NX_PREFER_NODE_STRIP_TYPES_DOCS_URL)) {
@@ -11,13 +11,14 @@ import { TaskPlanningContext } from '../../hasher/task-planning-context';
11
11
  import type { TaskSelection } from '../../tasks-runner/run-command';
12
12
  /**
13
13
  * Whether `nx affected` selects the individual tasks whose inputs a change
14
- * reaches, rather than whole projects. Off by default while the task path
15
- * settles.
14
+ * reaches, rather than whole projects. `NX_LEGACY_AFFECTED` overrides
15
+ * nx.json's `affected.legacy`.
16
16
  *
17
- * Env-var only, so `nx show projects --affected` and `nx affected` in one CI
18
- * script agree. The run also executes the selected tasks' dependencies.
17
+ * The run also executes the selected tasks' dependencies.
19
18
  */
20
- export declare function selectsAffectedTasks(): boolean;
19
+ export declare function selectsAffectedTasks(nxJson: NxJsonConfiguration): boolean;
20
+ /** What to change so {@link selectsAffectedTasks} returns true, for error messages. */
21
+ export declare function taskGranularityRequirement(): string;
21
22
  export interface AffectedTasksResult {
22
23
  /** The graph selection ran against, which the command should run with too. */
23
24
  projectGraph: ProjectGraph;
@@ -91,7 +92,8 @@ export declare function computeAffectedTasks(opts: ComputeAffectedTasksOptions):
91
92
  * task can read files no affected project owns. Shared by the client and the
92
93
  * daemon.
93
94
  */
94
- export declare function selectAffectedTasks(projectGraph: ProjectGraph, nxJson: NxJsonConfiguration, planningContext: TaskPlanningContext, request: AffectedTasksRequest, { touchedFiles, packageJson, ultracacheConfigurations, }?: {
95
+ export declare function selectAffectedTasks(...args: Parameters<typeof matchAffectedTasks>): ReturnType<typeof matchAffectedTasks>;
96
+ declare function matchAffectedTasks(projectGraph: ProjectGraph, nxJson: NxJsonConfiguration, planningContext: TaskPlanningContext, request: AffectedTasksRequest, { touchedFiles, packageJson, ultracacheConfigurations, }?: {
95
97
  touchedFiles?: FileChange[];
96
98
  packageJson?: any;
97
99
  ultracacheConfigurations?: UltracacheConfigurations;
@@ -101,3 +103,4 @@ export declare function selectAffectedTasks(projectGraph: ProjectGraph, nxJson:
101
103
  taskSelection: TaskSelection;
102
104
  explanation?: InternedExplanation;
103
105
  }>;
106
+ export {};
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.selectsAffectedTasks = selectsAffectedTasks;
4
+ exports.taskGranularityRequirement = taskGranularityRequirement;
4
5
  exports.computeAffectedTasks = computeAffectedTasks;
5
6
  exports.selectAffectedTasks = selectAffectedTasks;
6
7
  const native_1 = require("../../native");
@@ -16,6 +17,8 @@ const logger_1 = require("../../utils/logger");
16
17
  const error_types_1 = require("../error-types");
17
18
  const affected_reasons_1 = require("./affected-reasons");
18
19
  const workspace_root_1 = require("../../utils/workspace-root");
20
+ const delayed_spinner_1 = require("../../utils/delayed-spinner");
21
+ const progress_topics_1 = require("../../utils/progress-topics");
19
22
  const task_planning_context_1 = require("../../hasher/task-planning-context");
20
23
  const client_1 = require("../../daemon/client/client");
21
24
  const is_on_daemon_1 = require("../../daemon/is-on-daemon");
@@ -25,14 +28,23 @@ const npm_packages_1 = require("../../plugins/js/project-graph/affected/npm-pack
25
28
  const lock_file_1 = require("../../plugins/js/lock-file/lock-file");
26
29
  /**
27
30
  * Whether `nx affected` selects the individual tasks whose inputs a change
28
- * reaches, rather than whole projects. Off by default while the task path
29
- * settles.
31
+ * reaches, rather than whole projects. `NX_LEGACY_AFFECTED` overrides
32
+ * nx.json's `affected.legacy`.
30
33
  *
31
- * Env-var only, so `nx show projects --affected` and `nx affected` in one CI
32
- * script agree. The run also executes the selected tasks' dependencies.
34
+ * The run also executes the selected tasks' dependencies.
33
35
  */
34
- function selectsAffectedTasks() {
35
- return process.env.NX_LEGACY_AFFECTED === 'false';
36
+ function selectsAffectedTasks(nxJson) {
37
+ if (process.env.NX_LEGACY_AFFECTED === 'true')
38
+ return false;
39
+ if (process.env.NX_LEGACY_AFFECTED === 'false')
40
+ return true;
41
+ return !nxJson.affected?.legacy;
42
+ }
43
+ /** What to change so {@link selectsAffectedTasks} returns true, for error messages. */
44
+ function taskGranularityRequirement() {
45
+ return process.env.NX_LEGACY_AFFECTED === 'true'
46
+ ? 'NX_LEGACY_AFFECTED unset or set to false'
47
+ : 'affected.legacy unset or false in nx.json';
36
48
  }
37
49
  /**
38
50
  * Selects the tasks a change reaches, rather than the projects that own a
@@ -110,7 +122,18 @@ async function computeAffectedTasks(opts) {
110
122
  * task can read files no affected project owns. Shared by the client and the
111
123
  * daemon.
112
124
  */
113
- async function selectAffectedTasks(projectGraph, nxJson, planningContext, request, { touchedFiles = (0, file_utils_1.calculateFileChanges)(request.changedFiles, request.fileChangeArgs), packageJson, ultracacheConfigurations, } = {}) {
125
+ async function selectAffectedTasks(...args) {
126
+ const spinner = new delayed_spinner_1.DelayedSpinner('Calculating affected tasks', {
127
+ progressTopic: progress_topics_1.ProgressTopics.AffectedTasks,
128
+ });
129
+ try {
130
+ return await matchAffectedTasks(...args);
131
+ }
132
+ finally {
133
+ spinner.cleanup();
134
+ }
135
+ }
136
+ async function matchAffectedTasks(projectGraph, nxJson, planningContext, request, { touchedFiles = (0, file_utils_1.calculateFileChanges)(request.changedFiles, request.fileChangeArgs), packageJson, ultracacheConfigurations, } = {}) {
114
137
  const { targets } = request;
115
138
  // Only projects that have one of the targets: with a single target,
116
139
  // createTaskGraph tries to create a task for projects that lack it and
@@ -148,6 +171,7 @@ async function selectAffectedTasks(projectGraph, nxJson, planningContext, reques
148
171
  const dependencies = dependencyChanges(projectGraph, touchedFiles, nxJson, packageJson);
149
172
  const namedProjects = new Set(dependencies.projects);
150
173
  const projects = (0, project_graph_1.readProjectsConfigurationFromProjectGraph)(projectGraph).projects;
174
+ // TODO(v25): remove custom hasher support.
151
175
  const customHashed = new Set(taskIds.filter((id) => hasCustomHasher(taskGraph.tasks[id], projects)));
152
176
  const options = {
153
177
  projectGlobPatterns: await (0, affected_projects_1.getProjectGlobPatterns)(nxJson),
@@ -351,6 +351,13 @@ class IsolatedPlugin {
351
351
  this.shutdown();
352
352
  }
353
353
  async setWorkerEnv(env) {
354
+ // A restart may have spawned under the previous client env but not yet
355
+ // finished loading. Wait for that worker so it receives the update too.
356
+ // Do not start a stopped worker solely to forward env: its next spawn
357
+ // will inherit the daemon's already-updated environment.
358
+ if (!this._alive && this._connectPromise) {
359
+ await this._connectPromise;
360
+ }
354
361
  if (!this._alive) {
355
362
  return;
356
363
  }