@convesoft/nx-rust 0.0.0 → 1.0.0-rc.1

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 (391) hide show
  1. package/LICENSE-APACHE +201 -0
  2. package/LICENSE-MIT +21 -0
  3. package/README.md +47 -1
  4. package/executors.json +35 -0
  5. package/generators.json +19 -0
  6. package/package.json +17 -4
  7. package/src/cargo/build-settings.d.ts +54 -0
  8. package/src/cargo/build-settings.js +93 -0
  9. package/src/cargo/build-settings.js.map +1 -0
  10. package/src/cargo/configured-runner.d.ts +36 -0
  11. package/src/cargo/configured-runner.js +99 -0
  12. package/src/cargo/configured-runner.js.map +1 -0
  13. package/src/cargo/configured-tools.d.ts +35 -0
  14. package/src/cargo/configured-tools.js +46 -0
  15. package/src/cargo/configured-tools.js.map +1 -0
  16. package/src/cargo/dep-info-basedir.d.ts +18 -0
  17. package/src/cargo/dep-info-basedir.js +38 -0
  18. package/src/cargo/dep-info-basedir.js.map +1 -0
  19. package/src/cargo/directories.d.ts +40 -0
  20. package/src/cargo/directories.js +89 -0
  21. package/src/cargo/directories.js.map +1 -0
  22. package/src/cargo/host-triple.d.ts +7 -0
  23. package/src/cargo/host-triple.js +21 -0
  24. package/src/cargo/host-triple.js.map +1 -0
  25. package/src/cargo/lockfile.d.ts +63 -0
  26. package/src/cargo/lockfile.js +157 -0
  27. package/src/cargo/lockfile.js.map +1 -0
  28. package/src/cargo/metadata.d.ts +112 -0
  29. package/src/cargo/metadata.js +37 -0
  30. package/src/cargo/metadata.js.map +1 -0
  31. package/src/cargo/package-specs.d.ts +54 -0
  32. package/src/cargo/package-specs.js +109 -0
  33. package/src/cargo/package-specs.js.map +1 -0
  34. package/src/cargo/paths-crates.d.ts +27 -0
  35. package/src/cargo/paths-crates.js +69 -0
  36. package/src/cargo/paths-crates.js.map +1 -0
  37. package/src/cargo/print-artifact-folders.d.ts +1 -0
  38. package/src/cargo/print-artifact-folders.js +58 -0
  39. package/src/cargo/print-artifact-folders.js.map +1 -0
  40. package/src/cargo/redirections.d.ts +87 -0
  41. package/src/cargo/redirections.js +195 -0
  42. package/src/cargo/redirections.js.map +1 -0
  43. package/src/cargo/run-cargo.d.ts +31 -0
  44. package/src/cargo/run-cargo.js +75 -0
  45. package/src/cargo/run-cargo.js.map +1 -0
  46. package/src/cargo/target-triples.d.ts +98 -0
  47. package/src/cargo/target-triples.js +265 -0
  48. package/src/cargo/target-triples.js.map +1 -0
  49. package/src/cargo/version-req.d.ts +12 -0
  50. package/src/cargo/version-req.js +122 -0
  51. package/src/cargo/version-req.js.map +1 -0
  52. package/src/compatibility/cargo-version.d.ts +43 -0
  53. package/src/compatibility/cargo-version.js +83 -0
  54. package/src/compatibility/cargo-version.js.map +1 -0
  55. package/src/compatibility/nx-bridge.d.ts +312 -0
  56. package/src/compatibility/nx-bridge.js +407 -0
  57. package/src/compatibility/nx-bridge.js.map +1 -0
  58. package/src/compatibility/nx-version.d.ts +104 -0
  59. package/src/compatibility/nx-version.js +272 -0
  60. package/src/compatibility/nx-version.js.map +1 -0
  61. package/src/executors/affected-inputs.d.ts +29 -0
  62. package/src/executors/affected-inputs.js +259 -0
  63. package/src/executors/affected-inputs.js.map +1 -0
  64. package/src/executors/affected-run.d.ts +54 -0
  65. package/src/executors/affected-run.js +394 -0
  66. package/src/executors/affected-run.js.map +1 -0
  67. package/src/executors/affected.d.ts +239 -0
  68. package/src/executors/affected.js +589 -0
  69. package/src/executors/affected.js.map +1 -0
  70. package/src/executors/baseline-context.d.ts +85 -0
  71. package/src/executors/baseline-context.js +227 -0
  72. package/src/executors/baseline-context.js.map +1 -0
  73. package/src/executors/baseline.d.ts +123 -0
  74. package/src/executors/baseline.js +356 -0
  75. package/src/executors/baseline.js.map +1 -0
  76. package/src/executors/batch.d.ts +75 -0
  77. package/src/executors/batch.js +434 -0
  78. package/src/executors/batch.js.map +1 -0
  79. package/src/executors/build-records.d.ts +110 -0
  80. package/src/executors/build-records.js +267 -0
  81. package/src/executors/build-records.js.map +1 -0
  82. package/src/executors/cargo/executor.d.ts +28 -0
  83. package/src/executors/cargo/executor.js +58 -0
  84. package/src/executors/cargo/executor.js.map +1 -0
  85. package/src/executors/cargo/schema.json +54 -0
  86. package/src/executors/cargo-invocation.d.ts +81 -0
  87. package/src/executors/cargo-invocation.js +109 -0
  88. package/src/executors/cargo-invocation.js.map +1 -0
  89. package/src/executors/cargo-output.d.ts +212 -0
  90. package/src/executors/cargo-output.js +646 -0
  91. package/src/executors/cargo-output.js.map +1 -0
  92. package/src/executors/command.d.ts +318 -0
  93. package/src/executors/command.js +517 -0
  94. package/src/executors/command.js.map +1 -0
  95. package/src/executors/coverage-baseline.d.ts +23 -0
  96. package/src/executors/coverage-baseline.js +284 -0
  97. package/src/executors/coverage-baseline.js.map +1 -0
  98. package/src/executors/declared-options.d.ts +21 -0
  99. package/src/executors/declared-options.js +58 -0
  100. package/src/executors/declared-options.js.map +1 -0
  101. package/src/executors/digests.d.ts +94 -0
  102. package/src/executors/digests.js +190 -0
  103. package/src/executors/digests.js.map +1 -0
  104. package/src/executors/dotenv-check.d.ts +79 -0
  105. package/src/executors/dotenv-check.js +553 -0
  106. package/src/executors/dotenv-check.js.map +1 -0
  107. package/src/executors/group-invocations.d.ts +80 -0
  108. package/src/executors/group-invocations.js +253 -0
  109. package/src/executors/group-invocations.js.map +1 -0
  110. package/src/executors/group-run.d.ts +114 -0
  111. package/src/executors/group-run.js +591 -0
  112. package/src/executors/group-run.js.map +1 -0
  113. package/src/executors/groups.d.ts +113 -0
  114. package/src/executors/groups.js +285 -0
  115. package/src/executors/groups.js.map +1 -0
  116. package/src/executors/input-check.d.ts +52 -0
  117. package/src/executors/input-check.js +271 -0
  118. package/src/executors/input-check.js.map +1 -0
  119. package/src/executors/kept-files.d.ts +98 -0
  120. package/src/executors/kept-files.js +341 -0
  121. package/src/executors/kept-files.js.map +1 -0
  122. package/src/executors/lockfile/executor.d.ts +16 -0
  123. package/src/executors/lockfile/executor.js +37 -0
  124. package/src/executors/lockfile/executor.js.map +1 -0
  125. package/src/executors/lockfile/schema.json +50 -0
  126. package/src/executors/napi-build.d.ts +73 -0
  127. package/src/executors/napi-build.js +420 -0
  128. package/src/executors/napi-build.js.map +1 -0
  129. package/src/executors/nextest.d.ts +185 -0
  130. package/src/executors/nextest.js +498 -0
  131. package/src/executors/nextest.js.map +1 -0
  132. package/src/executors/nx-command.d.ts +95 -0
  133. package/src/executors/nx-command.js +205 -0
  134. package/src/executors/nx-command.js.map +1 -0
  135. package/src/executors/nx-task-files.d.ts +82 -0
  136. package/src/executors/nx-task-files.js +156 -0
  137. package/src/executors/nx-task-files.js.map +1 -0
  138. package/src/executors/print-test-mode.d.ts +1 -0
  139. package/src/executors/print-test-mode.js +25 -0
  140. package/src/executors/print-test-mode.js.map +1 -0
  141. package/src/executors/release-publish/executor.d.ts +24 -0
  142. package/src/executors/release-publish/executor.js +165 -0
  143. package/src/executors/release-publish/executor.js.map +1 -0
  144. package/src/executors/release-publish/schema.json +30 -0
  145. package/src/executors/run/executor.d.ts +12 -0
  146. package/src/executors/run/executor.js +27 -0
  147. package/src/executors/run/executor.js.map +1 -0
  148. package/src/executors/run/schema.json +45 -0
  149. package/src/executors/runner-script.d.ts +12 -0
  150. package/src/executors/runner-script.js +22 -0
  151. package/src/executors/runner-script.js.map +1 -0
  152. package/src/executors/runtime-input-check.d.ts +24 -0
  153. package/src/executors/runtime-input-check.js +87 -0
  154. package/src/executors/runtime-input-check.js.map +1 -0
  155. package/src/executors/shared-artifacts.d.ts +44 -0
  156. package/src/executors/shared-artifacts.js +132 -0
  157. package/src/executors/shared-artifacts.js.map +1 -0
  158. package/src/executors/split-words.d.ts +24 -0
  159. package/src/executors/split-words.js +111 -0
  160. package/src/executors/split-words.js.map +1 -0
  161. package/src/executors/stage.d.ts +163 -0
  162. package/src/executors/stage.js +526 -0
  163. package/src/executors/stage.js.map +1 -0
  164. package/src/executors/staged-run.d.ts +24 -0
  165. package/src/executors/staged-run.js +110 -0
  166. package/src/executors/staged-run.js.map +1 -0
  167. package/src/executors/task-env.d.ts +271 -0
  168. package/src/executors/task-env.js +494 -0
  169. package/src/executors/task-env.js.map +1 -0
  170. package/src/executors/task-execution.d.ts +61 -0
  171. package/src/executors/task-execution.js +122 -0
  172. package/src/executors/task-execution.js.map +1 -0
  173. package/src/executors/task-guards.d.ts +112 -0
  174. package/src/executors/task-guards.js +430 -0
  175. package/src/executors/task-guards.js.map +1 -0
  176. package/src/executors/task-options.d.ts +114 -0
  177. package/src/executors/task-options.js +258 -0
  178. package/src/executors/task-options.js.map +1 -0
  179. package/src/executors/task.d.ts +166 -0
  180. package/src/executors/task.js +520 -0
  181. package/src/executors/task.js.map +1 -0
  182. package/src/executors/test-mode.d.ts +182 -0
  183. package/src/executors/test-mode.js +391 -0
  184. package/src/executors/test-mode.js.map +1 -0
  185. package/src/executors/test-runner.d.ts +44 -0
  186. package/src/executors/test-runner.js +159 -0
  187. package/src/executors/test-runner.js.map +1 -0
  188. package/src/executors/test-steps.d.ts +109 -0
  189. package/src/executors/test-steps.js +535 -0
  190. package/src/executors/test-steps.js.map +1 -0
  191. package/src/executors/wasm-build.d.ts +56 -0
  192. package/src/executors/wasm-build.js +216 -0
  193. package/src/executors/wasm-build.js.map +1 -0
  194. package/src/generators/crate/binary.schema.json +28 -0
  195. package/src/generators/crate/crate.d.ts +24 -0
  196. package/src/generators/crate/crate.js +108 -0
  197. package/src/generators/crate/crate.js.map +1 -0
  198. package/src/generators/crate/enclosing-workspace.d.ts +25 -0
  199. package/src/generators/crate/enclosing-workspace.js +58 -0
  200. package/src/generators/crate/enclosing-workspace.js.map +1 -0
  201. package/src/generators/crate/library.schema.json +28 -0
  202. package/src/generators/init/graph-check.d.ts +81 -0
  203. package/src/generators/init/graph-check.js +299 -0
  204. package/src/generators/init/graph-check.js.map +1 -0
  205. package/src/generators/init/init.d.ts +23 -0
  206. package/src/generators/init/init.js +113 -0
  207. package/src/generators/init/init.js.map +1 -0
  208. package/src/generators/init/report.d.ts +19 -0
  209. package/src/generators/init/report.js +93 -0
  210. package/src/generators/init/report.js.map +1 -0
  211. package/src/generators/init/schema.json +9 -0
  212. package/src/graph/artifact-kinds.d.ts +29 -0
  213. package/src/graph/artifact-kinds.js +50 -0
  214. package/src/graph/artifact-kinds.js.map +1 -0
  215. package/src/graph/artifact-names.d.ts +97 -0
  216. package/src/graph/artifact-names.js +276 -0
  217. package/src/graph/artifact-names.js.map +1 -0
  218. package/src/graph/build-records.d.ts +74 -0
  219. package/src/graph/build-records.js +104 -0
  220. package/src/graph/build-records.js.map +1 -0
  221. package/src/graph/caching.d.ts +148 -0
  222. package/src/graph/caching.js +676 -0
  223. package/src/graph/caching.js.map +1 -0
  224. package/src/graph/collisions.d.ts +106 -0
  225. package/src/graph/collisions.js +156 -0
  226. package/src/graph/collisions.js.map +1 -0
  227. package/src/graph/computation-reports.d.ts +89 -0
  228. package/src/graph/computation-reports.js +216 -0
  229. package/src/graph/computation-reports.js.map +1 -0
  230. package/src/graph/declared-files.d.ts +190 -0
  231. package/src/graph/declared-files.js +600 -0
  232. package/src/graph/declared-files.js.map +1 -0
  233. package/src/graph/discovery.d.ts +175 -0
  234. package/src/graph/discovery.js +656 -0
  235. package/src/graph/discovery.js.map +1 -0
  236. package/src/graph/edges.d.ts +25 -0
  237. package/src/graph/edges.js +94 -0
  238. package/src/graph/edges.js.map +1 -0
  239. package/src/graph/entries.d.ts +83 -0
  240. package/src/graph/entries.js +259 -0
  241. package/src/graph/entries.js.map +1 -0
  242. package/src/graph/inputs.d.ts +420 -0
  243. package/src/graph/inputs.js +746 -0
  244. package/src/graph/inputs.js.map +1 -0
  245. package/src/graph/lockfile-task.d.ts +74 -0
  246. package/src/graph/lockfile-task.js +105 -0
  247. package/src/graph/lockfile-task.js.map +1 -0
  248. package/src/graph/names.d.ts +41 -0
  249. package/src/graph/names.js +34 -0
  250. package/src/graph/names.js.map +1 -0
  251. package/src/graph/napi.d.ts +107 -0
  252. package/src/graph/napi.js +206 -0
  253. package/src/graph/napi.js.map +1 -0
  254. package/src/graph/nx-glob.d.ts +36 -0
  255. package/src/graph/nx-glob.js +152 -0
  256. package/src/graph/nx-glob.js.map +1 -0
  257. package/src/graph/nx-internals.d.ts +57 -0
  258. package/src/graph/nx-internals.js +128 -0
  259. package/src/graph/nx-internals.js.map +1 -0
  260. package/src/graph/options.d.ts +32 -0
  261. package/src/graph/options.js +80 -0
  262. package/src/graph/options.js.map +1 -0
  263. package/src/graph/outputs.d.ts +75 -0
  264. package/src/graph/outputs.js +140 -0
  265. package/src/graph/outputs.js.map +1 -0
  266. package/src/graph/path-dependencies.d.ts +122 -0
  267. package/src/graph/path-dependencies.js +459 -0
  268. package/src/graph/path-dependencies.js.map +1 -0
  269. package/src/graph/plugin-package.d.ts +36 -0
  270. package/src/graph/plugin-package.js +132 -0
  271. package/src/graph/plugin-package.js.map +1 -0
  272. package/src/graph/plugin-version.d.ts +20 -0
  273. package/src/graph/plugin-version.js +153 -0
  274. package/src/graph/plugin-version.js.map +1 -0
  275. package/src/graph/projects.d.ts +141 -0
  276. package/src/graph/projects.js +182 -0
  277. package/src/graph/projects.js.map +1 -0
  278. package/src/graph/reached-projects.d.ts +46 -0
  279. package/src/graph/reached-projects.js +102 -0
  280. package/src/graph/reached-projects.js.map +1 -0
  281. package/src/graph/real-path.d.ts +47 -0
  282. package/src/graph/real-path.js +113 -0
  283. package/src/graph/real-path.js.map +1 -0
  284. package/src/graph/redirected-uses.d.ts +98 -0
  285. package/src/graph/redirected-uses.js +434 -0
  286. package/src/graph/redirected-uses.js.map +1 -0
  287. package/src/graph/registration.d.ts +121 -0
  288. package/src/graph/registration.js +233 -0
  289. package/src/graph/registration.js.map +1 -0
  290. package/src/graph/script-input.d.ts +46 -0
  291. package/src/graph/script-input.js +65 -0
  292. package/src/graph/script-input.js.map +1 -0
  293. package/src/graph/settings.d.ts +178 -0
  294. package/src/graph/settings.js +479 -0
  295. package/src/graph/settings.js.map +1 -0
  296. package/src/graph/target-defaults-causes.d.ts +33 -0
  297. package/src/graph/target-defaults-causes.js +202 -0
  298. package/src/graph/target-defaults-causes.js.map +1 -0
  299. package/src/graph/target-defaults-layers.d.ts +186 -0
  300. package/src/graph/target-defaults-layers.js +420 -0
  301. package/src/graph/target-defaults-layers.js.map +1 -0
  302. package/src/graph/target-defaults-meaning.d.ts +95 -0
  303. package/src/graph/target-defaults-meaning.js +292 -0
  304. package/src/graph/target-defaults-meaning.js.map +1 -0
  305. package/src/graph/target-defaults-report.d.ts +77 -0
  306. package/src/graph/target-defaults-report.js +242 -0
  307. package/src/graph/target-defaults-report.js.map +1 -0
  308. package/src/graph/target-defaults.d.ts +79 -0
  309. package/src/graph/target-defaults.js +425 -0
  310. package/src/graph/target-defaults.js.map +1 -0
  311. package/src/graph/target-fields.d.ts +16 -0
  312. package/src/graph/target-fields.js +134 -0
  313. package/src/graph/target-fields.js.map +1 -0
  314. package/src/graph/target-tables.d.ts +45 -0
  315. package/src/graph/target-tables.js +299 -0
  316. package/src/graph/target-tables.js.map +1 -0
  317. package/src/graph/targets.d.ts +367 -0
  318. package/src/graph/targets.js +404 -0
  319. package/src/graph/targets.js.map +1 -0
  320. package/src/graph/unification.d.ts +141 -0
  321. package/src/graph/unification.js +459 -0
  322. package/src/graph/unification.js.map +1 -0
  323. package/src/graph/unignored-directories.d.ts +25 -0
  324. package/src/graph/unignored-directories.js +89 -0
  325. package/src/graph/unignored-directories.js.map +1 -0
  326. package/src/graph/visibility.d.ts +17 -0
  327. package/src/graph/visibility.js +67 -0
  328. package/src/graph/visibility.js.map +1 -0
  329. package/src/graph/warnings.d.ts +38 -0
  330. package/src/graph/warnings.js +77 -0
  331. package/src/graph/warnings.js.map +1 -0
  332. package/src/graph/wasm.d.ts +56 -0
  333. package/src/graph/wasm.js +77 -0
  334. package/src/graph/wasm.js.map +1 -0
  335. package/src/index.d.ts +68 -0
  336. package/src/index.js +109 -0
  337. package/src/index.js.map +1 -0
  338. package/src/release/manifests.d.ts +95 -0
  339. package/src/release/manifests.js +164 -0
  340. package/src/release/manifests.js.map +1 -0
  341. package/src/release/places.d.ts +127 -0
  342. package/src/release/places.js +368 -0
  343. package/src/release/places.js.map +1 -0
  344. package/src/release/publish-cargo.d.ts +177 -0
  345. package/src/release/publish-cargo.js +351 -0
  346. package/src/release/publish-cargo.js.map +1 -0
  347. package/src/release/publish-crates.d.ts +124 -0
  348. package/src/release/publish-crates.js +242 -0
  349. package/src/release/publish-crates.js.map +1 -0
  350. package/src/release/publish-environments.d.ts +50 -0
  351. package/src/release/publish-environments.js +284 -0
  352. package/src/release/publish-environments.js.map +1 -0
  353. package/src/release/publish-messages.d.ts +66 -0
  354. package/src/release/publish-messages.js +273 -0
  355. package/src/release/publish-messages.js.map +1 -0
  356. package/src/release/publish-registry.d.ts +27 -0
  357. package/src/release/publish-registry.js +135 -0
  358. package/src/release/publish-registry.js.map +1 -0
  359. package/src/release/publish-settings.d.ts +26 -0
  360. package/src/release/publish-settings.js +56 -0
  361. package/src/release/publish-settings.js.map +1 -0
  362. package/src/release/publish.d.ts +59 -0
  363. package/src/release/publish.js +620 -0
  364. package/src/release/publish.js.map +1 -0
  365. package/src/release/repository.d.ts +73 -0
  366. package/src/release/repository.js +219 -0
  367. package/src/release/repository.js.map +1 -0
  368. package/src/release/requirements.d.ts +34 -0
  369. package/src/release/requirements.js +30 -0
  370. package/src/release/requirements.js.map +1 -0
  371. package/src/release/toml-edit.d.ts +67 -0
  372. package/src/release/toml-edit.js +453 -0
  373. package/src/release/toml-edit.js.map +1 -0
  374. package/src/release/version-actions.d.ts +133 -0
  375. package/src/release/version-actions.js +474 -0
  376. package/src/release/version-actions.js.map +1 -0
  377. package/src/release/version-checks.d.ts +21 -0
  378. package/src/release/version-checks.js +151 -0
  379. package/src/release/version-checks.js.map +1 -0
  380. package/src/release/version-lockfiles.d.ts +61 -0
  381. package/src/release/version-lockfiles.js +222 -0
  382. package/src/release/version-lockfiles.js.map +1 -0
  383. package/src/tools/napi-cli.d.ts +70 -0
  384. package/src/tools/napi-cli.js +63 -0
  385. package/src/tools/napi-cli.js.map +1 -0
  386. package/src/tools/optional-tools.d.ts +121 -0
  387. package/src/tools/optional-tools.js +303 -0
  388. package/src/tools/optional-tools.js.map +1 -0
  389. package/src/tools/print-napi-cli.d.ts +1 -0
  390. package/src/tools/print-napi-cli.js +24 -0
  391. package/src/tools/print-napi-cli.js.map +1 -0
