@cybedefend/vibedefend 1.8.3 → 1.9.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 (320) hide show
  1. package/README.md +135 -16
  2. package/dist/clients/antigravity.js +30 -6
  3. package/dist/clients/antigravity.js.map +1 -1
  4. package/dist/clients/claude-code.js +209 -17
  5. package/dist/clients/claude-code.js.map +1 -1
  6. package/dist/clients/codex.js +171 -11
  7. package/dist/clients/codex.js.map +1 -1
  8. package/dist/clients/cursor.js +149 -9
  9. package/dist/clients/cursor.js.map +1 -1
  10. package/dist/clients/dependency-check-wiring.js +24 -0
  11. package/dist/clients/dependency-check-wiring.js.map +1 -0
  12. package/dist/clients/opencode-plugin.js +905 -0
  13. package/dist/clients/opencode-plugin.js.map +1 -0
  14. package/dist/clients/opencode.js +653 -0
  15. package/dist/clients/opencode.js.map +1 -0
  16. package/dist/clients/registry.js +2 -0
  17. package/dist/clients/registry.js.map +1 -1
  18. package/dist/clients/vscode.js +106 -12
  19. package/dist/clients/vscode.js.map +1 -1
  20. package/dist/clients/windsurf.js +9 -1
  21. package/dist/clients/windsurf.js.map +1 -1
  22. package/dist/commands/mcp/index.js +11 -0
  23. package/dist/commands/mcp/index.js.map +1 -1
  24. package/dist/config.js +3 -0
  25. package/dist/config.js.map +1 -1
  26. package/dist/diagnostics.js +22 -3
  27. package/dist/diagnostics.js.map +1 -1
  28. package/dist/doctor.js +26 -1
  29. package/dist/doctor.js.map +1 -1
  30. package/dist/guards-evaluator/command-analysis.js +347 -86
  31. package/dist/guards-evaluator/command-analysis.js.map +1 -1
  32. package/dist/guards-evaluator/command-view.js +116 -16
  33. package/dist/guards-evaluator/command-view.js.map +1 -1
  34. package/dist/guards-evaluator/evaluate.js +185 -41
  35. package/dist/guards-evaluator/evaluate.js.map +1 -1
  36. package/dist/guards-evaluator/file-reads.js +202 -0
  37. package/dist/guards-evaluator/file-reads.js.map +1 -0
  38. package/dist/guards-evaluator/index.js +1 -1
  39. package/dist/guards-evaluator/index.js.map +1 -1
  40. package/dist/guards-evaluator/inline-danger.js +299 -0
  41. package/dist/guards-evaluator/inline-danger.js.map +1 -0
  42. package/dist/guards-evaluator/normalize.js +1186 -55
  43. package/dist/guards-evaluator/normalize.js.map +1 -1
  44. package/dist/guards-evaluator/regex.js +91 -4
  45. package/dist/guards-evaluator/regex.js.map +1 -1
  46. package/dist/guards-evaluator/shell-files.js +587 -0
  47. package/dist/guards-evaluator/shell-files.js.map +1 -0
  48. package/dist/guards-evaluator/triage.js +32 -2
  49. package/dist/guards-evaluator/triage.js.map +1 -1
  50. package/dist/hook-runner.js +25598 -5432
  51. package/dist/hooks/install.js +8 -3
  52. package/dist/hooks/install.js.map +1 -1
  53. package/dist/hooks/runtime/antigravity-session.js +109 -50
  54. package/dist/hooks/runtime/antigravity-session.js.map +1 -1
  55. package/dist/hooks/runtime/apply-patch.js +92 -0
  56. package/dist/hooks/runtime/apply-patch.js.map +1 -0
  57. package/dist/hooks/runtime/caller-gate.js +27 -0
  58. package/dist/hooks/runtime/caller-gate.js.map +1 -0
  59. package/dist/hooks/runtime/code-mode.js +259 -0
  60. package/dist/hooks/runtime/code-mode.js.map +1 -0
  61. package/dist/hooks/runtime/dependency-check/api.js +179 -0
  62. package/dist/hooks/runtime/dependency-check/api.js.map +1 -0
  63. package/dist/hooks/runtime/dependency-check/capabilities.js +99 -0
  64. package/dist/hooks/runtime/dependency-check/capabilities.js.map +1 -0
  65. package/dist/hooks/runtime/dependency-check/checked-packages.js +48 -0
  66. package/dist/hooks/runtime/dependency-check/checked-packages.js.map +1 -0
  67. package/dist/hooks/runtime/dependency-check/commands/cwd.js +154 -0
  68. package/dist/hooks/runtime/dependency-check/commands/cwd.js.map +1 -0
  69. package/dist/hooks/runtime/dependency-check/commands/env.js +99 -0
  70. package/dist/hooks/runtime/dependency-check/commands/env.js.map +1 -0
  71. package/dist/hooks/runtime/dependency-check/commands/flags.js +164 -0
  72. package/dist/hooks/runtime/dependency-check/commands/flags.js.map +1 -0
  73. package/dist/hooks/runtime/dependency-check/commands/managers.js +418 -0
  74. package/dist/hooks/runtime/dependency-check/commands/managers.js.map +1 -0
  75. package/dist/hooks/runtime/dependency-check/commands/peel.js +111 -0
  76. package/dist/hooks/runtime/dependency-check/commands/peel.js.map +1 -0
  77. package/dist/hooks/runtime/dependency-check/commands/shell.js +217 -0
  78. package/dist/hooks/runtime/dependency-check/commands/shell.js.map +1 -0
  79. package/dist/hooks/runtime/dependency-check/commands/types.js +4 -0
  80. package/dist/hooks/runtime/dependency-check/commands/types.js.map +1 -0
  81. package/dist/hooks/runtime/dependency-check/commands.js +34 -0
  82. package/dist/hooks/runtime/dependency-check/commands.js.map +1 -0
  83. package/dist/hooks/runtime/dependency-check/deadlines.js +69 -0
  84. package/dist/hooks/runtime/dependency-check/deadlines.js.map +1 -0
  85. package/dist/hooks/runtime/dependency-check/dispatch.js +344 -0
  86. package/dist/hooks/runtime/dependency-check/dispatch.js.map +1 -0
  87. package/dist/hooks/runtime/dependency-check/entering.js +63 -0
  88. package/dist/hooks/runtime/dependency-check/entering.js.map +1 -0
  89. package/dist/hooks/runtime/dependency-check/exec-cache.js +36 -0
  90. package/dist/hooks/runtime/dependency-check/exec-cache.js.map +1 -0
  91. package/dist/hooks/runtime/dependency-check/git-blob.js +116 -0
  92. package/dist/hooks/runtime/dependency-check/git-blob.js.map +1 -0
  93. package/dist/hooks/runtime/dependency-check/hook.js +418 -0
  94. package/dist/hooks/runtime/dependency-check/hook.js.map +1 -0
  95. package/dist/hooks/runtime/dependency-check/local-store.js +74 -0
  96. package/dist/hooks/runtime/dependency-check/local-store.js.map +1 -0
  97. package/dist/hooks/runtime/dependency-check/lockfile-walk.js +89 -0
  98. package/dist/hooks/runtime/dependency-check/lockfile-walk.js.map +1 -0
  99. package/dist/hooks/runtime/dependency-check/lockfiles/bun.js +153 -0
  100. package/dist/hooks/runtime/dependency-check/lockfiles/bun.js.map +1 -0
  101. package/dist/hooks/runtime/dependency-check/lockfiles/by-name.js +46 -0
  102. package/dist/hooks/runtime/dependency-check/lockfiles/by-name.js.map +1 -0
  103. package/dist/hooks/runtime/dependency-check/lockfiles/cargo.js +91 -0
  104. package/dist/hooks/runtime/dependency-check/lockfiles/cargo.js.map +1 -0
  105. package/dist/hooks/runtime/dependency-check/lockfiles/composer.js +98 -0
  106. package/dist/hooks/runtime/dependency-check/lockfiles/composer.js.map +1 -0
  107. package/dist/hooks/runtime/dependency-check/lockfiles/gemfile.js +88 -0
  108. package/dist/hooks/runtime/dependency-check/lockfiles/gemfile.js.map +1 -0
  109. package/dist/hooks/runtime/dependency-check/lockfiles/go-mod.js +154 -0
  110. package/dist/hooks/runtime/dependency-check/lockfiles/go-mod.js.map +1 -0
  111. package/dist/hooks/runtime/dependency-check/lockfiles/gradle-lockfile.js +27 -0
  112. package/dist/hooks/runtime/dependency-check/lockfiles/gradle-lockfile.js.map +1 -0
  113. package/dist/hooks/runtime/dependency-check/lockfiles/graph.js +131 -0
  114. package/dist/hooks/runtime/dependency-check/lockfiles/graph.js.map +1 -0
  115. package/dist/hooks/runtime/dependency-check/lockfiles/npm.js +107 -0
  116. package/dist/hooks/runtime/dependency-check/lockfiles/npm.js.map +1 -0
  117. package/dist/hooks/runtime/dependency-check/lockfiles/nuget-packages-lock.js +60 -0
  118. package/dist/hooks/runtime/dependency-check/lockfiles/nuget-packages-lock.js.map +1 -0
  119. package/dist/hooks/runtime/dependency-check/lockfiles/pins.js +105 -0
  120. package/dist/hooks/runtime/dependency-check/lockfiles/pins.js.map +1 -0
  121. package/dist/hooks/runtime/dependency-check/lockfiles/pip-report.js +34 -0
  122. package/dist/hooks/runtime/dependency-check/lockfiles/pip-report.js.map +1 -0
  123. package/dist/hooks/runtime/dependency-check/lockfiles/pnpm.js +109 -0
  124. package/dist/hooks/runtime/dependency-check/lockfiles/pnpm.js.map +1 -0
  125. package/dist/hooks/runtime/dependency-check/lockfiles/poetry.js +105 -0
  126. package/dist/hooks/runtime/dependency-check/lockfiles/poetry.js.map +1 -0
  127. package/dist/hooks/runtime/dependency-check/lockfiles/uv.js +181 -0
  128. package/dist/hooks/runtime/dependency-check/lockfiles/uv.js.map +1 -0
  129. package/dist/hooks/runtime/dependency-check/lockfiles/yaml.js +319 -0
  130. package/dist/hooks/runtime/dependency-check/lockfiles/yaml.js.map +1 -0
  131. package/dist/hooks/runtime/dependency-check/lockfiles/yarn-berry.js +71 -0
  132. package/dist/hooks/runtime/dependency-check/lockfiles/yarn-berry.js.map +1 -0
  133. package/dist/hooks/runtime/dependency-check/lockfiles/yarn1.js +144 -0
  134. package/dist/hooks/runtime/dependency-check/lockfiles/yarn1.js.map +1 -0
  135. package/dist/hooks/runtime/dependency-check/manifests/apply.js +110 -0
  136. package/dist/hooks/runtime/dependency-check/manifests/apply.js.map +1 -0
  137. package/dist/hooks/runtime/dependency-check/manifests/diff.js +127 -0
  138. package/dist/hooks/runtime/dependency-check/manifests/diff.js.map +1 -0
  139. package/dist/hooks/runtime/dependency-check/manifests/edit.js +259 -0
  140. package/dist/hooks/runtime/dependency-check/manifests/edit.js.map +1 -0
  141. package/dist/hooks/runtime/dependency-check/manifests/json.js +109 -0
  142. package/dist/hooks/runtime/dependency-check/manifests/json.js.map +1 -0
  143. package/dist/hooks/runtime/dependency-check/manifests/kind.js +40 -0
  144. package/dist/hooks/runtime/dependency-check/manifests/kind.js.map +1 -0
  145. package/dist/hooks/runtime/dependency-check/manifests/patch.js +179 -0
  146. package/dist/hooks/runtime/dependency-check/manifests/patch.js.map +1 -0
  147. package/dist/hooks/runtime/dependency-check/manifests/text.js +665 -0
  148. package/dist/hooks/runtime/dependency-check/manifests/text.js.map +1 -0
  149. package/dist/hooks/runtime/dependency-check/manifests/toml.js +350 -0
  150. package/dist/hooks/runtime/dependency-check/manifests/toml.js.map +1 -0
  151. package/dist/hooks/runtime/dependency-check/manifests.js +14 -0
  152. package/dist/hooks/runtime/dependency-check/manifests.js.map +1 -0
  153. package/dist/hooks/runtime/dependency-check/messages.js +270 -0
  154. package/dist/hooks/runtime/dependency-check/messages.js.map +1 -0
  155. package/dist/hooks/runtime/dependency-check/net-baseline.js +157 -0
  156. package/dist/hooks/runtime/dependency-check/net-baseline.js.map +1 -0
  157. package/dist/hooks/runtime/dependency-check/net-state.js +70 -0
  158. package/dist/hooks/runtime/dependency-check/net-state.js.map +1 -0
  159. package/dist/hooks/runtime/dependency-check/pending-forces.js +54 -0
  160. package/dist/hooks/runtime/dependency-check/pending-forces.js.map +1 -0
  161. package/dist/hooks/runtime/dependency-check/post-tool-use.js +108 -0
  162. package/dist/hooks/runtime/dependency-check/post-tool-use.js.map +1 -0
  163. package/dist/hooks/runtime/dependency-check/ranges.js +369 -0
  164. package/dist/hooks/runtime/dependency-check/ranges.js.map +1 -0
  165. package/dist/hooks/runtime/dependency-check/requirement-files.js +144 -0
  166. package/dist/hooks/runtime/dependency-check/requirement-files.js.map +1 -0
  167. package/dist/hooks/runtime/dependency-check/resolvers/bun.js +38 -0
  168. package/dist/hooks/runtime/dependency-check/resolvers/bun.js.map +1 -0
  169. package/dist/hooks/runtime/dependency-check/resolvers/bundler.js +218 -0
  170. package/dist/hooks/runtime/dependency-check/resolvers/bundler.js.map +1 -0
  171. package/dist/hooks/runtime/dependency-check/resolvers/cargo.js +303 -0
  172. package/dist/hooks/runtime/dependency-check/resolvers/cargo.js.map +1 -0
  173. package/dist/hooks/runtime/dependency-check/resolvers/composer.js +250 -0
  174. package/dist/hooks/runtime/dependency-check/resolvers/composer.js.map +1 -0
  175. package/dist/hooks/runtime/dependency-check/resolvers/config-files.js +27 -0
  176. package/dist/hooks/runtime/dependency-check/resolvers/config-files.js.map +1 -0
  177. package/dist/hooks/runtime/dependency-check/resolvers/direct-only-registry.js +409 -0
  178. package/dist/hooks/runtime/dependency-check/resolvers/direct-only-registry.js.map +1 -0
  179. package/dist/hooks/runtime/dependency-check/resolvers/direct-only.js +290 -0
  180. package/dist/hooks/runtime/dependency-check/resolvers/direct-only.js.map +1 -0
  181. package/dist/hooks/runtime/dependency-check/resolvers/gem.js +89 -0
  182. package/dist/hooks/runtime/dependency-check/resolvers/gem.js.map +1 -0
  183. package/dist/hooks/runtime/dependency-check/resolvers/go.js +313 -0
  184. package/dist/hooks/runtime/dependency-check/resolvers/go.js.map +1 -0
  185. package/dist/hooks/runtime/dependency-check/resolvers/npm.js +81 -0
  186. package/dist/hooks/runtime/dependency-check/resolvers/npm.js.map +1 -0
  187. package/dist/hooks/runtime/dependency-check/resolvers/pip.js +229 -0
  188. package/dist/hooks/runtime/dependency-check/resolvers/pip.js.map +1 -0
  189. package/dist/hooks/runtime/dependency-check/resolvers/pipx.js +8 -0
  190. package/dist/hooks/runtime/dependency-check/resolvers/pipx.js.map +1 -0
  191. package/dist/hooks/runtime/dependency-check/resolvers/pnpm.js +68 -0
  192. package/dist/hooks/runtime/dependency-check/resolvers/pnpm.js.map +1 -0
  193. package/dist/hooks/runtime/dependency-check/resolvers/poetry.js +70 -0
  194. package/dist/hooks/runtime/dependency-check/resolvers/poetry.js.map +1 -0
  195. package/dist/hooks/runtime/dependency-check/resolvers/project.js +208 -0
  196. package/dist/hooks/runtime/dependency-check/resolvers/project.js.map +1 -0
  197. package/dist/hooks/runtime/dependency-check/resolvers/python-index.js +270 -0
  198. package/dist/hooks/runtime/dependency-check/resolvers/python-index.js.map +1 -0
  199. package/dist/hooks/runtime/dependency-check/resolvers/python.js +229 -0
  200. package/dist/hooks/runtime/dependency-check/resolvers/python.js.map +1 -0
  201. package/dist/hooks/runtime/dependency-check/resolvers/registry.js +221 -0
  202. package/dist/hooks/runtime/dependency-check/resolvers/registry.js.map +1 -0
  203. package/dist/hooks/runtime/dependency-check/resolvers/shared.js +440 -0
  204. package/dist/hooks/runtime/dependency-check/resolvers/shared.js.map +1 -0
  205. package/dist/hooks/runtime/dependency-check/resolvers/tree.js +131 -0
  206. package/dist/hooks/runtime/dependency-check/resolvers/tree.js.map +1 -0
  207. package/dist/hooks/runtime/dependency-check/resolvers/uv.js +433 -0
  208. package/dist/hooks/runtime/dependency-check/resolvers/uv.js.map +1 -0
  209. package/dist/hooks/runtime/dependency-check/resolvers/xml-lite.js +132 -0
  210. package/dist/hooks/runtime/dependency-check/resolvers/xml-lite.js.map +1 -0
  211. package/dist/hooks/runtime/dependency-check/resolvers/yarn-berry.js +106 -0
  212. package/dist/hooks/runtime/dependency-check/resolvers/yarn-berry.js.map +1 -0
  213. package/dist/hooks/runtime/dependency-check/sandbox.js +328 -0
  214. package/dist/hooks/runtime/dependency-check/sandbox.js.map +1 -0
  215. package/dist/hooks/runtime/dependency-check/specs.js +171 -0
  216. package/dist/hooks/runtime/dependency-check/specs.js.map +1 -0
  217. package/dist/hooks/runtime/dependency-check/static-view.js +90 -0
  218. package/dist/hooks/runtime/dependency-check/static-view.js.map +1 -0
  219. package/dist/hooks/runtime/dependency-check/stop-net.js +278 -0
  220. package/dist/hooks/runtime/dependency-check/stop-net.js.map +1 -0
  221. package/dist/hooks/runtime/dependency-check/stop-wiring.js +94 -0
  222. package/dist/hooks/runtime/dependency-check/stop-wiring.js.map +1 -0
  223. package/dist/hooks/runtime/dependency-check/tool-call.js +130 -0
  224. package/dist/hooks/runtime/dependency-check/tool-call.js.map +1 -0
  225. package/dist/hooks/runtime/dependency-check/types.js +96 -0
  226. package/dist/hooks/runtime/dependency-check/types.js.map +1 -0
  227. package/dist/hooks/runtime/emit.js +240 -52
  228. package/dist/hooks/runtime/emit.js.map +1 -1
  229. package/dist/hooks/runtime/exit-deadlock-guard.js +24 -8
  230. package/dist/hooks/runtime/exit-deadlock-guard.js.map +1 -1
  231. package/dist/hooks/runtime/fetch-rules.js +78 -29
  232. package/dist/hooks/runtime/fetch-rules.js.map +1 -1
  233. package/dist/hooks/runtime/grep-include.js +228 -0
  234. package/dist/hooks/runtime/grep-include.js.map +1 -0
  235. package/dist/hooks/runtime/pre-compact.js +1 -1
  236. package/dist/hooks/runtime/pre-compact.js.map +1 -1
  237. package/dist/hooks/runtime/pre-invocation.js +3 -3
  238. package/dist/hooks/runtime/pre-invocation.js.map +1 -1
  239. package/dist/hooks/runtime/repo-registry.js +72 -0
  240. package/dist/hooks/runtime/repo-registry.js.map +1 -0
  241. package/dist/hooks/runtime/repo-scope.js +75 -0
  242. package/dist/hooks/runtime/repo-scope.js.map +1 -0
  243. package/dist/hooks/runtime/resolve.js +11 -2
  244. package/dist/hooks/runtime/resolve.js.map +1 -1
  245. package/dist/hooks/runtime/runner-args.js +17 -2
  246. package/dist/hooks/runtime/runner-args.js.map +1 -1
  247. package/dist/hooks/runtime/script-resolve.js +21 -5
  248. package/dist/hooks/runtime/script-resolve.js.map +1 -1
  249. package/dist/hooks/runtime/session-activation.js +71 -18
  250. package/dist/hooks/runtime/session-activation.js.map +1 -1
  251. package/dist/hooks/runtime/session-review.js +136 -66
  252. package/dist/hooks/runtime/session-review.js.map +1 -1
  253. package/dist/hooks/runtime/session-start.js +68 -13
  254. package/dist/hooks/runtime/session-start.js.map +1 -1
  255. package/dist/hooks/runtime/session-writes.js +11 -5
  256. package/dist/hooks/runtime/session-writes.js.map +1 -1
  257. package/dist/hooks/runtime/shell-writes.js +7 -88
  258. package/dist/hooks/runtime/shell-writes.js.map +1 -1
  259. package/dist/hooks/runtime/sniff.js +227 -2
  260. package/dist/hooks/runtime/sniff.js.map +1 -1
  261. package/dist/hooks/runtime/target-resolve.js +32 -17
  262. package/dist/hooks/runtime/target-resolve.js.map +1 -1
  263. package/dist/hooks/runtime/unmapped-tools.js +77 -1
  264. package/dist/hooks/runtime/unmapped-tools.js.map +1 -1
  265. package/dist/hooks/runtime/user-prompt-submit.js +1 -1
  266. package/dist/hooks/runtime/user-prompt-submit.js.map +1 -1
  267. package/dist/hooks/runtime/work-dir.js +3 -0
  268. package/dist/hooks/runtime/work-dir.js.map +1 -1
  269. package/dist/hooks/shim.js +27 -20
  270. package/dist/hooks/shim.js.map +1 -1
  271. package/dist/index.js +40 -3
  272. package/dist/index.js.map +1 -1
  273. package/dist/install-scope.js +12 -0
  274. package/dist/install-scope.js.map +1 -0
  275. package/dist/install.js +188 -78
  276. package/dist/install.js.map +1 -1
  277. package/dist/link.js +55 -5
  278. package/dist/link.js.map +1 -1
  279. package/dist/mcp/config/hook.js +25 -0
  280. package/dist/mcp/config/hook.js.map +1 -1
  281. package/dist/org.js +3 -1
  282. package/dist/org.js.map +1 -1
  283. package/dist/prompts.js +96 -12
  284. package/dist/prompts.js.map +1 -1
  285. package/dist/refresh-hooks.js +67 -15
  286. package/dist/refresh-hooks.js.map +1 -1
  287. package/dist/repo/exclude-block.js +112 -0
  288. package/dist/repo/exclude-block.js.map +1 -0
  289. package/dist/repo/footer.js +93 -0
  290. package/dist/repo/footer.js.map +1 -0
  291. package/dist/repo/git-repo.js +77 -0
  292. package/dist/repo/git-repo.js.map +1 -0
  293. package/dist/repo/guarded-write.js +45 -0
  294. package/dist/repo/guarded-write.js.map +1 -0
  295. package/dist/repo/install-repo.js +508 -0
  296. package/dist/repo/install-repo.js.map +1 -0
  297. package/dist/repo/machine-wiring.js +122 -0
  298. package/dist/repo/machine-wiring.js.map +1 -0
  299. package/dist/repo/mcp-json.js +57 -0
  300. package/dist/repo/mcp-json.js.map +1 -0
  301. package/dist/repo/registry.js +53 -0
  302. package/dist/repo/registry.js.map +1 -0
  303. package/dist/repo/repo-mode-guard.js +83 -0
  304. package/dist/repo/repo-mode-guard.js.map +1 -0
  305. package/dist/repo/repo-setups.js +123 -0
  306. package/dist/repo/repo-setups.js.map +1 -0
  307. package/dist/repo/repo-status.js +283 -0
  308. package/dist/repo/repo-status.js.map +1 -0
  309. package/dist/repo/uninstall-repo.js +56 -0
  310. package/dist/repo/uninstall-repo.js.map +1 -0
  311. package/dist/repo/unsupported.js +14 -0
  312. package/dist/repo/unsupported.js.map +1 -0
  313. package/dist/shim.js +9 -7
  314. package/dist/status.js +53 -11
  315. package/dist/status.js.map +1 -1
  316. package/dist/uninstall.js +51 -3
  317. package/dist/uninstall.js.map +1 -1
  318. package/dist/update.js +6 -1
  319. package/dist/update.js.map +1 -1
  320. package/package.json +5 -2
