@smoothbricks/nx-plugin 0.5.7 → 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 (432) hide show
  1. package/README.md +1086 -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/bounded-exec/bounds.d.ts +56 -0
  59. package/dist/executors/bounded-exec/bounds.d.ts.map +1 -0
  60. package/dist/executors/bounded-exec/bounds.js +43 -0
  61. package/dist/executors/bounded-exec/cpu-pool.d.ts +33 -36
  62. package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
  63. package/dist/executors/bounded-exec/cpu-pool.js +54 -119
  64. package/dist/executors/bounded-exec/executor.d.ts +19 -12
  65. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  66. package/dist/executors/bounded-exec/executor.js +371 -239
  67. package/dist/executors/bounded-exec/gateway-lease.d.ts +22 -19
  68. package/dist/executors/bounded-exec/gateway-lease.d.ts.map +1 -1
  69. package/dist/executors/bounded-exec/gateway-lease.js +81 -28
  70. package/dist/executors/bounded-exec/hang-diagnostics.d.ts +18 -1
  71. package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -1
  72. package/dist/executors/bounded-exec/hang-diagnostics.js +148 -30
  73. package/dist/executors/bounded-exec/lease-wait.d.ts +43 -0
  74. package/dist/executors/bounded-exec/lease-wait.d.ts.map +1 -0
  75. package/dist/executors/bounded-exec/lease-wait.js +68 -0
  76. package/dist/executors/bounded-exec/lock-wait.d.ts +51 -0
  77. package/dist/executors/bounded-exec/lock-wait.d.ts.map +1 -0
  78. package/dist/executors/bounded-exec/lock-wait.js +108 -0
  79. package/dist/executors/bounded-exec/owned-subtree.d.ts +84 -0
  80. package/dist/executors/bounded-exec/owned-subtree.d.ts.map +1 -0
  81. package/dist/executors/bounded-exec/owned-subtree.js +178 -0
  82. package/dist/executors/bounded-exec/progress.d.ts +4 -1
  83. package/dist/executors/bounded-exec/progress.d.ts.map +1 -1
  84. package/dist/executors/bounded-exec/progress.js +5 -2
  85. package/dist/executors/bounded-exec/ram-attach.d.ts +19 -0
  86. package/dist/executors/bounded-exec/ram-attach.d.ts.map +1 -0
  87. package/dist/executors/bounded-exec/ram-attach.js +207 -0
  88. package/dist/executors/bounded-exec/ram-detach.d.ts +25 -0
  89. package/dist/executors/bounded-exec/ram-detach.d.ts.map +1 -0
  90. package/dist/executors/bounded-exec/ram-detach.js +207 -0
  91. package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts +76 -0
  92. package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts.map +1 -1
  93. package/dist/executors/bounded-exec/ram-temp-fixtures.js +296 -0
  94. package/dist/executors/bounded-exec/ram-temp.d.ts +388 -88
  95. package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -1
  96. package/dist/executors/bounded-exec/ram-temp.js +1213 -399
  97. package/dist/executors/bounded-exec/run-cpu-pool.d.ts +4 -4
  98. package/dist/executors/bounded-exec/run-cpu-pool.d.ts.map +1 -1
  99. package/dist/executors/bounded-exec/run-cpu-pool.js +20 -30
  100. package/dist/executors/bounded-exec/runner-hook.js +14 -5
  101. package/dist/executors/bounded-exec/runner-lifecycle.d.ts +14 -1
  102. package/dist/executors/bounded-exec/runner-lifecycle.d.ts.map +1 -1
  103. package/dist/executors/bounded-exec/runner-lifecycle.js +27 -6
  104. package/dist/executors/bounded-exec/{cpu-tokens.d.ts → runner-sizing.d.ts} +14 -42
  105. package/dist/executors/bounded-exec/runner-sizing.d.ts.map +1 -0
  106. package/dist/executors/bounded-exec/{cpu-tokens.js → runner-sizing.js} +5 -35
  107. package/dist/executors/bounded-exec/runtime-pin.d.ts +73 -0
  108. package/dist/executors/bounded-exec/runtime-pin.d.ts.map +1 -0
  109. package/dist/executors/bounded-exec/runtime-pin.js +167 -0
  110. package/dist/executors/bounded-exec/schema.d.ts +18 -1
  111. package/dist/executors/bounded-exec/schema.d.ts.map +1 -1
  112. package/dist/executors/bounded-exec/verdict.d.ts +40 -11
  113. package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
  114. package/dist/executors/bounded-exec/verdict.js +88 -19
  115. package/dist/executors/cargo-zigbuild/executor.d.ts +21 -0
  116. package/dist/executors/cargo-zigbuild/executor.d.ts.map +1 -1
  117. package/dist/executors/cargo-zigbuild/executor.js +67 -12
  118. package/dist/executors/clean-outputs/executor.js +1 -0
  119. package/dist/executors/scriptc-native/executor.d.ts +79 -0
  120. package/dist/executors/scriptc-native/executor.d.ts.map +1 -0
  121. package/dist/executors/scriptc-native/executor.js +367 -0
  122. package/dist/executors/scriptc-native/ffi-paths.d.ts +9 -0
  123. package/dist/executors/scriptc-native/ffi-paths.d.ts.map +1 -0
  124. package/dist/executors/scriptc-native/ffi-paths.js +25 -0
  125. package/dist/executors/scriptc-native/schema.d.ts +34 -0
  126. package/dist/executors/scriptc-native/schema.d.ts.map +1 -0
  127. package/dist/executors/scriptc-native/schema.js +1 -0
  128. package/dist/executors/typescript-emit/executor.d.ts +3 -1
  129. package/dist/executors/typescript-emit/executor.d.ts.map +1 -1
  130. package/dist/executors/typescript-emit/executor.js +164 -33
  131. package/dist/forbidden-spelling-policy.d.ts +56 -0
  132. package/dist/forbidden-spelling-policy.d.ts.map +1 -0
  133. package/dist/forbidden-spelling-policy.js +176 -0
  134. package/dist/generators/create-package/generator.d.ts.map +1 -1
  135. package/dist/generators/create-package/generator.js +3 -4
  136. package/dist/graph-input-contract.d.ts +14 -0
  137. package/dist/graph-input-contract.d.ts.map +1 -1
  138. package/dist/graph-input-contract.js +67 -2
  139. package/dist/index.d.ts +23 -6
  140. package/dist/index.d.ts.map +1 -1
  141. package/dist/index.js +672 -214
  142. package/dist/managed-assets.d.ts +2 -0
  143. package/dist/managed-assets.d.ts.map +1 -1
  144. package/dist/managed-files/files.d.ts +3 -3
  145. package/dist/managed-files/files.d.ts.map +1 -1
  146. package/dist/managed-files/files.js +28 -3
  147. package/dist/managed-files/managed-format.d.ts.map +1 -1
  148. package/dist/managed-files/managed-format.js +1 -0
  149. package/dist/nextest-code-bound.js +1 -0
  150. package/dist/nextest-timings.d.ts +35 -0
  151. package/dist/nextest-timings.d.ts.map +1 -0
  152. package/dist/nextest-timings.js +168 -0
  153. package/dist/owned-installation.d.ts +6 -5
  154. package/dist/owned-installation.d.ts.map +1 -1
  155. package/dist/owned-installation.js +150 -26
  156. package/dist/package-target-policy.d.ts.map +1 -1
  157. package/dist/package-target-policy.js +2 -3
  158. package/dist/process-children.d.ts +7 -0
  159. package/dist/process-children.d.ts.map +1 -0
  160. package/dist/process-children.darwin.d.ts +7 -0
  161. package/dist/process-children.darwin.d.ts.map +1 -0
  162. package/dist/process-children.darwin.js +13 -0
  163. package/dist/process-children.js +14 -0
  164. package/dist/process-children.linux.d.ts +8 -0
  165. package/dist/process-children.linux.d.ts.map +1 -0
  166. package/dist/process-children.linux.js +25 -0
  167. package/dist/process-group.d.ts +108 -0
  168. package/dist/process-group.d.ts.map +1 -0
  169. package/dist/process-group.js +171 -0
  170. package/dist/process-listing.d.ts +7 -0
  171. package/dist/process-listing.d.ts.map +1 -0
  172. package/dist/process-listing.js +51 -0
  173. package/dist/producer-receipts.d.ts +8 -2
  174. package/dist/producer-receipts.d.ts.map +1 -1
  175. package/dist/producer-receipts.js +75 -48
  176. package/dist/task-graph-policy.d.ts +21 -0
  177. package/dist/task-graph-policy.d.ts.map +1 -0
  178. package/dist/task-graph-policy.js +91 -0
  179. package/dist/test-timings.js +4 -4
  180. package/dist/test-walk-policy.d.ts +14 -5
  181. package/dist/test-walk-policy.d.ts.map +1 -1
  182. package/dist/test-walk-policy.js +8 -2
  183. package/dist/testing.d.ts +73 -28
  184. package/dist/testing.d.ts.map +1 -1
  185. package/dist/testing.js +217 -223
  186. package/dist/tool-bins.d.ts +33 -0
  187. package/dist/tool-bins.d.ts.map +1 -0
  188. package/dist/tool-bins.js +72 -0
  189. package/dist/typecheck-test-policy.d.ts.map +1 -1
  190. package/dist/typecheck-test-policy.js +3 -4
  191. package/dist/wait-why-policy.d.ts +28 -0
  192. package/dist/wait-why-policy.d.ts.map +1 -0
  193. package/dist/wait-why-policy.js +223 -0
  194. package/dist/workspace-config-policy.d.ts +14 -8
  195. package/dist/workspace-config-policy.d.ts.map +1 -1
  196. package/dist/workspace-config-policy.js +60 -16
  197. package/dist/workspace-manifest.d.ts +41 -6
  198. package/dist/workspace-manifest.d.ts.map +1 -1
  199. package/dist/workspace-manifest.js +57 -0
  200. package/executors.json +16 -1
  201. package/loader.js +2 -0
  202. package/managed/raw/envrc +11 -0
  203. package/managed/raw/patches/nx@23.2.1.patch +2840 -199
  204. package/managed/raw/patches/ttsc@0.34.1.patch +119 -0
  205. package/managed/raw/tooling/direnv/cargo-fetch-bound.ts +245 -0
  206. package/managed/raw/tooling/direnv/cargo-fetch-run.ts +299 -0
  207. package/managed/raw/tooling/direnv/compiler-variables.sh +42 -0
  208. package/managed/raw/tooling/direnv/developer-links.ts +464 -25
  209. package/managed/raw/tooling/direnv/devenv.smoo.nix +78 -38
  210. package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +14 -12
  211. package/managed/raw/tooling/direnv/installed-bun-links.ts +308 -0
  212. package/managed/raw/tooling/direnv/linked-snapshots.ts +62 -3
  213. package/managed/raw/tooling/direnv/nx-socket-dir.sh +56 -17
  214. package/managed/raw/tooling/direnv/repo-path +68 -6
  215. package/managed/raw/tooling/direnv/secret-references.ts +13 -4
  216. package/managed/raw/tooling/direnv/setup-environment.ts +128 -537
  217. package/managed/raw/tooling/direnv/toolchain-stamp.ts +4 -2
  218. package/managed/raw/tooling/direnv/ttsc-env.sh +9 -0
  219. package/managed/raw/tooling/direnv/uv-relocation.ts +227 -0
  220. package/managed/raw/tooling/git-hooks/commit-msg.sh +2 -1
  221. package/managed/raw/tooling/git-hooks/pre-commit.sh +2 -1
  222. package/managed/raw/tooling/git-hooks/pre-push.sh +2 -1
  223. package/managed/templates/github/actions/cache-ttsc-plugins/action.yml +85 -7
  224. package/managed/templates/github/actions/save-nix-devenv/action.yml +12 -2
  225. package/managed/templates/github/actions/setup-devenv/action.yml +2 -0
  226. package/package.json +77 -13
  227. package/src/bin/smoo-nx-cargo-toolchain.ts +11 -0
  228. package/src/bin/smoo-nx-forbidden-spellings.ts +33 -0
  229. package/src/bin/smoo-nx-nextest-timings.ts +31 -0
  230. package/src/bounded-test-policy.ts +12 -14
  231. package/src/build-state-output-policy.ts +458 -34
  232. package/src/bun-lock-scope.ts +108 -0
  233. package/src/cargo-build-script-env.ts +265 -0
  234. package/src/cargo-closure-input.ts +74 -7
  235. package/src/cargo-retention-hook.ts +94 -0
  236. package/src/cargo-source-hash.ts +138 -41
  237. package/src/cargo-toolchain-paths.ts +95 -0
  238. package/src/cargo-toolchain-policy.ts +49 -5
  239. package/src/cargo-workspace.ts +72 -123
  240. package/src/cross-check-policy.ts +12 -10
  241. package/src/disk-command-policy.ts +1 -0
  242. package/src/ensure-built-receipt.ts +132 -39
  243. package/src/ensure-built-witness.ts +62 -10
  244. package/src/ensure-built.ts +11 -1
  245. package/src/eslint-config-closure.ts +357 -0
  246. package/src/executors/bounded-exec/bounds.ts +76 -0
  247. package/src/executors/bounded-exec/cpu-pool.ts +51 -117
  248. package/src/executors/bounded-exec/executor.ts +423 -259
  249. package/src/executors/bounded-exec/gateway-lease.ts +82 -33
  250. package/src/executors/bounded-exec/hang-diagnostics.ts +173 -31
  251. package/src/executors/bounded-exec/lease-wait.ts +89 -0
  252. package/src/executors/bounded-exec/lock-wait.ts +141 -0
  253. package/src/executors/bounded-exec/owned-subtree.ts +235 -0
  254. package/src/executors/bounded-exec/progress.ts +9 -3
  255. package/src/executors/bounded-exec/ram-attach.ts +238 -0
  256. package/src/executors/bounded-exec/ram-detach.ts +226 -0
  257. package/src/executors/bounded-exec/ram-temp-fixtures.ts +358 -0
  258. package/src/executors/bounded-exec/ram-temp-registry.txt +440 -0
  259. package/src/executors/bounded-exec/ram-temp.ts +1497 -460
  260. package/src/executors/bounded-exec/run-cpu-pool.ts +22 -30
  261. package/src/executors/bounded-exec/runner-hook.ts +14 -6
  262. package/src/executors/bounded-exec/runner-lifecycle.ts +31 -8
  263. package/src/executors/bounded-exec/{cpu-tokens.ts → runner-sizing.ts} +13 -59
  264. package/src/executors/bounded-exec/runtime-pin.ts +232 -0
  265. package/src/executors/bounded-exec/schema.json +11 -2
  266. package/src/executors/bounded-exec/schema.ts +19 -1
  267. package/src/executors/bounded-exec/verdict.ts +137 -34
  268. package/src/executors/cargo-zigbuild/executor.ts +82 -8
  269. package/src/executors/clean-outputs/executor.ts +1 -0
  270. package/src/executors/scriptc-native/executor.ts +394 -0
  271. package/src/executors/scriptc-native/ffi-paths.ts +29 -0
  272. package/src/executors/scriptc-native/schema.json +60 -0
  273. package/src/executors/scriptc-native/schema.ts +34 -0
  274. package/src/executors/typescript-emit/executor.ts +205 -38
  275. package/src/forbidden-spelling-policy.ts +226 -0
  276. package/src/generators/create-package/generator.ts +7 -7
  277. package/src/graph-input-contract.ts +61 -2
  278. package/src/index.ts +788 -224
  279. package/src/managed-assets.ts +3 -0
  280. package/src/managed-files/files.ts +28 -3
  281. package/src/managed-files/managed-format.ts +1 -0
  282. package/src/nextest-code-bound.ts +1 -0
  283. package/src/nextest-timings.ts +106 -0
  284. package/src/owned-installation.ts +150 -23
  285. package/src/package-target-policy.ts +2 -3
  286. package/src/process-children.darwin.ts +14 -0
  287. package/src/process-children.linux.ts +33 -0
  288. package/src/process-children.ts +22 -0
  289. package/src/process-group.ts +209 -0
  290. package/src/process-listing.ts +54 -0
  291. package/src/producer-receipts.ts +68 -45
  292. package/src/task-graph-policy.ts +98 -0
  293. package/src/test-walk-policy.ts +23 -8
  294. package/src/testing.ts +240 -232
  295. package/src/tool-bins.ts +108 -0
  296. package/src/typecheck-test-policy.ts +2 -3
  297. package/src/wait-why-policy.ts +226 -0
  298. package/src/workspace-config-policy.ts +63 -15
  299. package/src/workspace-manifest.ts +89 -6
  300. package/test-timings.json +122 -98
  301. package/dist/bin/smoo-nx-failures.d.ts +0 -3
  302. package/dist/bin/smoo-nx-failures.d.ts.map +0 -1
  303. package/dist/bin/smoo-nx-failures.js +0 -3
  304. package/dist/bin/smoo-nx-nextest-extract.d.ts +0 -3
  305. package/dist/bin/smoo-nx-nextest-extract.d.ts.map +0 -1
  306. package/dist/bin/smoo-nx-nextest-extract.js +0 -42
  307. package/dist/executors/bounded-exec/cpu-tokens.d.ts.map +0 -1
  308. package/dist/failure-summary.d.ts +0 -5
  309. package/dist/failure-summary.d.ts.map +0 -1
  310. package/dist/failure-summary.js +0 -118
  311. package/dist/nextest-extraction.d.ts +0 -117
  312. package/dist/nextest-extraction.d.ts.map +0 -1
  313. package/dist/nextest-extraction.js +0 -303
  314. package/managed/raw/patches/ttsc@0.30.4.patch +0 -2255
  315. package/src/__tests__/cargo-closure-filesets.ts +0 -94
  316. package/src/__tests__/cargo-closure-fixture.ts +0 -113
  317. package/src/__tests__/counted-cargo-process.ts +0 -286
  318. package/src/__tests__/counted-cargo.ts +0 -713
  319. package/src/__tests__/directory-change.ts +0 -27
  320. package/src/__tests__/fixture-cargo-home.ts +0 -36
  321. package/src/__tests__/fixture-nx-env.ts +0 -193
  322. package/src/__tests__/owned-installation.ts +0 -13
  323. package/src/__tests__/past-tick.ts +0 -12
  324. package/src/__tests__/progress-clock.ts +0 -43
  325. package/src/__tests__/runtime-input.ts +0 -23
  326. package/src/bin/smoo-nx-bound-failures.test.ts +0 -127
  327. package/src/bin/smoo-nx-failures.ts +0 -4
  328. package/src/bin/smoo-nx-nextest-extract.ts +0 -44
  329. package/src/bounded-test-policy.test.ts +0 -1029
  330. package/src/build-state-output-policy.test.ts +0 -115
  331. package/src/bun-bootstrap.test.ts +0 -102
  332. package/src/bun-file-packages.test.ts +0 -47
  333. package/src/cargo-closure-filesets.test.ts +0 -63
  334. package/src/cargo-closure-input.property.test.ts +0 -50
  335. package/src/cargo-closure-input.test.ts +0 -506
  336. package/src/cargo-closure-key.test.ts +0 -240
  337. package/src/cargo-resolve-cache.test.ts +0 -1181
  338. package/src/cargo-source-hash.test.ts +0 -707
  339. package/src/cargo-workspace.test.ts +0 -615
  340. package/src/cross-check-policy.test.ts +0 -316
  341. package/src/disk-command-policy.test.ts +0 -61
  342. package/src/ensure-built-receipt.test.ts +0 -279
  343. package/src/ensure-built-witness.test.ts +0 -688
  344. package/src/ensure-built.test.ts +0 -1462
  345. package/src/executors/all-verdicts/executor.test.ts +0 -135
  346. package/src/executors/bounded-exec/cargo-progress-host.test.ts +0 -332
  347. package/src/executors/bounded-exec/cpu-pool.test.ts +0 -684
  348. package/src/executors/bounded-exec/cpu-tokens.test.ts +0 -519
  349. package/src/executors/bounded-exec/disk-lease.test.ts +0 -219
  350. package/src/executors/bounded-exec/executor-host.test.ts +0 -800
  351. package/src/executors/bounded-exec/executor.test.ts +0 -1819
  352. package/src/executors/bounded-exec/go-progress-host.test.ts +0 -171
  353. package/src/executors/bounded-exec/hang-diagnostics.test.ts +0 -291
  354. package/src/executors/bounded-exec/progress.test.ts +0 -139
  355. package/src/executors/bounded-exec/ram-temp-held.test.ts +0 -264
  356. package/src/executors/bounded-exec/ram-temp-host.test.ts +0 -635
  357. package/src/executors/bounded-exec/ram-temp.test.ts +0 -750
  358. package/src/executors/bounded-exec/run-cpu-pool.test.ts +0 -79
  359. package/src/executors/bounded-exec/runner-hook.test.ts +0 -193
  360. package/src/executors/bounded-exec/runner-lifecycle.test.ts +0 -82
  361. package/src/executors/bounded-exec/verdict.test.ts +0 -545
  362. package/src/executors/cargo-zigbuild/executor.test.ts +0 -129
  363. package/src/executors/clean-outputs/executor.test.ts +0 -20
  364. package/src/executors/typescript-emit/executor.test.ts +0 -83
  365. package/src/failure-summary.ts +0 -119
  366. package/src/generators/bounded-test-targets/generator.test.ts +0 -138
  367. package/src/generators/bun-test-tracing/generator.test.ts +0 -250
  368. package/src/generators/create-package/generator.test.ts +0 -190
  369. package/src/generators/make-public/generator.test.ts +0 -137
  370. package/src/graph-input-contract.test.ts +0 -379
  371. package/src/host-controller-wiring.test.ts +0 -31
  372. package/src/index.test.ts +0 -3321
  373. package/src/linked-snapshots.nx.test.ts +0 -254
  374. package/src/managed-files/forgejo-artifact.test.ts +0 -395
  375. package/src/managed-files/generator.test.ts +0 -243
  376. package/src/managed-files/github-host-cache-isolation.test.ts +0 -86
  377. package/src/managed-files/json-edit.test.ts +0 -216
  378. package/src/managed-files/managed-content.test.ts +0 -166
  379. package/src/managed-files/managed-format-json.test.ts +0 -308
  380. package/src/managed-files/repo-path.test.ts +0 -172
  381. package/src/managed-files/setup-devenv-free-disk.test.ts +0 -95
  382. package/src/managed-files/trace-db-artifact.test.ts +0 -7
  383. package/src/managed-files/tree-permissions.test.ts +0 -109
  384. package/src/managed-files/tree.test.ts +0 -123
  385. package/src/manifest-hash.test.ts +0 -219
  386. package/src/nextest-code-bound.test.ts +0 -161
  387. package/src/nextest-extraction.test.ts +0 -216
  388. package/src/nextest-extraction.ts +0 -371
  389. package/src/nextest-partitions.test.ts +0 -501
  390. package/src/nx-cache-bound.test.ts +0 -109
  391. package/src/nx-cache-restore-mtime.test.ts +0 -170
  392. package/src/nx-daemon-claim.test.ts +0 -279
  393. package/src/nx-daemon-idle-cpu.test.ts +0 -80
  394. package/src/nx-daemon-idle-policy.test.ts +0 -111
  395. package/src/nx-daemon-ignore-files.test.ts +0 -210
  396. package/src/nx-daemon-root-normalization.test.ts +0 -105
  397. package/src/nx-daemon-start-never.test.ts +0 -292
  398. package/src/nx-daemon-validity.test.ts +0 -1055
  399. package/src/nx-dot-input-policy.test.ts +0 -353
  400. package/src/nx-failure-life-cycles.test.ts +0 -207
  401. package/src/nx-files-archive-racy.test.ts +0 -97
  402. package/src/nx-foreign-workspace-env.test.ts +0 -329
  403. package/src/nx-incomplete-run-summary.test.ts +0 -70
  404. package/src/nx-plugin-load-errors.test.ts +0 -120
  405. package/src/nx-project-graph-errors.test.ts +0 -70
  406. package/src/nx-project-resolution-cache.test.ts +0 -176
  407. package/src/nx-raw-inputs.test.ts +0 -166
  408. package/src/nx-resident-graph-workers.test.ts +0 -112
  409. package/src/nx-run-information.test.ts +0 -118
  410. package/src/nx-skipped-task-exit.test.ts +0 -180
  411. package/src/nx-state-location.test.ts +0 -63
  412. package/src/nx-store-resolution.test.ts +0 -81
  413. package/src/nx-task-graph-cycles.test.ts +0 -148
  414. package/src/nx-task-output-lease.test.ts +0 -550
  415. package/src/nx-use-local.test.ts +0 -105
  416. package/src/owned-installation.test.ts +0 -105
  417. package/src/package-target-policy.test.ts +0 -1014
  418. package/src/producer-receipts.test.ts +0 -285
  419. package/src/release-config-policy.test.ts +0 -311
  420. package/src/runtime-input.test.ts +0 -393
  421. package/src/serial-group-wiring.test.ts +0 -326
  422. package/src/task-history-namespace.test.ts +0 -181
  423. package/src/task-results.test.ts +0 -228
  424. package/src/test-clock-policy.test.ts +0 -338
  425. package/src/test-program.test.ts +0 -303
  426. package/src/test-timings.test.ts +0 -240
  427. package/src/test-walk-policy.test.ts +0 -620
  428. package/src/testing.test.ts +0 -509
  429. package/src/typecheck-test-policy.test.ts +0 -1468
  430. package/src/typescript-resolution.test.ts +0 -76
  431. package/src/version-actions.test.ts +0 -80
  432. package/src/workspace-config-policy.test.ts +0 -737
