@preventive/triage 1.0.0-alpha.6 → 1.0.0-alpha.61

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 (409) hide show
  1. package/LICENSE-APACHE +202 -0
  2. package/README.md +16 -0
  3. package/api/reap.ts +17 -0
  4. package/cli.js +6 -0
  5. package/client/dependency-paths.d.ts +3 -0
  6. package/client/dependency-paths.js +36 -0
  7. package/client/finding-link.js +305 -0
  8. package/client/linked-findings.d.ts +1 -0
  9. package/client/linked-findings.js +115 -0
  10. package/common/bundle-commit.d.ts +1 -0
  11. package/common/bundle-commit.js +4 -0
  12. package/common/bundle-compare-diff.d.ts +3 -0
  13. package/common/bundle-compare-diff.js +376 -0
  14. package/common/bundle-compare-inputs.d.ts +3 -0
  15. package/common/bundle-compare-inputs.js +141 -0
  16. package/common/bundle-compare-versions.js +172 -0
  17. package/common/bundle-comparison.d.ts +8 -0
  18. package/common/bundle-comparison.js +69 -0
  19. package/common/bundle-metadata.d.ts +15 -0
  20. package/common/bundle-metadata.js +226 -0
  21. package/common/bundle-pkg-of.d.ts +1 -0
  22. package/common/bundle-pkg-of.js +90 -0
  23. package/common/bundle-reasons.d.ts +2 -0
  24. package/common/bundle-reasons.js +21 -0
  25. package/common/bundle-source-links.d.ts +6 -0
  26. package/common/bundle-source-links.js +216 -0
  27. package/common/bundle-sourcemap.d.ts +10 -0
  28. package/common/bundle-sourcemap.js +100 -0
  29. package/common/bundle-sources.d.ts +7 -0
  30. package/common/bundle-sources.js +333 -0
  31. package/common/bundle-stats.js +41 -0
  32. package/common/bundle-tabs.js +1 -0
  33. package/common/code-language.js +65 -0
  34. package/common/default-scan-models.ts +36 -0
  35. package/common/dependency-reviews.d.ts +18 -0
  36. package/common/dependency-reviews.js +64 -0
  37. package/common/finding-duplicates.js +58 -0
  38. package/common/finding-filters.js +274 -0
  39. package/common/finding-id.js +47 -0
  40. package/common/finding-repo.d.ts +5 -0
  41. package/common/finding-repo.js +67 -0
  42. package/common/github-issue-labels.d.ts +1 -0
  43. package/common/github-issue-labels.js +11 -0
  44. package/common/github-pr.ts +56 -0
  45. package/common/gzip.js +59 -0
  46. package/common/line-diff.d.ts +8 -0
  47. package/common/line-diff.js +57 -0
  48. package/common/linked-workspace-groups.js +63 -0
  49. package/common/managed/agent-tasks.ts +292 -0
  50. package/common/managed/comments.ts +43 -0
  51. package/common/managed/finding-detail.d.ts +5 -0
  52. package/common/managed/finding-detail.js +75 -0
  53. package/common/managed/finding-values.d.ts +2 -0
  54. package/common/managed/finding-values.js +44 -0
  55. package/common/managed/github-agents.ts +114 -0
  56. package/common/managed/github-logins.ts +49 -0
  57. package/common/managed/lite-name.d.ts +2 -0
  58. package/common/managed/lite-name.js +20 -0
  59. package/common/managed/npm-packages.d.ts +7 -0
  60. package/common/managed/npm-packages.js +51 -0
  61. package/common/managed/permissions.ts +31 -0
  62. package/common/managed/report-content.ts +72 -0
  63. package/common/managed/report-filter.ts +120 -0
  64. package/common/managed/repository-alias.ts +65 -0
  65. package/common/managed/roles.ts +35 -0
  66. package/common/managed/routes.d.ts +2 -0
  67. package/common/managed/routes.js +363 -0
  68. package/common/managed/scan-models.ts +6 -0
  69. package/common/managed/team-app.d.ts +15 -0
  70. package/common/managed/team-app.js +100 -0
  71. package/common/managed/team-filters.js +26 -0
  72. package/common/managed/triage.ts +83 -0
  73. package/common/managed/upload-seal.ts +126 -0
  74. package/common/pretty-print.d.ts +5 -0
  75. package/common/pretty-print.js +24 -0
  76. package/common/repo-commit.d.ts +4 -0
  77. package/common/repo-commit.js +30 -0
  78. package/common/revalidation-conflicts.js +48 -0
  79. package/common/revalidation-input-groups.js +56 -0
  80. package/common/save-error-reason.ts +20 -7
  81. package/common/scan-server.ts +13 -0
  82. package/common/security-links.d.ts +5 -0
  83. package/common/security-links.js +33 -0
  84. package/common/server-info.ts +46 -0
  85. package/common/utf8.d.ts +3 -0
  86. package/common/utf8.js +45 -0
  87. package/common/workspace-app.js +71 -0
  88. package/common/workspace-groups.js +176 -0
  89. package/out/activity.js +4 -0
  90. package/out/brotli-fallback.js +3 -3
  91. package/out/chunk-2XUEZHIP.js +28 -0
  92. package/out/chunk-4EMM6UCD.js +1 -0
  93. package/out/chunk-4ISO5F7Y.js +7 -0
  94. package/out/chunk-4XIH7YTX.js +1 -0
  95. package/out/chunk-6CCSTJWB.js +1 -0
  96. package/out/chunk-74AEKRES.js +10 -0
  97. package/out/chunk-7BKKYVWR.js +7 -0
  98. package/out/chunk-7C7DWL7I.js +1 -0
  99. package/out/chunk-B3FNMHOE.js +1 -0
  100. package/out/chunk-BNH52UHC.js +2 -0
  101. package/out/chunk-BRO77PQY.js +42 -0
  102. package/out/chunk-C4Z6ZBXV.js +10 -0
  103. package/out/chunk-DEVAORP2.js +1 -0
  104. package/out/chunk-E3LFSUDJ.js +9 -0
  105. package/out/chunk-G3LY2FV4.js +1 -0
  106. package/out/chunk-GO7FT4OD.js +1 -0
  107. package/out/chunk-GRGIZOTP.js +4 -0
  108. package/out/chunk-HAZKDK4M.js +4 -0
  109. package/out/chunk-HOB3YPS5.js +1 -0
  110. package/out/chunk-IYPY47MC.js +1 -0
  111. package/out/chunk-IZ6MYRYB.js +3 -0
  112. package/out/chunk-J2FWBXFV.js +1 -0
  113. package/out/chunk-JCIIBLKR.js +1 -0
  114. package/out/chunk-JFL7WLRV.js +1 -0
  115. package/out/chunk-JJK5OZG2.js +15 -0
  116. package/out/chunk-JMG5DXII.js +2 -0
  117. package/out/chunk-JOXLZXMI.js +1 -0
  118. package/out/chunk-M37X4LCF.js +14 -0
  119. package/out/chunk-M3Y6SLC4.js +1 -0
  120. package/out/chunk-NRPC74AM.js +1 -0
  121. package/out/chunk-NXATZJQ2.js +1 -0
  122. package/out/chunk-OFZYEWBH.js +244 -0
  123. package/out/chunk-OIERSXON.js +1 -0
  124. package/out/chunk-OOJM4CTU.js +1 -0
  125. package/out/chunk-PAD2JHZT.js +1 -0
  126. package/out/chunk-PNHBZGDD.js +1 -0
  127. package/out/chunk-PTFQKLKO.js +1 -0
  128. package/out/chunk-PWFUOLZK.js +17 -0
  129. package/out/chunk-PXK7EU4V.js +1 -0
  130. package/out/chunk-QCOGVL37.js +52 -0
  131. package/out/chunk-QMVOEBWC.js +13 -0
  132. package/out/chunk-QRKFPLA4.js +80 -0
  133. package/out/chunk-R3NZFXVR.js +1 -0
  134. package/out/chunk-R5O6FAW4.js +2 -0
  135. package/out/chunk-RRBIJL2B.js +1 -0
  136. package/out/chunk-SYXT3SFP.js +2 -0
  137. package/out/chunk-TOXMUOIW.js +5 -0
  138. package/out/chunk-TUII34K2.js +1 -0
  139. package/out/chunk-UCP3JRE2.js +1 -0
  140. package/out/chunk-VFWMQ3LG.js +2 -0
  141. package/out/chunk-VRX2APNA.js +9 -0
  142. package/out/chunk-W3QFV4SP.js +3 -0
  143. package/out/chunk-W6VOKW2N.js +12 -0
  144. package/out/chunk-WCPJDAYA.js +10 -0
  145. package/out/chunk-WMFDQS2L.js +11 -0
  146. package/out/chunk-WREU7JAG.js +1 -0
  147. package/out/chunk-Y5ZHFNBD.js +2 -0
  148. package/out/chunk-YF4M5OCI.js +1 -0
  149. package/out/chunk-Z667U2UJ.js +1 -0
  150. package/out/chunk-ZQHLECTI.js +1 -0
  151. package/out/chunk-ZQNEWVGG.js +1 -0
  152. package/out/client-managed-import.js +4 -0
  153. package/out/client-managed.js +34 -0
  154. package/out/client-sync.js +11 -17
  155. package/out/compare.js +40 -0
  156. package/out/dialogs.js +40 -0
  157. package/out/github-issue-authorized.html +3 -0
  158. package/out/github-issue-authorized.js +1 -0
  159. package/out/graph.js +19 -4
  160. package/out/index.html +106 -8
  161. package/out/prism.js +14 -10
  162. package/out/scan.js +2 -0
  163. package/out/stasis.svg +20 -0
  164. package/out/terminal.js +366 -39
  165. package/out/view.css +1 -1
  166. package/out/view.js +19 -144
  167. package/package.json +383 -63
  168. package/risk/actions/findings.js +161 -0
  169. package/risk/actions/resolve.js +250 -0
  170. package/risk/actions/scripts/commands.js +182 -0
  171. package/risk/actions/scripts/grade.js +113 -0
  172. package/risk/actions/scripts/packages.js +123 -0
  173. package/risk/actions/scripts/shell.js +169 -0
  174. package/risk/actions/uses.js +76 -0
  175. package/risk/actions/workflow.js +110 -0
  176. package/risk/files/characters.js +196 -0
  177. package/risk/files/hosts.js +205 -0
  178. package/risk/files/readability.js +177 -0
  179. package/risk/files/runs-code.js +615 -0
  180. package/risk/files/script.js +118 -0
  181. package/risk/files/stamps.js +47 -0
  182. package/risk/index.d.ts +272 -0
  183. package/risk/index.js +11 -0
  184. package/risk/npm/assess.js +285 -0
  185. package/risk/npm/combined.js +68 -0
  186. package/risk/npm/compare.js +257 -0
  187. package/risk/npm/dependencies.js +172 -0
  188. package/risk/npm/diff.js +79 -0
  189. package/risk/npm/downloads.js +84 -0
  190. package/risk/npm/files.js +445 -0
  191. package/risk/npm/held.js +63 -0
  192. package/risk/npm/install-scripts.js +34 -0
  193. package/risk/npm/malware.js +38 -0
  194. package/risk/npm/manifest.js +65 -0
  195. package/risk/npm/new-dependency.js +60 -0
  196. package/risk/npm/old-version.js +108 -0
  197. package/risk/npm/registry.js +390 -0
  198. package/risk/npm/release.js +85 -0
  199. package/risk/npm/score.js +59 -0
  200. package/risk/npm/specs.js +124 -0
  201. package/risk/npm/tarball.js +96 -0
  202. package/server-common/database-config.ts +16 -0
  203. package/server-common/initialize.ts +18 -0
  204. package/server-common/npm-advisories.ts +101 -0
  205. package/{server → server-common}/origin.ts +5 -5
  206. package/server-common/reap.ts +48 -0
  207. package/server-common/scan-config.ts +19 -0
  208. package/server-common/standalone.ts +29 -0
  209. package/server-common/storage-crypto.ts +182 -0
  210. package/server-common/storage-log.ts +38 -0
  211. package/server-common/vercel-blob.ts +103 -0
  212. package/server-e2e/app.ts +487 -0
  213. package/{server → server-e2e}/bus-receiver.ts +2 -1
  214. package/{server → server-e2e}/cli.js +9 -4
  215. package/{server → server-e2e}/config.ts +50 -42
  216. package/{server → server-e2e}/db-neon.ts +2 -2
  217. package/{server → server-e2e}/db-revision-sql.ts +1 -1
  218. package/{server → server-e2e}/db-stmt.ts +2 -2
  219. package/{server → server-e2e}/db.ts +7 -7
  220. package/{server → server-e2e}/http.ts +44 -13
  221. package/{server → server-e2e}/hub.ts +40 -9
  222. package/server-e2e/index.ts +17 -0
  223. package/server-e2e/lifecycle.ts +95 -0
  224. package/{server → server-e2e}/neon-driver.ts +2 -2
  225. package/{server → server-e2e}/npm-proxy.ts +12 -145
  226. package/{server → server-e2e}/objstore/blob-vercel.ts +10 -114
  227. package/{server → server-e2e}/objstore/blob.ts +1 -1
  228. package/{server → server-e2e}/objstore/fetch-mint-guard.ts +2 -2
  229. package/{server → server-e2e}/objstore/handlers.ts +9 -8
  230. package/{server → server-e2e}/objstore/init.ts +19 -27
  231. package/{server → server-e2e}/objstore/reaper.ts +1 -1
  232. package/{server → server-e2e}/objstore/rest-deny.ts +1 -1
  233. package/{server → server-e2e}/objstore/rest-mint.ts +3 -3
  234. package/{server → server-e2e}/objstore/rest.ts +3 -3
  235. package/{server → server-e2e}/objstore/store-neon.ts +6 -10
  236. package/{server → server-e2e}/objstore/store.ts +7 -7
  237. package/{server → server-e2e}/objstore/tokens.ts +2 -2
  238. package/{server → server-e2e}/pubsub.ts +12 -9
  239. package/{server → server-e2e}/sign.ts +4 -4
  240. package/{server → server-e2e}/sse-server.ts +60 -33
  241. package/{server → server-e2e}/static.ts +31 -21
  242. package/{server → server-e2e}/sync-handlers.ts +64 -30
  243. package/{server → server-e2e}/ws-server.ts +20 -9
  244. package/server-managed/activity.ts +238 -0
  245. package/server-managed/agent-merges.ts +109 -0
  246. package/server-managed/app-agents.ts +23 -0
  247. package/server-managed/avatar-store.ts +13 -0
  248. package/server-managed/blob-store.ts +26 -0
  249. package/server-managed/brotli.ts +10 -0
  250. package/server-managed/bundle-advisories.ts +103 -0
  251. package/server-managed/bundle-advisory-inventory.ts +77 -0
  252. package/server-managed/bundle-build-diagnostics.d.ts +10 -0
  253. package/server-managed/bundle-build-diagnostics.js +23 -0
  254. package/server-managed/bundle-build-leases.ts +41 -0
  255. package/server-managed/bundle-build-worker.js +238 -0
  256. package/server-managed/bundle-build.ts +240 -0
  257. package/server-managed/bundle-cache.ts +199 -0
  258. package/server-managed/bundle-catalog.ts +29 -0
  259. package/server-managed/bundle-commits.ts +133 -0
  260. package/server-managed/bundle-dependency-reviews.ts +68 -0
  261. package/server-managed/bundle-store.ts +24 -0
  262. package/server-managed/bundle-summary-cache.ts +139 -0
  263. package/server-managed/bundle-validation.ts +33 -0
  264. package/server-managed/bundle.ts +119 -0
  265. package/server-managed/cache-storage.ts +20 -0
  266. package/server-managed/cli.js +21 -0
  267. package/server-managed/combined.ts +43 -0
  268. package/server-managed/comments.ts +138 -0
  269. package/server-managed/commit-coauthors.ts +105 -0
  270. package/server-managed/commit-lockfiles.ts +77 -0
  271. package/server-managed/comparison.ts +50 -0
  272. package/server-managed/config.ts +163 -0
  273. package/server-managed/content-access.ts +15 -0
  274. package/server-managed/crypto.ts +25 -0
  275. package/server-managed/db-methods.ts +1877 -0
  276. package/server-managed/db-neon.ts +388 -0
  277. package/server-managed/db-schema.ts +253 -0
  278. package/server-managed/db-table-names.ts +22 -0
  279. package/server-managed/db.ts +146 -0
  280. package/server-managed/dependabot-access.ts +61 -0
  281. package/server-managed/dependabot-alerts.ts +180 -0
  282. package/server-managed/dependency-review-comments.ts +92 -0
  283. package/server-managed/dependency-reviews.ts +363 -0
  284. package/server-managed/github-accounts.ts +59 -0
  285. package/server-managed/github-actions.ts +71 -0
  286. package/server-managed/github-app.ts +347 -0
  287. package/server-managed/github-errors.ts +70 -0
  288. package/server-managed/github-graphql.ts +42 -0
  289. package/server-managed/github-issue-links.ts +264 -0
  290. package/server-managed/github-issue-oauth.ts +30 -0
  291. package/server-managed/github-issues.ts +157 -0
  292. package/server-managed/github-link-oauth.ts +56 -0
  293. package/server-managed/github-links.ts +204 -0
  294. package/server-managed/github-metadata.ts +213 -0
  295. package/server-managed/github-oauth.ts +264 -0
  296. package/server-managed/github-pulls.ts +257 -0
  297. package/server-managed/github-requests.ts +179 -0
  298. package/server-managed/github-users.ts +30 -0
  299. package/server-managed/github-values.ts +26 -0
  300. package/server-managed/history-windows.ts +172 -0
  301. package/server-managed/http-response.ts +76 -0
  302. package/server-managed/http.ts +5796 -0
  303. package/server-managed/import-triage.ts +51 -0
  304. package/server-managed/index.ts +204 -0
  305. package/server-managed/kept-briefly.ts +37 -0
  306. package/server-managed/kept.ts +28 -0
  307. package/server-managed/link-reports.ts +149 -0
  308. package/server-managed/listed-activity.ts +39 -0
  309. package/server-managed/locked-packages.ts +152 -0
  310. package/server-managed/lockfile-scope.ts +49 -0
  311. package/server-managed/lru.ts +30 -0
  312. package/server-managed/managed-issues.ts +92 -0
  313. package/server-managed/management-catalog.ts +45 -0
  314. package/server-managed/management.ts +110 -0
  315. package/server-managed/npm-delta-worker.js +23 -0
  316. package/server-managed/npm-delta.ts +159 -0
  317. package/server-managed/npm-insights.ts +455 -0
  318. package/server-managed/npm-kept.ts +234 -0
  319. package/server-managed/npm-loads.ts +259 -0
  320. package/server-managed/npm-manifest.ts +117 -0
  321. package/server-managed/npm-packages.ts +462 -0
  322. package/server-managed/npm-patch.ts +317 -0
  323. package/server-managed/npm-provenance.ts +127 -0
  324. package/server-managed/npm-risk.ts +287 -0
  325. package/server-managed/object-storage-disk.ts +147 -0
  326. package/server-managed/object-storage-vercel.ts +71 -0
  327. package/server-managed/object-storage.ts +82 -0
  328. package/server-managed/package-entry-points.ts +79 -0
  329. package/server-managed/pretty-print.ts +425 -0
  330. package/server-managed/public-workspace.ts +242 -0
  331. package/server-managed/pull-comment-reviews.ts +161 -0
  332. package/server-managed/pull-dependencies.ts +340 -0
  333. package/server-managed/pull-dependency-reviews.ts +327 -0
  334. package/server-managed/pull-reviews.ts +202 -0
  335. package/server-managed/queue.ts +53 -0
  336. package/server-managed/release-commits.ts +85 -0
  337. package/server-managed/rename-diff-worker.js +26 -0
  338. package/server-managed/rename-diff.ts +236 -0
  339. package/server-managed/repo-path.ts +21 -0
  340. package/server-managed/report-migration.ts +32 -0
  341. package/server-managed/report-query.ts +10 -0
  342. package/server-managed/report-response.ts +16 -0
  343. package/server-managed/report-sources.ts +181 -0
  344. package/server-managed/report-store.ts +77 -0
  345. package/server-managed/repository-actions.ts +220 -0
  346. package/server-managed/repository-agents.ts +422 -0
  347. package/server-managed/repository-aliases.ts +85 -0
  348. package/server-managed/repository-browser.ts +303 -0
  349. package/server-managed/repository-changes.ts +280 -0
  350. package/server-managed/repository-code.ts +215 -0
  351. package/server-managed/repository-dependency-reviews.ts +159 -0
  352. package/server-managed/repository-discovery.ts +83 -0
  353. package/server-managed/repository-history.ts +428 -0
  354. package/server-managed/repository-issues.ts +224 -0
  355. package/server-managed/repository-policy.ts +27 -0
  356. package/server-managed/repository-pulls.ts +207 -0
  357. package/server-managed/repository-pulse.ts +477 -0
  358. package/server-managed/repository-risk-assess.ts +108 -0
  359. package/server-managed/repository-risk-audit.ts +78 -0
  360. package/server-managed/repository-risk-read.ts +170 -0
  361. package/server-managed/repository-risk.ts +483 -0
  362. package/server-managed/repository-squashes.ts +160 -0
  363. package/server-managed/repository-stamp.ts +41 -0
  364. package/server-managed/request-timing.ts +63 -0
  365. package/server-managed/reviewed-dependencies.ts +149 -0
  366. package/server-managed/revisions.ts +35 -0
  367. package/server-managed/scan-downloads.ts +87 -0
  368. package/server-managed/session.ts +132 -0
  369. package/server-managed/slugs.ts +38 -0
  370. package/server-managed/solidity-entry-points.ts +71 -0
  371. package/server-managed/sql-postgres.ts +34 -0
  372. package/server-managed/sql.ts +107 -0
  373. package/server-managed/stasis-config.ts +55 -0
  374. package/server-managed/static.ts +28 -0
  375. package/server-managed/storage-command.ts +16 -0
  376. package/server-managed/storage-db.ts +183 -0
  377. package/server-managed/storage-encryption.ts +288 -0
  378. package/server-managed/storage-maintenance.ts +259 -0
  379. package/server-managed/storage-payload.ts +121 -0
  380. package/server-managed/storage-stores.ts +91 -0
  381. package/server-managed/storage.ts +82 -0
  382. package/server-managed/team-app-summaries.ts +54 -0
  383. package/server-managed/team-app.ts +154 -0
  384. package/server-managed/team-catalog.ts +7 -0
  385. package/server-managed/team-feed.ts +180 -0
  386. package/server-managed/team-npm-scopes.ts +103 -0
  387. package/server-managed/team-reports.ts +351 -0
  388. package/server-managed/triage-response.ts +16 -0
  389. package/server-managed/type-only-proof.js +108 -0
  390. package/server-managed/type-only-worker.js +31 -0
  391. package/server-managed/type-only.ts +115 -0
  392. package/server-managed/uploads.ts +106 -0
  393. package/server-managed/upstream-cache.ts +250 -0
  394. package/server-managed/view-as.ts +58 -0
  395. package/server-managed/worker-turns.ts +76 -0
  396. package/server-managed/workspace-shares.ts +170 -0
  397. package/server.ts +70 -0
  398. package/server/index.ts +0 -480
  399. package/server/lifecycle.ts +0 -208
  400. /package/{LICENSE → LICENSE-MIT} +0 -0
  401. /package/{server → server-e2e}/auth.ts +0 -0
  402. /package/{server → server-e2e}/config.example.json +0 -0
  403. /package/{server → server-e2e}/objstore/blob-fs.ts +0 -0
  404. /package/{server → server-e2e}/objstore/fs.ts +0 -0
  405. /package/{server → server-e2e}/objstore/sign.ts +0 -0
  406. /package/{server → server-e2e}/peer.ts +0 -0
  407. /package/{server → server-e2e}/sse-session.ts +0 -0
  408. /package/{server → server-e2e}/util.ts +0 -0
  409. /package/{server → server-e2e}/validation.ts +0 -0
