@smoothbricks/nx-plugin 0.4.26 → 0.4.27

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 (343) hide show
  1. package/README.md +994 -117
  2. package/dist/bin/smoo-nx-bound-failures.d.ts +3 -0
  3. package/dist/bin/smoo-nx-bound-failures.d.ts.map +1 -0
  4. package/dist/bin/smoo-nx-bound-failures.js +31 -0
  5. package/dist/bin/smoo-nx-cargo-hash.js +28 -3
  6. package/dist/bin/smoo-nx-exec.js +15 -73
  7. package/dist/bin/smoo-nx-failures.d.ts +3 -0
  8. package/dist/bin/smoo-nx-failures.d.ts.map +1 -0
  9. package/dist/bin/smoo-nx-failures.js +3 -0
  10. package/dist/bin/smoo-nx-nextest-extract.js +3 -2
  11. package/dist/bin/smoo-nx-test-walks.d.ts +3 -0
  12. package/dist/bin/smoo-nx-test-walks.d.ts.map +1 -0
  13. package/dist/bin/smoo-nx-test-walks.js +34 -0
  14. package/dist/bounded-test-policy.d.ts +7 -1
  15. package/dist/bounded-test-policy.d.ts.map +1 -1
  16. package/dist/bounded-test-policy.js +101 -40
  17. package/dist/build-state-output-policy.d.ts +25 -0
  18. package/dist/build-state-output-policy.d.ts.map +1 -0
  19. package/dist/build-state-output-policy.js +64 -0
  20. package/dist/cargo-closure-input.d.ts +3 -2
  21. package/dist/cargo-closure-input.d.ts.map +1 -1
  22. package/dist/cargo-closure-input.js +16 -15
  23. package/dist/cargo-dev-profile.d.ts +37 -0
  24. package/dist/cargo-dev-profile.d.ts.map +1 -0
  25. package/dist/cargo-dev-profile.js +108 -0
  26. package/dist/cargo-source-hash.d.ts +43 -6
  27. package/dist/cargo-source-hash.d.ts.map +1 -1
  28. package/dist/cargo-source-hash.js +309 -73
  29. package/dist/cargo-toolchain-policy.d.ts +4 -0
  30. package/dist/cargo-toolchain-policy.d.ts.map +1 -1
  31. package/dist/cargo-toolchain-policy.js +5 -0
  32. package/dist/cargo-workspace.d.ts +101 -5
  33. package/dist/cargo-workspace.d.ts.map +1 -1
  34. package/dist/cargo-workspace.js +291 -10
  35. package/dist/cross-check-policy.d.ts +21 -3
  36. package/dist/cross-check-policy.d.ts.map +1 -1
  37. package/dist/cross-check-policy.js +24 -6
  38. package/dist/disk-command-policy.d.ts +7 -0
  39. package/dist/disk-command-policy.d.ts.map +1 -0
  40. package/dist/disk-command-policy.js +98 -0
  41. package/dist/ensure-built-receipt.d.ts +25 -0
  42. package/dist/ensure-built-receipt.d.ts.map +1 -0
  43. package/dist/ensure-built-receipt.js +261 -0
  44. package/dist/ensure-built-witness.d.ts +57 -0
  45. package/dist/ensure-built-witness.d.ts.map +1 -0
  46. package/dist/ensure-built-witness.js +412 -0
  47. package/dist/ensure-built.d.ts +207 -12
  48. package/dist/ensure-built.d.ts.map +1 -1
  49. package/dist/ensure-built.js +576 -202
  50. package/dist/eslint-file-set.d.ts +7 -0
  51. package/dist/eslint-file-set.d.ts.map +1 -0
  52. package/dist/eslint-file-set.js +12 -0
  53. package/dist/executors/bounded-exec/cpu-pool.d.ts +63 -0
  54. package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -0
  55. package/dist/executors/bounded-exec/cpu-pool.js +379 -0
  56. package/dist/executors/bounded-exec/cpu-tokens.d.ts +82 -0
  57. package/dist/executors/bounded-exec/cpu-tokens.d.ts.map +1 -0
  58. package/dist/executors/bounded-exec/cpu-tokens.js +114 -0
  59. package/dist/executors/bounded-exec/disk-lease.d.ts +61 -0
  60. package/dist/executors/bounded-exec/disk-lease.d.ts.map +1 -0
  61. package/dist/executors/bounded-exec/disk-lease.js +91 -0
  62. package/dist/executors/bounded-exec/executor.d.ts +45 -2
  63. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  64. package/dist/executors/bounded-exec/executor.js +447 -52
  65. package/dist/executors/bounded-exec/gateway-lease.d.ts +52 -0
  66. package/dist/executors/bounded-exec/gateway-lease.d.ts.map +1 -0
  67. package/dist/executors/bounded-exec/gateway-lease.js +143 -0
  68. package/dist/executors/bounded-exec/hang-diagnostics.d.ts +35 -0
  69. package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -0
  70. package/dist/executors/bounded-exec/hang-diagnostics.js +231 -0
  71. package/dist/executors/bounded-exec/progress.d.ts +35 -0
  72. package/dist/executors/bounded-exec/progress.d.ts.map +1 -0
  73. package/dist/executors/bounded-exec/progress.js +79 -0
  74. package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts +3 -0
  75. package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts.map +1 -0
  76. package/dist/executors/bounded-exec/ram-temp-fixtures.js +12 -0
  77. package/dist/executors/bounded-exec/ram-temp-held.d.ts +91 -0
  78. package/dist/executors/bounded-exec/ram-temp-held.d.ts.map +1 -0
  79. package/dist/executors/bounded-exec/ram-temp-held.js +152 -0
  80. package/dist/executors/bounded-exec/ram-temp.d.ts +223 -0
  81. package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -0
  82. package/dist/executors/bounded-exec/ram-temp.js +1528 -0
  83. package/dist/executors/bounded-exec/schema.d.ts +29 -11
  84. package/dist/executors/bounded-exec/schema.d.ts.map +1 -1
  85. package/dist/executors/bounded-exec/verdict.d.ts +162 -0
  86. package/dist/executors/bounded-exec/verdict.d.ts.map +1 -0
  87. package/dist/executors/bounded-exec/verdict.js +318 -0
  88. package/dist/executors/shard-timings/executor.d.ts +14 -0
  89. package/dist/executors/shard-timings/executor.d.ts.map +1 -0
  90. package/dist/executors/shard-timings/executor.js +25 -0
  91. package/dist/executors/shard-timings/schema.d.ts +4 -0
  92. package/dist/executors/shard-timings/schema.d.ts.map +1 -0
  93. package/dist/executors/shard-timings/schema.js +1 -0
  94. package/dist/failure-summary.d.ts +5 -0
  95. package/dist/failure-summary.d.ts.map +1 -0
  96. package/dist/failure-summary.js +118 -0
  97. package/dist/generators/create-package/generator.d.ts.map +1 -1
  98. package/dist/generators/create-package/generator.js +6 -2
  99. package/dist/index.d.ts +14 -2
  100. package/dist/index.d.ts.map +1 -1
  101. package/dist/index.js +370 -138
  102. package/dist/managed-files/ci-workflow.d.ts +13 -0
  103. package/dist/managed-files/ci-workflow.d.ts.map +1 -1
  104. package/dist/managed-files/ci-workflow.js +44 -13
  105. package/dist/managed-files/files.d.ts +7 -1
  106. package/dist/managed-files/files.d.ts.map +1 -1
  107. package/dist/managed-files/files.js +62 -8
  108. package/dist/managed-files/json-edit.d.ts +21 -0
  109. package/dist/managed-files/json-edit.d.ts.map +1 -0
  110. package/dist/managed-files/json-edit.js +295 -0
  111. package/dist/managed-files/managed-format.d.ts +33 -1
  112. package/dist/managed-files/managed-format.d.ts.map +1 -1
  113. package/dist/managed-files/managed-format.js +82 -2
  114. package/dist/managed-files/pr-preview-cleanup-workflow.d.ts +7 -0
  115. package/dist/managed-files/pr-preview-cleanup-workflow.d.ts.map +1 -1
  116. package/dist/managed-files/pr-preview-cleanup-workflow.js +68 -4
  117. package/dist/managed-files/publish-workflow.d.ts.map +1 -1
  118. package/dist/managed-files/publish-workflow.js +231 -48
  119. package/dist/managed-files/tree.d.ts +5 -0
  120. package/dist/managed-files/tree.d.ts.map +1 -1
  121. package/dist/managed-files/tree.js +5 -3
  122. package/dist/manifest-hash.d.ts.map +1 -1
  123. package/dist/manifest-hash.js +2 -5
  124. package/dist/nextest-code-bound.d.ts +62 -0
  125. package/dist/nextest-code-bound.d.ts.map +1 -0
  126. package/dist/nextest-code-bound.js +154 -0
  127. package/dist/nextest-extraction.d.ts +24 -8
  128. package/dist/nextest-extraction.d.ts.map +1 -1
  129. package/dist/nextest-extraction.js +42 -7
  130. package/dist/package-target-policy.d.ts.map +1 -1
  131. package/dist/package-target-policy.js +3 -5
  132. package/dist/release-config-policy.d.ts.map +1 -1
  133. package/dist/release-config-policy.js +3 -5
  134. package/dist/runtime-input.d.ts +14 -0
  135. package/dist/runtime-input.d.ts.map +1 -0
  136. package/dist/runtime-input.js +15 -0
  137. package/dist/rust-tokens.d.ts +11 -0
  138. package/dist/rust-tokens.d.ts.map +1 -0
  139. package/dist/rust-tokens.js +81 -0
  140. package/dist/task-results.d.ts +6 -0
  141. package/dist/task-results.d.ts.map +1 -0
  142. package/dist/task-results.js +61 -0
  143. package/dist/test-program.d.ts +54 -0
  144. package/dist/test-program.d.ts.map +1 -0
  145. package/dist/test-program.js +292 -0
  146. package/dist/test-timings.d.ts +71 -0
  147. package/dist/test-timings.d.ts.map +1 -0
  148. package/dist/test-timings.js +393 -0
  149. package/dist/test-walk-policy.d.ts +103 -0
  150. package/dist/test-walk-policy.d.ts.map +1 -0
  151. package/dist/test-walk-policy.js +657 -0
  152. package/dist/testing.d.ts +177 -0
  153. package/dist/testing.d.ts.map +1 -0
  154. package/dist/testing.js +824 -0
  155. package/dist/type-guards.d.ts +3 -0
  156. package/dist/type-guards.d.ts.map +1 -0
  157. package/dist/type-guards.js +4 -0
  158. package/dist/typecheck-test-policy.d.ts +8 -5
  159. package/dist/typecheck-test-policy.d.ts.map +1 -1
  160. package/dist/typecheck-test-policy.js +113 -100
  161. package/dist/workspace-config-policy.d.ts +8 -0
  162. package/dist/workspace-config-policy.d.ts.map +1 -1
  163. package/dist/workspace-config-policy.js +175 -63
  164. package/dist/workspace-index.d.ts +12 -0
  165. package/dist/workspace-index.d.ts.map +1 -0
  166. package/dist/workspace-index.js +17 -0
  167. package/dist/workspace-manifest.d.ts +37 -0
  168. package/dist/workspace-manifest.d.ts.map +1 -1
  169. package/executors.json +5 -0
  170. package/loader.js +13 -11
  171. package/managed/raw/envrc +33 -67
  172. package/managed/raw/git-format-staged.yml +30 -35
  173. package/managed/raw/patches/nx@23.2.1.patch +3484 -0
  174. package/managed/raw/tooling/direnv/apple-developer.sh +83 -0
  175. package/managed/raw/tooling/direnv/developer-links.ts +569 -11
  176. package/managed/raw/tooling/direnv/devenv.smoo.nix +314 -93
  177. package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +20 -11
  178. package/managed/raw/tooling/direnv/linked-snapshots.ts +845 -0
  179. package/managed/raw/tooling/direnv/nx-socket-dir.sh +82 -0
  180. package/managed/raw/tooling/direnv/repo-path +14 -2
  181. package/managed/raw/tooling/direnv/setup-environment.ts +962 -148
  182. package/managed/raw/tooling/direnv/toolchain-stamp.ts +45 -3
  183. package/managed/raw/tooling/direnv/ttsc-env.sh +39 -0
  184. package/managed/raw/tooling/git-hooks/commit-msg.sh +5 -6
  185. package/managed/raw/tooling/git-hooks/pre-commit.sh +7 -6
  186. package/managed/raw/tooling/git-hooks/pre-push.sh +20 -15
  187. package/managed/templates/github/actions/cache-nix-devenv/action.yml +6 -6
  188. package/managed/templates/github/actions/cache-node-modules/action.yml +6 -4
  189. package/managed/templates/github/actions/cache-nx/action.yml +1 -1
  190. package/managed/templates/github/actions/cache-ttsc-plugins/action.yml +1 -1
  191. package/managed/templates/github/actions/forgejo-artifact.cjs +99 -0
  192. package/managed/templates/github/actions/forgejo-download-artifact/action.yml +49 -0
  193. package/managed/templates/github/actions/forgejo-download-artifact/index.cjs +7 -0
  194. package/managed/templates/github/actions/forgejo-upload-artifact/action.yml +65 -0
  195. package/managed/templates/github/actions/forgejo-upload-artifact/index.cjs +7 -0
  196. package/managed/templates/github/actions/setup-devenv/action.yml +21 -3
  197. package/managed/templates/github/workflows/managed-files.yml +1 -2
  198. package/nextest.toml +8 -41
  199. package/package.json +74 -12
  200. package/runtime-input.sh +81 -0
  201. package/src/__tests__/counted-cargo.ts +33 -14
  202. package/src/__tests__/fixture-nx-env.ts +111 -46
  203. package/src/__tests__/progress-clock.ts +43 -0
  204. package/src/__tests__/runtime-input.ts +23 -0
  205. package/src/bin/smoo-nx-bound-failures.test.ts +127 -0
  206. package/src/bin/smoo-nx-bound-failures.ts +33 -0
  207. package/src/bin/smoo-nx-cargo-hash.ts +28 -3
  208. package/src/bin/smoo-nx-exec.ts +16 -74
  209. package/src/bin/smoo-nx-failures.ts +4 -0
  210. package/src/bin/smoo-nx-nextest-extract.ts +3 -2
  211. package/src/bin/smoo-nx-test-walks.ts +42 -0
  212. package/src/bounded-test-policy.test.ts +268 -21
  213. package/src/bounded-test-policy.ts +114 -42
  214. package/src/build-state-output-policy.test.ts +115 -0
  215. package/src/build-state-output-policy.ts +90 -0
  216. package/src/bun-bootstrap.test.ts +57 -3
  217. package/src/bun-file-packages.test.ts +47 -0
  218. package/src/cargo-closure-input.test.ts +138 -66
  219. package/src/cargo-closure-input.ts +17 -15
  220. package/src/cargo-dev-profile.ts +137 -0
  221. package/src/cargo-resolve-cache.test.ts +70 -1
  222. package/src/cargo-source-hash.test.ts +193 -97
  223. package/src/cargo-source-hash.ts +345 -68
  224. package/src/cargo-toolchain-policy.ts +6 -0
  225. package/src/cargo-workspace.test.ts +320 -0
  226. package/src/cargo-workspace.ts +336 -10
  227. package/src/cross-check-policy.test.ts +59 -1
  228. package/src/cross-check-policy.ts +25 -6
  229. package/src/disk-command-policy.test.ts +61 -0
  230. package/src/disk-command-policy.ts +107 -0
  231. package/src/ensure-built-receipt.test.ts +184 -0
  232. package/src/ensure-built-receipt.ts +263 -0
  233. package/src/ensure-built-witness.test.ts +344 -0
  234. package/src/ensure-built-witness.ts +252 -0
  235. package/src/ensure-built.test.ts +1036 -578
  236. package/src/ensure-built.ts +820 -224
  237. package/src/eslint-file-set.ts +9 -0
  238. package/src/executors/bounded-exec/cpu-pool.test.ts +454 -0
  239. package/src/executors/bounded-exec/cpu-pool.ts +417 -0
  240. package/src/executors/bounded-exec/cpu-tokens.test.ts +269 -0
  241. package/src/executors/bounded-exec/cpu-tokens.ts +177 -0
  242. package/src/executors/bounded-exec/disk-lease.test.ts +185 -0
  243. package/src/executors/bounded-exec/disk-lease.ts +139 -0
  244. package/src/executors/bounded-exec/executor-host.test.ts +778 -0
  245. package/src/executors/bounded-exec/executor.test.ts +1116 -63
  246. package/src/executors/bounded-exec/executor.ts +565 -67
  247. package/src/executors/bounded-exec/gateway-lease.ts +176 -0
  248. package/src/executors/bounded-exec/hang-diagnostics.test.ts +285 -0
  249. package/src/executors/bounded-exec/hang-diagnostics.ts +283 -0
  250. package/src/executors/bounded-exec/progress.test.ts +79 -0
  251. package/src/executors/bounded-exec/progress.ts +118 -0
  252. package/src/executors/bounded-exec/ram-temp-fixtures.ts +12 -0
  253. package/src/executors/bounded-exec/ram-temp-held.test.ts +264 -0
  254. package/src/executors/bounded-exec/ram-temp-held.ts +242 -0
  255. package/src/executors/bounded-exec/ram-temp-host.test.ts +605 -0
  256. package/src/executors/bounded-exec/ram-temp.test.ts +674 -0
  257. package/src/executors/bounded-exec/ram-temp.ts +1918 -0
  258. package/src/executors/bounded-exec/schema.json +11 -5
  259. package/src/executors/bounded-exec/schema.ts +27 -11
  260. package/src/executors/bounded-exec/verdict.test.ts +440 -0
  261. package/src/executors/bounded-exec/verdict.ts +433 -0
  262. package/src/executors/shard-timings/executor.ts +36 -0
  263. package/src/executors/shard-timings/schema.json +21 -0
  264. package/src/executors/shard-timings/schema.ts +4 -0
  265. package/src/failure-summary.ts +119 -0
  266. package/src/generators/bounded-test-targets/generator.test.ts +4 -4
  267. package/src/generators/bun-test-tracing/generator.test.ts +2 -2
  268. package/src/generators/create-package/generator.test.ts +6 -0
  269. package/src/generators/create-package/generator.ts +6 -2
  270. package/src/host-controller-wiring.test.ts +31 -0
  271. package/src/index.test.ts +909 -295
  272. package/src/index.ts +441 -143
  273. package/src/linked-snapshots.nx.test.ts +172 -0
  274. package/src/managed-files/ci-workflow.ts +54 -13
  275. package/src/managed-files/files.ts +65 -9
  276. package/src/managed-files/forgejo-artifact.test.ts +395 -0
  277. package/src/managed-files/generator.test.ts +60 -1
  278. package/src/managed-files/json-edit.test.ts +216 -0
  279. package/src/managed-files/json-edit.ts +290 -0
  280. package/src/managed-files/managed-format-json.test.ts +308 -0
  281. package/src/managed-files/managed-format.ts +90 -2
  282. package/src/managed-files/pr-preview-cleanup-workflow.ts +69 -3
  283. package/src/managed-files/publish-workflow.ts +285 -67
  284. package/src/managed-files/repo-path.test.ts +129 -0
  285. package/src/managed-files/trace-db-artifact.test.ts +7 -0
  286. package/src/managed-files/tree.ts +11 -3
  287. package/src/manifest-hash.ts +2 -6
  288. package/src/nextest-code-bound.test.ts +155 -0
  289. package/src/nextest-code-bound.ts +195 -0
  290. package/src/nextest-extraction.test.ts +37 -5
  291. package/src/nextest-extraction.ts +51 -9
  292. package/src/nextest-partitions.test.ts +427 -82
  293. package/src/nx-cache-bound.test.ts +5 -10
  294. package/src/nx-cache-restore-mtime.test.ts +170 -0
  295. package/src/nx-daemon-claim.test.ts +277 -0
  296. package/src/nx-daemon-idle-cpu.test.ts +81 -0
  297. package/src/nx-daemon-idle-policy.test.ts +51 -0
  298. package/src/nx-daemon-ignore-files.test.ts +210 -0
  299. package/src/nx-daemon-root-normalization.test.ts +105 -0
  300. package/src/nx-daemon-validity.test.ts +925 -0
  301. package/src/nx-dot-input-policy.test.ts +353 -0
  302. package/src/nx-failure-life-cycles.test.ts +207 -0
  303. package/src/nx-files-archive-racy.test.ts +97 -0
  304. package/src/nx-foreign-workspace-env.test.ts +329 -0
  305. package/src/nx-incomplete-run-summary.test.ts +70 -0
  306. package/src/nx-plugin-load-errors.test.ts +120 -0
  307. package/src/nx-project-resolution-cache.test.ts +176 -0
  308. package/src/nx-raw-inputs.test.ts +166 -0
  309. package/src/nx-resident-graph-workers.test.ts +7 -16
  310. package/src/nx-run-information.test.ts +118 -0
  311. package/src/nx-skipped-task-exit.test.ts +180 -0
  312. package/src/nx-state-location.test.ts +63 -0
  313. package/src/nx-store-resolution.test.ts +26 -25
  314. package/src/nx-task-graph-cycles.test.ts +148 -0
  315. package/src/nx-task-output-lease.test.ts +414 -0
  316. package/src/nx-use-local.test.ts +103 -0
  317. package/src/package-target-policy.ts +3 -6
  318. package/src/release-config-policy.ts +3 -6
  319. package/src/runtime-input.test.ts +215 -0
  320. package/src/runtime-input.ts +17 -0
  321. package/src/rust-tokens.ts +78 -0
  322. package/src/serial-group-wiring.test.ts +326 -0
  323. package/src/task-history-namespace.test.ts +87 -89
  324. package/src/task-results.test.ts +226 -0
  325. package/src/task-results.ts +75 -0
  326. package/src/test-program.test.ts +303 -0
  327. package/src/test-program.ts +341 -0
  328. package/src/test-timings.test.ts +240 -0
  329. package/src/test-timings.ts +311 -0
  330. package/src/test-walk-policy.test.ts +585 -0
  331. package/src/test-walk-policy.ts +731 -0
  332. package/src/testing.test.ts +509 -0
  333. package/src/testing.ts +922 -0
  334. package/src/type-guards.ts +4 -0
  335. package/src/typecheck-test-policy.test.ts +496 -11
  336. package/src/typecheck-test-policy.ts +137 -103
  337. package/src/workspace-config-policy.test.ts +212 -13
  338. package/src/workspace-config-policy.ts +101 -73
  339. package/src/workspace-index.ts +18 -0
  340. package/src/workspace-manifest.ts +41 -0
  341. package/test-timings.json +85 -30
  342. package/managed/raw/tooling/direnv/inherited-devenv.ts +0 -665
  343. package/managed/raw/tooling/direnv/shared-caches.sh +0 -53
