repometry 0.4.2 → 0.6.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 (269) hide show
  1. package/README.md +36 -14
  2. package/package.json +1 -1
  3. package/target/main/resources/report/json/comparison-v1.schema.json +6 -6
  4. package/target/main/resources/report/json/file-metrics-v1.schema.json +7 -6
  5. package/target/main/resources/report/json/pull-review-v1.schema.json +5 -5
  6. package/target/main/resources/report/json/report-v2.schema.json +210 -11
  7. package/target/main/resources/report/json/repository-summary-v1.schema.json +161 -14
  8. package/target/main/resources/report/json/viewer-inspection-v1.schema.json +518 -6
  9. package/target/main/resources/viewer/styles.css +7 -2
  10. package/target/main/ts/api/git/changes.d.ts +1 -1
  11. package/target/main/ts/api/git/changes.js +3 -3
  12. package/target/main/ts/api/git/commit-metadata.js +6 -4
  13. package/target/main/ts/api/git/git.d.ts +2 -1
  14. package/target/main/ts/api/git/git.js +16 -4
  15. package/target/main/ts/api/git/inspection-source.d.ts +1 -1
  16. package/target/main/ts/api/git/inspection-source.js +4 -10
  17. package/target/main/ts/api/git/local.d.ts +1 -1
  18. package/target/main/ts/api/git/local.js +41 -7
  19. package/target/main/ts/api/process/docker-tool-runner.d.ts +13 -0
  20. package/target/main/ts/api/process/docker-tool-runner.js +108 -0
  21. package/target/main/ts/api/process/failure.d.ts +1 -0
  22. package/target/main/ts/api/process/failure.js +12 -0
  23. package/target/main/ts/api/process/plugin.d.ts +10 -0
  24. package/target/main/ts/api/process/plugin.js +96 -0
  25. package/target/main/ts/api/worker/remote-executor.d.ts +1 -1
  26. package/target/main/ts/api/worker/remote-executor.js +2 -2
  27. package/target/main/ts/api/worker/worker-protocol.d.ts +2 -2
  28. package/target/main/ts/api/worker/worker-protocol.js +8 -8
  29. package/target/main/ts/api/worker/worker.d.ts +1 -1
  30. package/target/main/ts/api/worker/worker.js +4 -4
  31. package/target/main/ts/cli/main.js +4 -3
  32. package/target/main/ts/cli/reporting.d.ts +1 -1
  33. package/target/main/ts/cli/reporting.js +1 -1
  34. package/target/main/ts/compose/analysis-files.d.ts +13 -0
  35. package/target/main/ts/compose/analysis-files.js +95 -0
  36. package/target/main/ts/compose/analysis-imports.d.ts +7 -0
  37. package/target/main/ts/compose/analysis-imports.js +34 -0
  38. package/target/main/ts/compose/analysis-report.d.ts +5 -0
  39. package/target/main/ts/compose/analysis-report.js +78 -0
  40. package/target/main/ts/compose/analysis-repository.d.ts +6 -0
  41. package/target/main/ts/compose/analysis-repository.js +61 -0
  42. package/target/main/ts/compose/analysis-results.d.ts +38 -0
  43. package/target/main/ts/compose/analysis-results.js +78 -0
  44. package/target/main/ts/compose/analysis-sources.d.ts +73 -0
  45. package/target/main/ts/compose/analysis-sources.js +47 -0
  46. package/target/main/ts/compose/analyze-snapshot.d.ts +3 -2
  47. package/target/main/ts/compose/analyze-snapshot.js +19 -197
  48. package/target/main/ts/compose/diff-coverage.d.ts +2 -0
  49. package/target/main/ts/compose/diff-coverage.js +6 -4
  50. package/target/main/ts/compose/inspect.d.ts +5 -0
  51. package/target/main/ts/compose/inspect.js +14 -7
  52. package/target/main/ts/compose/languages.d.ts +29 -0
  53. package/target/main/ts/compose/languages.js +87 -0
  54. package/target/main/ts/compose/sources.js +14 -12
  55. package/target/main/ts/core/engine/execute.d.ts +3 -1
  56. package/target/main/ts/core/engine/execute.js +14 -2
  57. package/target/main/ts/core/engine/manifest.d.ts +2 -2
  58. package/target/main/ts/core/engine/manifest.js +25 -5
  59. package/target/main/ts/core/engine/operation-cache.d.ts +14 -0
  60. package/target/main/ts/core/engine/operation-cache.js +66 -0
  61. package/target/main/ts/core/engine/plan.d.ts +3 -4
  62. package/target/main/ts/core/engine/plan.js +28 -11
  63. package/target/main/ts/core/engine/plugin.d.ts +10 -2
  64. package/target/main/ts/core/engine/plugin.js +1 -3
  65. package/target/main/ts/core/engine/report-products.js +2 -13
  66. package/target/main/ts/core/model/clone-source.d.ts +1 -0
  67. package/target/main/ts/core/model/clone-source.js +2 -1
  68. package/target/main/ts/core/model/code-structure.d.ts +5 -0
  69. package/target/main/ts/core/model/code-structure.js +10 -1
  70. package/target/main/ts/core/model/finding-ignore.js +1 -1
  71. package/target/main/ts/core/model/finding.js +1 -1
  72. package/target/main/ts/core/model/language.d.ts +10 -0
  73. package/target/main/ts/core/model/language.js +6 -0
  74. package/target/main/ts/core/model/line-coverage.d.ts +5 -1
  75. package/target/main/ts/core/model/line-coverage.js +14 -11
  76. package/target/main/ts/core/model/measurement.d.ts +7 -6
  77. package/target/main/ts/core/model/measurement.js +18 -7
  78. package/target/main/ts/core/model/plugin-data.d.ts +5 -0
  79. package/target/main/ts/core/model/plugin-data.js +15 -1
  80. package/target/main/ts/core/model/quality-summary.js +6 -5
  81. package/target/main/ts/core/model/report.d.ts +1 -2
  82. package/target/main/ts/core/model/report.js +0 -1
  83. package/target/main/ts/core/model/scanner-import.js +1 -1
  84. package/target/main/ts/core/model/snapshot.d.ts +1 -2
  85. package/target/main/ts/core/model/snapshot.js +5 -7
  86. package/target/main/ts/core/model/source.d.ts +3 -0
  87. package/target/main/ts/core/model/source.js +15 -0
  88. package/target/main/ts/core/ports/tool-runner.d.ts +18 -0
  89. package/target/main/ts/core/ports/tool-runner.js +2 -0
  90. package/target/main/ts/core/usecases/compare.js +61 -17
  91. package/target/main/ts/core/usecases/inspect.js +2 -2
  92. package/target/main/ts/plugin.d.ts +10 -3
  93. package/target/main/ts/plugin.js +4 -2
  94. package/target/main/ts/plugins/coverage/coverage.d.ts +5 -2
  95. package/target/main/ts/plugins/coverage/coverage.js +35 -10
  96. package/target/main/ts/plugins/duplication/duplication.js +10 -4
  97. package/target/main/ts/plugins/language-js/babel-provider.js +8 -2
  98. package/target/main/ts/plugins/language-js/extensions.d.ts +3 -0
  99. package/target/main/ts/plugins/language-js/extensions.js +4 -0
  100. package/target/main/ts/plugins/language-js/function-facts.d.ts +1 -0
  101. package/target/main/ts/plugins/language-js/function-facts.js +30 -4
  102. package/target/main/ts/plugins/language-js/js-security.js +3 -2
  103. package/target/main/ts/report/html/app/viewer-chart-bars.d.ts +11 -0
  104. package/target/main/ts/report/html/app/viewer-chart-bars.js +54 -0
  105. package/target/main/ts/report/html/app/viewer-chart-label.d.ts +15 -0
  106. package/target/main/ts/report/html/app/viewer-chart-label.js +43 -0
  107. package/target/main/ts/report/html/app/viewer-chart-line.d.ts +24 -0
  108. package/target/main/ts/report/html/app/viewer-chart-line.js +89 -0
  109. package/target/main/ts/report/html/app/viewer-chart-points.d.ts +49 -0
  110. package/target/main/ts/report/html/app/viewer-chart-points.js +74 -0
  111. package/target/main/ts/report/html/app/viewer-chart-scale.d.ts +21 -0
  112. package/target/main/ts/report/html/app/viewer-chart-scale.js +93 -0
  113. package/target/main/ts/report/html/app/viewer-chart-svg.d.ts +28 -0
  114. package/target/main/ts/report/html/app/viewer-chart-svg.js +41 -0
  115. package/target/main/ts/report/html/app/viewer-chart-time.d.ts +26 -0
  116. package/target/main/ts/report/html/app/viewer-chart-time.js +150 -0
  117. package/target/main/ts/report/html/app/viewer-chart-tip.d.ts +4 -0
  118. package/target/main/ts/report/html/app/viewer-chart-tip.js +210 -0
  119. package/target/main/ts/report/html/app/viewer-chart-x.d.ts +12 -0
  120. package/target/main/ts/report/html/app/viewer-chart-x.js +50 -0
  121. package/target/main/ts/report/html/app/viewer-chart.d.ts +4 -98
  122. package/target/main/ts/report/html/app/viewer-chart.js +16 -677
  123. package/target/main/ts/report/html/app/viewer-code-map.d.ts +27 -0
  124. package/target/main/ts/report/html/app/viewer-code-map.js +175 -0
  125. package/target/main/ts/report/html/app/viewer-columns.d.ts +38 -0
  126. package/target/main/ts/report/html/app/viewer-columns.js +92 -0
  127. package/target/main/ts/report/html/app/viewer-commit-picker.d.ts +12 -0
  128. package/target/main/ts/report/html/app/viewer-commit-picker.js +229 -0
  129. package/target/main/ts/report/html/app/viewer-commits.d.ts +5 -9
  130. package/target/main/ts/report/html/app/viewer-commits.js +17 -216
  131. package/target/main/ts/report/html/app/viewer-controls.d.ts +43 -0
  132. package/target/main/ts/report/html/app/viewer-controls.js +141 -0
  133. package/target/main/ts/report/html/app/viewer-copy.d.ts +17 -0
  134. package/target/main/ts/report/html/app/viewer-copy.js +64 -0
  135. package/target/main/ts/report/html/app/viewer-data.d.ts +1 -1
  136. package/target/main/ts/report/html/app/viewer-data.js +2 -29
  137. package/target/main/ts/report/html/app/viewer-diagnostics.d.ts +4 -0
  138. package/target/main/ts/report/html/app/viewer-diagnostics.js +60 -0
  139. package/target/main/ts/report/html/app/viewer-dom.d.ts +27 -0
  140. package/target/main/ts/report/html/app/viewer-dom.js +99 -0
  141. package/target/main/ts/report/html/app/viewer-file-aside.d.ts +19 -0
  142. package/target/main/ts/report/html/app/viewer-file-aside.js +124 -0
  143. package/target/main/ts/report/html/app/viewer-file-figures.d.ts +15 -0
  144. package/target/main/ts/report/html/app/viewer-file-figures.js +60 -0
  145. package/target/main/ts/report/html/app/viewer-file-source.d.ts +7 -0
  146. package/target/main/ts/report/html/app/viewer-file-source.js +119 -0
  147. package/target/main/ts/report/html/app/viewer-files.d.ts +2 -118
  148. package/target/main/ts/report/html/app/viewer-files.js +24 -2184
  149. package/target/main/ts/report/html/app/viewer-filter.d.ts +3 -51
  150. package/target/main/ts/report/html/app/viewer-filter.js +111 -450
  151. package/target/main/ts/report/html/app/viewer-hotspots.d.ts +4 -0
  152. package/target/main/ts/report/html/app/viewer-hotspots.js +131 -0
  153. package/target/main/ts/report/html/app/viewer-inspection.d.ts +69 -0
  154. package/target/main/ts/report/html/app/viewer-inspection.js +36 -0
  155. package/target/main/ts/report/html/app/viewer-issue-group.d.ts +27 -0
  156. package/target/main/ts/report/html/app/viewer-issue-group.js +174 -0
  157. package/target/main/ts/report/html/app/viewer-issues.d.ts +4 -0
  158. package/target/main/ts/report/html/app/viewer-issues.js +173 -0
  159. package/target/main/ts/report/html/app/viewer-language-bar.d.ts +9 -0
  160. package/target/main/ts/report/html/app/viewer-language-bar.js +72 -0
  161. package/target/main/ts/report/html/app/viewer-languages.d.ts +27 -0
  162. package/target/main/ts/report/html/app/viewer-languages.js +93 -0
  163. package/target/main/ts/report/html/app/viewer-layout.d.ts +14 -0
  164. package/target/main/ts/report/html/app/viewer-layout.js +134 -0
  165. package/target/main/ts/report/html/app/viewer-line-coverage.d.ts +47 -0
  166. package/target/main/ts/report/html/app/viewer-line-coverage.js +121 -0
  167. package/target/main/ts/report/html/app/viewer-locations.d.ts +16 -0
  168. package/target/main/ts/report/html/app/viewer-locations.js +31 -0
  169. package/target/main/ts/report/html/app/viewer-map-scale.d.ts +26 -0
  170. package/target/main/ts/report/html/app/viewer-map-scale.js +147 -0
  171. package/target/main/ts/report/html/app/viewer-map-shape.d.ts +42 -0
  172. package/target/main/ts/report/html/app/viewer-map-shape.js +102 -0
  173. package/target/main/ts/report/html/app/viewer-metric-format.d.ts +23 -0
  174. package/target/main/ts/report/html/app/viewer-metric-format.js +93 -0
  175. package/target/main/ts/report/html/app/viewer-metric-registry.d.ts +0 -20
  176. package/target/main/ts/report/html/app/viewer-metric-registry.js +7 -84
  177. package/target/main/ts/report/html/app/viewer-metrics-view.d.ts +4 -0
  178. package/target/main/ts/report/html/app/viewer-metrics-view.js +162 -0
  179. package/target/main/ts/report/html/app/viewer-metrics.d.ts +6 -1
  180. package/target/main/ts/report/html/app/viewer-metrics.js +53 -35
  181. package/target/main/ts/report/html/app/viewer-overview-cards.d.ts +12 -0
  182. package/target/main/ts/report/html/app/viewer-overview-cards.js +118 -0
  183. package/target/main/ts/report/html/app/viewer-overview-hotspots.d.ts +9 -0
  184. package/target/main/ts/report/html/app/viewer-overview-hotspots.js +173 -0
  185. package/target/main/ts/report/html/app/viewer-overview-lead.d.ts +12 -0
  186. package/target/main/ts/report/html/app/viewer-overview-lead.js +116 -0
  187. package/target/main/ts/report/html/app/viewer-profile-badges.d.ts +11 -0
  188. package/target/main/ts/report/html/app/viewer-profile-badges.js +119 -0
  189. package/target/main/ts/report/html/app/viewer-profile-table.d.ts +29 -0
  190. package/target/main/ts/report/html/app/viewer-profile-table.js +124 -0
  191. package/target/main/ts/report/html/app/viewer-profile.d.ts +2 -6
  192. package/target/main/ts/report/html/app/viewer-profile.js +6 -248
  193. package/target/main/ts/report/html/app/viewer-pull-sections.d.ts +4 -0
  194. package/target/main/ts/report/html/app/viewer-pull-sections.js +118 -0
  195. package/target/main/ts/report/html/app/viewer-pull-trend.d.ts +5 -0
  196. package/target/main/ts/report/html/app/viewer-pull-trend.js +63 -0
  197. package/target/main/ts/report/html/app/viewer-pulls.d.ts +0 -1
  198. package/target/main/ts/report/html/app/viewer-pulls.js +28 -178
  199. package/target/main/ts/report/html/app/viewer-query-field.d.ts +19 -0
  200. package/target/main/ts/report/html/app/viewer-query-field.js +203 -0
  201. package/target/main/ts/report/html/app/viewer-route.d.ts +34 -0
  202. package/target/main/ts/report/html/app/viewer-route.js +55 -0
  203. package/target/main/ts/report/html/app/viewer-shell.d.ts +20 -0
  204. package/target/main/ts/report/html/app/viewer-shell.js +116 -0
  205. package/target/main/ts/report/html/app/viewer-source-view.d.ts +49 -0
  206. package/target/main/ts/report/html/app/viewer-source-view.js +150 -0
  207. package/target/main/ts/report/html/app/viewer-source.d.ts +0 -84
  208. package/target/main/ts/report/html/app/viewer-source.js +7 -365
  209. package/target/main/ts/report/html/app/viewer-suggest.d.ts +13 -0
  210. package/target/main/ts/report/html/app/viewer-suggest.js +91 -0
  211. package/target/main/ts/report/html/app/viewer-sunburst.d.ts +5 -0
  212. package/target/main/ts/report/html/app/viewer-sunburst.js +40 -0
  213. package/target/main/ts/report/html/app/viewer-table-cells.d.ts +25 -0
  214. package/target/main/ts/report/html/app/viewer-table-cells.js +129 -0
  215. package/target/main/ts/report/html/app/viewer-table-rows.d.ts +54 -0
  216. package/target/main/ts/report/html/app/viewer-table-rows.js +95 -0
  217. package/target/main/ts/report/html/app/viewer-tokenizer.d.ts +16 -0
  218. package/target/main/ts/report/html/app/viewer-tokenizer.js +192 -0
  219. package/target/main/ts/report/html/app/viewer-totals.d.ts +14 -0
  220. package/target/main/ts/report/html/app/viewer-totals.js +89 -0
  221. package/target/main/ts/report/html/app/viewer-treemap.d.ts +24 -0
  222. package/target/main/ts/report/html/app/viewer-treemap.js +112 -0
  223. package/target/main/ts/report/html/app/viewer-trend-data.d.ts +54 -0
  224. package/target/main/ts/report/html/app/viewer-trend-data.js +109 -0
  225. package/target/main/ts/report/html/app/viewer-trend-nav.d.ts +5 -0
  226. package/target/main/ts/report/html/app/viewer-trend-nav.js +85 -0
  227. package/target/main/ts/report/html/app/viewer-trend-points.d.ts +30 -0
  228. package/target/main/ts/report/html/app/viewer-trend-points.js +128 -0
  229. package/target/main/ts/report/html/app/viewer-trend-series.d.ts +26 -0
  230. package/target/main/ts/report/html/app/viewer-trend-series.js +98 -0
  231. package/target/main/ts/report/html/app/viewer-trends.d.ts +2 -70
  232. package/target/main/ts/report/html/app/viewer-trends.js +41 -392
  233. package/target/main/ts/report/html/app/viewer.js +152 -663
  234. package/target/main/ts/report/html/site/export-site.d.ts +3 -4
  235. package/target/main/ts/report/html/site/export-site.js +24 -41
  236. package/target/main/ts/report/html/site/exported-server.js +2 -1
  237. package/target/main/ts/report/html/site/local-server.d.ts +1 -1
  238. package/target/main/ts/report/html/site/local-server.js +13 -19
  239. package/target/main/ts/report/html/site/projects.js +8 -17
  240. package/target/main/ts/report/json/projections/commit-summary.d.ts +2 -2
  241. package/target/main/ts/report/json/projections/commit-summary.js +18 -19
  242. package/target/main/ts/report/json/projections/file-metrics.js +31 -24
  243. package/target/main/ts/report/json/projections/inspection-context.js +10 -1
  244. package/target/main/ts/report/json/projections/inspection-details.d.ts +1 -1
  245. package/target/main/ts/report/json/projections/inspection-details.js +2 -2
  246. package/target/main/ts/report/json/projections/metric-values.d.ts +1 -0
  247. package/target/main/ts/report/json/projections/metric-values.js +15 -5
  248. package/target/main/ts/report/json/store/local-store.js +2 -12
  249. package/target/main/ts/report/json/store/operation-cache.d.ts +8 -0
  250. package/target/main/ts/report/json/store/operation-cache.js +32 -0
  251. package/target/main/ts/report/json/store/pull-review-store.js +1 -2
  252. package/target/main/ts/report/json/store/replace-file.d.ts +1 -0
  253. package/target/main/ts/report/json/store/replace-file.js +14 -0
  254. package/target/main/ts/report/json/validation/report.d.ts +1 -1
  255. package/target/main/ts/report/json/validation/report.js +10 -8
  256. package/target/main/ts/report/json/validation/summary-validation.js +1 -3
  257. package/target/main/ts/report/json/wire/file-metrics-model.d.ts +2 -0
  258. package/target/main/ts/report/json/wire/inspection-details-model.d.ts +0 -5
  259. package/target/main/ts/report/json/wire/public-history-model.d.ts +0 -6
  260. package/target/main/ts/report/json/wire/public-history-model.js +0 -1
  261. package/target/main/ts/report.d.ts +3 -3
  262. package/target/main/ts/report.js +2 -2
  263. package/target/main/resources/report/json/inspection-context-v1.schema.json +0 -172
  264. package/target/main/resources/report/json/public-history-v1.schema.json +0 -50
  265. package/target/main/resources/report/json/quality-history-v1.schema.json +0 -51
  266. package/target/main/resources/report/json/report-v1.schema.json +0 -65
  267. package/target/main/resources/report/json/viewer-details-v1.schema.json +0 -346
  268. package/target/main/ts/report/json/projections/public-history.d.ts +0 -4
  269. package/target/main/ts/report/json/projections/public-history.js +0 -17