@@ -0,0 +1,115 @@
1
+ // The "links" file — a small JSON document that says which findings
2
+ // are the SAME finding, reported twice:
3
+ //
4
+ // [["a", "b"], ["c", "d", "e"]]
5
+ // Entries may also be objects such as {"id":"a"}, for existing exports.
6
+ //
7
+ // One inner array per link. Every finding named in it is a duplicate
8
+ // of every other one in that array, and the file says nothing else:
9
+ // no severity, no title, no file, no prose. That is the whole format.
10
+ //
11
+ // It is NOT a report, and this module deliberately sits outside
12
+ // `@preventive/report` because of it. A report carries findings; a links file
13
+ // carries only ids of findings that must already live in reports the
14
+ // reader holds. So it never reaches `ingestReport` / `state.reports`,
15
+ // it has its own view (`ui/view/render-links.js`) that points at the
16
+ // findings. It also supplies the "Duplicates:" row on finding cards
17
+ // and groups explicitly linked rows in workspace App view.
18
+ //
19
+ // Pure — no storage, no DOM, no app state. `linked-findings-index.js`
20
+ // beside this file is the OPFS-wide store built on top; everything
21
+ // here is text in, data out, so the recognition rules are testable on
22
+ // their own.
23
+
24
+ import { isLinkableFindingId } from './finding-link.js'
25
+
26
+ // The `source` marker a links file is filed under — the same slot a
27
+ // report's producer ('deepsec', 'piolium', …) occupies in the counts
28
+ // cache, so `getKind(name)` answers "what kind of file is this" for
29
+ // links and reports alike and the sidebar can bucket both from one
30
+ // lookup. No report format can collide with it: this value comes from
31
+ // here, never from a document's own content.
32
+ export const LINKS_KIND = 'links'
33
+
34
+ // Read a string ID or an existing object entry — `{"id": "…"}`. Extra fields are allowed and ignored: an exporter that
35
+ // writes the title or the report alongside the id is writing a
36
+ // superset of this format, not a different one.
37
+ function entryId(entry) {
38
+ if (typeof entry === 'string') return entry.length > 0 ? entry : null
39
+ if (!entry || typeof entry !== 'object' || Array.isArray(entry)) return null
40
+ const { id } = entry
41
+ return typeof id === 'string' && id.length > 0 ? id : null
42
+ }
43
+
44
+ // Recognise `content` as a links file and normalise it.
45
+ //
46
+ // Returns `{ groups, skipped }` — `groups` is one `string[]` of finding
47
+ // ids per link, and `skipped` counts ids the app could never follow (a
48
+ // session-local numeric id, a control character, something absurdly
49
+ // long — `isLinkableFindingId` draws the same line the per-finding Link
50
+ // button draws). Returns null when the text isn't this format at all.
51
+ //
52
+ // Recognition is on SHAPE, and it is strict, because this parser runs
53
+ // against every dropped file before the report readers get their turn:
54
+ // a top-level array, holding only arrays, holding string IDs or objects with a
55
+ // string `id`. Nothing else this app reads is a bare JSON array, so
56
+ // nothing else can be mistaken for one — and an empty top-level array
57
+ // is refused rather than claimed, since `[]` is every empty JSON list
58
+ // in the world, not distinctively a links file.
59
+ //
60
+ // Normalisation drops what carries no information: ids repeated inside
61
+ // one link, ids that can't be linked, and then any link left naming
62
+ // fewer than two findings — a "link" to a single finding links nothing.
63
+ // A file whose every link normalises away is still a links file; it
64
+ // just has no links, which its view says plainly.
65
+ export function parseLinkedFindings(content) {
66
+ // Only text opening an array can parse to one, so a report — which
67
+ // opens an object — is turned away without being parsed twice.
68
+ if (typeof content === 'string' && !/^\s*\[/u.test(content)) return null
69
+ let data
70
+ try { data = JSON.parse(content) } catch { return null }
71
+ if (!Array.isArray(data) || data.length === 0) return null
72
+ const groups = []
73
+ let skipped = 0
74
+ for (const raw of data) {
75
+ if (!Array.isArray(raw)) return null
76
+ const ids = new Set()
77
+ for (const entry of raw) {
78
+ const id = entryId(entry)
79
+ if (id === null) return null
80
+ if (isLinkableFindingId(id)) ids.add(id)
81
+ else skipped++
82
+ }
83
+ if (ids.size > 1) groups.push([...ids])
84
+ }
85
+ return { groups, skipped }
86
+ }
87
+
88
+ // How many findings the links in `groups` name, counted once each — a
89
+ // finding named by two links is one linked finding. What the sidebar
90
+ // badge and the view's header report alongside the link count.
91
+ export function countLinkedIds(groups) {
92
+ const ids = new Set()
93
+ for (const group of groups) for (const id of group) ids.add(id)
94
+ return ids.size
95
+ }
96
+
97
+ // Fold links into `index` (a `Map<id, Set<id>>`): every id in a link
98
+ // gains every OTHER id in it as a duplicate. Called once per links
99
+ // file, so an id linked by two files ends up with the union of what
100
+ // both said about it.
101
+ //
102
+ // Union, NOT transitive closure. If one file links a↔b and another
103
+ // links b↔c, then b has two duplicates and a has one — a and c were
104
+ // never said to be the same finding, and inferring it would put a
105
+ // claim in the reader's card that no file they dropped ever made.
106
+ export function collectDuplicates(groups, index) {
107
+ for (const group of groups) {
108
+ for (const id of group) {
109
+ let set = index.get(id)
110
+ if (!set) index.set(id, set = new Set())
111
+ for (const other of group) if (other !== id) set.add(other)
112
+ }
113
+ }
114
+ return index
115
+ }
@@ -0,0 +1 @@
1
+ export function bundleCommitHash(value: unknown): string | null
@@ -0,0 +1,4 @@
1
+ // Match the full Git object IDs used by bundle origin links.
2
+ export function bundleCommitHash(value) {
3
+ return typeof value === 'string' && /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/u.test(value) ? value : null
4
+ }
@@ -0,0 +1,3 @@
1
+ export function computeBundleDiff(base: Map<string, unknown>, other: Map<string, unknown>, pkgOf: (path: string) => string, layout?: import('@preventive/compare').Layout): {
2
+ files: { onlyBase: { path: string; basePath?: string }[]; onlyOther: { path: string }[]; changed: { path: string; basePath?: string; renamedFrom?: string }[] }
3
+ }
@@ -0,0 +1,376 @@
1
+ // Shared bundle comparison — no Lit, no DOM, no `state`. Given two
2
+ // `Map<path, content>` file maps (the shape `bundleFilesAsMap` returns
3
+ // for either a sourcemap or a stasis bundle: every file the terminal
4
+ // mounts, source or resource, with no directory captures) plus a
5
+ // `pkgOf(path)` bucketing function, it computes a structural diff:
6
+ // which files exist only in one side, which exist in both but changed,
7
+ // per-package size deltas, and the roll-up totals.
8
+ //
9
+ // Kept free of Lit, the DOM and the OPFS parse pipeline on purpose, so
10
+ // `<bundle-compare>` (the Compare slide in the bundles view) and its
11
+ // unit test can both consume the same logic — the test exercises this
12
+ // module directly. Its imports are the file sizer the Overview uses and
13
+ // @preventive/compare's renames and layout, all pure. The component is a
14
+ // thin rendering shell around `computeBundleDiff`.
15
+ //
16
+ // `base` is the currently-open bundle (the tab you're viewing);
17
+ // `other` is the bundle picked to compare against. The result names
18
+ // the two sides `onlyBase` / `onlyOther` rather than added / removed
19
+ // so the UI can label them with each bundle's actual name — "added"
20
+ // is ambiguous without knowing which side is newer.
21
+
22
+ import { compareTrees, treeLayout } from '@preventive/compare'
23
+ import { bundleFileByteLength } from './bundle-sources.js'
24
+ import { resolutionKey } from './bundle-compare-inputs.js'
25
+
26
+ // Resolutions compare independently from file bytes: identical files can be
27
+ // wired together differently. Inputs are keyed by importer, specifier,
28
+ // conditions (including import attributes), and platform. Resolutions whose
29
+ // targets changed are reported (`changed`, repointed); one recorded on a side
30
+ // alone (`onlyBase`, `onlyOther`) only where its importer holds the same
31
+ // contents on both sides (`identical`, of its path as the other bundle lays
32
+ // it out), as a file whose code changed gains and drops imports with it.
33
+ // Each row names its target on either side, null on the side without one.
34
+ // `renames` (base path → other path, see renamesOf) names base files as
35
+ // the other bundle does: a renamed importer's resolutions pair with its new
36
+ // path's, reported under it, and a target renamed is the same target.
37
+ // `basePaths` and `root` (computeBundleDiff's `files`) name the rest where
38
+ // the bundles' roots differ, a base target shown as the other bundle would
39
+ // lay it out; a path no file has (an importer the bundle didn't capture, a
40
+ // builtin) may read either as it is or through the root.
41
+ export function computeResolutionDiff(base, other, renames = new Map(), basePaths = new Map(), root = null, identical = () => false) {
42
+ const names = path => {
43
+ const known = renames.get(path) ?? basePaths.get(path)
44
+ return known === undefined ? [...new Set([path, through(root, path) ?? path])] : [known]
45
+ }
46
+ const changed = [], onlyBase = [], onlyOther = []
47
+ const paired = new Set()
48
+ for (const before of base.values()) {
49
+ const after = names(before.parent).map(parent => other.get(resolutionKey(parent, before.specifier, before.conditions, before.platform))).find(Boolean)
50
+ const baseTarget = basePaths.get(before.target) ?? before.target
51
+ if (after) {
52
+ paired.add(after.key)
53
+ if (!names(before.target).includes(after.target)) {
54
+ const { target: otherTarget, ...identity } = after
55
+ changed.push({ ...identity, baseTarget, otherTarget })
56
+ }
57
+ continue
58
+ }
59
+ const parent = names(before.parent).find(identical)
60
+ if (parent === undefined) continue
61
+ const { specifier, conditions, platform } = before
62
+ onlyBase.push({ key: resolutionKey(parent, specifier, conditions, platform), parent, specifier, conditions, platform, baseTarget, otherTarget: null })
63
+ }
64
+ for (const after of other.values()) {
65
+ if (paired.has(after.key) || !identical(after.parent)) continue
66
+ const { target: otherTarget, ...identity } = after
67
+ onlyOther.push({ ...identity, baseTarget: null, otherTarget })
68
+ }
69
+ for (const rows of [changed, onlyBase, onlyOther]) rows.sort((a, b) => a.key.localeCompare(b.key))
70
+ return { changed, onlyBase, onlyOther, totalChanges: changed.length + onlyBase.length + onlyOther.length }
71
+ }
72
+
73
+ // A file's size, by the measure the Overview and Treemap use: text by the
74
+ // UTF-8 it encodes to, a base64 resource by the bytes it decodes to. A
75
+ // file with no size to give (a base64 spelling that does not decode)
76
+ // counts as zero bytes, but is still compared.
77
+ function byteLen(content) {
78
+ return bundleFileByteLength(content) ?? 0
79
+ }
80
+
81
+ // Whether two sides hold the same file. Text compares as text; a base64
82
+ // resource arrives as a fresh `{ format: 'base64', data }` on each side,
83
+ // so it compares by its spelling — identity would call every image
84
+ // changed. A file that is text on one side and base64 on the other has
85
+ // changed. An npm package's binary file compares by its digest.
86
+ function sameContent(a, b) {
87
+ return a === b || (a?.format === 'base64' && b?.format === 'base64' && a.data === b.data)
88
+ || (a?.format === 'digest' && b?.format === 'digest' && a.digest === b.digest)
89
+ }
90
+
91
+ // What a stasis bundle records of a file beside its bytes: the format it
92
+ // loads it in (a resource is carried as data, the rest run as code), whether
93
+ // it carries an execute bit, and whether the bundle starts from it. A
94
+ // function of the file's path; null for another kind of bundle, which
95
+ // records none of it.
96
+ export function bundleFileMeta(details) {
97
+ if (details?.kind !== 'stasis' || !details.bundle) return null
98
+ const { formats, executable, entries } = details.bundle
99
+ return path => ({ format: formats?.get(path), executable: executable?.has(path) ?? false, entry: entries?.has(path) ?? false })
100
+ }
101
+
102
+ // How a file's record changed from one stasis bundle to the other, as
103
+ // `{ field, from, to }` (bundleFileMeta's fields): none where either side
104
+ // records nothing. A format left unsaid is one too: stasis runs such a
105
+ // file as code, so a resource whose format is dropped runs.
106
+ function metaChanges(before, after) {
107
+ if (!before || !after) return []
108
+ return ['format', 'executable', 'entry'].filter(field => before[field] !== after[field]).map(field => ({ field, from: before[field], to: after[field] }))
109
+ }
110
+
111
+ // Comparator: largest absolute delta first, then path/label ascending
112
+ // so equal-magnitude rows stay stably ordered. Used for the changed
113
+ // file + package lists, where the biggest mover is the most
114
+ // interesting row.
115
+ function byAbsDeltaThenKey(key) {
116
+ return (a, b) => {
117
+ const d = Math.abs(b.delta) - Math.abs(a.delta)
118
+ // `d || …` falls through to the tiebreak only when the magnitudes
119
+ // match (d === 0); a non-zero d is returned as-is.
120
+ return d || a[key].localeCompare(b[key])
121
+ }
122
+ }
123
+
124
+ // Largest byte size first, then key ascending — for the only-in-one-
125
+ // side lists, where there's no delta to rank by.
126
+ function byBytesThenKey(key) {
127
+ return (a, b) => {
128
+ const d = b.bytes - a.bytes
129
+ return d || a[key].localeCompare(b[key])
130
+ }
131
+ }
132
+
133
+ // A file's content as compareTrees reads it to find renames, each kind tagged
134
+ // apart: text as it is (a lone surrogate, which no UTF-8 holds, as U+FFFD); a
135
+ // resource by its spelling or its digest; and one with none, by its place in
136
+ // its list alone, so that only its path pairs it.
137
+ function treeData(content, at) {
138
+ if (typeof content === 'string') return `\0text\0${content.toWellFormed()}`
139
+ if (content?.format === 'base64') return `\0base64\0${content.data}`
140
+ return content?.format === 'digest' ? `\0digest\0${content.digest}` : `\0none\0${at}`
141
+ }
142
+
143
+ // git's diff.renameLimit for a package's renames: past this many removed files
144
+ // by added ones, squared, no pair is scored, as that would hold the page for
145
+ // seconds, and only identical content and paths pair them.
146
+ const RENAME_LIMIT = 250
147
+
148
+ // The files of `onlyBase` renamed to one of `onlyOther`, both by path as the
149
+ // other bundle lays them out, within a package: `Map<base path, other path>`,
150
+ // as @preventive/compare's compareTrees finds them, by content as git diff -M
151
+ // does and where their paths say so. Whether a renamed file changed is
152
+ // sameContent's to say, not this reading's. A path no UTF-8 holds is left out.
153
+ function renamesOf(onlyBase, onlyOther, base, other, pkgOf) {
154
+ const entries = (rows, files, side) => rows.filter(({ path }) => path !== '' && path.isWellFormed())
155
+ .map(({ path }, at) => ({ name: path, data: treeData(files.get(path), `${side}${at}`) }))
156
+ const options = { paths: 'keys', renameGroup: pkgOf, renameLimit: RENAME_LIMIT, lines: false }
157
+ const changes = compareTrees(entries(onlyBase, base, 'a'), entries(onlyOther, other, 'b'), options)
158
+ return new Map(changes.filter(({ status }) => status === 'renamed').map(change => [change.old.path, change.new.path]))
159
+ }
160
+
161
+ // A base path through `root` as treeLayout reads it, or null for one outside
162
+ // a base root.
163
+ function through(root, path) {
164
+ if (!root) return path
165
+ if (root.base === '') return `${root.other}${path}`
166
+ return path.startsWith(root.base) ? path.slice(root.base.length) : null
167
+ }
168
+
169
+ // Per-package accumulator factory. Tracks each side's byte total plus
170
+ // per-bucket file counts so a package is flagged `changed` whenever
171
+ // ANY of its files moved — not only when the byte total happens to
172
+ // differ (two versions can shuffle content while landing on the same
173
+ // size).
174
+ function emptyPkgAcc() {
175
+ return {
176
+ baseBytes: 0,
177
+ otherBytes: 0,
178
+ onlyBaseFiles: 0,
179
+ onlyOtherFiles: 0,
180
+ changedFiles: 0,
181
+ }
182
+ }
183
+
184
+ // Compare two bundle source maps. Returns:
185
+ // {
186
+ // totals: { baseFiles, baseBytes, otherFiles, otherBytes,
187
+ // onlyBaseFiles, onlyBaseBytes, onlyOtherFiles,
188
+ // onlyOtherBytes, changedFiles, changedDelta,
189
+ // unchangedFiles, fileDelta, byteDelta, identical },
190
+ // files: {
191
+ // onlyBase: [{ path, bytes }],
192
+ // onlyOther: [{ path, bytes }],
193
+ // changed: [{ path, baseBytes, otherBytes, delta, basePath?, modified?, meta? }],
194
+ // },
195
+ // packages: {
196
+ // onlyBase: [{ pkg, bytes }],
197
+ // onlyOther: [{ pkg, bytes }],
198
+ // changed: [{ pkg, baseBytes, otherBytes, delta }],
199
+ // },
200
+ // }
201
+ //
202
+ // `delta` is always `other − base` (positive = the compared bundle is
203
+ // larger). A file renamed (see renamesOf) is changed, not
204
+ // removed and added: its row's `path` is the other side's, `renamedFrom`
205
+ // the base's, `modified` whether its contents changed too, and it counts in
206
+ // `renamedFiles` as well, its contents moved or not.
207
+ // Where one bundle's files sit under a directory of the other's (`root`, see
208
+ // treeLayout), the base's are compared as the other lays them out: a row's
209
+ // `path` (and `renamedFrom`) reads that way, and `basePath` names the file
210
+ // in the base bundle wherever that differs from `path`. `files.basePaths`
211
+ // maps every base file to how it reads. `layout` (treeLayout) may come
212
+ // from the caller, to key `pkgOf` by the same paths: it is asked of files
213
+ // as the other bundle lays them out.
214
+ // `meta`, each side's bundleFileMeta where it has one, compares what two
215
+ // stasis bundles record of a file beside its bytes: a row whose record
216
+ // changed carries how (`meta`, metaChanges), and a file whose record alone
217
+ // changed is changed too, `modified: false`, its bytes the same.
218
+ // `identical` is true when the two bundles carry the same files with
219
+ // byte-identical content, resources included, each recorded alike.
220
+ export function computeBundleDiff(base, other, pkgOf, layout = treeLayout(base.keys(), other.keys()), meta = []) {
221
+ const { root, paths: basePaths } = layout
222
+ // The base's files as the other lays them out, and back.
223
+ const baseFile = new Map([...basePaths].map(([from, to]) => [to, from]))
224
+ base = new Map([...base].map(([path, content]) => [basePaths.get(path), content]))
225
+ const atBase = path => baseFile.get(path) === path ? {} : { basePath: baseFile.get(path) }
226
+ // How a file's record changed, by its base path and its path, as a row's fields.
227
+ const recorded = (from, to) => {
228
+ const changes = metaChanges(meta[0]?.(from), meta[1]?.(to))
229
+ return changes.length > 0 ? { meta: changes } : {}
230
+ }
231
+ const onlyBase = []
232
+ const onlyOther = []
233
+ const changed = []
234
+ let baseBytes = 0
235
+ let otherBytes = 0
236
+ let onlyBaseBytes = 0
237
+ let onlyOtherBytes = 0
238
+ let changedDelta = 0
239
+ let unchangedFiles = 0
240
+ const pkgs = new Map()
241
+ const pkgAcc = (path) => {
242
+ const key = pkgOf(path)
243
+ let acc = pkgs.get(key)
244
+ if (!acc) { acc = emptyPkgAcc(); pkgs.set(key, acc) }
245
+ return acc
246
+ }
247
+
248
+ const allPaths = new Set([...base.keys(), ...other.keys()])
249
+ for (const path of allPaths) {
250
+ const inBase = base.has(path)
251
+ const inOther = other.has(path)
252
+ const acc = pkgAcc(path)
253
+ if (inBase && inOther) {
254
+ const bC = base.get(path)
255
+ const oC = other.get(path)
256
+ const same = sameContent(bC, oC)
257
+ const record = recorded(baseFile.get(path), path)
258
+ const bB = byteLen(bC)
259
+ // Identical content shares the byte count, so only measure the
260
+ // other side when the files actually differ.
261
+ const oB = same ? bB : byteLen(oC)
262
+ baseBytes += bB
263
+ otherBytes += oB
264
+ acc.baseBytes += bB
265
+ acc.otherBytes += oB
266
+ if (same && !record.meta) {
267
+ unchangedFiles++
268
+ } else {
269
+ const delta = oB - bB
270
+ changed.push({ path, ...atBase(path), baseBytes: bB, otherBytes: oB, delta, ...record, ...same ? { modified: false } : {} })
271
+ changedDelta += delta
272
+ acc.changedFiles++
273
+ }
274
+ } else if (inBase) {
275
+ const bB = byteLen(base.get(path))
276
+ baseBytes += bB
277
+ onlyBaseBytes += bB
278
+ acc.baseBytes += bB
279
+ acc.onlyBaseFiles++
280
+ onlyBase.push({ path, ...atBase(path), bytes: bB })
281
+ } else {
282
+ const oB = byteLen(other.get(path))
283
+ otherBytes += oB
284
+ onlyOtherBytes += oB
285
+ acc.otherBytes += oB
286
+ acc.onlyOtherFiles++
287
+ onlyOther.push({ path, bytes: oB })
288
+ }
289
+ }
290
+
291
+ const renames = renamesOf(onlyBase, onlyOther, base, other, pkgOf)
292
+ if (renames.size > 0) {
293
+ const renamedTo = new Set(renames.values())
294
+ for (const [from, to] of renames) {
295
+ const bC = base.get(from), oC = other.get(to)
296
+ const same = sameContent(bC, oC)
297
+ const bB = byteLen(bC), oB = same ? bB : byteLen(oC)
298
+ onlyBaseBytes -= bB
299
+ onlyOtherBytes -= oB
300
+ changed.push({ path: to, renamedFrom: from, basePath: baseFile.get(from), baseBytes: bB, otherBytes: oB, delta: oB - bB, modified: !same, ...recorded(baseFile.get(from), to) })
301
+ changedDelta += oB - bB
302
+ // Both in one package (its key is in the rename's).
303
+ const acc = pkgAcc(from)
304
+ acc.onlyBaseFiles--
305
+ acc.onlyOtherFiles--
306
+ acc.changedFiles++
307
+ }
308
+ onlyBase.splice(0, onlyBase.length, ...onlyBase.filter(row => !renames.has(row.path)))
309
+ onlyOther.splice(0, onlyOther.length, ...onlyOther.filter(row => !renamedTo.has(row.path)))
310
+ }
311
+
312
+ // Classify each package from its accumulator: present on exactly one
313
+ // side → onlyBase / onlyOther; present on both with any moved file →
314
+ // changed; otherwise unchanged (dropped — the lists surface only
315
+ // what differs).
316
+ const pkgOnlyBase = []
317
+ const pkgOnlyOther = []
318
+ const pkgChanged = []
319
+ const pkgUnchanged = []
320
+ for (const [pkg, acc] of pkgs) {
321
+ // Present on a side if any of its files contributed there — its
322
+ // byte total, an only-this-side file, or a changed file (which
323
+ // exists on both). A changed file alone is enough to count as
324
+ // present even when that side's bytes net to zero.
325
+ const onBase = acc.baseBytes > 0 || acc.onlyBaseFiles > 0 || acc.changedFiles > 0
326
+ const onOther = acc.otherBytes > 0 || acc.onlyOtherFiles > 0 || acc.changedFiles > 0
327
+ const movedFiles = acc.onlyBaseFiles + acc.onlyOtherFiles + acc.changedFiles
328
+ if (onBase && !onOther) {
329
+ pkgOnlyBase.push({ pkg, bytes: acc.baseBytes })
330
+ } else if (onOther && !onBase) {
331
+ pkgOnlyOther.push({ pkg, bytes: acc.otherBytes })
332
+ } else if (movedFiles > 0 || acc.baseBytes !== acc.otherBytes) {
333
+ pkgChanged.push({
334
+ pkg,
335
+ baseBytes: acc.baseBytes,
336
+ otherBytes: acc.otherBytes,
337
+ delta: acc.otherBytes - acc.baseBytes,
338
+ })
339
+ } else {
340
+ pkgUnchanged.push({ pkg, bytes: acc.baseBytes })
341
+ }
342
+ }
343
+
344
+ onlyBase.sort(byBytesThenKey('path'))
345
+ onlyOther.sort(byBytesThenKey('path'))
346
+ changed.sort(byAbsDeltaThenKey('path'))
347
+ pkgOnlyBase.sort(byBytesThenKey('pkg'))
348
+ pkgOnlyOther.sort(byBytesThenKey('pkg'))
349
+ pkgChanged.sort(byAbsDeltaThenKey('pkg'))
350
+
351
+ return {
352
+ totals: {
353
+ baseFiles: base.size,
354
+ baseBytes,
355
+ otherFiles: other.size,
356
+ otherBytes,
357
+ onlyBaseFiles: onlyBase.length,
358
+ onlyBaseBytes,
359
+ onlyOtherFiles: onlyOther.length,
360
+ onlyOtherBytes,
361
+ changedFiles: changed.length,
362
+ renamedFiles: renames.size,
363
+ changedDelta,
364
+ unchangedFiles,
365
+ fileDelta: other.size - base.size,
366
+ byteDelta: otherBytes - baseBytes,
367
+ identical: onlyBase.length === 0 && onlyOther.length === 0 && changed.length === 0,
368
+ },
369
+ files: { onlyBase, onlyOther, changed, root, basePaths },
370
+ // `unchanged` lends a version-only change its (equal) sizes.
371
+ packages: { onlyBase: pkgOnlyBase, onlyOther: pkgOnlyOther, changed: pkgChanged, unchanged: pkgUnchanged },
372
+ }
373
+ }
374
+
375
+ // The versions' part (bundle-compare-versions.js), as one comparison reads it.
376
+ export { comparePackages, compareSemver, computeVersionUpdates, versionDirection } from './bundle-compare-versions.js'
@@ -0,0 +1,3 @@
1
+ import type { BundleDetails } from './bundle-metadata.js'
2
+ export function bundleCompareFiles(details: BundleDetails, scope?: string | null): Map<string, unknown>
3
+ export function bundleCompareSideScopes(base: BundleDetails, other: BundleDetails, scope?: string | null): [string, string]
@@ -0,0 +1,141 @@
1
+ import { bundleFilesAsMap } from './bundle-sources.js'
2
+
3
+ // A side's files, and the named trees holding any of them, with those they hold.
4
+ function namedTrees(details) {
5
+ const files = bundleFilesAsMap(details), trees = new Map()
6
+ for (const [name, paths] of Object.entries(details?.bundle?.reason ?? {})) {
7
+ const present = new Set(Array.isArray(paths) ? paths.filter(path => files.has(path)) : [])
8
+ if (present.size > 0) trees.set(name, present)
9
+ }
10
+ return { stasis: details?.kind === 'stasis', files, trees }
11
+ }
12
+
13
+ // Trees two sides name apart for the same files: a side naming the second of
14
+ // a pair and not the first, the other the first and not the second, has it
15
+ // compared as the first. A static build names the Metro bundle's `bundle:metro`
16
+ // and the rest `bundle`, as a capture names them `metro` and `run`: `bundle` is
17
+ // `run` only where `bundle:metro` is `metro`, on the same side.
18
+ const ALIASES = [['extra', 'add'], ['metro', 'bundle:metro']]
19
+ function aliased(sides) {
20
+ if (sides.length !== 2) return sides
21
+ const apart = (name, alias) => sides.find((side, i) => side.trees.has(alias) && !side.trees.has(name)
22
+ && sides[1 - i].trees.has(name) && !sides[1 - i].trees.has(alias))
23
+ const renames = sides.map(() => new Map())
24
+ for (const [name, alias] of ALIASES) {
25
+ const side = apart(name, alias)
26
+ if (side) renames[sides.indexOf(side)].set(alias, name)
27
+ }
28
+ const built = apart('metro', 'bundle:metro')
29
+ if (built && apart('run', 'bundle') === built) renames[sides.indexOf(built)].set('bundle', 'run')
30
+ // `actual`: the name a side gives a tree it is compared as another by.
31
+ return sides.map((side, i) => renames[i].size === 0 ? side : { ...side,
32
+ trees: new Map([...side.trees].map(([name, paths]) => [renames[i].get(name) ?? name, paths])),
33
+ actual: new Map([...renames[i]].map(([alias, name]) => [name, alias])) })
34
+ }
35
+
36
+ // The one tree of a stasis side naming every file it has (its own selector
37
+ // hidden, as common/bundle-reasons.js hides it), where no other side names it:
38
+ // such a side is compared within that tree under any of the others' trees.
39
+ function soleTree(side, sides) {
40
+ if (!side.stasis || side.trees.size !== 1) return null
41
+ const [[name, paths]] = side.trees
42
+ return paths.size === side.files.size && !sides.some(other => other !== side && other.trees.has(name)) ? name : null
43
+ }
44
+
45
+ // A side naming no tree, or one alone holding all its files.
46
+ const trivial = side => side.trees.size === 0 || (side.trees.size === 1 && [...side.trees.values()][0].size === side.files.size)
47
+
48
+ // A tree of each side the other names none of, compared with each other, as
49
+ // one scope: the same whichever side is the base, as a swap keeps it.
50
+ const PAIR = 'reasons:'
51
+ const pairScope = (first, second) => `${PAIR}${JSON.stringify([first, second].toSorted())}`
52
+ function pairOf(scope) {
53
+ if (!scope.startsWith(PAIR)) return null
54
+ try {
55
+ const pair = JSON.parse(scope.slice(PAIR.length))
56
+ return Array.isArray(pair) && pair.length === 2 && pair.every(name => typeof name === 'string') ? pair : null
57
+ } catch { return null }
58
+ }
59
+
60
+ // Use the union of named trees, each as its side is compared (aliased). A tree
61
+ // absent from one stasis bundle contains no files there; falling back to all
62
+ // files would invent additions/removals. A bundle that names no trees (a
63
+ // sourcemap) is compared whole under any of them, as is one whose sole tree
64
+ // holds all its files where the other names none of it (soleTree), its tree
65
+ // left out. Where neither side is trivial and each names a tree the other
66
+ // doesn't, the trees both name are offered, and each of the first side's own
67
+ // paired with each of the second's (pairScope), labelled from the first to the
68
+ // second. Unlike a single-bundle graph, retain a scope that includes every file
69
+ // on one side.
70
+ export function bundleCompareScopes(...details) {
71
+ const sides = aliased(details.map(namedTrees))
72
+ if (sides.length === 2 && !sides.some(trivial)) {
73
+ const [first, second] = sides.map(side => [...side.trees.keys()].toSorted())
74
+ const shared = first.filter(name => second.includes(name))
75
+ const [firstOwn, secondOwn] = [first, second].map(names => names.filter(name => !shared.includes(name)))
76
+ if (firstOwn.length > 0 && secondOwn.length > 0) {
77
+ return [...shared.map(name => ({ id: `reason:${name}`, label: name })),
78
+ ...firstOwn.flatMap(from => secondOwn.map(to => ({ id: pairScope(from, to), label: `${from} → ${to}` })))]
79
+ }
80
+ }
81
+ const scoped = sides.filter(side => soleTree(side, sides) === null)
82
+ const names = new Set(scoped.flatMap(side => [...side.trees.keys()]))
83
+ // A scope is only useful as a filter if it changes the files compared on
84
+ // some side. Keep every scope when at least one does, otherwise hide the
85
+ // selector, as single-bundle views do (see common/bundle-reasons.js).
86
+ const narrows = name => scoped.some(side => side.stasis && (side.trees.get(name)?.size ?? 0) < side.files.size)
87
+ if (![...names].some(narrows)) return []
88
+ return [...names].toSorted().map(name => ({ id: `reason:${name}`, label: name }))
89
+ }
90
+
91
+ // Each side's scope in a comparison within `scope`: within the tree of a pair
92
+ // (pairScope) it names; a side whose sole tree holds all its files, the other
93
+ // naming none of it (soleTree), within that tree; each within the tree it
94
+ // names as it is compared (aliased).
95
+ export function bundleCompareSideScopes(base, other, scope = '') {
96
+ if (!scope) return ['', '']
97
+ const pair = pairOf(scope), sides = aliased([base, other].map(namedTrees))
98
+ const named = scope.startsWith('reason:') ? scope.slice('reason:'.length) : null
99
+ return sides.map(side => {
100
+ const name = pair ? pair.find(tree => side.trees.has(tree)) : soleTree(side, sides) ?? named
101
+ return name == null ? scope : `reason:${side.actual?.get(name) ?? name}`
102
+ })
103
+ }
104
+
105
+ export function bundleCompareFiles(details, scope = '') {
106
+ const files = bundleFilesAsMap(details)
107
+ if (!scope || details?.kind !== 'stasis') return files
108
+ const paths = details?.bundle?.reason?.[scope.replace(/^reason:/u, '')]
109
+ const selected = new Set(Array.isArray(paths) ? paths : [])
110
+ return new Map([...files].filter(([path]) => selected.has(path)))
111
+ }
112
+
113
+ // A resolution's identity: its importer, specifier, conditions (import
114
+ // attributes included), and Metro platform.
115
+ export function resolutionKey(parent, specifier, conditions, platform) {
116
+ return JSON.stringify([parent, specifier, conditions, platform])
117
+ }
118
+
119
+ // Keep the full resolution identity: collapsing to graph edges would lose
120
+ // specifier, condition/import-attribute, and Metro platform changes.
121
+ export function bundleCompareResolutions(details, scope = '') {
122
+ const result = new Map()
123
+ if (details?.kind !== 'stasis' || !details.bundle) return result
124
+ const files = scope ? bundleFilesAsMap(details) : null
125
+ const selected = scope ? bundleCompareFiles(details, scope) : null
126
+ for (const [conditions, byParent] of details.bundle.imports) {
127
+ for (const [parent, specifiers] of byParent) {
128
+ for (const [specifier, resolved] of specifiers) {
129
+ const targets = typeof resolved === 'string' ? [[null, resolved]] : resolved
130
+ for (const [platform, target] of targets) {
131
+ // Include imports from scoped files, plus imports into the scope
132
+ // from uncaptured parents (e.g. an app in a dependencies-only bundle).
133
+ if (selected && !selected.has(parent) && (files.has(parent) || !selected.has(target))) continue
134
+ const key = resolutionKey(parent, specifier, conditions, platform)
135
+ result.set(key, { key, parent, specifier, conditions, platform, target })
136
+ }
137
+ }
138
+ }
139
+ }
140
+ return result
141
+ }