@smoothbricks/nx-plugin 0.5.6 → 0.6.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 (440) hide show
  1. package/README.md +1095 -360
  2. package/dist/.build-inputs.json +138 -0
  3. package/dist/bin/smoo-nx-cargo-toolchain.d.ts +3 -0
  4. package/dist/bin/smoo-nx-cargo-toolchain.d.ts.map +1 -0
  5. package/dist/bin/smoo-nx-cargo-toolchain.js +8 -0
  6. package/dist/bin/smoo-nx-forbidden-spellings.d.ts +3 -0
  7. package/dist/bin/smoo-nx-forbidden-spellings.d.ts.map +1 -0
  8. package/dist/bin/smoo-nx-forbidden-spellings.js +32 -0
  9. package/dist/bin/smoo-nx-nextest-timings.d.ts +3 -0
  10. package/dist/bin/smoo-nx-nextest-timings.d.ts.map +1 -0
  11. package/dist/bin/smoo-nx-nextest-timings.js +28 -0
  12. package/dist/bounded-test-policy.d.ts +1 -1
  13. package/dist/bounded-test-policy.d.ts.map +1 -1
  14. package/dist/bounded-test-policy.js +14 -15
  15. package/dist/build-state-output-policy.d.ts +95 -1
  16. package/dist/build-state-output-policy.d.ts.map +1 -1
  17. package/dist/build-state-output-policy.js +368 -30
  18. package/dist/bun-lock-scope.d.ts +44 -0
  19. package/dist/bun-lock-scope.d.ts.map +1 -0
  20. package/dist/bun-lock-scope.js +97 -0
  21. package/dist/cargo-build-script-env.d.ts +49 -0
  22. package/dist/cargo-build-script-env.d.ts.map +1 -0
  23. package/dist/cargo-build-script-env.js +324 -0
  24. package/dist/cargo-closure-input.d.ts +31 -4
  25. package/dist/cargo-closure-input.d.ts.map +1 -1
  26. package/dist/cargo-closure-input.js +66 -6
  27. package/dist/cargo-retention-hook.d.ts +17 -0
  28. package/dist/cargo-retention-hook.d.ts.map +1 -0
  29. package/dist/cargo-retention-hook.js +85 -0
  30. package/dist/cargo-source-hash.d.ts +25 -7
  31. package/dist/cargo-source-hash.d.ts.map +1 -1
  32. package/dist/cargo-source-hash.js +108 -43
  33. package/dist/cargo-toolchain-paths.d.ts +40 -0
  34. package/dist/cargo-toolchain-paths.d.ts.map +1 -0
  35. package/dist/cargo-toolchain-paths.js +84 -0
  36. package/dist/cargo-toolchain-policy.d.ts +25 -8
  37. package/dist/cargo-toolchain-policy.d.ts.map +1 -1
  38. package/dist/cargo-toolchain-policy.js +39 -5
  39. package/dist/cargo-workspace.d.ts +10 -4
  40. package/dist/cargo-workspace.d.ts.map +1 -1
  41. package/dist/cargo-workspace.js +65 -95
  42. package/dist/cross-check-policy.d.ts +9 -9
  43. package/dist/cross-check-policy.d.ts.map +1 -1
  44. package/dist/cross-check-policy.js +11 -11
  45. package/dist/disk-command-policy.d.ts.map +1 -1
  46. package/dist/disk-command-policy.js +1 -0
  47. package/dist/ensure-built-receipt.d.ts +13 -5
  48. package/dist/ensure-built-receipt.d.ts.map +1 -1
  49. package/dist/ensure-built-receipt.js +126 -47
  50. package/dist/ensure-built-witness.d.ts +27 -8
  51. package/dist/ensure-built-witness.d.ts.map +1 -1
  52. package/dist/ensure-built-witness.js +45 -15
  53. package/dist/ensure-built.d.ts.map +1 -1
  54. package/dist/ensure-built.js +9 -1
  55. package/dist/eslint-config-closure.d.ts +7 -0
  56. package/dist/eslint-config-closure.d.ts.map +1 -0
  57. package/dist/eslint-config-closure.js +346 -0
  58. package/dist/executors/all-verdicts/executor.d.ts +35 -0
  59. package/dist/executors/all-verdicts/executor.d.ts.map +1 -0
  60. package/dist/executors/all-verdicts/executor.js +133 -0
  61. package/dist/executors/all-verdicts/schema.d.ts +10 -0
  62. package/dist/executors/all-verdicts/schema.d.ts.map +1 -0
  63. package/dist/executors/all-verdicts/schema.js +2 -0
  64. package/dist/executors/bounded-exec/bounds.d.ts +56 -0
  65. package/dist/executors/bounded-exec/bounds.d.ts.map +1 -0
  66. package/dist/executors/bounded-exec/bounds.js +43 -0
  67. package/dist/executors/bounded-exec/cpu-pool.d.ts +33 -36
  68. package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
  69. package/dist/executors/bounded-exec/cpu-pool.js +54 -119
  70. package/dist/executors/bounded-exec/executor.d.ts +19 -12
  71. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  72. package/dist/executors/bounded-exec/executor.js +371 -239
  73. package/dist/executors/bounded-exec/gateway-lease.d.ts +22 -19
  74. package/dist/executors/bounded-exec/gateway-lease.d.ts.map +1 -1
  75. package/dist/executors/bounded-exec/gateway-lease.js +81 -28
  76. package/dist/executors/bounded-exec/hang-diagnostics.d.ts +18 -1
  77. package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -1
  78. package/dist/executors/bounded-exec/hang-diagnostics.js +148 -30
  79. package/dist/executors/bounded-exec/lease-wait.d.ts +43 -0
  80. package/dist/executors/bounded-exec/lease-wait.d.ts.map +1 -0
  81. package/dist/executors/bounded-exec/lease-wait.js +68 -0
  82. package/dist/executors/bounded-exec/lock-wait.d.ts +51 -0
  83. package/dist/executors/bounded-exec/lock-wait.d.ts.map +1 -0
  84. package/dist/executors/bounded-exec/lock-wait.js +108 -0
  85. package/dist/executors/bounded-exec/owned-subtree.d.ts +84 -0
  86. package/dist/executors/bounded-exec/owned-subtree.d.ts.map +1 -0
  87. package/dist/executors/bounded-exec/owned-subtree.js +178 -0
  88. package/dist/executors/bounded-exec/progress.d.ts +4 -1
  89. package/dist/executors/bounded-exec/progress.d.ts.map +1 -1
  90. package/dist/executors/bounded-exec/progress.js +5 -2
  91. package/dist/executors/bounded-exec/ram-attach.d.ts +19 -0
  92. package/dist/executors/bounded-exec/ram-attach.d.ts.map +1 -0
  93. package/dist/executors/bounded-exec/ram-attach.js +207 -0
  94. package/dist/executors/bounded-exec/ram-detach.d.ts +25 -0
  95. package/dist/executors/bounded-exec/ram-detach.d.ts.map +1 -0
  96. package/dist/executors/bounded-exec/ram-detach.js +207 -0
  97. package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts +76 -0
  98. package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts.map +1 -1
  99. package/dist/executors/bounded-exec/ram-temp-fixtures.js +296 -0
  100. package/dist/executors/bounded-exec/ram-temp.d.ts +388 -88
  101. package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -1
  102. package/dist/executors/bounded-exec/ram-temp.js +1213 -399
  103. package/dist/executors/bounded-exec/run-cpu-pool.d.ts +4 -4
  104. package/dist/executors/bounded-exec/run-cpu-pool.d.ts.map +1 -1
  105. package/dist/executors/bounded-exec/run-cpu-pool.js +20 -30
  106. package/dist/executors/bounded-exec/runner-hook.js +14 -5
  107. package/dist/executors/bounded-exec/runner-lifecycle.d.ts +14 -1
  108. package/dist/executors/bounded-exec/runner-lifecycle.d.ts.map +1 -1
  109. package/dist/executors/bounded-exec/runner-lifecycle.js +27 -6
  110. package/dist/executors/bounded-exec/{cpu-tokens.d.ts → runner-sizing.d.ts} +14 -42
  111. package/dist/executors/bounded-exec/runner-sizing.d.ts.map +1 -0
  112. package/dist/executors/bounded-exec/{cpu-tokens.js → runner-sizing.js} +5 -35
  113. package/dist/executors/bounded-exec/runtime-pin.d.ts +73 -0
  114. package/dist/executors/bounded-exec/runtime-pin.d.ts.map +1 -0
  115. package/dist/executors/bounded-exec/runtime-pin.js +167 -0
  116. package/dist/executors/bounded-exec/schema.d.ts +18 -1
  117. package/dist/executors/bounded-exec/schema.d.ts.map +1 -1
  118. package/dist/executors/bounded-exec/verdict.d.ts +40 -11
  119. package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
  120. package/dist/executors/bounded-exec/verdict.js +88 -19
  121. package/dist/executors/cargo-zigbuild/executor.d.ts +21 -0
  122. package/dist/executors/cargo-zigbuild/executor.d.ts.map +1 -1
  123. package/dist/executors/cargo-zigbuild/executor.js +67 -12
  124. package/dist/executors/clean-outputs/executor.js +1 -0
  125. package/dist/executors/scriptc-native/executor.d.ts +79 -0
  126. package/dist/executors/scriptc-native/executor.d.ts.map +1 -0
  127. package/dist/executors/scriptc-native/executor.js +367 -0
  128. package/dist/executors/scriptc-native/ffi-paths.d.ts +9 -0
  129. package/dist/executors/scriptc-native/ffi-paths.d.ts.map +1 -0
  130. package/dist/executors/scriptc-native/ffi-paths.js +25 -0
  131. package/dist/executors/scriptc-native/schema.d.ts +34 -0
  132. package/dist/executors/scriptc-native/schema.d.ts.map +1 -0
  133. package/dist/executors/scriptc-native/schema.js +1 -0
  134. package/dist/executors/typescript-emit/executor.d.ts +3 -1
  135. package/dist/executors/typescript-emit/executor.d.ts.map +1 -1
  136. package/dist/executors/typescript-emit/executor.js +164 -33
  137. package/dist/forbidden-spelling-policy.d.ts +56 -0
  138. package/dist/forbidden-spelling-policy.d.ts.map +1 -0
  139. package/dist/forbidden-spelling-policy.js +176 -0
  140. package/dist/generators/create-package/generator.d.ts.map +1 -1
  141. package/dist/generators/create-package/generator.js +3 -4
  142. package/dist/graph-input-contract.d.ts +14 -0
  143. package/dist/graph-input-contract.d.ts.map +1 -1
  144. package/dist/graph-input-contract.js +67 -2
  145. package/dist/index.d.ts +23 -6
  146. package/dist/index.d.ts.map +1 -1
  147. package/dist/index.js +676 -215
  148. package/dist/managed-assets.d.ts +2 -0
  149. package/dist/managed-assets.d.ts.map +1 -1
  150. package/dist/managed-files/files.d.ts +3 -3
  151. package/dist/managed-files/files.d.ts.map +1 -1
  152. package/dist/managed-files/files.js +28 -3
  153. package/dist/managed-files/managed-format.d.ts.map +1 -1
  154. package/dist/managed-files/managed-format.js +1 -0
  155. package/dist/nextest-code-bound.js +1 -0
  156. package/dist/nextest-timings.d.ts +35 -0
  157. package/dist/nextest-timings.d.ts.map +1 -0
  158. package/dist/nextest-timings.js +168 -0
  159. package/dist/owned-installation.d.ts +6 -5
  160. package/dist/owned-installation.d.ts.map +1 -1
  161. package/dist/owned-installation.js +150 -26
  162. package/dist/package-target-policy.d.ts.map +1 -1
  163. package/dist/package-target-policy.js +2 -3
  164. package/dist/process-children.d.ts +7 -0
  165. package/dist/process-children.d.ts.map +1 -0
  166. package/dist/process-children.darwin.d.ts +7 -0
  167. package/dist/process-children.darwin.d.ts.map +1 -0
  168. package/dist/process-children.darwin.js +13 -0
  169. package/dist/process-children.js +14 -0
  170. package/dist/process-children.linux.d.ts +8 -0
  171. package/dist/process-children.linux.d.ts.map +1 -0
  172. package/dist/process-children.linux.js +25 -0
  173. package/dist/process-group.d.ts +108 -0
  174. package/dist/process-group.d.ts.map +1 -0
  175. package/dist/process-group.js +171 -0
  176. package/dist/process-listing.d.ts +7 -0
  177. package/dist/process-listing.d.ts.map +1 -0
  178. package/dist/process-listing.js +51 -0
  179. package/dist/producer-receipts.d.ts +8 -2
  180. package/dist/producer-receipts.d.ts.map +1 -1
  181. package/dist/producer-receipts.js +75 -48
  182. package/dist/task-graph-policy.d.ts +21 -0
  183. package/dist/task-graph-policy.d.ts.map +1 -0
  184. package/dist/task-graph-policy.js +91 -0
  185. package/dist/test-timings.js +4 -4
  186. package/dist/test-walk-policy.d.ts +14 -5
  187. package/dist/test-walk-policy.d.ts.map +1 -1
  188. package/dist/test-walk-policy.js +8 -2
  189. package/dist/testing.d.ts +73 -28
  190. package/dist/testing.d.ts.map +1 -1
  191. package/dist/testing.js +217 -223
  192. package/dist/tool-bins.d.ts +33 -0
  193. package/dist/tool-bins.d.ts.map +1 -0
  194. package/dist/tool-bins.js +72 -0
  195. package/dist/typecheck-test-policy.d.ts.map +1 -1
  196. package/dist/typecheck-test-policy.js +3 -4
  197. package/dist/wait-why-policy.d.ts +28 -0
  198. package/dist/wait-why-policy.d.ts.map +1 -0
  199. package/dist/wait-why-policy.js +223 -0
  200. package/dist/workspace-config-policy.d.ts +14 -8
  201. package/dist/workspace-config-policy.d.ts.map +1 -1
  202. package/dist/workspace-config-policy.js +60 -16
  203. package/dist/workspace-manifest.d.ts +41 -6
  204. package/dist/workspace-manifest.d.ts.map +1 -1
  205. package/dist/workspace-manifest.js +57 -0
  206. package/executors.json +21 -1
  207. package/loader.js +2 -0
  208. package/managed/raw/envrc +11 -0
  209. package/managed/raw/patches/nx@23.2.1.patch +2840 -199
  210. package/managed/raw/patches/ttsc@0.34.1.patch +119 -0
  211. package/managed/raw/tooling/direnv/cargo-fetch-bound.ts +245 -0
  212. package/managed/raw/tooling/direnv/cargo-fetch-run.ts +299 -0
  213. package/managed/raw/tooling/direnv/compiler-variables.sh +42 -0
  214. package/managed/raw/tooling/direnv/developer-links.ts +464 -25
  215. package/managed/raw/tooling/direnv/devenv.smoo.nix +78 -38
  216. package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +14 -12
  217. package/managed/raw/tooling/direnv/installed-bun-links.ts +308 -0
  218. package/managed/raw/tooling/direnv/linked-snapshots.ts +62 -3
  219. package/managed/raw/tooling/direnv/nx-socket-dir.sh +56 -17
  220. package/managed/raw/tooling/direnv/repo-path +68 -6
  221. package/managed/raw/tooling/direnv/secret-references.ts +13 -4
  222. package/managed/raw/tooling/direnv/setup-environment.ts +128 -537
  223. package/managed/raw/tooling/direnv/toolchain-stamp.ts +4 -2
  224. package/managed/raw/tooling/direnv/ttsc-env.sh +9 -0
  225. package/managed/raw/tooling/direnv/uv-relocation.ts +227 -0
  226. package/managed/raw/tooling/git-hooks/commit-msg.sh +2 -1
  227. package/managed/raw/tooling/git-hooks/pre-commit.sh +2 -1
  228. package/managed/raw/tooling/git-hooks/pre-push.sh +2 -1
  229. package/managed/templates/github/actions/cache-ttsc-plugins/action.yml +85 -7
  230. package/managed/templates/github/actions/save-nix-devenv/action.yml +12 -2
  231. package/managed/templates/github/actions/setup-devenv/action.yml +2 -0
  232. package/package.json +77 -13
  233. package/src/bin/smoo-nx-cargo-toolchain.ts +11 -0
  234. package/src/bin/smoo-nx-forbidden-spellings.ts +33 -0
  235. package/src/bin/smoo-nx-nextest-timings.ts +31 -0
  236. package/src/bounded-test-policy.ts +12 -14
  237. package/src/build-state-output-policy.ts +458 -34
  238. package/src/bun-lock-scope.ts +108 -0
  239. package/src/cargo-build-script-env.ts +265 -0
  240. package/src/cargo-closure-input.ts +74 -7
  241. package/src/cargo-retention-hook.ts +94 -0
  242. package/src/cargo-source-hash.ts +138 -41
  243. package/src/cargo-toolchain-paths.ts +95 -0
  244. package/src/cargo-toolchain-policy.ts +49 -5
  245. package/src/cargo-workspace.ts +72 -123
  246. package/src/cross-check-policy.ts +12 -10
  247. package/src/disk-command-policy.ts +1 -0
  248. package/src/ensure-built-receipt.ts +132 -39
  249. package/src/ensure-built-witness.ts +62 -10
  250. package/src/ensure-built.ts +11 -1
  251. package/src/eslint-config-closure.ts +357 -0
  252. package/src/executors/all-verdicts/executor.ts +164 -0
  253. package/src/executors/all-verdicts/schema.json +22 -0
  254. package/src/executors/all-verdicts/schema.ts +10 -0
  255. package/src/executors/bounded-exec/bounds.ts +76 -0
  256. package/src/executors/bounded-exec/cpu-pool.ts +51 -117
  257. package/src/executors/bounded-exec/executor.ts +423 -259
  258. package/src/executors/bounded-exec/gateway-lease.ts +82 -33
  259. package/src/executors/bounded-exec/hang-diagnostics.ts +173 -31
  260. package/src/executors/bounded-exec/lease-wait.ts +89 -0
  261. package/src/executors/bounded-exec/lock-wait.ts +141 -0
  262. package/src/executors/bounded-exec/owned-subtree.ts +235 -0
  263. package/src/executors/bounded-exec/progress.ts +9 -3
  264. package/src/executors/bounded-exec/ram-attach.ts +238 -0
  265. package/src/executors/bounded-exec/ram-detach.ts +226 -0
  266. package/src/executors/bounded-exec/ram-temp-fixtures.ts +358 -0
  267. package/src/executors/bounded-exec/ram-temp-registry.txt +440 -0
  268. package/src/executors/bounded-exec/ram-temp.ts +1497 -460
  269. package/src/executors/bounded-exec/run-cpu-pool.ts +22 -30
  270. package/src/executors/bounded-exec/runner-hook.ts +14 -6
  271. package/src/executors/bounded-exec/runner-lifecycle.ts +31 -8
  272. package/src/executors/bounded-exec/{cpu-tokens.ts → runner-sizing.ts} +13 -59
  273. package/src/executors/bounded-exec/runtime-pin.ts +232 -0
  274. package/src/executors/bounded-exec/schema.json +11 -2
  275. package/src/executors/bounded-exec/schema.ts +19 -1
  276. package/src/executors/bounded-exec/verdict.ts +137 -34
  277. package/src/executors/cargo-zigbuild/executor.ts +82 -8
  278. package/src/executors/clean-outputs/executor.ts +1 -0
  279. package/src/executors/scriptc-native/executor.ts +394 -0
  280. package/src/executors/scriptc-native/ffi-paths.ts +29 -0
  281. package/src/executors/scriptc-native/schema.json +60 -0
  282. package/src/executors/scriptc-native/schema.ts +34 -0
  283. package/src/executors/typescript-emit/executor.ts +205 -38
  284. package/src/forbidden-spelling-policy.ts +226 -0
  285. package/src/generators/create-package/generator.ts +7 -7
  286. package/src/graph-input-contract.ts +61 -2
  287. package/src/index.ts +792 -225
  288. package/src/managed-assets.ts +3 -0
  289. package/src/managed-files/files.ts +28 -3
  290. package/src/managed-files/managed-format.ts +1 -0
  291. package/src/nextest-code-bound.ts +1 -0
  292. package/src/nextest-timings.ts +106 -0
  293. package/src/owned-installation.ts +150 -23
  294. package/src/package-target-policy.ts +2 -3
  295. package/src/process-children.darwin.ts +14 -0
  296. package/src/process-children.linux.ts +33 -0
  297. package/src/process-children.ts +22 -0
  298. package/src/process-group.ts +209 -0
  299. package/src/process-listing.ts +54 -0
  300. package/src/producer-receipts.ts +68 -45
  301. package/src/task-graph-policy.ts +98 -0
  302. package/src/test-walk-policy.ts +23 -8
  303. package/src/testing.ts +240 -232
  304. package/src/tool-bins.ts +108 -0
  305. package/src/typecheck-test-policy.ts +2 -3
  306. package/src/wait-why-policy.ts +226 -0
  307. package/src/workspace-config-policy.ts +63 -15
  308. package/src/workspace-manifest.ts +89 -6
  309. package/test-timings.json +123 -98
  310. package/dist/bin/smoo-nx-failures.d.ts +0 -3
  311. package/dist/bin/smoo-nx-failures.d.ts.map +0 -1
  312. package/dist/bin/smoo-nx-failures.js +0 -3
  313. package/dist/bin/smoo-nx-nextest-extract.d.ts +0 -3
  314. package/dist/bin/smoo-nx-nextest-extract.d.ts.map +0 -1
  315. package/dist/bin/smoo-nx-nextest-extract.js +0 -42
  316. package/dist/executors/bounded-exec/cpu-tokens.d.ts.map +0 -1
  317. package/dist/failure-summary.d.ts +0 -5
  318. package/dist/failure-summary.d.ts.map +0 -1
  319. package/dist/failure-summary.js +0 -118
  320. package/dist/nextest-extraction.d.ts +0 -117
  321. package/dist/nextest-extraction.d.ts.map +0 -1
  322. package/dist/nextest-extraction.js +0 -303
  323. package/managed/raw/patches/ttsc@0.30.4.patch +0 -2255
  324. package/src/__tests__/cargo-closure-filesets.ts +0 -94
  325. package/src/__tests__/cargo-closure-fixture.ts +0 -113
  326. package/src/__tests__/counted-cargo-process.ts +0 -286
  327. package/src/__tests__/counted-cargo.ts +0 -713
  328. package/src/__tests__/directory-change.ts +0 -27
  329. package/src/__tests__/fixture-cargo-home.ts +0 -36
  330. package/src/__tests__/fixture-nx-env.ts +0 -193
  331. package/src/__tests__/owned-installation.ts +0 -13
  332. package/src/__tests__/past-tick.ts +0 -12
  333. package/src/__tests__/progress-clock.ts +0 -43
  334. package/src/__tests__/runtime-input.ts +0 -23
  335. package/src/bin/smoo-nx-bound-failures.test.ts +0 -127
  336. package/src/bin/smoo-nx-failures.ts +0 -4
  337. package/src/bin/smoo-nx-nextest-extract.ts +0 -44
  338. package/src/bounded-test-policy.test.ts +0 -1029
  339. package/src/build-state-output-policy.test.ts +0 -115
  340. package/src/bun-bootstrap.test.ts +0 -102
  341. package/src/bun-file-packages.test.ts +0 -47
  342. package/src/cargo-closure-filesets.test.ts +0 -63
  343. package/src/cargo-closure-input.property.test.ts +0 -50
  344. package/src/cargo-closure-input.test.ts +0 -506
  345. package/src/cargo-closure-key.test.ts +0 -240
  346. package/src/cargo-resolve-cache.test.ts +0 -1181
  347. package/src/cargo-source-hash.test.ts +0 -707
  348. package/src/cargo-workspace.test.ts +0 -615
  349. package/src/cross-check-policy.test.ts +0 -316
  350. package/src/disk-command-policy.test.ts +0 -61
  351. package/src/ensure-built-receipt.test.ts +0 -279
  352. package/src/ensure-built-witness.test.ts +0 -688
  353. package/src/ensure-built.test.ts +0 -1462
  354. package/src/executors/bounded-exec/cargo-progress-host.test.ts +0 -332
  355. package/src/executors/bounded-exec/cpu-pool.test.ts +0 -684
  356. package/src/executors/bounded-exec/cpu-tokens.test.ts +0 -519
  357. package/src/executors/bounded-exec/disk-lease.test.ts +0 -219
  358. package/src/executors/bounded-exec/executor-host.test.ts +0 -800
  359. package/src/executors/bounded-exec/executor.test.ts +0 -1819
  360. package/src/executors/bounded-exec/go-progress-host.test.ts +0 -171
  361. package/src/executors/bounded-exec/hang-diagnostics.test.ts +0 -291
  362. package/src/executors/bounded-exec/progress.test.ts +0 -139
  363. package/src/executors/bounded-exec/ram-temp-held.test.ts +0 -264
  364. package/src/executors/bounded-exec/ram-temp-host.test.ts +0 -635
  365. package/src/executors/bounded-exec/ram-temp.test.ts +0 -750
  366. package/src/executors/bounded-exec/run-cpu-pool.test.ts +0 -79
  367. package/src/executors/bounded-exec/runner-hook.test.ts +0 -193
  368. package/src/executors/bounded-exec/runner-lifecycle.test.ts +0 -82
  369. package/src/executors/bounded-exec/verdict.test.ts +0 -545
  370. package/src/executors/cargo-zigbuild/executor.test.ts +0 -129
  371. package/src/executors/clean-outputs/executor.test.ts +0 -20
  372. package/src/executors/typescript-emit/executor.test.ts +0 -83
  373. package/src/failure-summary.ts +0 -119
  374. package/src/generators/bounded-test-targets/generator.test.ts +0 -138
  375. package/src/generators/bun-test-tracing/generator.test.ts +0 -250
  376. package/src/generators/create-package/generator.test.ts +0 -190
  377. package/src/generators/make-public/generator.test.ts +0 -137
  378. package/src/graph-input-contract.test.ts +0 -379
  379. package/src/host-controller-wiring.test.ts +0 -31
  380. package/src/index.test.ts +0 -3319
  381. package/src/linked-snapshots.nx.test.ts +0 -254
  382. package/src/managed-files/forgejo-artifact.test.ts +0 -395
  383. package/src/managed-files/generator.test.ts +0 -243
  384. package/src/managed-files/github-host-cache-isolation.test.ts +0 -86
  385. package/src/managed-files/json-edit.test.ts +0 -216
  386. package/src/managed-files/managed-content.test.ts +0 -166
  387. package/src/managed-files/managed-format-json.test.ts +0 -308
  388. package/src/managed-files/repo-path.test.ts +0 -172
  389. package/src/managed-files/setup-devenv-free-disk.test.ts +0 -95
  390. package/src/managed-files/trace-db-artifact.test.ts +0 -7
  391. package/src/managed-files/tree-permissions.test.ts +0 -109
  392. package/src/managed-files/tree.test.ts +0 -123
  393. package/src/manifest-hash.test.ts +0 -219
  394. package/src/nextest-code-bound.test.ts +0 -161
  395. package/src/nextest-extraction.test.ts +0 -216
  396. package/src/nextest-extraction.ts +0 -371
  397. package/src/nextest-partitions.test.ts +0 -501
  398. package/src/nx-cache-bound.test.ts +0 -109
  399. package/src/nx-cache-restore-mtime.test.ts +0 -170
  400. package/src/nx-daemon-claim.test.ts +0 -279
  401. package/src/nx-daemon-idle-cpu.test.ts +0 -80
  402. package/src/nx-daemon-idle-policy.test.ts +0 -111
  403. package/src/nx-daemon-ignore-files.test.ts +0 -210
  404. package/src/nx-daemon-root-normalization.test.ts +0 -105
  405. package/src/nx-daemon-start-never.test.ts +0 -292
  406. package/src/nx-daemon-validity.test.ts +0 -1055
  407. package/src/nx-dot-input-policy.test.ts +0 -353
  408. package/src/nx-failure-life-cycles.test.ts +0 -207
  409. package/src/nx-files-archive-racy.test.ts +0 -97
  410. package/src/nx-foreign-workspace-env.test.ts +0 -329
  411. package/src/nx-incomplete-run-summary.test.ts +0 -70
  412. package/src/nx-plugin-load-errors.test.ts +0 -120
  413. package/src/nx-project-graph-errors.test.ts +0 -70
  414. package/src/nx-project-resolution-cache.test.ts +0 -176
  415. package/src/nx-raw-inputs.test.ts +0 -166
  416. package/src/nx-resident-graph-workers.test.ts +0 -112
  417. package/src/nx-run-information.test.ts +0 -118
  418. package/src/nx-skipped-task-exit.test.ts +0 -180
  419. package/src/nx-state-location.test.ts +0 -63
  420. package/src/nx-store-resolution.test.ts +0 -81
  421. package/src/nx-task-graph-cycles.test.ts +0 -148
  422. package/src/nx-task-output-lease.test.ts +0 -550
  423. package/src/nx-use-local.test.ts +0 -105
  424. package/src/owned-installation.test.ts +0 -105
  425. package/src/package-target-policy.test.ts +0 -1014
  426. package/src/producer-receipts.test.ts +0 -285
  427. package/src/release-config-policy.test.ts +0 -311
  428. package/src/runtime-input.test.ts +0 -393
  429. package/src/serial-group-wiring.test.ts +0 -326
  430. package/src/task-history-namespace.test.ts +0 -181
  431. package/src/task-results.test.ts +0 -228
  432. package/src/test-clock-policy.test.ts +0 -338
  433. package/src/test-program.test.ts +0 -303
  434. package/src/test-timings.test.ts +0 -240
  435. package/src/test-walk-policy.test.ts +0 -620
  436. package/src/testing.test.ts +0 -509
  437. package/src/typecheck-test-policy.test.ts +0 -1468
  438. package/src/typescript-resolution.test.ts +0 -76
  439. package/src/version-actions.test.ts +0 -80
  440. package/src/workspace-config-policy.test.ts +0 -737