@@ -0,0 +1,221 @@
1
+ /**
2
+ * Which registry a package resolves from, read from the configuration files
3
+ * and variables the manager itself reads (never from the network). A package
4
+ * is public only when every setting that could apply to it names the public
5
+ * npm registry: a private registry anywhere, or a value that cannot be read
6
+ * (`${TOKEN_URL}`), makes it not public, so its name never reaches a third
7
+ * party (spec, "What leaves the machine").
8
+ */
9
+ import { readFileSync, statSync } from 'node:fs';
10
+ import { dirname, join } from 'node:path';
11
+ import { asObject, isPublicNpmUrl } from '../lockfiles/graph.js';
12
+ import { parseLockYaml } from '../lockfiles/yaml.js';
13
+ import { UNREADABLE, readSetting } from './config-files.js';
14
+ export const NOTHING_PUBLIC = { isPublic: () => false };
15
+ const MAX_CONFIG_BYTES = 1024 * 1024;
16
+ /** A small configuration file's text; null when absent or unreadable. */
17
+ export function readConfig(path) {
18
+ if (path === null)
19
+ return null;
20
+ try {
21
+ const st = statSync(path);
22
+ if (!st.isFile() || st.size > MAX_CONFIG_BYTES)
23
+ return null;
24
+ return readFileSync(path, 'utf8');
25
+ }
26
+ catch {
27
+ return null;
28
+ }
29
+ }
30
+ /** A variable by name, whatever its case (npm reads `npm_config_*` either way). */
31
+ export function envValue(env, name) {
32
+ const lower = name.toLowerCase();
33
+ const key = Object.keys(env).find((k) => k.toLowerCase() === lower);
34
+ return key === undefined ? undefined : env[key];
35
+ }
36
+ class Collected {
37
+ defaults = [];
38
+ scopes = new Map();
39
+ unreadable = false;
40
+ addDefault(url) {
41
+ this.defaults.push(url);
42
+ }
43
+ addScope(scope, url) {
44
+ const s = scope.toLowerCase();
45
+ this.scopes.set(s, [...(this.scopes.get(s) ?? []), url]);
46
+ }
47
+ markUnreadable() {
48
+ this.unreadable = true;
49
+ }
50
+ isPublic(name) {
51
+ if (this.unreadable || !this.defaults.every(isPublicNpmUrl))
52
+ return false;
53
+ if (!name.startsWith('@'))
54
+ return true;
55
+ const scope = name.slice(0, name.indexOf('/')).toLowerCase();
56
+ return (this.scopes.get(scope) ?? []).every(isPublicNpmUrl);
57
+ }
58
+ }
59
+ const unquote = (v) => {
60
+ const t = v.trim();
61
+ return (t.startsWith('"') && t.endsWith('"')) || (t.startsWith("'") && t.endsWith("'")) ? t.slice(1, -1) : t;
62
+ };
63
+ /** `registry=` and `@scope:registry=` lines of an `.npmrc` (ini). */
64
+ function addNpmrc(c, text) {
65
+ for (const raw of text.split(/\r?\n/)) {
66
+ const line = raw.trim();
67
+ if (line === '' || line.startsWith(';') || line.startsWith('#') || line.startsWith('['))
68
+ continue;
69
+ const eq = line.indexOf('=');
70
+ if (eq < 0)
71
+ continue;
72
+ const key = line.slice(0, eq).trim().toLowerCase();
73
+ const value = unquote(line.slice(eq + 1));
74
+ if (key === 'registry')
75
+ c.addDefault(value);
76
+ else if (/^@[^:]+:registry$/.test(key))
77
+ c.addScope(key.slice(0, key.indexOf(':')), value);
78
+ }
79
+ }
80
+ function npmGlobalConfig(ctx) {
81
+ const named = envValue(ctx.env, 'npm_config_globalconfig');
82
+ if (named)
83
+ return named;
84
+ const prefix = envValue(ctx.env, 'npm_config_prefix') ?? ((ctx.platform ?? process.platform) === 'win32' ? dirname(ctx.execPath) : dirname(dirname(ctx.execPath)));
85
+ return join(prefix, 'etc', 'npmrc');
86
+ }
87
+ /** npm's view: the project's `.npmrc`, the user's, the global one, and `npm_config_*registry` variables. */
88
+ export function npmrcView(ctx) {
89
+ const c = new Collected();
90
+ const files = [
91
+ ctx.dir === null ? null : join(ctx.dir, '.npmrc'),
92
+ envValue(ctx.env, 'npm_config_userconfig') ?? join(ctx.home, '.npmrc'),
93
+ npmGlobalConfig(ctx),
94
+ ];
95
+ for (const f of files) {
96
+ const text = readConfig(f);
97
+ if (text !== null)
98
+ addNpmrc(c, text);
99
+ }
100
+ for (const k of Object.keys(ctx.env)) {
101
+ const key = k.toLowerCase();
102
+ const v = ctx.env[k];
103
+ if (v === undefined || v === '')
104
+ continue;
105
+ if (key === 'npm_config_registry')
106
+ c.addDefault(v);
107
+ else if (/^npm_config_@[^:]+:registry$/.test(key))
108
+ c.addScope(key.slice('npm_config_'.length, key.indexOf(':')), v);
109
+ }
110
+ return c;
111
+ }
112
+ /** A directory and its parents, up to the filesystem root. */
113
+ export function upFrom(dir) {
114
+ const out = [dir];
115
+ for (let d = dir, i = 0; i < 64; i++) {
116
+ const up = dirname(d);
117
+ if (up === d)
118
+ break;
119
+ out.push(up);
120
+ d = up;
121
+ }
122
+ return out;
123
+ }
124
+ /**
125
+ * yarn 2+'s view: every `.yarnrc.yml` yarn reads (the project's, its
126
+ * parents', the user's) and `YARN_NPM_REGISTRY_SERVER`. The sandbox gets the
127
+ * project's file only, so a registry set above the project is seen here,
128
+ * which keeps `publicRegistry` false for it.
129
+ */
130
+ export function yarnrcView(ctx) {
131
+ const c = new Collected();
132
+ const dirs = [...(ctx.dir === null ? [] : upFrom(ctx.dir)), ctx.home];
133
+ for (const f of [...new Set(dirs)].map((d) => join(d, '.yarnrc.yml'))) {
134
+ const text = readConfig(f);
135
+ if (text === null)
136
+ continue;
137
+ let rc;
138
+ try {
139
+ rc = asObject(parseLockYaml(text));
140
+ }
141
+ catch {
142
+ rc = null;
143
+ }
144
+ if (rc === null) {
145
+ c.markUnreadable();
146
+ continue;
147
+ }
148
+ if (typeof rc.npmRegistryServer === 'string')
149
+ c.addDefault(rc.npmRegistryServer);
150
+ const scopes = asObject(rc.npmScopes) ?? {};
151
+ for (const scope of Object.keys(scopes)) {
152
+ const server = asObject(scopes[scope])?.npmRegistryServer;
153
+ if (typeof server === 'string')
154
+ c.addScope(`@${scope.replace(/^@/, '')}`, server);
155
+ }
156
+ }
157
+ const env = envValue(ctx.env, 'YARN_NPM_REGISTRY_SERVER');
158
+ if (env)
159
+ c.addDefault(env);
160
+ return c;
161
+ }
162
+ /**
163
+ * yarn 1's view: npm's (yarn 1 reads `.npmrc` too), plus every `.yarnrc` it
164
+ * reads (the project's, its parents', the user's: `registry "https://..."` and
165
+ * `"@scope:registry" "https://..."` lines) and `YARN_REGISTRY`. A `.yarnrc`
166
+ * that cannot be read makes nothing public.
167
+ */
168
+ export function yarn1View(ctx) {
169
+ const c = npmrcView(ctx);
170
+ const dirs = [...(ctx.dir === null ? [] : upFrom(ctx.dir)), ctx.home];
171
+ for (const f of [...new Set(dirs)].map((d) => join(d, '.yarnrc'))) {
172
+ const setting = readSetting(f);
173
+ if (setting === null)
174
+ continue;
175
+ if (setting === UNREADABLE) {
176
+ c.markUnreadable();
177
+ continue;
178
+ }
179
+ for (const raw of setting.split(/\r?\n/)) {
180
+ const line = raw.trim();
181
+ if (line === '' || line.startsWith('#'))
182
+ continue;
183
+ const m = /^"?([^"\s]+)"?\s+"?([^"\s]+)"?$/.exec(line);
184
+ if (m === null)
185
+ continue;
186
+ if (m[1] === 'registry')
187
+ c.addDefault(m[2]);
188
+ else if (/^@[^:]+:registry$/.test(m[1]))
189
+ c.addScope(m[1].slice(0, m[1].indexOf(':')), m[2]);
190
+ }
191
+ }
192
+ const env = envValue(ctx.env, 'YARN_REGISTRY');
193
+ if (env)
194
+ c.addDefault(env);
195
+ return c;
196
+ }
197
+ /**
198
+ * Bun's view: npm's, plus `bunfig.toml` (the project's and the user's) and
199
+ * `BUN_CONFIG_REGISTRY`. bunfig is TOML; any URL it holds that is not the
200
+ * public registry makes every package not public (scopes included).
201
+ */
202
+ export function bunView(ctx) {
203
+ const c = npmrcView(ctx);
204
+ const xdg = envValue(ctx.env, 'XDG_CONFIG_HOME');
205
+ const files = [ctx.dir === null ? null : join(ctx.dir, 'bunfig.toml'), join(ctx.home, '.bunfig.toml'), xdg ? join(xdg, '.bunfig.toml') : null];
206
+ for (const f of files) {
207
+ const text = readConfig(f);
208
+ if (text === null)
209
+ continue;
210
+ for (const line of text.split(/\r?\n/)) {
211
+ const code = line.trimStart().startsWith('#') ? '' : line;
212
+ for (const m of code.match(/https?:\/\/[^\s"',}]+/g) ?? [])
213
+ c.addDefault(m);
214
+ }
215
+ }
216
+ const env = envValue(ctx.env, 'BUN_CONFIG_REGISTRY');
217
+ if (env)
218
+ c.addDefault(env);
219
+ return c;
220
+ }
221
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../../../../src/hooks/runtime/dependency-check/resolvers/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAM5D,MAAM,CAAC,MAAM,cAAc,GAAiB,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,KAAK,EAAE,CAAC;AAYtE,MAAM,gBAAgB,GAAG,IAAI,GAAG,IAAI,CAAC;AAErC,yEAAyE;AACzE,MAAM,UAAU,UAAU,CAAC,IAAmB;IAC5C,IAAI,IAAI,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAC/B,IAAI,CAAC;QACH,MAAM,EAAE,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC1B,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,IAAI,GAAG,gBAAgB;YAAE,OAAO,IAAI,CAAC;QAC5D,OAAO,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACpC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,QAAQ,CAAC,GAAsB,EAAE,IAAY;IAC3D,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IACjC,MAAM,GAAG,GAAG,MAAM,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AAK,IAAI;YAAE,SAAS;QAC5B,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;YACvC,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;YAC1D,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,wBAAwB,CAAC,IAAI,EAAE;gBAAE,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAC9E,CAAC;IACH,CAAC;IACD,MAAM,GAAG,GAAG,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,qBAAqB,CAAC,CAAC;IACrD,IAAI,GAAG;QAAE,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAC3B,OAAO,CAAC,CAAC;AACX,CAAC"}
@@ -0,0 +1,440 @@
1
+ /**
2
+ * The resolution every JavaScript manager shares, in named steps: locate the
3
+ * project, copy the files the manager reads into a sandbox, read the old
4
+ * graph, write what the command changes, ask the version of the manager that
5
+ * will run (where it will run, with those files), run it in lockfile-only
6
+ * mode with install scripts off, and compare the lockfile before and after.
7
+ *
8
+ * A step that cannot go on throws `Fallback` with its reason. The answer is
9
+ * then a `direct_only` resolution: the specs whose version is exact are sent
10
+ * as direct packages, the others are not verified, and `incomplete` says why
11
+ * the tree was not resolved. Nothing here throws, logs, or writes outside the
12
+ * sandbox.
13
+ */
14
+ import { mkdir, readFile, writeFile } from 'node:fs/promises';
15
+ import { homedir } from 'node:os';
16
+ import { dirname, join, relative } from 'node:path';
17
+ import { allDirect, enteringNotVerified, enteringPackages } from '../entering.js';
18
+ import { asObject, emptyGraph, isExactVersion, stringEntries } from '../lockfiles/graph.js';
19
+ import { ARCHIVE_RE, REMOTE_RE } from '../specs.js';
20
+ import { DeadlineError, KILL_GRACE_MS, defaultSandboxBase, prepareSandbox, runManager, safeRelative, } from '../sandbox.js';
21
+ import { isFile, locateProject } from './project.js';
22
+ import { NOTHING_PUBLIC, readConfig } from './registry.js';
23
+ /** Kept back from a run's deadline: the kill grace, then the sandbox's removal. */
24
+ export const RUN_MARGIN_MS = KILL_GRACE_MS + 250;
25
+ /**
26
+ * How fast a lockfile is read, conservatively: the YAML reader took 11 ms for
27
+ * a 400 KB `pnpm-lock.yaml` (about 36,000 characters a millisecond).
28
+ */
29
+ const READ_CHARS_PER_MS = 10_000;
30
+ export function resolverDeps(over = {}) {
31
+ const home = over.home ?? homedir();
32
+ return {
33
+ run: runManager,
34
+ env: process.env,
35
+ execPath: process.execPath,
36
+ now: Date.now,
37
+ ...over,
38
+ home,
39
+ sandboxBase: over.sandboxBase ?? defaultSandboxBase(home),
40
+ };
41
+ }
42
+ /** The reasons a run failed: a spec without an exact version is not verified for that reason. */
43
+ const RUN_FAILURES = new Set(['resolution_timeout', 'resolution_failed', 'manager_missing']);
44
+ /** Thrown by a step: the resolution stops there and falls back to the direct packages. */
45
+ export class Fallback extends Error {
46
+ why;
47
+ constructor(why) {
48
+ super(why);
49
+ this.why = why;
50
+ }
51
+ }
52
+ export const stop = (why) => {
53
+ throw new Fallback(why);
54
+ };
55
+ /** Why a resolution that threw stops: a step's own reason, the deadline, or a failure. */
56
+ export function fallbackReason(e) {
57
+ return e instanceof Fallback ? e.why : e instanceof DeadlineError ? 'resolution_timeout' : 'resolution_failed';
58
+ }
59
+ const SCRIPTS_OFF = {
60
+ npm_config_ignore_scripts: 'true',
61
+ YARN_ENABLE_SCRIPTS: 'false',
62
+ npm_config_update_notifier: 'false',
63
+ // npm runs the program its `git` setting names for a git dependency, and a
64
+ // project's `.npmrc` can set it (`git=${PWD}/x.sh`; measured on npm 10.9.4,
65
+ // on an edit). A variable wins over every `.npmrc`. Of the settings that
66
+ // name a program (`shell`, `script-shell`, `editor`, `browser`, `viewer`,
67
+ // `node-gyp`, `init-module`, `onload-script`, `node-options`, and pnpm's
68
+ // `npm-path` and pnpmfiles), only this one ran during a lockfile-only
69
+ // resolution, on npm 10.9.4 and pnpm 10.15.0; yarn 2+ reads no `.npmrc`,
70
+ // and its own (`yarnPath`, `plugins`) are refused in `yarn-berry.ts`.
71
+ npm_config_git: 'git',
72
+ // corepack walks up past the sandbox to the nearest manifest and, with
73
+ // auto-pin on (the default up to corepack 0.32), writes `packageManager`
74
+ // into it: a file outside the sandbox. Forced off, never just dropped.
75
+ COREPACK_ENABLE_AUTO_PIN: '0',
76
+ };
77
+ /** Never passed on: corepack would download and run a manager from a URL a manifest names. */
78
+ const DROPPED = ['COREPACK_ENABLE_UNSAFE_CUSTOM_URLS'];
79
+ /**
80
+ * Dropped on an edit, which runs nothing the developer asked for: Node loads
81
+ * what `NODE_OPTIONS` names (`--require`, `--import`) into every manager. A
82
+ * command keeps it, since the real command runs with it.
83
+ */
84
+ export const DROPPED_ON_EDIT = ['NODE_OPTIONS'];
85
+ /**
86
+ * The developer's environment with ours on top; a same-named variable of any
87
+ * case is replaced, and the dropped ones (ours, and `drop`) are removed
88
+ * whatever their value.
89
+ */
90
+ export function managerEnv(base, extra, drop = []) {
91
+ const forced = { ...SCRIPTS_OFF, ...extra };
92
+ const names = new Set([...Object.keys(forced), ...DROPPED, ...drop].map((k) => k.toUpperCase()));
93
+ const out = {};
94
+ for (const [k, v] of Object.entries(base))
95
+ if (v !== undefined && !names.has(k.toUpperCase()))
96
+ out[k] = v;
97
+ return { ...out, ...forced };
98
+ }
99
+ const GITHUB_SHORTHAND_RE = /^[\w.-]+\/[\w.-]+(#.*)?$/;
100
+ /** What the trigger itself could not read: E2's unparsed words, E3's not-verified entries. */
101
+ export function told(input) {
102
+ const t = input.trigger;
103
+ if (t.kind === 'edit')
104
+ return t.changes.notVerified;
105
+ return t.unparsed.map((word) => ({
106
+ name: word,
107
+ reason: REMOTE_RE.test(word) || ARCHIVE_RE.test(word) || GITHUB_SHORTHAND_RE.test(word) ? 'git_or_url' : 'resolution_failed',
108
+ }));
109
+ }
110
+ export function dedupe(list) {
111
+ const seen = new Set();
112
+ return list.filter((n) => {
113
+ const k = `${n.name}\0${n.reason}`;
114
+ if (seen.has(k))
115
+ return false;
116
+ seen.add(k);
117
+ return true;
118
+ });
119
+ }
120
+ /** The exact version an npm spec names, else null. */
121
+ const npmExactVersion = (s) => (isExactVersion(s.range) ? s.range : null);
122
+ /**
123
+ * The direct packages only, `incomplete` saying why. A spec with an exact
124
+ * version (`exact`: the ecosystem's reading, npm's by default) is sent; any
125
+ * other is not verified, for the run's failure when it failed, else as
126
+ * `version_range` (the version that would be installed is unknown).
127
+ */
128
+ export function directOnly(specs, why, view, before = [], exact = npmExactVersion) {
129
+ const packages = [];
130
+ const notVerified = [...before];
131
+ const sent = new Set();
132
+ for (const s of specs) {
133
+ const version = exact(s);
134
+ if (version !== null) {
135
+ if (sent.has(`${s.name}@${version}`))
136
+ continue;
137
+ sent.add(`${s.name}@${version}`);
138
+ packages.push({ ecosystem: s.ecosystem, name: s.name, version, direct: true, publicRegistry: s.registry !== 'custom' && view.isPublic(s.name) });
139
+ }
140
+ else
141
+ notVerified.push({ name: s.name, reason: RUN_FAILURES.has(why) ? why : 'version_range' });
142
+ }
143
+ return { packages, notVerified: dedupe(notVerified), mode: 'direct_only', incomplete: why };
144
+ }
145
+ const specArg = (s) => (s.range ? `${s.name}@${s.range}` : s.name);
146
+ const NPM_SECTIONS = ['dependencies', 'devDependencies', 'optionalDependencies', 'peerDependencies'];
147
+ /** Whether every manifest declares no dependency (so the old graph is empty). */
148
+ async function declaresNothing(box, manifests) {
149
+ for (const m of manifests) {
150
+ const text = await readFile(join(box, m), 'utf8').catch(() => null);
151
+ if (text === null)
152
+ continue;
153
+ const doc = JSON.parse(text);
154
+ if (NPM_SECTIONS.some((s) => stringEntries(doc[s]).length > 0))
155
+ return false;
156
+ }
157
+ return true;
158
+ }
159
+ /** The specs written into a manifest, as the add command would (an existing entry keeps its section). */
160
+ async function writeSpecs(file, specs, m) {
161
+ const doc = asObject(JSON.parse(await readFile(file, 'utf8')));
162
+ if (doc === null)
163
+ throw new Error('not a manifest');
164
+ const own = (o, key) => asObject(o) !== null && Object.prototype.hasOwnProperty.call(o, key);
165
+ for (const s of specs) {
166
+ const section = NPM_SECTIONS.find((k) => own(doc[k], s.name)) ?? 'dependencies';
167
+ const table = asObject(doc[section]) ?? {};
168
+ if (s.range === undefined && m.keepDeclaredRange && typeof table[s.name] === 'string' && own(table, s.name))
169
+ continue;
170
+ // Own data property, whatever the name (`constructor`, `__proto__`).
171
+ Object.defineProperty(table, s.name, { value: s.range ?? m.bareRange ?? 'latest', enumerable: true, writable: true, configurable: true });
172
+ doc[section] = table;
173
+ }
174
+ await writeFile(file, `${JSON.stringify(doc, null, 2)}\n`);
175
+ }
176
+ /** The manifest a command in `startRel` changes: the nearest one up. */
177
+ function targetManifest(project) {
178
+ const parts = project.startRel.split('/').filter(Boolean);
179
+ for (let n = parts.length; n > 0; n--) {
180
+ const m = `${parts.slice(0, n).join('/')}/package.json`;
181
+ if (project.manifests.includes(m))
182
+ return m;
183
+ }
184
+ return 'package.json';
185
+ }
186
+ function generatedManifest(m, configDir) {
187
+ const doc = { name: 'vd-depcheck', version: '0.0.0', private: true };
188
+ if (m.packageManagerPrefix && configDir !== null) {
189
+ try {
190
+ const pm = JSON.parse(readConfig(join(configDir, 'package.json')) ?? '{}').packageManager;
191
+ if (typeof pm === 'string' && pm.startsWith(m.packageManagerPrefix))
192
+ doc.packageManager = pm;
193
+ }
194
+ catch {
195
+ /* no usable packageManager: the manager's default runs */
196
+ }
197
+ }
198
+ return `${JSON.stringify(doc, null, 2)}\n`;
199
+ }
200
+ function versionOf(stdout) {
201
+ const m = /\d+\.\d+\.\d+/.exec(stdout);
202
+ return m ? m[0] : null;
203
+ }
204
+ /**
205
+ * Which manager a manifest makes corepack run: `packageManager` and
206
+ * `devEngines.packageManager`, compared as written. Throws on a manifest that
207
+ * is not JSON.
208
+ */
209
+ function managerDeclared(text) {
210
+ const doc = text === null ? null : asObject(JSON.parse(text));
211
+ return JSON.stringify([doc?.packageManager ?? null, asObject(doc?.devEngines)?.packageManager ?? null]);
212
+ }
213
+ const timeLeft = (job) => job.deadlineAt - job.deps.now() - RUN_MARGIN_MS;
214
+ function jobOf(m, input, deps) {
215
+ const t = input.trigger;
216
+ const notes = told(input);
217
+ const specs = [];
218
+ for (const s of (t.kind === 'edit' ? t.changes.specs : t.specs).filter((x) => x.ecosystem === 'npm')) {
219
+ // A name starting with a dash would be read as an option (`--prefix=..`).
220
+ if (s.name.startsWith('-'))
221
+ notes.push({ name: s.name, reason: 'resolution_failed' });
222
+ else
223
+ specs.push(s);
224
+ }
225
+ return {
226
+ m,
227
+ input,
228
+ deps,
229
+ deadlineAt: deps.now() + Math.max(0, input.deadlineMs),
230
+ specs,
231
+ notes: dedupe(notes),
232
+ edit: input.onEdit || t.kind === 'edit',
233
+ isolated: t.kind !== 'edit' && (t.kind === 'exec' || t.global),
234
+ start: t.kind === 'edit' ? dirname(t.path) : input.root,
235
+ };
236
+ }
237
+ /** Step 1: the project, and the registry configuration that applies to it. */
238
+ function locate(job) {
239
+ const t = job.input.trigger;
240
+ const project = t.kind !== 'edit' && t.global
241
+ ? null
242
+ : locateProject(job.start, {
243
+ lockfiles: job.m.lockfiles,
244
+ workspaces: job.m.workspaces,
245
+ home: job.deps.home,
246
+ deadlineAt: job.deadlineAt,
247
+ now: job.deps.now,
248
+ manifestAt: t.kind === 'edit' ? job.start : undefined,
249
+ });
250
+ const configDir = project?.dir ?? null;
251
+ return {
252
+ own: job.isolated ? null : project,
253
+ configDir,
254
+ view: job.m.registry({ dir: configDir, env: job.deps.env, home: job.deps.home, execPath: job.deps.execPath }),
255
+ };
256
+ }
257
+ /** Step 1b: whether the manager may run on this project at all. */
258
+ function checkMayRun(job, place) {
259
+ if (job.m.refuses?.(place.configDir, job.edit))
260
+ stop('project_code');
261
+ if (place.own?.tooMany)
262
+ stop('workspace_too_large');
263
+ if (place.own?.lockfile && (job.m.unreadable ?? []).includes(place.own.lockfile))
264
+ stop('resolution_failed');
265
+ }
266
+ /** Step 2: the sandbox, with the files the manager reads and nothing else. */
267
+ async function copy(job, place) {
268
+ const { m } = job;
269
+ const { own, configDir } = place;
270
+ const files = own
271
+ ? [...own.manifests, ...(own.lockfile ? [own.lockfile] : []), ...m.configFiles]
272
+ : configDir === null
273
+ ? []
274
+ : [...m.execConfigFiles];
275
+ const sandbox = await prepareSandbox(configDir ?? job.start, files, {
276
+ base: job.deps.sandboxBase,
277
+ home: job.deps.home,
278
+ // Only a located project is the root to keep the sandboxes out of; an
279
+ // exec, a global install or a command outside any project copies nothing
280
+ // of the directory it runs in, `~` included.
281
+ rootIsProject: own !== null,
282
+ deadlineAt: job.deadlineAt - RUN_MARGIN_MS,
283
+ now: job.deps.now,
284
+ });
285
+ try {
286
+ if (!own)
287
+ await writeFile(join(sandbox.dir, 'package.json'), generatedManifest(m, configDir));
288
+ const lockName = own?.lockfile ?? m.writes;
289
+ if (m.seedLockfile && !isFile(join(sandbox.dir, lockName)))
290
+ await writeFile(join(sandbox.dir, lockName), '');
291
+ const env = managerEnv(job.deps.env, await m.prepare(sandbox.dir), job.edit ? DROPPED_ON_EDIT : []);
292
+ return { sandbox, lockName, env };
293
+ }
294
+ catch (e) {
295
+ await sandbox.dispose();
296
+ throw e;
297
+ }
298
+ }
299
+ /**
300
+ * Step 3: the old graph. The project's lockfile; empty when the project
301
+ * declares nothing yet (a fresh `npm init`); none for an exec or global
302
+ * command. Also the time kept back to read the new lockfile after the run.
303
+ */
304
+ async function oldGraph(job, place, box) {
305
+ const { own } = place;
306
+ if (!own)
307
+ return { before: job.isolated ? null : emptyGraph(), reserveMs: 0 };
308
+ if (!own.lockfile) {
309
+ if (await declaresNothing(box.sandbox.dir, own.manifests))
310
+ return { before: emptyGraph(), reserveMs: 0 };
311
+ return stop('resolution_failed');
312
+ }
313
+ const text = await readFile(join(box.sandbox.dir, own.lockfile), 'utf8').catch(() => null);
314
+ const before = text === null ? null : job.m.read(text);
315
+ if (text === null || before === null)
316
+ return stop('resolution_failed');
317
+ return { before, reserveMs: Math.ceil(text.length / READ_CHARS_PER_MS) };
318
+ }
319
+ /**
320
+ * Step 4: the command, and what it needs written first (the edited file, or
321
+ * the specs). An edit that changes which manager corepack would run
322
+ * (`packageManager`, `devEngines.packageManager`: added, removed or another)
323
+ * runs nothing: the agent is choosing the manager, and it is not run for it.
324
+ */
325
+ async function command(job, place, box) {
326
+ const t = job.input.trigger;
327
+ const dir = box.sandbox.dir;
328
+ const { own } = place;
329
+ if (t.kind === 'edit') {
330
+ const rel = own === null ? null : safeRelative(relative(own.dir, t.path));
331
+ if (rel === null)
332
+ return stop('resolution_failed');
333
+ const was = await readFile(join(dir, rel), 'utf8').catch(() => null);
334
+ if (managerDeclared(was) !== managerDeclared(t.content))
335
+ return stop('project_code');
336
+ await mkdir(dirname(join(dir, rel)), { recursive: true });
337
+ await writeFile(join(dir, rel), t.content);
338
+ return { args: job.m.installArgs(), cwd: dir };
339
+ }
340
+ const add = job.m.addArgs(job.specs.map(specArg));
341
+ if (add === null) {
342
+ const manifest = own ? targetManifest(own) : 'package.json';
343
+ await writeSpecs(join(dir, manifest), job.specs, job.m);
344
+ if (own?.lockfile && job.m.requestAgain)
345
+ await job.m.requestAgain(join(dir, own.lockfile), job.specs.map((s) => s.name), manifest);
346
+ const installArgs = job.m.installArgs();
347
+ return job.m.installWhereCommandRuns ? whereCommandRuns(installArgs, dir, own) : { args: installArgs, cwd: dir };
348
+ }
349
+ return whereCommandRuns(add, dir, own);
350
+ }
351
+ /** In the command's directory, as the real command runs. */
352
+ async function whereCommandRuns(args, dir, own) {
353
+ const rel = own && own.startRel !== '' ? safeRelative(own.startRel) : null;
354
+ if (rel === null)
355
+ return { args, cwd: dir };
356
+ await mkdir(join(dir, rel), { recursive: true });
357
+ return { args, cwd: join(dir, rel) };
358
+ }
359
+ /**
360
+ * Step 5: the version of the manager that will run, asked where it will run
361
+ * (the run's directory, with the run's files written and its variables), so
362
+ * corepack answers for the same manifest. Returns that version.
363
+ */
364
+ async function versionGate(job, box, call) {
365
+ const { minimum } = job.m;
366
+ if (!minimum)
367
+ return null;
368
+ if (timeLeft(job) <= 0)
369
+ stop('resolution_timeout');
370
+ const v = await job.deps.run(job.m.command, ['--version'], { cwd: call.cwd, env: box.env, deadlineMs: timeLeft(job) });
371
+ if (v.missing)
372
+ stop('manager_missing');
373
+ if (v.timedOut)
374
+ stop('resolution_timeout');
375
+ const version = v.code === 0 ? versionOf(v.stdout) : null;
376
+ if (version === null)
377
+ return stop('resolution_failed');
378
+ const [major, minor] = version.split('.').map(Number);
379
+ if (major < minimum.major || (major === minimum.major && minor < minimum.minor))
380
+ stop('manager_missing');
381
+ return version;
382
+ }
383
+ /** Step 6: the run, and the new graph. A run that names another version than the one asked is not used. */
384
+ async function runAndRead(job, box, call, reserveMs, asked) {
385
+ const budget = timeLeft(job) - reserveMs;
386
+ if (budget <= 0)
387
+ stop('resolution_timeout');
388
+ const r = await job.deps.run(job.m.command, call.args, { cwd: call.cwd, env: box.env, deadlineMs: budget });
389
+ if (r.missing)
390
+ stop('manager_missing');
391
+ if (r.timedOut)
392
+ stop('resolution_timeout');
393
+ const ran = job.m.reportedVersion?.(r.stdout) ?? null;
394
+ if (asked !== null && ran !== null && ran !== asked)
395
+ stop('resolution_failed');
396
+ if (r.code !== 0)
397
+ stop('resolution_failed');
398
+ const text = await readFile(join(box.sandbox.dir, box.lockName), 'utf8').catch(() => null);
399
+ const after = text === null ? null : job.m.read(text);
400
+ return after ?? stop('resolution_failed');
401
+ }
402
+ /** Step 7: what enters, `publicRegistry` narrowed by the registry configuration. */
403
+ function compare(job, view, before, after) {
404
+ const custom = new Set(job.specs.filter((s) => s.registry === 'custom').map((s) => s.name));
405
+ const packages = enteringPackages(before, after, allDirect(after)).map((p) => ({
406
+ ...p,
407
+ publicRegistry: p.publicRegistry && !custom.has(p.name) && view.isPublic(p.name),
408
+ }));
409
+ return { packages, notVerified: dedupe([...job.notes, ...enteringNotVerified(before, after)]), mode: 'full' };
410
+ }
411
+ /** Resolves a trigger with one JavaScript manager. Never throws. */
412
+ export async function resolveJsTree(m, input, deps) {
413
+ const job = jobOf(m, input, deps);
414
+ if (job.specs.length === 0)
415
+ return { packages: [], notVerified: job.notes, mode: 'full' };
416
+ // A registry named on the command line is in no file the sandbox gets: never resolved.
417
+ if (input.trigger.kind !== 'edit' && input.trigger.customRegistry)
418
+ return directOnly(job.specs, 'custom_registry', NOTHING_PUBLIC, job.notes);
419
+ let view = NOTHING_PUBLIC;
420
+ let box = null;
421
+ try {
422
+ const place = locate(job);
423
+ view = place.view;
424
+ checkMayRun(job, place);
425
+ box = await copy(job, place);
426
+ const { before, reserveMs } = await oldGraph(job, place, box);
427
+ const call = await command(job, place, box);
428
+ const asked = await versionGate(job, box, call);
429
+ const after = await runAndRead(job, box, call, reserveMs, asked);
430
+ return compare(job, view, before, after);
431
+ }
432
+ catch (e) {
433
+ return directOnly(job.specs, fallbackReason(e), view, job.notes);
434
+ }
435
+ finally {
436
+ if (box)
437
+ await box.sandbox.dispose();
438
+ }
439
+ }
440
+ //# sourceMappingURL=shared.js.map