repometry 0.0.0-stage → 0.2.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 (274) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +28 -2
  3. package/package.json +64 -4
  4. package/target/main/resources/report/json/compact-json-v1.schema.json +24 -0
  5. package/target/main/resources/report/json/comparison-v1.schema.json +65 -0
  6. package/target/main/resources/report/json/config-v1.schema.json +33 -0
  7. package/target/main/resources/report/json/diff-coverage-v1.schema.json +55 -0
  8. package/target/main/resources/report/json/file-metrics-v1.schema.json +134 -0
  9. package/target/main/resources/report/json/inspection-context-v1.schema.json +172 -0
  10. package/target/main/resources/report/json/metabranch-v1.schema.json +9 -0
  11. package/target/main/resources/report/json/metric-catalog-v1.schema.json +31 -0
  12. package/target/main/resources/report/json/public-history-v1.schema.json +50 -0
  13. package/target/main/resources/report/json/pull-review-v1.schema.json +97 -0
  14. package/target/main/resources/report/json/quality-history-v1.schema.json +51 -0
  15. package/target/main/resources/report/json/report-v1.schema.json +65 -0
  16. package/target/main/resources/report/json/report-v2.schema.json +252 -0
  17. package/target/main/resources/report/json/repository-summary-v1.schema.json +181 -0
  18. package/target/main/resources/report/json/viewer-details-v1.schema.json +343 -0
  19. package/target/main/resources/report/json/viewer-inspection-v1.schema.json +13 -0
  20. package/target/main/resources/viewer/files.css +578 -0
  21. package/target/main/resources/viewer/index.html +120 -0
  22. package/target/main/resources/viewer/projects.html +52 -0
  23. package/target/main/resources/viewer/styles.css +560 -0
  24. package/target/main/resources/viewer/viewer-pulls.css +64 -0
  25. package/target/main/ts/api/gh/github.d.ts +6 -0
  26. package/target/main/ts/api/gh/github.js +92 -0
  27. package/target/main/ts/api/git/blob-batch.d.ts +10 -0
  28. package/target/main/ts/api/git/blob-batch.js +106 -0
  29. package/target/main/ts/api/git/changes.d.ts +22 -0
  30. package/target/main/ts/api/git/changes.js +108 -0
  31. package/target/main/ts/api/git/commit-metadata.d.ts +3 -0
  32. package/target/main/ts/api/git/commit-metadata.js +53 -0
  33. package/target/main/ts/api/git/git-churn.d.ts +9 -0
  34. package/target/main/ts/api/git/git-churn.js +71 -0
  35. package/target/main/ts/api/git/git-reader.d.ts +16 -0
  36. package/target/main/ts/api/git/git-reader.js +74 -0
  37. package/target/main/ts/api/git/git.d.ts +21 -0
  38. package/target/main/ts/api/git/git.js +153 -0
  39. package/target/main/ts/api/git/inspection-source.d.ts +15 -0
  40. package/target/main/ts/api/git/inspection-source.js +31 -0
  41. package/target/main/ts/api/git/local-sources.d.ts +5 -0
  42. package/target/main/ts/api/git/local-sources.js +47 -0
  43. package/target/main/ts/api/git/local.d.ts +3 -0
  44. package/target/main/ts/api/git/local.js +36 -0
  45. package/target/main/ts/api/git/metabranch-worktree.d.ts +1 -0
  46. package/target/main/ts/api/git/metabranch-worktree.js +35 -0
  47. package/target/main/ts/api/git/source-cache.d.ts +3 -0
  48. package/target/main/ts/api/git/source-cache.js +57 -0
  49. package/target/main/ts/api/import/finding-import.d.ts +9 -0
  50. package/target/main/ts/api/import/finding-import.js +227 -0
  51. package/target/main/ts/api/import/lcov-files.d.ts +5 -0
  52. package/target/main/ts/api/import/lcov-files.js +14 -0
  53. package/target/main/ts/api/import/profile-file.d.ts +4 -0
  54. package/target/main/ts/api/import/profile-file.js +17 -0
  55. package/target/main/ts/api/worker/remote-executor.d.ts +2 -0
  56. package/target/main/ts/api/worker/remote-executor.js +46 -0
  57. package/target/main/ts/api/worker/worker-protocol.d.ts +7 -0
  58. package/target/main/ts/api/worker/worker-protocol.js +102 -0
  59. package/target/main/ts/api/worker/worker.d.ts +5 -0
  60. package/target/main/ts/api/worker/worker.js +86 -0
  61. package/target/main/ts/cli/arguments.d.ts +28 -0
  62. package/target/main/ts/cli/arguments.js +111 -0
  63. package/target/main/ts/cli/config.d.ts +13 -0
  64. package/target/main/ts/cli/config.js +58 -0
  65. package/target/main/ts/cli/imports.d.ts +7 -0
  66. package/target/main/ts/cli/imports.js +30 -0
  67. package/target/main/ts/cli/main.d.ts +2 -0
  68. package/target/main/ts/cli/main.js +379 -0
  69. package/target/main/ts/cli/reporting.d.ts +18 -0
  70. package/target/main/ts/cli/reporting.js +104 -0
  71. package/target/main/ts/cli/revisions.d.ts +6 -0
  72. package/target/main/ts/cli/revisions.js +16 -0
  73. package/target/main/ts/cli/store.d.ts +13 -0
  74. package/target/main/ts/cli/store.js +39 -0
  75. package/target/main/ts/compose/analyze-snapshot.d.ts +4 -0
  76. package/target/main/ts/compose/analyze-snapshot.js +164 -0
  77. package/target/main/ts/compose/attach-churn.d.ts +2 -0
  78. package/target/main/ts/compose/attach-churn.js +50 -0
  79. package/target/main/ts/compose/diff-coverage.d.ts +20 -0
  80. package/target/main/ts/compose/diff-coverage.js +57 -0
  81. package/target/main/ts/compose/inspect.d.ts +23 -0
  82. package/target/main/ts/compose/inspect.js +45 -0
  83. package/target/main/ts/compose/plugin-list.d.ts +6 -0
  84. package/target/main/ts/compose/plugin-list.js +10 -0
  85. package/target/main/ts/compose/prepare-metabranch.d.ts +9 -0
  86. package/target/main/ts/compose/prepare-metabranch.js +17 -0
  87. package/target/main/ts/compose/review.d.ts +16 -0
  88. package/target/main/ts/compose/review.js +39 -0
  89. package/target/main/ts/compose/sources.d.ts +3 -0
  90. package/target/main/ts/compose/sources.js +30 -0
  91. package/target/main/ts/core/engine/execute.d.ts +10 -0
  92. package/target/main/ts/core/engine/execute.js +50 -0
  93. package/target/main/ts/core/engine/manifest.d.ts +4 -0
  94. package/target/main/ts/core/engine/manifest.js +105 -0
  95. package/target/main/ts/core/engine/plan.d.ts +22 -0
  96. package/target/main/ts/core/engine/plan.js +107 -0
  97. package/target/main/ts/core/engine/plugin.d.ts +59 -0
  98. package/target/main/ts/core/engine/plugin.js +4 -0
  99. package/target/main/ts/core/engine/report-products.d.ts +16 -0
  100. package/target/main/ts/core/engine/report-products.js +86 -0
  101. package/target/main/ts/core/model/changes.d.ts +8 -0
  102. package/target/main/ts/core/model/changes.js +2 -0
  103. package/target/main/ts/core/model/churn.d.ts +11 -0
  104. package/target/main/ts/core/model/churn.js +5 -0
  105. package/target/main/ts/core/model/clone-source.d.ts +16 -0
  106. package/target/main/ts/core/model/clone-source.js +15 -0
  107. package/target/main/ts/core/model/code-structure.d.ts +30 -0
  108. package/target/main/ts/core/model/code-structure.js +32 -0
  109. package/target/main/ts/core/model/comparison.d.ts +24 -0
  110. package/target/main/ts/core/model/comparison.js +1 -0
  111. package/target/main/ts/core/model/diff-coverage.d.ts +23 -0
  112. package/target/main/ts/core/model/diff-coverage.js +1 -0
  113. package/target/main/ts/core/model/finding-ignore.d.ts +8 -0
  114. package/target/main/ts/core/model/finding-ignore.js +36 -0
  115. package/target/main/ts/core/model/finding.d.ts +28 -0
  116. package/target/main/ts/core/model/finding.js +29 -0
  117. package/target/main/ts/core/model/ignore-rule.d.ts +11 -0
  118. package/target/main/ts/core/model/ignore-rule.js +1 -0
  119. package/target/main/ts/core/model/measurement.d.ts +33 -0
  120. package/target/main/ts/core/model/measurement.js +30 -0
  121. package/target/main/ts/core/model/metric-descriptor.d.ts +17 -0
  122. package/target/main/ts/core/model/metric-descriptor.js +1 -0
  123. package/target/main/ts/core/model/plugin-data.d.ts +25 -0
  124. package/target/main/ts/core/model/plugin-data.js +1 -0
  125. package/target/main/ts/core/model/pull-review.d.ts +48 -0
  126. package/target/main/ts/core/model/pull-review.js +1 -0
  127. package/target/main/ts/core/model/quality-summary.d.ts +42 -0
  128. package/target/main/ts/core/model/quality-summary.js +64 -0
  129. package/target/main/ts/core/model/report.d.ts +40 -0
  130. package/target/main/ts/core/model/report.js +5 -0
  131. package/target/main/ts/core/model/scanner-import.d.ts +39 -0
  132. package/target/main/ts/core/model/scanner-import.js +29 -0
  133. package/target/main/ts/core/model/snapshot.d.ts +15 -0
  134. package/target/main/ts/core/model/snapshot.js +51 -0
  135. package/target/main/ts/core/model/source-locator.d.ts +7 -0
  136. package/target/main/ts/core/model/source-locator.js +1 -0
  137. package/target/main/ts/core/model/source.d.ts +23 -0
  138. package/target/main/ts/core/model/source.js +1 -0
  139. package/target/main/ts/core/ports/report.d.ts +9 -0
  140. package/target/main/ts/core/ports/report.js +2 -0
  141. package/target/main/ts/core/ports/source-provider.d.ts +14 -0
  142. package/target/main/ts/core/ports/source-provider.js +5 -0
  143. package/target/main/ts/core/profile/exclusions.d.ts +11 -0
  144. package/target/main/ts/core/profile/exclusions.js +58 -0
  145. package/target/main/ts/core/profile/maintainability.d.ts +31 -0
  146. package/target/main/ts/core/profile/maintainability.js +10 -0
  147. package/target/main/ts/core/profile/profile.d.ts +4 -0
  148. package/target/main/ts/core/profile/profile.js +11 -0
  149. package/target/main/ts/core/usecases/compare.d.ts +6 -0
  150. package/target/main/ts/core/usecases/compare.js +146 -0
  151. package/target/main/ts/core/usecases/diff-coverage-policy.d.ts +6 -0
  152. package/target/main/ts/core/usecases/diff-coverage-policy.js +11 -0
  153. package/target/main/ts/core/usecases/diff-coverage.d.ts +40 -0
  154. package/target/main/ts/core/usecases/diff-coverage.js +16 -0
  155. package/target/main/ts/core/usecases/inspect.d.ts +38 -0
  156. package/target/main/ts/core/usecases/inspect.js +42 -0
  157. package/target/main/ts/core/usecases/review.d.ts +31 -0
  158. package/target/main/ts/core/usecases/review.js +129 -0
  159. package/target/main/ts/index.d.ts +35 -0
  160. package/target/main/ts/index.js +18 -0
  161. package/target/main/ts/plugin.d.ts +14 -0
  162. package/target/main/ts/plugin.js +6 -0
  163. package/target/main/ts/plugins/coverage/coverage.d.ts +25 -0
  164. package/target/main/ts/plugins/coverage/coverage.js +199 -0
  165. package/target/main/ts/plugins/coverage/diff-coverage.d.ts +7 -0
  166. package/target/main/ts/plugins/coverage/diff-coverage.js +90 -0
  167. package/target/main/ts/plugins/duplication/duplication.d.ts +4 -0
  168. package/target/main/ts/plugins/duplication/duplication.js +94 -0
  169. package/target/main/ts/plugins/language-js/babel-provider.d.ts +10 -0
  170. package/target/main/ts/plugins/language-js/babel-provider.js +47 -0
  171. package/target/main/ts/plugins/language-js/clone-candidates.d.ts +3 -0
  172. package/target/main/ts/plugins/language-js/clone-candidates.js +65 -0
  173. package/target/main/ts/plugins/language-js/code-lines.d.ts +6 -0
  174. package/target/main/ts/plugins/language-js/code-lines.js +36 -0
  175. package/target/main/ts/plugins/language-js/function-facts.d.ts +8 -0
  176. package/target/main/ts/plugins/language-js/function-facts.js +61 -0
  177. package/target/main/ts/plugins/language-js/structural-observations.d.ts +8 -0
  178. package/target/main/ts/plugins/language-js/structural-observations.js +80 -0
  179. package/target/main/ts/plugins/maintainability/maintainability.d.ts +9 -0
  180. package/target/main/ts/plugins/maintainability/maintainability.js +43 -0
  181. package/target/main/ts/plugins/maintainability/structural-smells.d.ts +3 -0
  182. package/target/main/ts/plugins/maintainability/structural-smells.js +16 -0
  183. package/target/main/ts/plugins/source/forges.d.ts +4 -0
  184. package/target/main/ts/plugins/source/forges.js +80 -0
  185. package/target/main/ts/plugins/structure/structure.d.ts +2 -0
  186. package/target/main/ts/plugins/structure/structure.js +38 -0
  187. package/target/main/ts/report/html/app/viewer-chart.d.ts +101 -0
  188. package/target/main/ts/report/html/app/viewer-chart.js +711 -0
  189. package/target/main/ts/report/html/app/viewer-commits.d.ts +36 -0
  190. package/target/main/ts/report/html/app/viewer-commits.js +280 -0
  191. package/target/main/ts/report/html/app/viewer-data.d.ts +23 -0
  192. package/target/main/ts/report/html/app/viewer-data.js +105 -0
  193. package/target/main/ts/report/html/app/viewer-files.d.ts +117 -0
  194. package/target/main/ts/report/html/app/viewer-files.js +2104 -0
  195. package/target/main/ts/report/html/app/viewer-filter.d.ts +113 -0
  196. package/target/main/ts/report/html/app/viewer-filter.js +492 -0
  197. package/target/main/ts/report/html/app/viewer-metric-registry.d.ts +70 -0
  198. package/target/main/ts/report/html/app/viewer-metric-registry.js +224 -0
  199. package/target/main/ts/report/html/app/viewer-metrics.d.ts +44 -0
  200. package/target/main/ts/report/html/app/viewer-metrics.js +172 -0
  201. package/target/main/ts/report/html/app/viewer-profile.d.ts +17 -0
  202. package/target/main/ts/report/html/app/viewer-profile.js +401 -0
  203. package/target/main/ts/report/html/app/viewer-projects.d.ts +1 -0
  204. package/target/main/ts/report/html/app/viewer-projects.js +90 -0
  205. package/target/main/ts/report/html/app/viewer-pulls.d.ts +3 -0
  206. package/target/main/ts/report/html/app/viewer-pulls.js +242 -0
  207. package/target/main/ts/report/html/app/viewer-source.d.ts +75 -0
  208. package/target/main/ts/report/html/app/viewer-source.js +313 -0
  209. package/target/main/ts/report/html/app/viewer-trends.d.ts +73 -0
  210. package/target/main/ts/report/html/app/viewer-trends.js +423 -0
  211. package/target/main/ts/report/html/app/viewer.d.ts +1 -0
  212. package/target/main/ts/report/html/app/viewer.js +735 -0
  213. package/target/main/ts/report/html/site/badges.d.ts +14 -0
  214. package/target/main/ts/report/html/site/badges.js +40 -0
  215. package/target/main/ts/report/html/site/export-site.d.ts +22 -0
  216. package/target/main/ts/report/html/site/export-site.js +150 -0
  217. package/target/main/ts/report/html/site/exported-server.d.ts +6 -0
  218. package/target/main/ts/report/html/site/exported-server.js +71 -0
  219. package/target/main/ts/report/html/site/local-server.d.ts +7 -0
  220. package/target/main/ts/report/html/site/local-server.js +65 -0
  221. package/target/main/ts/report/html/site/projects.d.ts +3 -0
  222. package/target/main/ts/report/html/site/projects.js +80 -0
  223. package/target/main/ts/report/html/site/server.d.ts +4 -0
  224. package/target/main/ts/report/html/site/server.js +65 -0
  225. package/target/main/ts/report/html/site/source-route.d.ts +6 -0
  226. package/target/main/ts/report/html/site/source-route.js +23 -0
  227. package/target/main/ts/report/json/projections/commit-summary.d.ts +12 -0
  228. package/target/main/ts/report/json/projections/commit-summary.js +124 -0
  229. package/target/main/ts/report/json/projections/components.d.ts +4 -0
  230. package/target/main/ts/report/json/projections/components.js +30 -0
  231. package/target/main/ts/report/json/projections/file-metrics.d.ts +5 -0
  232. package/target/main/ts/report/json/projections/file-metrics.js +244 -0
  233. package/target/main/ts/report/json/projections/inspection-context.d.ts +6 -0
  234. package/target/main/ts/report/json/projections/inspection-context.js +93 -0
  235. package/target/main/ts/report/json/projections/inspection-details.d.ts +11 -0
  236. package/target/main/ts/report/json/projections/inspection-details.js +70 -0
  237. package/target/main/ts/report/json/projections/metric-values.d.ts +7 -0
  238. package/target/main/ts/report/json/projections/metric-values.js +58 -0
  239. package/target/main/ts/report/json/projections/public-history.d.ts +4 -0
  240. package/target/main/ts/report/json/projections/public-history.js +17 -0
  241. package/target/main/ts/report/json/store/components.d.ts +2 -0
  242. package/target/main/ts/report/json/store/components.js +32 -0
  243. package/target/main/ts/report/json/store/local-store.d.ts +13 -0
  244. package/target/main/ts/report/json/store/local-store.js +180 -0
  245. package/target/main/ts/report/json/store/pull-review-store.d.ts +3 -0
  246. package/target/main/ts/report/json/store/pull-review-store.js +52 -0
  247. package/target/main/ts/report/json/validation/metabranch.d.ts +4 -0
  248. package/target/main/ts/report/json/validation/metabranch.js +8 -0
  249. package/target/main/ts/report/json/validation/report.d.ts +15 -0
  250. package/target/main/ts/report/json/validation/report.js +65 -0
  251. package/target/main/ts/report/json/validation/summary-validation.d.ts +4 -0
  252. package/target/main/ts/report/json/validation/summary-validation.js +28 -0
  253. package/target/main/ts/report/json/wire/compact-json.d.ts +11 -0
  254. package/target/main/ts/report/json/wire/compact-json.js +76 -0
  255. package/target/main/ts/report/json/wire/component-model.d.ts +9 -0
  256. package/target/main/ts/report/json/wire/component-model.js +1 -0
  257. package/target/main/ts/report/json/wire/domain-types.d.ts +2 -0
  258. package/target/main/ts/report/json/wire/domain-types.js +1 -0
  259. package/target/main/ts/report/json/wire/file-metrics-model.d.ts +77 -0
  260. package/target/main/ts/report/json/wire/file-metrics-model.js +1 -0
  261. package/target/main/ts/report/json/wire/inspection-context-model.d.ts +26 -0
  262. package/target/main/ts/report/json/wire/inspection-context-model.js +1 -0
  263. package/target/main/ts/report/json/wire/inspection-details-model.d.ts +82 -0
  264. package/target/main/ts/report/json/wire/inspection-details-model.js +1 -0
  265. package/target/main/ts/report/json/wire/project-model.d.ts +7 -0
  266. package/target/main/ts/report/json/wire/project-model.js +1 -0
  267. package/target/main/ts/report/json/wire/public-history-model.d.ts +42 -0
  268. package/target/main/ts/report/json/wire/public-history-model.js +6 -0
  269. package/target/main/ts/report/json/wire/pull-review-model.d.ts +7 -0
  270. package/target/main/ts/report/json/wire/pull-review-model.js +1 -0
  271. package/target/main/ts/report/json/wire/summary-model.d.ts +45 -0
  272. package/target/main/ts/report/json/wire/summary-model.js +1 -0
  273. package/target/main/ts/report.d.ts +11 -0
  274. package/target/main/ts/report.js +6 -0