package/src/index.ts CHANGED
@@ -3,39 +3,48 @@ import { readdir, readFile } from 'node:fs/promises';
3
3
  import { createRequire } from 'node:module';
4
4
  import { dirname, isAbsolute, join, posix, relative, resolve, sep } from 'node:path';
5
5
  import { fileURLToPath } from 'node:url';
6
-
7
6
  import {
7
+ EXTRACTED_BINARIES_METADATA,
8
+ EXTRACTED_CARGO_METADATA,
9
+ EXTRACTED_TARGET_DIR,
10
+ NEXTEST_ARCHIVE_KEY_SUFFIX,
11
+ } from '@smoothbricks/nextest-extract';
12
+ import {
13
+ type CreateDependencies,
14
+ type CreateMetadata,
8
15
  type CreateNodesContextV2,
9
16
  type CreateNodesResultV2,
10
17
  type CreateNodesV2,
11
18
  type PostTasksExecution,
12
19
  type PreTasksExecution,
20
+ type ProjectGraphExternalNode,
13
21
  readJsonFile,
14
22
  type TargetConfiguration,
15
23
  } from 'nx/src/devkit-exports.js';
16
24
  import { AggregateCreateNodesError } from 'nx/src/project-graph/error-types.js';
17
25
  import { parse as parseToml } from 'smol-toml';
18
26
  import { type ParsedCommandLine, parseJsonConfigFileContent, readConfigFile, sys as typescriptSys } from 'typescript';
19
-
20
27
  import { BOUNDED_TEST_IDLE_TIMEOUT_MS, BOUNDED_TEST_KILL_AFTER_MS } from './bounded-test-policy.js';
28
+ import { refuseOverlappingOutputs } from './build-state-output-policy.js';
29
+ import { bunLockDependencies, bunLockInput, bunLockNode } from './bun-lock-scope.js';
21
30
  import {
22
31
  CARGO_CLOSURE_INPUT,
32
+ CARGO_LOCK_NODE_PREFIX,
23
33
  type CargoClosureSource,
24
34
  cargoClosureInputs,
35
+ cargoLockNode,
36
+ cargoLockNodeName,
25
37
  indexedCargoManifests,
38
+ isCargoLockInput,
26
39
  resolveCargoClosureSource,
27
40
  } from './cargo-closure-input.js';