@@ -1,14 +1,16 @@
1
1
  import { execFileSync, spawn, spawnSync } from 'node:child_process';
2
2
  import { createHash, randomUUID } from 'node:crypto';
3
3
  import { channel } from 'node:diagnostics_channel';
4
- import { constants, realpathSync, statSync } from 'node:fs';
4
+ import { constants, existsSync, readdirSync, readFileSync, realpathSync, statSync } from 'node:fs';
5
5
  import { access, lstat, mkdir, readdir, readFile, readlink, realpath, rename, rm, stat, writeFile, } from 'node:fs/promises';
6
+ import { createRequire } from 'node:module';
6
7
  import { homedir } from 'node:os';
7
8
  import { delimiter, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
8
9
  import native from 'nx/src/native/index.js';
9
10
  import { workspaceDataDirectoryForWorkspace } from 'nx/src/utils/cache-directory.js';
10
11
  import { CARGO_TOOLCHAIN_PIN_INPUTS } from './cargo-toolchain-policy.js';
11
- const { FileLock, IS_WASM, WorkspaceContext } = native;
12
+ import { rustTokens } from './rust-tokens.js';
13
+ const { IS_WASM, WorkspaceContext } = native;
12
14
  const cargoResolveEvents = channel('@smoothbricks/nx-plugin:cargo-resolve');
13
15
  /**
14
16
  * Narrowed field by field, not by typia: graph inference imports this module,
@@ -32,6 +34,8 @@ function parseCargoMetadata(json) {
32
34
  return {
33
35
  packages: list(member(document, 'packages'), 'packages').map((pkg) => ({
34
36
  id: text(member(pkg, 'id'), 'package id'),
37
+ name: text(member(pkg, 'name'), 'package name'),
38
+ version: text(member(pkg, 'version'), 'package version'),
35
39
  source: member(pkg, 'source') === null ? null : text(member(pkg, 'source'), 'package source'),
36
40
  manifest_path: text(member(pkg, 'manifest_path'), 'package manifest_path'),
37
41
  targets: list(member(pkg, 'targets'), 'package targets').map((target) => ({
@@ -60,6 +64,9 @@ function parseCargoMetadata(json) {
60
64
  * Cargo groups. Standalone callers need signal forwarding after detaching
61
65
  * Cargo from the terminal; handlers are installed only where the caller has
62
66
  * not already chosen a signal disposition, and removed after the last child.
67
+ * The hooks are in place before the first child is spawned: a child runs as
68
+ * soon as it is spawned, and a signal that reached this process before its
69
+ * hooks would end it on the default action with Cargo's group left running.
63
70
  * Uncatchable SIGKILL cannot execute either hook.
64
71
  */
65
72
  const cargoChildren = new Set();
@@ -107,6 +114,10 @@ function ownCargoChildren() {
107
114
  forwardedSignals.add(signal);
108
115
  }
109
116
  }