@@ -0,0 +1,656 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.discoverWorkspaces = discoverWorkspaces;
4
+ exports.discoverReportedWorkspaces = discoverReportedWorkspaces;
5
+ exports.describeWorkspaces = describeWorkspaces;
6
+ const tslib_1 = require("tslib");
7
+ const node_fs_1 = require("node:fs");
8
+ const node_path_1 = require("node:path");
9
+ const configured_tools_1 = require("../cargo/configured-tools");
10
+ const paths_crates_1 = require("../cargo/paths-crates");
11
+ const redirections_1 = require("../cargo/redirections");
12
+ const target_triples_1 = require("../cargo/target-triples");
13
+ const run_cargo_1 = require("../cargo/run-cargo");
14
+ const cargo_version_1 = require("../compatibility/cargo-version");
15
+ const computation_reports_1 = require("./computation-reports");
16
+ const real_path_1 = require("./real-path");
17
+ const visibility_1 = require("./visibility");
18
+ /**
19
+ * Finds the Cargo workspaces among the manifests that Nx hands to the plugin
20
+ * and reads each one's `cargo metadata` report as cargo gives it in the
21
+ * workspace's root folder, where the workspace's tasks run cargo: where Nx
22
+ * does not hand the root manifest, that takes a second request
23
+ * ({@link readWorkspace}).
24
+ *
25
+ * Until every manifest is claimed, the shallowest unclaimed one is read, and
26
+ * the workspace its report describes claims its root manifest and its
27
+ * members. A crate outside every workspace, or excluded by the workspace
28
+ * around it, is still unclaimed after that workspace's step and becomes a
29
+ * workspace of one. Each workspace's redirections are read from its root
30
+ * manifest and the configuration files that apply to it.
31
+ *
32
+ * A manifest whose folder holds `.cargo-checksum.json` belongs to a package
33
+ * of a directory source, such as a crate that `cargo vendor` wrote, and is
34
+ * never read: such a crate gets a project only as a member of a workspace
35
+ * that another manifest's report describes, as when a path dependency makes
36
+ * cargo enrol it ({@link isDirectorySourcePackage}).
37
+ *
38
+ * Afterwards, every path dependency without a project, and every crate
39
+ * without a project that `[patch]`, `[replace]` or `paths` redirects to,
40
+ * whose crate no report covers yet gets a report of its own, so that the
41
+ * path dependencies behind it are known. A package of a directory source
42
+ * gets none. The crates of a `paths` entry are found below its folder as
43
+ * cargo finds them, once per folder, and only where a workspace has such an
44
+ * entry ({@link cratesBelowPathsFolder}), together with their path
45
+ * dependencies of every kind ({@link pathsCandidates}).
46
+ *
47
+ * @param manifests The `Cargo.toml` files, relative to `workspaceRoot`.
48
+ * @param workspaceRoot The absolute path of the repository root.
49
+ * @param reports Where the reports come from: the reports of the graph
50
+ * computation, which other plugin entries may share.
51
+ * @throws {Error} When cargo cannot be started or a report fails, naming the
52
+ * manifest, or when a manifest or configuration file is no valid TOML.
53
+ */
54
+ // @mara implements DES-DISCOVERY
55
+ function discoverWorkspaces(manifests_1, workspaceRoot_1) {
56
+ return tslib_1.__awaiter(this, arguments, void 0, function* (manifests, workspaceRoot, reports = new computation_reports_1.ComputationReports()) {
57
+ var _a, e_1, _b, _c;
58
+ const handed = new Set(manifests);
59
+ const workspaces = [];
60
+ const warnings = [];
61
+ try {
62
+ for (var _d = true, _e = tslib_1.__asyncValues(claimWorkspaces(manifests, workspaceRoot, reports)), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
63
+ _c = _f.value;
64
+ _d = false;
65
+ const { report, rootManifest, memberPackages } = _c;
66
+ const found = yield (0, redirections_1.readRedirections)(report.workspace_root);
67
+ warnings.push(...found.warnings);
68
+ workspaces.push({
69
+ root: repositoryPath(workspaceRoot, report.workspace_root) || ".",
70
+ rootManifest,
71
+ rootManifestHanded: handed.has(rootManifest),
72
+ report,
73
+ members: memberPackages
74
+ .filter((pkg) => handed.has(repositoryPath(workspaceRoot, pkg.manifest_path)))
75
+ .sort((a, b) => compare(a.manifest_path, b.manifest_path)),
76
+ redirections: found.redirections,
77
+ triples: (0, target_triples_1.pickedTriples)(report.workspace_root, process.env),
78
+ configuredTriples: (0, target_triples_1.configuredTriples)(report.workspace_root, process.env),
79
+ configuredTools: (0, configured_tools_1.configuredTools)(report.workspace_root, process.env),
80
+ configIncludes: found.includedFiles,
81
+ configFiles: found.configFiles,
82
+ warnings: [...new Set(found.warnings)],
83
+ configurationWarnings: [],
84
+ });
85
+ }
86
+ }
87
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
88
+ finally {
89
+ try {
90
+ if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
91
+ }
92
+ finally { if (e_1) throw e_1.error; }
93
+ }
94
+ const unreportedPathDependencies = new Map();
95
+ const pathsFolders = pathsFolderCrates(workspaces);
96
+ const { pathDependencyReports, candidates } = yield readPathDependencies(workspaces, workspaceRoot, reports, warnings, unreportedPathDependencies, pathsFolders);
97
+ for (const workspace of workspaces) {
98
+ const paths = workspace.redirections.filter((redirection) => redirection.table === "paths");
99
+ if (paths.length > 0) {
100
+ workspace.pathsCrates = new Map(paths.map(({ folder }) => { var _a; return [folder, (_a = candidates.get((0, real_path_1.realPath)(folder))) !== null && _a !== void 0 ? _a : []]; }));
101
+ }
102
+ }
103
+ warnings.push(...(yield unhashedConfigurationWarnings(workspaces, workspaceRoot)));
104
+ return {
105
+ workspaceRoot,
106
+ workspaces,
107
+ pathDependencyReports,
108
+ warnings: [...new Set(warnings)],
109
+ unreportedPathDependencies,
110
+ };
111
+ });
112
+ }
113
+ /**
114
+ * The workspaces that the manifests make up, each as its root folder and
115
+ * report, found as {@link discoverWorkspaces} finds them: the shallowest
116
+ * unclaimed manifest is read until every manifest is claimed. Nothing else
117
+ * of the workspaces is read. For the workspaces that other entries of the
118
+ * plugin receive, whose artifact directories graph creation compares with
119
+ * its own (`DES-OUTPUTS`, "Files of one name").
120
+ *
121
+ * @throws {Error} As {@link discoverWorkspaces} does for a report.
122
+ */
123
+ function discoverReportedWorkspaces(manifests_1, workspaceRoot_1) {
124
+ return tslib_1.__awaiter(this, arguments, void 0, function* (manifests, workspaceRoot, reports = new computation_reports_1.ComputationReports()) {
125
+ var _a, e_2, _b, _c;
126
+ const workspaces = [];
127
+ try {
128
+ for (var _d = true, _e = tslib_1.__asyncValues(claimWorkspaces(manifests, workspaceRoot, reports)), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
129
+ _c = _f.value;
130
+ _d = false;
131
+ const { report } = _c;
132
+ workspaces.push({ root: repositoryPath(workspaceRoot, report.workspace_root) || ".", report });
133
+ }
134
+ }
135
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
136
+ finally {
137
+ try {
138
+ if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
139
+ }
140
+ finally { if (e_2) throw e_2.error; }
141
+ }
142
+ return workspaces;
143
+ });
144
+ }
145
+ // The workspaces that the manifests make up, in the order of discovery:
146
+ // the shallowest unclaimed manifest is read, and the workspace that its
147
+ // report describes claims its root manifest and its members. A manifest of
148
+ // a directory source is never read (`isDirectorySourcePackage`).
149
+ function claimWorkspaces(manifests, workspaceRoot, reports) {
150
+ return tslib_1.__asyncGenerator(this, arguments, function* claimWorkspaces_1() {
151
+ const claimed = new Set();
152
+ const readable = manifests.filter((manifest) => !isDirectorySourcePackage((0, node_path_1.join)(workspaceRoot, manifest)));
153
+ for (const manifest of [...readable].sort(shallowestFirst)) {
154
+ if (claimed.has(manifest)) {
155
+ continue;
156
+ }
157
+ const report = yield tslib_1.__await(readWorkspace(manifest, workspaceRoot, reports));
158
+ const members = new Set(report.workspace_members);
159
+ const memberPackages = report.packages.filter((pkg) => members.has(pkg.id));
160
+ const rootManifest = repositoryPath(workspaceRoot, (0, node_path_1.join)(report.workspace_root, "Cargo.toml"));
161
+ claimed.add(manifest);
162
+ claimed.add(rootManifest);
163
+ for (const pkg of memberPackages) {
164
+ claimed.add(repositoryPath(workspaceRoot, pkg.manifest_path));
165
+ }
166
+ yield yield tslib_1.__await({ report, rootManifest, memberPackages });
167
+ }
168
+ });
169
+ }
170
+ /**
171
+ * The top-level keys of a Cargo configuration file whose settings can
172
+ * change what cargo builds or checks: the compiler, its flags and the
173
+ * linker, the profiles, the environment, the sources and the unstable
174
+ * features (`DES-DIAGNOSTICS`). `[resolver]`, `[registry]` and
175
+ * `[registries]` change only what `Cargo.lock` records, which the keys
176
+ * follow through the lockfile task's digests.
177
+ */
178
+ const buildTables = [
179
+ "build",
180
+ "target",
181
+ "host",
182
+ "profile",
183
+ "env",
184
+ "patch",
185
+ "source",
186
+ "paths",
187
+ "unstable",
188
+ "doc",
189
+ ];
190
+ /**
191
+ * One warning for each file that cargo reads for a workspace, that Nx does
192
+ * not hash, and that sets something that can change a build or a check
193
+ * ({@link buildTables}) or redirects dependencies: a configuration file
194
+ * outside the repository, such as the Cargo home's, and a configuration
195
+ * file or root manifest inside it that an ignore rule, such as one in
196
+ * `.gitignore` or `.nxignore`, leaves out of the files that Nx reads
197
+ * ({@link filesNxSees}). A result cached before a change to such a file can
198
+ * be restored after it, and where the file redirects dependencies, the Nx
199
+ * daemon keeps the graph's edges until it creates the graph again for
200
+ * another reason (`EVD-CARGO-REDIRECTIONS`, `RISK-HOST-ENVIRONMENT`).
201
+ *
202
+ * Each warning joins the {@link CargoWorkspace.configurationWarnings} of
203
+ * the workspaces it names, and stays out of their projects' keys, so that a
204
+ * Cargo configuration of one machine gives no keys of their own. It is
205
+ * printed at the start of every task, so it is kept to a few lines, and
206
+ * points to the caching guide for more.
207
+ */
208
+ // @mara implements DES-DIAGNOSTICS
209
+ function unhashedConfigurationWarnings(workspaces, workspaceRoot) {
210
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
211
+ const byFile = new Map();
212
+ const entry = (file, workspace) => {
213
+ var _a;
214
+ const found = (_a = byFile.get(file)) !== null && _a !== void 0 ? _a : { concerned: [], tables: new Set(), redirects: new Set() };
215
+ if (!found.concerned.includes(workspace)) {
216
+ found.concerned.push(workspace);
217
+ }
218
+ byFile.set(file, found);
219
+ return found;
220
+ };
221
+ for (const workspace of workspaces) {
222
+ for (const { file, keys } of workspace.configFiles) {
223
+ const counted = keys.filter((key) => buildTables.includes(key));
224
+ if (counted.length > 0) {
225
+ const found = entry(file, workspace);
226
+ counted.forEach((key) => found.tables.add(key));
227
+ }
228
+ }
229
+ for (const { file, table } of workspace.redirections) {
230
+ entry(file, workspace).redirects.add(table);
231
+ }
232
+ }
233
+ const inside = [...byFile.keys()]
234
+ .filter((file) => !isOutside(workspaceRoot, file))
235
+ .map((file) => repositoryPath(workspaceRoot, file));
236
+ const seen = yield (0, visibility_1.filesNxSees)(workspaceRoot, inside);
237
+ const messages = [];
238
+ for (const [file, { concerned, tables, redirects }] of byFile) {
239
+ const outside = isOutside(workspaceRoot, file);
240
+ if (!outside && seen.has(repositoryPath(workspaceRoot, file))) {
241
+ continue;
242
+ }
243
+ const shown = displayPath(workspaceRoot, file);
244
+ const subject = describeWorkspaces(concerned.map((workspace) => workspace.root));
245
+ const through = tableList(["patch", "replace", "paths"].filter((table) => redirects.has(table)));
246
+ const graph = `with the Nx daemon, the graph keeps these edges until a file that Nx reads changes or the daemon restarts (\`nx reset\`)`;
247
+ const guide = 'see "Cargo configuration that Nx does not hash" in the nx-rust caching guide';
248
+ // A root manifest sets nothing else that this warning names.
249
+ const message = (tables.size === 0
250
+ ? [
251
+ `nx-rust: ${shown} redirects dependencies of ${subject} through ${through}, so nx-rust gives the crates that may use the redirected crates edges to them.`,
252
+ outside
253
+ ? `The file lies outside the repository, so Nx does not see when it changes: ${graph}.`
254
+ : `An ignore rule, such as one in .gitignore or .nxignore, leaves the file out of the files that Nx reads, so Nx does not see when it changes: ${graph}.`,
255
+ outside
256
+ ? "To let Nx follow the redirections, move them into the root Cargo.toml of the workspace that needs them or into a .cargo/config.toml inside the repository."
257
+ : "To let Nx follow the redirections, stop ignoring the file, or run `nx reset` after each change to it.",
258
+ ]
259
+ : [
260
+ `nx-rust: ${shown} sets ${tableList(buildTables.filter((table) => tables.has(table)))} for ${subject}, but ${outside ? "lies outside the repository" : "an ignore rule leaves it out of the files that Nx reads"}, so Nx does not hash it, and a result cached before a change to it can be restored afterwards.`,
261
+ ...(redirects.size === 0
262
+ ? []
263
+ : [
264
+ `It redirects dependencies through ${through}; with the Nx daemon, the graph's edges follow a change to it only once Nx creates the graph again.`,
265
+ ]),
266
+ `${outside ? "Run" : "Stop ignoring it to have Nx hash it, or run"} \`nx reset\` after each change to it; --skip-nx-cache covers only the command it is given to (${guide}).`,
267
+ ]).join("\n");
268
+ for (const workspace of concerned) {
269
+ if (!workspace.configurationWarnings.includes(message)) {
270
+ workspace.configurationWarnings.push(message);
271
+ }
272
+ }
273
+ messages.push(message);
274
+ }
275
+ return messages;
276
+ });
277
+ }
278
+ // "[build]", "[build] and paths", or "[build], [env] and paths".
279
+ function tableList(tables) {
280
+ const named = tables.map((table) => (table === "paths" ? table : `[${table}]`));
281
+ return named.length <= 1
282
+ ? named.join("")
283
+ : `${named.slice(0, -1).join(", ")} and ${named[named.length - 1]}`;
284
+ }
285
+ // Adds a warning to those that the workspace's projects repeat, once.
286
+ function addWarning(workspace, message) {
287
+ if (!workspace.warnings.includes(message)) {
288
+ workspace.warnings.push(message);
289
+ }
290
+ }
291
+ /** "the Cargo workspace in rust", or "the Cargo workspaces in rust and shared". */
292
+ function describeWorkspaces(folders) {
293
+ const named = folders.map((folder) => (folder === "." ? "the repository root" : folder));
294
+ if (named.length === 1) {
295
+ return folders[0] === "."
296
+ ? "the Cargo workspace at the repository root"
297
+ : `the Cargo workspace in ${named[0]}`;
298
+ }
299
+ return `the Cargo workspaces in ${named.slice(0, -1).join(", ")} and ${named[named.length - 1]}`;
300
+ }
301
+ /**
302
+ * The folders of the crates that cargo finds below the folder of each
303
+ * `paths` entry of the workspaces ({@link cratesBelowPathsFolder}), by the
304
+ * real path of the entry's folder, each folder walked once. Without a
305
+ * `paths` entry, nothing is walked.
306
+ */
307
+ // @mara implements DES-METADATA-REPORT
308
+ function pathsFolderCrates(workspaces) {
309
+ const found = new Map();
310
+ for (const workspace of workspaces) {
311
+ for (const redirection of workspace.redirections) {
312
+ const real = (0, real_path_1.realPath)(redirection.folder);
313
+ if (redirection.table === "paths" && !found.has(real)) {
314
+ found.set(real, (0, paths_crates_1.cratesBelowPathsFolder)(real));
315
+ }
316
+ }
317
+ }
318
+ return found;
319
+ }
320
+ /**
321
+ * The crates that a `paths` entry can redirect to, by real folder: those
322
+ * that cargo finds below its folder (`found`) and, as cargo takes them as
323
+ * well, the path dependencies of each, of every kind, dev-dependencies and
324
+ * those for other platforms included, to any depth, inside or outside the
325
+ * folder, through crates with a project or without
326
+ * (`EVD-CARGO-REDIRECTIONS`). A crate that no report describes counts,
327
+ * but what it depends on is not known.
328
+ *
329
+ * This is not the walk that says what cargo builds with a crate, which
330
+ * takes normal and build dependencies only (`projectsBehindDependency` in
331
+ * `reached-projects.ts`): cargo takes these crates as candidates whether or
332
+ * not it compiles the crate that names them.
333
+ */
334
+ // @mara implements DES-METADATA-REPORT
335
+ function pathsCandidates(found, known) {
336
+ var _a, _b;
337
+ const candidates = [];
338
+ const visited = new Set();
339
+ const queue = [...found];
340
+ while (queue.length > 0) {
341
+ const folder = queue.shift();
342
+ if (visited.has(folder)) {
343
+ continue;
344
+ }
345
+ visited.add(folder);
346
+ candidates.push(folder);
347
+ for (const dependency of (_b = (_a = known.get(folder)) === null || _a === void 0 ? void 0 : _a.dependencies) !== null && _b !== void 0 ? _b : []) {
348
+ if (typeof dependency.path === "string") {
349
+ queue.push((0, real_path_1.realPath)(dependency.path));
350
+ }
351
+ }
352
+ }
353
+ return candidates;
354
+ }
355
+ /**
356
+ * Requests a report for each crate that the members reach through path
357
+ * dependencies, directly or through other such crates, and for each crate
358
+ * that a workspace's `[patch]` or `[replace]` entry redirects to, or that
359
+ * cargo takes from the folder of a `paths` entry (`pathsFolders`), that has
360
+ * no project and that no report covers yet; then for the crates that those
361
+ * reach through path dependencies, of every kind. Then it returns, by the
362
+ * real path of each `paths` folder, the crates that the entry can redirect
363
+ * to ({@link pathsCandidates}), without a folder whose report describes no
364
+ * package there, which holds a virtual manifest and no crate, as the root
365
+ * folder of a workspace whose report lists no package there does. Cargo
366
+ * starts in the root folder of the workspace whose member the walk started
367
+ * from, or whose table redirects to the crate: there the member's tasks
368
+ * run, and so there plain cargo reads the crate. A redirection to a folder
369
+ * without a `Cargo.toml` gets no report: cargo fails when it applies one,
370
+ * and the plugin leaves that failure to the cargo of the tasks. A crate,
371
+ * whether a path or a redirection names it, is compared with the crates
372
+ * that have projects and with those that a report describes by the real
373
+ * path of its folder, through symbolic links, so a path through a link to a
374
+ * crate with a project asks for no report.
375
+ *
376
+ * When cargo fails for a redirected crate, as for a crate inside a
377
+ * workspace's folder that is not its member, which cargo builds as a patch
378
+ * but does not report, graph creation goes on: a warning in `warnings` names
379
+ * the manifest and cargo's message, and the crate has no report. So it does
380
+ * for a path dependency whose report cargo refuses for a reason that it
381
+ * checks only for the crate it reports, which it builds as a dependency all
382
+ * the same ({@link isUnreportedPathDependency}); any other failure of a
383
+ * path dependency's report fails graph creation. Such a path dependency's warning
384
+ * also goes into `unreported`, by the real path of the crate's folder, and
385
+ * the warning of a redirected crate joins the {@link CargoWorkspace.warnings}
386
+ * of each workspace whose table redirects to it.
387
+ *
388
+ * A package of a directory source that no workspace report lists as a
389
+ * member gets no report ({@link isDirectorySourcePackage}); like any crate
390
+ * without a project, its folder is an input of the crates that use it.
391
+ */
392
+ // @mara implements DES-METADATA-REPORT
393
+ function readPathDependencies(workspaces, workspaceRoot, reports, warnings, unreported, pathsFolders) {
394
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
395
+ var _a;
396
+ // Crates by the real paths of their folders: a path names the crate at
397
+ // the real path of its folder, also where it passes a symbolic link.
398
+ const folderOf = (manifest) => (0, real_path_1.realPath)((0, node_path_1.dirname)(manifest));
399
+ const withProject = new Set(workspaces.flatMap((workspace) => workspace.members.map((pkg) => folderOf(pkg.manifest_path))));
400
+ const known = new Map();
401
+ for (const workspace of workspaces) {
402
+ for (const pkg of workspace.report.packages) {
403
+ known.set(folderOf(pkg.manifest_path), pkg);
404
+ }
405
+ }
406
+ // The root folders of the workspaces, whose reports describe any package there.
407
+ const workspaceRoots = new Set(workspaces.map((workspace) => (0, real_path_1.realPath)(workspace.report.workspace_root)));
408
+ const pathDependencyReports = [];
409
+ const noCrate = new Set();
410
+ const visited = new Set();
411
+ // The warning for each crate whose report cargo refused, by its real folder.
412
+ const failures = new Map();
413
+ const queue = [];
414
+ // Requests the report of a crate without a project, unless one covers it
415
+ // already, and queues the crate so that its path dependencies follow. A
416
+ // failure of cargo that graph creation goes on after, for a crate reached
417
+ // by path or by redirection, becomes a warning and leaves the crate
418
+ // without a report.
419
+ const reach = (manifest, cwd, subject, via) => tslib_1.__awaiter(this, void 0, void 0, function* () {
420
+ const folder = folderOf(manifest);
421
+ if (withProject.has(folder) || visited.has(folder)) {
422
+ return;
423
+ }
424
+ visited.add(folder);
425
+ if (!known.has(folder) && workspaceRoots.has(folder)) {
426
+ noCrate.add(folder);
427
+ return;
428
+ }
429
+ if (!known.has(folder) && isDirectorySourcePackage(manifest)) {
430
+ return;
431
+ }
432
+ if (!known.has(folder)) {
433
+ const report = yield readPathDependency(manifest, subject(), cwd, workspaceRoot, reports, via === "path" ? (error) => isUnreportedPathDependency(error, manifest) : () => true);
434
+ if (typeof report === "string") {
435
+ warnings.push(report);
436
+ failures.set(folder, report);
437
+ if (via === "path") {
438
+ unreported.set(folder, report);
439
+ }
440
+ return;
441
+ }
442
+ pathDependencyReports.push({ manifest: repositoryPath(workspaceRoot, manifest), report });
443
+ for (const pkg of report.packages) {
444
+ if (!known.has(folderOf(pkg.manifest_path))) {
445
+ known.set(folderOf(pkg.manifest_path), pkg);
446
+ }
447
+ }
448
+ }
449
+ const pkg = known.get(folder);
450
+ if (pkg) {
451
+ queue.push({ pkg, cwd });
452
+ }
453
+ else {
454
+ noCrate.add(folder);
455
+ }
456
+ });
457
+ const drain = () => tslib_1.__awaiter(this, void 0, void 0, function* () {
458
+ while (queue.length > 0) {
459
+ const { pkg: dependent, cwd } = queue.shift();
460
+ for (const dependency of dependent.dependencies) {
461
+ if (typeof dependency.path === "string") {
462
+ yield reach((0, node_path_1.join)(dependency.path, "Cargo.toml"), cwd, () => `a path dependency of ${displayPath(workspaceRoot, dependent.manifest_path)} that has no project of its own`, "path");
463
+ }
464
+ }
465
+ }
466
+ });
467
+ for (const workspace of workspaces) {
468
+ for (const pkg of workspace.members) {
469
+ queue.push({ pkg, cwd: workspace.report.workspace_root });
470
+ }
471
+ }
472
+ yield drain();
473
+ for (const workspace of workspaces) {
474
+ for (const { table, folder, file } of workspace.redirections) {
475
+ const manifests = table === "paths"
476
+ ? ((_a = pathsFolders.get((0, real_path_1.realPath)(folder))) !== null && _a !== void 0 ? _a : []).map((crate) => (0, node_path_1.join)(crate, "Cargo.toml"))
477
+ : [(0, node_path_1.join)(folder, "Cargo.toml")];
478
+ for (const manifest of manifests.filter((manifest) => (0, node_fs_1.existsSync)(manifest))) {
479
+ yield reach(manifest, workspace.report.workspace_root, () => `a crate that ${displayPath(workspaceRoot, file)} redirects dependencies of the Cargo workspace in ${workspace.root} to, which has no project of its own`, "redirection");
480
+ const failure = failures.get(folderOf(manifest));
481
+ if (failure !== undefined) {
482
+ addWarning(workspace, failure);
483
+ }
484
+ yield drain();
485
+ }
486
+ }
487
+ }
488
+ const candidates = new Map();
489
+ for (const [folder, found] of pathsFolders) {
490
+ candidates.set(folder, pathsCandidates(found, known).filter((crate) => !noCrate.has(crate)));
491
+ }
492
+ return { pathDependencyReports, candidates };
493
+ });
494
+ }
495
+ /**
496
+ * Whether the crate of a manifest, by its absolute path, is a package of a
497
+ * directory source, such as one that `cargo vendor` wrote: its folder holds
498
+ * `.cargo-checksum.json`, which `cargo vendor` writes for every crate it
499
+ * vendors and without which cargo refuses such a package. It is a package of
500
+ * the source that the directory replaces, not a crate of the repository,
501
+ * whatever configuration names the folder and wherever it lies.
502
+ */
503
+ // @mara implements DES-DISCOVERY
504
+ function isDirectorySourcePackage(manifest) {
505
+ return (0, node_fs_1.existsSync)((0, node_path_1.join)((0, node_path_1.dirname)(manifest), ".cargo-checksum.json"));
506
+ }
507
+ /**
508
+ * Reads the workspace of a manifest that Nx handed to the plugin. The
509
+ * report requested in the manifest's folder names the workspace root. Where
510
+ * that is another folder, because Nx did not hand the root manifest to the
511
+ * plugin, one more report is requested in the root folder, where the
512
+ * workspace's tasks run cargo, and replaces the first: cargo takes its
513
+ * configuration files, a relative `CARGO_TARGET_DIR` and rustup its
514
+ * toolchain from the folder it starts in, so only that report names the
515
+ * artifact and build directories that the tasks use (`DES-DISCOVERY`).
516
+ */
517
+ // @mara implements DES-DISCOVERY
518
+ function readWorkspace(manifest, workspaceRoot, reports) {
519
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
520
+ const path = (0, node_path_1.join)(workspaceRoot, manifest);
521
+ const found = yield requestWorkspace(manifest, workspaceRoot, (0, node_path_1.dirname)(path), () => reports.request(path, (0, node_path_1.dirname)(path)));
522
+ if (reports.fromRoot(found)) {
523
+ return found;
524
+ }
525
+ const root = found.workspace_root;
526
+ return requestWorkspace(manifest, workspaceRoot, root, () => reports.requestFromRoot((0, node_path_1.join)(root, "Cargo.toml")));
527
+ });
528
+ }
529
+ // Makes one request of `readWorkspace`, with cargo started in `cwd`.
530
+ function requestWorkspace(manifest, workspaceRoot, cwd, request) {
531
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
532
+ try {
533
+ return yield request();
534
+ }
535
+ catch (error) {
536
+ const folder = displayPath(workspaceRoot, cwd) || "the repository root";
537
+ throw new Error(failureMessage(error, `the Cargo workspace of ${manifest}`, [
538
+ `Fix what cargo reports, so that \`cargo metadata --no-deps\` succeeds in ${folder}.`,
539
+ `If Nx should not read this manifest, add its path to "exclude" on the @convesoft/nx-rust entry in nx.json.`,
540
+ ]));
541
+ }
542
+ });
543
+ }
544
+ /**
545
+ * Whether cargo refused the report of a crate for a reason that it checks
546
+ * only for the crate it reports, never for a path dependency or patch that
547
+ * it builds for another workspace, so that such a crate builds as before
548
+ * (`EVD-CARGO-UNREPORTED-CRATES`). Cargo 1.91 and later state each reason
549
+ * with one message:
550
+ *
551
+ * - "current package believes it's in a workspace when it's not": the crate
552
+ * lies in the folder of a workspace, or names one in `package.workspace`,
553
+ * without being its member;
554
+ * - "root of a workspace inferred but wasn't a root": the manifest that the
555
+ * crate's `package.workspace`, or that of a crate above it, names has no
556
+ * `[workspace]` table;
557
+ * - "failed to read" a manifest other than the crate's own: cargo cannot
558
+ * read that manifest, as where `package.workspace` names a missing folder.
559
+ *
560
+ * The last two count only as cargo's error itself, the first line of its
561
+ * output that starts with `error:`. Cargo prints them also below another
562
+ * error, as the cause of a manifest that it rejects, such as one that takes
563
+ * a key from a workspace that it cannot read, and then it fails to build the
564
+ * crate as a dependency as well. "failed to load manifest for workspace
565
+ * member" stays an error: cargo prints it also where the member that fails
566
+ * to load is one that the crate depends on.
567
+ *
568
+ * @param manifest The absolute path of the crate's manifest, which cargo
569
+ * names where it cannot read that manifest itself.
570
+ */
571
+ function isUnreportedPathDependency(error, manifest) {
572
+ var _a, _b, _c;
573
+ if (error.stderr.includes("current package believes it's in a workspace when it's not")) {
574
+ return true;
575
+ }
576
+ const failure = (_b = (_a = /^error: (.*)$/m.exec(error.stderr)) === null || _a === void 0 ? void 0 : _a[1].trim()) !== null && _b !== void 0 ? _b : "";
577
+ if (failure.startsWith("root of a workspace inferred but wasn't a root: ")) {
578
+ return true;
579
+ }
580
+ const unread = (_c = /^failed to read `(.+)`$/.exec(failure)) === null || _c === void 0 ? void 0 : _c[1];
581
+ return unread !== undefined && (0, real_path_1.realPath)(unread) !== (0, real_path_1.realPath)(manifest);
582
+ }
583
+ // Reads a crate without a project. A failure of cargo itself that `goesOn`
584
+ // accepts gives the warning to print instead of a report.
585
+ function readPathDependency(manifest, subject, cwd, workspaceRoot, reports, goesOn) {
586
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
587
+ const shown = displayPath(workspaceRoot, manifest);
588
+ const folder = displayPath(workspaceRoot, cwd) || "the repository root";
589
+ try {
590
+ return yield reports.request(manifest, cwd);
591
+ }
592
+ catch (error) {
593
+ if (error instanceof run_cargo_1.CargoError && !error.notStarted && goesOn(error)) {
594
+ const output = error.stderr.trim();
595
+ return [
596
+ `nx-rust: \`cargo metadata\` failed for ${shown}, ${subject}: ${error.message}.`,
597
+ ...(output === "" ? [] : [output]),
598
+ "nx-rust goes on without its report, so it does not follow the crates that this crate depends on by path: the crates that use it take only its own folder into their cache keys, and a change in a crate behind it can leave their keys unchanged.",
599
+ `To have those crates followed, fix what cargo reports, so that \`cargo metadata --no-deps --manifest-path ${shown}\` succeeds in ${folder}, or declare their files with fileInputs in the [package.metadata.nx] or [workspace.metadata.nx] table of the crates that use it.`,
600
+ ].join("\n");
601
+ }
602
+ throw new Error(failureMessage(error, `${shown}, ${subject}`, [
603
+ "nx-rust reads such a manifest to find the path dependencies behind it.",
604
+ `Fix what cargo reports, so that \`cargo metadata --no-deps --manifest-path ${shown}\` succeeds in ${folder}.`,
605
+ ]));
606
+ }
607
+ });
608
+ }
609
+ // A message that names what failed, for what, and what to do.
610
+ function failureMessage(error, subject, fixes) {
611
+ if (error instanceof cargo_version_1.UnsupportedCargoError) {
612
+ return error.messageFor(subject);
613
+ }
614
+ if (error instanceof run_cargo_1.CargoError && error.notStarted) {
615
+ return [
616
+ `nx-rust could not read ${subject}: ${error.message}.`,
617
+ "nx-rust asks cargo for the crates whenever Nx creates the project graph, so every machine that runs nx in this repository needs cargo.",
618
+ "Install a Rust toolchain or put cargo on PATH, then run the command again.",
619
+ ].join("\n");
620
+ }
621
+ if (error instanceof run_cargo_1.CargoError) {
622
+ const output = error.stderr.trim();
623
+ return [
624
+ `\`cargo metadata\` failed for ${subject}: ${error.message}.`,
625
+ ...(output === "" ? [] : [output]),
626
+ ...fixes,
627
+ ].join("\n");
628
+ }
629
+ const reason = error instanceof Error ? error.message : String(error);
630
+ return [
631
+ `\`cargo metadata\` printed no report that nx-rust can read for ${subject}: ${reason}.`,
632
+ "Check that the cargo on PATH is Cargo 1.91 or later.",
633
+ ].join("\n");
634
+ }
635
+ // The path relative to the repository root, with `/` separators, or "" for
636
+ // the root itself. A path outside the repository starts with "..".
637
+ function repositoryPath(workspaceRoot, path) {
638
+ return (0, node_path_1.relative)(workspaceRoot, path);
639
+ }
640
+ // A path for a message: relative to the repository root where it lies
641
+ // inside, absolute otherwise.
642
+ function displayPath(workspaceRoot, path) {
643
+ return isOutside(workspaceRoot, path) ? path : repositoryPath(workspaceRoot, path);
644
+ }
645
+ // Whether the path lies outside the repository.
646
+ function isOutside(workspaceRoot, path) {
647
+ const inside = repositoryPath(workspaceRoot, path);
648
+ return inside === ".." || inside.startsWith("../") || (0, node_path_1.isAbsolute)(inside);
649
+ }
650
+ function shallowestFirst(a, b) {
651
+ return a.split("/").length - b.split("/").length || compare(a, b);
652
+ }
653
+ function compare(a, b) {
654
+ return a < b ? -1 : a > b ? 1 : 0;
655
+ }
656
+ //# sourceMappingURL=discovery.js.map