28
- import {
29
- CARGO_TOOLCHAIN_NAMED_INPUT,
30
- CARGO_TOOLCHAIN_PIN_INPUTS,
31
- cargoRuntimeInput,
32
- } from './cargo-toolchain-policy.js';
41
+ import { CARGO_PRODUCER_METADATA, postTasksExecution as postCargoRetention } from './cargo-retention-hook.js';
42
+ import { CARGO_TOOLCHAIN_NAMED_INPUT, cargoRuntimeInput, cargoToolchainInputs } from './cargo-toolchain-policy.js';
33
43
  import {
34
44
  type AttributedCargoWorkspacePackage,
35
45
  attributeCargoWorkspacePackages,
36
46
  CARGO_TEST_ARCHIVE_FILE,
37
47
  CARGO_TEST_ARCHIVE_TARGET,
38
- CARGO_TEST_COMPILE_TARGET,
39
48
  CARGO_TEST_EXCEPTIONS_SUFFIX,
40
49
  CARGO_TEST_TARGET,
41
50
  type CargoCrossTestTarget,
@@ -44,12 +53,14 @@ import {
44
53
  cargoTestGroupTargetName,
45
54
  cargoTestPackageTargetName,
46
55
  createCargoInputsCache,
56
+ EXTERNAL_RUST_CRATES_INPUT,
47
57
  exceptionalTestFilter,
48
58
  listCargoCrossTestTargets,
49
59
  listCargoWorkspacePackages,
50
60
  NEXTEST_REPO_CONFIG_PATH,
51
61
  nextestToolConfigArg,
52
62
  PLUGIN_NEXTEST_CONFIG_PATH,
63
+ requireExternalRustCratesInput,
53
64
  type SerialTestGroup,
54
65
  serialTestGroups,
55
66
  } from './cargo-workspace.js';
@@ -65,15 +76,14 @@ import {
65
76
  cargoFrozen,
66
77
  runsFrozenCargo,
67
78
  } from './cross-check-policy.js';
79
+ import { eslintConfigClosure } from './eslint-config-closure.js';
68
80
  import type { EslintFileSet } from './eslint-file-set.js';
81
+ import { ALL_VERDICTS_EXECUTOR } from './executors/all-verdicts/schema.js';
69
82
  import { closeRunCpuPool, serveRunCpuPool } from './executors/bounded-exec/run-cpu-pool.js';
83
+ import { ffiPathProblem } from './executors/scriptc-native/ffi-paths.js';
84
+ import type { ScriptcNativeFfi } from './executors/scriptc-native/schema.js';
70
85
  import { hashVersionlessCrateManifests } from './manifest-hash.js';
71
- import {
72
- EXTRACTED_BINARIES_METADATA,
73
- EXTRACTED_CARGO_METADATA,
74
- EXTRACTED_TARGET_DIR,
75
- NEXTEST_EXTRACT_BIN,
76
- } from './nextest-extraction.js';
86
+ import { NEXTEST_TIMINGS_PATH, namedTestsFilter, readNextestTimings, timedShardMembers } from './nextest-timings.js';
77
87
  import {
78
88
  type ProducerReceiptsOptions,
79
89
  postTasksExecution as postProducerReceipts,
@@ -81,26 +91,27 @@ import {
81
91
  } from './producer-receipts.js';
82
92
  import { runtimeInput, shellWord } from './runtime-input.js';
83
93
  import { isNonSourceDirectory } from './source-directories.js';
94
+ import { inferredTaskKind, refuseBuildTestDependencies } from './task-graph-policy.js';
84
95
  import { postTasksExecution as postTaskResults, preTasksExecution as preTaskResults } from './task-results.js';
85
96
  import { SHARD_TIMINGS_EXECUTOR, SHARD_TIMINGS_TARGET, timingsShardedSuite } from './test-timings.js';
86
97
  import { assertUpstreamBasePrecondition } from './test-walk-policy.js';
98
+ import { type NativeTools, nativeToolCommand, nativeToolDependsOn, resolveNativeTools } from './tool-bins.js';
87
99
  import {
88
100
  isBuildOutputTargetName,
101
+ isTestNamespaceTargetName,
89
102
  isTestRunnerTargetName,
90
103
  PLATFORM_TARGET_GLOBS,
91
104
  RELEASE_CONFIGURATION,
92
105
  } from './workspace-config-policy.js';
93
106
  import { globIndexedFiles } from './workspace-index.js';
94
107
 
95
- export { CARGO_TEST_COMPILE_TARGET };
96
-
97
108
  /** Makes a version live and proves it answers; never cached. */
98
109
  export const DEPLOY_TARGET = 'deploy';
99
110
  /** The purely file-derived half a deploy needs built first; cached. */
100
111
  export const DEPLOY_BUILD_TARGET = 'deploy-build';
101
112
 
102
- /** The workspace-wide manifests a release rewrites: the version of every member, and the lockfile mirror of it. */
103
- const RELEASE_REWRITTEN_WORKSPACE_INPUTS = ['{workspaceRoot}/package.json', '{workspaceRoot}/bun.lock'];
113
+ /** The workspace-wide manifest a release rewrites: the version of every member. */
114
+ const RELEASE_REWRITTEN_WORKSPACE_INPUTS = ['{workspaceRoot}/package.json'];
104
115
  /** Installed patch bytes and pins affect the compiler; Markdown explains them but is not loaded. */
105
116
  const TYPESCRIPT_PATCH_INPUTS = ['{workspaceRoot}/patches/**/*', '!{workspaceRoot}/patches/**/*.md'];
106
117
  /**
@@ -129,16 +140,16 @@ function typecheckCommand(args: string): string {
129
140
  }
130
141
 
131
142
  /**
132
- * The two release-rewritten files hashed by field instead of by byte, for a
133
- * check that only reads them.
143
+ * The release-rewritten root manifest hashed by field instead of by byte, for
144
+ * a check that only reads it.
134
145
  *
135
146
  * A `json` input is hashed by Nx's own hasher, so this costs no process. The
136
- * lockfile's `workspaces` section is the mirror of each member's manifest —
137
- * name, version and dependency specifiers — and every one of those is already
138
- * hashed from the member's own `package.json`. Dropping that section keeps the
139
- * resolution table, which is the reason the lockfile is an input at all.
147
+ * lockfile is no file input at all: the packages it resolves reach a task as
148
+ * Nx's own lockfile nodes, the root manifest's through the bun root lock-scope
149
+ * node and the project's through its `^` input, so a release's rewrite of the
150
+ * lockfile's `workspaces` mirror re-keys nothing.
140
151
  *
141
- * The root manifest also drops `scripts`, `smoo` and `nx`. No lint or
152
+ * The root manifest drops `scripts`, `smoo` and `nx`. No lint or
142
153
  * typecheck reads them: `scripts` are commands a developer runs, `smoo` holds
143
154
  * the developer links whose linked bytes reach the hash only through their own
144
155
  * inputs, and the root project's `nx` configuration is hashed as that
@@ -149,7 +160,6 @@ function typecheckCommand(args: string): string {
149
160
  */
150
161
  const VERSIONLESS_TOOLCHAIN_MANIFEST_INPUTS = [
151
162
  { json: '{workspaceRoot}/package.json', excludeFields: ['version', 'scripts', 'smoo', 'nx'] },
152
- { json: '{workspaceRoot}/bun.lock', excludeFields: ['workspaces'] },
153
163
  ];
154
164
 
155
165
  /** A path segment Nx's workspace file map never carries, so a fileset naming it hashes nothing. */
@@ -272,8 +282,8 @@ function resolveTypescriptConfigExtends(specifier: string, fromConfigPath: strin
272
282
  * Nx hashes workspace files that are not in node_modules, so two ancestor
273
283
  * kinds cannot be named — and they are not the same thing:
274
284
  *
275
- * - a dependency's config: `bun.lock` and the root manifest decide which
276
- * bytes are installed, and both are already inputs. Where they sit is the
285
+ * - a dependency's config: the lockfile entry of the package that holds it
286
+ * decides which bytes are installed, and the task is keyed on it. Where they sit is the
277
287
  * installer's business — bun keeps them in a global store outside the
278
288
  * workspace entirely — so this is settled by HOW the specifier resolved,
279
289
  * not by where it landed. A workspace member reached through its package
@@ -317,6 +327,14 @@ const VERSIONLESS_PACKAGE_INPUTS = [
317
327
  { json: '{projectRoot}/package.json', excludeFields: ['version'] },
318
328
  ];
319
329
 
330
+ /**
331
+ * The root project owns the lockfiles, so its `default` fileset holds each
332
+ * whole, and a check keyed on it re-ran on every dependency change anywhere in
333
+ * the workspace. Its checks name what the lockfiles decide for it instead: the
334
+ * root manifest's bun lock-scope node and, for a root Cargo workspace, the
335
+ * Cargo nodes of its targets. No other project's fileset ever held them.
336
+ */
337
+ const ROOT_LOCKFILE_EXCLUSIONS = ['!{projectRoot}/bun.lock', '!{projectRoot}/bun.lockb', '!{projectRoot}/Cargo.lock'];
320
338
  /**
321
339
  * Crate manifests, for the projects that have any.
322
340
  *
@@ -356,9 +374,17 @@ const ESLINT_CONFIG_FILES = [
356
374
  /** Every JavaScript and TypeScript module kind ESLint is handed. */
357
375
  const ESLINT_SOURCES_GLOB = '**/*.{js,jsx,cjs,mjs,ts,tsx,cts,mts}';
358
376
 
377
+ /** What ESLint lints in this workspace and what its configuration loads. */
378
+ interface EslintWorkspace {
379
+ /** The JavaScript and TypeScript files of Nx's workspace file index. */
380
+ readonly sources: ReadonlySet<string>;
381
+ /** The workspace modules the root configs load, transitively, workspace-relative and sorted; the configs excluded. */
382
+ readonly configImports: readonly string[];
383
+ }
384
+
359
385
  /**
360
- * The JavaScript and TypeScript files of Nx's workspace file index, listed once
361
- * per graph computation; `null` when no workspace ESLint config enables ESLint.
386
+ * The ESLint sources and config closure of Nx's workspace file index, listed
387
+ * once per graph computation; `null` when no workspace ESLint config enables ESLint.
362
388
  *
363
389
  * The ESLint file list is part of the lint target's command, metadata and
364
390
  * inputs, and Nx hashes the whole target configuration into every task that
@@ -368,10 +394,20 @@ const ESLINT_SOURCES_GLOB = '**/*.{js,jsx,cjs,mjs,ts,tsx,cts,mts}';
368
394
  * and a fresh fork's did not, which alone re-keyed 197 of 510 gate tasks.
369
395
  * Drawing the list from the index makes the plugin and the hasher agree on one
370
396
  * file set.
397
+ *
398
+ * The configs key every lint target with exactly the workspace files they
399
+ * load (eslint-config-closure.ts): a glob over the directory holding a
400
+ * config's rule modules keyed every file beside them, and one test fixture
401
+ * there re-keyed 44 lint targets in one land.
371
402
  */
372
- async function indexedEslintSources(workspaceRoot: string): Promise<ReadonlySet<string> | null> {
373
- if (!ESLINT_CONFIG_FILES.some((name) => existsSync(join(workspaceRoot, name)))) return null;
374
- return new Set(await globIndexedFiles(workspaceRoot, [ESLINT_SOURCES_GLOB]));
403
+ async function eslintWorkspace(workspaceRoot: string): Promise<EslintWorkspace | null> {
404
+ const configs = ESLINT_CONFIG_FILES.filter((name) => existsSync(join(workspaceRoot, name)));
405
+ if (configs.length === 0) return null;
406
+ const indexed = new Set(await globIndexedFiles(workspaceRoot, [ESLINT_SOURCES_GLOB, '**/*.json']));
407
+ return {
408
+ sources: new Set([...indexed].filter((path) => !path.endsWith('.json'))),
409
+ configImports: eslintConfigClosure(workspaceRoot, configs, indexed),
410
+ };
375
411
  }
376
412
 
377
413
  /**
@@ -389,7 +425,7 @@ function readTestTsConfig(testConfig: string): ParsedCommandLine {
389
425
  function projectLintCommands(
390
426
  projectRoot: string,
391
427
  workspaceRoot: string,
392
- eslintSources: ReadonlySet<string> | null,
428
+ eslint: EslintWorkspace | null,
393
429
  ): { commands: string[]; inputs: string[]; eslintFileSet: EslintFileSet | null } {
394
430
  const commands: string[] = [];
395
431
  const inputs: string[] = [];
@@ -399,10 +435,10 @@ function projectLintCommands(
399
435
  if (BIOME_CONFIG_FILES.some((name) => existsSync(join(workspaceRoot, name)))) {
400
436
  commands.push(`biome check --files-ignore-unknown=true ${quote(projectRoot)}`);
401
437
  }
402
- if (eslintSources !== null) {
438
+ if (eslint !== null) {
403
439
  const sourcePrefix = projectRoot === '.' ? 'src/' : `${posix.normalize(projectRoot)}/src/`;
404
440
  const sourceFiles = new Set<string>();
405
- for (const path of eslintSources) {
441
+ for (const path of eslint.sources) {
406
442
  if (
407
443
  path.startsWith(sourcePrefix) &&
408
444
  !path.slice(sourcePrefix.length).split('/').slice(0, -1).some(isNonSourceDirectory)
@@ -430,7 +466,7 @@ function projectLintCommands(
430
466
  }
431
467
  // Only a module Nx indexes is linted and keyed. An ignored one is build
432
468
  // output that a fresh checkout lacks; a JSON file is not ESLint's.
433
- if (!eslintSources.has(path) || path.split('/').some(isNonSourceDirectory)) continue;
469
+ if (!eslint.sources.has(path) || path.split('/').some(isNonSourceDirectory)) continue;
434
470
  sourceFiles.add(path);
435
471
  inputs.push(`{workspaceRoot}/${path}`);
436
472
  }
@@ -447,6 +483,12 @@ function projectLintCommands(
447
483
  type NapiArchitecture = 'arm64' | 'x64';
448
484
  type NapiTargetFamily = 'linux' | 'macos';
449
485
 
486
+ /** A host's directory under a package's `dist/bin`, as `@smoothbricks/cowshed`'s launcher names it. */
487
+ const EXECUTABLE_PLATFORM_DIRECTORY: Readonly<Record<NapiTargetFamily, Readonly<Record<NapiArchitecture, string>>>> = {
488
+ linux: { arm64: 'linux-arm64', x64: 'linux-x64' },
489
+ macos: { arm64: 'darwin-arm64', x64: 'darwin-x64' },
490
+ };
491
+
450
492
  interface NapiPlatform {
451
493
  architecture: NapiArchitecture;
452
494
  targetFamily: NapiTargetFamily;
@@ -500,7 +542,6 @@ const CARGO_WORKSPACE_PATTERN = /^\s*\[workspace\]/m;
500
542
  const CARGO_INPUTS = [
501
543
  '{projectRoot}/**/*.rs',
502
544
  '{projectRoot}/**/Cargo.toml',
503
- '{projectRoot}/**/Cargo.lock',
504
545
  '{projectRoot}/**/.cargo/config.toml',
505
546
  // Shell scripts a `.cargo/config.toml` points at — linker, runner, and rustc wrappers — decide
506
547
  // what the compiler produces as surely as the config naming them does. Tracking the config
@@ -515,14 +556,27 @@ const CARGO_INPUTS = [
515
556
  // step runs before the build), so every publish recompiled every native
516
557
  // binary on every platform for a change to a version string. What the N-API
517
558
  // build really reads is the package's `napi` block (binary name, targets) and
518
- // the `@napi-rs/cli` it runs; those are hashed as such by napiInputs().
559
+ // the `@napi-rs/cli` it runs; those are hashed as such by napiInputs(). The
560
+ // locked crates are each cached cargo target's lock-scope node (below).
519
561
  const CARGO_OUTPUT_INPUTS = CARGO_INPUTS;
562
+ /** The lockfiles of crates no resolved Cargo workspace claims, which have no lock-scope node. */
563
+ const UNRESOLVED_CARGO_LOCK_INPUT = '{projectRoot}/**/Cargo.lock';
564
+ /**
565
+ * What the uncached `cargo-fetch` reads: the manifests and the lock that name the crates, and the Cargo configuration
566
+ * that says where they come from. They key nothing; they are what a producer receipt binds the fetch to. Unnamed, Nx
567
+ * plans every file of the project, which for a repository-root project includes its symlinked managed files, and a
568
+ * receipt binds no symlink. That workspace's members belong to other projects, so its globs start at the repository root.
569
+ */
570
+ function cargoFetchInputs(projectRoot: string): string[] {
571
+ const base = projectRoot === '.' ? '{workspaceRoot}' : '{projectRoot}';
572
+ return [`${base}/**/Cargo.toml`, `${base}/**/Cargo.lock`, `${base}/**/.cargo/config.toml`, `!${base}/**/target/**`];
573
+ }
520
574
  /** A full cargo-mutants sweep's wall-clock backstop: a sweep takes hours, and a hung one must still end. */
521
575
  const MUTATION_TIMEOUT_MS = 6 * 60 * 60 * 1000;
522
576
  // The toolchain half of a cargo task's identity lives in its own module
523
- // because `smoo monorepo validate` reads the same two constants to refuse a
524
- // declaration that drops it. See cargo-toolchain-policy.ts for why it is the
525
- // declared pin and not the ambient environment.
577
+ // because `smoo monorepo validate` reads the same entries to refuse a
578
+ // declaration that drops any of them. See cargo-toolchain-policy.ts for why it
579
+ // is the declared pin and the shell's declared programs, not the ambient environment.
526
580
 
527
581
  /** A runtime input that changes when the file's bytes do: the runtime hashes the file itself. */
528
582
  function fileHashInput(path: string): { runtime: string } {
@@ -559,14 +613,14 @@ function targetCommandText(target: TargetConfiguration): string {
559
613
  ].join('\n');
560
614
  }
561
615
  /**
562
- * The N-API build's inputs beyond the Cargo sources: the toolchain pin, the
563
- * package's `napi` block, which names the binary and the targets, and the
616
+ * The N-API build's inputs beyond the Cargo sources: the toolchain identity,
617
+ * the package's `napi` block, which names the binary and the targets, and the
564
618
  * resolved version of the npm package that drives the build (the napi CLI on
565
619
  * macOS; none on Linux, where devenv's zig and cargo-zigbuild are covered by
566
- * the pin). Neither the package version nor any other lockfile entry is part
620
+ * the identity). Neither the package version nor any other lockfile entry is part
567
621
  * of the artifact.
568
622
  *
569
- * The pin is stated here rather than inherited: neither `napi build` nor the
623
+ * The identity is stated here rather than inherited: neither `napi build` nor the
570
624
  * `cargo-zigbuild` executor spells `cargo --frozen`, which is how every other
571
625
  * cached cargo target acquires its toolchain identity. Without it a `.node`
572
626
  * linked against one toolchain hashed equal to the same sources linked against
@@ -584,7 +638,7 @@ function napiInputs(
584
638
  CARGO_CLOSURE_INPUT,
585
639
  '{projectRoot}/scripts/*.sh',
586
640
  ...(repoRooted ? ['{workspaceRoot}/scripts/*.sh'] : []),
587
- ...CARGO_TOOLCHAIN_PIN_INPUTS,
641
+ ...cargoToolchainInputs(),
588
642
  runtimeInput(`bun -e 'console.log(JSON.stringify(require(${JSON.stringify(packageJson)}).napi ?? null))'`),
589
643
  { externalDependencies: [...externalDependencies] },
590
644
  ];
@@ -637,6 +691,27 @@ const CARGO_PROFILE_FLAG: Readonly<Record<CargoProfile, string>> = { dev: '', re
637
691
  /** The directory under `target/<triple>/` each profile writes. */
638
692
  const CARGO_PROFILE_OUTPUT_DIR: Readonly<Record<CargoProfile, string>> = { dev: 'debug', release: 'release' };
639
693
 
694
+ /**
695
+ * Where a build that ships writes, per profile. Two directories, never one: Nx restores a task's outputs as a tree, so
696
+ * a dev and a release build that share a path replace each other's restore and neither is a cache hit again. A release
697
+ * build writes where its package ships it (`dist/`, which publishes wholesale); a dev build writes under `.cache/`,
698
+ * which no package publishes and no loader mistakes for a release artifact.
699
+ *
700
+ * The target states each profile's directory once, as its `outputDir` option. Its declared output reads that as
701
+ * `{options.outputDir}` (Nx resolves it against the options of the run's configuration) and its command as
702
+ * `{args.outputDir}` (`nx:run-commands` fills it from the same option), so neither holds a copy that could drift.
703
+ */
704
+ const OUTPUT_DIR_OPTION = '{options.outputDir}';
705
+ const OUTPUT_DIR_ARGUMENT = '{args.outputDir}';
706
+ /** Dev builds of N-API addons (one subdirectory per platform, beside `host`) and of wasm-bindgen's modules. */
707
+ const NATIVE_DEV_DIRECTORY = '.cache/native-dev';
708
+ const WASM_DEV_DIRECTORY = '.cache/wasm-dev';
709
+
710
+ /** An addon's directory per profile: `dist/native/<name>` ships, `.cache/native-dev/<name>` is for local builds. */
711
+ function nativeOutputPaths(name: string): Readonly<Record<CargoProfile, string>> {
712
+ return { dev: `${NATIVE_DEV_DIRECTORY}/${name}`, release: `dist/native/${name}` };
713
+ }
714
+
640
715
  /**
641
716
  * Cargo's default target directory for a crate, relative to the command's cwd:
642
717
  * `target/` beside the workspace root that owns the crate, or beside the
@@ -666,7 +741,7 @@ function createCargoWasmTarget(
666
741
  repoRooted: boolean,
667
742
  cargoTargetDirectory: string,
668
743
  ): TargetConfiguration {
669
- const outputDirectory = repoRooted ? posix.join(projectRoot, config.outputDirectory) : config.outputDirectory;
744
+ const outputDirectory = repoRooted ? posix.join(projectRoot, OUTPUT_DIR_ARGUMENT) : OUTPUT_DIR_ARGUMENT;
670
745
  const cargoSelection = repoRooted ? `-p ${config.cargoPackage}` : `--manifest-path ${config.manifestPath}`;
671
746
  const buildCommand = (profile: CargoProfile): string =>
672
747
  sequence([
@@ -679,56 +754,20 @@ function createCargoWasmTarget(
679
754
  ]);
680
755
  return {
681
756
  executor: 'nx:run-commands',
757
+ metadata: CARGO_PRODUCER_METADATA,
682
758
  cache: true,
683
759
  dependsOn: ['^build'],
684
760
  inputs: repoRooted
685
761
  ? [CARGO_CLOSURE_INPUT, '{workspaceRoot}/scripts/*.sh', '{projectRoot}/scripts/*.sh']
686
762
  : CARGO_OUTPUT_INPUTS,
687
- outputs: [`{projectRoot}/${config.outputDirectory}`],
763
+ outputs: [`{projectRoot}/${OUTPUT_DIR_OPTION}/`],
688
764
  options: {
689
765
  command: buildCommand('dev'),
690
766
  cwd: repoRooted ? '.' : projectRoot,
767
+ outputDir: WASM_DEV_DIRECTORY,
691
768
  },
692
- configurations: { [RELEASE_CONFIGURATION]: { command: buildCommand('release') } },
693
- };
694
- }
695
-
696
- /**
697
- * Compilation is excluded from the bounded test window: a cold Cargo
698
- * workspace can take many minutes to compile while still making progress,
699
- * which is not a property of the tests. `cargo test --no-run` pays that cost
700
- * in its own unbounded target. Cargo reuses incremental compilation locally;
701
- * Nx cannot cache this warming action without restoring shared mutable state.
702
- *
703
- * Cargo flocks one `target/` per invocation and owns that lock: a second cargo
704
- * process on the same directory waits inside cargo ("Blocking waiting for file
705
- * lock"). Inference adds no edge to keep writers apart — an edge says one
706
- * target consumes another's output, and none of these do. These are unbounded
707
- * `nx:run-commands` targets, so a wait is not charged against a test budget.
708
- *
709
- * Clippy runs ONCE over the whole workspace, in that same `target/`, rather
710
- * than once per crate. Clippy of a crate is a check build of its whole
711
- * closure, so 49 crates meant 49 closure rebuilds and 11 GiB of target
712
- * directories on one repository, and no per-crate cache hit ever repaid that.
713
- * Sharing the build's directory costs nothing: cargo's own lock serializes
714
- * the invocations that use it, and the host units a dev build compiled are
715
- * reused instead of compiled again.
716
- *
717
- * Tests compile the dev profile only, so no test target carries a
718
- * RELEASE_CONFIGURATION: Nx forwards a run's configuration down every
719
- * `dependsOn` edge to each target that has it, and a release `build` must
720
- * warm the dev test binaries the test run will use, not release ones nobody
721
- * runs.
722
- */
723
- function createCargoTestCompileTarget(projectRoot: string): TargetConfiguration {
724
- return {
725
- executor: 'nx:run-commands',
726
- cache: false,
727
- inputs: CARGO_INPUTS,
728
- outputs: [],
729
- options: {
730
- command: cargoFrozen('test --workspace --no-run'),
731
- cwd: projectRoot,
769
+ configurations: {
770
+ [RELEASE_CONFIGURATION]: { command: buildCommand('release'), outputDir: config.outputDirectory },
732
771
  },
733
772
  };
734
773
  }
@@ -745,25 +784,47 @@ function createCargoTestCompileTarget(projectRoot: string): TargetConfiguration
745
784
  * entirely — the runners execute one extraction of it and never write cargo's
746
785
  * `target/` build tree — which is what lets the runners fan out.
747
786
  *
748
- * Cached, unlike `cargo-test-compile`, because it produces a VALUE: one file,
749
- * not a mutable build tree Nx would have to restore. `--workspace` matches the
750
- * clippy selection exactly, so both gates unify features the same way.
787
+ * It is also the step that keeps compilation out of the bounded test window: a
788
+ * cold workspace can take many minutes to compile while still making progress,
789
+ * which is not a property of the tests, and the runners start after it. It is
790
+ * test work, so no `build` depends on it (a build never consumes test binaries)
791
+ * and each target that executes them names the edge itself. There is no separate
792
+ * uncached `cargo test --no-run` warm-up: it compiled the same dev units a
793
+ * second time, queued on the same `target/` lock.
794
+ *
795
+ * Cached because it produces a VALUE: one file, not a mutable build tree Nx
796
+ * would have to restore. `--workspace` matches the clippy selection exactly, so
797
+ * both gates unify features the same way.
798
+ *
799
+ * Tests compile the dev profile only, so no test target carries a
800
+ * RELEASE_CONFIGURATION: Nx forwards a run's configuration down every
801
+ * `dependsOn` edge to each target that has it, and a release configuration
802
+ * must never turn the test binaries into release ones nobody runs.
751
803
  *
752
804
  * The directory and the archive are ONE command: nextest does not create the
753
805
  * archive's parent, so the archive step consumes what the `mkdir` produced.
806
+ * The same command writes the task's hash beside the archive, the key every
807
+ * runner's extraction is looked up by (smoo-nx-nextest-extract), and declares it
808
+ * an output, so a cache hit restores the key with the archive it names.
754
809
  */
810
+ const CARGO_TEST_ARCHIVE_KEY_FILE = `${CARGO_TEST_ARCHIVE_FILE}${NEXTEST_ARCHIVE_KEY_SUFFIX}`;
811
+
755
812
  function createCargoTestArchiveTarget(projectRoot: string, toolConfig: string): TargetConfiguration {
756
813
  return {
757
814
  executor: 'nx:run-commands',
815
+ metadata: CARGO_PRODUCER_METADATA,
758
816
  cache: true,
759
817
  inputs: CARGO_INPUTS,
760
- outputs: [`{projectRoot}/${CARGO_TEST_ARCHIVE_FILE}`],
818
+ outputs: [`{projectRoot}/${CARGO_TEST_ARCHIVE_FILE}`, `{projectRoot}/${CARGO_TEST_ARCHIVE_KEY_FILE}`],
761
819
  options: {
762
820
  command: sequence([
763
821
  `mkdir -p ${posix.dirname(CARGO_TEST_ARCHIVE_FILE)}`,
764
822
  cargoFrozen(
765
823
  `nextest archive --workspace --archive-file ${CARGO_TEST_ARCHIVE_FILE} --user-config-file none ${toolConfig}`,
766
824
  ),
825
+ // Outside Nx there is no task hash, and an archive no task names is refused here, not by every runner.
826
+ 'test -n "$NX_TASK_HASH"',
827
+ `printf '%s\\n' "$NX_TASK_HASH" > ${CARGO_TEST_ARCHIVE_KEY_FILE}`,
767
828
  ]),
768
829
  cwd: projectRoot,
769
830
  },
@@ -805,6 +866,7 @@ function createCargoCrossTestTargets(
805
866
  toolConfig: string,
806
867
  crossTarget: CargoCrossTestTarget,
807
868
  archiveInputs: NonNullable<TargetConfiguration['inputs']>,
869
+ pluginInstalled: boolean,
808
870
  ): Record<string, TargetConfiguration> {
809
871
  const { target: triple, cargo } = crossTarget;
810
872
  const archiveFile = cargoCrossTestArchiveFile(triple);
@@ -817,6 +879,7 @@ function createCargoCrossTestTargets(
817
879
  return {
818
880
  [cargoCrossTestArchiveTargetName(triple)]: {
819
881
  executor: archiveExecutor,
882
+ metadata: CARGO_PRODUCER_METADATA,
820
883
  cache: true,
821
884
  // The toolchain inputs every cached cargo target carries, plus the
822
885
  // declared driver's own bytes. Those toolchain inputs are attached
@@ -831,10 +894,14 @@ function createCargoCrossTestTargets(
831
894
  // the cross profile. For the same reason it names its npm packages here.
832
895
  inputs: [
833
896
  ...archiveInputs,
834
- ...CARGO_TOOLCHAIN_PIN_INPUTS,
897
+ ...cargoToolchainInputs(),
835
898
  ...(cargo === undefined ? [] : [`{projectRoot}/${cargo}`]),
836
899
  cargoRuntimeInput(projectRoot, 'rustc -vV && cargo -V && cargo nextest --version'),
837
- { externalDependencies: cargoCommandNpmPackages({ executor: archiveExecutor }, archiveCommand) },
900
+ {
901
+ externalDependencies: cargoCommandNpmPackages({ executor: archiveExecutor }, archiveCommand, pluginInstalled),
902
+ },
903
+ // The Cargo.lock entries the whole workspace reaches, for the same reason.
904
+ { externalDependencies: [cargoLockNodeName(projectRoot)] },
838
905
  ],
839
906
  outputs: [`{projectRoot}/${archiveFile}`],
840
907
  dependsOn: [CARGO_FETCH_TARGET],
@@ -871,9 +938,10 @@ function createCargoCrossTestTargets(
871
938
  function createCargoTestTarget(projectRoot: string): TargetConfiguration {
872
939
  return {
873
940
  executor: '@smoothbricks/nx-plugin:bounded-exec',
941
+ metadata: CARGO_PRODUCER_METADATA,
874
942
  cache: true,
875
943
  inputs: CARGO_INPUTS,
876
- dependsOn: [CARGO_TEST_COMPILE_TARGET],
944
+ dependsOn: [CARGO_TEST_ARCHIVE_TARGET],
877
945
  options: {
878
946
  command: cargoFrozen('test --workspace'),
879
947
  cwd: projectRoot,
@@ -892,14 +960,49 @@ const PLUGIN_NEXTEST_CODE_BOUND = fileURLToPath(new URL('../src/nextest-code-bou
892
960
 
893
961
  const PLUGIN_PACKAGE = '@smoothbricks/nx-plugin';
894
962
  /**
895
- * Whether this plugin runs as an installed npm package. Inside the repository
896
- * that develops it, it is a workspace project, and Nx refuses a workspace
897
- * project named as an `externalDependencies` entry.
963
+ * Whether this plugin's code was loaded from an installed npm package: a path
964
+ * through `node_modules`. Not enough alone to name it as an
965
+ * `externalDependencies` entry ({@link pluginInstalledIn}).
898
966
  */
899
- const PLUGIN_IS_INSTALLED = fileURLToPath(new URL('..', import.meta.url))
967
+ const PLUGIN_LOADED_FROM_NODE_MODULES = fileURLToPath(new URL('..', import.meta.url))
900
968
  .split(sep)
901
969
  .includes('node_modules');
902
970
 
971
+ const workspaceProjectPlugins = new Map<string, boolean>();
972
+
973
+ /**
974
+ * Whether the workspace at `workspaceRoot` runs this plugin as an installed npm package, whose lockfile node an
975
+ * `externalDependencies` entry can name. In the repository that develops it the plugin is a workspace project: the
976
+ * workspace's own `node_modules/@smoothbricks/nx-plugin` resolves to a directory of the workspace outside every
977
+ * `node_modules`, and Nx refuses a workspace project named as an `externalDependencies` entry ("could not be
978
+ * found"), whatever path this process loaded the plugin's code through. A daemon of that repository did load it
979
+ * through one with `node_modules` in it, and every cargo target it inferred afterwards named the plugin, so a gate
980
+ * refused the graph.
981
+ */
982
+ export function pluginInstalledIn(
983
+ workspaceRoot: string,
984
+ loadedFromNodeModules = PLUGIN_LOADED_FROM_NODE_MODULES,
985
+ ): boolean {
986
+ if (!loadedFromNodeModules) return false;
987
+ let workspaceProject = workspaceProjectPlugins.get(workspaceRoot);
988
+ if (workspaceProject === undefined) {
989
+ let linked: string | null = null;
990
+ try {
991
+ linked = relative(realpathSync(workspaceRoot), realpathSync(join(workspaceRoot, 'node_modules', PLUGIN_PACKAGE)));
992
+ } catch {
993
+ // No such package in the workspace: whatever runs the plugin, it is not a project of this workspace.
994
+ }
995
+ workspaceProject =
996
+ linked !== null &&
997
+ linked !== '' &&
998
+ !isAbsolute(linked) &&
999
+ linked !== '..' &&
1000
+ !linked.startsWith(`..${sep}`) &&
1001
+ !linked.split(sep).includes('node_modules');
1002
+ workspaceProjectPlugins.set(workspaceRoot, workspaceProject);
1003
+ }
1004
+ return !workspaceProject;
1005
+ }
903
1006
  /**
904
1007
  * The npm packages a cached cargo target runs, for its `externalDependencies`.
905
1008
  * Cargo runs none. A target this plugin's executor runs, or whose command reads
@@ -911,7 +1014,7 @@ const PLUGIN_IS_INSTALLED = fileURLToPath(new URL('..', import.meta.url))
911
1014
  export function cargoCommandNpmPackages(
912
1015
  target: TargetConfiguration,
913
1016
  commandText: string,
914
- installed = PLUGIN_IS_INSTALLED,
1017
+ installed: boolean,
915
1018
  ): string[] {
916
1019
  const runsPlugin =
917
1020
  target.executor?.startsWith(`${PLUGIN_PACKAGE}:`) === true ||
@@ -1000,10 +1103,20 @@ function createNodesHandler(hostPlatform: NapiPlatform | null): CreateNodesHandl
1000
1103
  const results: CreateNodesResultV2 = [];
1001
1104
  const errors: Array<[file: string | null, error: Error]> = [];
1002
1105
  let cargoWorkspaces: CargoWorkspace[];
1003
- let eslintSources: ReadonlySet<string> | null;
1106
+ let eslint: EslintWorkspace | null;
1107
+ let nativeTools: NativeTools | null;
1004
1108
  try {
1005
1109
  cargoWorkspaces = await resolveCargoWorkspaces(projectConfigurationFiles, context.workspaceRoot, hostPlatform);
1006
- eslintSources = await indexedEslintSources(context.workspaceRoot);
1110
+ eslint = await eslintWorkspace(context.workspaceRoot);
1111
+ nativeTools =
1112
+ hostPlatform === null
1113
+ ? null
1114
+ : await resolveNativeTools(
1115
+ context.workspaceRoot,
1116
+ projectConfigurationFiles,
1117
+ EXECUTABLE_PLATFORM_DIRECTORY[hostPlatform.targetFamily][hostPlatform.architecture],
1118
+ scriptcTargetName(hostPlatform),
1119
+ );
1007
1120
  } catch (error) {
1008
1121
  throw new AggregateCreateNodesError([[null, error instanceof Error ? error : new Error(String(error))]], results);
1009
1122
  }
@@ -1028,8 +1141,9 @@ function createNodesHandler(hostPlatform: NapiPlatform | null): CreateNodesHandl
1028
1141
  packageJsonPath,
1029
1142
  context.workspaceRoot,
1030
1143
  hostPlatform,
1144
+ nativeTools,
1031
1145
  cargoWorkspaces,
1032
- eslintSources,
1146
+ eslint,
1033
1147
  versionless,
1034
1148
  ),
1035
1149
  ]);
@@ -1073,8 +1187,9 @@ function isBuildOutputPackageJson(packageJsonPath: string): boolean {
1073
1187
  * Nx accepts one pre/post task-hook pair per plugin. Two independent observers share it: the controller's task-results
1074
1188
  * hint and the opt-in producer completion receipts. Each sees the same options and run context; neither reads the
1075
1189
  * other's output. The hint is recorded first so a producer-receipt bug cannot cost the controller its evidence. The
1076
- * pair also serves a run on a host without a gateway its own CPU pool, which every task inherits
1077
- * (`run-cpu-pool.ts`), and closes it when the run ends.
1190
+ * pair also serves a run that inherits no CPU pool its own, which every task inherits (`run-cpu-pool.ts`), and closes
1191
+ * it when the run ends. Last, once every task has finished, the post hook reclaims the
1192
+ * superseded Cargo unit generations of each Cargo workspace the run built into (`@smoothbricks/cargo-retain`).
1078
1193
  */
1079
1194
  export const preTasksExecution: PreTasksExecution<ProducerReceiptsOptions> = async (options, context) => {
1080
1195
  // Before any task is hashed: a workspace that declares the test-walk check
@@ -1088,16 +1203,30 @@ export const postTasksExecution: PostTasksExecution<ProducerReceiptsOptions> = a
1088
1203
  await postTaskResults(options, context);
1089
1204
  await postProducerReceipts(options, context);
1090
1205
  await closeRunCpuPool(context);
1206
+ await postCargoRetention(options, context);
1091
1207
  };
1092
1208
 
1093
- export default { createNodesV2, postTasksExecution, preTasksExecution };
1209
+ /** The lock-scope nodes' edges: each bun node's to the packages and members its manifest resolves. */
1210
+ export const createDependencies: CreateDependencies = (_options, context) => bunLockDependencies(context);
1211
+
1212
+ /** Nx invokes this only after merging inferred/declarative targets and every plugin's project dependencies. */
1213
+ export const createMetadata: CreateMetadata = (graph, _options, context) => {
1214
+ refuseOverlappingOutputs(graph, context.workspaceRoot);
1215
+ refuseBuildTestDependencies(graph, context.workspaceRoot);
1216
+ return {};
1217
+ };
1218
+
1219
+ export default { createNodesV2, createDependencies, createMetadata, postTasksExecution, preTasksExecution };
1094
1220
 
1095
1221
  interface PackageJson {
1096
1222
  bin?: unknown;
1223
+ devDependencies?: Record<string, unknown>;
1097
1224
  name?: string;
1098
1225
  napi?: Record<string, unknown>;
1099
1226
  /** npm's own "never published" flag, which is what makes a package a deployable target rather than a library. */
1100
1227
  private?: boolean;
1228
+ /** Native entry overrides (`entries`) and the C the executables call (`ffi`). */
1229
+ scriptc?: unknown;
1101
1230
  scripts?: Record<string, unknown>;
1102
1231
  nx?: {
1103
1232
  name?: string;
@@ -1106,26 +1235,237 @@ interface PackageJson {
1106
1235
  }
1107
1236
 
1108
1237
  function packageBinOutputs(packageJson: PackageJson, packageJsonPath: string): string[] {
1238
+ return [...new Set(packageBinEntries(packageJson, packageJsonPath).values())];
1239
+ }
1240
+
1241
+ /** `package.json#bin` as npm links it: each command's name and executable path; a lone path is the unscoped package's. */
1242
+ function packageBinEntries(packageJson: PackageJson, packageJsonPath: string): Map<string, string> {
1109
1243
  if (packageJson.bin === undefined) {
1110
- return [];
1244
+ return new Map();
1111
1245
  }
1112
1246
  if (typeof packageJson.bin === 'string') {
1113
1247
  if (packageJson.bin.length === 0) {
1114
1248
  throw new Error(`${packageJsonPath}: bin must not be empty`);
1115
1249
  }
1116
- return [packageJson.bin];
1250
+ return new Map([[(packageJson.name ?? '').replace(/^@[^/]*\//, ''), packageJson.bin]]);
1117
1251
  }
1118
1252
  if (!isRecord(packageJson.bin)) {
1119
1253
  throw new Error(`${packageJsonPath}: bin must be a string or an object of executable paths`);
1120
1254
  }
1121
- const outputs = new Set<string>();
1255
+ const entries = new Map<string, string>();
1122
1256
  for (const [name, output] of Object.entries(packageJson.bin)) {
1123
1257
  if (typeof output !== 'string' || output.length === 0) {
1124
1258
  throw new Error(`${packageJsonPath}: bin.${name} must be a non-empty executable path`);
1125
1259
  }
1126
- outputs.add(output);
1260
+ entries.set(name, output);
1261
+ }
1262
+ return entries;
1263
+ }
1264
+
1265
+ /** Resolve declared bins and optional package-root-relative native overrides to emit-root-relative modules. */
1266
+ export function scriptcBinModules(
1267
+ bins: ReadonlyMap<string, string>,
1268
+ scriptc: unknown,
1269
+ packageJsonPath: string,
1270
+ javascriptRoot: string,
1271
+ ): Record<string, string> {
1272
+ const modulePath = (name: string, entry: string, field: string): string => {
1273
+ const emitted = posix.normalize(entry);
1274
+ if (!/^[\w.-]+$/.test(name) || !emitted.startsWith(`${javascriptRoot}/`) || !emitted.endsWith('.js')) {
1275
+ throw new Error(
1276
+ `${packageJsonPath}: ${field} must name JavaScript tsc-js emits under ${javascriptRoot}/ (it is ${entry})`,
1277
+ );
1278
+ }
1279
+ return emitted.slice(javascriptRoot.length + 1);
1280
+ };
1281
+ const modules: Record<string, string> = Object.fromEntries(bins);
1282
+ for (const [name, entry] of bins) {
1283
+ modules[name] = modulePath(name, entry, `bin.${name}`);
1284
+ }
1285
+ if (scriptc === undefined) return modules;
1286
+ if (!isRecord(scriptc) || Array.isArray(scriptc)) {
1287
+ throw new Error(`${packageJsonPath}: scriptc must be an object`);
1288
+ }
1289
+ const overrides = scriptc.entries;
1290
+ if (overrides === undefined) return modules;
1291
+ if (!isRecord(overrides) || Array.isArray(overrides)) {
1292
+ throw new Error(`${packageJsonPath}: scriptc.entries must be an object mapping declared bin names to module paths`);
1293
+ }
1294
+ for (const [name, entry] of Object.entries(overrides)) {
1295
+ if (!bins.has(name)) {
1296
+ throw new Error(
1297
+ `${packageJsonPath}: scriptc.entries.${name} is not declared in bin; entries cannot add executables`,
1298
+ );
1299
+ }
1300
+ if (typeof entry !== 'string' || entry.length === 0) {
1301
+ throw new Error(`${packageJsonPath}: scriptc.entries.${name} must be a non-empty module path`);
1302
+ }
1303
+ modules[name] = modulePath(name, entry, `scriptc.entries.${name}`);
1304
+ }
1305
+ return modules;
1306
+ }
1307
+
1308
+ /**
1309
+ * Every platform a scriptc package ships an executable for, with the triple `SCRIPTC_TARGET` names for it and the
1310
+ * runtime pack scriptc links that triple against. Linux executables are static musl, as cowshed's CLI is, so one file
1311
+ * runs on every distribution.
1312
+ */
1313
+ const SCRIPTC_PLATFORMS: readonly (NapiPlatform & { readonly triple: string; readonly runtimePack: string })[] = [
1314
+ {
1315
+ architecture: 'arm64',
1316
+ targetFamily: 'macos',
1317
+ triple: 'aarch64-macos',
1318
+ runtimePack: '@scriptc/runtime-darwin-arm64',
1319
+ },
1320
+ { architecture: 'x64', targetFamily: 'macos', triple: 'x86_64-macos', runtimePack: '@scriptc/runtime-darwin-x64' },
1321
+ {
1322
+ architecture: 'arm64',
1323
+ targetFamily: 'linux',
1324
+ triple: 'aarch64-linux-musl',
1325
+ runtimePack: '@scriptc/runtime-linux-arm64-musl',
1326
+ },
1327
+ {
1328
+ architecture: 'x64',
1329
+ targetFamily: 'linux',
1330
+ triple: 'x86_64-linux-musl',
1331
+ runtimePack: '@scriptc/runtime-linux-x64-musl',
1332
+ },
1333
+ ];
1334
+
1335
+ /**
1336
+ * `package.json#scriptc.ffi`: the C a package's executables call through scriptc's FFI, which every platform run stages
1337
+ * beside the emitted JavaScript and builds for its triple. Absent for a package that calls no C.
1338
+ */
1339
+ function scriptcFfi(packageJson: PackageJson, packageJsonPath: string): ScriptcNativeFfi | undefined {
1340
+ if (packageJson.scriptc === undefined || (isRecord(packageJson.scriptc) && packageJson.scriptc.ffi === undefined)) {
1341
+ return undefined;
1342
+ }
1343
+ const refusal = (what: string): Error =>
1344
+ new Error(
1345
+ `${packageJsonPath}: scriptc.ffi ${what}; it is { "manifest": "<ffi.json>", "declarations": ` +
1346
+ '{ "<source .d.ts>": "<path beside the emitted JavaScript>" }, "sources": ["<C file>"] }',
1347
+ );
1348
+ const ffi = isRecord(packageJson.scriptc) ? packageJson.scriptc.ffi : undefined;
1349
+ if (!isRecord(ffi)) {
1350
+ throw refusal('must be an object');
1351
+ }
1352
+ const { manifest, declarations, sources } = ffi;
1353
+ if (typeof manifest !== 'string' || manifest.length === 0) {
1354
+ throw refusal('needs a manifest path');
1355
+ }
1356
+ if (!isRecord(declarations)) {
1357
+ throw refusal('needs declarations mapping each source file to its staged path');
1358
+ }
1359
+ const staged: Record<string, string> = {};
1360
+ for (const [source, destination] of Object.entries(declarations)) {
1361
+ if (typeof destination !== 'string') {
1362
+ throw refusal(`needs declarations mapping each source file to its staged path (${source} is not)`);
1363
+ }
1364
+ staged[source] = destination;
1127
1365
  }
1128
- return [...outputs];
1366
+ if (!Array.isArray(sources)) {
1367
+ throw refusal('needs sources, a list of C files');
1368
+ }
1369
+ const files: string[] = [];
1370
+ for (const source of sources) {
1371
+ if (typeof source !== 'string') {
1372
+ throw refusal('needs sources, a list of C files');
1373
+ }
1374
+ files.push(source);
1375
+ }
1376
+ const declared = { manifest, declarations: staged, sources: files };
1377
+ const problem = ffiPathProblem(declared);
1378
+ if (problem !== undefined) {
1379
+ throw refusal(problem);
1380
+ }
1381
+ return declared;
1382
+ }
1383
+
1384
+ /** The files a target's FFI is built from: change one and every platform's executable is stale. */
1385
+ function scriptcFfiInputs(ffi: ScriptcNativeFfi | undefined): string[] {
1386
+ return ffi === undefined
1387
+ ? []
1388
+ : [ffi.manifest, ...Object.keys(ffi.declarations), ...ffi.sources].map((path) => `{projectRoot}/${path}`);
1389
+ }
1390
+
1391
+ /** The scriptc target writing `platform`'s executables; its suffix is the platform family the publish legs select. */
1392
+ function scriptcTargetName(platform: NapiPlatform): string {
1393
+ return `scriptc-${platform.architecture}-${platform.targetFamily}`;
1394
+ }
1395
+
1396
+ /**
1397
+ * `scriptc-<arch>-<family>`, one per platform in SCRIPTC_PLATFORMS: each `package.json#bin` entry compiled by scriptc
1398
+ * to the executable `dist/bin/<platform>/<name>`, from the transformed JavaScript the run itself emits from
1399
+ * `tsconfig.lib.json` into private staging, never from `tsc-js`'s output: a platform target's closure stays in its
1400
+ * family (package-target-policy.ts) and the four are collected on different hosts, so none depends on a sibling or
1401
+ * shares an output with another. A package opts in by depending on `scriptc`, which also pins the compiler the targets
1402
+ * run, and lists each platform's runtime pack at that same version. Every host builds every platform the same way,
1403
+ * `SCRIPTC_TARGET=<triple>` with zig as the C compiler, so a target's output does not depend on the host that built
1404
+ * it, and like every platform target the host's own joins `build` while the publish legs build the rest. The bins
1405
+ * name JavaScript below `dist/` beside `bin/` (`dist/ts`), so `tsc-js`'s output and the executables are disjoint.
1406
+ */
1407
+ function scriptcPlatformTargets(
1408
+ packageJson: PackageJson,
1409
+ packageJsonPath: string,
1410
+ projectRoot: string,
1411
+ libTsconfigPath: string,
1412
+ toolchainInputs: NonNullable<TargetConfiguration['inputs']>,
1413
+ ): Record<string, TargetConfiguration> {
1414
+ const compiler = packageJson.devDependencies?.scriptc;
1415
+ if (compiler === undefined) {
1416
+ return {};
1417
+ }
1418
+ const missingPacks = SCRIPTC_PLATFORMS.filter(
1419
+ (platform) => packageJson.devDependencies?.[platform.runtimePack] !== compiler,
1420
+ ).map((platform) => `${platform.runtimePack}@${String(compiler)}`);
1421
+ if (missingPacks.length > 0) {
1422
+ throw new Error(
1423
+ `${packageJsonPath}: a scriptc package builds every platform's executable, each linked against its runtime pack at ` +
1424
+ `the compiler's version; list ${missingPacks.join(', ')} in devDependencies beside scriptc`,
1425
+ );
1426
+ }
1427
+ const javascriptRoot = typescriptOutDir(libTsconfigPath, packageJsonPath);
1428
+ const [outputRoot, below] = javascriptRoot?.split('/') ?? [];
1429
+ if (javascriptRoot === null || outputRoot !== 'dist' || below === undefined || below === 'bin') {
1430
+ throw new Error(
1431
+ `${packageJsonPath}: a scriptc package emits its JavaScript below dist/ beside dist/bin; ` +
1432
+ `set tsconfig.lib.json compilerOptions.outDir to "dist/ts" (it is ${JSON.stringify(javascriptRoot)})`,
1433
+ );
1434
+ }
1435
+ const entries = packageBinEntries(packageJson, packageJsonPath);
1436
+ if (entries.size === 0) {
1437
+ throw new Error(`${packageJsonPath}: a scriptc package names the executables it compiles in bin`);
1438
+ }
1439
+ const modules = scriptcBinModules(entries, packageJson.scriptc, packageJsonPath, javascriptRoot);
1440
+ const ffi = scriptcFfi(packageJson, packageJsonPath);
1441
+ const targets: Record<string, TargetConfiguration> = {};
1442
+ for (const platform of SCRIPTC_PLATFORMS) {
1443
+ const outputDirectory = `dist/bin/${EXECUTABLE_PLATFORM_DIRECTORY[platform.targetFamily][platform.architecture]}`;
1444
+ targets[scriptcTargetName(platform)] = {
1445
+ executor: '@smoothbricks/nx-plugin:scriptc-native',
1446
+ cache: true,
1447
+ inputs: [
1448
+ 'production',
1449
+ '^production',
1450
+ ...toolchainInputs,
1451
+ '{projectRoot}/tsconfig.lib.json',
1452
+ { externalDependencies: ['scriptc', platform.runtimePack] },
1453
+ ...scriptcFfiInputs(ffi),
1454
+ ],
1455
+ outputs: [...entries.keys()].map((name) => `{projectRoot}/${outputDirectory}/${name}`),
1456
+ // The emit type-checks against its dependencies' emitted JavaScript, as tsc-js does.
1457
+ dependsOn: ['^*-js'],
1458
+ options: {
1459
+ cwd: projectRoot,
1460
+ tsConfig: 'tsconfig.lib.json',
1461
+ triple: platform.triple,
1462
+ outputDirectory,
1463
+ entries: modules,
1464
+ ...(ffi === undefined ? {} : { ffi }),
1465
+ },
1466
+ };
1467
+ }
1468
+ return targets;
1129
1469
  }
1130
1470
 
1131
1471
  /**
@@ -1173,8 +1513,9 @@ async function createProjectTargets(
1173
1513
  packageJsonPath: string,
1174
1514
  workspaceRoot: string,
1175
1515
  hostPlatform: NapiPlatform | null,
1516
+ nativeTools: NativeTools | null,
1176
1517
  cargoWorkspaces: readonly CargoWorkspace[],
1177
- eslintSources: ReadonlySet<string> | null,
1518
+ eslint: EslintWorkspace | null,
1178
1519
  versionless: VersionlessManifestPolicy | null,
1179
1520
  ) {
1180
1521
  const projectRoot = dirname(packageJsonPath);
@@ -1209,7 +1550,10 @@ async function createProjectTargets(
1209
1550
  const hasCrateManifests = isCargoProject || existsSync(cargoTomlPath);
1210
1551
  const crateInputs =
1211
1552
  versionless !== null && hasCrateManifests ? await versionlessCrateInputs(projectRoot, workspaceRoot) : [];
1212
- const versionlessProjectInputs = versionless === null ? [] : [...VERSIONLESS_PACKAGE_INPUTS, ...crateInputs];
1553
+ const versionlessProjectInputs =
1554
+ versionless === null
1555
+ ? []
1556
+ : [...VERSIONLESS_PACKAGE_INPUTS, ...crateInputs, ...(projectRoot === '.' ? ROOT_LOCKFILE_EXCLUSIONS : [])];
1213
1557
  // The options a TypeScript task's answer really depends on, which is the
1214
1558
  // whole `extends` chain of the configs its commands name and not just those
1215
1559
  // two files. Resolved once per project: every target below shares it.
@@ -1217,11 +1561,21 @@ async function createProjectTargets(
1217
1561
  [...(hasLibTsconfig ? [libTsconfigPath] : []), ...(hasTestTsconfig ? [testTsconfigPath] : [])],
1218
1562
  workspaceRoot,
1219
1563
  );
1220
- const toolchainInputs = [...RELEASE_REWRITTEN_WORKSPACE_INPUTS, ...TYPESCRIPT_PATCH_INPUTS, ...typescriptConfigChain];
1564
+ const toolchainInputs = [
1565
+ ...RELEASE_REWRITTEN_WORKSPACE_INPUTS,
1566
+ bunLockInput(projectRoot),
1567
+ ...TYPESCRIPT_PATCH_INPUTS,
1568
+ ...typescriptConfigChain,
1569
+ ];
1221
1570
  const checkInputs =
1222
1571
  versionless === null
1223
1572
  ? toolchainInputs
1224
- : [...TYPESCRIPT_PATCH_INPUTS, ...typescriptConfigChain, ...VERSIONLESS_TOOLCHAIN_MANIFEST_INPUTS];
1573
+ : [
1574
+ ...TYPESCRIPT_PATCH_INPUTS,
1575
+ ...typescriptConfigChain,
1576
+ ...VERSIONLESS_TOOLCHAIN_MANIFEST_INPUTS,
1577
+ bunLockInput(projectRoot),
1578
+ ];
1225
1579
  const selfProduction = versionless === null ? 'production' : VERSIONLESS_PRODUCTION_INPUT;
1226
1580
  const selfDefault = versionless === null ? 'default' : VERSIONLESS_DEFAULT_INPUT;
1227
1581
  const dependencyProduction =
@@ -1286,6 +1640,10 @@ async function createProjectTargets(
1286
1640
  cwd: projectRoot,
1287
1641
  },
1288
1642
  };
1643
+ Object.assign(
1644
+ targets,
1645
+ scriptcPlatformTargets(packageJson, packageJsonPath, projectRoot, libTsconfigPath, toolchainInputs),
1646
+ );
1289
1647
  }
1290
1648
 
1291
1649
  if (hasTestTsconfig) {
@@ -1340,7 +1698,10 @@ async function createProjectTargets(
1340
1698
  }
1341
1699
 
1342
1700
  if (napiConfig) {
1343
- Object.assign(targets, createNapiTargets(projectRoot, napiConfig, hostPlatform, isRepoRootedCargoProject));
1701
+ Object.assign(
1702
+ targets,
1703
+ createNapiTargets(projectRoot, napiConfig, hostPlatform, nativeTools, isRepoRootedCargoProject),
1704
+ );
1344
1705
  if (
1345
1706
  !('napi-test' in (packageJson.nx?.targets ?? {})) &&
1346
1707
  existsSync(join(absoluteProjectRoot, 'src/native.test.ts'))
@@ -1387,7 +1748,7 @@ async function createProjectTargets(
1387
1748
  // `dependsOn` REPLACES rather than unions. These lists state what each target
1388
1749
  // consumes — the fetched registry, the archive, the debug addon — and a
1389
1750
  // package that must re-route one (build its artifact ahead of the test run,
1390
- // or drop `cargo-test-compile` because it compiles differently) can only say
1751
+ // or drop `cargo-test-archive` because it compiles differently) can only say
1391
1752
  // so by replacing the list; a union would make every inferred edge
1392
1753
  // unremovable and a corrected order unrepresentable.
1393
1754
  // Additive intent already has a spelling (`"..."` above), so a plugin-local
@@ -1402,7 +1763,6 @@ async function createProjectTargets(
1402
1763
  const ownsCargoWorkspaceTargets = isCargoWorkspaceRoot;
1403
1764
  if (ownsCargoWorkspaceTargets && cargoWorkspace) {
1404
1765
  const cargoWorkspaceRoot = cargoWorkspace.projectRoot;
1405
- targets[CARGO_TEST_COMPILE_TARGET] = createCargoTestCompileTarget(cargoWorkspaceRoot);
1406
1766
  const workspaceInputs = [
1407
1767
  ...new Set(
1408
1768
  (
@@ -1413,6 +1773,7 @@ async function createProjectTargets(
1413
1773
  absoluteProjectRoot: join(workspaceRoot, cargoWorkspaceRoot),
1414
1774
  memberDir: plan.package.dir,
1415
1775
  cache: cargoWorkspace.inputsCache,
1776
+ cargo: cargoWorkspace.closureSource.cargo,
1416
1777
  }),
1417
1778
  ),
1418
1779
  )
@@ -1431,7 +1792,6 @@ async function createProjectTargets(
1431
1792
  ...(workspaceInputs.length > 0 ? workspaceInputs : CARGO_INPUTS),
1432
1793
  { dependentTasksOutputFiles: '**/*', transitive: false },
1433
1794
  ];
1434
- targets[CARGO_TEST_COMPILE_TARGET].inputs = workspaceCargoInputs;
1435
1795
  targets[CARGO_TEST_ARCHIVE_TARGET] = createCargoTestArchiveTarget(
1436
1796
  cargoWorkspaceRoot,
1437
1797
  nextestToolConfigArg(cargoWorkspaceRoot),
@@ -1446,10 +1806,13 @@ async function createProjectTargets(
1446
1806
  for (const crossTarget of listCargoCrossTestTargets(join(workspaceRoot, cargoWorkspaceRoot))) {
1447
1807
  Object.assign(
1448
1808
  targets,
1449
- createCargoCrossTestTargets(cargoWorkspaceRoot, nextestToolConfigArg(cargoWorkspaceRoot), crossTarget, [
1450
- ...workspaceCargoInputs,
1451
- `{projectRoot}/${NEXTEST_REPO_CONFIG_PATH}`,
1452
- ]),
1809
+ createCargoCrossTestTargets(
1810
+ cargoWorkspaceRoot,
1811
+ nextestToolConfigArg(cargoWorkspaceRoot),
1812
+ crossTarget,
1813
+ [...workspaceCargoInputs, `{projectRoot}/${NEXTEST_REPO_CONFIG_PATH}`],
1814
+ pluginInstalledIn(workspaceRoot),
1815
+ ),
1453
1816
  );
1454
1817
  }
1455
1818
  // A serial group's filter can span members, so no single crate owns it. The root
@@ -1460,6 +1823,7 @@ async function createProjectTargets(
1460
1823
  for (const group of cargoWorkspace.serialGroups) {
1461
1824
  targets[cargoTestGroupTargetName(group.group)] = cargoTestGroupTarget(
1462
1825
  cargoWorkspace,
1826
+ nativeTools,
1463
1827
  await cargoTestRunnerInputs(workspaceRoot, cargoWorkspace, serialGroupMemberDirs(cargoWorkspace, group)),
1464
1828
  group,
1465
1829
  );
@@ -1478,15 +1842,18 @@ async function createProjectTargets(
1478
1842
  aggregateDependencies.length > 0
1479
1843
  ? { executor: 'nx:noop', cache: true, outputs: [], dependsOn: aggregateDependencies }
1480
1844
  : createCargoTestTarget(cargoWorkspaceRoot);
1481
- // One clippy over the whole workspace, in the build's target dir. Clippy
1482
- // of a crate is a check build of its closure; a target dir per crate
1483
- // compiled every shared dependency once per crate (49 closures, 11 GiB on
1484
- // one repository) and no per-crate cache hit ever repaid that. The
1485
- // workspace inputs are exactly the union of every crate's, so the verdict
1486
- // caches on the same key set the compile does. Non-root packages depend on
1487
- // this target.
1845
+ // One clippy over the whole workspace. Clippy of a crate is a check build
1846
+ // of its closure; a target dir per crate compiled every shared dependency
1847
+ // once per crate (49 closures, 11 GiB on one repository) and no per-crate
1848
+ // cache hit ever repaid that. The workspace inputs are exactly the union of
1849
+ // every crate's, so the verdict caches on the same key set the archive
1850
+ // does. Non-root packages depend on this target. Its target dir is its own
1851
+ // (CARGO_LINT_CLIPPY_COMMAND, ./cross-check-policy.ts): Cargo flocks one
1852
+ // directory per invocation, and a workspace clippy holding the dev build's
1853
+ // `target/` queued the archive and every dev build behind it.
1488
1854
  targets['cargo-lint'] = {
1489
1855
  executor: 'nx:run-commands',
1856
+ metadata: CARGO_PRODUCER_METADATA,
1490
1857
  cache: true,
1491
1858
  inputs: workspaceCargoInputs,
1492
1859
  outputs: [],
@@ -1525,6 +1892,7 @@ async function createProjectTargets(
1525
1892
  // macOS host demand the zig toolchain that the devenv profile keeps opt-in.
1526
1893
  targets[CARGO_CROSS_LINT_TARGET] = {
1527
1894
  executor: 'nx:run-commands',
1895
+ metadata: CARGO_PRODUCER_METADATA,
1528
1896
  cache: true,
1529
1897
  inputs: workspaceCargoInputs,
1530
1898
  outputs: [],
@@ -1540,23 +1908,29 @@ async function createProjectTargets(
1540
1908
  // progress, so its bound is a wall-clock backstop, not a performance budget.
1541
1909
  targets.mutation = {
1542
1910
  executor: '@smoothbricks/nx-plugin:bounded-exec',
1911
+ metadata: CARGO_PRODUCER_METADATA,
1543
1912
  cache: false,
1544
1913
  options: { command: cargoFrozen('mutants --workspace'), cwd: cargoWorkspaceRoot, timeoutMs: MUTATION_TIMEOUT_MS },
1545
1914
  };
1546
1915
  targets.bench = {
1547
1916
  executor: 'nx:run-commands',
1917
+ metadata: CARGO_PRODUCER_METADATA,
1548
1918
  cache: false,
1549
1919
  options: { command: cargoFrozen('bench --workspace'), cwd: cargoWorkspaceRoot },
1550
1920
  };
1551
- // Target-dir GC. Cargo never removes superseded artifacts, so a busy
1552
- // workspace grows tens of GB of stale variants no fingerprint references;
1553
- // sweeping by age prunes exactly that junk while the warm current
1554
- // surface — the gated asset — survives untouched. Never cached: the
1555
- // verdict is about this machine's disk, not the commit.
1556
- targets['cargo-sweep'] = {
1921
+ // A read-only preview of the retention pass the plugin's postTasksExecution
1922
+ // schedules after runs that built (@smoothbricks/cargo-retain): the superseded unit
1923
+ // generations it would reclaim and why everything else stays. Never cached:
1924
+ // the verdict is about this machine's disk, not the commit.
1925
+ const retainTool = nativeToolDependsOn(nativeTools, 'cargo-retain');
1926
+ targets['cargo-retention'] = {
1557
1927
  executor: 'nx:run-commands',
1558
1928
  cache: false,
1559
- options: { command: 'cargo sweep --time 7', cwd: cargoWorkspaceRoot },
1929
+ ...(retainTool.length > 0 ? { dependsOn: retainTool } : {}),
1930
+ options: {
1931
+ command: nativeToolCommand(nativeTools, cargoWorkspaceRoot, 'cargo-retain', 'smoo-nx-cargo-retain'),
1932
+ cwd: cargoWorkspaceRoot,
1933
+ },
1560
1934
  };
1561
1935
  }
1562
1936
 
@@ -1567,6 +1941,7 @@ async function createProjectTargets(
1567
1941
  projectRoot,
1568
1942
  workspaceRoot,
1569
1943
  cargoWorkspace,
1944
+ nativeTools,
1570
1945
  );
1571
1946
  // Serial-group runners belong to the workspace root, outside inferred ordinary tests. Explicit repository
1572
1947
  // aggregates can reach them; their own inputs decide whether each runner executes or replays from cache.
@@ -1616,7 +1991,7 @@ async function createProjectTargets(
1616
1991
  };
1617
1992
  }
1618
1993
  for (const name of Object.keys(declaredTargets)) {
1619
- if (name === 'test' || !isTestRunnerTargetName(name) || targets[name] !== undefined) continue;
1994
+ if (name === 'test' || !isTestNamespaceTargetName(name) || targets[name] !== undefined) continue;
1620
1995
  targets[name] = { dependsOn: ['^build', 'build'] };
1621
1996
  }
1622
1997
 
@@ -1654,6 +2029,7 @@ async function createProjectTargets(
1654
2029
  // would skip work a cold registry still needs. Nothing here is a
1655
2030
  // workspace output, so there is nothing for Nx to restore in its place.
1656
2031
  cache: false,
2032
+ inputs: cargoFetchInputs(projectRoot),
1657
2033
  options: {
1658
2034
  // One fetch per manifest, independent of the others: Cargo's own
1659
2035
  // package-cache lock arbitrates the CARGO_HOME they share.
@@ -1692,7 +2068,8 @@ async function createProjectTargets(
1692
2068
  // Cache verdicts and dedicated artifacts, never Cargo's shared mutable build
1693
2069
  // directories. Resolve tool versions from the command's actual directory.
1694
2070
  // Name the npm packages the command runs (cargoCommandNpmPackages) unless
1695
- // the target already does.
2071
+ // the target already does, and the Cargo.lock entries its crates reach (the
2072
+ // lock-scope node of the directory it runs in) unless its inputs already do.
1696
2073
  for (const [name, target] of Object.entries(targets)) {
1697
2074
  const text = targetCommandText(target);
1698
2075
  if (!runsFrozenCargo(text)) continue;
@@ -1705,25 +2082,27 @@ async function createProjectTargets(
1705
2082
  ? ' && cargo nextest --version'
1706
2083
  : '';
1707
2084
  const inputs = target.inputs ?? CARGO_INPUTS;
1708
- const namesPackages = inputs.some((input) => typeof input === 'object' && 'externalDependencies' in input);
2085
+ const namesPackages = inputs.some(
2086
+ (input) => typeof input === 'object' && 'externalDependencies' in input && !isCargoLockInput(input),
2087
+ );
2088
+ const namesLock = inputs.some((input) => input === CARGO_CLOSURE_INPUT || isCargoLockInput(input));
2089
+ const lockDirectory = typeof cwd === 'string' ? cwd : projectRoot;
1709
2090
  target.inputs = [
1710
2091
  ...inputs,
1711
- ...CARGO_TOOLCHAIN_PIN_INPUTS,
2092
+ ...cargoToolchainInputs(),
1712
2093
  cargoRuntimeInput(typeof cwd === 'string' ? cwd : projectRoot, `rustc -vV && cargo -V${versions}`),
1713
- ...(namesPackages ? [] : [{ externalDependencies: cargoCommandNpmPackages(target, text) }]),
2094
+ ...(namesPackages
2095
+ ? []
2096
+ : [{ externalDependencies: cargoCommandNpmPackages(target, text, pluginInstalledIn(workspaceRoot)) }]),
2097
+ ...(namesLock
2098
+ ? []
2099
+ : cargoSourcesUnder(lockDirectory, cargoWorkspaces).length > 0
2100
+ ? [{ externalDependencies: [cargoLockNodeName(lockDirectory)] }]
2101
+ : // No project-rooted Cargo workspace claims these crates, so the plugin holds no resolve to scope.
2102
+ [UNRESOLVED_CARGO_LOCK_INPUT]),
1714
2103
  ];
1715
2104
  }
1716
2105
 
1717
- // `build` warms the test executables' compile; in a nested package that names
1718
- // the root workspace's one compile.
1719
- const cargoTestCompileDependency: CargoTargetDependency | null = targets[CARGO_TEST_COMPILE_TARGET]
1720
- ? CARGO_TEST_COMPILE_TARGET
1721
- : isCargoProject && cargoWorkspace
1722
- ? cargoTargetDependency(projectName, {
1723
- projectName: cargoWorkspace.rootProjectName,
1724
- targetName: CARGO_TEST_COMPILE_TARGET,
1725
- })
1726
- : null;
1727
2106
  const napiDebug = targets['napi-debug'];
1728
2107
  if (napiDebug && cargoWorkspace) {
1729
2108
  // A crate whose project also builds the debug cdylib runs its tests after
@@ -1743,15 +2122,6 @@ async function createProjectTargets(
1743
2122
  }
1744
2123
  }
1745
2124
  } else if (napiDebug) {
1746
- for (const [name, target] of Object.entries(targets)) {
1747
- if (!name.startsWith('cargo-test-') || name === CARGO_TEST_COMPILE_TARGET) {
1748
- continue;
1749
- }
1750
- const dependsOn = target.dependsOn ?? [];
1751
- if (dependsOn.includes(CARGO_TEST_COMPILE_TARGET) && !dependsOn.includes('napi-debug')) {
1752
- target.dependsOn = [...dependsOn, 'napi-debug'];
1753
- }
1754
- }
1755
2125
  const cargoTest = targets[CARGO_TEST_TARGET];
1756
2126
  if (
1757
2127
  cargoTest?.options &&
@@ -1772,6 +2142,32 @@ async function createProjectTargets(
1772
2142
  hostPlatform,
1773
2143
  );
1774
2144
 
2145
+ // `<tool>-native` is the host's own build of one tool, so a test that runs it names one edge: `cli-native` is the
2146
+ // declared `cli-<arch>-<family>` build for this machine, `napi-native` the addon (this host's platform target, or
2147
+ // cargo-napi where no configured triple is this machine's), and scriptc-native its host executable producer.
2148
+ // Each is picked from hostPlatformBinaries by the same
2149
+ // suffix rule, its family name `-native` joins it to `build`, and it states no outputs. It runs nothing, so it
2150
+ // states `cache: false`; a cached aggregate would need inputs of its own. A host with no such producer gets no
2151
+ // aggregate, and inference makes no test depend on one.
2152
+ const hostBuilds: Record<string, string[]> = {
2153
+ 'scriptc-native': hostPlatformBinaries.filter((name) => name.startsWith('scriptc-')),
2154
+ 'cli-native': hostPlatformBinaries.filter((name) => name.startsWith('cli-')),
2155
+ 'napi-native': targets['cargo-napi']
2156
+ ? ['cargo-napi']
2157
+ : hostPlatformBinaries.filter((name) => name.startsWith('napi-')),
2158
+ };
2159
+ for (const [name, dependsOn] of Object.entries(hostBuilds)) {
2160
+ if (dependsOn.length > 0) {
2161
+ targets[name] = {
2162
+ executor: 'nx:noop',
2163
+ cache: false,
2164
+ outputs: [],
2165
+ dependsOn,
2166
+ configurations: { production: {} },
2167
+ };
2168
+ }
2169
+ }
2170
+
1775
2171
  // A deploy is never cached; the build half beside it always is.
1776
2172
  //
1777
2173
  // Nx's cache answers "did this exact input set already produce an output". A deploy's real
@@ -1856,9 +2252,6 @@ async function createProjectTargets(
1856
2252
  dependsOn: [
1857
2253
  ...new Set([
1858
2254
  '^build',
1859
- // Compiling the test executables is unbounded preparation. Cargo
1860
- // reuses its incremental state; Nx never restores that shared state.
1861
- ...(cargoTestCompileDependency ? [cargoTestCompileDependency] : []),
1862
2255
  ...buildOutputTargetNames([...Object.keys(declaredTargets), ...Object.keys(targets)]),
1863
2256
  ...hostPlatformBinaries,
1864
2257
  ]),
@@ -1938,10 +2331,12 @@ async function createProjectTargets(
1938
2331
  commands: lintCommands,
1939
2332
  inputs: lintProgramInputs,
1940
2333
  eslintFileSet,
1941
- } = projectLintCommands(projectRoot, workspaceRoot, eslintSources);
2334
+ } = projectLintCommands(projectRoot, workspaceRoot, eslint);
2335
+ // Every lint tool reaches its own verdict in one run: run-commands would end the
2336
+ // other tools once one fails, and their findings would surface a run later.
1942
2337
  if (validationTargets.length > 0 || lintCommands.length > 0) {
1943
2338
  targets.lint = {
1944
- executor: lintCommands.length > 0 ? 'nx:run-commands' : 'nx:noop',
2339
+ executor: lintCommands.length > 0 ? ALL_VERDICTS_EXECUTOR : 'nx:noop',
1945
2340
  ...(eslintFileSet === null ? {} : { metadata: { eslintFileSet } }),
1946
2341
  cache: true,
1947
2342
  dependsOn: validationTargets,
@@ -1955,7 +2350,7 @@ async function createProjectTargets(
1955
2350
  `{workspaceRoot}/${name}`,
1956
2351
  `{projectRoot}/${name}`,
1957
2352
  ]),
1958
- '{workspaceRoot}/tooling/checks/**/*',
2353
+ ...(eslint?.configImports ?? []).map((path) => `{workspaceRoot}/${path}`),
1959
2354
  ],
1960
2355
  ...(lintCommands.length > 0
1961
2356
  ? {
@@ -1965,12 +2360,22 @@ async function createProjectTargets(
1965
2360
  };
1966
2361
  }
1967
2362
 
2363
+ // Publish each inferred target's semantic kind (`inferredTaskKind`) as metadata. Nx merges metadata beneath a
2364
+ // declaration, so the final graph still says which tasks are build and which are test work after a package rewrites
2365
+ // one. Fresh objects: `CARGO_PRODUCER_METADATA` is shared by every producer.
2366
+ for (const [name, target] of Object.entries(targets)) {
2367
+ const kind = inferredTaskKind(name);
2368
+ if (kind !== undefined) {
2369
+ target.metadata = { ...target.metadata, smooTaskKind: kind };
2370
+ }
2371
+ }
2372
+
1968
2373
  // A declared target REPLACES the inferred input list, pin included, so a
1969
2374
  // repository that hand-writes `inputs` for a cargo target silently loses its
1970
- // toolchain identity. Name the pin once here so such a declaration can
1971
- // reference it as `cargoToolchain` instead of restating two paths that could
2375
+ // toolchain identity. Name the identity once here so such a declaration can
2376
+ // reference it as `cargoToolchain` instead of restating entries that could
1972
2377
  // drift from the plugin; `smoo monorepo validate` refuses a cached cargo
1973
- // target whose resolved inputs reach neither. Defined only for projects that
2378
+ // target that does not reach it. Defined only for projects that
1974
2379
  // HAVE cargo targets: a project's namedInputs definitions are hashed into
1975
2380
  // its configuration hash, so defining it everywhere would invalidate every
1976
2381
  // task in the repository to serve projects that can never reference it.
@@ -1982,7 +2387,7 @@ async function createProjectTargets(
1982
2387
  [VERSIONLESS_DEFAULT_INPUT]: ['default', ...versionlessProjectInputs],
1983
2388
  }),
1984
2389
  ...(Object.keys(targets).some((name) => name.startsWith('cargo-') || name.startsWith('napi-'))
1985
- ? { [CARGO_TOOLCHAIN_NAMED_INPUT]: [...CARGO_TOOLCHAIN_PIN_INPUTS] }
2390
+ ? { [CARGO_TOOLCHAIN_NAMED_INPUT]: cargoToolchainInputs() }
1986
2391
  : {}),
1987
2392
  };
1988
2393
  // A custom Cargo target names this instead of a hand-kept crate list or a
@@ -1990,19 +2395,21 @@ async function createProjectTargets(
1990
2395
  // computation and Nx hashes its files from its own index. Defined for a
1991
2396
  // project with a workspace crate under its root — the same projects the
1992
2397
  // `--closure <projectRoot>` command could describe.
1993
- const closureSources = cargoWorkspaces.filter((workspace) =>
1994
- workspace.packages.some(({ package: pkg }) => {
1995
- const crate = posix.join(workspace.projectRoot, pkg.dir);
1996
- return projectRoot === '.' || crate === projectRoot || crate.startsWith(`${projectRoot}/`);
1997
- }),
1998
- );
2398
+ const closureSources = cargoSourcesUnder(projectRoot, cargoWorkspaces);
1999
2399
  if (closureSources.length > 0) {
2000
- namedInputs[CARGO_CLOSURE_INPUT] = await cargoClosureInputs(
2001
- projectRoot,
2002
- closureSources.map((workspace) => workspace.closureSource),
2003
- );
2400
+ namedInputs[CARGO_CLOSURE_INPUT] = await cargoClosureInputs(projectRoot, closureSources);
2004
2401
  }
2402
+ const externalNodes = await lockScopeNodes(
2403
+ projectRoot,
2404
+ [
2405
+ ...Object.values(targets).map((target) => target.inputs),
2406
+ ...Object.values(declaredTargets).map((target) => (isRecord(target) ? target.inputs : undefined)),
2407
+ ...Object.values(namedInputs),
2408
+ ],
2409
+ cargoWorkspaces,
2410
+ );
2005
2411
  return {
2412
+ ...(Object.keys(externalNodes).length === 0 ? {} : { externalNodes }),
2006
2413
  projects: {
2007
2414
  [projectRoot]: {
2008
2415
  name: projectName,
@@ -2021,6 +2428,51 @@ async function createProjectTargets(
2021
2428
  };
2022
2429
  }
2023
2430
 
2431
+ /** The Cargo resolves with a workspace crate under `directory`: the ones its crates' closure and lock scope cover. */
2432
+ function cargoSourcesUnder(directory: string, cargoWorkspaces: readonly CargoWorkspace[]): CargoClosureSource[] {
2433
+ return cargoWorkspaces
2434
+ .filter((workspace) =>
2435
+ workspace.packages.some(({ package: pkg }) => {
2436
+ const crate = posix.join(workspace.projectRoot, pkg.dir);
2437
+ return directory === '.' || crate === directory || crate.startsWith(`${directory}/`);
2438
+ }),
2439
+ )
2440
+ .map((workspace) => workspace.closureSource);
2441
+ }
2442
+
2443
+ /**
2444
+ * The lock-scope nodes a project publishes: its own bun node, and one Cargo
2445
+ * node per directory its inputs name, computed from the resolves that cover
2446
+ * it. A project names only nodes its own crates' resolves define, so two
2447
+ * projects publishing the same node publish the same value.
2448
+ */
2449
+ async function lockScopeNodes(
2450
+ projectRoot: string,
2451
+ inputLists: readonly unknown[],
2452
+ cargoWorkspaces: readonly CargoWorkspace[],
2453
+ ): Promise<Record<string, ProjectGraphExternalNode>> {
2454
+ const directories = new Set<string>();
2455
+ for (const inputs of inputLists) {
2456
+ if (!Array.isArray(inputs)) continue;
2457
+ for (const input of inputs) {
2458
+ if (!isRecord(input) || !Array.isArray(input.externalDependencies)) continue;
2459
+ for (const name of input.externalDependencies) {
2460
+ if (typeof name === 'string' && name.startsWith(CARGO_LOCK_NODE_PREFIX)) {
2461
+ directories.add(name.slice(CARGO_LOCK_NODE_PREFIX.length));
2462
+ }
2463
+ }
2464
+ }
2465
+ }
2466
+ const own = bunLockNode(projectRoot);
2467
+ const nodes: Record<string, ProjectGraphExternalNode> = { [own.name]: own };
2468
+ for (const node of await Promise.all(
2469
+ [...directories].map((directory) => cargoLockNode(directory, cargoSourcesUnder(directory, cargoWorkspaces))),
2470
+ )) {
2471
+ nodes[node.name] = node;
2472
+ }
2473
+ return nodes;
2474
+ }
2475
+
2024
2476
  interface ResolvedCargoWasmConfig {
2025
2477
  cargoPackage: string;
2026
2478
  libraryName: string;
@@ -2151,21 +2603,28 @@ interface ResolvedNapiConfig {
2151
2603
  }
2152
2604
 
2153
2605
  function inferTypescriptOutputs(tsconfigPath: string, packageJsonPath: string): string[] {
2606
+ const outDir = typescriptOutDir(tsconfigPath, packageJsonPath);
2607
+ // No .tsbuildinfo here: the emit executor overlays incremental: false, so
2608
+ // tsc-js never writes one and a declared-but-absent output fails the
2609
+ // release-candidate output inspection.
2610
+ return outDir === null
2611
+ ? ['{projectRoot}/dist/**/*.{js,cjs,mjs,jsx,d.ts,d.cts,d.mts}{,.map}']
2612
+ : [`{projectRoot}/${outDir}/`];
2613
+ }
2614
+
2615
+ /** The project-relative `compilerOptions.outDir` the config itself states, or null when it states none. */
2616
+ function typescriptOutDir(tsconfigPath: string, packageJsonPath: string): string | null {
2154
2617
  const tsconfig: unknown = readJsonFile(tsconfigPath);
2155
2618
  const compilerOptions = isRecord(tsconfig) && isRecord(tsconfig.compilerOptions) ? tsconfig.compilerOptions : null;
2156
2619
  const outDir = compilerOptions?.outDir;
2157
2620
  if (typeof outDir !== 'string' || outDir.length === 0) {
2158
- // No .tsbuildinfo here: the emit executor overlays incremental: false, so
2159
- // tsc-js never writes one and a declared-but-absent output fails the
2160
- // release-candidate output inspection.
2161
- return ['{projectRoot}/dist/**/*.{js,cjs,mjs,jsx,d.ts,d.cts,d.mts}{,.map}'];
2621
+ return null;
2162
2622
  }
2163
-
2164
2623
  const normalized = posix.normalize(outDir.replaceAll('\\', '/'));
2165
2624
  if (normalized === '.' || normalized === '..' || normalized.startsWith('../') || normalized.startsWith('/')) {
2166
2625
  throw new Error(`${packageJsonPath}: tsconfig.lib.json compilerOptions.outDir must stay inside the project`);
2167
2626
  }
2168
- return [`{projectRoot}/${normalized}`];
2627
+ return normalized.replace(/\/$/, '');
2169
2628
  }
2170
2629
 
2171
2630
  function resolveNapiConfig(
@@ -2217,6 +2676,7 @@ function createNapiTargets(
2217
2676
  projectRoot: string,
2218
2677
  config: ResolvedNapiConfig,
2219
2678
  hostPlatform: NapiPlatform | null,
2679
+ nativeTools: NativeTools | null,
2220
2680
  repoRooted: boolean,
2221
2681
  ): Record<string, TargetConfiguration> {
2222
2682
  // napi derives the addon filename ([name]) from the nearest package.json `napi`
@@ -2231,7 +2691,24 @@ function createNapiTargets(
2231
2691
  // A repository-root Cargo invocation runs outside the owning npm package, so
2232
2692
  // Nx's root-only PATH cannot resolve that package's napi CLI.
2233
2693
  const napiCommand = repoRooted ? posix.join(projectRoot, 'node_modules/.bin/napi') : 'napi';
2234
- const outputPath = (projectOutput: string) => (repoRooted ? posix.join(projectRoot, projectOutput) : projectOutput);
2694
+ const outputDir = (projectOutput: string) => (repoRooted ? posix.join(projectRoot, projectOutput) : projectOutput);
2695
+ // The directory a run writes into, as its `outputDir` option states it for the run's profile.
2696
+ const runOutputDirectory = outputDir(OUTPUT_DIR_ARGUMENT);
2697
+ // After a build, the step that writes its input record (build-inputs.ts) into the output directory from the dep-info
2698
+ // rustc wrote for the addon (`target/[<triple>/]<profile>/lib<crate>.d`). The record is inside the target's
2699
+ // outputs, so Nx restores it with the addon it describes. Relative to the runner's cwd, so the hashed command is
2700
+ // the same in every checkout.
2701
+ const recordInputs = (triple: string | null, profile: CargoProfile, outputDirectory: string): string => {
2702
+ const depInfo = posix.join(
2703
+ ...(triple === null ? [] : [triple]),
2704
+ CARGO_PROFILE_OUTPUT_DIR[profile],
2705
+ `lib${config.cargoPackage.replaceAll('-', '_')}.d`,
2706
+ );
2707
+ const bin = nativeToolCommand(nativeTools, cargoCwd, 'build-inputs', 'smoo-nx-build-inputs');
2708
+ return ` && ${bin} --manifest-path ${config.manifestPath} --dep-info ${depInfo} --output ${outputDirectory}`;
2709
+ };
2710
+ // The task that builds the executable recordInputs runs, when this workspace builds it.
2711
+ const buildInputsTool = nativeToolDependsOn(nativeTools, 'build-inputs');
2235
2712
  const hasHostPlatformTarget = config.targets.some((triple) => {
2236
2713
  const convention = NAPI_TARGET_CONVENTIONS[triple];
2237
2714
  return convention !== undefined && sameNapiPlatform(convention, hostPlatform);
@@ -2248,13 +2725,14 @@ function createNapiTargets(
2248
2725
  // production loads never see it.
2249
2726
  targets['napi-debug'] = {
2250
2727
  executor: 'nx:run-commands',
2728
+ metadata: CARGO_PRODUCER_METADATA,
2251
2729
  cache: true,
2252
2730
  dependsOn: ['^build'],
2253
2731
  inputs: cargoInputs,
2254
- outputs: ['{projectRoot}/.cache/native-debug'],
2732
+ outputs: ['{projectRoot}/.cache/native-debug/'],
2255
2733
  options: {
2256
2734
  cwd: cargoCwd,
2257
- command: `${napiCommand} build --platform --no-js --dts ${config.binaryName}.napi.d.ts ${commonCommand} --output-dir ${outputPath('.cache/native-debug')}`,
2735
+ command: `${napiCommand} build --platform --no-js --dts ${config.binaryName}.napi.d.ts ${commonCommand} --output-dir ${outputDir('.cache/native-debug')}`,
2258
2736
  },
2259
2737
  };
2260
2738
 
@@ -2263,21 +2741,27 @@ function createNapiTargets(
2263
2741
  // second cargo-napi invocation only buys a duplicate dependency graph
2264
2742
  // (a plain build and a `--target` build write different target/
2265
2743
  // subdirectories); native.ts already resolves the identical
2266
- // platform-suffixed filename from dist/native/<platform-dir> after
2267
- // dist/native/host.
2744
+ // platform-suffixed filename from <tree>/<platform-dir> after <tree>/host,
2745
+ // in the one tree its package's source authority selects (.cache/native-dev
2746
+ // in a checkout, dist/native installed).
2268
2747
  const hostBuild = (profile: CargoProfile): string =>
2269
- `${napiCommand} build${CARGO_PROFILE_FLAG[profile]} --platform --no-js --dts ${config.binaryName}.napi.d.ts ${commonCommand} --output-dir ${outputPath('dist/native/host')}`;
2748
+ `${napiCommand} build${CARGO_PROFILE_FLAG[profile]} --platform --no-js --dts ${config.binaryName}.napi.d.ts ${commonCommand} --output-dir ${runOutputDirectory}${recordInputs(null, profile, runOutputDirectory)}`;
2749
+ const hostOutputs = nativeOutputPaths('host');
2270
2750
  targets['cargo-napi'] = {
2271
2751
  executor: 'nx:run-commands',
2752
+ metadata: CARGO_PRODUCER_METADATA,
2272
2753
  cache: true,
2273
- dependsOn: ['^build'],
2754
+ dependsOn: ['^build', ...buildInputsTool],
2274
2755
  inputs: cargoInputs,
2275
- outputs: ['{projectRoot}/dist/native/host'],
2756
+ outputs: [`{projectRoot}/${OUTPUT_DIR_OPTION}/`],
2276
2757
  options: {
2277
2758
  cwd: cargoCwd,
2278
2759
  command: hostBuild('dev'),
2760
+ outputDir: hostOutputs.dev,
2761
+ },
2762
+ configurations: {
2763
+ [RELEASE_CONFIGURATION]: { command: hostBuild('release'), outputDir: hostOutputs.release },
2279
2764
  },
2280
- configurations: { [RELEASE_CONFIGURATION]: { command: hostBuild('release') } },
2281
2765
  };
2282
2766
  }
2283
2767
 
@@ -2287,41 +2771,52 @@ function createNapiTargets(
2287
2771
  throw new Error(`Missing N-API target convention for ${triple}`);
2288
2772
  }
2289
2773
  const targetName = `napi-${convention.architecture}-${convention.targetFamily}`;
2290
- const outputDirectory = `dist/native/${convention.outputName}`;
2774
+ const outputs = nativeOutputPaths(convention.outputName);
2291
2775
  if (convention.targetFamily === 'linux') {
2292
2776
  // Every host builds a Linux addon the same way: devenv's zig through
2293
2777
  // cargo-zigbuild, glibc pinned by the triple suffix. The napi CLI cannot
2294
2778
  // carry that suffix (it looks for the artifact under
2295
2779
  // target/<triple>.2.17/), so the executor names the `.node` itself.
2780
+ const nodeFile = (directory: string): string =>
2781
+ `{projectRoot}/${directory}/${config.binaryName}.${convention.outputName}.node`;
2296
2782
  targets[targetName] = {
2297
2783
  executor: '@smoothbricks/nx-plugin:cargo-zigbuild',
2784
+ metadata: CARGO_PRODUCER_METADATA,
2298
2785
  cache: true,
2299
2786
  inputs: napiInputs(projectRoot, repoRooted, []),
2300
- outputs: [`{projectRoot}/${outputDirectory}`],
2787
+ // The executor takes no `outputDir`: its `output` file is the one place each profile states where it
2788
+ // writes, and the declared output reads the directory holding it from there (`/../`, which Nx's interpolation
2789
+ // joins to the parent). The build-input record stamped beside the `.node` file is restored with it.
2790
+ outputs: ['{options.output}/../'],
2301
2791
  options: {
2302
2792
  target: `${triple}.${LINUX_GLIBC_FLOOR}`,
2303
2793
  manifestPath: posix.join(cargoCwd, config.manifestPath),
2304
2794
  package: config.cargoPackage,
2305
- output: `{projectRoot}/${outputDirectory}/${config.binaryName}.${convention.outputName}.node`,
2795
+ output: nodeFile(outputs.dev),
2306
2796
  },
2307
- configurations: { [RELEASE_CONFIGURATION]: { release: true } },
2797
+ configurations: { [RELEASE_CONFIGURATION]: { release: true, output: nodeFile(outputs.release) } },
2308
2798
  };
2309
2799
  continue;
2310
2800
  }
2311
2801
  // macOS addons need Apple's SDK, which zig does not carry: the napi CLI
2312
2802
  // drives the host's own toolchain and writes the platform `.d.ts`.
2313
2803
  const platformBuild = (profile: CargoProfile): string =>
2314
- `${napiCommand} build${CARGO_PROFILE_FLAG[profile]} --platform --no-js --dts ${config.binaryName}.${convention.outputName}.d.ts --target ${triple} ${commonCommand} --output-dir ${outputPath(outputDirectory)}`;
2804
+ `${napiCommand} build${CARGO_PROFILE_FLAG[profile]} --platform --no-js --dts ${config.binaryName}.${convention.outputName}.d.ts --target ${triple} ${commonCommand} --output-dir ${runOutputDirectory}${recordInputs(triple, profile, runOutputDirectory)}`;
2315
2805
  targets[targetName] = {
2316
2806
  executor: 'nx:run-commands',
2807
+ metadata: CARGO_PRODUCER_METADATA,
2317
2808
  cache: true,
2809
+ ...(buildInputsTool.length > 0 ? { dependsOn: buildInputsTool } : {}),
2318
2810
  inputs: cargoInputs,
2319
- outputs: [`{projectRoot}/${outputDirectory}`],
2811
+ outputs: [`{projectRoot}/${OUTPUT_DIR_OPTION}/`],
2320
2812
  options: {
2321
2813
  cwd: cargoCwd,
2322
2814
  command: platformBuild('dev'),
2815
+ outputDir: outputs.dev,
2816
+ },
2817
+ configurations: {
2818
+ [RELEASE_CONFIGURATION]: { command: platformBuild('release'), outputDir: outputs.release },
2323
2819
  },
2324
- configurations: { [RELEASE_CONFIGURATION]: { command: platformBuild('release') } },
2325
2820
  };
2326
2821
  }
2327
2822
  return targets;
@@ -2363,9 +2858,11 @@ async function readPackageJson(packageJsonPath: string): Promise<PackageJson> {
2363
2858
  const rawNx = isRecord(parsed.nx) ? parsed.nx : undefined;
2364
2859
  return {
2365
2860
  ...('bin' in parsed ? { bin: parsed.bin } : {}),
2861
+ ...(isRecord(parsed.devDependencies) ? { devDependencies: parsed.devDependencies } : {}),
2366
2862
  ...(typeof parsed.name === 'string' ? { name: parsed.name } : {}),
2367
2863
  ...(isRecord(parsed.napi) ? { napi: parsed.napi } : {}),
2368
2864
  ...(typeof parsed.private === 'boolean' ? { private: parsed.private } : {}),
2865
+ ...('scriptc' in parsed ? { scriptc: parsed.scriptc } : {}),
2369
2866
  ...(isRecord(parsed.scripts) ? { scripts: parsed.scripts } : {}),
2370
2867
  ...(rawNx
2371
2868
  ? {
@@ -2522,10 +3019,28 @@ async function resolveCargoWorkspaces(
2522
3019
  // piece excludes them: each test is selected by exactly one target.
2523
3020
  const serialExclusion = serialGroups.length === 0 ? null : serialGroups.map((group) => group.filter).join(' or ');
2524
3021
  const notSerial = serialExclusion === null ? [] : [`not (${serialExclusion})`];
3022
+ const timings = readNextestTimings(join(absoluteRoot, NEXTEST_TIMINGS_PATH));
3023
+ for (const crate of Object.keys(timings)) {
3024
+ if (!attributed.some((pkg) => pkg.name === crate && pkg.testShards > 1)) {
3025
+ throw new Error(
3026
+ `${posix.join(rootProject.root, NEXTEST_TIMINGS_PATH)} times ${crate}, which is no member of this Cargo ` +
3027
+ 'workspace that declares smoothbricks.test.shards above 1',
3028
+ );
3029
+ }
3030
+ }
2525
3031
  for (const pkg of attributed) {
2526
3032
  const pieces: CargoTestPiece[] = [];
2527
3033
  const sharded = pkg.testShards > 1;
2528
- const pin = sharded && exceptional !== null ? exceptional : null;
3034
+ const timed = timings[pkg.name] ?? {};
3035
+ const named = Object.keys(timed);
3036
+ const exceptionalHere = sharded ? exceptional : null;
3037
+ // The tests the hash does not place: nextest.toml's exceptional class and the measured slow tests.
3038
+ const pin =
3039
+ named.length === 0
3040
+ ? exceptionalHere
3041
+ : exceptionalHere === null
3042
+ ? namedTestsFilter(named)
3043
+ : `(${exceptionalHere}) or (${namedTestsFilter(named)})`;
2529
3044
  const ordinary = [`package(${pkg.name})`, ...(pin === null ? [] : [`not (${pin})`]), ...notSerial].join(' and ');
2530
3045
  for (let index = 1; index <= pkg.testShards; index += 1) {
2531
3046
  const targetName = cargoTestPackageTargetName(pkg.name, sharded ? `shard${index}` : undefined);
@@ -2536,10 +3051,23 @@ async function resolveCargoWorkspaces(
2536
3051
  });
2537
3052
  }
2538
3053
  if (pin !== null) {
3054
+ // Measured tests are dealt by time; the last shard also takes every exceptional test the
3055
+ // manifest does not name, so the exception shards stay an exact cover of the pin.
3056
+ const members = named.length === 0 ? null : timedShardMembers(timed, pkg.testShards);
2539
3057
  for (let index = 1; index <= pkg.testShards; index += 1) {
3058
+ const own = members?.[index - 1];
3059
+ const unnamed =
3060
+ own !== undefined && exceptionalHere !== null && index === pkg.testShards
3061
+ ? ` or ((${exceptionalHere}) and not (${namedTestsFilter(named)}))`
3062
+ : '';
2540
3063
  pieces.push({
2541
- extra: ` --partition hash:${index}/${pkg.testShards}`,
2542
- selector: [`package(${pkg.name}) and (${pin})`, ...notSerial].join(' and '),
3064
+ extra: own === undefined ? ` --partition hash:${index}/${pkg.testShards}` : '',
3065
+ selector: [
3066
+ own === undefined
3067
+ ? `package(${pkg.name}) and (${pin})`
3068
+ : `package(${pkg.name}) and ((${namedTestsFilter(own)})${unnamed})`,
3069
+ ...notSerial,
3070
+ ].join(' and '),
2543
3071
  targetName: cargoTestPackageTargetName(pkg.name, `${CARGO_TEST_EXCEPTIONS_SUFFIX}-shard${index}`),
2544
3072
  });
2545
3073
  }
@@ -2592,12 +3120,13 @@ async function resolveCargoWorkspaces(
2592
3120
  * own on every run, so N pieces paid N extractions of every binary in the
2593
3121
  * workspace to run 1/N of the tests each: on a workspace with ~200 test
2594
3122
  * binaries, ~25 runners extracting side by side on a loaded host all hit the
2595
- * 120s bound still "Extracting". `smoo-nx-nextest-extract` hashes the archive,
2596
- * unpacks it under that hash unless a previous runner already did — one
3123
+ * 120s bound still "Extracting". `smoo-nx-nextest-extract` reads the archive's
3124
+ * key, the hash of the task that produced it (createCargoTestArchiveTarget),
3125
+ * unpacks it under that key unless a previous runner already did — one
2597
3126
  * extracts while the rest wait — and prints the directory; the run then reuses
2598
3127
  * it through nextest's own reuse-build flags, which is what `--archive-file`
2599
- * does after unpacking. Keyed by the archive's bytes, so a rebuilt or restored
2600
- * archive can never run an older extraction's binaries. The one difference
3128
+ * does after unpacking. Keyed by the producing task's inputs, so a rebuilt or
3129
+ * restored archive of other inputs can never run an older extraction's binaries. The one difference
2601
3130
  * from `--archive-file` is the Rust standard library directory: nextest has no
2602
3131
  * flag to remap it, so a run uses the producing toolchain's own sysroot rather
2603
3132
  * than the archived copy of it — the same toolchain, because the archive's hash
@@ -2646,6 +3175,7 @@ async function addCargoTestTargets(
2646
3175
  projectRoot: string,
2647
3176
  workspaceRoot: string,
2648
3177
  workspace: CargoWorkspace,
3178
+ nativeTools: NativeTools | null,
2649
3179
  ): Promise<string[]> {
2650
3180
  const targetNames: string[] = [];
2651
3181
  for (const plan of workspace.packages) {
@@ -2659,7 +3189,7 @@ async function addCargoTestTargets(
2659
3189
  });
2660
3190
  for (const piece of plan.pieces) {
2661
3191
  targetNames.push(piece.targetName);
2662
- targets[piece.targetName] = cargoTestRunnerTarget(workspace, archive, inputs, piece);
3192
+ targets[piece.targetName] = cargoTestRunnerTarget(workspace, nativeTools, archive, inputs, piece);
2663
3193
  }
2664
3194
  }
2665
3195
  return targetNames;
@@ -2688,15 +3218,16 @@ function serialGroupMemberDirs(workspace: CargoWorkspace, group: SerialTestGroup
2688
3218
 
2689
3219
  /**
2690
3220
  * The inputs of the runners that select crates from one cargo workspace: the
2691
- * sources of the crates they select, every member manifest, and the repository's
2692
- * nextest config.
3221
+ * sources of the crates they select, the manifest of every package the workspace
3222
+ * builds, and the repository's nextest config.
2693
3223
  *
2694
3224
  * Workspace-anchored for the reason `cargoPackageTestInputs` gives: a
2695
3225
  * `{projectRoot}` glob hashes only files this project owns, and sibling manifests
2696
3226
  * belong to whichever nested project holds them. A workspace nextest build unifies
2697
- * features across every selected member, so a sibling manifest can change a crate's
2698
- * tests without being a path dependency: track those manifests, not unrelated
2699
- * sibling sources.
3227
+ * features across every package it compiles, so a sibling manifest can change a
3228
+ * crate's tests without being a path dependency: a member's, and a path package's
3229
+ * that reaches the build only as another crate's dev-dependency. Track those
3230
+ * manifests, not unrelated sibling sources.
2700
3231
  *
2701
3232
  * The repository's own nextest config layers OVER the plugin's tool config, so it
2702
3233
  * decides timeouts, groups and archive contents: a cached verdict that ignored it
@@ -2715,16 +3246,40 @@ async function cargoTestRunnerInputs(
2715
3246
  absoluteProjectRoot: join(workspaceRoot, workspace.projectRoot),
2716
3247
  memberDir,
2717
3248
  cache: workspace.inputsCache,
3249
+ cargo: workspace.closureSource.cargo,
2718
3250
  }),
2719
3251
  ),
2720
3252
  );
3253
+ // The archive unifies every built package's manifest into every test binary, and a runner's key does not follow the
3254
+ // archive's outputs, so each runner names them all: the ones Nx holds as files, the rest through the repository's
3255
+ // runtime hash of external sources.
3256
+ const manifests: string[] = [];
3257
+ const external = new Map<string, string>();
3258
+ for (const pkg of workspace.closureSource.cargo.local) {
3259
+ const manifest = relative(workspace.closureSource.root, pkg.manifest);
3260
+ if (manifest === '..' || manifest.startsWith(`..${sep}`) || isAbsolute(manifest)) {
3261
+ external.set(pkg.name, pkg.directory);
3262
+ } else {
3263
+ manifests.push(posix.join('{workspaceRoot}', manifest.split(sep).join('/')));
3264
+ }
3265
+ }
3266
+ if (external.size > 0) {
3267
+ requireExternalRustCratesInput(workspaceRoot, posix.join(workspace.projectRoot, 'Cargo.toml'), external);
3268
+ }
2721
3269
  return [
2722
3270
  ...new Set([
2723
3271
  ...sources.flat(),
2724
- ...workspace.packages.map((member) => posix.join(inputRoot, member.package.dir, 'Cargo.toml')),
3272
+ ...manifests,
3273
+ ...(external.size > 0 ? [EXTERNAL_RUST_CRATES_INPUT] : []),
2725
3274
  posix.join(inputRoot, NEXTEST_REPO_CONFIG_PATH),
2726
3275
  ]),
2727
3276
  fileHashInput(PLUGIN_NEXTEST_CONFIG_PATH),
3277
+ // The Cargo.lock entries each selected crate's closure reaches.
3278
+ {
3279
+ externalDependencies: [
3280
+ ...new Set(memberDirs.map((memberDir) => cargoLockNodeName(posix.join(workspace.projectRoot, memberDir)))),
3281
+ ],
3282
+ },
2728
3283
  ];
2729
3284
  }
2730
3285
 
@@ -2733,16 +3288,21 @@ async function cargoTestRunnerInputs(
2733
3288
  * workspace builds its command here, so the extraction, reuse-build, tool config and cwd cannot
2734
3289
  * drift between the per-crate pieces and the serial groups.
2735
3290
  */
2736
- function nextestRunnerCommand(workspace: CargoWorkspace, selector: string, flags: string): string {
3291
+ function nextestRunnerCommand(
3292
+ workspace: CargoWorkspace,
3293
+ nativeTools: NativeTools | null,
3294
+ selector: string,
3295
+ flags: string,
3296
+ ): string {
2737
3297
  const toolConfig = nextestToolConfigArg(workspace.projectRoot);
2738
3298
  // Relative to the runner's cwd, so the hashed command is the same in every checkout.
2739
- const extractBin = posix.join(posix.relative(workspace.projectRoot, '.'), NEXTEST_EXTRACT_BIN);
3299
+ const extract = nativeToolCommand(nativeTools, workspace.projectRoot, 'nextest-extract', 'smoo-nx-nextest-extract');
2740
3300
  const reuseExtraction =
2741
3301
  `--binaries-metadata "$extracted/${EXTRACTED_BINARIES_METADATA}" ` +
2742
3302
  `--cargo-metadata "$extracted/${EXTRACTED_CARGO_METADATA}" ` +
2743
3303
  `--target-dir-remap "$extracted/${EXTRACTED_TARGET_DIR}"`;
2744
3304
  return (
2745
- `extracted="$(node ${extractBin} ${CARGO_TEST_ARCHIVE_FILE})" && ` +
3305
+ `extracted="$(${extract} ${CARGO_TEST_ARCHIVE_FILE})" && ` +
2746
3306
  cargoFrozen(
2747
3307
  `nextest run ${reuseExtraction} --workspace-remap . -E ${shellWord(selector)}${flags} --user-config-file none ${toolConfig}`,
2748
3308
  )
@@ -2752,6 +3312,7 @@ function nextestRunnerCommand(workspace: CargoWorkspace, selector: string, flags
2752
3312
  /** One per-crate piece: a bounded run of its partition of the archive's tests. */
2753
3313
  function cargoTestRunnerTarget(
2754
3314
  workspace: CargoWorkspace,
3315
+ nativeTools: NativeTools | null,
2755
3316
  archive: CargoTargetDependency,
2756
3317
  inputs: NonNullable<TargetConfiguration['inputs']>,
2757
3318
  piece: CargoTestPiece,
@@ -2760,9 +3321,14 @@ function cargoTestRunnerTarget(
2760
3321
  executor: '@smoothbricks/nx-plugin:bounded-exec',
2761
3322
  cache: true,
2762
3323
  inputs,
2763
- dependsOn: [archive],
3324
+ dependsOn: [archive, ...nativeToolDependsOn(nativeTools, 'nextest-extract')],
2764
3325
  options: {
2765
- command: nextestRunnerCommand(workspace, piece.selector, `${piece.extra} --no-fail-fast --no-tests=pass`),
3326
+ command: nextestRunnerCommand(
3327
+ workspace,
3328
+ nativeTools,
3329
+ piece.selector,
3330
+ `${piece.extra} --no-fail-fast --no-tests=pass`,
3331
+ ),
2766
3332
  cwd: workspace.projectRoot,
2767
3333
  idleTimeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
2768
3334
  killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
@@ -2780,6 +3346,7 @@ function cargoTestRunnerTarget(
2780
3346
  */
2781
3347
  function cargoTestGroupTarget(
2782
3348
  workspace: CargoWorkspace,
3349
+ nativeTools: NativeTools | null,
2783
3350
  inputs: NonNullable<TargetConfiguration['inputs']>,
2784
3351
  group: SerialTestGroup,
2785
3352
  ): TargetConfiguration {
@@ -2787,9 +3354,9 @@ function cargoTestGroupTarget(
2787
3354
  executor: '@smoothbricks/nx-plugin:bounded-exec',
2788
3355
  cache: true,
2789
3356
  inputs: [...inputs, fileHashInput(PLUGIN_NEXTEST_CODE_BOUND)],
2790
- dependsOn: [CARGO_TEST_ARCHIVE_TARGET],
3357
+ dependsOn: [CARGO_TEST_ARCHIVE_TARGET, ...nativeToolDependsOn(nativeTools, 'nextest-extract')],
2791
3358
  options: {
2792
- command: nextestRunnerCommand(workspace, group.filter, ' --no-fail-fast --no-tests=fail'),
3359
+ command: nextestRunnerCommand(workspace, nativeTools, group.filter, ' --no-fail-fast --no-tests=fail'),
2793
3360
  cwd: workspace.projectRoot,
2794
3361
  idleTimeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
2795
3362
  killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,