package/dist/index.js CHANGED
@@ -3,34 +3,41 @@ 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
+ import { EXTRACTED_BINARIES_METADATA, EXTRACTED_CARGO_METADATA, EXTRACTED_TARGET_DIR, NEXTEST_ARCHIVE_KEY_SUFFIX, } from '@smoothbricks/nextest-extract';
6
7
  import { readJsonFile, } from 'nx/src/devkit-exports.js';
7
8
  import { AggregateCreateNodesError } from 'nx/src/project-graph/error-types.js';
8
9
  import { parse as parseToml } from 'smol-toml';
9
10
  import { parseJsonConfigFileContent, readConfigFile, sys as typescriptSys } from 'typescript';
10
11
  import { BOUNDED_TEST_IDLE_TIMEOUT_MS, BOUNDED_TEST_KILL_AFTER_MS } from './bounded-test-policy.js';
11
- import { CARGO_CLOSURE_INPUT, cargoClosureInputs, indexedCargoManifests, resolveCargoClosureSource, } from './cargo-closure-input.js';
12
- import { CARGO_TOOLCHAIN_NAMED_INPUT, CARGO_TOOLCHAIN_PIN_INPUTS, cargoRuntimeInput, } from './cargo-toolchain-policy.js';
13
- import { attributeCargoWorkspacePackages, CARGO_TEST_ARCHIVE_FILE, CARGO_TEST_ARCHIVE_TARGET, CARGO_TEST_COMPILE_TARGET, CARGO_TEST_EXCEPTIONS_SUFFIX, CARGO_TEST_TARGET, cargoPackageTestInputs, cargoTestGroupTargetName, cargoTestPackageTargetName, createCargoInputsCache, exceptionalTestFilter, listCargoCrossTestTargets, listCargoWorkspacePackages, NEXTEST_REPO_CONFIG_PATH, nextestToolConfigArg, PLUGIN_NEXTEST_CONFIG_PATH, serialTestGroups, } from './cargo-workspace.js';
12
+ import { refuseOverlappingOutputs } from './build-state-output-policy.js';
13
+ import { bunLockDependencies, bunLockInput, bunLockNode } from './bun-lock-scope.js';
14
+ import { CARGO_CLOSURE_INPUT, CARGO_LOCK_NODE_PREFIX, cargoClosureInputs, cargoLockNode, cargoLockNodeName, indexedCargoManifests, isCargoLockInput, resolveCargoClosureSource, } from './cargo-closure-input.js';
15
+ import { CARGO_PRODUCER_METADATA, postTasksExecution as postCargoRetention } from './cargo-retention-hook.js';
16
+ import { CARGO_TOOLCHAIN_NAMED_INPUT, cargoRuntimeInput, cargoToolchainInputs } from './cargo-toolchain-policy.js';
17
+ import { attributeCargoWorkspacePackages, CARGO_TEST_ARCHIVE_FILE, CARGO_TEST_ARCHIVE_TARGET, CARGO_TEST_EXCEPTIONS_SUFFIX, CARGO_TEST_TARGET, cargoPackageTestInputs, cargoTestGroupTargetName, cargoTestPackageTargetName, createCargoInputsCache, EXTERNAL_RUST_CRATES_INPUT, exceptionalTestFilter, listCargoCrossTestTargets, listCargoWorkspacePackages, NEXTEST_REPO_CONFIG_PATH, nextestToolConfigArg, PLUGIN_NEXTEST_CONFIG_PATH, requireExternalRustCratesInput, serialTestGroups, } from './cargo-workspace.js';
14
18
  import { CARGO_CROSS_LINT_COMMAND, CARGO_CROSS_LINT_TARGET, CARGO_FETCH_COMMAND, CARGO_FETCH_TARGET, CARGO_LINT_CLIPPY_COMMAND, cargoCrossTestArchiveFile, cargoCrossTestArchiveTargetName, cargoCrossTestTargetName, cargoFrozen, runsFrozenCargo, } from './cross-check-policy.js';
19
+ import { eslintConfigClosure } from './eslint-config-closure.js';
15
20
  import { ALL_VERDICTS_EXECUTOR } from './executors/all-verdicts/schema.js';
16
21
  import { closeRunCpuPool, serveRunCpuPool } from './executors/bounded-exec/run-cpu-pool.js';
22
+ import { ffiPathProblem } from './executors/scriptc-native/ffi-paths.js';
17
23
  import { hashVersionlessCrateManifests } from './manifest-hash.js';
18
- import { EXTRACTED_BINARIES_METADATA, EXTRACTED_CARGO_METADATA, EXTRACTED_TARGET_DIR, NEXTEST_EXTRACT_BIN, } from './nextest-extraction.js';
24
+ import { NEXTEST_TIMINGS_PATH, namedTestsFilter, readNextestTimings, timedShardMembers } from './nextest-timings.js';
19
25
  import { postTasksExecution as postProducerReceipts, preTasksExecution as preProducerReceipts, } from './producer-receipts.js';
20
26
  import { runtimeInput, shellWord } from './runtime-input.js';
21
27
  import { isNonSourceDirectory } from './source-directories.js';
28
+ import { inferredTaskKind, refuseBuildTestDependencies } from './task-graph-policy.js';
22
29
  import { postTasksExecution as postTaskResults, preTasksExecution as preTaskResults } from './task-results.js';
23
30
  import { SHARD_TIMINGS_EXECUTOR, SHARD_TIMINGS_TARGET, timingsShardedSuite } from './test-timings.js';
24
31
  import { assertUpstreamBasePrecondition } from './test-walk-policy.js';
25
- import { isBuildOutputTargetName, isTestRunnerTargetName, PLATFORM_TARGET_GLOBS, RELEASE_CONFIGURATION, } from './workspace-config-policy.js';
32
+ import { nativeToolCommand, nativeToolDependsOn, resolveNativeTools } from './tool-bins.js';
33
+ import { isBuildOutputTargetName, isTestNamespaceTargetName, isTestRunnerTargetName, PLATFORM_TARGET_GLOBS, RELEASE_CONFIGURATION, } from './workspace-config-policy.js';
26
34
  import { globIndexedFiles } from './workspace-index.js';
27
- export { CARGO_TEST_COMPILE_TARGET };
28
35
  /** Makes a version live and proves it answers; never cached. */
29
36
  export const DEPLOY_TARGET = 'deploy';
30
37
  /** The purely file-derived half a deploy needs built first; cached. */
31
38
  export const DEPLOY_BUILD_TARGET = 'deploy-build';
32
- /** The workspace-wide manifests a release rewrites: the version of every member, and the lockfile mirror of it. */
33
- const RELEASE_REWRITTEN_WORKSPACE_INPUTS = ['{workspaceRoot}/package.json', '{workspaceRoot}/bun.lock'];
39
+ /** The workspace-wide manifest a release rewrites: the version of every member. */
40
+ const RELEASE_REWRITTEN_WORKSPACE_INPUTS = ['{workspaceRoot}/package.json'];
34
41
  /** Installed patch bytes and pins affect the compiler; Markdown explains them but is not loaded. */
35
42
  const TYPESCRIPT_PATCH_INPUTS = ['{workspaceRoot}/patches/**/*', '!{workspaceRoot}/patches/**/*.md'];
36
43
  /**
@@ -57,16 +64,16 @@ function typecheckCommand(args) {
57
64
  return `"\${${TYPECHECK_COMPILER_ENV}:?is unset, enter the devenv shell (devenv.smoo.nix builds the typecheck compiler)}" ${args}`;
58
65
  }
59
66
  /**
60
- * The two release-rewritten files hashed by field instead of by byte, for a
61
- * check that only reads them.
67
+ * The release-rewritten root manifest hashed by field instead of by byte, for
68
+ * a check that only reads it.
62
69
  *
63
70
  * A `json` input is hashed by Nx's own hasher, so this costs no process. The
64
- * lockfile's `workspaces` section is the mirror of each member's manifest —
65
- * name, version and dependency specifiers — and every one of those is already
66
- * hashed from the member's own `package.json`. Dropping that section keeps the
67
- * resolution table, which is the reason the lockfile is an input at all.
71
+ * lockfile is no file input at all: the packages it resolves reach a task as
72
+ * Nx's own lockfile nodes, the root manifest's through the bun root lock-scope
73
+ * node and the project's through its `^` input, so a release's rewrite of the
74
+ * lockfile's `workspaces` mirror re-keys nothing.
68
75
  *
69
- * The root manifest also drops `scripts`, `smoo` and `nx`. No lint or
76
+ * The root manifest drops `scripts`, `smoo` and `nx`. No lint or
70
77
  * typecheck reads them: `scripts` are commands a developer runs, `smoo` holds
71
78
  * the developer links whose linked bytes reach the hash only through their own
72
79
  * inputs, and the root project's `nx` configuration is hashed as that
@@ -77,7 +84,6 @@ function typecheckCommand(args) {
77
84
  */