117
+ function disownCargoChildren() {
118
+ process.removeListener('exit', killCargoChildren);
119
+ removeCargoSignalHandlers();
120
+ }
110
121
  /**
111
122
  * Cargo's stdout, or its failure with Cargo's stderr in the message. Not
112
123
  * `promisify` from `node:util`: importing that module makes Node probe color
@@ -115,15 +126,28 @@ function ownCargoChildren() {
115
126
  * under its own pid, which a runtime input would hash as a new digest on
116
127
  * every run.
117
128
  */
118
- function runCargo(args, cwd) {
129
+ function runCargo(args, cwd, boundMs = CARGO_RESOLVE_BOUND_MS) {
119
130
  // spawn forwards detached groups; execFile does not. The public ES2022
120
131
  // library API requires the constructor form, not Promise.withResolvers.
121
132
  return new Promise((settle, reject) => {
122
- const child = spawn('cargo', args, {
123
- cwd,
124
- detached: process.platform !== 'win32',
125
- stdio: ['ignore', 'pipe', 'pipe'],
126
- });
133
+ // Hooks first: a signal caught from here on runs its listener after this
134
+ // synchronous body, by which time the child is in `cargoChildren`.
135
+ if (cargoChildren.size === 0)
136
+ ownCargoChildren();
137
+ let child;
138
+ try {
139
+ child = spawn('cargo', args, {
140
+ cwd,
141
+ detached: process.platform !== 'win32',
142
+ stdio: ['ignore', 'pipe', 'pipe'],
143
+ });
144
+ }
145
+ catch (error) {
146
+ if (cargoChildren.size === 0)
147
+ disownCargoChildren();
148
+ throw error;
149
+ }
150
+ cargoChildren.add(child);
127
151
  let stdout = '';
128
152
  let stderr = '';
129
153
  let stdoutBytes = 0;
@@ -133,6 +157,8 @@ function runCargo(args, cwd) {
133
157
  failure ??= error;
134
158
  killCargoChild(child);
135
159
  };
160
+ const timer = setTimeout(() => fail(new Error(`cargo ${args.join(' ')} in ${cwd} did not finish within ${boundMs}ms; killed it, ` +
161
+ 'because an unbounded Cargo wait hangs every project-graph construction with no output')), boundMs);
136
162
  child.stdout.setEncoding('utf8');
137
163
  child.stderr.setEncoding('utf8');
138
164
  child.stdout.on('data', (chunk) => {
@@ -161,11 +187,10 @@ function runCargo(args, cwd) {
161
187
  child.stdout.on('error', fail);
162
188
  child.stderr.on('error', fail);
163
189
  child.on('close', (code, signal) => {
190
+ clearTimeout(timer);
164
191
  cargoChildren.delete(child);
165
- if (cargoChildren.size === 0) {
166
- process.removeListener('exit', killCargoChildren);
167
- removeCargoSignalHandlers();
168
- }
192
+ if (cargoChildren.size === 0)
193
+ disownCargoChildren();
169
194
  if (failure !== undefined)
170
195
  reject(failure);
171
196
  else if (code !== 0) {
@@ -174,9 +199,6 @@ function runCargo(args, cwd) {
174
199
  else
175
200
  settle(stdout);
176
201
  });
177
- if (cargoChildren.size === 0)
178
- ownCargoChildren();
179
- cargoChildren.add(child);
180
202
  });
181
203
  }
182
204
  /** Directories the hash never descends into: build output, VCS and volume metadata, installed packages. */
@@ -184,6 +206,7 @@ export const HASH_SKIPPED_DIRECTORIES = [
184
206
  'target',
185
207
  '.git',
186
208
  'node_modules',
209
+ '.nx',
187
210
  '.cache',
188
211
  '.cowshed',
189
212
  '.fseventsd',
@@ -205,8 +228,8 @@ export const CARGO_ANCESTOR_INPUTS = ['Cargo.toml', '.cargo/config', '.cargo/con
205
228
  * directory actually depend on, so an edit to an unrelated workspace member
206
229
  * leaves the digest alone.
207
230
  *
208
- * This covers Rust sources and Cargo configuration, matching the plugin's
209
- * in-workspace Rust inputs. Build scripts' other data/environment inputs remain
231
+ * This covers Rust sources, literal compiled-in files and Cargo configuration,
232
+ * matching the plugin's in-workspace Rust inputs. Build scripts' other data/environment inputs remain
210
233
  * explicit Nx inputs, just as they are for in-workspace crates. Files git
211
234
  * ignores beneath a package are left out, like Nx's own file inputs: a
212
235
  * generated source is its producer's output, which the consuming target hashes
@@ -220,6 +243,18 @@ export const CARGO_ANCESTOR_INPUTS = ['Cargo.toml', '.cargo/config', '.cargo/con
220
243
  // stderr is kept for the failure path only, where runCargo includes it in the
221
244
  // rejected error. Git runs under the same rule.
222
245
  const CHILD_STDIO = ['ignore', 'pipe', 'pipe'];
246
+ /**
247
+ * Git reads only the repository, never the operator's home (cowshed
248
+ * `04_sandbox.md`, runtime inputs). A host client's runtime input runs in a
249
+ * workspace's sandboxed daemon with the host's HOME: git dies on the global
250
+ * configuration the sandbox denies, and its global ignore file
251
+ * (`~/.config/git/ignore`, read even without a global configuration) would
252
+ * decide which sources the key covers. Neither belongs to the tree.
253
+ */
254
+ const ISOLATED_GIT_ARGS = ['-c', 'core.excludesFile=/dev/null'];
255
+ function isolatedGitEnv() {
256
+ return { ...process.env, GIT_CONFIG_GLOBAL: '/dev/null', GIT_CONFIG_NOSYSTEM: '1' };
257
+ }
223
258
  /** A Cargo resolution refusal: no stale closure or runtime whole-workspace substitute is safe. */
224
259
  export class CargoMetadataError extends Error {
225
260
  manifestPath;
@@ -235,7 +270,15 @@ export class CargoMetadataError extends Error {
235
270
  }
236
271
  }
237
272
  const resolves = new Map();
238
- const RESOLVE_CACHE_SCHEMA = 'cargo-resolve-v1';
273
+ // v2 retains package name/version for checkout-independent artifact input identities.
274
+ const RESOLVE_CACHE_SCHEMA = 'cargo-resolve-v2';
275
+ /**
276
+ * The longest one Cargo child, or one wait for a foreign resolve flight's lock, may take.
277
+ * Both waits sit on every project-graph construction, so an unbounded one is a silent,
278
+ * output-free hang of every gate that resolves the graph (a stopped lock holder, a Cargo
279
+ * process convoy): at the bound the wait fails, naming what it waited on and for how long.
280
+ */
281
+ export const CARGO_RESOLVE_BOUND_MS = 300_000;
239
282
  /**
240
283
  * The full manifest SET, not merely the last closure: adding a glob workspace
241
284
  * member must invalidate resolution even when Cargo.lock did not change.
@@ -322,6 +365,8 @@ function cargoFromMetadata(metadata) {
322
365
  throw new Error('Cargo cache omitted a governing manifest');
323
366
  return {
324
367
  id: pkg.id,
368
+ name: pkg.name,
369
+ version: pkg.version,
325
370
  directory: dirname(pkg.manifest_path),
326
371
  manifest: pkg.manifest_path,
327
372
  sources: pkg.targets.map((target) => target.src_path),
@@ -358,12 +403,11 @@ async function loadResolveCache(file) {
358
403
  }
359
404
  /**
360
405
  * One content-keyed resolution per Cargo workspace, across concurrent graph
361
- * calls and workers. Nx's kernel FileLock releases even if its worker dies;
362
- * in-process callers join before taking that lock, so a synchronous lock()
363
- * cannot block the continuation that owns it. A changed key queues behind
364
- * the old child instead of receiving its stale answer.
406
+ * calls and workers. A bounded child owns Nx's kernel FileLock while the
407
+ * resolution runs; in-process callers join before asking for that lease.
408
+ * A changed key queues behind the old child instead of receiving its stale answer.
365
409
  */
366
- export async function readCargoResolve(manifestPath, cwd, indexed) {
410
+ export async function readCargoResolve(manifestPath, cwd, indexed, boundMs = CARGO_RESOLVE_BOUND_MS) {
367
411
  let manifest = resolve(manifestPath);
368
412
  try {
369
413
  const root = await realpath(cwd);
@@ -416,7 +460,7 @@ export async function readCargoResolve(manifestPath, cwd, indexed) {
416
460
  if (joined === 3)
417
461
  break;
418
462
  const active = state;
419
- const promise = resolveAndCache(root, manifest, index, directory, file, active);
463
+ const promise = resolveAndCache(root, manifest, index, directory, file, active, boundMs);
420
464
  active.pending = { key, promise };
421
465
  try {
422
466
  return await promise;
@@ -434,17 +478,20 @@ export async function readCargoResolve(manifestPath, cwd, indexed) {
434
478
  throw new CargoMetadataError(manifest, error);
435
479
  }
436
480
  }
437
- async function resolveAndCache(root, manifest, indexed, directory, file, state) {
481
+ async function resolveAndCache(root, manifest, indexed, directory, file, state, boundMs = CARGO_RESOLVE_BOUND_MS) {
438
482
  if (IS_WASM)
439
483
  throw new Error('Cargo resolution requires the native Nx file lock; a WASM Nx host cannot own Cargo children');
440
484
  await mkdir(directory, { recursive: true });
485
+ // A warm cache answers with no lock: reading it and keying it spawns nothing and
486
+ // waits for nobody, so an unchanged workspace never queues behind a foreign flight.
487
+ state.cached = await loadResolveCache(file);
488
+ {
489
+ const key = await resolutionKey(root, manifest, state.cached?.cargo ?? null, indexed);
490
+ if (state.cached?.key === key)
491
+ return state.cached.cargo;
492
+ }
441
493
  const lockFile = join(directory, 'resolve.lock');
442
- const lock = new FileLock(lockFile);
443
- while (lock.check())
444
- await lock.wait();
445
- // Nx's lock() is synchronous: losing this inter-process check/acquire race
446
- // can block for one foreign flight. Only the in-process leader reaches it.
447
- lock.lock();
494
+ const lock = await acquireCargoResolveLock(lockFile, boundMs);
448
495
  try {
449
496
  // Another worker may have populated it while this worker waited.
450
497
  state.cached = await loadResolveCache(file);
@@ -458,7 +505,7 @@ async function resolveAndCache(root, manifest, indexed, directory, file, state)
458
505
  // discovered external input edited during this flight requires replay.
459
506
  await writeFile(lockFile, '');
460
507
  const started = (await stat(lockFile)).mtimeMs;
461
- const metadata = await resolveCargoMetadata(manifest, root);
508
+ const metadata = await resolveCargoMetadata(manifest, root, boundMs);
462
509
  const cargo = cargoFromMetadata(metadata);
463
510
  // Capture the published key before validation. Reading it afterwards
464
511
  // could pair a post-edit key with Cargo's pre-edit answer.
@@ -494,11 +541,115 @@ async function resolveAndCache(root, manifest, indexed, directory, file, state)
494
541
  throw new Error('Cargo resolution inputs kept changing during three consecutive locked offline queries');
495
542
  }
496
543
  finally {
497
- lock.unlock();
544
+ await lock.release();
545
+ }
546
+ }
547
+ /** A failed acquisition names the lock, elapsed wait, and the reaped waiter. */
548
+ export class CargoResolveLockError extends Error {
549
+ lockFile;
550
+ boundMs;
551
+ waitedMs;
552
+ waiterPid;
553
+ constructor(lockFile, boundMs, waitedMs, waiterPid) {
554
+ super(`waited ${waitedMs}ms for the Cargo resolve lock ${lockFile} (bound ${boundMs}ms; holder pid unknown); ` +
555
+ `killed and reaped lock waiter pid ${waiterPid ?? 'unavailable'} because an unbounded wait hangs project-graph construction`);
556
+ this.lockFile = lockFile;
557
+ this.boundMs = boundMs;
558
+ this.waitedMs = waitedMs;
559
+ this.waiterPid = waiterPid;
560
+ this.name = 'CargoResolveLockError';
498
561
  }
499
562
  }
500
- async function resolveCargoMetadata(manifestPath, cwd) {
501
- const stdout = await runCargo(['metadata', '--format-version', '1', '--locked', '--offline', '--manifest-path', manifestPath], cwd);
563
+ /**
564
+ * The pinned Nx binding has only blocking acquisition. Isolate that syscall in
565
+ * one child per cold flight so the caller's deadline can kill and reap it.
566
+ * Closing stdin releases a successful lease; warm cache reads spawn no child.
567
+ */
568
+ export function acquireCargoResolveLock(lockFile, boundMs) {
569
+ const nativeModule = createRequire(import.meta.url).resolve('nx/src/native/index.js');
570
+ const program = [
571
+ `const { FileLock } = require(${JSON.stringify(nativeModule)});`,
572
+ `const lock = new FileLock(${JSON.stringify(lockFile)});`,
573
+ 'lock.lock();',
574
+ "process.stdout.write('locked\\n');",
575
+ 'process.stdin.resume();',
576
+ "process.stdin.on('end', () => { lock.unlock(); process.exit(0); });",
577
+ ].join('\n');
578
+ // The public ES2022 library API requires the constructor form, not Promise.withResolvers.
579
+ return new Promise((settle, reject) => {
580
+ const started = performance.now();
581
+ const child = spawn(process.execPath, ['--eval', program], {
582
+ detached: process.platform !== 'win32',
583
+ stdio: ['pipe', 'pipe', 'pipe'],
584
+ });
585
+ let acquired = false;
586
+ let releasing = false;
587
+ let failure;
588
+ let stdout = '';
589
+ let stderr = '';
590
+ const fail = (error) => {
591
+ failure ??= error;
592
+ killCargoChild(child);
593
+ };
594
+ const timer = setTimeout(() => fail(new CargoResolveLockError(lockFile, boundMs, Math.ceil(performance.now() - started), child.pid)), boundMs);
595
+ const closed = new Promise((finish) => {
596
+ child.on('close', (code, signal) => {
597
+ clearTimeout(timer);
598
+ cargoChildren.delete(child);
599
+ if (cargoChildren.size === 0) {
600
+ process.removeListener('exit', killCargoChildren);
601
+ removeCargoSignalHandlers();
602
+ }
603
+ if (failure === undefined && (!releasing || code !== 0)) {
604
+ failure = new Error(`Cargo resolve lock ${lockFile} waiter pid ${child.pid} exited (${signal ?? code}): ${stderr.trim()}`);
605
+ }
606
+ if (!acquired)
607
+ reject(failure);
608
+ finish();
609
+ });
610
+ });
611
+ child.stdout.setEncoding('utf8');
612
+ child.stderr.setEncoding('utf8');
613
+ child.stdout.on('data', (chunk) => {
614
+ stdout += chunk;
615
+ if (failure !== undefined || acquired || stdout !== 'locked\n')
616
+ return;
617
+ const waitedMs = Math.ceil(performance.now() - started);
618
+ if (waitedMs >= boundMs) {
619
+ fail(new CargoResolveLockError(lockFile, boundMs, waitedMs, child.pid));
620
+ return;
621
+ }
622
+ if (child.pid === undefined) {
623
+ fail(new Error(`Cargo resolve lock ${lockFile} acquired without a child pid`));
624
+ return;
625
+ }
626
+ acquired = true;
627
+ clearTimeout(timer);
628
+ settle({
629
+ pid: child.pid,
630
+ release: async () => {
631
+ releasing = true;
632
+ child.stdin.end();
633
+ await closed;
634
+ if (failure !== undefined)
635
+ throw failure;
636
+ },
637
+ });
638
+ });
639
+ child.stderr.on('data', (chunk) => {
640
+ stderr += chunk;
641
+ });
642
+ child.on('error', fail);
643
+ child.stdin.on('error', fail);
644
+ child.stdout.on('error', fail);
645
+ child.stderr.on('error', fail);
646
+ if (cargoChildren.size === 0)
647
+ ownCargoChildren();
648
+ cargoChildren.add(child);
649
+ });
650
+ }
651
+ async function resolveCargoMetadata(manifestPath, cwd, boundMs = CARGO_RESOLVE_BOUND_MS) {
652
+ const stdout = await runCargo(['metadata', '--format-version', '1', '--locked', '--offline', '--manifest-path', manifestPath], cwd, boundMs);
502
653
  const metadata = parseCargoMetadata(stdout);
503
654
  metadata.workspace_root = await realpath(metadata.workspace_root);
504
655
  const members = new Set(metadata.workspace_members);
@@ -512,7 +663,7 @@ async function resolveCargoMetadata(manifestPath, cwd) {
512
663
  target.src_path = await realpath(target.src_path);
513
664
  pkg.governing_manifest_path = members.has(pkg.id)
514
665
  ? join(metadata.workspace_root, 'Cargo.toml')
515
- : await realpath((await runCargo(['locate-project', '--workspace', '--manifest-path', pkg.manifest_path, '--message-format', 'plain'], cwd)).trim());
666
+ : await realpath((await runCargo(['locate-project', '--workspace', '--manifest-path', pkg.manifest_path, '--message-format', 'plain'], cwd, boundMs)).trim());
516
667
  }
517
668
  return metadata;
518
669
  }
@@ -520,12 +671,29 @@ export async function hashCargoPathInputs(manifestPath, workspaceRoot, options)
520
671
  const root = await realpath(workspaceRoot);
521
672
  const cargo = await readCargoResolve(manifestPath, root);
522
673
  const members = options?.closure === undefined ? undefined : await dependencyClosure(cargo, resolve(options.closure));
523
- const directories = new Set();
524
- const files = new Set();
674
+ const inputKey = (pkg, role, path) => JSON.stringify([pkg.name, pkg.version, role, path.split(sep).join('/')]);
675
+ const directories = new Map();
676
+ const files = new Map();
525
677
  const ancestors = new Set();
526
678
  const links = new Map();
527
679
  const packageSources = [];
528
- for (const pkg of cargo.local) {
680
+ // Read shared bytes once. The smallest declared identity makes multiple owners
681
+ // deterministic without using a consuming checkout's mount path as an input.
682
+ const includeFile = (file, key) => {
683
+ const prior = files.get(file);
684
+ if (prior === undefined || key < prior)
685
+ files.set(file, key);
686
+ };
687
+ const packages = [...cargo.local].sort((left, right) => left.name < right.name
688
+ ? -1
689
+ : left.name > right.name
690
+ ? 1
691
+ : left.version < right.version
692
+ ? -1
693
+ : left.version > right.version
694
+ ? 1
695
+ : 0);
696
+ for (const pkg of packages) {
529
697
  if (members !== undefined && !members.has(pkg.id))
530
698
  continue;
531
699
  const directory = pkg.directory;
@@ -533,38 +701,36 @@ export async function hashCargoPathInputs(manifestPath, workspaceRoot, options)
533
701
  const fromRoot = relative(root, directory);
534
702
  const fromCargo = relative(cargo.root, directory);
535
703
  if (fromRoot !== '..' &&
536
- !fromRoot.startsWith(`..${sep}`) &&
704
+ !fromRoot.startsWith('..' + sep) &&
537
705
  !isAbsolute(fromRoot) &&
538
706
  fromCargo !== '..' &&
539
- !fromCargo.startsWith(`..${sep}`) &&
707
+ !fromCargo.startsWith('..' + sep) &&
540
708
  !isAbsolute(fromCargo) &&
541
709
  !fromRoot.split(sep).includes('node_modules'))
542
710
  continue;
543
711
  }
544
- directories.add(directory);
545
- files.add(pkg.manifest);
546
- files.add(pkg.governingManifest);
547
- packageSources.push(...pkg.sources);
548
- // A member can inherit edition, lint policy, dependencies and
549
- // profiles from a workspace above its package directory. Those manifests
550
- // are not descendants of the source roots returned by Cargo metadata.
551
- for (let ancestor = dirname(directory); !ancestors.has(ancestor); ancestor = dirname(ancestor)) {
712
+ directories.set(directory, pkg);
713
+ includeFile(pkg.manifest, inputKey(pkg, 'manifest', 'Cargo.toml'));
714
+ includeFile(pkg.governingManifest, inputKey(pkg, 'workspace', 'Cargo.toml'));
715
+ for (const [index, file] of pkg.sources.entries())
716
+ packageSources.push({ file, key: inputKey(pkg, 'target', String(index)) });
717
+ for (let ancestor = dirname(directory), depth = 1; !ancestors.has(ancestor); ancestor = dirname(ancestor), depth += 1) {
552
718
  ancestors.add(ancestor);
553
719
  for (const name of CARGO_ANCESTOR_INPUTS) {
554
720
  const file = join(ancestor, name);
555
- if (statSync(file, { throwIfNoEntry: false })?.isFile())
556
- files.add(await realpath(file));
721
+ if (statSync(file, { throwIfNoEntry: false })?.isFile()) {
722
+ includeFile(await realpath(file), inputKey(pkg, 'ancestor', depth + '/' + name));
723
+ }
557
724
  }
558
725
  }
559
726
  }
560
- const ignored = gitIgnoredBeneath([...directories]);
561
- for (const source of packageSources)
562
- if (!ignored(source))
563
- files.add(source);
727
+ const ignored = gitIgnoredBeneath([...directories.keys()]);
728
+ for (const { file, key } of packageSources)
729
+ if (!ignored(file))
730
+ includeFile(file, key);
564
731
  const skipped = new Set(HASH_SKIPPED_DIRECTORIES);
565
- // Overlapping packages (a facade root plus its child crates) share one walk.
566
732
  const visited = new Set();
567
- async function walk(directory) {
733
+ async function walk(directory, owner, within) {
568
734
  const canonical = await realpath(directory);
569
735
  if (visited.has(canonical))
570
736
  return;
@@ -575,35 +741,43 @@ export async function hashCargoPathInputs(manifestPath, workspaceRoot, options)
575
741
  const path = join(canonical, entry.name);
576
742
  if (ignored(path))
577
743
  continue;
744
+ const localPath = within === '' ? entry.name : within + '/' + entry.name;
578
745
  if (entry.isSymbolicLink())
579
- links.set(path, await readlink(path));
746
+ links.set(path, { key: inputKey(owner, 'link', localPath), target: await readlink(path) });
580
747
  const info = entry.isSymbolicLink() ? await lstat(await realpath(path)) : entry;
581
748
  if (info.isDirectory()) {
582
- await walk(path);
749
+ await walk(path, owner, localPath);
583
750
  }
584
751
  else if (info.isFile() &&
585
752
  (entry.name.endsWith('.rs') ||
586
753
  entry.name === 'Cargo.toml' ||
587
- (canonical.endsWith(`${sep}.cargo`) && (entry.name === 'config' || entry.name === 'config.toml')))) {
588
- files.add(await realpath(path));
754
+ ((within === '.cargo' || within.endsWith('/.cargo')) &&
755
+ (entry.name === 'config' || entry.name === 'config.toml')))) {
756
+ includeFile(await realpath(path), inputKey(owner, 'file', localPath));
757
+ }
758
+ }
759
+ }
760
+ for (const [directory, owner] of directories)
761
+ await walk(directory, owner, '');
762
+ const compiledCache = new Map();
763
+ for (const [directory, owner] of directories) {
764
+ for (const input of compiledInFiles(directory, compiledCache)) {
765
+ if (!ignored(input.file)) {
766
+ includeFile(await realpath(input.file), inputKey(owner, 'include', relative(directory, input.source) + '\0' + input.literal));
589
767
  }
590
768
  }
591
769
  }
592
- for (const directory of directories)
593
- await walk(directory);
594
770
  const hash = createHash('sha256');
595
- hash.update('cargo-path-inputs-v1\0');
596
- for (const [path, target] of [...links].sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0))) {
597
- hash.update(relative(root, path));
771
+ hash.update('cargo-path-inputs-v2\0');
772
+ for (const { key, target } of [...links.values()].sort((left, right) => left.key < right.key ? -1 : left.key > right.key ? 1 : 0)) {
773
+ hash.update(key);
598
774
  hash.update('\0symlink\0');
599
775
  hash.update(target);
600
776
  hash.update('\0');
601
777
  }
602
- for (const file of [...files].sort()) {
778
+ for (const [file, key] of [...files].sort((left, right) => (left[1] < right[1] ? -1 : left[1] > right[1] ? 1 : 0))) {
603
779
  const bytes = await readFile(file);
604
- // Both names and bytes matter: moving a module can change resolution even
605
- // when its contents are unchanged. Length framing makes boundaries unique.
606
- hash.update(relative(root, file));
780
+ hash.update(key);
607
781
  hash.update('\0');
608
782
  hash.update(String(bytes.length));
609
783
  hash.update('\0');
@@ -663,6 +837,7 @@ function gitIgnoredBeneath(directories) {
663
837
  continue;
664
838
  const installed = [...ignoredRoots].map((member) => join(repository, member));
665
839
  const listing = execFileSync('git', [
840
+ ...ISOLATED_GIT_ARGS,
666
841
  '--literal-pathspecs',
667
842
  '-C',
668
843
  repository,
@@ -674,7 +849,7 @@ function gitIgnoredBeneath(directories) {
674
849
  '--directory',
675
850
  '--',
676
851
  ...sourceRoots,
677
- ], { encoding: 'utf8', maxBuffer: 64 * 1024 * 1024, stdio: CHILD_STDIO });
852
+ ], { encoding: 'utf8', maxBuffer: 64 * 1024 * 1024, stdio: CHILD_STDIO, env: isolatedGitEnv() });
678
853
  for (const entry of listing.split('\0')) {
679
854
  if (entry.length === 0)
680
855
  continue;
@@ -692,10 +867,11 @@ function gitIgnoredBeneath(directories) {
692
867
  }
693
868
  /** The members of `paths` (relative to `repository`) that git ignores, own patterns or an ancestor's. */
694
869
  function gitCheckIgnore(repository, paths) {
695
- const result = spawnSync('git', ['-C', repository, 'check-ignore', '-z', '--stdin'], {
870
+ const result = spawnSync('git', [...ISOLATED_GIT_ARGS, '-C', repository, 'check-ignore', '-z', '--stdin'], {
696
871
  input: `${paths.join('\0')}\0`,
697
872
  encoding: 'utf8',
698
873
  maxBuffer: 64 * 1024 * 1024,
874
+ env: isolatedGitEnv(),
699
875
  });
700
876
  // check-ignore answers 1 when nothing is ignored; only 0 carries a listing.
701
877
  if (result.status === 1)
@@ -709,9 +885,10 @@ function gitCheckIgnore(repository, paths) {
709
885
  function gitRepository(directory) {
710
886
  try {
711
887
  // The walk compares realpaths, so git's answer is canonicalized the same way.
712
- return realpathSync(execFileSync('git', ['-C', directory, 'rev-parse', '--show-toplevel'], {
888
+ return realpathSync(execFileSync('git', [...ISOLATED_GIT_ARGS, '-C', directory, 'rev-parse', '--show-toplevel'], {
713
889
  encoding: 'utf8',
714
890
  stdio: CHILD_STDIO,
891
+ env: isolatedGitEnv(),
715
892
  }).trim());
716
893
  }
717
894
  catch (error) {
@@ -725,3 +902,62 @@ function gitRepository(directory) {
725
902
  throw error;
726
903
  }
727
904
  }
905
+ // A tokenized literal macro, never text inside a comment or another string.
906
+ const INCLUDE_CLOSERS = { '(': ')', '[': ']', '{': '}' };
907
+ const INCLUDE_STRING = /^"([^"\\\r\n]*)"$/u;
908
+ const INCLUDE_RAW_STRING = /^r(#*)"([\s\S]*)"\1$/u;
909
+ /**
910
+ * Existing literal include_str!/include_bytes! files read by this package's Rust sources.
911
+ * One graph owns the memo; runtime hashes use a fresh memo. Nested packages own their
912
+ * sources separately. Computed paths and arbitrary build-script reads remain explicit inputs.
913
+ */
914
+ export function compiledInFiles(root, cache) {
915
+ const cached = cache.get(root);
916
+ if (cached !== undefined)
917
+ return cached;
918
+ const found = new Map();
919
+ const skipped = HASH_SKIPPED_DIRECTORIES;
920
+ const scan = [root];
921
+ while (scan.length > 0) {
922
+ const current = scan.pop();
923
+ if (current === undefined || !existsSync(current))
924
+ continue;
925
+ for (const entry of readdirSync(current, { withFileTypes: true })) {
926
+ const child = join(current, entry.name);
927
+ if (entry.isDirectory()) {
928
+ if (!skipped.includes(entry.name) && !existsSync(join(child, 'Cargo.toml')))
929
+ scan.push(child);
930
+ }
931
+ else if (entry.isFile() && entry.name.endsWith('.rs')) {
932
+ const text = readFileSync(child, 'utf8');
933
+ if (!text.includes('include_'))
934
+ continue;
935
+ const tokens = rustTokens(text);
936
+ for (let index = 0; index < tokens.length; index += 1) {
937
+ if (tokens[index]?.text !== 'include_str' && tokens[index]?.text !== 'include_bytes')
938
+ continue;
939
+ if (tokens[index + 1]?.text !== '!')
940
+ continue;
941
+ const closing = INCLUDE_CLOSERS[tokens[index + 2]?.text ?? ''];
942
+ const end = tokens[index + 4]?.text === ',' ? index + 5 : index + 4;
943
+ if (closing === undefined || tokens[end]?.text !== closing)
944
+ continue;
945
+ const literal = tokens[index + 3]?.text ?? '';
946
+ const path = INCLUDE_STRING.exec(literal)?.[1] ?? INCLUDE_RAW_STRING.exec(literal)?.[2];
947
+ if (path === undefined || path === '')
948
+ continue;
949
+ const file = resolve(current, path);
950
+ if (statSync(file, { throwIfNoEntry: false })?.isFile()) {
951
+ const prior = found.get(file);
952
+ if (prior === undefined || child < prior.source || (child === prior.source && path < prior.literal)) {
953
+ found.set(file, { file, source: child, literal: path });
954
+ }
955
+ }
956
+ }
957
+ }
958
+ }
959
+ }
960
+ const files = [...found.values()].sort((left, right) => left.file < right.file ? -1 : left.file > right.file ? 1 : 0);
961
+ cache.set(root, files);
962
+ return files;
963
+ }
@@ -50,6 +50,10 @@ export declare const CARGO_TOOLCHAIN_PIN_INPUTS: readonly string[];
50
50
  * token that cannot drift from what the plugin attaches.
51
51
  */
52
52
  export declare const CARGO_TOOLCHAIN_NAMED_INPUT = "cargoToolchain";
53
+ /** The toolchain versions `command` prints, from the directory whose rust-toolchain selects them. */
54
+ export declare function cargoRuntimeInput(projectRoot: string, command: string): {
55
+ runtime: string;
56
+ };
53
57
  /**
54
58
  * Does one resolved input string carry the toolchain identity?
55
59
  *
@@ -1 +1 @@
1
- {"version":3,"file":"cargo-toolchain-policy.d.ts","sourceRoot":"","sources":["../src/cargo-toolchain-policy.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,eAAO,MAAM,0BAA0B,EAAE,SAAS,MAAM,EAGvD,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,2BAA2B,mBAAmB,CAAC;AAE5D;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE5D"}
1
+ {"version":3,"file":"cargo-toolchain-policy.d.ts","sourceRoot":"","sources":["../src/cargo-toolchain-policy.ts"],"names":[],"mappings":"AACA;;;;GAIG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,eAAO,MAAM,0BAA0B,EAAE,SAAS,MAAM,EAGvD,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,2BAA2B,mBAAmB,CAAC;AAE5D,qGAAqG;AACrG,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAE3F;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE5D"}
@@ -1,3 +1,4 @@
1
+ import { runtimeInput, shellWord } from './runtime-input.js';
1
2
  /**
2
3
  * The toolchain half of a cargo task's identity, shared by the two things that
3
4
  * must agree about it: target inference, which attaches it, and the monorepo
@@ -53,6 +54,10 @@ export const CARGO_TOOLCHAIN_PIN_INPUTS = [
53
54
  * token that cannot drift from what the plugin attaches.
54
55
  */
55
56
  export const CARGO_TOOLCHAIN_NAMED_INPUT = 'cargoToolchain';
57
+ /** The toolchain versions `command` prints, from the directory whose rust-toolchain selects them. */
58
+ export function cargoRuntimeInput(projectRoot, command) {
59
+ return runtimeInput(`sh -c ${shellWord(`cd "$0" && ${command}`)} ${shellWord(projectRoot)}`);
60
+ }
56
61
  /**
57
62
  * Does one resolved input string carry the toolchain identity?
58
63
  *