@smoothbricks/nx-plugin 0.5.6 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (440) hide show
  1. package/README.md +1095 -360
  2. package/dist/.build-inputs.json +138 -0
  3. package/dist/bin/smoo-nx-cargo-toolchain.d.ts +3 -0
  4. package/dist/bin/smoo-nx-cargo-toolchain.d.ts.map +1 -0
  5. package/dist/bin/smoo-nx-cargo-toolchain.js +8 -0
  6. package/dist/bin/smoo-nx-forbidden-spellings.d.ts +3 -0
  7. package/dist/bin/smoo-nx-forbidden-spellings.d.ts.map +1 -0
  8. package/dist/bin/smoo-nx-forbidden-spellings.js +32 -0
  9. package/dist/bin/smoo-nx-nextest-timings.d.ts +3 -0
  10. package/dist/bin/smoo-nx-nextest-timings.d.ts.map +1 -0
  11. package/dist/bin/smoo-nx-nextest-timings.js +28 -0
  12. package/dist/bounded-test-policy.d.ts +1 -1
  13. package/dist/bounded-test-policy.d.ts.map +1 -1
  14. package/dist/bounded-test-policy.js +14 -15
  15. package/dist/build-state-output-policy.d.ts +95 -1
  16. package/dist/build-state-output-policy.d.ts.map +1 -1
  17. package/dist/build-state-output-policy.js +368 -30
  18. package/dist/bun-lock-scope.d.ts +44 -0
  19. package/dist/bun-lock-scope.d.ts.map +1 -0
  20. package/dist/bun-lock-scope.js +97 -0
  21. package/dist/cargo-build-script-env.d.ts +49 -0
  22. package/dist/cargo-build-script-env.d.ts.map +1 -0
  23. package/dist/cargo-build-script-env.js +324 -0
  24. package/dist/cargo-closure-input.d.ts +31 -4
  25. package/dist/cargo-closure-input.d.ts.map +1 -1
  26. package/dist/cargo-closure-input.js +66 -6
  27. package/dist/cargo-retention-hook.d.ts +17 -0
  28. package/dist/cargo-retention-hook.d.ts.map +1 -0
  29. package/dist/cargo-retention-hook.js +85 -0
  30. package/dist/cargo-source-hash.d.ts +25 -7
  31. package/dist/cargo-source-hash.d.ts.map +1 -1
  32. package/dist/cargo-source-hash.js +108 -43
  33. package/dist/cargo-toolchain-paths.d.ts +40 -0
  34. package/dist/cargo-toolchain-paths.d.ts.map +1 -0
  35. package/dist/cargo-toolchain-paths.js +84 -0
  36. package/dist/cargo-toolchain-policy.d.ts +25 -8
  37. package/dist/cargo-toolchain-policy.d.ts.map +1 -1
  38. package/dist/cargo-toolchain-policy.js +39 -5
  39. package/dist/cargo-workspace.d.ts +10 -4
  40. package/dist/cargo-workspace.d.ts.map +1 -1
  41. package/dist/cargo-workspace.js +65 -95
  42. package/dist/cross-check-policy.d.ts +9 -9
  43. package/dist/cross-check-policy.d.ts.map +1 -1
  44. package/dist/cross-check-policy.js +11 -11
  45. package/dist/disk-command-policy.d.ts.map +1 -1
  46. package/dist/disk-command-policy.js +1 -0
  47. package/dist/ensure-built-receipt.d.ts +13 -5
  48. package/dist/ensure-built-receipt.d.ts.map +1 -1
  49. package/dist/ensure-built-receipt.js +126 -47
  50. package/dist/ensure-built-witness.d.ts +27 -8
  51. package/dist/ensure-built-witness.d.ts.map +1 -1
  52. package/dist/ensure-built-witness.js +45 -15
  53. package/dist/ensure-built.d.ts.map +1 -1
  54. package/dist/ensure-built.js +9 -1
  55. package/dist/eslint-config-closure.d.ts +7 -0
  56. package/dist/eslint-config-closure.d.ts.map +1 -0
  57. package/dist/eslint-config-closure.js +346 -0
  58. package/dist/executors/all-verdicts/executor.d.ts +35 -0
  59. package/dist/executors/all-verdicts/executor.d.ts.map +1 -0
  60. package/dist/executors/all-verdicts/executor.js +133 -0
  61. package/dist/executors/all-verdicts/schema.d.ts +10 -0
  62. package/dist/executors/all-verdicts/schema.d.ts.map +1 -0
  63. package/dist/executors/all-verdicts/schema.js +2 -0
  64. package/dist/executors/bounded-exec/bounds.d.ts +56 -0
  65. package/dist/executors/bounded-exec/bounds.d.ts.map +1 -0
  66. package/dist/executors/bounded-exec/bounds.js +43 -0
  67. package/dist/executors/bounded-exec/cpu-pool.d.ts +33 -36
  68. package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
  69. package/dist/executors/bounded-exec/cpu-pool.js +54 -119
  70. package/dist/executors/bounded-exec/executor.d.ts +19 -12
  71. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  72. package/dist/executors/bounded-exec/executor.js +371 -239
  73. package/dist/executors/bounded-exec/gateway-lease.d.ts +22 -19
  74. package/dist/executors/bounded-exec/gateway-lease.d.ts.map +1 -1
  75. package/dist/executors/bounded-exec/gateway-lease.js +81 -28
  76. package/dist/executors/bounded-exec/hang-diagnostics.d.ts +18 -1
  77. package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -1
  78. package/dist/executors/bounded-exec/hang-diagnostics.js +148 -30
  79. package/dist/executors/bounded-exec/lease-wait.d.ts +43 -0
  80. package/dist/executors/bounded-exec/lease-wait.d.ts.map +1 -0
  81. package/dist/executors/bounded-exec/lease-wait.js +68 -0
  82. package/dist/executors/bounded-exec/lock-wait.d.ts +51 -0
  83. package/dist/executors/bounded-exec/lock-wait.d.ts.map +1 -0
  84. package/dist/executors/bounded-exec/lock-wait.js +108 -0
  85. package/dist/executors/bounded-exec/owned-subtree.d.ts +84 -0
  86. package/dist/executors/bounded-exec/owned-subtree.d.ts.map +1 -0
  87. package/dist/executors/bounded-exec/owned-subtree.js +178 -0
  88. package/dist/executors/bounded-exec/progress.d.ts +4 -1
  89. package/dist/executors/bounded-exec/progress.d.ts.map +1 -1
  90. package/dist/executors/bounded-exec/progress.js +5 -2
  91. package/dist/executors/bounded-exec/ram-attach.d.ts +19 -0
  92. package/dist/executors/bounded-exec/ram-attach.d.ts.map +1 -0
  93. package/dist/executors/bounded-exec/ram-attach.js +207 -0
  94. package/dist/executors/bounded-exec/ram-detach.d.ts +25 -0
  95. package/dist/executors/bounded-exec/ram-detach.d.ts.map +1 -0
  96. package/dist/executors/bounded-exec/ram-detach.js +207 -0
  97. package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts +76 -0
  98. package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts.map +1 -1
  99. package/dist/executors/bounded-exec/ram-temp-fixtures.js +296 -0
  100. package/dist/executors/bounded-exec/ram-temp.d.ts +388 -88
  101. package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -1
  102. package/dist/executors/bounded-exec/ram-temp.js +1213 -399
  103. package/dist/executors/bounded-exec/run-cpu-pool.d.ts +4 -4
  104. package/dist/executors/bounded-exec/run-cpu-pool.d.ts.map +1 -1
  105. package/dist/executors/bounded-exec/run-cpu-pool.js +20 -30
  106. package/dist/executors/bounded-exec/runner-hook.js +14 -5
  107. package/dist/executors/bounded-exec/runner-lifecycle.d.ts +14 -1
  108. package/dist/executors/bounded-exec/runner-lifecycle.d.ts.map +1 -1
  109. package/dist/executors/bounded-exec/runner-lifecycle.js +27 -6
  110. package/dist/executors/bounded-exec/{cpu-tokens.d.ts → runner-sizing.d.ts} +14 -42
  111. package/dist/executors/bounded-exec/runner-sizing.d.ts.map +1 -0
  112. package/dist/executors/bounded-exec/{cpu-tokens.js → runner-sizing.js} +5 -35
  113. package/dist/executors/bounded-exec/runtime-pin.d.ts +73 -0
  114. package/dist/executors/bounded-exec/runtime-pin.d.ts.map +1 -0
  115. package/dist/executors/bounded-exec/runtime-pin.js +167 -0
  116. package/dist/executors/bounded-exec/schema.d.ts +18 -1
  117. package/dist/executors/bounded-exec/schema.d.ts.map +1 -1
  118. package/dist/executors/bounded-exec/verdict.d.ts +40 -11
  119. package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
  120. package/dist/executors/bounded-exec/verdict.js +88 -19
  121. package/dist/executors/cargo-zigbuild/executor.d.ts +21 -0
  122. package/dist/executors/cargo-zigbuild/executor.d.ts.map +1 -1
  123. package/dist/executors/cargo-zigbuild/executor.js +67 -12
  124. package/dist/executors/clean-outputs/executor.js +1 -0
  125. package/dist/executors/scriptc-native/executor.d.ts +79 -0
  126. package/dist/executors/scriptc-native/executor.d.ts.map +1 -0
  127. package/dist/executors/scriptc-native/executor.js +367 -0
  128. package/dist/executors/scriptc-native/ffi-paths.d.ts +9 -0
  129. package/dist/executors/scriptc-native/ffi-paths.d.ts.map +1 -0
  130. package/dist/executors/scriptc-native/ffi-paths.js +25 -0
  131. package/dist/executors/scriptc-native/schema.d.ts +34 -0
  132. package/dist/executors/scriptc-native/schema.d.ts.map +1 -0
  133. package/dist/executors/scriptc-native/schema.js +1 -0
  134. package/dist/executors/typescript-emit/executor.d.ts +3 -1
  135. package/dist/executors/typescript-emit/executor.d.ts.map +1 -1
  136. package/dist/executors/typescript-emit/executor.js +164 -33
  137. package/dist/forbidden-spelling-policy.d.ts +56 -0
  138. package/dist/forbidden-spelling-policy.d.ts.map +1 -0
  139. package/dist/forbidden-spelling-policy.js +176 -0
  140. package/dist/generators/create-package/generator.d.ts.map +1 -1
  141. package/dist/generators/create-package/generator.js +3 -4
  142. package/dist/graph-input-contract.d.ts +14 -0
  143. package/dist/graph-input-contract.d.ts.map +1 -1
  144. package/dist/graph-input-contract.js +67 -2
  145. package/dist/index.d.ts +23 -6
  146. package/dist/index.d.ts.map +1 -1
  147. package/dist/index.js +676 -215
  148. package/dist/managed-assets.d.ts +2 -0
  149. package/dist/managed-assets.d.ts.map +1 -1
  150. package/dist/managed-files/files.d.ts +3 -3
  151. package/dist/managed-files/files.d.ts.map +1 -1
  152. package/dist/managed-files/files.js +28 -3
  153. package/dist/managed-files/managed-format.d.ts.map +1 -1
  154. package/dist/managed-files/managed-format.js +1 -0
  155. package/dist/nextest-code-bound.js +1 -0
  156. package/dist/nextest-timings.d.ts +35 -0
  157. package/dist/nextest-timings.d.ts.map +1 -0
  158. package/dist/nextest-timings.js +168 -0
  159. package/dist/owned-installation.d.ts +6 -5
  160. package/dist/owned-installation.d.ts.map +1 -1
  161. package/dist/owned-installation.js +150 -26
  162. package/dist/package-target-policy.d.ts.map +1 -1
  163. package/dist/package-target-policy.js +2 -3
  164. package/dist/process-children.d.ts +7 -0
  165. package/dist/process-children.d.ts.map +1 -0
  166. package/dist/process-children.darwin.d.ts +7 -0
  167. package/dist/process-children.darwin.d.ts.map +1 -0
  168. package/dist/process-children.darwin.js +13 -0
  169. package/dist/process-children.js +14 -0
  170. package/dist/process-children.linux.d.ts +8 -0
  171. package/dist/process-children.linux.d.ts.map +1 -0
  172. package/dist/process-children.linux.js +25 -0
  173. package/dist/process-group.d.ts +108 -0
  174. package/dist/process-group.d.ts.map +1 -0
  175. package/dist/process-group.js +171 -0
  176. package/dist/process-listing.d.ts +7 -0
  177. package/dist/process-listing.d.ts.map +1 -0
  178. package/dist/process-listing.js +51 -0
  179. package/dist/producer-receipts.d.ts +8 -2
  180. package/dist/producer-receipts.d.ts.map +1 -1
  181. package/dist/producer-receipts.js +75 -48
  182. package/dist/task-graph-policy.d.ts +21 -0
  183. package/dist/task-graph-policy.d.ts.map +1 -0
  184. package/dist/task-graph-policy.js +91 -0
  185. package/dist/test-timings.js +4 -4
  186. package/dist/test-walk-policy.d.ts +14 -5
  187. package/dist/test-walk-policy.d.ts.map +1 -1
  188. package/dist/test-walk-policy.js +8 -2
  189. package/dist/testing.d.ts +73 -28
  190. package/dist/testing.d.ts.map +1 -1
  191. package/dist/testing.js +217 -223
  192. package/dist/tool-bins.d.ts +33 -0
  193. package/dist/tool-bins.d.ts.map +1 -0
  194. package/dist/tool-bins.js +72 -0
  195. package/dist/typecheck-test-policy.d.ts.map +1 -1
  196. package/dist/typecheck-test-policy.js +3 -4
  197. package/dist/wait-why-policy.d.ts +28 -0
  198. package/dist/wait-why-policy.d.ts.map +1 -0
  199. package/dist/wait-why-policy.js +223 -0
  200. package/dist/workspace-config-policy.d.ts +14 -8
  201. package/dist/workspace-config-policy.d.ts.map +1 -1
  202. package/dist/workspace-config-policy.js +60 -16
  203. package/dist/workspace-manifest.d.ts +41 -6
  204. package/dist/workspace-manifest.d.ts.map +1 -1
  205. package/dist/workspace-manifest.js +57 -0
  206. package/executors.json +21 -1
  207. package/loader.js +2 -0
  208. package/managed/raw/envrc +11 -0
  209. package/managed/raw/patches/nx@23.2.1.patch +2840 -199
  210. package/managed/raw/patches/ttsc@0.34.1.patch +119 -0
  211. package/managed/raw/tooling/direnv/cargo-fetch-bound.ts +245 -0
  212. package/managed/raw/tooling/direnv/cargo-fetch-run.ts +299 -0
  213. package/managed/raw/tooling/direnv/compiler-variables.sh +42 -0
  214. package/managed/raw/tooling/direnv/developer-links.ts +464 -25
  215. package/managed/raw/tooling/direnv/devenv.smoo.nix +78 -38
  216. package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +14 -12
  217. package/managed/raw/tooling/direnv/installed-bun-links.ts +308 -0
  218. package/managed/raw/tooling/direnv/linked-snapshots.ts +62 -3
  219. package/managed/raw/tooling/direnv/nx-socket-dir.sh +56 -17
  220. package/managed/raw/tooling/direnv/repo-path +68 -6
  221. package/managed/raw/tooling/direnv/secret-references.ts +13 -4
  222. package/managed/raw/tooling/direnv/setup-environment.ts +128 -537
  223. package/managed/raw/tooling/direnv/toolchain-stamp.ts +4 -2
  224. package/managed/raw/tooling/direnv/ttsc-env.sh +9 -0
  225. package/managed/raw/tooling/direnv/uv-relocation.ts +227 -0
  226. package/managed/raw/tooling/git-hooks/commit-msg.sh +2 -1
  227. package/managed/raw/tooling/git-hooks/pre-commit.sh +2 -1
  228. package/managed/raw/tooling/git-hooks/pre-push.sh +2 -1
  229. package/managed/templates/github/actions/cache-ttsc-plugins/action.yml +85 -7
  230. package/managed/templates/github/actions/save-nix-devenv/action.yml +12 -2
  231. package/managed/templates/github/actions/setup-devenv/action.yml +2 -0
  232. package/package.json +77 -13
  233. package/src/bin/smoo-nx-cargo-toolchain.ts +11 -0
  234. package/src/bin/smoo-nx-forbidden-spellings.ts +33 -0
  235. package/src/bin/smoo-nx-nextest-timings.ts +31 -0
  236. package/src/bounded-test-policy.ts +12 -14
  237. package/src/build-state-output-policy.ts +458 -34
  238. package/src/bun-lock-scope.ts +108 -0
  239. package/src/cargo-build-script-env.ts +265 -0
  240. package/src/cargo-closure-input.ts +74 -7
  241. package/src/cargo-retention-hook.ts +94 -0
  242. package/src/cargo-source-hash.ts +138 -41
  243. package/src/cargo-toolchain-paths.ts +95 -0
  244. package/src/cargo-toolchain-policy.ts +49 -5
  245. package/src/cargo-workspace.ts +72 -123
  246. package/src/cross-check-policy.ts +12 -10
  247. package/src/disk-command-policy.ts +1 -0
  248. package/src/ensure-built-receipt.ts +132 -39
  249. package/src/ensure-built-witness.ts +62 -10
  250. package/src/ensure-built.ts +11 -1
  251. package/src/eslint-config-closure.ts +357 -0
  252. package/src/executors/all-verdicts/executor.ts +164 -0
  253. package/src/executors/all-verdicts/schema.json +22 -0
  254. package/src/executors/all-verdicts/schema.ts +10 -0
  255. package/src/executors/bounded-exec/bounds.ts +76 -0
  256. package/src/executors/bounded-exec/cpu-pool.ts +51 -117
  257. package/src/executors/bounded-exec/executor.ts +423 -259
  258. package/src/executors/bounded-exec/gateway-lease.ts +82 -33
  259. package/src/executors/bounded-exec/hang-diagnostics.ts +173 -31
  260. package/src/executors/bounded-exec/lease-wait.ts +89 -0
  261. package/src/executors/bounded-exec/lock-wait.ts +141 -0
  262. package/src/executors/bounded-exec/owned-subtree.ts +235 -0
  263. package/src/executors/bounded-exec/progress.ts +9 -3
  264. package/src/executors/bounded-exec/ram-attach.ts +238 -0
  265. package/src/executors/bounded-exec/ram-detach.ts +226 -0
  266. package/src/executors/bounded-exec/ram-temp-fixtures.ts +358 -0
  267. package/src/executors/bounded-exec/ram-temp-registry.txt +440 -0
  268. package/src/executors/bounded-exec/ram-temp.ts +1497 -460
  269. package/src/executors/bounded-exec/run-cpu-pool.ts +22 -30
  270. package/src/executors/bounded-exec/runner-hook.ts +14 -6
  271. package/src/executors/bounded-exec/runner-lifecycle.ts +31 -8
  272. package/src/executors/bounded-exec/{cpu-tokens.ts → runner-sizing.ts} +13 -59
  273. package/src/executors/bounded-exec/runtime-pin.ts +232 -0
  274. package/src/executors/bounded-exec/schema.json +11 -2
  275. package/src/executors/bounded-exec/schema.ts +19 -1
  276. package/src/executors/bounded-exec/verdict.ts +137 -34
  277. package/src/executors/cargo-zigbuild/executor.ts +82 -8
  278. package/src/executors/clean-outputs/executor.ts +1 -0
  279. package/src/executors/scriptc-native/executor.ts +394 -0
  280. package/src/executors/scriptc-native/ffi-paths.ts +29 -0
  281. package/src/executors/scriptc-native/schema.json +60 -0
  282. package/src/executors/scriptc-native/schema.ts +34 -0
  283. package/src/executors/typescript-emit/executor.ts +205 -38
  284. package/src/forbidden-spelling-policy.ts +226 -0
  285. package/src/generators/create-package/generator.ts +7 -7
  286. package/src/graph-input-contract.ts +61 -2
  287. package/src/index.ts +792 -225
  288. package/src/managed-assets.ts +3 -0
  289. package/src/managed-files/files.ts +28 -3
  290. package/src/managed-files/managed-format.ts +1 -0
  291. package/src/nextest-code-bound.ts +1 -0
  292. package/src/nextest-timings.ts +106 -0
  293. package/src/owned-installation.ts +150 -23
  294. package/src/package-target-policy.ts +2 -3
  295. package/src/process-children.darwin.ts +14 -0
  296. package/src/process-children.linux.ts +33 -0
  297. package/src/process-children.ts +22 -0
  298. package/src/process-group.ts +209 -0
  299. package/src/process-listing.ts +54 -0
  300. package/src/producer-receipts.ts +68 -45
  301. package/src/task-graph-policy.ts +98 -0
  302. package/src/test-walk-policy.ts +23 -8
  303. package/src/testing.ts +240 -232
  304. package/src/tool-bins.ts +108 -0
  305. package/src/typecheck-test-policy.ts +2 -3
  306. package/src/wait-why-policy.ts +226 -0
  307. package/src/workspace-config-policy.ts +63 -15
  308. package/src/workspace-manifest.ts +89 -6
  309. package/test-timings.json +123 -98
  310. package/dist/bin/smoo-nx-failures.d.ts +0 -3
  311. package/dist/bin/smoo-nx-failures.d.ts.map +0 -1
  312. package/dist/bin/smoo-nx-failures.js +0 -3
  313. package/dist/bin/smoo-nx-nextest-extract.d.ts +0 -3
  314. package/dist/bin/smoo-nx-nextest-extract.d.ts.map +0 -1
  315. package/dist/bin/smoo-nx-nextest-extract.js +0 -42
  316. package/dist/executors/bounded-exec/cpu-tokens.d.ts.map +0 -1
  317. package/dist/failure-summary.d.ts +0 -5
  318. package/dist/failure-summary.d.ts.map +0 -1
  319. package/dist/failure-summary.js +0 -118
  320. package/dist/nextest-extraction.d.ts +0 -117
  321. package/dist/nextest-extraction.d.ts.map +0 -1
  322. package/dist/nextest-extraction.js +0 -303
  323. package/managed/raw/patches/ttsc@0.30.4.patch +0 -2255
  324. package/src/__tests__/cargo-closure-filesets.ts +0 -94
  325. package/src/__tests__/cargo-closure-fixture.ts +0 -113
  326. package/src/__tests__/counted-cargo-process.ts +0 -286
  327. package/src/__tests__/counted-cargo.ts +0 -713
  328. package/src/__tests__/directory-change.ts +0 -27
  329. package/src/__tests__/fixture-cargo-home.ts +0 -36
  330. package/src/__tests__/fixture-nx-env.ts +0 -193
  331. package/src/__tests__/owned-installation.ts +0 -13
  332. package/src/__tests__/past-tick.ts +0 -12
  333. package/src/__tests__/progress-clock.ts +0 -43
  334. package/src/__tests__/runtime-input.ts +0 -23
  335. package/src/bin/smoo-nx-bound-failures.test.ts +0 -127
  336. package/src/bin/smoo-nx-failures.ts +0 -4
  337. package/src/bin/smoo-nx-nextest-extract.ts +0 -44
  338. package/src/bounded-test-policy.test.ts +0 -1029
  339. package/src/build-state-output-policy.test.ts +0 -115
  340. package/src/bun-bootstrap.test.ts +0 -102
  341. package/src/bun-file-packages.test.ts +0 -47
  342. package/src/cargo-closure-filesets.test.ts +0 -63
  343. package/src/cargo-closure-input.property.test.ts +0 -50
  344. package/src/cargo-closure-input.test.ts +0 -506
  345. package/src/cargo-closure-key.test.ts +0 -240
  346. package/src/cargo-resolve-cache.test.ts +0 -1181
  347. package/src/cargo-source-hash.test.ts +0 -707
  348. package/src/cargo-workspace.test.ts +0 -615
  349. package/src/cross-check-policy.test.ts +0 -316
  350. package/src/disk-command-policy.test.ts +0 -61
  351. package/src/ensure-built-receipt.test.ts +0 -279
  352. package/src/ensure-built-witness.test.ts +0 -688
  353. package/src/ensure-built.test.ts +0 -1462
  354. package/src/executors/bounded-exec/cargo-progress-host.test.ts +0 -332
  355. package/src/executors/bounded-exec/cpu-pool.test.ts +0 -684
  356. package/src/executors/bounded-exec/cpu-tokens.test.ts +0 -519
  357. package/src/executors/bounded-exec/disk-lease.test.ts +0 -219
  358. package/src/executors/bounded-exec/executor-host.test.ts +0 -800
  359. package/src/executors/bounded-exec/executor.test.ts +0 -1819
  360. package/src/executors/bounded-exec/go-progress-host.test.ts +0 -171
  361. package/src/executors/bounded-exec/hang-diagnostics.test.ts +0 -291
  362. package/src/executors/bounded-exec/progress.test.ts +0 -139
  363. package/src/executors/bounded-exec/ram-temp-held.test.ts +0 -264
  364. package/src/executors/bounded-exec/ram-temp-host.test.ts +0 -635
  365. package/src/executors/bounded-exec/ram-temp.test.ts +0 -750
  366. package/src/executors/bounded-exec/run-cpu-pool.test.ts +0 -79
  367. package/src/executors/bounded-exec/runner-hook.test.ts +0 -193
  368. package/src/executors/bounded-exec/runner-lifecycle.test.ts +0 -82
  369. package/src/executors/bounded-exec/verdict.test.ts +0 -545
  370. package/src/executors/cargo-zigbuild/executor.test.ts +0 -129
  371. package/src/executors/clean-outputs/executor.test.ts +0 -20
  372. package/src/executors/typescript-emit/executor.test.ts +0 -83
  373. package/src/failure-summary.ts +0 -119
  374. package/src/generators/bounded-test-targets/generator.test.ts +0 -138
  375. package/src/generators/bun-test-tracing/generator.test.ts +0 -250
  376. package/src/generators/create-package/generator.test.ts +0 -190
  377. package/src/generators/make-public/generator.test.ts +0 -137
  378. package/src/graph-input-contract.test.ts +0 -379
  379. package/src/host-controller-wiring.test.ts +0 -31
  380. package/src/index.test.ts +0 -3319
  381. package/src/linked-snapshots.nx.test.ts +0 -254
  382. package/src/managed-files/forgejo-artifact.test.ts +0 -395
  383. package/src/managed-files/generator.test.ts +0 -243
  384. package/src/managed-files/github-host-cache-isolation.test.ts +0 -86
  385. package/src/managed-files/json-edit.test.ts +0 -216
  386. package/src/managed-files/managed-content.test.ts +0 -166
  387. package/src/managed-files/managed-format-json.test.ts +0 -308
  388. package/src/managed-files/repo-path.test.ts +0 -172
  389. package/src/managed-files/setup-devenv-free-disk.test.ts +0 -95
  390. package/src/managed-files/trace-db-artifact.test.ts +0 -7
  391. package/src/managed-files/tree-permissions.test.ts +0 -109
  392. package/src/managed-files/tree.test.ts +0 -123
  393. package/src/manifest-hash.test.ts +0 -219
  394. package/src/nextest-code-bound.test.ts +0 -161
  395. package/src/nextest-extraction.test.ts +0 -216
  396. package/src/nextest-extraction.ts +0 -371
  397. package/src/nextest-partitions.test.ts +0 -501
  398. package/src/nx-cache-bound.test.ts +0 -109
  399. package/src/nx-cache-restore-mtime.test.ts +0 -170
  400. package/src/nx-daemon-claim.test.ts +0 -279
  401. package/src/nx-daemon-idle-cpu.test.ts +0 -80
  402. package/src/nx-daemon-idle-policy.test.ts +0 -111
  403. package/src/nx-daemon-ignore-files.test.ts +0 -210
  404. package/src/nx-daemon-root-normalization.test.ts +0 -105
  405. package/src/nx-daemon-start-never.test.ts +0 -292
  406. package/src/nx-daemon-validity.test.ts +0 -1055
  407. package/src/nx-dot-input-policy.test.ts +0 -353
  408. package/src/nx-failure-life-cycles.test.ts +0 -207
  409. package/src/nx-files-archive-racy.test.ts +0 -97
  410. package/src/nx-foreign-workspace-env.test.ts +0 -329
  411. package/src/nx-incomplete-run-summary.test.ts +0 -70
  412. package/src/nx-plugin-load-errors.test.ts +0 -120
  413. package/src/nx-project-graph-errors.test.ts +0 -70
  414. package/src/nx-project-resolution-cache.test.ts +0 -176
  415. package/src/nx-raw-inputs.test.ts +0 -166
  416. package/src/nx-resident-graph-workers.test.ts +0 -112
  417. package/src/nx-run-information.test.ts +0 -118
  418. package/src/nx-skipped-task-exit.test.ts +0 -180
  419. package/src/nx-state-location.test.ts +0 -63
  420. package/src/nx-store-resolution.test.ts +0 -81
  421. package/src/nx-task-graph-cycles.test.ts +0 -148
  422. package/src/nx-task-output-lease.test.ts +0 -550
  423. package/src/nx-use-local.test.ts +0 -105
  424. package/src/owned-installation.test.ts +0 -105
  425. package/src/package-target-policy.test.ts +0 -1014
  426. package/src/producer-receipts.test.ts +0 -285
  427. package/src/release-config-policy.test.ts +0 -311
  428. package/src/runtime-input.test.ts +0 -393
  429. package/src/serial-group-wiring.test.ts +0 -326
  430. package/src/task-history-namespace.test.ts +0 -181
  431. package/src/task-results.test.ts +0 -228
  432. package/src/test-clock-policy.test.ts +0 -338
  433. package/src/test-program.test.ts +0 -303
  434. package/src/test-timings.test.ts +0 -240
  435. package/src/test-walk-policy.test.ts +0 -620
  436. package/src/testing.test.ts +0 -509
  437. package/src/typecheck-test-policy.test.ts +0 -1468
  438. package/src/typescript-resolution.test.ts +0 -76
  439. package/src/version-actions.test.ts +0 -80
  440. package/src/workspace-config-policy.test.ts +0 -737