@@ -1,199 +1,21 @@
1
- import { extname } from 'node:path';
2
- import { execute } from '../core/engine/execute.js';
3
- import { plan } from '../core/engine/plan.js';
4
- import { ReportProducts } from '../core/engine/report-products.js';
5
- import { definitions } from '../core/model/measurement.js';
6
- import { debtModel } from '../core/model/quality-summary.js';
7
- import { reportSchema } from '../core/model/report.js';
8
- import { comparePaths, digest, isSourcePath, sourceDirectoriesExcluded, sourceExtensions, sourceFile, sourceLineCounts, textLineCount } from '../core/model/snapshot.js';
9
- import { isClaimedText, maxClaimedFileBytes } from '../core/model/source.js';
10
- import { defaultSourceExclusions, exclusionMatcher, generatedSourcePolicy, sourceExclusionMatcher } from '../core/profile/exclusions.js';
11
- import { duplicationSettings, structuralRules } from '../core/profile/maintainability.js';
12
- import { coverage, coverageResult, lcovInput } from '../plugins/coverage/coverage.js';
13
- import { duplication, duplicationInput } from '../plugins/duplication/duplication.js';
14
- import { babelProvider, babelTypes, parserDefaults } from '../plugins/language-js/babel-provider.js';
15
- import { fileQuality, maintainability } from '../plugins/maintainability/maintainability.js';
16
- import { structure } from '../plugins/structure/structure.js';
17
- import { securityPlugins } from './security-plugins.js';
18
- const sourcePlugins = [babelProvider, { ...structure, tools: babelTypes }, { ...maintainability, tools: babelTypes }];
19
- const selected = ['structure/size', 'structure/complexity', 'maintainability/file'];
20
- const bindings = new Map(selected.map(operation => [operation, { syntax: { operation: 'babel-syntax/parse' } }]));
21
- const sourcePlan = plan({ plugins: sourcePlugins, select: selected, inputs: new Map([['file', sourceFile.id]]), bindings });
22
- const duplicationPlan = plan({ plugins: [duplication], select: ['duplication/detect'], inputs: new Map([['sources', duplicationInput.id]]) });
23
- const coveragePlan = plan({ plugins: [coverage], select: ['lcov/import', 'lcov/lines'], inputs: new Map([['lcov', lcovInput.id]]) });
24
- const securityClaims = securityPlugins.map(plugin => claimMatcher(plugin.claims));
25
- export function claimsNativeFile(path) {
26
- return securityClaims.some(match => match(path));
27
- }
28
- const measurementDefinitions = {
29
- [definitions.lines]: 'Physical lines including blank lines and comments. A final line terminator does not add a line.',
30
- [definitions.functions]: 'Babel function nodes with bodies, including nested functions and methods.',
31
- [definitions.complexity]: 'One plus branches in the function body: if, ternary, loops, catch, non-default switch cases and logical operators. Nested functions are measured separately. Line and column are 1-based and columns count UTF-16 units.',
32
- [definitions.coverage]: 'Distinct covered code lines divided by the distinct code lines listed in LCOV DA records. Hit counts are summed across records. A zero denominator has no ratio.',
33
- [definitions.codeLines]: 'Nonblank physical lines after removing Babel comment spans and the interpreter directive. A line containing both code and a comment counts as code.',
34
- [definitions.comments]: 'Physical lines containing only a Babel comment or interpreter directive.',
35
- [definitions.classes]: 'Babel class declaration and expression nodes.',
36
- [definitions.cognitiveComplexity]: 'Flow breaks plus nesting weight and logical operator sequences. Nested functions are measured separately. File complexity sums functions and module-level flow breaks.',
37
- [definitions.duplicatedLines]: 'Distinct code lines inside repeated Babel syntax subtrees, including original and repeated occurrences. Identifier and literal spellings are ignored for similar-code matches.',
38
- };
39
- export async function analyzeSnapshot({ snapshot, excludedOutput, excludedPaths = [], coverage: inputCoverage }, additional = []) {
40
- const rows = [];
41
- const diagnostics = (snapshot.oversizedClaims ?? []).map(oversizedClaim);
42
- const findings = [];
43
- const cloneSources = [];
44
- const sourceFiles = snapshot.files.filter(file => isSourcePath(file.path));
45
- const claimedPlugins = [...securityPlugins.filter(plugin => !additional.includes(plugin)), ...additional];
46
- const enabled = [...sourcePlugins, duplication, ...(inputCoverage === undefined ? [] : [coverage])];
47
- const plugins = [...enabled, ...claimedPlugins];
48
- if (additional.length)
49
- plan({ plugins, select: [], inputs: new Map() });
50
- if (inputCoverage === undefined && additional.some(plugin => plugin.id === coverage.id))
51
- throw new Error('An additional plugin uses a built-in plugin ID');
52
- const reportProducts = new ReportProducts(plugins);
53
- const sourcePlans = new Map([['[true]', sourcePlan]]);
54
- const usedPlans = new Map(sourcePlan.map(task => [task.key, task]));
55
- const matches = claimedPlugins.map(plugin => claimMatcher(plugin.claims));
56
- const parsed = new Set();
57
- const inspected = new Set();
58
- const scanned = new Set();
59
- let completedFileInspection = false;
60
- const scanOnlyOperations = new Set(plugins.filter(plugin => plugin.claims?.scanOnly).flatMap(({ id, operations }) => operations.map(operation => `${id}/${operation.id}`)));
61
- const securityOperations = new Map(claimedPlugins.filter(plugin => plugin.kinds.includes('security')).flatMap(plugin => plugin.operations.filter(operation => operation.role === 'inspection').map(operation => [`${plugin.id}/${operation.id}`, plugin.id])));
62
- for (const file of snapshot.files) {
63
- const source = isSourcePath(file.path);
64
- const claimed = claimedPlugins.filter((_, index) => matches[index](file.path));
65
- const selectedPlugins = isClaimedText(file.bytes) ? claimed : [];
66
- if (claimed.length && file.bytes.byteLength > maxClaimedFileBytes)
67
- diagnostics.push(oversizedClaim(file.path));
68
- if (!source && !selectedPlugins.length)
69
- continue;
70
- const groupKey = JSON.stringify([source, ...selectedPlugins.map(plugin => plugin.id)]);
71
- const tasks = sourcePlans.get(groupKey) ?? plan({
72
- plugins: source ? [...sourcePlugins, ...claimedPlugins] : selectedPlugins,
73
- select: [...(source ? selected : []), ...selectedPlugins.flatMap(plugin => plugin.operations
74
- .filter(operation => operation.role === 'inspection').map(operation => `${plugin.id}/${operation.id}`))],
75
- inputs: new Map([['file', sourceFile.id]]), ...(source ? { bindings } : {}),
76
- });
77
- sourcePlans.set(groupKey, tasks);
78
- const results = await execute(tasks, new Map([['file', { contract: sourceFile.id, value: file }]]));
79
- if (results.get('babel-syntax/parse')?.state === 'completed')
80
- parsed.add(file.path);
81
- for (const task of tasks) {
82
- usedPlans.set(task.key, task);
83
- const outcome = results.get(task.key);
84
- record(task, outcome, file.path);
85
- if (outcome.state === 'completed' && outcome.product.contract === fileQuality.id && fileQuality.accepts(outcome.product.value)) {
86
- cloneSources.push(outcome.product.value.cloneSource);
87
- }
88
- }
89
- }
90
- const copies = (await execute(duplicationPlan, new Map([['sources', { contract: duplicationInput.id, value: cloneSources }]])))
91
- .get('duplication/detect');
92
- record(duplicationPlan[0], copies);
93
- if (inputCoverage !== undefined) {
94
- const value = { text: inputCoverage.text, root: inputCoverage.sourceRoot, sourceLines: sourceLineCounts(sourceFiles),
95
- codeLines: new Map(cloneSources.map(({ path, codeLines }) => [path, new Set(codeLines)])),
96
- excludes: sourceExclusionMatcher(excludedPaths, snapshot.generatedExcluded) };
97
- const outcomes = await execute(coveragePlan, new Map([['lcov', { contract: lcovInput.id, value }]]));
98
- for (const task of coveragePlan)
99
- record(task, outcomes.get(task.key));
100
- const result = outcomes.get('lcov/import');
101
- if (result.state === 'completed' && coverageResult.accepts(result.product.value)) {
102
- for (const { path, reason } of result.product.value.gaps) {
103
- diagnostics.push({ operation: 'lcov/import', state: 'partial', path, message: reason });
104
- }
105
- }
106
- }
107
- const pluginData = reportProducts.result();
108
- const securityScanners = claimedPlugins.filter(plugin => scanned.has(plugin.id)).map(({ id, version }) => ({ name: id, version }));
109
- const inventory = new Map((snapshot.inventory ?? []).map(({ path, lines, bytes }) => [path, { lines, bytes }]));
110
- for (const { path, bytes } of snapshot.files) {
111
- if (!inventory.has(path))
112
- inventory.set(path, { lines: textLineCount(bytes), bytes: bytes.length });
113
- }
114
- return {
115
- schema: reportSchema,
116
- subject: snapshot.subject,
117
- generatedAt: new Date().toISOString(),
118
- appliedConfig: {
119
- profile: 'js-ts/v2', mode: snapshot.subject.kind,
120
- source: { extensions: sourceExtensions, excludedDirectories: sourceDirectoriesExcluded, excludedOutput, excludedPaths,
121
- defaultExclusions: defaultSourceExclusions, generatedSourcePolicy, generatedExcluded: snapshot.generatedExcluded ?? [] },
122
- parser: parserDefaults,
123
- maintainability: { structuralRules, duplication: duplicationSettings, debtModel, remediation: 'nonoverlapping-complexity/v1' },
124
- coverage: inputCoverage === undefined ? null : { inputDigest: digest(inputCoverage.text), pathBase: inputCoverage.sourceRoot,
125
- merge: 'any-hit', hitCounts: 'sum', lines: 'code-only' },
126
- ...(securityScanners.length ? { securityScanners } : {}),
127
- plugins: plugins.map(({ id, version, api, tools, kinds, claims }) => ({ id, version, api, tools: tools ?? {}, ...(kinds === undefined ? {} : { kinds }), ...(claims === undefined ? {} : { claims }) })),
128
- operations: [...usedPlans.values(), ...duplicationPlan, ...(inputCoverage === undefined ? [] : coveragePlan)]
129
- .map(task => ({ key: task.key, inputs: Object.fromEntries(task.inputs) })),
130
- },
131
- definitions: { ...Object.fromEntries((pluginData?.metrics ?? []).map(metric => [metric.id, metric.description ?? metric.label])),
132
- ...measurementDefinitions },
133
- scope: { files: sourceFiles.length, parsed: parsed.size },
134
- status: diagnostics.length > 0 ? 'partial' : sourceFiles.length === 0 && !completedFileInspection ? 'not-applicable' : 'complete',
135
- measurements: rows,
136
- diagnostics,
137
- findings,
138
- ...(pluginData === undefined ? {} : { pluginData: { ...pluginData,
139
- inventory: [...inventory].sort(([left], [right]) => comparePaths(left, right)).map(([path, { lines, bytes }]) => ({ path, lines, ...(bytes === undefined ? {} : { bytes }), language: languageId(path), analysed: parsed.has(path) || inspected.has(path) })) } }),
140
- };
141
- function record(task, outcome, path) {
142
- if (outcome.state !== 'completed') {
143
- diagnostics.push(diagnostic(task.key, outcome, path));
144
- return;
145
- }
146
- try {
147
- const stored = reportProducts.record(task, outcome.product, path);
148
- if (path !== undefined && task.operation.role === 'inspection') {
149
- completedFileInspection = true;
150
- if (!scanOnlyOperations.has(task.key))
151
- inspected.add(path);
152
- }
153
- const scanner = securityOperations.get(task.key);
154
- if (scanner)
155
- scanned.add(scanner);
156
- if (stored) {
157
- rows.push(...stored.measurements);
158
- findings.push(...stored.findings);
159
- }
160
- }
161
- catch (error) {
162
- diagnostics.push({ operation: task.key, state: 'failed', path, message: error instanceof Error ? error.message : String(error) });
163
- }
164
- }
165
- }
166
- function oversizedClaim(path) {
167
- return { operation: 'source/claims', state: 'partial', path, message: 'Plugin inspection skipped a file larger than 1 MiB' };
168
- }
169
- function languageId(path) {
170
- const suffix = extname(path).toLowerCase();
171
- if (['.js', '.mjs', '.cjs', '.jsx'].includes(suffix))
172
- return 'javascript';
173
- if (['.ts', '.mts', '.cts', '.tsx'].includes(suffix))
174
- return 'typescript';
175
- if (suffix === '.md' || suffix === '.mdx')
176
- return 'markdown';
177
- if (suffix === '.yml')
178
- return 'yaml';
179
- if (suffix === '.py')
180
- return 'python';
181
- if (suffix === '.rs')
182
- return 'rust';
183
- if (suffix === '.kt' || suffix === '.kts')
184
- return 'kotlin';
185
- return suffix.slice(1) || 'other';
186
- }
187
- function claimMatcher(claims) {
188
- const { extensions = [], globs = [], languages = [] } = claims ?? {};
189
- if (extensions.length === 0 && globs.length === 0 && languages.length === 0)
190
- return () => true;
191
- const glob = exclusionMatcher(globs);
192
- const suffixes = new Set(extensions);
193
- const languageSet = new Set(languages);
194
- return path => suffixes.has(extname(path)) || glob(path) || languageSet.has(languageId(path));
195
- }
196
- function diagnostic(operation, outcome, path) {
197
- return { operation, state: outcome.state, message: outcome.reason, ...(path === undefined ? {} : { path }) };
1
+ import { defaultFilePlan, inspectFiles } from './analysis-files.js';
2
+ import { importAnalysisCoverage, inspectDuplication } from './analysis-imports.js';
3
+ import { collectRepositorySyntax, inspectRepositories } from './analysis-repository.js';
4
+ import { assembleAnalysisReport } from './analysis-report.js';
5
+ import { AnalysisResults } from './analysis-results.js';
6
+ import { selectAnalysisSources } from './analysis-sources.js';
7
+ export { inspectionFileMatcher } from './analysis-sources.js';
8
+ export async function analyzeSnapshot(input, additional = [], cache) {
9
+ const withCoverage = input.coverage !== undefined;
10
+ const sources = selectAnalysisSources(input.snapshot, additional, withCoverage);
11
+ const results = new AnalysisResults(sources.plugins, sources.claimedPlugins, input.snapshot.oversizedClaims ?? []);
12
+ for (const task of defaultFilePlan)
13
+ results.remember(task);
14
+ const batchFacts = await collectRepositorySyntax(sources, results, cache);
15
+ const files = await inspectFiles(sources, batchFacts, results, withCoverage, cache);
16
+ await inspectRepositories(sources, results, cache);
17
+ await inspectDuplication(files, results, cache);
18
+ await importAnalysisCoverage(input, sources, files, results, cache);
19
+ return assembleAnalysisReport(input, sources, results);
198
20
  }
199
21
  //# sourceMappingURL=analyze-snapshot.js.map
@@ -1,3 +1,4 @@
1
+ import type { Plugin } from '../core/engine/plugin.js';
1
2
  import type { DiffCoveragePorts, DiffCoverageReport } from '../core/usecases/diff-coverage.js';
2
3
  import type { LcovFiles } from '../api/import/lcov-files.js';
3
4
  export { diffCoverageSchema } from '../core/usecases/diff-coverage.js';
@@ -9,6 +10,7 @@ export interface DiffCoverageRequest {
9
10
  readonly lcov: LcovFiles;
10
11
  readonly exclude?: readonly string[];
11
12
  readonly minimumPercent?: number;
13
+ readonly plugins?: readonly Plugin[];
12
14
  }
13
15
  export declare function measureDiffCoverage(request: DiffCoverageRequest, overrides?: Partial<DiffCoveragePorts>): Promise<DiffCoverageReport>;
14
16
  export declare function measureChangedLines(request: DiffCoverageRequest, overrides?: Partial<DiffCoveragePorts>): Promise<{
@@ -1,6 +1,6 @@
1
1
  import { execute } from '../core/engine/execute.js';
2
2
  import { plan } from '../core/engine/plan.js';
3
- import { digest, sourceDirectoriesExcluded, sourceExtensions, sourceLineCounts } from '../core/model/snapshot.js';
3
+ import { digest, sourceDirectoriesExcluded, sourceLineCounts } from '../core/model/snapshot.js';
4
4
  import { executeDiffCoverage } from '../core/usecases/diff-coverage.js';
5
5
  import { defaultSourceExclusions, generatedSourcePolicy, sourceExclusionMatcher } from '../core/profile/exclusions.js';
6
6
  import { coverage, lcovInput } from '../plugins/coverage/coverage.js';
@@ -8,6 +8,7 @@ import { changesInput, diffCoverage, diffCoverageResult } from '../plugins/cover
8
8
  import { diffMethod, findMergeBase, readChanges } from '../api/git/changes.js';
9
9
  import { gitText, physicalGitRoot, readGitCommit, resolveGitCommit } from '../api/git/git.js';
10
10
  import { readLcovFiles } from '../api/import/lcov-files.js';
11
+ import { defaultLanguages, languageRegistry } from './languages.js';
11
12
  export { diffCoverageSchema } from '../core/usecases/diff-coverage.js';
12
13
  const operation = 'diff-coverage/measure';
13
14
  const steps = plan({ plugins: [diffCoverage], select: [operation],
@@ -43,10 +44,11 @@ async function readInputs(request, excludedPaths, excludes) {
43
44
  gitText(root, ['--version']).then(text => text.trim()),
44
45
  ]);
45
46
  const base = await findMergeBase(root, requestedBase, head);
46
- const snapshot = await readGitCommit(root, head, excludes);
47
- const changes = await readChanges(root, base, snapshot, sourceExclusionMatcher(excludedPaths, snapshot.generatedExcluded));
47
+ const { isSource, extensions, globs } = request.plugins?.length ? languageRegistry(request.plugins) : defaultLanguages;
48
+ const snapshot = await readGitCommit(root, head, excludes, isSource);
49
+ const changes = await readChanges(root, base, snapshot, sourceExclusionMatcher(excludedPaths, snapshot.generatedExcluded), isSource);
48
50
  return { requestedBase, base, head, snapshot, changes, root, lcovText: lcov.text, appliedConfig: {
49
- source: { extensions: sourceExtensions, excludedDirectories: sourceDirectoriesExcluded, excludedPaths,
51
+ source: { extensions, ...(globs.length ? { globs } : {}), excludedDirectories: sourceDirectoriesExcluded, excludedPaths,
50
52
  defaultExclusions: defaultSourceExclusions, generatedSourcePolicy, generatedExcluded: snapshot.generatedExcluded ?? [] },
51
53
  gitDiff: { ...diffMethod, version: gitVersion },
52
54
  lcov: { inputDigest: digest(lcov.text), pathBase: root, merge: 'any-hit', importerVersion: coverage.version,
@@ -1,4 +1,6 @@
1
1
  import type { LcovFiles } from '../api/import/lcov-files.js';
2
+ import type { OperationCacheOptions } from '../core/engine/operation-cache.js';
3
+ import type { Plugin } from '../core/engine/plugin.js';
2
4
  import type { FindingIgnoreRule } from '../core/model/finding-ignore.js';
3
5
  import type { Report } from '../core/model/report.js';
4
6
  import type { FindingInput } from '../core/model/scanner-import.js';
@@ -18,6 +20,9 @@ export interface InspectRequest {
18
20
  readonly findingInputs?: readonly FindingInput[];
19
21
  readonly findingRoot?: string;
20
22
  readonly ignore?: readonly FindingIgnoreRule[];
23
+ /** Trusted in-process plugins for the default executor. */
24
+ readonly plugins?: readonly Plugin[];
25
+ readonly operationCache?: OperationCacheOptions;
21
26
  }
22
27
  export declare function inspect(request: InspectRequest, overrides?: AnalysisExecutor | Partial<InspectionPorts>): Promise<Report>;
23
28
  export declare function attachFindings(report: Report, inputs: readonly FindingInput[], root: string, findingRoot: string, excludes: (path: string) => boolean): Promise<Report>;
@@ -7,23 +7,30 @@ import { reportSchema } from '../core/model/report.js';
7
7
  import { isExcludedDirectory } from '../core/model/snapshot.js';
8
8
  import { executeInspection } from '../core/usecases/inspect.js';
9
9
  import { LocalReportStore } from '../report/json/store/local-store.js';
10
- import { analyzeSnapshot, claimsNativeFile } from './analyze-snapshot.js';
10
+ import { analyzeSnapshot, inspectionFileMatcher } from './analyze-snapshot.js';
11
11
  import { attachChurn } from './attach-churn.js';
12
+ import { defaultLanguages, languageRegistry } from './languages.js';
12
13
  export { analyzeSnapshot } from './analyze-snapshot.js';
13
14
  export async function inspect(request, overrides) {
14
- const { lcov, findingInputs = [] } = request;
15
+ const { lcov, findingInputs = [], plugins = [], operationCache } = request;
16
+ if ((plugins.length || operationCache) && (typeof overrides === 'function' || overrides?.analyze)) {
17
+ throw new Error('Configure plugins and the operation cache on the custom executor');
18
+ }
19
+ const languages = plugins.length ? languageRegistry(plugins) : defaultLanguages;
20
+ const claims = inspectionFileMatcher(plugins, languages);
21
+ const { isSource } = languages;
15
22
  const ports = {
16
- readSource: excludes => readSource(request, excludes),
17
- analyze: analyzeSnapshot,
23
+ readSource: excludes => readSource(request, excludes, isSource, claims),
24
+ analyze: input => analyzeSnapshot(input, plugins, operationCache),
18
25
  ...(lcov === undefined ? {} : { readCoverage: () => readLcovFiles(lcov) }),
19
26
  ...(findingInputs.length === 0 ? {} : { importFindings: (report, root, excludes) => attachFindings(report, findingInputs, root, request.findingRoot === undefined ? root : resolve(request.findingRoot), excludes) }),
20
- recordChurn: attachChurn,
27
+ recordChurn: (report, root, paths) => attachChurn(report, root, paths.filter(isSource)),
21
28
  ...(typeof overrides === 'function' ? { analyze: overrides } : overrides),
22
29
  };
23
30
  return executeInspection(request, ports);
24
31
  }
25
- async function readSource(request, excludes) {
26
- const source = await readInspectionSource(request, excludes, claimsNativeFile);
32
+ async function readSource(request, excludes, isSource, claims) {
33
+ const source = await readInspectionSource(request, excludes, isSource, claims);
27
34
  const store = new LocalReportStore(source.output);
28
35
  return { ...source, save: (report) => store.save(report) };
29
36
  }
@@ -0,0 +1,29 @@
1
+ import type { FileClaims, Operation, Plugin } from '../core/engine/plugin.js';
2
+ import type { LanguageDisplay } from '../core/model/language.js';
3
+ export interface LanguageProvider {
4
+ readonly plugin: Plugin;
5
+ readonly operation: Operation;
6
+ readonly key: string;
7
+ readonly batch: boolean;
8
+ readonly language: (path: string) => string | undefined;
9
+ }
10
+ export declare const defaultLanguages: {
11
+ select(path: string): LanguageProvider | undefined;
12
+ isSource(path: string): boolean;
13
+ id(path: string): string;
14
+ readonly extensions: readonly string[];
15
+ readonly globs: readonly string[];
16
+ readonly catalog: readonly LanguageDisplay[];
17
+ readonly providers: readonly LanguageProvider[];
18
+ };
19
+ export declare function languageRegistry(plugins: readonly Plugin[]): {
20
+ select(path: string): LanguageProvider | undefined;
21
+ isSource(path: string): boolean;
22
+ id(path: string): string;
23
+ readonly extensions: readonly string[];
24
+ readonly globs: readonly string[];
25
+ readonly catalog: readonly LanguageDisplay[];
26
+ readonly providers: readonly LanguageProvider[];
27
+ };
28
+ export declare function languageId(path: string): string;
29
+ export declare function claimMatcher(claims: FileClaims | undefined, identify?: typeof languageId): (path: string) => boolean;
@@ -0,0 +1,87 @@
1
+ import { extname } from 'node:path';
2
+ import { codeStructure, codeStructures } from '../core/model/code-structure.js';
3
+ import { isExcludedDirectory } from '../core/model/snapshot.js';
4
+ import { exclusionMatcher } from '../core/profile/exclusions.js';
5
+ import { babelProvider } from '../plugins/language-js/babel-provider.js';
6
+ import { javaScriptExtensions, typeScriptExtensions } from '../plugins/language-js/extensions.js';
7
+ export const defaultLanguages = languageRegistry([]);
8
+ export function languageRegistry(plugins) {
9
+ const entries = [babelProvider, ...plugins.filter(plugin => plugin.kinds?.includes('language'))].map(plugin => {
10
+ const operations = plugin.operations.filter(operation => operation.role === 'provider'
11
+ && operation.output.id === (operation.scope === 'repository' ? codeStructures.id : codeStructure.id));
12
+ const [operation] = operations;
13
+ const declared = plugin.providesLanguages ?? [];
14
+ if (!operation || operations.length !== 1 || (!plugin.claims && !declared.length)) {
15
+ throw new Error(`Language plugin ${plugin.id} must claim files and provide code structure`);
16
+ }
17
+ const classifiers = declared.map(({ id, extensions, globs }) => ({ id, matches: claimMatcher({ extensions, globs }) }));
18
+ function language(path) {
19
+ let found;
20
+ for (const { id, matches } of classifiers) {
21
+ if (!matches(path))
22
+ continue;
23
+ if (found)
24
+ throw new Error(`Language plugin ${plugin.id} declares multiple languages for ${path}`);
25
+ found = id;
26
+ }
27
+ return found;
28
+ }
29
+ const provider = { plugin, operation, key: `${plugin.id}/${operation.id}`, batch: operation.scope === 'repository', language };
30
+ const claims = declared.length ? declared : [plugin.claims];
31
+ return { provider, claims, matches: declared.length ? (path) => language(path) !== undefined : claimMatcher(plugin.claims) };
32
+ });
33
+ const claims = entries.flatMap(entry => entry.claims);
34
+ const extensions = [...new Set(claims.flatMap(entry => entry.extensions ?? []))];
35
+ const globs = [...new Set(claims.flatMap(entry => entry.globs ?? []))];
36
+ const providers = entries.map(({ provider }) => provider);
37
+ const catalog = providers.flatMap(({ plugin }) => (plugin.providesLanguages ?? []).map(({ id, label, color }) => ({
38
+ id, label, ...(color === undefined ? {} : { color }),
39
+ })));
40
+ if (new Set(catalog.map(({ id }) => id)).size !== catalog.length)
41
+ throw new Error('Duplicate provided language ID');
42
+ return { select, isSource: path => select(path) !== undefined, id: path => select(path)?.language(path) ?? languageId(path), extensions, globs,
43
+ catalog, providers };
44
+ function select(path) {
45
+ let selected;
46
+ for (const { provider, matches } of entries) {
47
+ if (!matches(path))
48
+ continue;
49
+ if (!selected && path.split('/').slice(0, -1).some(isExcludedDirectory))
50
+ return undefined;
51
+ if (selected)
52
+ throw new Error(`Multiple language providers claim ${path}: ${selected.plugin.id}, ${provider.plugin.id}`);
53
+ selected = provider;
54
+ }
55
+ return selected;
56
+ }
57
+ }
58
+ const js = new Set(javaScriptExtensions);
59
+ const ts = new Set(typeScriptExtensions);
60
+ export function languageId(path) {
61
+ const suffix = extname(path).toLowerCase();
62
+ if (js.has(suffix))
63
+ return 'javascript';
64
+ if (ts.has(suffix))
65
+ return 'typescript';
66
+ if (suffix === '.md' || suffix === '.mdx')
67
+ return 'markdown';
68
+ if (suffix === '.yml')
69
+ return 'yaml';
70
+ if (suffix === '.py')
71
+ return 'python';
72
+ if (suffix === '.rs')
73
+ return 'rust';
74
+ if (suffix === '.kt' || suffix === '.kts')
75
+ return 'kotlin';
76
+ return suffix.slice(1) || 'other';
77
+ }
78
+ export function claimMatcher(claims, identify = languageId) {
79
+ const { extensions = [], globs = [], languages = [] } = claims ?? {};
80
+ if (extensions.length === 0 && globs.length === 0 && languages.length === 0)
81
+ return () => true;
82
+ const glob = exclusionMatcher(globs);
83
+ const suffixes = new Set(extensions);
84
+ const languageSet = new Set(languages);
85
+ return path => suffixes.has(extname(path)) || glob(path) || (languageSet.size > 0 && languageSet.has(identify(path)));
86
+ }
87
+ //# sourceMappingURL=languages.js.map
@@ -5,18 +5,8 @@ export function resolveSourceLocator(option, context, providers = sourceProvider
5
5
  plan({ plugins: providers, select: [], inputs: new Map() });
6
6
  if (option === 'none')
7
7
  return undefined;
8
- if (option && option !== 'auto') {
9
- const colon = option.indexOf(':');
10
- const id = colon < 0 ? option : option.slice(0, colon);
11
- const spec = colon < 0 ? undefined : option.slice(colon + 1);
12
- const provider = providers.find(item => item.id === id);
13
- if (!provider)
14
- throw new Error(`Unknown source provider: ${id}. Choose ${providers.map(item => item.id).join(', ')}.`);
15
- const locator = provider.locate({ ...context, option: spec });
16
- if (!locator)
17
- throw new Error(`Cannot locate sources for ${id}. Name the repository as ${id}:OWNER/REPO.`);
18
- return locator;
19
- }
8
+ if (option && option !== 'auto')
9
+ return namedSourceLocator(option, context, providers);
20
10
  const remoteProviders = providers.filter(provider => provider.id !== 'local');
21
11
  for (const candidate of [{ env: context.env, remotes: [] }, { env: {}, remotes: context.remotes }]) {
22
12
  for (const provider of remoteProviders) {
@@ -27,4 +17,16 @@ export function resolveSourceLocator(option, context, providers = sourceProvider
27
17
  }
28
18
  return providers.find(provider => provider.id === 'local')?.locate(context);
29
19
  }
20
+ function namedSourceLocator(option, context, providers) {
21
+ const colon = option.indexOf(':');
22
+ const id = colon < 0 ? option : option.slice(0, colon);
23
+ const spec = colon < 0 ? undefined : option.slice(colon + 1);
24
+ const provider = providers.find(item => item.id === id);
25
+ if (!provider)
26
+ throw new Error(`Unknown source provider: ${id}. Choose ${providers.map(item => item.id).join(', ')}.`);
27
+ const locator = provider.locate({ ...context, option: spec });
28
+ if (!locator)
29
+ throw new Error(`Cannot locate sources for ${id}. Name the repository as ${id}:OWNER/REPO.`);
30
+ return locator;
31
+ }
30
32
  //# sourceMappingURL=sources.js.map
@@ -1,10 +1,12 @@
1
+ import type { OperationCacheOptions } from './operation-cache.js';
1
2
  import type { Product } from './plugin.js';
2
3
  import type { PlannedOperation } from './plan.js';
3
4
  export type Outcome = {
4
5
  readonly state: 'completed';
5
6
  readonly product: Product;
7
+ readonly diagnostics?: readonly string[];
6
8
  } | {
7
9
  readonly state: 'failed' | 'blocked';
8
10
  readonly reason: string;
9
11
  };
10
- export declare function execute(plan: readonly PlannedOperation[], external: ReadonlyMap<string, Product>): Promise<ReadonlyMap<string, Outcome>>;
12
+ export declare function execute(plan: readonly PlannedOperation[], external: ReadonlyMap<string, Product>, cache?: OperationCacheOptions): Promise<ReadonlyMap<string, Outcome>>;
@@ -1,4 +1,5 @@
1
- export async function execute(plan, external) {
1
+ import { operationCacheKey, readCachedOperation, writeCachedOperation } from './operation-cache.js';
2
+ export async function execute(plan, external, cache) {
2
3
  const results = new Map();
3
4
  for (const task of plan) {
4
5
  const inputs = new Map();
@@ -18,6 +19,13 @@ export async function execute(plan, external) {
18
19
  for (const [name, contract] of Object.entries(task.operation.inputs)) {
19
20
  readInput(inputs, name, contract);
20
21
  }
22
+ const key = cache && operationCacheKey(task, inputs, cache.configurationDigest);
23
+ const hit = key && cache ? await readCachedOperation(cache.store, key, task) : undefined;
24
+ if (hit) {
25
+ results.set(task.key, { state: 'completed', product: hit });
26
+ continue;
27
+ }
28
+ const diagnostics = [];
21
29
  const context = {
22
30
  read: (port, contract) => {
23
31
  if (!Object.hasOwn(task.operation.inputs, port) || task.operation.inputs[port]?.id !== contract.id) {
@@ -25,6 +33,7 @@ export async function execute(plan, external) {
25
33
  }
26
34
  return readInput(inputs, port, contract);
27
35
  },
36
+ emitDiagnostic: message => diagnostics.push(message),
28
37
  };
29
38
  const value = await task.operation.execute(context);
30
39
  const { output } = task.operation;
@@ -32,7 +41,10 @@ export async function execute(plan, external) {
32
41
  throw new Error(`Invalid output for ${output.id}`);
33
42
  if (task.validateOutput && !task.validateOutput(value))
34
43
  throw new Error(`Output violates the schema for ${output.id}`);
35
- results.set(task.key, { state: 'completed', product: { contract: output.id, value } });
44
+ const product = { contract: output.id, value };
45
+ if (key && cache && diagnostics.length === 0)
46
+ await writeCachedOperation(cache.store, key, product);
47
+ results.set(task.key, { state: 'completed', product, ...(diagnostics.length ? { diagnostics } : {}) });
36
48
  }
37
49
  catch (error) {
38
50
  results.set(task.key, { state: 'failed', reason: error instanceof Error ? error.message : String(error) });
@@ -1,4 +1,4 @@
1
- import type { LegacyPlugin, MetricDescriptor, Plugin, ProductDeclaration } from './plugin.js';
1
+ import type { MetricDescriptor, Plugin, ProductDeclaration } from './plugin.js';
2
2
  export declare function isCoreReportProduct(contract: string): boolean;
3
- export declare function manifestProducts(plugin: Plugin | LegacyPlugin, allowLegacy: boolean): ReadonlyMap<string, ProductDeclaration> | undefined;
3
+ export declare function manifestProducts(plugin: Plugin): ReadonlyMap<string, ProductDeclaration>;
4
4
  export declare function isMetricDescriptor(value: unknown): value is MetricDescriptor;
@@ -1,5 +1,6 @@
1
1
  import { isRecord } from './plugin.js';
2
2
  import { definitions } from '../model/measurement.js';
3
+ import { isLanguageDisplay } from '../model/language.js';
3
4
  const kinds = new Set(['language', 'analysis', 'coverage', 'security', 'import', 'source']);
4
5
  const persistence = new Set(['report', 'cache', 'transient']);
5
6
  const units = new Set(['count', 'ratio', 'minutes']);
@@ -15,11 +16,9 @@ const coreProducts = new Set([
15
16
  export function isCoreReportProduct(contract) {
16
17
  return coreProducts.has(contract);
17
18
  }
18
- export function manifestProducts(plugin, allowLegacy) {
19
- const { id, kinds: declaredKinds, claims, produces, rules, config } = plugin;
20
- if (declaredKinds === undefined && claims === undefined && produces === undefined) {
21
- if (allowLegacy)
22
- return undefined;
19
+ export function manifestProducts(plugin) {
20
+ const { id, kinds: declaredKinds, claims, providesLanguages, produces, rules, config } = plugin;
21
+ if (declaredKinds === undefined && claims === undefined && providesLanguages === undefined && produces === undefined) {
23
22
  throw new Error(`Missing plugin manifest for ${id}. Declare kinds and produces.`);
24
23
  }
25
24
  if (Object.hasOwn(plugin, 'languages'))
@@ -32,6 +31,9 @@ export function manifestProducts(plugin, allowLegacy) {
32
31
  || (key === 'extensions' && values.some(extension => !/^\.[\w-]+$/.test(extension)))))) {
33
32
  throw new Error(`Invalid file claims for plugin ${id}`);
34
33
  }
34
+ if (providesLanguages !== undefined && (!declaredKinds.includes('language') || !validLanguages(providesLanguages))) {
35
+ throw new Error(`Invalid provided languages for plugin ${id}`);
36
+ }
35
37
  if (!Array.isArray(produces))
36
38
  throw new Error(`Plugin ${id} must declare its products`);
37
39
  if (rules !== undefined && (!Array.isArray(rules) || !rules.every(isRuleDescriptor)
@@ -77,6 +79,24 @@ export function manifestProducts(plugin, allowLegacy) {
77
79
  }
78
80
  return products;
79
81
  }
82
+ function validLanguages(values) {
83
+ if (!Array.isArray(values) || values.length === 0)
84
+ return false;
85
+ const ids = new Set();
86
+ for (const value of values) {
87
+ if (!isRecord(value) || !isLanguageDisplay(value) || ids.has(value.id))
88
+ return false;
89
+ const { extensions, globs } = value;
90
+ if (extensions !== undefined && (!strings(extensions) || extensions.some(extension => !/^\.[\w-]+$/.test(extension))))
91
+ return false;
92
+ if (globs !== undefined && !strings(globs))
93
+ return false;
94
+ if (!(Array.isArray(extensions) && extensions.length || Array.isArray(globs) && globs.length))
95
+ return false;
96
+ ids.add(value.id);
97
+ }
98
+ return true;
99
+ }
80
100
  function isRuleDescriptor(value) {
81
101
  return isRecord(value) && text(value.id) && text(value.category) && optionalText(value.description)
82
102
  && optionalText(value.measure) && (value.per === undefined || (Array.isArray(value.per) && value.per.length === 2 && value.per.every(text)))
@@ -0,0 +1,14 @@
1
+ import type { PlannedOperation } from './plan.js';
2
+ import type { Product } from './plugin.js';
3
+ export interface OperationCache {
4
+ read(key: string): Promise<Uint8Array | undefined>;
5
+ write(key: string, bytes: Uint8Array): Promise<void>;
6
+ }
7
+ export interface OperationCacheOptions {
8
+ readonly store: OperationCache;
9
+ /** Digest of effective settings that the input products do not carry. */
10
+ readonly configurationDigest: string;
11
+ }
12
+ export declare function operationCacheKey(task: PlannedOperation, inputs: ReadonlyMap<string, Product>, configurationDigest: string): string | undefined;
13
+ export declare function readCachedOperation(store: OperationCache, key: string, task: PlannedOperation): Promise<Product | undefined>;
14
+ export declare function writeCachedOperation(store: OperationCache, key: string, product: Product): Promise<void>;