@@ -0,0 +1,153 @@
1
+ import { realpath } from 'node:fs/promises';
2
+ import { execFile, spawnSync } from 'node:child_process';
3
+ import { promisify } from 'node:util';
4
+ import { comparePaths, isExcludedDirectory, isSourcePath, textLineCount, utf8 } from '../../core/model/snapshot.js';
5
+ import { isGeneratedSource } from '../../core/profile/exclusions.js';
6
+ const git = promisify(execFile);
7
+ const maxBuffer = 64 * 1024 * 1024;
8
+ const oidPattern = /^(?:[a-f0-9]{40}|[a-f0-9]{64})$/;
9
+ const env = { ...process.env, GIT_NO_LAZY_FETCH: '1' };
10
+ export async function gitRoot(directory) {
11
+ try {
12
+ return (await gitText(directory, ['rev-parse', '--show-toplevel'])).replace(/\r?\n$/, '');
13
+ }
14
+ catch (error) {
15
+ const detail = error instanceof Error ? error.message : String(error);
16
+ const reason = `${directory} is not a Git repository`;
17
+ throw new Error(process.env.REPOMETRY_DEBUG === '1' ? `${reason}\n${detail}` : reason, { cause: error });
18
+ }
19
+ }
20
+ export async function physicalGitRoot(directory) {
21
+ return realpath(await gitRoot(directory));
22
+ }
23
+ export async function gitText(directory, args, timeout) {
24
+ const { stdout } = await git('git', ['--no-replace-objects', ...args], { cwd: directory, env, maxBuffer, timeout });
25
+ return stdout;
26
+ }
27
+ export async function gitUtf8(directory, args, timeout) {
28
+ const result = await git('git', ['--no-replace-objects', ...args], { cwd: directory, env, encoding: 'buffer', maxBuffer, timeout });
29
+ return utf8(result.stdout);
30
+ }
31
+ export async function resolveGitCommit(directory, revision) {
32
+ let output;
33
+ try {
34
+ output = await gitText(directory, ['rev-parse', '--verify', '--end-of-options', `${revision}^{commit}`]);
35
+ }
36
+ catch (error) {
37
+ const detail = error instanceof Error ? error.message : String(error);
38
+ const reason = /not a git repository/i.test(detail) ? `${directory} is not a Git repository` : `${revision} is not a commit in ${directory}`;
39
+ throw new Error(process.env.REPOMETRY_DEBUG === '1' ? `${reason}\n${detail}` : reason, { cause: error });
40
+ }
41
+ const id = output.trim();
42
+ if (!oidPattern.test(id))
43
+ throw new Error('Git returned an invalid commit ID');
44
+ return id;
45
+ }
46
+ /** Commits on the first-parent line of `head` after `base`, oldest first. */
47
+ export async function firstParentRange(directory, base, head) {
48
+ const [from, to] = await Promise.all([resolveGitCommit(directory, base), resolveGitCommit(directory, head)]);
49
+ const commits = (await gitText(directory, ['rev-list', '--first-parent', '--reverse', `${from}..${to}`])).split('\n').filter(Boolean);
50
+ if (!commits.every(id => oidPattern.test(id)))
51
+ throw new Error('Git returned an invalid commit ID');
52
+ return { base: from, head: to, commits };
53
+ }
54
+ export async function gitTreeFiles(directory, commit, prefix, includeSize = false) {
55
+ if (!oidPattern.test(commit))
56
+ throw new Error('A full commit object ID is required');
57
+ const args = ['--no-replace-objects', '--literal-pathspecs', 'ls-tree', '-r', '-z', '--full-tree'];
58
+ if (includeSize)
59
+ args.push('--long');
60
+ args.push(commit);
61
+ if (prefix !== undefined)
62
+ args.push('--', prefix);
63
+ const tree = await git('git', args, { cwd: directory, env, encoding: 'buffer', maxBuffer });
64
+ const entries = [];
65
+ for (const entry of utf8(tree.stdout).split('\0')) {
66
+ if (!entry)
67
+ continue;
68
+ const tab = entry.indexOf('\t');
69
+ const header = entry.slice(0, tab);
70
+ const match = /^100(?:644|755) blob ([a-f0-9]+)(?: +([0-9]+|-))?$/.exec(header);
71
+ const oid = match?.[1];
72
+ const path = entry.slice(tab + 1);
73
+ const size = Number(match?.[2]);
74
+ if (oid && oidPattern.test(oid))
75
+ entries.push({ path, oid, ...(Number.isSafeInteger(size) ? { size } : {}) });
76
+ }
77
+ return entries;
78
+ }
79
+ export async function gitBlobText(directory, oid) {
80
+ if (!oidPattern.test(oid))
81
+ throw new Error('A full blob object ID is required');
82
+ const result = await git('git', ['--no-replace-objects', 'cat-file', 'blob', oid], { cwd: directory, env, encoding: 'buffer', maxBuffer });
83
+ return utf8(result.stdout);
84
+ }
85
+ export async function readGitCommit(directory, revision, excludes) {
86
+ const id = await resolveGitCommit(directory, revision);
87
+ const tracked = (await gitTreeFiles(directory, id, undefined, true)).filter(({ path }) => !path.split('/').slice(0, -1).some(isExcludedDirectory) && !excludes(path));
88
+ const entries = tracked.filter(entry => isSourcePath(entry.path));
89
+ const blobs = readBlobs(directory, [...new Set(entries.map(entry => entry.oid))]);
90
+ const generated = new Set();
91
+ const files = entries.flatMap(({ path, oid }) => {
92
+ const bytes = blobs.get(oid);
93
+ if (!bytes)
94
+ throw new Error(`Git blob unavailable: ${oid}`);
95
+ if (!isGeneratedSource(bytes))
96
+ return [{ path, bytes }];
97
+ generated.add(path);
98
+ return [];
99
+ });
100
+ files.sort((left, right) => comparePaths(left.path, right.path));
101
+ const counts = inventoryLineCounts(directory, tracked, blobs);
102
+ const inventory = tracked.filter(({ path }) => !generated.has(path)).map(({ path, oid, size }) => ({ path, lines: counts.get(oid) ?? null, ...(size === undefined ? {} : { bytes: size }) }));
103
+ return { subject: { kind: 'commit', id }, files, inventory, generatedExcluded: [...generated].sort(comparePaths) };
104
+ }
105
+ function inventoryLineCounts(directory, entries, sources) {
106
+ const lines = new Map([...sources].map(([oid, value]) => [oid, textLineCount(value)]));
107
+ const entriesById = new Map(entries.map(entry => [entry.oid, entry]));
108
+ let batch = [];
109
+ let bytes = 0;
110
+ for (const [oid, { size }] of entriesById) {
111
+ if (lines.has(oid) || size === undefined || size + 128 > maxBuffer)
112
+ continue;
113
+ const estimate = size + 128;
114
+ if (bytes + estimate > maxBuffer)
115
+ flush();
116
+ batch.push(oid);
117
+ bytes += estimate;
118
+ }
119
+ flush();
120
+ return lines;
121
+ function flush() {
122
+ for (const [oid, value] of readBlobs(directory, batch))
123
+ lines.set(oid, textLineCount(value));
124
+ batch = [];
125
+ bytes = 0;
126
+ }
127
+ }
128
+ function readBlobs(directory, ids) {
129
+ const blobs = new Map();
130
+ if (ids.length === 0)
131
+ return blobs;
132
+ const result = spawnSync('git', ['--no-replace-objects', 'cat-file', '--batch'], { cwd: directory, env, input: `${ids.join('\n')}\n`, maxBuffer });
133
+ if (result.error)
134
+ throw result.error;
135
+ if (result.status !== 0)
136
+ throw new Error(`git cat-file failed: ${result.stderr.toString('utf8').trim()}`);
137
+ let cursor = 0;
138
+ for (const oid of ids) {
139
+ const end = result.stdout.indexOf(10, cursor);
140
+ if (end < 0)
141
+ throw new Error(`Missing Git blob header: ${oid}`);
142
+ const match = /^([a-f0-9]+) blob (\d+)$/.exec(result.stdout.toString('ascii', cursor, end));
143
+ const size = Number(match?.[2]);
144
+ const from = end + 1;
145
+ const to = from + size;
146
+ if (match?.[1] !== oid || !Number.isSafeInteger(size) || result.stdout[to] !== 10)
147
+ throw new Error(`Invalid Git blob: ${oid}`);
148
+ blobs.set(oid, result.stdout.subarray(from, to));
149
+ cursor = to + 1;
150
+ }
151
+ return blobs;
152
+ }
153
+ //# sourceMappingURL=git.js.map
@@ -0,0 +1,15 @@
1
+ export interface SourceSelection {
2
+ readonly directory: string;
3
+ readonly output: string;
4
+ readonly source: {
5
+ readonly workingTree: true;
6
+ } | {
7
+ readonly revision: string;
8
+ };
9
+ }
10
+ export declare function readInspectionSource(request: SourceSelection, excludes: (path: string) => boolean): Promise<{
11
+ root: string;
12
+ snapshot: import("../../plugin.js").SourceSnapshot;
13
+ excludedOutput: string | null;
14
+ output: string;
15
+ }>;
@@ -0,0 +1,31 @@
1
+ import { realpath } from 'node:fs/promises';
2
+ import { basename, dirname, join, relative, resolve, sep } from 'node:path';
3
+ import { gitRoot, readGitCommit } from './git.js';
4
+ import { containsPath, readWorkingTree } from './local.js';
5
+ export async function readInspectionSource(request, excludes) {
6
+ const root = await realpath('workingTree' in request.source ? request.directory : await gitRoot(request.directory));
7
+ const output = await physicalPath(resolve(request.output));
8
+ if (containsPath(output, root) || output.split(sep).includes('.git')) {
9
+ throw new Error('Choose a dedicated report directory outside Git metadata');
10
+ }
11
+ const snapshot = 'workingTree' in request.source
12
+ ? await readWorkingTree(root, output, excludes)
13
+ : await readGitCommit(root, request.source.revision, excludes);
14
+ const excludedOutput = snapshot.subject.kind === 'working-tree' && containsPath(root, output)
15
+ ? relative(root, output).split(sep).join('/') : null;
16
+ return { root, snapshot, excludedOutput, output };
17
+ }
18
+ async function physicalPath(path) {
19
+ try {
20
+ return await realpath(path);
21
+ }
22
+ catch (error) {
23
+ if (!(error instanceof Error && 'code' in error && error.code === 'ENOENT'))
24
+ throw error;
25
+ const parent = dirname(path);
26
+ if (parent === path)
27
+ throw error;
28
+ return join(await physicalPath(parent), basename(path));
29
+ }
30
+ }
31
+ //# sourceMappingURL=inspection-source.js.map
@@ -0,0 +1,5 @@
1
+ export declare function readLocalSources(repository: string, cache?: string): {
2
+ read(revision: string, path: string, signal?: AbortSignal): Promise<Uint8Array | undefined>;
3
+ close: () => void;
4
+ };
5
+ export declare function sourceRemotes(repository: string): Promise<string[]>;
@@ -0,0 +1,47 @@
1
+ import { utf8 } from '../../core/model/snapshot.js';
2
+ import { validSubjectId } from '../../core/model/report.js';
3
+ import { isSourcePathname } from '../../core/ports/source-provider.js';
4
+ import { GitBlobBatch } from './blob-batch.js';
5
+ import { gitText, gitTreeFiles } from './git.js';
6
+ import { cachedBlob, sourceCacheRoot } from './source-cache.js';
7
+ export function readLocalSources(repository, cache = sourceCacheRoot()) {
8
+ const git = new GitBlobBatch(repository);
9
+ const known = new Map();
10
+ return {
11
+ async read(revision, path, signal) {
12
+ if (!validSubjectId('commit', revision) || !isSourcePathname(path))
13
+ return undefined;
14
+ const key = revision + '\0' + path;
15
+ let oid = known.get(key);
16
+ if (oid === undefined) {
17
+ oid = gitTreeFiles(repository, revision, path).then(entries => entries.find(entry => entry.path === path)?.oid).catch(error => {
18
+ known.delete(key);
19
+ if (error instanceof Error && 'code' in error && typeof error.code === 'number')
20
+ return undefined;
21
+ throw error;
22
+ });
23
+ known.set(key, oid);
24
+ }
25
+ const id = await oid;
26
+ if (!id)
27
+ return undefined;
28
+ signal?.throwIfAborted();
29
+ const bytes = await cachedBlob(cache, id, () => git.read(id, signal));
30
+ if (!bytes || bytes.includes(0))
31
+ return undefined;
32
+ try {
33
+ utf8(bytes);
34
+ return bytes;
35
+ }
36
+ catch {
37
+ return undefined;
38
+ }
39
+ },
40
+ close: () => git.close(),
41
+ };
42
+ }
43
+ export async function sourceRemotes(repository) {
44
+ const origins = await gitText(repository, ['remote', 'get-url', '--all', 'origin']).catch(() => '');
45
+ return origins.split(/\r?\n/).filter(Boolean);
46
+ }
47
+ //# sourceMappingURL=local-sources.js.map
@@ -0,0 +1,3 @@
1
+ import type { SourceSnapshot } from '../../core/model/snapshot.js';
2
+ export declare function containsPath(parent: string, path: string): boolean;
3
+ export declare function readWorkingTree(directory: string, output: string, excludes: (path: string) => boolean): Promise<SourceSnapshot>;
@@ -0,0 +1,36 @@
1
+ import { readdir, realpath, readFile } from 'node:fs/promises';
2
+ import { isAbsolute, join, relative, sep } from 'node:path';
3
+ import { comparePaths, isExcludedDirectory, isSourcePath, workingSnapshot } from '../../core/model/snapshot.js';
4
+ import { isGeneratedSource } from '../../core/profile/exclusions.js';
5
+ export function containsPath(parent, path) {
6
+ const rest = relative(parent, path);
7
+ return rest === '' || (!isAbsolute(rest) && rest !== '..' && !rest.startsWith(`..${sep}`));
8
+ }
9
+ export async function readWorkingTree(directory, output, excludes) {
10
+ const root = await realpath(directory);
11
+ const files = [];
12
+ const generatedExcluded = [];
13
+ if (containsPath(output, root))
14
+ throw new Error('The output directory must be separate from the source root');
15
+ async function visit(folder, prefix) {
16
+ for (const entry of await readdir(folder, { withFileTypes: true })) {
17
+ const path = prefix + entry.name;
18
+ const absolute = join(folder, entry.name);
19
+ if (excludes(path))
20
+ continue;
21
+ if (entry.isDirectory() && !isExcludedDirectory(entry.name) && absolute !== output) {
22
+ await visit(absolute, `${path}/`);
23
+ }
24
+ else if (entry.isFile() && isSourcePath(path)) {
25
+ const bytes = await readFile(absolute);
26
+ if (isGeneratedSource(bytes))
27
+ generatedExcluded.push(path);
28
+ else
29
+ files.push({ path, bytes });
30
+ }
31
+ }
32
+ }
33
+ await visit(root, '');
34
+ return { ...workingSnapshot(files), generatedExcluded: generatedExcluded.sort(comparePaths) };
35
+ }
36
+ //# sourceMappingURL=local.js.map
@@ -0,0 +1 @@
1
+ export declare function openMetabranchWorktree(repository: string, worktree: string, branch: string, sourceCommit: string): Promise<string>;
@@ -0,0 +1,35 @@
1
+ import { lstat, readFile, readdir, realpath, writeFile } from 'node:fs/promises';
2
+ import { join } from 'node:path';
3
+ import { gitRoot, gitText, resolveGitCommit } from './git.js';
4
+ import { containsPath } from './local.js';
5
+ import { checkMetaManifest, metaManifest } from '../../report/json/validation/metabranch.js';
6
+ export async function openMetabranchWorktree(repository, worktree, branch, sourceCommit) {
7
+ await resolveGitCommit(repository, sourceCommit);
8
+ const source = await realpath(await gitRoot(repository));
9
+ const target = await realpath(worktree);
10
+ if (containsPath(source, target) || containsPath(target, source) || await realpath(await gitRoot(target)) !== target) {
11
+ throw new Error('Select the root of a separate worktree outside the source checkout');
12
+ }
13
+ const commonDir = async (path) => realpath((await gitText(path, ['rev-parse', '--path-format=absolute', '--git-common-dir'])).replace(/\r?\n$/, ''));
14
+ if (await commonDir(source) !== await commonDir(target))
15
+ throw new Error('Metabranch worktree must belong to the source repository');
16
+ const expectedRef = `refs/heads/${branch}`;
17
+ await gitText(target, ['check-ref-format', expectedRef]);
18
+ if ((await gitText(target, ['symbolic-ref', '--quiet', 'HEAD'])).trim() !== expectedRef) {
19
+ throw new Error(`Metabranch worktree must be on ${expectedRef}`);
20
+ }
21
+ const marker = join(target, 'manifest.json');
22
+ const entries = await readdir(target);
23
+ if (entries.includes('manifest.json')) {
24
+ if (!(await lstat(marker)).isFile())
25
+ throw new Error('The metabranch manifest must be a regular file');
26
+ checkMetaManifest(await readFile(marker, 'utf8'));
27
+ }
28
+ else {
29
+ if (entries.some(name => name !== '.git'))
30
+ throw new Error('Start from an empty metabranch worktree or an existing Repometry manifest');
31
+ await writeFile(marker, `${JSON.stringify(metaManifest, null, 2)}\n`, { flag: 'wx', mode: 0o600 });
32
+ }
33
+ return target;
34
+ }
35
+ //# sourceMappingURL=metabranch-worktree.js.map
@@ -0,0 +1,3 @@
1
+ export declare function sourceCacheRoot(env?: NodeJS.ProcessEnv, system?: NodeJS.Platform, home?: string): string;
2
+ export declare function clearSourceCache(root?: string): Promise<void>;
3
+ export declare function cachedBlob(root: string, oid: string, load: () => Promise<Buffer | undefined>): Promise<Buffer | undefined>;
@@ -0,0 +1,57 @@
1
+ import { createHash, randomUUID } from 'node:crypto';
2
+ import { lstat, mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
3
+ import { homedir } from 'node:os';
4
+ import { join, resolve } from 'node:path';
5
+ import { validSubjectId } from '../../core/model/report.js';
6
+ export function sourceCacheRoot(env = process.env, system = process.platform, home = homedir()) {
7
+ if (env.REPOMETRY_CACHE_DIR)
8
+ return resolve(env.REPOMETRY_CACHE_DIR);
9
+ if (env.XDG_CACHE_HOME)
10
+ return resolve(env.XDG_CACHE_HOME, 'repometry');
11
+ if (system === 'darwin')
12
+ return join(home, 'Library', 'Caches', 'repometry');
13
+ if (system === 'win32' && env.LOCALAPPDATA)
14
+ return resolve(env.LOCALAPPDATA, 'repometry', 'cache');
15
+ return join(home, '.cache', 'repometry');
16
+ }
17
+ export async function clearSourceCache(root = sourceCacheRoot()) {
18
+ await rm(join(root, 'sources'), { recursive: true, force: true });
19
+ }
20
+ export async function cachedBlob(root, oid, load) {
21
+ if (!validSubjectId('commit', oid))
22
+ throw new Error('Invalid source blob ID');
23
+ const folder = join(root, 'sources', oid.slice(0, 2));
24
+ const path = join(folder, oid);
25
+ try {
26
+ if ((await lstat(path)).isFile()) {
27
+ const hit = await readFile(path);
28
+ if (blobMatches(oid, hit))
29
+ return hit;
30
+ }
31
+ }
32
+ catch (error) {
33
+ if (!isMissing(error))
34
+ throw error;
35
+ }
36
+ const bytes = await load();
37
+ if (bytes === undefined || !blobMatches(oid, bytes))
38
+ return undefined;
39
+ await mkdir(folder, { recursive: true, mode: 0o700 });
40
+ const temporary = join(folder, `.${randomUUID()}.tmp`);
41
+ try {
42
+ await writeFile(temporary, bytes, { flag: 'wx', mode: 0o600 });
43
+ await rename(temporary, path);
44
+ }
45
+ finally {
46
+ await rm(temporary, { force: true });
47
+ }
48
+ return bytes;
49
+ }
50
+ function blobMatches(oid, bytes) {
51
+ return createHash(oid.length === 40 ? 'sha1' : 'sha256')
52
+ .update(`blob ${bytes.length}\0`).update(bytes).digest('hex') === oid;
53
+ }
54
+ function isMissing(error) {
55
+ return error instanceof Error && 'code' in error && error.code === 'ENOENT';
56
+ }
57
+ //# sourceMappingURL=source-cache.js.map
@@ -0,0 +1,9 @@
1
+ import type { Finding } from '../../core/model/finding.js';
2
+ import type { FindingInput, ImportMetadata } from '../../core/model/scanner-import.js';
3
+ export { findingImportMethods } from '../../core/model/scanner-import.js';
4
+ export type { FindingInput } from '../../core/model/scanner-import.js';
5
+ interface Imported {
6
+ readonly findings: readonly Finding[];
7
+ readonly metadata: ImportMetadata;
8
+ }
9
+ export declare function importFindings(input: FindingInput, root: string, excludes: (path: string) => boolean, knownPaths: ReadonlySet<string> | undefined): Promise<Imported>;
@@ -0,0 +1,227 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { isAbsolute, relative, resolve, sep } from 'node:path';
3
+ import { fileURLToPath, pathToFileURL } from 'node:url';
4
+ import { isRecord } from '../../core/engine/plugin.js';
5
+ import { digest } from '../../core/model/snapshot.js';
6
+ import { uniqueScanners, scannerText as text } from '../../core/model/scanner-import.js';
7
+ export { findingImportMethods } from '../../core/model/scanner-import.js';
8
+ export async function importFindings(input, root, excludes, knownPaths) {
9
+ const bytes = await readFile(input.file);
10
+ let parsed;
11
+ try {
12
+ const value = JSON.parse(bytes.toString('utf8'));
13
+ const map = (path) => repositoryPath(root, path);
14
+ parsed = input.format === 'sarif' ? parseSarif(value, input.category, root)
15
+ : input.format === 'eslint' ? parseESLint(value, map) : parseOSV(value, map);
16
+ }
17
+ catch {
18
+ throw new Error(`Invalid ${input.format.toUpperCase()} finding input (${input.category})`);
19
+ }
20
+ const { toolVersion, settingsDigest = null, scope = null } = input;
21
+ if (toolVersion !== undefined && (parsed.tools.length !== 1 || !text(toolVersion)))
22
+ throw new Error('A tool version override requires one scanner');
23
+ if (settingsDigest !== null && !/^[a-f0-9]{64}$/.test(settingsDigest))
24
+ throw new Error('Invalid scanner settings digest');
25
+ const tools = toolVersion === undefined ? parsed.tools : [{ name: parsed.tools[0].name, version: toolVersion }];
26
+ const findings = [];
27
+ let unmapped = 0;
28
+ for (const item of parsed.items) {
29
+ if (item?.path && excludes(item.path))
30
+ continue;
31
+ if (item === null || (item.path && knownPaths && !knownPaths.has(item.path))) {
32
+ unmapped++;
33
+ continue;
34
+ }
35
+ const related = item.related?.filter(location => !excludes(location.path) && (!knownPaths || knownPaths.has(location.path)));
36
+ findings.push({ ...item, related: related?.length ? related : undefined });
37
+ }
38
+ return { findings, metadata: { format: input.format, category: input.category, inputDigest: digest(bytes), tools, settingsDigest, scope,
39
+ imported: findings.length, reported: parsed.items.length, unmapped, units: parsed.units } };
40
+ }
41
+ function parseSarif(value, category, root) {
42
+ const report = object(value);
43
+ if (report.version !== '2.1.0')
44
+ throw new Error('Unknown SARIF version');
45
+ const runs = array(report.runs);
46
+ const tools = [];
47
+ const items = [];
48
+ for (const value of runs) {
49
+ const run = object(value);
50
+ const driver = object(object(run.tool).driver);
51
+ const tool = requiredText(driver.name);
52
+ tools.push({ name: tool, version: text(driver.semanticVersion) ?? text(driver.version) ?? null });
53
+ const rules = optionalArray(driver.rules);
54
+ const rulesById = new Map(rules.filter(isRecord).map(rule => [text(rule.id), rule]));
55
+ const artifacts = optionalArray(run.artifacts);
56
+ const bases = isRecord(run.originalUriBaseIds) ? run.originalUriBaseIds : {};
57
+ if (optionalArray(run.invocations).some(invocation => object(invocation).executionSuccessful === false)) {
58
+ throw new Error('SARIF run reports an execution failure');
59
+ }
60
+ for (const candidate of optionalArray(run.results)) {
61
+ const result = object(candidate);
62
+ if (result.kind !== undefined && result.kind !== 'fail' || optionalArray(result.suppressions).some(suppression => object(suppression).status === undefined || object(suppression).status === 'accepted'))
63
+ continue;
64
+ const id = text(result.ruleId);
65
+ const descriptor = safeIndex(result.ruleIndex) ? rules[result.ruleIndex] : id ? rulesById.get(id) : undefined;
66
+ const rule = isRecord(descriptor) ? descriptor : {};
67
+ const defaultConfiguration = isRecord(rule.defaultConfiguration) ? rule.defaultConfiguration : {};
68
+ const level = lookupLevel(result.level ?? defaultConfiguration.level);
69
+ const ruleId = id ?? text(rule.id) ?? '(unclassified)';
70
+ const message = category === 'secret' ? 'Potential secret reported by a scanner' : sarifMessage(result.message);
71
+ const locations = optionalArray(result.locations).map(location => sarifLocation(location, artifacts, bases, root));
72
+ const primary = locations.find(location => location && location.path !== null);
73
+ const related = locations.filter((location) => location !== primary && location !== undefined && location.path !== null && location.line !== undefined && location.endLine !== undefined);
74
+ items.push(locations.some(location => location?.path === null) && !primary ? null : {
75
+ tool, rule: ruleId, category, level, message, ...(primary?.path && { ...primary, path: primary.path }), related,
76
+ });
77
+ }
78
+ }
79
+ return { tools: uniqueScanners(tools), items, units: runs.length };
80
+ }
81
+ function sarifMessage(value) {
82
+ const message = object(value);
83
+ return text(message.text) ?? text(message.markdown) ?? text(message.id) ?? '(missing message)';
84
+ }
85
+ function sarifLocation(value, artifacts, bases, root) {
86
+ const location = object(value);
87
+ const physical = location.physicalLocation;
88
+ if (!isRecord(physical) || !isRecord(physical.artifactLocation))
89
+ return;
90
+ const artifact = physical.artifactLocation;
91
+ const stored = safeIndex(artifact.index) ? artifacts[artifact.index] : undefined;
92
+ const fallback = isRecord(stored) && isRecord(stored.location) ? stored.location : {};
93
+ const uri = text(artifact.uri) ?? text(fallback.uri);
94
+ if (!uri)
95
+ return { path: null };
96
+ const baseId = text(artifact.uriBaseId) ?? text(fallback.uriBaseId);
97
+ const base = pathToFileURL(`${root}${sep}`);
98
+ const resolvedBase = baseId ? sarifBase(baseId, bases, base, new Set()) : base;
99
+ const file = fileLocation(uri, resolvedBase);
100
+ const path = file === null ? null : repositoryPath(root, file);
101
+ const source = isRecord(physical.region) ? physical.region : {};
102
+ return { path, ...range(source.startLine, source.endLine) };
103
+ }
104
+ function sarifBase(id, bases, fallback, visited) {
105
+ if (visited.has(id))
106
+ return null;
107
+ if (!Object.hasOwn(bases, id))
108
+ return id === '%SRCROOT%' ? fallback : null;
109
+ visited.add(id);
110
+ const item = object(bases[id]);
111
+ const uri = text(item.uri);
112
+ const parent = text(item.uriBaseId);
113
+ const base = parent ? sarifBase(parent, bases, fallback, visited) : fallback;
114
+ const file = uri && fileLocation(uri, base);
115
+ return file ? pathToFileURL(file) : null;
116
+ }
117
+ function fileLocation(uri, base) {
118
+ try {
119
+ const url = base === null ? new URL(uri) : new URL(uri, base);
120
+ if (url.protocol !== 'file:' || url.search !== '' || url.hash !== '')
121
+ return null;
122
+ return fileURLToPath(url);
123
+ }
124
+ catch {
125
+ return null;
126
+ }
127
+ }
128
+ function parseESLint(value, map) {
129
+ const files = array(isRecord(value) ? value.results : value);
130
+ const items = [];
131
+ for (const candidate of files) {
132
+ const file = object(candidate);
133
+ const path = map(requiredText(file.filePath));
134
+ for (const value of array(file.messages)) {
135
+ const message = object(value);
136
+ items.push(path === null ? null : { tool: 'eslint', rule: text(message.ruleId) ?? (message.fatal === true ? 'parse-error' : '(unclassified)'),
137
+ category: 'lint', level: message.severity === 2 ? 'high' : message.severity === 1 ? 'medium' : 'unknown',
138
+ message: requiredText(message.message), path, ...range(message.line, message.endLine) });
139
+ }
140
+ }
141
+ return { tools: [{ name: 'eslint', version: null }], items, units: files.length };
142
+ }
143
+ function parseOSV(value, map) {
144
+ const report = object(value);
145
+ const sources = report.results === null ? [] : array(report.results);
146
+ const items = [];
147
+ let units = 0;
148
+ for (const value of sources) {
149
+ const source = object(value);
150
+ const pathValue = isRecord(source.source) ? text(source.source.path) : undefined;
151
+ const path = pathValue === undefined ? undefined : map(pathValue);
152
+ for (const candidate of array(source.packages)) {
153
+ units++;
154
+ const listed = object(candidate);
155
+ const pkg = object(listed.package);
156
+ const name = requiredText(pkg.name);
157
+ const version = text(pkg.version) ?? text(pkg.commit);
158
+ const advisories = new Set(optionalArray(listed.vulnerabilities).map(value => requiredText(object(value).id)));
159
+ for (const entry of optionalArray(listed.groups)) {
160
+ const group = object(entry);
161
+ const identifiers = array(group.ids).map(requiredText);
162
+ if (advisories.size > 0 && identifiers.some(id => advisories.has(id))) {
163
+ const canonical = advisoryId([...identifiers, ...optionalArray(group.aliases).map(requiredText)]);
164
+ add(canonical, scoreLevel(group.max_severity));
165
+ for (const id of identifiers)
166
+ advisories.delete(id);
167
+ }
168
+ }
169
+ for (const advisory of advisories)
170
+ add(advisory, 'unknown');
171
+ function add(rule, level) {
172
+ items.push(path === null ? null : { tool: 'osv-scanner', rule, category: 'dependency', level, path,
173
+ message: `Advisory for ${name}${version ? `@${version}` : ''}` });
174
+ }
175
+ }
176
+ }
177
+ return { tools: [{ name: 'osv-scanner', version: null }], items, units };
178
+ }
179
+ function advisoryId(ids) {
180
+ const sorted = [...ids].sort();
181
+ return sorted.find(id => id.startsWith('CVE-')) ?? sorted.find(id => id.startsWith('GHSA-')) ?? sorted[0];
182
+ }
183
+ function scoreLevel(value) {
184
+ const numeric = typeof value === 'string' && /^(?:\d+|\d+\.\d+)$/.test(value) ? Number(value) : value;
185
+ if (typeof numeric !== 'number' || !Number.isFinite(numeric) || numeric <= 0 || numeric > 10)
186
+ return 'unknown';
187
+ return numeric >= 7 ? 'high' : numeric >= 4 ? 'medium' : 'low';
188
+ }
189
+ function lookupLevel(value) {
190
+ return value === 'error' ? 'high' : value === 'warning' ? 'medium' : value === 'note' ? 'low' : 'unknown';
191
+ }
192
+ function range(first, last) {
193
+ if (!safeIndex(first) || first === 0)
194
+ return {};
195
+ return { line: first, endLine: safeIndex(last) && last >= first ? last : first };
196
+ }
197
+ function repositoryPath(root, path) {
198
+ if (/[\0\r\n]/.test(path))
199
+ return null;
200
+ const result = relative(root, resolve(root, path));
201
+ if (result === '' || isAbsolute(result) || result === '..' || result.startsWith(`..${sep}`))
202
+ return null;
203
+ return result.split(sep).join('/');
204
+ }
205
+ function requiredText(value) {
206
+ const result = text(value);
207
+ if (result === undefined)
208
+ throw new Error('Invalid scanner field');
209
+ return result;
210
+ }
211
+ function object(value) {
212
+ if (!isRecord(value))
213
+ throw new Error('Expected scanner object');
214
+ return value;
215
+ }
216
+ function array(value) {
217
+ if (!Array.isArray(value))
218
+ throw new Error('Expected scanner array');
219
+ return value;
220
+ }
221
+ function optionalArray(value) {
222
+ return value === undefined ? [] : array(value);
223
+ }
224
+ function safeIndex(value) {
225
+ return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0;
226
+ }
227
+ //# sourceMappingURL=finding-import.js.map
@@ -0,0 +1,5 @@
1
+ export type LcovFiles = string | readonly string[];
2
+ export declare function readLcovFiles(input: LcovFiles): Promise<{
3
+ text: string;
4
+ inputDigests: string[];
5
+ }>;
@@ -0,0 +1,14 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { comparePaths, digest, utf8 } from '../../core/model/snapshot.js';
3
+ export async function readLcovFiles(input) {
4
+ const paths = typeof input === 'string' ? [input] : input;
5
+ if (paths.length === 0)
6
+ throw new Error('Provide at least one LCOV file');
7
+ const sources = await Promise.all(paths.map(async (path) => {
8
+ const text = utf8(await readFile(path));
9
+ return { text, digest: digest(text) };
10
+ }));
11
+ sources.sort((a, b) => comparePaths(a.digest, b.digest));
12
+ return { text: sources.map(source => source.text).join('\n'), inputDigests: sources.map(source => source.digest) };
13
+ }
14
+ //# sourceMappingURL=lcov-files.js.map