@@ -1,5 +1,9 @@
1
+ import { type Dirent, lstatSync, readdirSync, statSync } from 'node:fs';
1
2
  import { posix } from 'node:path';
2
- import type { ProjectGraph } from 'nx/src/config/project-graph';
3
+ import { Minimatch } from 'minimatch';
4
+ import type { ProjectGraph, ProjectGraphProjectNode } from 'nx/src/config/project-graph';
5
+ import type { TargetConfiguration } from 'nx/src/devkit-exports.js';
6
+ import type { expandOutputs } from 'nx/src/native';
3
7
  import { getOutputsForTargetAndConfiguration, interpolate } from 'nx/src/tasks-runner/utils';
4
8
 
5
9
  /** The read-only path records returned by `cowshed build-state --json`. */
@@ -8,21 +12,44 @@ export interface BuildStatePath {
8
12
  readonly volume: string;
9
13
  }
10
14
 
11
- export interface BuildStateOutputFinding {
15
+ /**
16
+ * What an output names, as its declaration states it: a declaration ending in `/` names a directory, any other a file.
17
+ * Nx records no kind and its interpolation drops a trailing `/`, so the kind is read from the declaration as written.
18
+ */
19
+ export type OutputKind = 'file' | 'directory';
20
+
21
+ /**
22
+ * One output a task declares (a target under one configuration), as Nx interpolates it. `undefined` is the target's own
23
+ * options, a task only when it has no `defaultConfiguration`: Nx resolves a run naming none to that.
24
+ */
25
+ export interface DeclaredOutput {
12
26
  readonly project: string;
13
27
  readonly target: string;
14
28
  readonly configuration: string | undefined;
15
29
  readonly output: string;
30
+ readonly kind: OutputKind;
31
+ }
32
+
33
+ export interface BuildStateOutputFinding extends DeclaredOutput {
16
34
  readonly buildStatePath: string;
17
35
  }
18
36
 
37
+ /** `project:target[:configuration]`, as Nx names the task. */
38
+ function taskName({
39
+ project,
40
+ target,
41
+ configuration,
42
+ }: Pick<DeclaredOutput, 'project' | 'target' | 'configuration'>): string {
43
+ return `${project}:${target}${configuration ? `:${configuration}` : ''}`;
44
+ }
45
+
19
46
  export class BuildStateOutputError extends Error {
20
47
  constructor(readonly findings: readonly BuildStateOutputFinding[]) {
21
48
  super(
22
49
  `Nx outputs must not cover cowshed build-state paths:\n${findings
23
50
  .map(
24
- ({ project, target, configuration, output, buildStatePath }) =>
25
- ` ${project}:${target}${configuration ? `:${configuration}` : ''}: ${JSON.stringify(output)} covers ${JSON.stringify(buildStatePath)}`,
51
+ (finding) =>
52
+ ` ${taskName(finding)}: ${JSON.stringify(finding.output)} covers ${JSON.stringify(finding.buildStatePath)}`,
26
53
  )
27
54
  .join('\n')}`,
28
55
  );
@@ -30,6 +57,82 @@ export class BuildStateOutputError extends Error {
30
57
  }
31
58
  }
32
59
 
60
+ /** A target whose outputs Nx refuses to interpolate, named: Nx's own error names only the output. */
61
+ export class OutputDeclarationError extends Error {
62
+ constructor(
63
+ readonly project: string,
64
+ readonly target: string,
65
+ readonly configuration: string | undefined,
66
+ cause: unknown,
67
+ ) {
68
+ super(
69
+ `${taskName({ project, target, configuration })}: ${cause instanceof Error ? cause.message : String(cause)}`,
70
+ { cause },
71
+ );
72
+ this.name = 'OutputDeclarationError';
73
+ }
74
+ }
75
+
76
+ /**
77
+ * Two tasks, each a target under one configuration, that declare one output path or pattern, or one inside the other.
78
+ * Each side names its project, target, configuration and output.
79
+ */
80
+ export interface OutputOverlap {
81
+ readonly left: DeclaredOutput;
82
+ readonly right: DeclaredOutput;
83
+ }
84
+
85
+ export class OutputOverlapError extends Error {
86
+ constructor(readonly overlaps: readonly OutputOverlap[]) {
87
+ super(
88
+ `Each Nx output path has one producing task; these tasks declare one path or pattern, or one inside another:\n${overlaps
89
+ .map(
90
+ ({ left, right }) =>
91
+ ` ${taskName(left)}: ${JSON.stringify(left.output)} overlaps ${taskName(right)}: ${JSON.stringify(right.output)}`,
92
+ )
93
+ .join('\n')}`,
94
+ );
95
+ this.name = 'OutputOverlapError';
96
+ }
97
+ }
98
+
99
+ /** What a path is on disk: absent, or the kind a restore of it would write. */
100
+ export type OutputOnDisk = OutputKind | 'absent';
101
+
102
+ /** A literal output whose declared kind the built tree contradicts. */
103
+ export interface OutputKindFinding extends DeclaredOutput {
104
+ readonly onDisk: OutputKind;
105
+ }
106
+
107
+ export class OutputKindError extends Error {
108
+ constructor(readonly findings: readonly OutputKindFinding[]) {
109
+ super(
110
+ `Each Nx output declaration states its kind: a directory output ends in \`/\`, a file output does not. These contradict the built tree:\n${findings
111
+ .map(
112
+ (finding) =>
113
+ ` ${taskName(finding)}: ${JSON.stringify(finding.output)} is declared a ${finding.kind} but is a ${finding.onDisk} on disk`,
114
+ )
115
+ .join('\n')}`,
116
+ );
117
+ this.name = 'OutputKindError';
118
+ }
119
+ }
120
+
121
+ /** Task outputs naming the workspace root itself or a path outside it: no file of the checkout is theirs to name. */
122
+ export class OutputEscapeError extends Error {
123
+ constructor(readonly findings: readonly DeclaredOutput[]) {
124
+ super(
125
+ `Each Nx output names a path inside its workspace, below the root; these do not:\n${findings
126
+ .map((finding) => ` ${taskName(finding)}: ${JSON.stringify(finding.output)}`)
127
+ .join('\n')}`,
128
+ );
129
+ this.name = 'OutputEscapeError';
130
+ }
131
+ }
132
+
133
+ /** A path segment holding glob syntax, read conservatively: any character that may start a pattern. */
134
+ const GLOB_PART = /[*?[\]{}()!]/;
135
+
33
136
  function contains(parent: string, child: string): boolean {
34
137
  return parent === child || child.startsWith(parent.endsWith('/') ? parent : `${parent}/`);
35
138
  }
@@ -37,10 +140,93 @@ function contains(parent: string, child: string): boolean {
37
140
  /** The non-glob directory prefix, conservatively including every possible glob match. */
38
141
  function staticPrefix(output: string): string {
39
142
  const parts = output.replaceAll('\\', '/').split('/');
40
- const firstGlob = parts.findIndex((part) => /[*?[\]{}()!]/.test(part));
143
+ const firstGlob = parts.findIndex((part) => GLOB_PART.test(part));
41
144
  return firstGlob < 0 ? parts.join('/') : parts.slice(0, firstGlob).join('/') || '.';
42
145
  }
43
146
 
147
+ function absoluteRoot(workspaceRoot: string): string {
148
+ const root = workspaceRoot.replaceAll('\\', '/');
149
+ if (!posix.isAbsolute(root)) throw new Error('Nx output validation requires an absolute workspace root');
150
+ return root;
151
+ }
152
+
153
+ /**
154
+ * What one target declares under one configuration. Nx's task helper rejects root globs and absolute declarations
155
+ * before expanding them, and its interpolation throws on a misplaced `{workspaceRoot}` without naming the target; the
156
+ * declarations are interpolated here, so those outputs are judged too and a refusal names its target.
157
+ */
158
+ function targetOutputs(
159
+ project: string,
160
+ target: string,
161
+ options: TargetConfiguration,
162
+ configuration: string | undefined,
163
+ node: ProjectGraphProjectNode,
164
+ root: string,
165
+ ): Pick<DeclaredOutput, 'output' | 'kind'>[] {
166
+ try {
167
+ return options.outputs
168
+ ? options.outputs
169
+ .map((output) => ({
170
+ output: interpolate(output, {
171
+ workspaceRoot: root,
172
+ projectRoot: node.data.root,
173
+ projectName: node.name,
174
+ project: { ...node.data, name: node.name },
175
+ options: { ...options.options, ...(configuration ? options.configurations?.[configuration] : {}) },
176
+ }),
177
+ kind: declaredKind(output),
178
+ }))
179
+ .filter(({ output }) => output && !/{(projectRoot|workspaceRoot|(options.*))}/.test(output))
180
+ : // A target declaring no outputs takes Nx's fallback: its options' outputPath, or for build and prepare the
181
+ // legacy dist, build and public directories. Each names a directory, and no declaration states otherwise.
182
+ getOutputsForTargetAndConfiguration({ project, target, configuration }, {}, node).map((output) => ({
183
+ output,
184
+ kind: 'directory' as const,
185
+ }));
186
+ } catch (error) {
187
+ // Nx tests a template against a module-level global regex before it throws, leaving that regex's lastIndex past
188
+ // the first placeholder; the next interpolation in this process would then skip its placeholders and drop its
189
+ // output. One interpolation rewinds it: a test that fails resets lastIndex.
190
+ interpolate('', {});
191
+ throw new OutputDeclarationError(project, target, configuration, error);
192
+ }
193
+ }
194
+
195
+ function declaredKind(declaration: string): OutputKind {
196
+ return declaration.endsWith('/') ? 'directory' : 'file';
197
+ }
198
+
199
+ /**
200
+ * The configurations a target's tasks run under: each named one, and the run naming none. Nx resolves that run to the
201
+ * target's `defaultConfiguration` when it has one, so the target's own options are a task only without one.
202
+ */
203
+ export function taskConfigurations({
204
+ defaultConfiguration,
205
+ configurations,
206
+ }: TargetConfiguration): (string | undefined)[] {
207
+ const named = Object.keys(configurations ?? {});
208
+ return defaultConfiguration ? [...new Set([defaultConfiguration, ...named])] : [undefined, ...named];
209
+ }
210
+
211
+ /**
212
+ * Every output of every task in the resolved graph (project overrides included), as Nx interpolates it: one task per
213
+ * configuration a target runs under. A target declaring no outputs yields Nx's fallback outputs. Pass the absolute
214
+ * workspace root. This is the one reading of what a task writes: every output policy takes its declarations from here.
215
+ */
216
+ export function declaredOutputs(graph: ProjectGraph, root: string): DeclaredOutput[] {
217
+ const declared: DeclaredOutput[] = [];
218
+ for (const [project, node] of Object.entries(graph.nodes)) {
219
+ for (const [target, options] of Object.entries(node.data.targets ?? {})) {
220
+ for (const configuration of taskConfigurations(options)) {
221
+ for (const output of targetOutputs(project, target, options, configuration, node, root)) {
222
+ declared.push({ project, target, configuration, ...output });
223
+ }
224
+ }
225
+ }
226
+ }
227
+ return declared;
228
+ }
229
+
44
230
  /**
45
231
  * Enforce spec 16 at the consuming repository's Nx lint boundary, using its already resolved
46
232
  * graph (including project overrides). Never construct a graph during cowshed job admission.
@@ -52,39 +238,277 @@ export function refuseOutputsUnderBuildState(
52
238
  buildStatePaths: readonly BuildStatePath[],
53
239
  workspaceRoot: string,
54
240
  ): void {
55
- const root = workspaceRoot.replaceAll('\\', '/');
56
- if (!posix.isAbsolute(root)) throw new Error('build-state output validation requires an absolute workspace root');
241
+ const root = absoluteRoot(workspaceRoot);
57
242
  const paths = buildStatePaths.map(({ checkout }) => ({ checkout, absolute: posix.resolve(root, checkout) }));
58
243
  const findings: BuildStateOutputFinding[] = [];
59
- for (const [project, node] of Object.entries(graph.nodes)) {
60
- for (const [target, options] of Object.entries(node.data.targets ?? {})) {
61
- const configurations: (string | undefined)[] = [undefined, ...Object.keys(options.configurations ?? {})];
62
- for (const configuration of configurations) {
63
- // Nx's task helper rejects root globs and absolute declarations before expanding
64
- // them. This lint must name the overlapping build path even for those declarations.
65
- const outputs = options.outputs
66
- ? options.outputs
67
- .map((output) =>
68
- interpolate(output, {
69
- workspaceRoot: root,
70
- projectRoot: node.data.root,
71
- projectName: node.name,
72
- project: { ...node.data, name: node.name },
73
- options: { ...options.options, ...(configuration ? options.configurations?.[configuration] : {}) },
74
- }),
75
- )
76
- .filter((output) => output && !/{(projectRoot|workspaceRoot|(options.*))}/.test(output))
77
- : getOutputsForTargetAndConfiguration({ project, target, configuration }, {}, node);
78
- for (const output of outputs) {
79
- const prefix = posix.resolve(root, staticPrefix(output));
80
- for (const path of paths) {
81
- if (contains(prefix, path.absolute) || contains(path.absolute, prefix)) {
82
- findings.push({ project, target, configuration, output, buildStatePath: path.checkout });
83
- }
84
- }
85
- }
244
+ for (const declared of declaredOutputs(graph, root)) {
245
+ const prefix = posix.resolve(root, staticPrefix(declared.output));
246
+ for (const path of paths) {
247
+ if (contains(prefix, path.absolute) || contains(path.absolute, prefix)) {
248
+ findings.push({ ...declared, buildStatePath: path.checkout });
86
249
  }
87
250
  }
88
251
  }
89
252
  if (findings.length) throw new BuildStateOutputError(findings);
90
253
  }
254
+
255
+ /** One path a target's output names, absolute, and workspace-relative for matching. */
256
+ interface PathClaim {
257
+ readonly form: 'path';
258
+ readonly declared: DeclaredOutput;
259
+ readonly absolute: string;
260
+ readonly relative: string;
261
+ }
262
+
263
+ /** One pattern a target's output names: the directory it cannot write outside of, and the pattern compiled once. */
264
+ interface GlobClaim {
265
+ readonly form: 'glob';
266
+ readonly declared: DeclaredOutput;
267
+ readonly prefix: string;
268
+ readonly matcher: Minimatch;
269
+ }
270
+
271
+ type OutputClaim = PathClaim | GlobClaim;
272
+
273
+ /**
274
+ * Each task's declared outputs once per distinct path and declared kind; a negation claims nothing. A task is a target
275
+ * under one configuration, and the configuration is part of the identity: two configurations declaring one path are
276
+ * two claims, and each is judged. So is the kind: a path a task declares as both a file and a directory is two claims.
277
+ */
278
+ function outputClaims(declared: readonly DeclaredOutput[], root: string): OutputClaim[] {
279
+ const seen = new Set<string>();
280
+ const claims: OutputClaim[] = [];
281
+ for (const output of declared) {
282
+ if (output.output.startsWith('!')) continue;
283
+ const absolute = posix.resolve(root, output.output);
284
+ const key = JSON.stringify([output.project, output.target, output.configuration, absolute, output.kind]);
285
+ if (seen.has(key)) continue;
286
+ seen.add(key);
287
+ const relative = posix.relative(root, absolute);
288
+ claims.push(
289
+ GLOB_PART.test(relative)
290
+ ? {
291
+ form: 'glob',
292
+ declared: output,
293
+ prefix: posix.resolve(root, staticPrefix(relative)),
294
+ // Nx's own matcher, as Nx pins it. Dotfiles match: a restore writes them like any other file.
295
+ matcher: new Minimatch(relative, { dot: true }),
296
+ }
297
+ : { form: 'path', declared: output, absolute, relative },
298
+ );
299
+ }
300
+ return claims;
301
+ }
302
+
303
+ /**
304
+ * A pattern conflicts with a path at or above its static prefix, a path it matches, or a directory it can reach inside.
305
+ * Reaching is minimatch's partial match: it expands braces before it splits segments, so an alternative that crosses a
306
+ * slash is walked whole, and a directory whose every segment matches the pattern's leading segments is one the pattern
307
+ * can write under. A file the pattern does not match below its prefix is not written by it, whatever the pattern writes
308
+ * beside it; a file at or above the prefix collides by kind, since the pattern needs a directory there to write into.
309
+ */
310
+ function patternMeetsPath(pattern: GlobClaim, path: PathClaim): boolean {
311
+ return (
312
+ contains(path.absolute, pattern.prefix) ||
313
+ pattern.matcher.match(path.relative) ||
314
+ (path.declared.kind === 'directory' && pattern.matcher.match(path.relative, true))
315
+ );
316
+ }
317
+
318
+ /**
319
+ * Two paths conflict at, under or above each other. Two patterns conflict only as one pattern named twice, which
320
+ * matches the same files: Nx restores a pattern file by file, so two different patterns collide only on a file both
321
+ * match, and that cannot be named without the tree.
322
+ */
323
+ function conflicts(left: OutputClaim, right: OutputClaim): boolean {
324
+ if (left.form === 'path') {
325
+ return right.form === 'path'
326
+ ? contains(left.absolute, right.absolute) || contains(right.absolute, left.absolute)
327
+ : patternMeetsPath(right, left);
328
+ }
329
+ return right.form === 'path' ? patternMeetsPath(left, right) : left.matcher.pattern === right.matcher.pattern;
330
+ }
331
+
332
+ /**
333
+ * One producing task per output path: refuse any task whose output is at, under or above another task's output. A task
334
+ * is a target under one configuration (`project:target[:configuration]`, as Nx names it): two targets conflict, and so
335
+ * do two configurations of one target. `outputs` belongs to the target, so only an options placeholder
336
+ * (`{options.out}`) that the configurations set apart gives each its own. A task's own outputs never conflict with
337
+ * each other. Nx restores a directory output as one tree, so a second task writing inside it makes the first task's
338
+ * tree differ from its cache artifact after every build: each run restores one producer over the other, and neither is
339
+ * ever a cache hit.
340
+ */
341
+ export function refuseOverlappingOutputs(graph: ProjectGraph, workspaceRoot: string): void {
342
+ const root = absoluteRoot(workspaceRoot);
343
+ const claims = outputClaims(declaredOutputs(graph, root), root);
344
+ const overlaps: OutputOverlap[] = [];
345
+ for (const [index, left] of claims.entries()) {
346
+ for (const right of claims.slice(index + 1)) {
347
+ const sameTask =
348
+ left.declared.project === right.declared.project &&
349
+ left.declared.target === right.declared.target &&
350
+ left.declared.configuration === right.declared.configuration;
351
+ if (!sameTask && conflicts(left, right)) overlaps.push({ left: left.declared, right: right.declared });
352
+ }
353
+ }
354
+ if (overlaps.length) throw new OutputOverlapError(overlaps);
355
+ }
356
+
357
+ /** The kind of `path` on disk, following links as a restore's reader does; a path under a file is absent. */
358
+ export function outputOnDisk(path: string): OutputOnDisk {
359
+ try {
360
+ const stats = statSync(path, { throwIfNoEntry: false });
361
+ return stats === undefined ? 'absent' : stats.isDirectory() ? 'directory' : 'file';
362
+ } catch (error) {
363
+ if (error instanceof Error && 'code' in error && error.code === 'ENOTDIR') return 'absent';
364
+ throw error;
365
+ }
366
+ }
367
+
368
+ /**
369
+ * Hold every literal output's declared kind to the built tree under `workspaceRoot`: a directory output must be a
370
+ * directory and a file output a file. Run where the outputs exist after a build; an output absent on disk is not judged,
371
+ * and a pattern names its files by matching, so it states no kind to hold. The overlap policy reads the declared kind
372
+ * alone; this keeps that declaration honest.
373
+ */
374
+ export function refuseMisdeclaredOutputKinds(graph: ProjectGraph, workspaceRoot: string): void {
375
+ const root = absoluteRoot(workspaceRoot);
376
+ const findings: OutputKindFinding[] = [];
377
+ for (const claim of outputClaims(declaredOutputs(graph, root), root)) {
378
+ if (claim.form !== 'path') continue;
379
+ const onDisk = outputOnDisk(claim.absolute);
380
+ if (onDisk !== 'absent' && onDisk !== claim.declared.kind) findings.push({ ...claim.declared, onDisk });
381
+ }
382
+ if (findings.length) throw new OutputKindError(findings);
383
+ }
384
+
385
+ /** What a path itself is, read as written: a symbolic link is `other`, never what it points at. */
386
+ type EntryKind = OutputKind | 'other' | 'absent';
387
+
388
+ /** A path that is gone, or that runs through a file: what an output not written yet reads as. */
389
+ function isAbsent(error: unknown): boolean {
390
+ return error instanceof Error && 'code' in error && (error.code === 'ENOENT' || error.code === 'ENOTDIR');
391
+ }
392
+
393
+ /** The failure a read under `existingOutputFiles` raises: the operation and the workspace-relative path it read. */
394
+ function readError(operation: string, relative: string, cause: unknown): Error {
395
+ return new Error(
396
+ `existingOutputFiles: ${operation} ${JSON.stringify(relative)} failed: ${cause instanceof Error ? cause.message : String(cause)}`,
397
+ { cause },
398
+ );
399
+ }
400
+
401
+ /** What the workspace-relative path itself is under `root`, without following a link at it. */
402
+ function entryKind(root: string, relative: string): EntryKind {
403
+ try {
404
+ const stats = lstatSync(posix.join(root, relative), { throwIfNoEntry: false });
405
+ return stats === undefined ? 'absent' : stats.isDirectory() ? 'directory' : stats.isFile() ? 'file' : 'other';
406
+ } catch (error) {
407
+ if (isAbsent(error)) return 'absent';
408
+ throw readError('lstat', relative, error);
409
+ }
410
+ }
411
+
412
+ /** The entries of the directory at the workspace-relative path, each read as written; none once it is gone. */
413
+ function directoryEntries(root: string, relative: string): Dirent[] {
414
+ try {
415
+ return readdirSync(posix.join(root, relative), { withFileTypes: true });
416
+ } catch (error) {
417
+ if (isAbsent(error)) return [];
418
+ throw readError('readdir', relative, error);
419
+ }
420
+ }
421
+
422
+ /**
423
+ * An output as stock Nx's expansion reads it: relative to `root`, a negation keeping its `!`. `undefined` when the
424
+ * output names `root` itself or a path outside it.
425
+ */
426
+ function outputEntry(output: string, root: string): string | undefined {
427
+ const negated = output.startsWith('!');
428
+ const relative = posix.relative(root, posix.resolve(root, negated ? output.slice(1) : output));
429
+ if (relative === '' || relative === '..' || relative.startsWith('../')) return undefined;
430
+ return negated ? `!${relative}` : relative;
431
+ }
432
+
433
+ /**
434
+ * Whether some ancestor of `relative` below `root` is not a directory as written, a symbolic link above all: a path
435
+ * reached only through one is never listed under that spelling.
436
+ */
437
+ function throughNonDirectory(root: string, relative: string): boolean {
438
+ const parts = relative.split('/');
439
+ let ancestor = '';
440
+ for (const [index, part] of parts.entries()) {
441
+ if (index === parts.length - 1) break;
442
+ ancestor = ancestor === '' ? part : `${ancestor}/${part}`;
443
+ if (entryKind(root, ancestor) !== 'directory') return true;
444
+ }
445
+ return false;
446
+ }
447
+
448
+ /** Add every regular file beneath the directory `relative` to `files`, never descending a symbolic link. */
449
+ function collectDirectory(root: string, relative: string, files: Set<string>): void {
450
+ for (const entry of directoryEntries(root, relative)) {
451
+ const child = `${relative}/${entry.name}`;
452
+ if (entry.isFile()) files.add(child);
453
+ else if (entry.isDirectory()) collectDirectory(root, child, files);
454
+ }
455
+ }
456
+
457
+ /**
458
+ * Add what one path stock Nx's expansion returned contributes to `files`: a regular file itself, every regular file
459
+ * beneath a directory, and nothing for a symbolic link, any other kind, an absent path, or a path reached through a
460
+ * link above it.
461
+ */
462
+ function collectExpanded(root: string, relative: string, files: Set<string>): void {
463
+ if (throughNonDirectory(root, relative)) return;
464
+ const kind = entryKind(root, relative);
465
+ if (kind === 'file') files.add(relative);
466
+ else if (kind === 'directory') collectDirectory(root, relative, files);
467
+ }
468
+
469
+ /**
470
+ * Every regular file the resolved graph's outputs name under `workspaceRoot`, workspace-relative, sorted and once each.
471
+ * Every task counts, whether or not a run selected it: each target under each configuration it runs under, Nx's
472
+ * fallback outputs of a target declaring none included (`declaredOutputs`).
473
+ *
474
+ * Each task's outputs are expanded on their own with stock Nx's `expandOutputs` (`expand`, from the caller's workspace Nx), the native expansion Nx's cache uses,
475
+ * so a task's negation drops only its own matches, never a path another task claims. An expanded regular file is
476
+ * listed; an expanded directory contributes every regular file beneath it, read without descending a symbolic link at,
477
+ * above or below it; a symbolic link or other entry is skipped, and an absent path contributes nothing. Any other
478
+ * read failure throws, naming the operation and the workspace-relative path, so an unreadable directory beneath a
479
+ * literal directory output is refused rather than passed over. Stock expansion silently drops entries it cannot read
480
+ * while matching a glob; that is Nx's behaviour, and it is accepted here. An undeclared generated build input is
481
+ * outside this contract: only a file some task's declared output names is listed. An output naming the workspace root
482
+ * or a path outside it throws an `OutputEscapeError` naming every such task, before any disk access.
483
+ */
484
+ export function existingOutputFiles(
485
+ graph: ProjectGraph,
486
+ workspaceRoot: string,
487
+ expand: typeof expandOutputs,
488
+ ): string[] {
489
+ const root = absoluteRoot(workspaceRoot);
490
+ const tasks = new Map<string, string[]>();
491
+ const escapes: DeclaredOutput[] = [];
492
+ for (const declared of declaredOutputs(graph, root)) {
493
+ const entry = outputEntry(declared.output, root);
494
+ if (entry === undefined) {
495
+ escapes.push(declared);
496
+ continue;
497
+ }
498
+ const task = JSON.stringify([declared.project, declared.target, declared.configuration]);
499
+ const entries = tasks.get(task);
500
+ if (entries) entries.push(entry);
501
+ else tasks.set(task, [entry]);
502
+ }
503
+ if (escapes.length) throw new OutputEscapeError(escapes);
504
+ const files = new Set<string>();
505
+ const collected = new Set<string>();
506
+ for (const entries of tasks.values()) {
507
+ for (const expanded of expand(root, entries)) {
508
+ if (collected.has(expanded)) continue;
509
+ collected.add(expanded);
510
+ collectExpanded(root, expanded, files);
511
+ }
512
+ }
513
+ return [...files].sort();
514
+ }
@@ -0,0 +1,108 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { join, posix } from 'node:path';
3
+
4
+ import {
5
+ type CreateDependenciesContext,
6
+ DependencyType,
7
+ type ProjectGraphExternalNode,
8
+ type ProjectGraphProjectNode,
9
+ type RawProjectGraphDependency,
10
+ readJsonFile,
11
+ } from 'nx/src/devkit-exports.js';
12
+ import { TargetProjectLocator } from 'nx/src/plugins/js/project-graph/build-dependencies/target-project-locator.js';
13
+
14
+ /**
15
+ * Every bun lock-scope node's name starts with this; the rest is the root of
16
+ * the project whose manifest it stands for, `.` for the workspace root.
17
+ *
18
+ * A lock-scope node is the part of bun.lock one manifest reaches: what the
19
+ * package can load. Its edges go to the npm nodes the manifest's dependencies
20
+ * resolve to; a member's also go to the node of each workspace member it
21
+ * depends on and to the root's, since a member's `node_modules` lookup ends in
22
+ * the root's. The root's node has no member edges: every member reaches it, so
23
+ * one would key every member on the packages of whichever members the root
24
+ * manifest lists, which a member loads only through its own declaration (or an
25
+ * import Nx turns into a project edge, which a `^` input follows). Nx's
26
+ * lockfile parser links each npm node to the packages it depends on, so a
27
+ * target naming a node in its `externalDependencies` is keyed on every package
28
+ * of that closure by the hash bun.lock records for it, and on nothing else in
29
+ * the lockfile. That replaces bun.lock as a file input: a lockfile edit re-keys
30
+ * the tasks that can load what changed.
31
+ *
32
+ * The nodes carry no content of their own; Nx hashes a node's version and the
33
+ * nodes it reaches.
34
+ */
35
+ export const BUN_LOCK_NODE_PREFIX = 'bun-lock:';
36
+
37
+ /** The lock-scope node of the project at `projectRoot`. */
38
+ export function bunLockNodeName(projectRoot: string): string {
39
+ return `${BUN_LOCK_NODE_PREFIX}${posix.normalize(projectRoot === '' ? '.' : projectRoot)}`;
40
+ }
41
+
42
+ /** The node of the workspace root manifest, which every member's node reaches. */
43
+ export const BUN_ROOT_LOCK_NODE = bunLockNodeName('.');
44
+
45
+ /** The input that keys a target on the bun.lock entries its project's manifest reaches. */
46
+ export function bunLockInput(projectRoot: string): { externalDependencies: string[] } {
47
+ return { externalDependencies: [bunLockNodeName(projectRoot)] };
48
+ }
49
+
50
+ /** The node itself, published by its project; {@link bunLockDependencies} gives it its edges. */
51
+ export function bunLockNode(projectRoot: string): ProjectGraphExternalNode {
52
+ const name = bunLockNodeName(projectRoot);
53
+ return { type: 'bun', name, data: { packageName: name, version: '0.0.0' } };
54
+ }
55
+
56
+ /** The manifest sections Nx reads a project's package dependencies from, in the order it lets them override. */
57
+ const DEPENDENCY_SECTIONS = ['optionalDependencies', 'peerDependencies', 'devDependencies', 'dependencies'] as const;
58
+
59
+ /**
60
+ * The edges of every published bun lock-scope node. A manifest's dependencies
61
+ * are resolved exactly as Nx resolves a project's own package edges
62
+ * (`buildExplicitPackageJsonDependencies`, one `TargetProjectLocator` over
63
+ * the same projects and lockfile nodes): an installed package becomes an edge
64
+ * to its npm node, a workspace member (outside the root manifest) an edge to
65
+ * that member's node, and a package that resolves to no node is skipped
66
+ * exactly as Nx skips it.
67
+ */
68
+ export function bunLockDependencies(context: CreateDependenciesContext): RawProjectGraphDependency[] {
69
+ const externalNodes = context.externalNodes ?? {};
70
+ const nodes: Record<string, ProjectGraphProjectNode> = {};
71
+ for (const [name, data] of Object.entries(context.projects)) {
72
+ nodes[name] = { name, type: data.projectType === 'application' ? 'app' : 'lib', data };
73
+ }
74
+ const locator = new TargetProjectLocator(nodes, externalNodes);
75
+ const nodeOfMember = (member: string): string | null => {
76
+ const root = context.projects[member]?.root;
77
+ return root === undefined ? null : bunLockNodeName(root);
78
+ };
79
+ const dependencies: RawProjectGraphDependency[] = [];
80
+ for (const project of Object.values(context.projects).sort((left, right) =>
81
+ left.root < right.root ? -1 : left.root > right.root ? 1 : 0,
82
+ )) {
83
+ const source = bunLockNodeName(project.root);
84
+ if (externalNodes[source] === undefined) continue;
85
+ const manifestPath = posix.join(project.root, 'package.json');
86
+ if (!existsSync(join(context.workspaceRoot, manifestPath))) continue;
87
+ const manifest = readJsonFile<Record<string, unknown>>(join(context.workspaceRoot, manifestPath));
88
+ const specifiers = new Map<string, string>();
89
+ for (const section of DEPENDENCY_SECTIONS) {
90
+ const declared = manifest[section];
91
+ if (typeof declared !== 'object' || declared === null) continue;
92
+ for (const [name, specifier] of Object.entries(declared)) {
93
+ if (typeof specifier === 'string') specifiers.set(name, specifier);
94
+ }
95
+ }
96
+ const targets = new Set<string>(source === BUN_ROOT_LOCK_NODE ? [] : [BUN_ROOT_LOCK_NODE]);
97
+ for (const [name, specifier] of specifiers) {
98
+ const member = locator.findDependencyInWorkspaceProjects(manifestPath, name, specifier);
99
+ if (member !== null && source === BUN_ROOT_LOCK_NODE) continue;
100
+ const target = member === null ? locator.findNpmProjectFromImport(name, manifestPath) : nodeOfMember(member);
101
+ if (target !== null && target !== source && externalNodes[target] !== undefined) targets.add(target);
102
+ }
103
+ for (const target of [...targets].sort()) {
104
+ dependencies.push({ source, target, type: DependencyType.static });
105
+ }
106
+ }
107
+ return dependencies;
108
+ }