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,379 @@
1
+ #!/usr/bin/env node
2
+ import { lstat, readFile } from 'node:fs/promises';
3
+ import { join, resolve } from 'node:path';
4
+ import { firstParentRange, gitRoot, resolveGitCommit } from '../api/git/git.js';
5
+ import { resolveGitBranch } from '../api/git/commit-metadata.js';
6
+ import { clearSourceCache, sourceCacheRoot } from '../api/git/source-cache.js';
7
+ import { writeGitHubDiffCoverage, writeGitHubResult, writeGitHubReview } from '../api/gh/github.js';
8
+ import { remoteExecutor } from '../api/worker/remote-executor.js';
9
+ import { serveWorker } from '../api/worker/worker.js';
10
+ import { workerToken } from '../api/worker/worker-protocol.js';
11
+ import { analyzeSnapshot, attachFindings, inspect } from '../compose/inspect.js';
12
+ import { measureDiffCoverage } from '../compose/diff-coverage.js';
13
+ import { prepareMetabranch } from '../compose/prepare-metabranch.js';
14
+ import { reviewExitCode, reviewPull } from '../compose/review.js';
15
+ import { builtInPlugins } from '../compose/plugin-list.js';
16
+ import { isRecord } from '../core/engine/plugin.js';
17
+ import { validSubjectId } from '../core/model/report.js';
18
+ import { sourceExclusionMatcher } from '../core/profile/exclusions.js';
19
+ import { compareInspections } from '../core/usecases/compare.js';
20
+ import { exportProjects } from '../report/html/site/projects.js';
21
+ import { fileMetrics } from '../report/json/projections/file-metrics.js';
22
+ import { savePullReview } from '../report/json/store/pull-review-store.js';
23
+ import { dispatch, flag, option } from './arguments.js';
24
+ import { readConfig } from './config.js';
25
+ import { importerIds, readInputs } from './imports.js';
26
+ import { outputReports, reporterIds, viewTarget } from './reporting.js';
27
+ import { parseRange } from './revisions.js';
28
+ import { findRepository, selectStore, writableStore } from './store.js';
29
+ const configOptions = { config: option('FILE', 'Read a different JSON configuration.'), 'no-config': flag('Skip configuration.') };
30
+ const importOption = option('FORMAT=PATH', 'Import a report produced by another tool. Repeatable.', { multiple: true });
31
+ const excludeOption = option('PATTERN', 'Exclude a path or glob. Repeatable.', { multiple: true });
32
+ const ciOption = option('PROVIDER', 'Send CI output to github or none.');
33
+ const outputOption = option('PATH', 'Set the report output path.', { short: 'o' });
34
+ const baselineOption = option('PATH|git:REF', 'Select the baseline report store.');
35
+ const branchOption = option('NAME', 'Name the branch represented by the report.');
36
+ const renderOptions = {
37
+ output: outputOption,
38
+ sources: option('auto|none|ID[:SPEC]', 'Select where the report reads source files.'),
39
+ title: option('NAME', 'Set the report title.'), components: option('FILE', 'Read component definitions.'),
40
+ 'no-footer': flag('Omit the footer.'), branch: branchOption,
41
+ };
42
+ const commands = {
43
+ analyze: {
44
+ description: 'Analyze and save one revision or a range of commits.', parameters: '[REVISION | BASE..[HEAD]]', max: 1,
45
+ options: { ...configOptions, ...renderOptions, 'working-tree': flag('Analyze the working directory.'),
46
+ 'skip-saved': flag('Keep commits that already have a saved inspection.'),
47
+ import: importOption, report: option('FORMAT[=PATH]', 'Generate a report after inspection. Repeatable.', { multiple: true }),
48
+ exclude: excludeOption, 'import-root': option('DIR', 'Resolve scanner locations relative to this directory.'),
49
+ worker: option('URL', 'Run analysis on a Repometry worker.'), ci: ciOption },
50
+ run: analyze,
51
+ },
52
+ show: {
53
+ description: 'Print a saved report.', parameters: 'REVISION|DIGEST', min: 1, max: 1,
54
+ options: { files: flag('Print file metrics.') }, run: show,
55
+ },
56
+ history: { description: 'List saved inspections.', async run(input) {
57
+ const { store } = await context(input);
58
+ print({ schema: 'urn:repometry:schema:inspection-history:1', inspections: (await store.reader.list()).map(inspectionSummary) });
59
+ } },
60
+ compare: {
61
+ description: 'Compare two saved reports.', parameters: 'BASE [HEAD]', min: 1, max: 2,
62
+ options: { 'baseline-store': baselineOption }, run: compare,
63
+ },
64
+ 'diff-coverage': {
65
+ description: 'Measure coverage of added lines.', parameters: 'BASE [HEAD]', min: 1, max: 2,
66
+ options: { ...configOptions, import: importOption, exclude: excludeOption, ci: ciOption,
67
+ 'min-coverage': option('PERCENT', 'Minimum acceptable changed-line coverage.') }, run: diffCoverage,
68
+ },
69
+ review: {
70
+ description: 'Review coverage and issues introduced by a change.', parameters: 'BASE [HEAD]', min: 1, max: 2,
71
+ options: { ...configOptions, import: importOption, exclude: excludeOption, ci: ciOption,
72
+ 'baseline-store': baselineOption, pull: option('NUMBER', 'Store a review for this pull request.'),
73
+ 'min-coverage': option('PERCENT', 'Minimum acceptable changed-line coverage.'),
74
+ 'min-lines': option('COUNT', 'Minimum measured lines for the changed-line coverage gate.'),
75
+ 'max-coverage-drop': option('POINTS', 'Maximum total coverage drop.'),
76
+ 'max-new-issues': option('COUNT', 'Maximum count of new quality findings.'),
77
+ annotations: flag('Write GitHub line annotations.') }, run: review,
78
+ },
79
+ report: {
80
+ description: 'Render HTML or JSON from saved reports.', parameters: '[FORMAT[=PATH]]...', max: Infinity,
81
+ options: { ...configOptions, ...renderOptions }, async run(input) {
82
+ const { root, store } = await context(input);
83
+ const config = await readConfig(root, input);
84
+ const requests = input.args.length ? input.args : config.reports.length ? config.reports : ['html'];
85
+ print({ schema: 'urn:repometry:schema:render-result:1', reports: await outputReports(root, store, requests, input, config) });
86
+ },
87
+ },
88
+ view: {
89
+ description: 'Open a repository, store or exported site locally.', parameters: '[TARGET]', max: 1,
90
+ options: { ...configOptions, branch: branchOption, port: option('PORT', 'Listen on this localhost port.'), title: renderOptions.title,
91
+ components: renderOptions.components, 'no-footer': renderOptions['no-footer'] },
92
+ async run(input) { announce(await viewTarget(input, port(input.text('port') ?? '0'))); },
93
+ },
94
+ projects: {
95
+ description: 'Generate a projects index.', options: { output: outputOption, 'no-footer': renderOptions['no-footer'] },
96
+ async run(input) {
97
+ const destination = resolve(input.text('repo') ?? '.', input.text('output') ?? '.');
98
+ print({ schema: 'urn:repometry:schema:projects-result:1', destination,
99
+ projects: await exportProjects(destination, { footer: !input.flag('no-footer') }) });
100
+ },
101
+ },
102
+ prepare: {
103
+ description: 'Prepare a report for a Git storage branch.', parameters: 'REVISION', min: 1, max: 1,
104
+ options: { worktree: option('DIR', 'Select the storage worktree.'), branch: option('NAME', 'Select the storage branch.') },
105
+ async run(input) {
106
+ const { directory, root, store } = await context(input);
107
+ const path = input.text('worktree');
108
+ if (!path)
109
+ throw new Error('prepare requires --worktree');
110
+ const worktree = resolve(directory, path);
111
+ const id = await commitId(root, input.args[0]);
112
+ const report = await store.reader.read({ kind: 'commit', id });
113
+ const files = await prepareMetabranch({ repository: root, worktree, branch: input.text('branch') ?? 'repometry', report });
114
+ print({ schema: 'urn:repometry:schema:prepare-result:1', subject: report.subject, worktree, files });
115
+ },
116
+ },
117
+ plugins: { description: 'List plugins and supported formats.', run() {
118
+ print({ schema: 'urn:repometry:schema:plugin-list:1', plugins: builtInPlugins, importers: importerIds,
119
+ reporters: reporterIds, ci: ['github'], stores: ['local', 'git'] });
120
+ } },
121
+ cache: {
122
+ description: 'Find or clear the system cache.', parameters: 'path|clear', min: 1, max: 1,
123
+ options: { sources: flag('Clear only source blobs.') },
124
+ async run(input) {
125
+ const action = input.args[0];
126
+ if (action !== 'path' && action !== 'clear')
127
+ throw new Error('Use cache path or cache clear');
128
+ if (action === 'path' && input.flag('sources'))
129
+ throw new Error('--sources requires cache clear');
130
+ const path = sourceCacheRoot();
131
+ if (action === 'clear')
132
+ await clearSourceCache(path);
133
+ print({ schema: 'urn:repometry:schema:cache-result:1', path, ...(action === 'clear' ? { cleared: ['sources'] } : {}) });
134
+ },
135
+ },
136
+ worker: { description: 'Run the remote analysis worker.',
137
+ options: { port: option('PORT', 'Listen on this port.'), listen: option('ADDRESS', 'Listen on 127.0.0.1 or 0.0.0.0.') },
138
+ async run(input) {
139
+ const host = input.text('listen') ?? '127.0.0.1';
140
+ if (host !== '127.0.0.1' && host !== '0.0.0.0')
141
+ throw new Error('--listen must be 127.0.0.1 or 0.0.0.0');
142
+ announce(await serveWorker(host, port(input.text('port') ?? '7331'), workerToken(), analyzeSnapshot));
143
+ } },
144
+ };
145
+ async function context(input) {
146
+ const directory = resolve(input.text('repo') ?? '.');
147
+ const root = await findRepository(directory) ?? directory;
148
+ return { directory, root, store: selectStore(root, input.text('store'), directory) };
149
+ }
150
+ async function analyze(input) {
151
+ const range = input.args[0] === undefined ? undefined : parseRange(input.args[0]);
152
+ if (range)
153
+ return analyzeRange(input, range);
154
+ const { directory, root, store } = await context(input);
155
+ const output = writableStore(store);
156
+ if (input.flag('working-tree') && input.args.length)
157
+ throw new Error('Choose a revision or --working-tree');
158
+ if (input.flag('working-tree') && input.flag('skip-saved'))
159
+ throw new Error('--skip-saved applies to commits, not --working-tree');
160
+ const github = useGitHub(input);
161
+ const config = await readConfig(root, input);
162
+ const branch = input.text('branch') ?? config.branch;
163
+ const revision = input.args[0] ?? (!input.flag('working-tree') && branch !== undefined ? await resolveGitBranch(root, branch) : 'HEAD');
164
+ const imports = input.many('import');
165
+ const { lcov, findings } = imports.length ? readInputs(directory, imports) : readInputs(root, config.imports);
166
+ const importRoot = input.text('import-root');
167
+ if (importRoot && findings.length === 0)
168
+ throw new Error('--import-root requires a scanner report');
169
+ const worker = input.text('worker');
170
+ const savedId = input.flag('skip-saved') ? await resolveGitCommit(root, revision) : undefined;
171
+ const skipped = savedId !== undefined && await isSaved(output, savedId);
172
+ const report = skipped ? await store.reader.read({ kind: 'commit', id: savedId })
173
+ : await inspect({ directory, output, source: input.flag('working-tree') ? { workingTree: true } : { revision },
174
+ lcov, exclude: [...config.exclude, ...input.many('exclude')], ignore: config.ignore,
175
+ findingInputs: findings, findingRoot: importRoot ? resolve(directory, importRoot) : undefined }, worker === undefined ? undefined : remoteExecutor(worker, workerToken()));
176
+ if (github)
177
+ await writeGitHubResult(report);
178
+ const requested = input.many('report');
179
+ const reports = await outputReports(root, store, requested.length ? requested : config.reports, input, config);
180
+ print({ schema: 'urn:repometry:schema:analysis-result:1', ...inspectionSummary(report), ...(skipped ? { skipped: true } : {}),
181
+ store: output, reports });
182
+ return report.status === 'partial' ? 2 : 0;
183
+ }
184
+ async function analyzeRange(input, range) {
185
+ const { directory, root, store } = await context(input);
186
+ const output = writableStore(store);
187
+ if (input.flag('working-tree'))
188
+ throw new Error('Choose a range or --working-tree');
189
+ if (input.many('import').length)
190
+ throw new Error('--import describes one checkout and cannot be used with a range');
191
+ if (input.text('import-root'))
192
+ throw new Error('--import-root requires a scanner report');
193
+ if (useGitHub(input))
194
+ throw new Error('--ci github needs a single revision');
195
+ const config = await readConfig(root, input);
196
+ if (config.imports.length)
197
+ process.stderr.write('Imports from the config describe one checkout and are skipped for a range.\n');
198
+ const { base, head, commits } = await firstParentRange(root, range.base, range.head);
199
+ if (!commits.length)
200
+ process.stderr.write(`No commits in ${range.base}..${range.head}.\n`);
201
+ const worker = input.text('worker');
202
+ const executor = worker === undefined ? undefined : remoteExecutor(worker, workerToken());
203
+ const exclude = [...config.exclude, ...input.many('exclude')];
204
+ const analyzed = [], partial = [], skipped = [];
205
+ const failed = [];
206
+ let interrupted = false;
207
+ const stop = () => { interrupted = true; process.stderr.write('Stopping after the current commit.\n'); };
208
+ process.once('SIGINT', stop);
209
+ const width = String(commits.length).length;
210
+ const progress = (index, id, state) => process.stderr.write(`[${String(index + 1).padStart(width)}/${commits.length}] ${id.slice(0, 7)} ${state}\n`);
211
+ try {
212
+ for (const [index, id] of commits.entries()) {
213
+ if (interrupted)
214
+ break;
215
+ if (input.flag('skip-saved') && await isSaved(output, id)) {
216
+ skipped.push(id);
217
+ progress(index, id, 'skipped');
218
+ continue;
219
+ }
220
+ try {
221
+ const report = await inspect({ directory, output, source: { revision: id }, exclude, ignore: config.ignore }, executor);
222
+ analyzed.push(id);
223
+ if (report.status === 'partial')
224
+ partial.push(id);
225
+ progress(index, id, report.status === 'partial' ? 'partial' : 'analyzed');
226
+ }
227
+ catch (error) {
228
+ if (interrupted)
229
+ break;
230
+ const message = error instanceof Error ? error.message : String(error);
231
+ failed.push({ commit: id, error: message });
232
+ progress(index, id, `failed: ${message}`);
233
+ }
234
+ }
235
+ }
236
+ finally {
237
+ process.removeListener('SIGINT', stop);
238
+ }
239
+ const requested = input.many('report');
240
+ const reports = interrupted ? [] : await outputReports(root, store, requested.length ? requested : config.reports, input, config);
241
+ print({ schema: 'urn:repometry:schema:analyze-range:1', range: `${base}..${head}`,
242
+ analyzed, partial, skipped, failed, store: output, reports });
243
+ return interrupted ? 130 : failed.length || partial.length ? 2 : 0;
244
+ }
245
+ async function isSaved(store, id) {
246
+ try {
247
+ return (await lstat(join(store, 'commits', id, 'report.json'))).isFile();
248
+ }
249
+ catch (error) {
250
+ if (error instanceof Error && 'code' in error && (error.code === 'ENOENT' || error.code === 'ENOTDIR'))
251
+ return false;
252
+ throw error;
253
+ }
254
+ }
255
+ async function show(input) {
256
+ const { root, store } = await context(input);
257
+ const ref = input.args[0];
258
+ const id = await commitId(root, ref);
259
+ let report;
260
+ try {
261
+ report = await store.reader.read({ kind: 'commit', id });
262
+ }
263
+ catch (error) {
264
+ if (!validSubjectId('working-tree', ref) || store.path === undefined || !(error instanceof Error)
265
+ || !('code' in error) || error.code !== 'ENOENT')
266
+ throw error;
267
+ report = await store.reader.read({ kind: 'working-tree', id: ref });
268
+ }
269
+ print(input.flag('files') ? fileMetrics(report) : report);
270
+ }
271
+ async function compare(input) {
272
+ const { directory, root, store } = await context(input);
273
+ const baselinePath = input.text('baseline-store');
274
+ const baseline = baselinePath === undefined ? store : selectStore(root, baselinePath, directory);
275
+ const [base, head] = await Promise.all([commitId(root, input.args[0]), commitId(root, input.args[1] ?? 'HEAD')]);
276
+ const current = store.reader.read({ kind: 'commit', id: head });
277
+ const before = base === head && baseline === store ? current : baseline.reader.read({ kind: 'commit', id: base });
278
+ print(compareInspections(await before, await current));
279
+ }
280
+ async function diffCoverage(input) {
281
+ const { directory, root } = await context(input);
282
+ const config = await readConfig(root, input);
283
+ const imports = input.many('import');
284
+ const { lcov, findings } = imports.length ? readInputs(directory, imports) : readInputs(root, config.imports);
285
+ if (!lcov || (imports.length && findings.length))
286
+ throw new Error('diff-coverage requires --import lcov=PATH');
287
+ const report = await measureDiffCoverage({ directory: root, base: input.args[0], revision: input.args[1] ?? 'HEAD', lcov,
288
+ exclude: [...config.exclude, ...input.many('exclude')], minimumPercent: percent(input.text('min-coverage') ?? config.minCoverage, '--min-coverage') });
289
+ if (useGitHub(input))
290
+ await writeGitHubDiffCoverage(report);
291
+ print(report);
292
+ return report.status === 'partial' ? 2 : report.decision?.status === 'failed' ? 3 : 0;
293
+ }
294
+ async function review(input) {
295
+ const { directory, root, store } = await context(input);
296
+ const github = useGitHub(input);
297
+ if (input.flag('annotations') && !github)
298
+ throw new Error('--annotations requires --ci github');
299
+ const config = await readConfig(root, input);
300
+ const imports = input.many('import');
301
+ const { lcov, findings } = imports.length ? readInputs(directory, imports) : readInputs(root, config.imports);
302
+ const baselinePath = input.text('baseline-store');
303
+ const baseline = baselinePath === undefined ? store : selectStore(root, baselinePath, directory);
304
+ const exclude = [...config.exclude, ...input.many('exclude')];
305
+ const current = imports.length && findings.length ? {
306
+ list: () => store.reader.list(),
307
+ read: async (subject) => {
308
+ const report = await store.reader.read(subject);
309
+ const source = report.appliedConfig.source;
310
+ const generated = isRecord(source) && Array.isArray(source.generatedExcluded)
311
+ ? source.generatedExcluded.filter((path) => typeof path === 'string') : [];
312
+ return attachFindings(report, findings, root, root, sourceExclusionMatcher(exclude, generated));
313
+ },
314
+ } : store.reader;
315
+ const number = count(input.text('pull'), '--pull', 1);
316
+ const report = await reviewPull({ directory: root, base: input.args[0], revision: input.args[1] ?? 'HEAD', lcov, exclude, number,
317
+ minimumPercent: percent(input.text('min-coverage') ?? config.minCoverage, '--min-coverage'),
318
+ minimumLines: count(input.text('min-lines') ?? config.minLines, '--min-lines'),
319
+ maxCoverageDrop: percent(input.text('max-coverage-drop') ?? config.maxCoverageDrop, '--max-coverage-drop'),
320
+ maxNewIssues: count(input.text('max-new-issues') ?? config.maxNewIssues, '--max-new-issues') }, current, baseline.reader);
321
+ if (number !== undefined)
322
+ await savePullReview(writableStore(store), report);
323
+ if (github)
324
+ await writeGitHubReview(report, input.flag('annotations') ? await gitRoot(root) : undefined);
325
+ print(report);
326
+ return reviewExitCode(report);
327
+ }
328
+ function commitId(root, revision) {
329
+ return validSubjectId('commit', revision) ? Promise.resolve(revision) : resolveGitCommit(root, revision);
330
+ }
331
+ function useGitHub(input) {
332
+ const provider = input.text('ci') ?? 'none';
333
+ if (provider !== 'none' && provider !== 'github')
334
+ throw new Error('--ci must be github or none');
335
+ return provider === 'github';
336
+ }
337
+ function percent(value, name) {
338
+ if (value === undefined)
339
+ return undefined;
340
+ const number = Number(value);
341
+ if (!/^(?:\d+(?:\.\d+)?|\.\d+)$/.test(value) || number < 0 || number > 100)
342
+ throw new Error(`${name} must be a percentage from 0 to 100`);
343
+ return number;
344
+ }
345
+ function count(value, name, minimum = 0) {
346
+ if (value === undefined)
347
+ return undefined;
348
+ const number = Number(value);
349
+ if (!/^\d+$/.test(value) || !Number.isSafeInteger(number) || number < minimum)
350
+ throw new Error(`${name} must be an integer of at least ${minimum}`);
351
+ return number;
352
+ }
353
+ function port(value) {
354
+ const number = count(value, '--port');
355
+ if (number > 65535)
356
+ throw new Error('--port must be an integer from 0 to 65535');
357
+ return number;
358
+ }
359
+ function announce(server) {
360
+ process.once('SIGINT', () => { process.exitCode = 130; server.close(); });
361
+ process.once('SIGTERM', server.close);
362
+ process.stderr.write(`Serving${server.label ? ' ' + server.label : ''} at ${server.url}\n`);
363
+ }
364
+ function inspectionSummary(report) {
365
+ return { subject: report.subject, generatedAt: report.generatedAt, status: report.status, scope: report.scope,
366
+ measurements: report.measurements.length, diagnostics: report.diagnostics.length };
367
+ }
368
+ function print(value) {
369
+ process.stdout.write(JSON.stringify(value, null, 2) + '\n');
370
+ }
371
+ try {
372
+ const manifest = JSON.parse(await readFile(new URL('../../../../package.json', import.meta.url), 'utf8'));
373
+ process.exitCode = await dispatch(commands, process.argv.slice(2), manifest.version);
374
+ }
375
+ catch (error) {
376
+ process.stderr.write(`repometry: ${error instanceof Error ? error.message : String(error)}\n`);
377
+ process.exitCode = 1;
378
+ }
379
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1,18 @@
1
+ import { readConfig } from './config.js';
2
+ import type { Invocation } from './arguments.js';
3
+ import type { Store } from './store.js';
4
+ declare const reporters: {
5
+ readonly html: '.repometry/report/html';
6
+ readonly json: '.repometry/report/history.json';
7
+ };
8
+ export declare const reporterIds: string[];
9
+ export declare function outputReports(root: string, store: Store, requested: readonly string[], input: Invocation, config: Awaited<ReturnType<typeof readConfig>>): Promise<{
10
+ format: keyof typeof reporters;
11
+ path: string;
12
+ }[]>;
13
+ export declare function viewTarget(input: Invocation, port: number): Promise<{
14
+ url: string;
15
+ close: () => void;
16
+ label: string;
17
+ }>;
18
+ export {};
@@ -0,0 +1,104 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { mkdir, rename, rm, writeFile } from 'node:fs/promises';
3
+ import { basename, dirname, resolve } from 'node:path';
4
+ import { commitMetadataReader } from '../api/git/commit-metadata.js';
5
+ import { readLocalSources, sourceRemotes } from '../api/git/local-sources.js';
6
+ import { resolveSourceLocator } from '../compose/sources.js';
7
+ import { commitSummary, withCommitMetadata } from '../report/json/projections/commit-summary.js';
8
+ import { exportSite, siteSummary } from '../report/html/site/export-site.js';
9
+ import { readExportedSummary, serveExportedSite } from '../report/html/site/exported-server.js';
10
+ import { serveSite } from '../report/html/site/local-server.js';
11
+ import { readComponents } from '../report/json/store/components.js';
12
+ import { listPullReviews } from '../report/json/store/pull-review-store.js';
13
+ import { readConfig } from './config.js';
14
+ import { findRepository, invocationDirectory, isDirectory, selectStore } from './store.js';
15
+ const reporters = { html: '.repometry/report/html', json: '.repometry/report/history.json' };
16
+ export const reporterIds = Object.keys(reporters);
17
+ export async function outputReports(root, store, requested, input, config) {
18
+ const output = input.text('output');
19
+ if (output !== undefined && requested.length !== 1)
20
+ throw new Error('--output requires exactly one report; use FORMAT=PATH for multiple reports');
21
+ const requests = requested.map(spec => {
22
+ const equal = spec.indexOf('=');
23
+ const format = equal < 0 ? spec : spec.slice(0, equal);
24
+ const path = equal < 0 ? undefined : spec.slice(equal + 1);
25
+ if (!Object.hasOwn(reporters, format))
26
+ throw new Error(`Unknown reporter: ${format}. Choose ${reporterIds.join(', ')}.`);
27
+ if (path === '' || (output !== undefined && path !== undefined))
28
+ throw new Error('Specify one output per report with FORMAT=PATH or --output');
29
+ return { format: format, path: output ?? path
30
+ ? resolve(invocationDirectory(input), (output ?? path)) : resolve(root, reporters[format]) };
31
+ });
32
+ if (new Set(requests.map(request => request.path)).size !== requests.length)
33
+ throw new Error('Each report requires a separate output');
34
+ if (requests.length === 0)
35
+ return requests;
36
+ const repository = await findRepository(root);
37
+ const readCommitMetadata = repository === undefined ? undefined : commitMetadataReader(repository);
38
+ const sourceOption = input.text('sources') ?? config.sources;
39
+ const sources = resolveSourceLocator(sourceOption, { remotes: await sourceRemotes(root), env: process.env });
40
+ const [components, pulls] = await Promise.all([
41
+ readComponents(componentsPath(root, input), input.text('components') === undefined),
42
+ store.path ? listPullReviews(store.path) : [],
43
+ ]);
44
+ const options = { sources, components, pulls, readCommitMetadata, branch: input.text('branch') ?? config.branch,
45
+ title: input.text('title') ?? (input.text('repo') ? basename(root) : undefined),
46
+ footer: !input.flag('no-footer') };
47
+ for (const request of requests) {
48
+ if (request.format === 'html')
49
+ await exportSite(store.reader, request.path, options);
50
+ else {
51
+ const rows = await store.reader.listSummaries?.() ?? (await store.reader.list()).filter(report => report.subject.kind === 'commit').map(commitSummary);
52
+ const data = siteSummary(await withCommitMetadata(rows, readCommitMetadata), options);
53
+ await writeSummary(request.path, data);
54
+ }
55
+ }
56
+ return requests;
57
+ }
58
+ async function writeSummary(path, data) {
59
+ await mkdir(dirname(path), { recursive: true });
60
+ const temporary = `${path}.${randomUUID()}.tmp`;
61
+ try {
62
+ await writeFile(temporary, data, { mode: 0o644, flag: 'wx' });
63
+ await rename(temporary, path);
64
+ }
65
+ finally {
66
+ await rm(temporary, { force: true });
67
+ }
68
+ }
69
+ export async function viewTarget(input, port) {
70
+ if (input.args[0] !== undefined && input.text('repo') !== undefined)
71
+ throw new Error('Choose a view target or --repo, not both');
72
+ const target = resolve(input.args[0] ?? input.text('repo') ?? '.');
73
+ const exported = await readExportedSummary(target);
74
+ const repository = await findRepository(target);
75
+ if (exported) {
76
+ const local = exported.sources?.provider === 'local' && repository ? readLocalSources(repository) : undefined;
77
+ return { ...await serveExportedSite(target, port, local), label: target + ' (exported report)' };
78
+ }
79
+ const data = resolve(target, 'data');
80
+ const dataStore = basename(target) === '.repometry' && await isDirectory(data);
81
+ const directStore = await isDirectory(resolve(target, 'commits'));
82
+ if (!repository && !dataStore && !directStore) {
83
+ throw new Error(`No report at ${target}: expected a repository, a .repometry folder or an exported report`);
84
+ }
85
+ const root = repository ?? target;
86
+ const store = selectStore(root, input.text('store') ?? (dataStore ? data : directStore ? target : undefined), invocationDirectory(input));
87
+ if ((await store.reader.listSummaries?.() ?? []).length === 0)
88
+ throw new Error(`No saved inspections in ${store.path ?? input.text('store')}. Run repometry analyze first.`);
89
+ const [components, pulls, config] = await Promise.all([
90
+ readComponents(componentsPath(root, input), input.text('components') === undefined),
91
+ store.path ? listPullReviews(store.path) : [],
92
+ readConfig(root, input),
93
+ ]);
94
+ const local = repository ? readLocalSources(repository) : undefined;
95
+ const server = await serveSite(store.reader, port, { title: input.text('title') ?? basename(root), components, pulls,
96
+ branch: input.text('branch') ?? config.branch, readCommitMetadata: repository ? commitMetadataReader(repository) : undefined,
97
+ sources: local ? resolveSourceLocator('local', { remotes: [], env: {} }) : undefined, footer: !input.flag('no-footer') }, local);
98
+ return { ...server, label: `${basename(root)} (live from ${store.path ?? input.text('store')})` };
99
+ }
100
+ function componentsPath(root, input) {
101
+ const explicit = input.text('components');
102
+ return explicit === undefined ? resolve(root, '.repometry/components.json') : resolve(invocationDirectory(input), explicit);
103
+ }
104
+ //# sourceMappingURL=reporting.js.map
@@ -0,0 +1,6 @@
1
+ export interface RevisionRange {
2
+ readonly base: string;
3
+ readonly head: string;
4
+ }
5
+ /** Reads `BASE..HEAD` or `BASE..`; returns undefined for a single revision. Git refnames cannot contain `..`. */
6
+ export declare function parseRange(value: string): RevisionRange | undefined;
@@ -0,0 +1,16 @@
1
+ /** Reads `BASE..HEAD` or `BASE..`; returns undefined for a single revision. Git refnames cannot contain `..`. */
2
+ export function parseRange(value) {
3
+ if (!value.includes('..'))
4
+ return undefined;
5
+ if (value.includes('...'))
6
+ throw new Error(`${value}: a symmetric range has no first-parent line; use BASE..HEAD`);
7
+ const index = value.indexOf('..');
8
+ const base = value.slice(0, index);
9
+ const head = value.slice(index + 2);
10
+ if (!base)
11
+ throw new Error(`${value}: a range needs a base, as in HEAD~10..HEAD`);
12
+ if (head.includes('..'))
13
+ throw new Error(`${value}: use one BASE..HEAD range`);
14
+ return { base, head: head || 'HEAD' };
15
+ }
16
+ //# sourceMappingURL=revisions.js.map
@@ -0,0 +1,13 @@
1
+ import type { Invocation } from './arguments.js';
2
+ import type { ReportReader } from '../report/json/validation/report.js';
3
+ export type Store = {
4
+ readonly reader: ReportReader;
5
+ readonly path?: string;
6
+ };
7
+ export declare function findRepository(directory: string): Promise<string | undefined>;
8
+ /** Where relative paths typed on the command line resolve: --repo/-C, like git -C, or else the current directory. */
9
+ export declare function invocationDirectory(input: Invocation): string;
10
+ /** A typed path resolves against `base`; the default store resolves against the repository root. */
11
+ export declare function selectStore(root: string, value?: string, base?: string): Store;
12
+ export declare function writableStore(store: Store): string;
13
+ export declare function isDirectory(path: string): Promise<boolean>;
@@ -0,0 +1,39 @@
1
+ import { lstat } from 'node:fs/promises';
2
+ import { resolve } from 'node:path';
3
+ import { GitReportReader } from '../api/git/git-reader.js';
4
+ import { gitRoot } from '../api/git/git.js';
5
+ import { LocalReportStore } from '../report/json/store/local-store.js';
6
+ export async function findRepository(directory) {
7
+ return gitRoot(directory).catch(() => undefined);
8
+ }
9
+ /** Where relative paths typed on the command line resolve: --repo/-C, like git -C, or else the current directory. */
10
+ export function invocationDirectory(input) {
11
+ return resolve(input.text('repo') ?? '.');
12
+ }
13
+ /** A typed path resolves against `base`; the default store resolves against the repository root. */
14
+ export function selectStore(root, value, base = root) {
15
+ if (value?.startsWith('git:')) {
16
+ const ref = value.slice(4);
17
+ if (!ref)
18
+ throw new Error('--store git: requires a ref');
19
+ return { reader: new GitReportReader(root, ref) };
20
+ }
21
+ const path = value === undefined ? resolve(root, '.repometry') : resolve(base, value);
22
+ return { path, reader: new LocalReportStore(path) };
23
+ }
24
+ export function writableStore(store) {
25
+ if (store.path === undefined)
26
+ throw new Error('Use a local store when writing inspections or reviews');
27
+ return store.path;
28
+ }
29
+ export async function isDirectory(path) {
30
+ try {
31
+ return (await lstat(path)).isDirectory();
32
+ }
33
+ catch (error) {
34
+ if (error instanceof Error && 'code' in error && (error.code === 'ENOENT' || error.code === 'ENOTDIR'))
35
+ return false;
36
+ throw error;
37
+ }
38
+ }
39
+ //# sourceMappingURL=store.js.map
@@ -0,0 +1,4 @@
1
+ import type { Plugin } from '../core/engine/plugin.js';
2
+ import type { Report } from '../core/model/report.js';
3
+ import type { AnalysisInput } from '../core/usecases/inspect.js';
4
+ export declare function analyzeSnapshot({ snapshot, excludedOutput, excludedPaths, coverage: inputCoverage }: AnalysisInput, additional?: readonly Plugin[]): Promise<Report>;