78
85
  const VERSIONLESS_TOOLCHAIN_MANIFEST_INPUTS = [
79
86
  { json: '{workspaceRoot}/package.json', excludeFields: ['version', 'scripts', 'smoo', 'nx'] },
80
- { json: '{workspaceRoot}/bun.lock', excludeFields: ['workspaces'] },
81
87
  ];
82
88
  /** A path segment Nx's workspace file map never carries, so a fileset naming it hashes nothing. */
83
89
  const NODE_MODULES_SEGMENT = /(?:^|\/)node_modules(?:\/|$)/;
@@ -179,8 +185,8 @@ function resolveTypescriptConfigExtends(specifier, fromConfigPath) {
179
185
  * Nx hashes workspace files that are not in node_modules, so two ancestor
180
186
  * kinds cannot be named — and they are not the same thing:
181
187
  *
182
- * - a dependency's config: `bun.lock` and the root manifest decide which
183
- * bytes are installed, and both are already inputs. Where they sit is the
188
+ * - a dependency's config: the lockfile entry of the package that holds it
189
+ * decides which bytes are installed, and the task is keyed on it. Where they sit is the
184
190
  * installer's business — bun keeps them in a global store outside the
185
191
  * workspace entirely — so this is settled by HOW the specifier resolved,
186
192
  * not by where it landed. A workspace member reached through its package
@@ -221,6 +227,14 @@ const VERSIONLESS_PACKAGE_INPUTS = [
221
227
  '!{projectRoot}/package.json',
222
228
  { json: '{projectRoot}/package.json', excludeFields: ['version'] },
223
229
  ];
230
+ /**
231
+ * The root project owns the lockfiles, so its `default` fileset holds each
232
+ * whole, and a check keyed on it re-ran on every dependency change anywhere in
233
+ * the workspace. Its checks name what the lockfiles decide for it instead: the
234
+ * root manifest's bun lock-scope node and, for a root Cargo workspace, the
235
+ * Cargo nodes of its targets. No other project's fileset ever held them.
236
+ */
237
+ const ROOT_LOCKFILE_EXCLUSIONS = ['!{projectRoot}/bun.lock', '!{projectRoot}/bun.lockb', '!{projectRoot}/Cargo.lock'];
224
238
  /**
225
239
  * Crate manifests, for the projects that have any.
226
240
  *
@@ -257,8 +271,8 @@ const ESLINT_CONFIG_FILES = [
257
271
  /** Every JavaScript and TypeScript module kind ESLint is handed. */
258
272
  const ESLINT_SOURCES_GLOB = '**/*.{js,jsx,cjs,mjs,ts,tsx,cts,mts}';
259
273
  /**
260
- * The JavaScript and TypeScript files of Nx's workspace file index, listed once
261
- * per graph computation; `null` when no workspace ESLint config enables ESLint.
274
+ * The ESLint sources and config closure of Nx's workspace file index, listed
275
+ * once per graph computation; `null` when no workspace ESLint config enables ESLint.
262
276
  *
263
277
  * The ESLint file list is part of the lint target's command, metadata and
264
278
  * inputs, and Nx hashes the whole target configuration into every task that
@@ -268,11 +282,21 @@ const ESLINT_SOURCES_GLOB = '**/*.{js,jsx,cjs,mjs,ts,tsx,cts,mts}';
268
282
  * and a fresh fork's did not, which alone re-keyed 197 of 510 gate tasks.
269
283
  * Drawing the list from the index makes the plugin and the hasher agree on one
270
284
  * file set.
285
+ *
286
+ * The configs key every lint target with exactly the workspace files they
287
+ * load (eslint-config-closure.ts): a glob over the directory holding a
288
+ * config's rule modules keyed every file beside them, and one test fixture
289
+ * there re-keyed 44 lint targets in one land.
271
290
  */
272
- async function indexedEslintSources(workspaceRoot) {
273
- if (!ESLINT_CONFIG_FILES.some((name) => existsSync(join(workspaceRoot, name))))
291
+ async function eslintWorkspace(workspaceRoot) {
292
+ const configs = ESLINT_CONFIG_FILES.filter((name) => existsSync(join(workspaceRoot, name)));
293
+ if (configs.length === 0)
274
294
  return null;
275
- return new Set(await globIndexedFiles(workspaceRoot, [ESLINT_SOURCES_GLOB]));
295
+ const indexed = new Set(await globIndexedFiles(workspaceRoot, [ESLINT_SOURCES_GLOB, '**/*.json']));
296
+ return {
297
+ sources: new Set([...indexed].filter((path) => !path.endsWith('.json'))),
298
+ configImports: eslintConfigClosure(workspaceRoot, configs, indexed),
299
+ };
276
300
  }
277
301
  /**
278
302
  * Read a tsconfig with this plugin's own TypeScript. `@nx/js`'s readTsConfig does an
@@ -285,7 +309,7 @@ function readTestTsConfig(testConfig) {
285
309
  const readResult = readConfigFile(testConfig, typescriptSys.readFile);
286
310
  return parseJsonConfigFileContent(readResult.config, typescriptSys, dirname(testConfig));
287
311
  }
288
- function projectLintCommands(projectRoot, workspaceRoot, eslintSources) {
312
+ function projectLintCommands(projectRoot, workspaceRoot, eslint) {
289
313
  const commands = [];
290
314
  const inputs = [];
291
315
  let eslintFileSet = null;
@@ -294,10 +318,10 @@ function projectLintCommands(projectRoot, workspaceRoot, eslintSources) {
294
318
  if (BIOME_CONFIG_FILES.some((name) => existsSync(join(workspaceRoot, name)))) {
295
319
  commands.push(`biome check --files-ignore-unknown=true ${quote(projectRoot)}`);
296
320
  }
297
- if (eslintSources !== null) {
321
+ if (eslint !== null) {
298
322
  const sourcePrefix = projectRoot === '.' ? 'src/' : `${posix.normalize(projectRoot)}/src/`;
299
323
  const sourceFiles = new Set();
300
- for (const path of eslintSources) {
324
+ for (const path of eslint.sources) {
301
325
  if (path.startsWith(sourcePrefix) &&
302
326
  !path.slice(sourcePrefix.length).split('/').slice(0, -1).some(isNonSourceDirectory)) {
303
327
  sourceFiles.add(path);
@@ -321,7 +345,7 @@ function projectLintCommands(projectRoot, workspaceRoot, eslintSources) {
321
345
  }
322
346
  // Only a module Nx indexes is linted and keyed. An ignored one is build
323
347
  // output that a fresh checkout lacks; a JSON file is not ESLint's.
324
- if (!eslintSources.has(path) || path.split('/').some(isNonSourceDirectory))
348
+ if (!eslint.sources.has(path) || path.split('/').some(isNonSourceDirectory))
325
349
  continue;
326
350
  sourceFiles.add(path);
327
351
  inputs.push(`{workspaceRoot}/${path}`);
@@ -335,6 +359,11 @@ function projectLintCommands(projectRoot, workspaceRoot, eslintSources) {
335
359
  }
336
360
  return { commands, inputs: [...new Set(inputs)], eslintFileSet };
337
361
  }
362
+ /** A host's directory under a package's `dist/bin`, as `@smoothbricks/cowshed`'s launcher names it. */
363
+ const EXECUTABLE_PLATFORM_DIRECTORY = {
364
+ linux: { arm64: 'linux-arm64', x64: 'linux-x64' },
365
+ macos: { arm64: 'darwin-arm64', x64: 'darwin-x64' },
366
+ };
338
367
  function napiPlatform(platform, architecture) {
339
368
  const targetFamily = platform === 'darwin' ? 'macos' : platform === 'linux' ? 'linux' : null;
340
369
  const targetArchitecture = architecture === 'arm64' ? 'arm64' : architecture === 'x64' ? 'x64' : null;
@@ -380,7 +409,6 @@ const CARGO_WORKSPACE_PATTERN = /^\s*\[workspace\]/m;
380
409
  const CARGO_INPUTS = [
381
410
  '{projectRoot}/**/*.rs',
382
411
  '{projectRoot}/**/Cargo.toml',
383
- '{projectRoot}/**/Cargo.lock',
384
412
  '{projectRoot}/**/.cargo/config.toml',
385
413
  // Shell scripts a `.cargo/config.toml` points at — linker, runner, and rustc wrappers — decide
386
414
  // what the compiler produces as surely as the config naming them does. Tracking the config
@@ -395,14 +423,27 @@ const CARGO_INPUTS = [
395
423
  // step runs before the build), so every publish recompiled every native
396
424
  // binary on every platform for a change to a version string. What the N-API
397
425
  // build really reads is the package's `napi` block (binary name, targets) and
398
- // the `@napi-rs/cli` it runs; those are hashed as such by napiInputs().
426
+ // the `@napi-rs/cli` it runs; those are hashed as such by napiInputs(). The
427
+ // locked crates are each cached cargo target's lock-scope node (below).
399
428
  const CARGO_OUTPUT_INPUTS = CARGO_INPUTS;
429
+ /** The lockfiles of crates no resolved Cargo workspace claims, which have no lock-scope node. */
430
+ const UNRESOLVED_CARGO_LOCK_INPUT = '{projectRoot}/**/Cargo.lock';
431
+ /**
432
+ * What the uncached `cargo-fetch` reads: the manifests and the lock that name the crates, and the Cargo configuration
433
+ * that says where they come from. They key nothing; they are what a producer receipt binds the fetch to. Unnamed, Nx
434
+ * plans every file of the project, which for a repository-root project includes its symlinked managed files, and a
435
+ * receipt binds no symlink. That workspace's members belong to other projects, so its globs start at the repository root.
436
+ */
437
+ function cargoFetchInputs(projectRoot) {
438
+ const base = projectRoot === '.' ? '{workspaceRoot}' : '{projectRoot}';
439
+ return [`${base}/**/Cargo.toml`, `${base}/**/Cargo.lock`, `${base}/**/.cargo/config.toml`, `!${base}/**/target/**`];
440
+ }
400
441
  /** A full cargo-mutants sweep's wall-clock backstop: a sweep takes hours, and a hung one must still end. */
401
442
  const MUTATION_TIMEOUT_MS = 6 * 60 * 60 * 1000;
402
443
  // The toolchain half of a cargo task's identity lives in its own module
403
- // because `smoo monorepo validate` reads the same two constants to refuse a
404
- // declaration that drops it. See cargo-toolchain-policy.ts for why it is the
405
- // declared pin and not the ambient environment.
444
+ // because `smoo monorepo validate` reads the same entries to refuse a
445
+ // declaration that drops any of them. See cargo-toolchain-policy.ts for why it
446
+ // is the declared pin and the shell's declared programs, not the ambient environment.
406
447
  /** A runtime input that changes when the file's bytes do: the runtime hashes the file itself. */
407
448
  function fileHashInput(path) {
408
449
  return runtimeInput(`bun -e 'console.log(new Bun.CryptoHasher("sha256").update(require("node:fs").readFileSync(process.argv[1])).digest("hex"))' ${shellWord(path)}`);
@@ -434,14 +475,14 @@ function targetCommandText(target) {
434
475
  ].join('\n');
435
476
  }
436
477
  /**
437
- * The N-API build's inputs beyond the Cargo sources: the toolchain pin, the
438
- * package's `napi` block, which names the binary and the targets, and the
478
+ * The N-API build's inputs beyond the Cargo sources: the toolchain identity,
479
+ * the package's `napi` block, which names the binary and the targets, and the
439
480
  * resolved version of the npm package that drives the build (the napi CLI on
440
481
  * macOS; none on Linux, where devenv's zig and cargo-zigbuild are covered by
441
- * the pin). Neither the package version nor any other lockfile entry is part
482
+ * the identity). Neither the package version nor any other lockfile entry is part
442
483
  * of the artifact.
443
484
  *
444
- * The pin is stated here rather than inherited: neither `napi build` nor the
485
+ * The identity is stated here rather than inherited: neither `napi build` nor the
445
486
  * `cargo-zigbuild` executor spells `cargo --frozen`, which is how every other
446
487
  * cached cargo target acquires its toolchain identity. Without it a `.node`
447
488
  * linked against one toolchain hashed equal to the same sources linked against
@@ -455,7 +496,7 @@ function napiInputs(projectRoot, repoRooted, externalDependencies) {
455
496
  CARGO_CLOSURE_INPUT,
456
497
  '{projectRoot}/scripts/*.sh',
457
498
  ...(repoRooted ? ['{workspaceRoot}/scripts/*.sh'] : []),
458
- ...CARGO_TOOLCHAIN_PIN_INPUTS,
499
+ ...cargoToolchainInputs(),
459
500
  runtimeInput(`bun -e 'console.log(JSON.stringify(require(${JSON.stringify(packageJson)}).napi ?? null))'`),
460
501
  { externalDependencies: [...externalDependencies] },
461
502
  ];
@@ -493,6 +534,25 @@ const LINUX_GLIBC_FLOOR = '2.17';
493
534
  const CARGO_PROFILE_FLAG = { dev: '', release: ' --release' };
494
535
  /** The directory under `target/<triple>/` each profile writes. */
495
536
  const CARGO_PROFILE_OUTPUT_DIR = { dev: 'debug', release: 'release' };
537
+ /**
538
+ * Where a build that ships writes, per profile. Two directories, never one: Nx restores a task's outputs as a tree, so
539
+ * a dev and a release build that share a path replace each other's restore and neither is a cache hit again. A release
540
+ * build writes where its package ships it (`dist/`, which publishes wholesale); a dev build writes under `.cache/`,
541
+ * which no package publishes and no loader mistakes for a release artifact.
542
+ *
543
+ * The target states each profile's directory once, as its `outputDir` option. Its declared output reads that as
544
+ * `{options.outputDir}` (Nx resolves it against the options of the run's configuration) and its command as
545
+ * `{args.outputDir}` (`nx:run-commands` fills it from the same option), so neither holds a copy that could drift.
546
+ */
547
+ const OUTPUT_DIR_OPTION = '{options.outputDir}';
548
+ const OUTPUT_DIR_ARGUMENT = '{args.outputDir}';
549
+ /** Dev builds of N-API addons (one subdirectory per platform, beside `host`) and of wasm-bindgen's modules. */
550
+ const NATIVE_DEV_DIRECTORY = '.cache/native-dev';
551
+ const WASM_DEV_DIRECTORY = '.cache/wasm-dev';
552
+ /** An addon's directory per profile: `dist/native/<name>` ships, `.cache/native-dev/<name>` is for local builds. */
553
+ function nativeOutputPaths(name) {
554
+ return { dev: `${NATIVE_DEV_DIRECTORY}/${name}`, release: `dist/native/${name}` };
555
+ }
496
556
  /**
497
557
  * Cargo's default target directory for a crate, relative to the command's cwd:
498
558
  * `target/` beside the workspace root that owns the crate, or beside the
@@ -509,7 +569,7 @@ function cargoWasmTargetDirectory(projectRoot, config, repoRooted, cargoWorkspac
509
569
  return posix.relative(cwd, posix.join(owner, 'target'));
510
570
  }
511
571
  function createCargoWasmTarget(projectRoot, config, repoRooted, cargoTargetDirectory) {
512
- const outputDirectory = repoRooted ? posix.join(projectRoot, config.outputDirectory) : config.outputDirectory;
572
+ const outputDirectory = repoRooted ? posix.join(projectRoot, OUTPUT_DIR_ARGUMENT) : OUTPUT_DIR_ARGUMENT;
513
573
  const cargoSelection = repoRooted ? `-p ${config.cargoPackage}` : `--manifest-path ${config.manifestPath}`;
514
574
  const buildCommand = (profile) => sequence([
515
575
  cargoFrozen(`build${CARGO_PROFILE_FLAG[profile]} --target wasm32-unknown-unknown ${cargoSelection}`),
@@ -518,55 +578,20 @@ function createCargoWasmTarget(projectRoot, config, repoRooted, cargoTargetDirec
518
578
  ]);
519
579
  return {
520
580
  executor: 'nx:run-commands',
581
+ metadata: CARGO_PRODUCER_METADATA,
521
582
  cache: true,
522
583
  dependsOn: ['^build'],
523
584
  inputs: repoRooted
524
585
  ? [CARGO_CLOSURE_INPUT, '{workspaceRoot}/scripts/*.sh', '{projectRoot}/scripts/*.sh']
525
586
  : CARGO_OUTPUT_INPUTS,
526
- outputs: [`{projectRoot}/${config.outputDirectory}`],
587
+ outputs: [`{projectRoot}/${OUTPUT_DIR_OPTION}/`],
527
588
  options: {
528
589
  command: buildCommand('dev'),
529
590
  cwd: repoRooted ? '.' : projectRoot,
591
+ outputDir: WASM_DEV_DIRECTORY,
530
592
  },
531
- configurations: { [RELEASE_CONFIGURATION]: { command: buildCommand('release') } },
532
- };
533
- }
534
- /**
535
- * Compilation is excluded from the bounded test window: a cold Cargo
536
- * workspace can take many minutes to compile while still making progress,
537
- * which is not a property of the tests. `cargo test --no-run` pays that cost
538
- * in its own unbounded target. Cargo reuses incremental compilation locally;
539
- * Nx cannot cache this warming action without restoring shared mutable state.
540
- *
541
- * Cargo flocks one `target/` per invocation and owns that lock: a second cargo
542
- * process on the same directory waits inside cargo ("Blocking waiting for file
543
- * lock"). Inference adds no edge to keep writers apart — an edge says one
544
- * target consumes another's output, and none of these do. These are unbounded
545
- * `nx:run-commands` targets, so a wait is not charged against a test budget.
546
- *
547
- * Clippy runs ONCE over the whole workspace, in that same `target/`, rather
548
- * than once per crate. Clippy of a crate is a check build of its whole
549
- * closure, so 49 crates meant 49 closure rebuilds and 11 GiB of target
550
- * directories on one repository, and no per-crate cache hit ever repaid that.
551
- * Sharing the build's directory costs nothing: cargo's own lock serializes
552
- * the invocations that use it, and the host units a dev build compiled are
553
- * reused instead of compiled again.
554
- *
555
- * Tests compile the dev profile only, so no test target carries a
556
- * RELEASE_CONFIGURATION: Nx forwards a run's configuration down every
557
- * `dependsOn` edge to each target that has it, and a release `build` must
558
- * warm the dev test binaries the test run will use, not release ones nobody
559
- * runs.
560
- */
561
- function createCargoTestCompileTarget(projectRoot) {
562
- return {
563
- executor: 'nx:run-commands',
564
- cache: false,
565
- inputs: CARGO_INPUTS,
566
- outputs: [],
567
- options: {
568
- command: cargoFrozen('test --workspace --no-run'),
569
- cwd: projectRoot,
593
+ configurations: {
594
+ [RELEASE_CONFIGURATION]: { command: buildCommand('release'), outputDir: config.outputDirectory },
570
595
  },
571
596
  };
572
597
  }
@@ -582,23 +607,44 @@ function createCargoTestCompileTarget(projectRoot) {
582
607
  * entirely — the runners execute one extraction of it and never write cargo's
583
608
  * `target/` build tree — which is what lets the runners fan out.
584
609
  *
585
- * Cached, unlike `cargo-test-compile`, because it produces a VALUE: one file,
586
- * not a mutable build tree Nx would have to restore. `--workspace` matches the
587
- * clippy selection exactly, so both gates unify features the same way.
610
+ * It is also the step that keeps compilation out of the bounded test window: a
611
+ * cold workspace can take many minutes to compile while still making progress,
612
+ * which is not a property of the tests, and the runners start after it. It is
613
+ * test work, so no `build` depends on it (a build never consumes test binaries)
614
+ * and each target that executes them names the edge itself. There is no separate
615
+ * uncached `cargo test --no-run` warm-up: it compiled the same dev units a
616
+ * second time, queued on the same `target/` lock.
617
+ *
618
+ * Cached because it produces a VALUE: one file, not a mutable build tree Nx
619
+ * would have to restore. `--workspace` matches the clippy selection exactly, so
620
+ * both gates unify features the same way.
621
+ *
622
+ * Tests compile the dev profile only, so no test target carries a
623
+ * RELEASE_CONFIGURATION: Nx forwards a run's configuration down every
624
+ * `dependsOn` edge to each target that has it, and a release configuration
625
+ * must never turn the test binaries into release ones nobody runs.
588
626
  *
589
627
  * The directory and the archive are ONE command: nextest does not create the
590
628
  * archive's parent, so the archive step consumes what the `mkdir` produced.
629
+ * The same command writes the task's hash beside the archive, the key every
630
+ * runner's extraction is looked up by (smoo-nx-nextest-extract), and declares it
631
+ * an output, so a cache hit restores the key with the archive it names.
591
632
  */
633
+ const CARGO_TEST_ARCHIVE_KEY_FILE = `${CARGO_TEST_ARCHIVE_FILE}${NEXTEST_ARCHIVE_KEY_SUFFIX}`;
592
634
  function createCargoTestArchiveTarget(projectRoot, toolConfig) {
593
635
  return {
594
636
  executor: 'nx:run-commands',
637
+ metadata: CARGO_PRODUCER_METADATA,
595
638
  cache: true,
596
639
  inputs: CARGO_INPUTS,
597
- outputs: [`{projectRoot}/${CARGO_TEST_ARCHIVE_FILE}`],
640
+ outputs: [`{projectRoot}/${CARGO_TEST_ARCHIVE_FILE}`, `{projectRoot}/${CARGO_TEST_ARCHIVE_KEY_FILE}`],
598
641
  options: {
599
642
  command: sequence([
600
643
  `mkdir -p ${posix.dirname(CARGO_TEST_ARCHIVE_FILE)}`,
601
644
  cargoFrozen(`nextest archive --workspace --archive-file ${CARGO_TEST_ARCHIVE_FILE} --user-config-file none ${toolConfig}`),
645
+ // Outside Nx there is no task hash, and an archive no task names is refused here, not by every runner.
646
+ 'test -n "$NX_TASK_HASH"',
647
+ `printf '%s\\n' "$NX_TASK_HASH" > ${CARGO_TEST_ARCHIVE_KEY_FILE}`,
602
648
  ]),
603
649
  cwd: projectRoot,
604
650
  },
@@ -634,7 +680,7 @@ function createCargoTestArchiveTarget(projectRoot, toolConfig) {
634
680
  * target that needs no cargo: `nextest run --archive-file` extracts prebuilt
635
681
  * binaries and never invokes cargo (measured, zero invocations).
636
682
  */
637
- function createCargoCrossTestTargets(projectRoot, toolConfig, crossTarget, archiveInputs) {
683
+ function createCargoCrossTestTargets(projectRoot, toolConfig, crossTarget, archiveInputs, pluginInstalled) {
638
684
  const { target: triple, cargo } = crossTarget;
639
685
  const archiveFile = cargoCrossTestArchiveFile(triple);
640
686
  const archiveCommand = sequence([
@@ -646,6 +692,7 @@ function createCargoCrossTestTargets(projectRoot, toolConfig, crossTarget, archi
646
692
  return {
647
693
  [cargoCrossTestArchiveTargetName(triple)]: {
648
694
  executor: archiveExecutor,
695
+ metadata: CARGO_PRODUCER_METADATA,
649
696
  cache: true,
650
697
  // The toolchain inputs every cached cargo target carries, plus the
651
698
  // declared driver's own bytes. Those toolchain inputs are attached
@@ -660,10 +707,14 @@ function createCargoCrossTestTargets(projectRoot, toolConfig, crossTarget, archi
660
707
  // the cross profile. For the same reason it names its npm packages here.
661
708
  inputs: [
662
709
  ...archiveInputs,
663
- ...CARGO_TOOLCHAIN_PIN_INPUTS,
710
+ ...cargoToolchainInputs(),
664
711
  ...(cargo === undefined ? [] : [`{projectRoot}/${cargo}`]),
665
712
  cargoRuntimeInput(projectRoot, 'rustc -vV && cargo -V && cargo nextest --version'),
666
- { externalDependencies: cargoCommandNpmPackages({ executor: archiveExecutor }, archiveCommand) },
713
+ {
714
+ externalDependencies: cargoCommandNpmPackages({ executor: archiveExecutor }, archiveCommand, pluginInstalled),
715
+ },
716
+ // The Cargo.lock entries the whole workspace reaches, for the same reason.
717
+ { externalDependencies: [cargoLockNodeName(projectRoot)] },
667
718
  ],
668
719
  outputs: [`{projectRoot}/${archiveFile}`],
669
720
  dependsOn: [CARGO_FETCH_TARGET],
@@ -698,9 +749,10 @@ function createCargoCrossTestTargets(projectRoot, toolConfig, crossTarget, archi
698
749
  function createCargoTestTarget(projectRoot) {
699
750
  return {
700
751
  executor: '@smoothbricks/nx-plugin:bounded-exec',
752
+ metadata: CARGO_PRODUCER_METADATA,
701
753
  cache: true,
702
754
  inputs: CARGO_INPUTS,
703
- dependsOn: [CARGO_TEST_COMPILE_TARGET],
755
+ dependsOn: [CARGO_TEST_ARCHIVE_TARGET],
704
756
  options: {
705
757
  command: cargoFrozen('test --workspace'),
706
758
  cwd: projectRoot,
@@ -717,13 +769,46 @@ const PLUGIN_NEXTEST_CONFIG = fileURLToPath(new URL('../nextest.toml', import.me
717
769
  const PLUGIN_NEXTEST_CODE_BOUND = fileURLToPath(new URL('../src/nextest-code-bound.ts', import.meta.url));
718
770
  const PLUGIN_PACKAGE = '@smoothbricks/nx-plugin';
719
771
  /**
720
- * Whether this plugin runs as an installed npm package. Inside the repository
721
- * that develops it, it is a workspace project, and Nx refuses a workspace
722
- * project named as an `externalDependencies` entry.
772
+ * Whether this plugin's code was loaded from an installed npm package: a path
773
+ * through `node_modules`. Not enough alone to name it as an
774
+ * `externalDependencies` entry ({@link pluginInstalledIn}).
723
775
  */
724
- const PLUGIN_IS_INSTALLED = fileURLToPath(new URL('..', import.meta.url))
776
+ const PLUGIN_LOADED_FROM_NODE_MODULES = fileURLToPath(new URL('..', import.meta.url))
725
777
  .split(sep)
726
778
  .includes('node_modules');
779
+ const workspaceProjectPlugins = new Map();
780
+ /**
781
+ * Whether the workspace at `workspaceRoot` runs this plugin as an installed npm package, whose lockfile node an
782
+ * `externalDependencies` entry can name. In the repository that develops it the plugin is a workspace project: the
783
+ * workspace's own `node_modules/@smoothbricks/nx-plugin` resolves to a directory of the workspace outside every
784
+ * `node_modules`, and Nx refuses a workspace project named as an `externalDependencies` entry ("could not be
785
+ * found"), whatever path this process loaded the plugin's code through. A daemon of that repository did load it
786
+ * through one with `node_modules` in it, and every cargo target it inferred afterwards named the plugin, so a gate
787
+ * refused the graph.
788
+ */
789
+ export function pluginInstalledIn(workspaceRoot, loadedFromNodeModules = PLUGIN_LOADED_FROM_NODE_MODULES) {
790
+ if (!loadedFromNodeModules)
791
+ return false;
792
+ let workspaceProject = workspaceProjectPlugins.get(workspaceRoot);
793
+ if (workspaceProject === undefined) {
794
+ let linked = null;
795
+ try {
796
+ linked = relative(realpathSync(workspaceRoot), realpathSync(join(workspaceRoot, 'node_modules', PLUGIN_PACKAGE)));
797
+ }
798
+ catch {
799
+ // No such package in the workspace: whatever runs the plugin, it is not a project of this workspace.
800
+ }
801
+ workspaceProject =
802
+ linked !== null &&
803
+ linked !== '' &&
804
+ !isAbsolute(linked) &&
805
+ linked !== '..' &&
806
+ !linked.startsWith(`..${sep}`) &&
807
+ !linked.split(sep).includes('node_modules');
808
+ workspaceProjectPlugins.set(workspaceRoot, workspaceProject);
809
+ }
810
+ return !workspaceProject;
811
+ }
727
812
  /**
728
813
  * The npm packages a cached cargo target runs, for its `externalDependencies`.
729
814
  * Cargo runs none. A target this plugin's executor runs, or whose command reads
@@ -732,7 +817,7 @@ const PLUGIN_IS_INSTALLED = fileURLToPath(new URL('..', import.meta.url))
732
817
  * executor is not an `@nx/` one on every package in the lockfile, so a
733
818
  * lockfile-only commit re-ran every cargo verdict.
734
819
  */
735
- export function cargoCommandNpmPackages(target, commandText, installed = PLUGIN_IS_INSTALLED) {
820
+ export function cargoCommandNpmPackages(target, commandText, installed) {
736
821
  const runsPlugin = target.executor?.startsWith(`${PLUGIN_PACKAGE}:`) === true ||
737
822
  commandText.includes(`node_modules/${PLUGIN_PACKAGE}/`);
738
823
  return installed && runsPlugin ? [PLUGIN_PACKAGE] : [];
@@ -782,10 +867,15 @@ function createNodesHandler(hostPlatform) {
782
867
  const results = [];
783
868
  const errors = [];
784
869
  let cargoWorkspaces;
785
- let eslintSources;
870
+ let eslint;
871
+ let nativeTools;
786
872
  try {
787
873
  cargoWorkspaces = await resolveCargoWorkspaces(projectConfigurationFiles, context.workspaceRoot, hostPlatform);
788
- eslintSources = await indexedEslintSources(context.workspaceRoot);
874
+ eslint = await eslintWorkspace(context.workspaceRoot);
875
+ nativeTools =
876
+ hostPlatform === null
877
+ ? null
878
+ : await resolveNativeTools(context.workspaceRoot, projectConfigurationFiles, EXECUTABLE_PLATFORM_DIRECTORY[hostPlatform.targetFamily][hostPlatform.architecture], scriptcTargetName(hostPlatform));
789
879
  }
790
880
  catch (error) {
791
881
  throw new AggregateCreateNodesError([[null, error instanceof Error ? error : new Error(String(error))]], results);
@@ -805,7 +895,7 @@ function createNodesHandler(hostPlatform) {
805
895
  }
806
896
  results.push([
807
897
  packageJsonPath,
808
- await createProjectTargets(packageJsonPath, context.workspaceRoot, hostPlatform, cargoWorkspaces, eslintSources, versionless),
898
+ await createProjectTargets(packageJsonPath, context.workspaceRoot, hostPlatform, nativeTools, cargoWorkspaces, eslint, versionless),
809
899
  ]);
810
900
  }
811
901
  catch (error) {
@@ -839,8 +929,9 @@ function isBuildOutputPackageJson(packageJsonPath) {
839
929
  * Nx accepts one pre/post task-hook pair per plugin. Two independent observers share it: the controller's task-results
840
930
  * hint and the opt-in producer completion receipts. Each sees the same options and run context; neither reads the
841
931
  * other's output. The hint is recorded first so a producer-receipt bug cannot cost the controller its evidence. The
842
- * pair also serves a run on a host without a gateway its own CPU pool, which every task inherits
843
- * (`run-cpu-pool.ts`), and closes it when the run ends.
932
+ * pair also serves a run that inherits no CPU pool its own, which every task inherits (`run-cpu-pool.ts`), and closes
933
+ * it when the run ends. Last, once every task has finished, the post hook reclaims the
934
+ * superseded Cargo unit generations of each Cargo workspace the run built into (`@smoothbricks/cargo-retain`).
844
935
  */
845
936
  export const preTasksExecution = async (options, context) => {
846
937
  // Before any task is hashed: a workspace that declares the test-walk check
@@ -854,29 +945,220 @@ export const postTasksExecution = async (options, context) => {
854
945
  await postTaskResults(options, context);
855
946
  await postProducerReceipts(options, context);
856
947
  await closeRunCpuPool(context);
948
+ await postCargoRetention(options, context);
857
949
  };
858
- export default { createNodesV2, postTasksExecution, preTasksExecution };
950
+ /** The lock-scope nodes' edges: each bun node's to the packages and members its manifest resolves. */
951
+ export const createDependencies = (_options, context) => bunLockDependencies(context);
952
+ /** Nx invokes this only after merging inferred/declarative targets and every plugin's project dependencies. */
953
+ export const createMetadata = (graph, _options, context) => {
954
+ refuseOverlappingOutputs(graph, context.workspaceRoot);
955
+ refuseBuildTestDependencies(graph, context.workspaceRoot);
956
+ return {};
957
+ };
958
+ export default { createNodesV2, createDependencies, createMetadata, postTasksExecution, preTasksExecution };
859
959
  function packageBinOutputs(packageJson, packageJsonPath) {
960
+ return [...new Set(packageBinEntries(packageJson, packageJsonPath).values())];
961
+ }
962
+ /** `package.json#bin` as npm links it: each command's name and executable path; a lone path is the unscoped package's. */
963
+ function packageBinEntries(packageJson, packageJsonPath) {
860
964
  if (packageJson.bin === undefined) {
861
- return [];
965
+ return new Map();
862
966
  }
863
967
  if (typeof packageJson.bin === 'string') {
864
968
  if (packageJson.bin.length === 0) {
865
969
  throw new Error(`${packageJsonPath}: bin must not be empty`);
866
970
  }
867
- return [packageJson.bin];
971
+ return new Map([[(packageJson.name ?? '').replace(/^@[^/]*\//, ''), packageJson.bin]]);
868
972
  }
869
973
  if (!isRecord(packageJson.bin)) {
870
974
  throw new Error(`${packageJsonPath}: bin must be a string or an object of executable paths`);
871
975
  }
872
- const outputs = new Set();
976
+ const entries = new Map();
873
977
  for (const [name, output] of Object.entries(packageJson.bin)) {
874
978
  if (typeof output !== 'string' || output.length === 0) {
875
979
  throw new Error(`${packageJsonPath}: bin.${name} must be a non-empty executable path`);
876
980
  }
877
- outputs.add(output);
981
+ entries.set(name, output);
982
+ }
983
+ return entries;
984
+ }
985
+ /** Resolve declared bins and optional package-root-relative native overrides to emit-root-relative modules. */
986
+ export function scriptcBinModules(bins, scriptc, packageJsonPath, javascriptRoot) {
987
+ const modulePath = (name, entry, field) => {
988
+ const emitted = posix.normalize(entry);
989
+ if (!/^[\w.-]+$/.test(name) || !emitted.startsWith(`${javascriptRoot}/`) || !emitted.endsWith('.js')) {
990
+ throw new Error(`${packageJsonPath}: ${field} must name JavaScript tsc-js emits under ${javascriptRoot}/ (it is ${entry})`);
991
+ }
992
+ return emitted.slice(javascriptRoot.length + 1);
993
+ };
994
+ const modules = Object.fromEntries(bins);
995
+ for (const [name, entry] of bins) {
996
+ modules[name] = modulePath(name, entry, `bin.${name}`);
997
+ }
998
+ if (scriptc === undefined)
999
+ return modules;
1000
+ if (!isRecord(scriptc) || Array.isArray(scriptc)) {
1001
+ throw new Error(`${packageJsonPath}: scriptc must be an object`);
1002
+ }
1003
+ const overrides = scriptc.entries;
1004
+ if (overrides === undefined)
1005
+ return modules;
1006
+ if (!isRecord(overrides) || Array.isArray(overrides)) {
1007
+ throw new Error(`${packageJsonPath}: scriptc.entries must be an object mapping declared bin names to module paths`);
1008
+ }
1009
+ for (const [name, entry] of Object.entries(overrides)) {
1010
+ if (!bins.has(name)) {
1011
+ throw new Error(`${packageJsonPath}: scriptc.entries.${name} is not declared in bin; entries cannot add executables`);
1012
+ }
1013
+ if (typeof entry !== 'string' || entry.length === 0) {
1014
+ throw new Error(`${packageJsonPath}: scriptc.entries.${name} must be a non-empty module path`);
1015
+ }
1016
+ modules[name] = modulePath(name, entry, `scriptc.entries.${name}`);
878
1017
  }
879
- return [...outputs];
1018
+ return modules;
1019
+ }
1020
+ /**
1021
+ * Every platform a scriptc package ships an executable for, with the triple `SCRIPTC_TARGET` names for it and the
1022
+ * runtime pack scriptc links that triple against. Linux executables are static musl, as cowshed's CLI is, so one file
1023
+ * runs on every distribution.
1024
+ */
1025
+ const SCRIPTC_PLATFORMS = [
1026
+ {
1027
+ architecture: 'arm64',
1028
+ targetFamily: 'macos',
1029
+ triple: 'aarch64-macos',
1030
+ runtimePack: '@scriptc/runtime-darwin-arm64',
1031
+ },
1032
+ { architecture: 'x64', targetFamily: 'macos', triple: 'x86_64-macos', runtimePack: '@scriptc/runtime-darwin-x64' },
1033
+ {
1034
+ architecture: 'arm64',
1035
+ targetFamily: 'linux',
1036
+ triple: 'aarch64-linux-musl',
1037
+ runtimePack: '@scriptc/runtime-linux-arm64-musl',
1038
+ },
1039
+ {
1040
+ architecture: 'x64',
1041
+ targetFamily: 'linux',
1042
+ triple: 'x86_64-linux-musl',
1043
+ runtimePack: '@scriptc/runtime-linux-x64-musl',
1044
+ },
1045
+ ];
1046
+ /**
1047
+ * `package.json#scriptc.ffi`: the C a package's executables call through scriptc's FFI, which every platform run stages
1048
+ * beside the emitted JavaScript and builds for its triple. Absent for a package that calls no C.
1049
+ */
1050
+ function scriptcFfi(packageJson, packageJsonPath) {
1051
+ if (packageJson.scriptc === undefined || (isRecord(packageJson.scriptc) && packageJson.scriptc.ffi === undefined)) {
1052
+ return undefined;
1053
+ }
1054
+ const refusal = (what) => new Error(`${packageJsonPath}: scriptc.ffi ${what}; it is { "manifest": "<ffi.json>", "declarations": ` +
1055
+ '{ "<source .d.ts>": "<path beside the emitted JavaScript>" }, "sources": ["<C file>"] }');
1056
+ const ffi = isRecord(packageJson.scriptc) ? packageJson.scriptc.ffi : undefined;
1057
+ if (!isRecord(ffi)) {
1058
+ throw refusal('must be an object');
1059
+ }
1060
+ const { manifest, declarations, sources } = ffi;
1061
+ if (typeof manifest !== 'string' || manifest.length === 0) {
1062
+ throw refusal('needs a manifest path');
1063
+ }
1064
+ if (!isRecord(declarations)) {
1065
+ throw refusal('needs declarations mapping each source file to its staged path');
1066
+ }
1067
+ const staged = {};
1068
+ for (const [source, destination] of Object.entries(declarations)) {
1069
+ if (typeof destination !== 'string') {
1070
+ throw refusal(`needs declarations mapping each source file to its staged path (${source} is not)`);
1071
+ }
1072
+ staged[source] = destination;
1073
+ }
1074
+ if (!Array.isArray(sources)) {
1075
+ throw refusal('needs sources, a list of C files');
1076
+ }
1077
+ const files = [];
1078
+ for (const source of sources) {
1079
+ if (typeof source !== 'string') {
1080
+ throw refusal('needs sources, a list of C files');
1081
+ }
1082
+ files.push(source);
1083
+ }
1084
+ const declared = { manifest, declarations: staged, sources: files };
1085
+ const problem = ffiPathProblem(declared);
1086
+ if (problem !== undefined) {
1087
+ throw refusal(problem);
1088
+ }
1089
+ return declared;
1090
+ }
1091
+ /** The files a target's FFI is built from: change one and every platform's executable is stale. */
1092
+ function scriptcFfiInputs(ffi) {
1093
+ return ffi === undefined
1094
+ ? []
1095
+ : [ffi.manifest, ...Object.keys(ffi.declarations), ...ffi.sources].map((path) => `{projectRoot}/${path}`);
1096
+ }
1097
+ /** The scriptc target writing `platform`'s executables; its suffix is the platform family the publish legs select. */
1098
+ function scriptcTargetName(platform) {
1099
+ return `scriptc-${platform.architecture}-${platform.targetFamily}`;
1100
+ }
1101
+ /**
1102
+ * `scriptc-<arch>-<family>`, one per platform in SCRIPTC_PLATFORMS: each `package.json#bin` entry compiled by scriptc
1103
+ * to the executable `dist/bin/<platform>/<name>`, from the transformed JavaScript the run itself emits from
1104
+ * `tsconfig.lib.json` into private staging, never from `tsc-js`'s output: a platform target's closure stays in its
1105
+ * family (package-target-policy.ts) and the four are collected on different hosts, so none depends on a sibling or
1106
+ * shares an output with another. A package opts in by depending on `scriptc`, which also pins the compiler the targets
1107
+ * run, and lists each platform's runtime pack at that same version. Every host builds every platform the same way,
1108
+ * `SCRIPTC_TARGET=<triple>` with zig as the C compiler, so a target's output does not depend on the host that built
1109
+ * it, and like every platform target the host's own joins `build` while the publish legs build the rest. The bins
1110
+ * name JavaScript below `dist/` beside `bin/` (`dist/ts`), so `tsc-js`'s output and the executables are disjoint.
1111
+ */
1112
+ function scriptcPlatformTargets(packageJson, packageJsonPath, projectRoot, libTsconfigPath, toolchainInputs) {
1113
+ const compiler = packageJson.devDependencies?.scriptc;
1114
+ if (compiler === undefined) {
1115
+ return {};
1116
+ }
1117
+ const missingPacks = SCRIPTC_PLATFORMS.filter((platform) => packageJson.devDependencies?.[platform.runtimePack] !== compiler).map((platform) => `${platform.runtimePack}@${String(compiler)}`);
1118
+ if (missingPacks.length > 0) {
1119
+ throw new Error(`${packageJsonPath}: a scriptc package builds every platform's executable, each linked against its runtime pack at ` +
1120
+ `the compiler's version; list ${missingPacks.join(', ')} in devDependencies beside scriptc`);
1121
+ }
1122
+ const javascriptRoot = typescriptOutDir(libTsconfigPath, packageJsonPath);
1123
+ const [outputRoot, below] = javascriptRoot?.split('/') ?? [];
1124
+ if (javascriptRoot === null || outputRoot !== 'dist' || below === undefined || below === 'bin') {
1125
+ throw new Error(`${packageJsonPath}: a scriptc package emits its JavaScript below dist/ beside dist/bin; ` +
1126
+ `set tsconfig.lib.json compilerOptions.outDir to "dist/ts" (it is ${JSON.stringify(javascriptRoot)})`);
1127
+ }
1128
+ const entries = packageBinEntries(packageJson, packageJsonPath);
1129
+ if (entries.size === 0) {
1130
+ throw new Error(`${packageJsonPath}: a scriptc package names the executables it compiles in bin`);
1131
+ }
1132
+ const modules = scriptcBinModules(entries, packageJson.scriptc, packageJsonPath, javascriptRoot);
1133
+ const ffi = scriptcFfi(packageJson, packageJsonPath);
1134
+ const targets = {};
1135
+ for (const platform of SCRIPTC_PLATFORMS) {
1136
+ const outputDirectory = `dist/bin/${EXECUTABLE_PLATFORM_DIRECTORY[platform.targetFamily][platform.architecture]}`;
1137
+ targets[scriptcTargetName(platform)] = {
1138
+ executor: '@smoothbricks/nx-plugin:scriptc-native',
1139
+ cache: true,
1140
+ inputs: [
1141
+ 'production',
1142
+ '^production',
1143
+ ...toolchainInputs,
1144
+ '{projectRoot}/tsconfig.lib.json',
1145
+ { externalDependencies: ['scriptc', platform.runtimePack] },
1146
+ ...scriptcFfiInputs(ffi),
1147
+ ],
1148
+ outputs: [...entries.keys()].map((name) => `{projectRoot}/${outputDirectory}/${name}`),
1149
+ // The emit type-checks against its dependencies' emitted JavaScript, as tsc-js does.
1150
+ dependsOn: ['^*-js'],
1151
+ options: {
1152
+ cwd: projectRoot,
1153
+ tsConfig: 'tsconfig.lib.json',
1154
+ triple: platform.triple,
1155
+ outputDirectory,
1156
+ entries: modules,
1157
+ ...(ffi === undefined ? {} : { ffi }),
1158
+ },
1159
+ };
1160
+ }
1161
+ return targets;
880
1162
  }
881
1163
  /**
882
1164
  * The deployment manifests wrangler itself looks for, in its own precedence
@@ -917,7 +1199,7 @@ const WRANGLER_CONFIG_FILES = ['wrangler.jsonc', 'wrangler.json', 'wrangler.toml
917
1199
  * `--stage` refuses it, which is the failure we want at the boundary.
918
1200
  */
919
1201
  const WRANGLER_DEPLOY_COMMAND = 'smoo wrangler deploy-stage --stage {args.stage}';
920
- async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform, cargoWorkspaces, eslintSources, versionless) {
1202
+ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform, nativeTools, cargoWorkspaces, eslint, versionless) {
921
1203
  const projectRoot = dirname(packageJsonPath);
922
1204
  const absoluteProjectRoot = join(workspaceRoot, projectRoot);
923
1205
  const packageJson = await readPackageJson(join(workspaceRoot, packageJsonPath));
@@ -947,15 +1229,27 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
947
1229
  // transitive half `^production`.
948
1230
  const hasCrateManifests = isCargoProject || existsSync(cargoTomlPath);
949
1231
  const crateInputs = versionless !== null && hasCrateManifests ? await versionlessCrateInputs(projectRoot, workspaceRoot) : [];
950
- const versionlessProjectInputs = versionless === null ? [] : [...VERSIONLESS_PACKAGE_INPUTS, ...crateInputs];
1232
+ const versionlessProjectInputs = versionless === null
1233
+ ? []
1234
+ : [...VERSIONLESS_PACKAGE_INPUTS, ...crateInputs, ...(projectRoot === '.' ? ROOT_LOCKFILE_EXCLUSIONS : [])];
951
1235
  // The options a TypeScript task's answer really depends on, which is the
952
1236
  // whole `extends` chain of the configs its commands name and not just those
953
1237
  // two files. Resolved once per project: every target below shares it.
954
1238
  const typescriptConfigChain = typescriptConfigChainInputs([...(hasLibTsconfig ? [libTsconfigPath] : []), ...(hasTestTsconfig ? [testTsconfigPath] : [])], workspaceRoot);
955
- const toolchainInputs = [...RELEASE_REWRITTEN_WORKSPACE_INPUTS, ...TYPESCRIPT_PATCH_INPUTS, ...typescriptConfigChain];
1239
+ const toolchainInputs = [
1240
+ ...RELEASE_REWRITTEN_WORKSPACE_INPUTS,
1241
+ bunLockInput(projectRoot),
1242
+ ...TYPESCRIPT_PATCH_INPUTS,
1243
+ ...typescriptConfigChain,
1244
+ ];
956
1245
  const checkInputs = versionless === null
957
1246
  ? toolchainInputs
958
- : [...TYPESCRIPT_PATCH_INPUTS, ...typescriptConfigChain, ...VERSIONLESS_TOOLCHAIN_MANIFEST_INPUTS];
1247
+ : [
1248
+ ...TYPESCRIPT_PATCH_INPUTS,
1249
+ ...typescriptConfigChain,
1250
+ ...VERSIONLESS_TOOLCHAIN_MANIFEST_INPUTS,
1251
+ bunLockInput(projectRoot),
1252
+ ];
959
1253
  const selfProduction = versionless === null ? 'production' : VERSIONLESS_PRODUCTION_INPUT;
960
1254
  const selfDefault = versionless === null ? 'default' : VERSIONLESS_DEFAULT_INPUT;
961
1255
  const dependencyProduction = versionless?.transitive === true
@@ -1005,6 +1299,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
1005
1299
  cwd: projectRoot,
1006
1300
  },
1007
1301
  };
1302
+ Object.assign(targets, scriptcPlatformTargets(packageJson, packageJsonPath, projectRoot, libTsconfigPath, toolchainInputs));
1008
1303
  }
1009
1304
  if (hasTestTsconfig) {
1010
1305
  targets['typecheck-tests'] = {
@@ -1052,7 +1347,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
1052
1347
  targets['cargo-wasm'] = createCargoWasmTarget(projectRoot, cargoWasmConfig, isRepoRootedCargoProject, cargoWasmTargetDirectory(projectRoot, cargoWasmConfig, isRepoRootedCargoProject, cargoWorkspace));
1053
1348
  }
1054
1349
  if (napiConfig) {
1055
- Object.assign(targets, createNapiTargets(projectRoot, napiConfig, hostPlatform, isRepoRootedCargoProject));
1350
+ Object.assign(targets, createNapiTargets(projectRoot, napiConfig, hostPlatform, nativeTools, isRepoRootedCargoProject));
1056
1351
  if (!('napi-test' in (packageJson.nx?.targets ?? {})) &&
1057
1352
  existsSync(join(absoluteProjectRoot, 'src/native.test.ts'))) {
1058
1353
  targets['napi-test'] = createNapiTestTarget(projectRoot, existsSync(join(absoluteProjectRoot, 'bunfig.napi-test.toml')));
@@ -1093,7 +1388,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
1093
1388
  // `dependsOn` REPLACES rather than unions. These lists state what each target
1094
1389
  // consumes — the fetched registry, the archive, the debug addon — and a
1095
1390
  // package that must re-route one (build its artifact ahead of the test run,
1096
- // or drop `cargo-test-compile` because it compiles differently) can only say
1391
+ // or drop `cargo-test-archive` because it compiles differently) can only say
1097
1392
  // so by replacing the list; a union would make every inferred edge
1098
1393
  // unremovable and a corrected order unrepresentable.
1099
1394
  // Additive intent already has a spelling (`"..."` above), so a plugin-local
@@ -1108,13 +1403,13 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
1108
1403
  const ownsCargoWorkspaceTargets = isCargoWorkspaceRoot;
1109
1404
  if (ownsCargoWorkspaceTargets && cargoWorkspace) {
1110
1405
  const cargoWorkspaceRoot = cargoWorkspace.projectRoot;
1111
- targets[CARGO_TEST_COMPILE_TARGET] = createCargoTestCompileTarget(cargoWorkspaceRoot);
1112
1406
  const workspaceInputs = [
1113
1407
  ...new Set((await Promise.all(cargoWorkspace.packages.map((plan) => cargoPackageTestInputs({
1114
1408
  workspaceRoot,
1115
1409
  absoluteProjectRoot: join(workspaceRoot, cargoWorkspaceRoot),
1116
1410
  memberDir: plan.package.dir,
1117
1411
  cache: cargoWorkspace.inputsCache,
1412
+ cargo: cargoWorkspace.closureSource.cargo,
1118
1413
  })))).flat()),
1119
1414
  ];
1120
1415
  // Generated crate sources (wire codecs, vocabularies, fixtures) are
@@ -1129,7 +1424,6 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
1129
1424
  ...(workspaceInputs.length > 0 ? workspaceInputs : CARGO_INPUTS),
1130
1425
  { dependentTasksOutputFiles: '**/*', transitive: false },
1131
1426
  ];
1132
- targets[CARGO_TEST_COMPILE_TARGET].inputs = workspaceCargoInputs;
1133
1427
  targets[CARGO_TEST_ARCHIVE_TARGET] = createCargoTestArchiveTarget(cargoWorkspaceRoot, nextestToolConfigArg(cargoWorkspaceRoot));
1134
1428
  // `archive.include` lives in the repository's nextest config, so that file
1135
1429
  // decides what the archive CONTAINS, not merely how a run behaves.
@@ -1139,10 +1433,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
1139
1433
  // binaries whichever machine they are for, so a change that invalidates
1140
1434
  // the host archive must invalidate every cross one.
1141
1435
  for (const crossTarget of listCargoCrossTestTargets(join(workspaceRoot, cargoWorkspaceRoot))) {
1142
- Object.assign(targets, createCargoCrossTestTargets(cargoWorkspaceRoot, nextestToolConfigArg(cargoWorkspaceRoot), crossTarget, [
1143
- ...workspaceCargoInputs,
1144
- `{projectRoot}/${NEXTEST_REPO_CONFIG_PATH}`,
1145
- ]));
1436
+ Object.assign(targets, createCargoCrossTestTargets(cargoWorkspaceRoot, nextestToolConfigArg(cargoWorkspaceRoot), crossTarget, [...workspaceCargoInputs, `{projectRoot}/${NEXTEST_REPO_CONFIG_PATH}`], pluginInstalledIn(workspaceRoot)));
1146
1437
  }
1147
1438
  // A serial group's filter can span members, so no single crate owns it. The root
1148
1439
  // owns each group's runner beside the archive it executes, and gives it the inputs
@@ -1150,7 +1441,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
1150
1441
  // to its packages reruns only when their sources or local dependencies change,
1151
1442
  // and an unscoped one hashes every member, as the archive itself does.
1152
1443
  for (const group of cargoWorkspace.serialGroups) {
1153
- targets[cargoTestGroupTargetName(group.group)] = cargoTestGroupTarget(cargoWorkspace, await cargoTestRunnerInputs(workspaceRoot, cargoWorkspace, serialGroupMemberDirs(cargoWorkspace, group)), group);
1444
+ targets[cargoTestGroupTargetName(group.group)] = cargoTestGroupTarget(cargoWorkspace, nativeTools, await cargoTestRunnerInputs(workspaceRoot, cargoWorkspace, serialGroupMemberDirs(cargoWorkspace, group)), group);
1154
1445
  }
1155
1446
  // Every project's crate pieces. The serial groups' runners are the gate's (`test`, below), so
1156
1447
  // `cargo-test` is the ordinary suite alone and a run of it never reaches a group's real-image tests.
@@ -1162,15 +1453,18 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
1162
1453
  aggregateDependencies.length > 0
1163
1454
  ? { executor: 'nx:noop', cache: true, outputs: [], dependsOn: aggregateDependencies }
1164
1455
  : createCargoTestTarget(cargoWorkspaceRoot);
1165
- // One clippy over the whole workspace, in the build's target dir. Clippy
1166
- // of a crate is a check build of its closure; a target dir per crate
1167
- // compiled every shared dependency once per crate (49 closures, 11 GiB on
1168
- // one repository) and no per-crate cache hit ever repaid that. The
1169
- // workspace inputs are exactly the union of every crate's, so the verdict
1170
- // caches on the same key set the compile does. Non-root packages depend on
1171
- // this target.
1456
+ // One clippy over the whole workspace. Clippy of a crate is a check build
1457
+ // of its closure; a target dir per crate compiled every shared dependency
1458
+ // once per crate (49 closures, 11 GiB on one repository) and no per-crate
1459
+ // cache hit ever repaid that. The workspace inputs are exactly the union of
1460
+ // every crate's, so the verdict caches on the same key set the archive
1461
+ // does. Non-root packages depend on this target. Its target dir is its own
1462
+ // (CARGO_LINT_CLIPPY_COMMAND, ./cross-check-policy.ts): Cargo flocks one
1463
+ // directory per invocation, and a workspace clippy holding the dev build's
1464
+ // `target/` queued the archive and every dev build behind it.
1172
1465
  targets['cargo-lint'] = {
1173
1466
  executor: 'nx:run-commands',
1467
+ metadata: CARGO_PRODUCER_METADATA,
1174
1468
  cache: true,
1175
1469
  inputs: workspaceCargoInputs,
1176
1470
  outputs: [],
@@ -1209,6 +1503,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
1209
1503
  // macOS host demand the zig toolchain that the devenv profile keeps opt-in.
1210
1504
  targets[CARGO_CROSS_LINT_TARGET] = {
1211
1505
  executor: 'nx:run-commands',
1506
+ metadata: CARGO_PRODUCER_METADATA,
1212
1507
  cache: true,
1213
1508
  inputs: workspaceCargoInputs,
1214
1509
  outputs: [],
@@ -1224,27 +1519,33 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
1224
1519
  // progress, so its bound is a wall-clock backstop, not a performance budget.
1225
1520
  targets.mutation = {
1226
1521
  executor: '@smoothbricks/nx-plugin:bounded-exec',
1522
+ metadata: CARGO_PRODUCER_METADATA,
1227
1523
  cache: false,
1228
1524
  options: { command: cargoFrozen('mutants --workspace'), cwd: cargoWorkspaceRoot, timeoutMs: MUTATION_TIMEOUT_MS },
1229
1525
  };
1230
1526
  targets.bench = {
1231
1527
  executor: 'nx:run-commands',
1528
+ metadata: CARGO_PRODUCER_METADATA,
1232
1529
  cache: false,
1233
1530
  options: { command: cargoFrozen('bench --workspace'), cwd: cargoWorkspaceRoot },
1234
1531
  };
1235
- // Target-dir GC. Cargo never removes superseded artifacts, so a busy
1236
- // workspace grows tens of GB of stale variants no fingerprint references;
1237
- // sweeping by age prunes exactly that junk while the warm current
1238
- // surface — the gated asset — survives untouched. Never cached: the
1239
- // verdict is about this machine's disk, not the commit.
1240
- targets['cargo-sweep'] = {
1532
+ // A read-only preview of the retention pass the plugin's postTasksExecution
1533
+ // schedules after runs that built (@smoothbricks/cargo-retain): the superseded unit
1534
+ // generations it would reclaim and why everything else stays. Never cached:
1535
+ // the verdict is about this machine's disk, not the commit.
1536
+ const retainTool = nativeToolDependsOn(nativeTools, 'cargo-retain');
1537
+ targets['cargo-retention'] = {
1241
1538
  executor: 'nx:run-commands',
1242
1539
  cache: false,
1243
- options: { command: 'cargo sweep --time 7', cwd: cargoWorkspaceRoot },
1540
+ ...(retainTool.length > 0 ? { dependsOn: retainTool } : {}),
1541
+ options: {
1542
+ command: nativeToolCommand(nativeTools, cargoWorkspaceRoot, 'cargo-retain', 'smoo-nx-cargo-retain'),
1543
+ cwd: cargoWorkspaceRoot,
1544
+ },
1244
1545
  };
1245
1546
  }
1246
1547
  if (cargoWorkspace) {
1247
- const packageTargetNames = await addCargoTestTargets(targets, projectName, projectRoot, workspaceRoot, cargoWorkspace);
1548
+ const packageTargetNames = await addCargoTestTargets(targets, projectName, projectRoot, workspaceRoot, cargoWorkspace, nativeTools);
1248
1549
  // Serial-group runners belong to the workspace root, outside inferred ordinary tests. Explicit repository
1249
1550
  // aggregates can reach them; their own inputs decide whether each runner executes or replays from cache.
1250
1551
  if (!isCargoWorkspaceRoot) {
@@ -1292,7 +1593,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
1292
1593
  };
1293
1594
  }
1294
1595
  for (const name of Object.keys(declaredTargets)) {
1295
- if (name === 'test' || !isTestRunnerTargetName(name) || targets[name] !== undefined)
1596
+ if (name === 'test' || !isTestNamespaceTargetName(name) || targets[name] !== undefined)
1296
1597
  continue;
1297
1598
  targets[name] = { dependsOn: ['^build', 'build'] };
1298
1599
  }
@@ -1330,6 +1631,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
1330
1631
  // would skip work a cold registry still needs. Nothing here is a
1331
1632
  // workspace output, so there is nothing for Nx to restore in its place.
1332
1633
  cache: false,
1634
+ inputs: cargoFetchInputs(projectRoot),
1333
1635
  options: {
1334
1636
  // One fetch per manifest, independent of the others: Cargo's own
1335
1637
  // package-cache lock arbitrates the CARGO_HOME they share.
@@ -1366,7 +1668,8 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
1366
1668
  // Cache verdicts and dedicated artifacts, never Cargo's shared mutable build
1367
1669
  // directories. Resolve tool versions from the command's actual directory.
1368
1670
  // Name the npm packages the command runs (cargoCommandNpmPackages) unless
1369
- // the target already does.
1671
+ // the target already does, and the Cargo.lock entries its crates reach (the
1672
+ // lock-scope node of the directory it runs in) unless its inputs already do.
1370
1673
  for (const [name, target] of Object.entries(targets)) {
1371
1674
  const text = targetCommandText(target);
1372
1675
  if (!runsFrozenCargo(text))
@@ -1381,24 +1684,24 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
1381
1684
  ? ' && cargo nextest --version'
1382
1685
  : '';
1383
1686
  const inputs = target.inputs ?? CARGO_INPUTS;
1384
- const namesPackages = inputs.some((input) => typeof input === 'object' && 'externalDependencies' in input);
1687
+ const namesPackages = inputs.some((input) => typeof input === 'object' && 'externalDependencies' in input && !isCargoLockInput(input));
1688
+ const namesLock = inputs.some((input) => input === CARGO_CLOSURE_INPUT || isCargoLockInput(input));
1689
+ const lockDirectory = typeof cwd === 'string' ? cwd : projectRoot;
1385
1690
  target.inputs = [
1386
1691
  ...inputs,
1387
- ...CARGO_TOOLCHAIN_PIN_INPUTS,
1692
+ ...cargoToolchainInputs(),
1388
1693
  cargoRuntimeInput(typeof cwd === 'string' ? cwd : projectRoot, `rustc -vV && cargo -V${versions}`),
1389
- ...(namesPackages ? [] : [{ externalDependencies: cargoCommandNpmPackages(target, text) }]),
1694
+ ...(namesPackages
1695
+ ? []
1696
+ : [{ externalDependencies: cargoCommandNpmPackages(target, text, pluginInstalledIn(workspaceRoot)) }]),
1697
+ ...(namesLock
1698
+ ? []
1699
+ : cargoSourcesUnder(lockDirectory, cargoWorkspaces).length > 0
1700
+ ? [{ externalDependencies: [cargoLockNodeName(lockDirectory)] }]
1701
+ : // No project-rooted Cargo workspace claims these crates, so the plugin holds no resolve to scope.
1702
+ [UNRESOLVED_CARGO_LOCK_INPUT]),
1390
1703
  ];
1391
1704
  }
1392
- // `build` warms the test executables' compile; in a nested package that names
1393
- // the root workspace's one compile.
1394
- const cargoTestCompileDependency = targets[CARGO_TEST_COMPILE_TARGET]
1395
- ? CARGO_TEST_COMPILE_TARGET
1396
- : isCargoProject && cargoWorkspace
1397
- ? cargoTargetDependency(projectName, {
1398
- projectName: cargoWorkspace.rootProjectName,
1399
- targetName: CARGO_TEST_COMPILE_TARGET,
1400
- })
1401
- : null;
1402
1705
  const napiDebug = targets['napi-debug'];
1403
1706
  if (napiDebug && cargoWorkspace) {
1404
1707
  // A crate whose project also builds the debug cdylib runs its tests after
@@ -1419,15 +1722,6 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
1419
1722
  }
1420
1723
  }
1421
1724
  else if (napiDebug) {
1422
- for (const [name, target] of Object.entries(targets)) {
1423
- if (!name.startsWith('cargo-test-') || name === CARGO_TEST_COMPILE_TARGET) {
1424
- continue;
1425
- }
1426
- const dependsOn = target.dependsOn ?? [];
1427
- if (dependsOn.includes(CARGO_TEST_COMPILE_TARGET) && !dependsOn.includes('napi-debug')) {
1428
- target.dependsOn = [...dependsOn, 'napi-debug'];
1429
- }
1430
- }
1431
1725
  const cargoTest = targets[CARGO_TEST_TARGET];
1432
1726
  if (cargoTest?.options &&
1433
1727
  typeof cargoTest.options.command === 'string' &&
@@ -1441,6 +1735,31 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
1441
1735
  // The inferring host's own platform binaries join the aggregate `build`;
1442
1736
  // publish still owns foreign platforms.
1443
1737
  const hostPlatformBinaries = hostPlatformTargetNames([...Object.keys(declaredTargets), ...Object.keys(targets)], hostPlatform);
1738
+ // `<tool>-native` is the host's own build of one tool, so a test that runs it names one edge: `cli-native` is the
1739
+ // declared `cli-<arch>-<family>` build for this machine, `napi-native` the addon (this host's platform target, or
1740
+ // cargo-napi where no configured triple is this machine's), and scriptc-native its host executable producer.
1741
+ // Each is picked from hostPlatformBinaries by the same
1742
+ // suffix rule, its family name `-native` joins it to `build`, and it states no outputs. It runs nothing, so it
1743
+ // states `cache: false`; a cached aggregate would need inputs of its own. A host with no such producer gets no
1744
+ // aggregate, and inference makes no test depend on one.
1745
+ const hostBuilds = {
1746
+ 'scriptc-native': hostPlatformBinaries.filter((name) => name.startsWith('scriptc-')),
1747
+ 'cli-native': hostPlatformBinaries.filter((name) => name.startsWith('cli-')),
1748
+ 'napi-native': targets['cargo-napi']
1749
+ ? ['cargo-napi']
1750
+ : hostPlatformBinaries.filter((name) => name.startsWith('napi-')),
1751
+ };
1752
+ for (const [name, dependsOn] of Object.entries(hostBuilds)) {
1753
+ if (dependsOn.length > 0) {
1754
+ targets[name] = {
1755
+ executor: 'nx:noop',
1756
+ cache: false,
1757
+ outputs: [],
1758
+ dependsOn,
1759
+ configurations: { production: {} },
1760
+ };
1761
+ }
1762
+ }
1444
1763
  // A deploy is never cached; the build half beside it always is.
1445
1764
  //
1446
1765
  // Nx's cache answers "did this exact input set already produce an output". A deploy's real
@@ -1523,9 +1842,6 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
1523
1842
  dependsOn: [
1524
1843
  ...new Set([
1525
1844
  '^build',
1526
- // Compiling the test executables is unbounded preparation. Cargo
1527
- // reuses its incremental state; Nx never restores that shared state.
1528
- ...(cargoTestCompileDependency ? [cargoTestCompileDependency] : []),
1529
1845
  ...buildOutputTargetNames([...Object.keys(declaredTargets), ...Object.keys(targets)]),
1530
1846
  ...hostPlatformBinaries,
1531
1847
  ]),
@@ -1594,7 +1910,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
1594
1910
  };
1595
1911
  validationTargets.push(SHARD_TIMINGS_TARGET);
1596
1912
  }
1597
- const { commands: lintCommands, inputs: lintProgramInputs, eslintFileSet, } = projectLintCommands(projectRoot, workspaceRoot, eslintSources);
1913
+ const { commands: lintCommands, inputs: lintProgramInputs, eslintFileSet, } = projectLintCommands(projectRoot, workspaceRoot, eslint);
1598
1914
  // Every lint tool reaches its own verdict in one run: run-commands would end the
1599
1915
  // other tools once one fails, and their findings would surface a run later.
1600
1916
  if (validationTargets.length > 0 || lintCommands.length > 0) {
@@ -1613,7 +1929,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
1613
1929
  `{workspaceRoot}/${name}`,
1614
1930
  `{projectRoot}/${name}`,
1615
1931
  ]),
1616
- '{workspaceRoot}/tooling/checks/**/*',
1932
+ ...(eslint?.configImports ?? []).map((path) => `{workspaceRoot}/${path}`),
1617
1933
  ],
1618
1934
  ...(lintCommands.length > 0
1619
1935
  ? {
@@ -1622,12 +1938,21 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
1622
1938
  : {}),
1623
1939
  };
1624
1940
  }
1941
+ // Publish each inferred target's semantic kind (`inferredTaskKind`) as metadata. Nx merges metadata beneath a
1942
+ // declaration, so the final graph still says which tasks are build and which are test work after a package rewrites
1943
+ // one. Fresh objects: `CARGO_PRODUCER_METADATA` is shared by every producer.
1944
+ for (const [name, target] of Object.entries(targets)) {
1945
+ const kind = inferredTaskKind(name);
1946
+ if (kind !== undefined) {
1947
+ target.metadata = { ...target.metadata, smooTaskKind: kind };
1948
+ }
1949
+ }
1625
1950
  // A declared target REPLACES the inferred input list, pin included, so a
1626
1951
  // repository that hand-writes `inputs` for a cargo target silently loses its
1627
- // toolchain identity. Name the pin once here so such a declaration can
1628
- // reference it as `cargoToolchain` instead of restating two paths that could
1952
+ // toolchain identity. Name the identity once here so such a declaration can
1953
+ // reference it as `cargoToolchain` instead of restating entries that could
1629
1954
  // drift from the plugin; `smoo monorepo validate` refuses a cached cargo
1630
- // target whose resolved inputs reach neither. Defined only for projects that
1955
+ // target that does not reach it. Defined only for projects that
1631
1956
  // HAVE cargo targets: a project's namedInputs definitions are hashed into
1632
1957
  // its configuration hash, so defining it everywhere would invalidate every
1633
1958
  // task in the repository to serve projects that can never reference it.
@@ -1639,7 +1964,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
1639
1964
  [VERSIONLESS_DEFAULT_INPUT]: ['default', ...versionlessProjectInputs],
1640
1965
  }),
1641
1966
  ...(Object.keys(targets).some((name) => name.startsWith('cargo-') || name.startsWith('napi-'))
1642
- ? { [CARGO_TOOLCHAIN_NAMED_INPUT]: [...CARGO_TOOLCHAIN_PIN_INPUTS] }
1967
+ ? { [CARGO_TOOLCHAIN_NAMED_INPUT]: cargoToolchainInputs() }
1643
1968
  : {}),
1644
1969
  };
1645
1970
  // A custom Cargo target names this instead of a hand-kept crate list or a
@@ -1647,14 +1972,17 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
1647
1972
  // computation and Nx hashes its files from its own index. Defined for a
1648
1973
  // project with a workspace crate under its root — the same projects the
1649
1974
  // `--closure <projectRoot>` command could describe.
1650
- const closureSources = cargoWorkspaces.filter((workspace) => workspace.packages.some(({ package: pkg }) => {
1651
- const crate = posix.join(workspace.projectRoot, pkg.dir);
1652
- return projectRoot === '.' || crate === projectRoot || crate.startsWith(`${projectRoot}/`);
1653
- }));
1975
+ const closureSources = cargoSourcesUnder(projectRoot, cargoWorkspaces);
1654
1976
  if (closureSources.length > 0) {
1655
- namedInputs[CARGO_CLOSURE_INPUT] = await cargoClosureInputs(projectRoot, closureSources.map((workspace) => workspace.closureSource));
1977
+ namedInputs[CARGO_CLOSURE_INPUT] = await cargoClosureInputs(projectRoot, closureSources);
1656
1978
  }
1979
+ const externalNodes = await lockScopeNodes(projectRoot, [
1980
+ ...Object.values(targets).map((target) => target.inputs),
1981
+ ...Object.values(declaredTargets).map((target) => (isRecord(target) ? target.inputs : undefined)),
1982
+ ...Object.values(namedInputs),
1983
+ ], cargoWorkspaces);
1657
1984
  return {
1985
+ ...(Object.keys(externalNodes).length === 0 ? {} : { externalNodes }),
1658
1986
  projects: {
1659
1987
  [projectRoot]: {
1660
1988
  name: projectName,
@@ -1672,6 +2000,43 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
1672
2000
  },
1673
2001
  };
1674
2002
  }
2003
+ /** The Cargo resolves with a workspace crate under `directory`: the ones its crates' closure and lock scope cover. */
2004
+ function cargoSourcesUnder(directory, cargoWorkspaces) {
2005
+ return cargoWorkspaces
2006
+ .filter((workspace) => workspace.packages.some(({ package: pkg }) => {
2007
+ const crate = posix.join(workspace.projectRoot, pkg.dir);
2008
+ return directory === '.' || crate === directory || crate.startsWith(`${directory}/`);
2009
+ }))
2010
+ .map((workspace) => workspace.closureSource);
2011
+ }
2012
+ /**
2013
+ * The lock-scope nodes a project publishes: its own bun node, and one Cargo
2014
+ * node per directory its inputs name, computed from the resolves that cover
2015
+ * it. A project names only nodes its own crates' resolves define, so two
2016
+ * projects publishing the same node publish the same value.
2017
+ */
2018
+ async function lockScopeNodes(projectRoot, inputLists, cargoWorkspaces) {
2019
+ const directories = new Set();
2020
+ for (const inputs of inputLists) {
2021
+ if (!Array.isArray(inputs))
2022
+ continue;
2023
+ for (const input of inputs) {
2024
+ if (!isRecord(input) || !Array.isArray(input.externalDependencies))
2025
+ continue;
2026
+ for (const name of input.externalDependencies) {
2027
+ if (typeof name === 'string' && name.startsWith(CARGO_LOCK_NODE_PREFIX)) {
2028
+ directories.add(name.slice(CARGO_LOCK_NODE_PREFIX.length));
2029
+ }
2030
+ }
2031
+ }
2032
+ }
2033
+ const own = bunLockNode(projectRoot);
2034
+ const nodes = { [own.name]: own };
2035
+ for (const node of await Promise.all([...directories].map((directory) => cargoLockNode(directory, cargoSourcesUnder(directory, cargoWorkspaces))))) {
2036
+ nodes[node.name] = node;
2037
+ }
2038
+ return nodes;
2039
+ }
1675
2040
  const WASM_BINDGEN_OUTPUT_NAMES = {
1676
2041
  bundler: 'bundler',
1677
2042
  deno: 'deno',
@@ -1763,20 +2128,27 @@ async function resolveCargoWasmConfig(absoluteProjectRoot, packageJsonPath, work
1763
2128
  return resolved[0] ?? null;
1764
2129
  }
1765
2130
  function inferTypescriptOutputs(tsconfigPath, packageJsonPath) {
2131
+ const outDir = typescriptOutDir(tsconfigPath, packageJsonPath);
2132
+ // No .tsbuildinfo here: the emit executor overlays incremental: false, so
2133
+ // tsc-js never writes one and a declared-but-absent output fails the
2134
+ // release-candidate output inspection.
2135
+ return outDir === null
2136
+ ? ['{projectRoot}/dist/**/*.{js,cjs,mjs,jsx,d.ts,d.cts,d.mts}{,.map}']
2137
+ : [`{projectRoot}/${outDir}/`];
2138
+ }
2139
+ /** The project-relative `compilerOptions.outDir` the config itself states, or null when it states none. */
2140
+ function typescriptOutDir(tsconfigPath, packageJsonPath) {
1766
2141
  const tsconfig = readJsonFile(tsconfigPath);
1767
2142
  const compilerOptions = isRecord(tsconfig) && isRecord(tsconfig.compilerOptions) ? tsconfig.compilerOptions : null;
1768
2143
  const outDir = compilerOptions?.outDir;
1769
2144
  if (typeof outDir !== 'string' || outDir.length === 0) {
1770
- // No .tsbuildinfo here: the emit executor overlays incremental: false, so
1771
- // tsc-js never writes one and a declared-but-absent output fails the
1772
- // release-candidate output inspection.
1773
- return ['{projectRoot}/dist/**/*.{js,cjs,mjs,jsx,d.ts,d.cts,d.mts}{,.map}'];
2145
+ return null;
1774
2146
  }
1775
2147
  const normalized = posix.normalize(outDir.replaceAll('\\', '/'));
1776
2148
  if (normalized === '.' || normalized === '..' || normalized.startsWith('../') || normalized.startsWith('/')) {
1777
2149
  throw new Error(`${packageJsonPath}: tsconfig.lib.json compilerOptions.outDir must stay inside the project`);
1778
2150
  }
1779
- return [`{projectRoot}/${normalized}`];
2151
+ return normalized.replace(/\/$/, '');
1780
2152
  }
1781
2153
  function resolveNapiConfig(packageJson, packageJsonPath, absoluteProjectRoot, isCargoWorkspace, repoRootPackages) {
1782
2154
  if (!packageJson.napi) {
@@ -1812,7 +2184,7 @@ function resolveNapiConfig(packageJson, packageJsonPath, absoluteProjectRoot, is
1812
2184
  }
1813
2185
  return { binaryName, cargoPackage, manifestPath, targets };
1814
2186
  }
1815
- function createNapiTargets(projectRoot, config, hostPlatform, repoRooted) {
2187
+ function createNapiTargets(projectRoot, config, hostPlatform, nativeTools, repoRooted) {
1816
2188
  // napi derives the addon filename ([name]) from the nearest package.json `napi`
1817
2189
  // field starting at the invocation cwd. A repository-root invocation runs where
1818
2190
  // no such field exists, so without an explicit path every repo-rooted build
@@ -1825,7 +2197,20 @@ function createNapiTargets(projectRoot, config, hostPlatform, repoRooted) {
1825
2197
  // A repository-root Cargo invocation runs outside the owning npm package, so
1826
2198
  // Nx's root-only PATH cannot resolve that package's napi CLI.
1827
2199
  const napiCommand = repoRooted ? posix.join(projectRoot, 'node_modules/.bin/napi') : 'napi';
1828
- const outputPath = (projectOutput) => (repoRooted ? posix.join(projectRoot, projectOutput) : projectOutput);
2200
+ const outputDir = (projectOutput) => (repoRooted ? posix.join(projectRoot, projectOutput) : projectOutput);
2201
+ // The directory a run writes into, as its `outputDir` option states it for the run's profile.
2202
+ const runOutputDirectory = outputDir(OUTPUT_DIR_ARGUMENT);
2203
+ // After a build, the step that writes its input record (build-inputs.ts) into the output directory from the dep-info
2204
+ // rustc wrote for the addon (`target/[<triple>/]<profile>/lib<crate>.d`). The record is inside the target's
2205
+ // outputs, so Nx restores it with the addon it describes. Relative to the runner's cwd, so the hashed command is
2206
+ // the same in every checkout.
2207
+ const recordInputs = (triple, profile, outputDirectory) => {
2208
+ const depInfo = posix.join(...(triple === null ? [] : [triple]), CARGO_PROFILE_OUTPUT_DIR[profile], `lib${config.cargoPackage.replaceAll('-', '_')}.d`);
2209
+ const bin = nativeToolCommand(nativeTools, cargoCwd, 'build-inputs', 'smoo-nx-build-inputs');
2210
+ return ` && ${bin} --manifest-path ${config.manifestPath} --dep-info ${depInfo} --output ${outputDirectory}`;
2211
+ };
2212
+ // The task that builds the executable recordInputs runs, when this workspace builds it.
2213
+ const buildInputsTool = nativeToolDependsOn(nativeTools, 'build-inputs');
1829
2214
  const hasHostPlatformTarget = config.targets.some((triple) => {
1830
2215
  const convention = NAPI_TARGET_CONVENTIONS[triple];
1831
2216
  return convention !== undefined && sameNapiPlatform(convention, hostPlatform);
@@ -1841,13 +2226,14 @@ function createNapiTargets(projectRoot, config, hostPlatform, repoRooted) {
1841
2226
  // production loads never see it.
1842
2227
  targets['napi-debug'] = {
1843
2228
  executor: 'nx:run-commands',
2229
+ metadata: CARGO_PRODUCER_METADATA,
1844
2230
  cache: true,
1845
2231
  dependsOn: ['^build'],
1846
2232
  inputs: cargoInputs,
1847
- outputs: ['{projectRoot}/.cache/native-debug'],
2233
+ outputs: ['{projectRoot}/.cache/native-debug/'],
1848
2234
  options: {
1849
2235
  cwd: cargoCwd,
1850
- command: `${napiCommand} build --platform --no-js --dts ${config.binaryName}.napi.d.ts ${commonCommand} --output-dir ${outputPath('.cache/native-debug')}`,
2236
+ command: `${napiCommand} build --platform --no-js --dts ${config.binaryName}.napi.d.ts ${commonCommand} --output-dir ${outputDir('.cache/native-debug')}`,
1851
2237
  },
1852
2238
  };
1853
2239
  if (!hasHostPlatformTarget) {
@@ -1855,20 +2241,26 @@ function createNapiTargets(projectRoot, config, hostPlatform, repoRooted) {
1855
2241
  // second cargo-napi invocation only buys a duplicate dependency graph
1856
2242
  // (a plain build and a `--target` build write different target/
1857
2243
  // subdirectories); native.ts already resolves the identical
1858
- // platform-suffixed filename from dist/native/<platform-dir> after
1859
- // dist/native/host.
1860
- const hostBuild = (profile) => `${napiCommand} build${CARGO_PROFILE_FLAG[profile]} --platform --no-js --dts ${config.binaryName}.napi.d.ts ${commonCommand} --output-dir ${outputPath('dist/native/host')}`;
2244
+ // platform-suffixed filename from <tree>/<platform-dir> after <tree>/host,
2245
+ // in the one tree its package's source authority selects (.cache/native-dev
2246
+ // in a checkout, dist/native installed).
2247
+ const hostBuild = (profile) => `${napiCommand} build${CARGO_PROFILE_FLAG[profile]} --platform --no-js --dts ${config.binaryName}.napi.d.ts ${commonCommand} --output-dir ${runOutputDirectory}${recordInputs(null, profile, runOutputDirectory)}`;
2248
+ const hostOutputs = nativeOutputPaths('host');
1861
2249
  targets['cargo-napi'] = {
1862
2250
  executor: 'nx:run-commands',
2251
+ metadata: CARGO_PRODUCER_METADATA,
1863
2252
  cache: true,
1864
- dependsOn: ['^build'],
2253
+ dependsOn: ['^build', ...buildInputsTool],
1865
2254
  inputs: cargoInputs,
1866
- outputs: ['{projectRoot}/dist/native/host'],
2255
+ outputs: [`{projectRoot}/${OUTPUT_DIR_OPTION}/`],
1867
2256
  options: {
1868
2257
  cwd: cargoCwd,
1869
2258
  command: hostBuild('dev'),
2259
+ outputDir: hostOutputs.dev,
2260
+ },
2261
+ configurations: {
2262
+ [RELEASE_CONFIGURATION]: { command: hostBuild('release'), outputDir: hostOutputs.release },
1870
2263
  },
1871
- configurations: { [RELEASE_CONFIGURATION]: { command: hostBuild('release') } },
1872
2264
  };
1873
2265
  }
1874
2266
  for (const triple of config.targets) {
@@ -1877,40 +2269,50 @@ function createNapiTargets(projectRoot, config, hostPlatform, repoRooted) {
1877
2269
  throw new Error(`Missing N-API target convention for ${triple}`);
1878
2270
  }
1879
2271
  const targetName = `napi-${convention.architecture}-${convention.targetFamily}`;
1880
- const outputDirectory = `dist/native/${convention.outputName}`;
2272
+ const outputs = nativeOutputPaths(convention.outputName);
1881
2273
  if (convention.targetFamily === 'linux') {
1882
2274
  // Every host builds a Linux addon the same way: devenv's zig through
1883
2275
  // cargo-zigbuild, glibc pinned by the triple suffix. The napi CLI cannot
1884
2276
  // carry that suffix (it looks for the artifact under
1885
2277
  // target/<triple>.2.17/), so the executor names the `.node` itself.
2278
+ const nodeFile = (directory) => `{projectRoot}/${directory}/${config.binaryName}.${convention.outputName}.node`;
1886
2279
  targets[targetName] = {
1887
2280
  executor: '@smoothbricks/nx-plugin:cargo-zigbuild',
2281
+ metadata: CARGO_PRODUCER_METADATA,
1888
2282
  cache: true,
1889
2283
  inputs: napiInputs(projectRoot, repoRooted, []),
1890
- outputs: [`{projectRoot}/${outputDirectory}`],
2284
+ // The executor takes no `outputDir`: its `output` file is the one place each profile states where it
2285
+ // writes, and the declared output reads the directory holding it from there (`/../`, which Nx's interpolation
2286
+ // joins to the parent). The build-input record stamped beside the `.node` file is restored with it.
2287
+ outputs: ['{options.output}/../'],
1891
2288
  options: {
1892
2289
  target: `${triple}.${LINUX_GLIBC_FLOOR}`,
1893
2290
  manifestPath: posix.join(cargoCwd, config.manifestPath),
1894
2291
  package: config.cargoPackage,
1895
- output: `{projectRoot}/${outputDirectory}/${config.binaryName}.${convention.outputName}.node`,
2292
+ output: nodeFile(outputs.dev),
1896
2293
  },
1897
- configurations: { [RELEASE_CONFIGURATION]: { release: true } },
2294
+ configurations: { [RELEASE_CONFIGURATION]: { release: true, output: nodeFile(outputs.release) } },
1898
2295
  };
1899
2296
  continue;
1900
2297
  }
1901
2298
  // macOS addons need Apple's SDK, which zig does not carry: the napi CLI
1902
2299
  // drives the host's own toolchain and writes the platform `.d.ts`.
1903
- const platformBuild = (profile) => `${napiCommand} build${CARGO_PROFILE_FLAG[profile]} --platform --no-js --dts ${config.binaryName}.${convention.outputName}.d.ts --target ${triple} ${commonCommand} --output-dir ${outputPath(outputDirectory)}`;
2300
+ const platformBuild = (profile) => `${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)}`;
1904
2301
  targets[targetName] = {
1905
2302
  executor: 'nx:run-commands',
2303
+ metadata: CARGO_PRODUCER_METADATA,
1906
2304
  cache: true,
2305
+ ...(buildInputsTool.length > 0 ? { dependsOn: buildInputsTool } : {}),
1907
2306
  inputs: cargoInputs,
1908
- outputs: [`{projectRoot}/${outputDirectory}`],
2307
+ outputs: [`{projectRoot}/${OUTPUT_DIR_OPTION}/`],
1909
2308
  options: {
1910
2309
  cwd: cargoCwd,
1911
2310
  command: platformBuild('dev'),
2311
+ outputDir: outputs.dev,
2312
+ },
2313
+ configurations: {
2314
+ [RELEASE_CONFIGURATION]: { command: platformBuild('release'), outputDir: outputs.release },
1912
2315
  },
1913
- configurations: { [RELEASE_CONFIGURATION]: { command: platformBuild('release') } },
1914
2316
  };
1915
2317
  }
1916
2318
  return targets;
@@ -1950,9 +2352,11 @@ async function readPackageJson(packageJsonPath) {
1950
2352
  const rawNx = isRecord(parsed.nx) ? parsed.nx : undefined;
1951
2353
  return {
1952
2354
  ...('bin' in parsed ? { bin: parsed.bin } : {}),
2355
+ ...(isRecord(parsed.devDependencies) ? { devDependencies: parsed.devDependencies } : {}),
1953
2356
  ...(typeof parsed.name === 'string' ? { name: parsed.name } : {}),
1954
2357
  ...(isRecord(parsed.napi) ? { napi: parsed.napi } : {}),
1955
2358
  ...(typeof parsed.private === 'boolean' ? { private: parsed.private } : {}),
2359
+ ...('scriptc' in parsed ? { scriptc: parsed.scriptc } : {}),
1956
2360
  ...(isRecord(parsed.scripts) ? { scripts: parsed.scripts } : {}),
1957
2361
  ...(rawNx
1958
2362
  ? {
@@ -2057,10 +2461,25 @@ async function resolveCargoWorkspaces(packageJsonPaths, workspaceRoot, hostPlatf
2057
2461
  // piece excludes them: each test is selected by exactly one target.
2058
2462
  const serialExclusion = serialGroups.length === 0 ? null : serialGroups.map((group) => group.filter).join(' or ');
2059
2463
  const notSerial = serialExclusion === null ? [] : [`not (${serialExclusion})`];
2464
+ const timings = readNextestTimings(join(absoluteRoot, NEXTEST_TIMINGS_PATH));
2465
+ for (const crate of Object.keys(timings)) {
2466
+ if (!attributed.some((pkg) => pkg.name === crate && pkg.testShards > 1)) {
2467
+ throw new Error(`${posix.join(rootProject.root, NEXTEST_TIMINGS_PATH)} times ${crate}, which is no member of this Cargo ` +
2468
+ 'workspace that declares smoothbricks.test.shards above 1');
2469
+ }
2470
+ }
2060
2471
  for (const pkg of attributed) {
2061
2472
  const pieces = [];
2062
2473
  const sharded = pkg.testShards > 1;
2063
- const pin = sharded && exceptional !== null ? exceptional : null;
2474
+ const timed = timings[pkg.name] ?? {};
2475
+ const named = Object.keys(timed);
2476
+ const exceptionalHere = sharded ? exceptional : null;
2477
+ // The tests the hash does not place: nextest.toml's exceptional class and the measured slow tests.
2478
+ const pin = named.length === 0
2479
+ ? exceptionalHere
2480
+ : exceptionalHere === null
2481
+ ? namedTestsFilter(named)
2482
+ : `(${exceptionalHere}) or (${namedTestsFilter(named)})`;
2064
2483
  const ordinary = [`package(${pkg.name})`, ...(pin === null ? [] : [`not (${pin})`]), ...notSerial].join(' and ');
2065
2484
  for (let index = 1; index <= pkg.testShards; index += 1) {
2066
2485
  const targetName = cargoTestPackageTargetName(pkg.name, sharded ? `shard${index}` : undefined);
@@ -2071,10 +2490,22 @@ async function resolveCargoWorkspaces(packageJsonPaths, workspaceRoot, hostPlatf
2071
2490
  });
2072
2491
  }
2073
2492
  if (pin !== null) {
2493
+ // Measured tests are dealt by time; the last shard also takes every exceptional test the
2494
+ // manifest does not name, so the exception shards stay an exact cover of the pin.
2495
+ const members = named.length === 0 ? null : timedShardMembers(timed, pkg.testShards);
2074
2496
  for (let index = 1; index <= pkg.testShards; index += 1) {
2497
+ const own = members?.[index - 1];
2498
+ const unnamed = own !== undefined && exceptionalHere !== null && index === pkg.testShards
2499
+ ? ` or ((${exceptionalHere}) and not (${namedTestsFilter(named)}))`
2500
+ : '';
2075
2501
  pieces.push({
2076
- extra: ` --partition hash:${index}/${pkg.testShards}`,
2077
- selector: [`package(${pkg.name}) and (${pin})`, ...notSerial].join(' and '),
2502
+ extra: own === undefined ? ` --partition hash:${index}/${pkg.testShards}` : '',
2503
+ selector: [
2504
+ own === undefined
2505
+ ? `package(${pkg.name}) and (${pin})`
2506
+ : `package(${pkg.name}) and ((${namedTestsFilter(own)})${unnamed})`,
2507
+ ...notSerial,
2508
+ ].join(' and '),
2078
2509
  targetName: cargoTestPackageTargetName(pkg.name, `${CARGO_TEST_EXCEPTIONS_SUFFIX}-shard${index}`),
2079
2510
  });
2080
2511
  }
@@ -2120,12 +2551,13 @@ async function resolveCargoWorkspaces(packageJsonPaths, workspaceRoot, hostPlatf
2120
2551
  * own on every run, so N pieces paid N extractions of every binary in the
2121
2552
  * workspace to run 1/N of the tests each: on a workspace with ~200 test
2122
2553
  * binaries, ~25 runners extracting side by side on a loaded host all hit the
2123
- * 120s bound still "Extracting". `smoo-nx-nextest-extract` hashes the archive,
2124
- * unpacks it under that hash unless a previous runner already did — one
2554
+ * 120s bound still "Extracting". `smoo-nx-nextest-extract` reads the archive's
2555
+ * key, the hash of the task that produced it (createCargoTestArchiveTarget),
2556
+ * unpacks it under that key unless a previous runner already did — one
2125
2557
  * extracts while the rest wait — and prints the directory; the run then reuses
2126
2558
  * it through nextest's own reuse-build flags, which is what `--archive-file`
2127
- * does after unpacking. Keyed by the archive's bytes, so a rebuilt or restored
2128
- * archive can never run an older extraction's binaries. The one difference
2559
+ * does after unpacking. Keyed by the producing task's inputs, so a rebuilt or
2560
+ * restored archive of other inputs can never run an older extraction's binaries. The one difference
2129
2561
  * from `--archive-file` is the Rust standard library directory: nextest has no
2130
2562
  * flag to remap it, so a run uses the producing toolchain's own sysroot rather
2131
2563
  * than the archived copy of it — the same toolchain, because the archive's hash
@@ -2168,7 +2600,7 @@ async function resolveCargoWorkspaces(packageJsonPaths, workspaceRoot, hostPlatf
2168
2600
  * `target/`, so no piece waits on another. The one extraction per archive is
2169
2601
  * coordinated by `smoo-nx-nextest-extract` itself.
2170
2602
  */
2171
- async function addCargoTestTargets(targets, currentProjectName, projectRoot, workspaceRoot, workspace) {
2603
+ async function addCargoTestTargets(targets, currentProjectName, projectRoot, workspaceRoot, workspace, nativeTools) {
2172
2604
  const targetNames = [];
2173
2605
  for (const plan of workspace.packages) {
2174
2606
  if (plan.package.projectRoot !== projectRoot) {
@@ -2181,7 +2613,7 @@ async function addCargoTestTargets(targets, currentProjectName, projectRoot, wor
2181
2613
  });
2182
2614
  for (const piece of plan.pieces) {
2183
2615
  targetNames.push(piece.targetName);
2184
- targets[piece.targetName] = cargoTestRunnerTarget(workspace, archive, inputs, piece);
2616
+ targets[piece.targetName] = cargoTestRunnerTarget(workspace, nativeTools, archive, inputs, piece);
2185
2617
  }
2186
2618
  }
2187
2619
  return targetNames;
@@ -2206,15 +2638,16 @@ function serialGroupMemberDirs(workspace, group) {
2206
2638
  }
2207
2639
  /**
2208
2640
  * The inputs of the runners that select crates from one cargo workspace: the
2209
- * sources of the crates they select, every member manifest, and the repository's
2210
- * nextest config.
2641
+ * sources of the crates they select, the manifest of every package the workspace
2642
+ * builds, and the repository's nextest config.
2211
2643
  *
2212
2644
  * Workspace-anchored for the reason `cargoPackageTestInputs` gives: a
2213
2645
  * `{projectRoot}` glob hashes only files this project owns, and sibling manifests
2214
2646
  * belong to whichever nested project holds them. A workspace nextest build unifies
2215
- * features across every selected member, so a sibling manifest can change a crate's
2216
- * tests without being a path dependency: track those manifests, not unrelated
2217
- * sibling sources.
2647
+ * features across every package it compiles, so a sibling manifest can change a
2648
+ * crate's tests without being a path dependency: a member's, and a path package's
2649
+ * that reaches the build only as another crate's dev-dependency. Track those
2650
+ * manifests, not unrelated sibling sources.
2218
2651
  *
2219
2652
  * The repository's own nextest config layers OVER the plugin's tool config, so it
2220
2653
  * decides timeouts, groups and archive contents: a cached verdict that ignored it
@@ -2227,14 +2660,39 @@ async function cargoTestRunnerInputs(workspaceRoot, workspace, memberDirs) {
2227
2660
  absoluteProjectRoot: join(workspaceRoot, workspace.projectRoot),
2228
2661
  memberDir,
2229
2662
  cache: workspace.inputsCache,
2663
+ cargo: workspace.closureSource.cargo,
2230
2664
  })));
2665
+ // The archive unifies every built package's manifest into every test binary, and a runner's key does not follow the
2666
+ // archive's outputs, so each runner names them all: the ones Nx holds as files, the rest through the repository's
2667
+ // runtime hash of external sources.
2668
+ const manifests = [];
2669
+ const external = new Map();
2670
+ for (const pkg of workspace.closureSource.cargo.local) {
2671
+ const manifest = relative(workspace.closureSource.root, pkg.manifest);
2672
+ if (manifest === '..' || manifest.startsWith(`..${sep}`) || isAbsolute(manifest)) {
2673
+ external.set(pkg.name, pkg.directory);
2674
+ }
2675
+ else {
2676
+ manifests.push(posix.join('{workspaceRoot}', manifest.split(sep).join('/')));
2677
+ }
2678
+ }
2679
+ if (external.size > 0) {
2680
+ requireExternalRustCratesInput(workspaceRoot, posix.join(workspace.projectRoot, 'Cargo.toml'), external);
2681
+ }
2231
2682
  return [
2232
2683
  ...new Set([
2233
2684
  ...sources.flat(),
2234
- ...workspace.packages.map((member) => posix.join(inputRoot, member.package.dir, 'Cargo.toml')),
2685
+ ...manifests,
2686
+ ...(external.size > 0 ? [EXTERNAL_RUST_CRATES_INPUT] : []),
2235
2687
  posix.join(inputRoot, NEXTEST_REPO_CONFIG_PATH),
2236
2688
  ]),
2237
2689
  fileHashInput(PLUGIN_NEXTEST_CONFIG_PATH),
2690
+ // The Cargo.lock entries each selected crate's closure reaches.
2691
+ {
2692
+ externalDependencies: [
2693
+ ...new Set(memberDirs.map((memberDir) => cargoLockNodeName(posix.join(workspace.projectRoot, memberDir)))),
2694
+ ],
2695
+ },
2238
2696
  ];
2239
2697
  }
2240
2698
  /**
@@ -2242,25 +2700,25 @@ async function cargoTestRunnerInputs(workspaceRoot, workspace, memberDirs) {
2242
2700
  * workspace builds its command here, so the extraction, reuse-build, tool config and cwd cannot
2243
2701
  * drift between the per-crate pieces and the serial groups.
2244
2702
  */
2245
- function nextestRunnerCommand(workspace, selector, flags) {
2703
+ function nextestRunnerCommand(workspace, nativeTools, selector, flags) {
2246
2704
  const toolConfig = nextestToolConfigArg(workspace.projectRoot);
2247
2705
  // Relative to the runner's cwd, so the hashed command is the same in every checkout.
2248
- const extractBin = posix.join(posix.relative(workspace.projectRoot, '.'), NEXTEST_EXTRACT_BIN);
2706
+ const extract = nativeToolCommand(nativeTools, workspace.projectRoot, 'nextest-extract', 'smoo-nx-nextest-extract');
2249
2707
  const reuseExtraction = `--binaries-metadata "$extracted/${EXTRACTED_BINARIES_METADATA}" ` +
2250
2708
  `--cargo-metadata "$extracted/${EXTRACTED_CARGO_METADATA}" ` +
2251
2709
  `--target-dir-remap "$extracted/${EXTRACTED_TARGET_DIR}"`;
2252
- return (`extracted="$(node ${extractBin} ${CARGO_TEST_ARCHIVE_FILE})" && ` +
2710
+ return (`extracted="$(${extract} ${CARGO_TEST_ARCHIVE_FILE})" && ` +
2253
2711
  cargoFrozen(`nextest run ${reuseExtraction} --workspace-remap . -E ${shellWord(selector)}${flags} --user-config-file none ${toolConfig}`));
2254
2712
  }
2255
2713
  /** One per-crate piece: a bounded run of its partition of the archive's tests. */
2256
- function cargoTestRunnerTarget(workspace, archive, inputs, piece) {
2714
+ function cargoTestRunnerTarget(workspace, nativeTools, archive, inputs, piece) {
2257
2715
  return {
2258
2716
  executor: '@smoothbricks/nx-plugin:bounded-exec',
2259
2717
  cache: true,
2260
2718
  inputs,
2261
- dependsOn: [archive],
2719
+ dependsOn: [archive, ...nativeToolDependsOn(nativeTools, 'nextest-extract')],
2262
2720
  options: {
2263
- command: nextestRunnerCommand(workspace, piece.selector, `${piece.extra} --no-fail-fast --no-tests=pass`),
2721
+ command: nextestRunnerCommand(workspace, nativeTools, piece.selector, `${piece.extra} --no-fail-fast --no-tests=pass`),
2264
2722
  cwd: workspace.projectRoot,
2265
2723
  idleTimeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
2266
2724
  killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
@@ -2275,14 +2733,14 @@ function cargoTestRunnerTarget(workspace, archive, inputs, piece) {
2275
2733
  * tests and a failed verdict lists the failed ones, and `--no-tests=fail`, so a filter that selects
2276
2734
  * nothing fails rather than passing a group that ran no test.
2277
2735
  */
2278
- function cargoTestGroupTarget(workspace, inputs, group) {
2736
+ function cargoTestGroupTarget(workspace, nativeTools, inputs, group) {
2279
2737
  return {
2280
2738
  executor: '@smoothbricks/nx-plugin:bounded-exec',
2281
2739
  cache: true,
2282
2740
  inputs: [...inputs, fileHashInput(PLUGIN_NEXTEST_CODE_BOUND)],
2283
- dependsOn: [CARGO_TEST_ARCHIVE_TARGET],
2741
+ dependsOn: [CARGO_TEST_ARCHIVE_TARGET, ...nativeToolDependsOn(nativeTools, 'nextest-extract')],
2284
2742
  options: {
2285
- command: nextestRunnerCommand(workspace, group.filter, ' --no-fail-fast --no-tests=fail'),
2743
+ command: nextestRunnerCommand(workspace, nativeTools, group.filter, ' --no-fail-fast --no-tests=fail'),
2286
2744
  cwd: workspace.projectRoot,
2287
2745
  idleTimeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
2288
2746
  killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,