repometry 0.10.1 → 0.11.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 (147) hide show
  1. package/README.md +4 -2
  2. package/package.json +1 -1
  3. package/target/main/resources/config/process-plugins-v1.schema.json +22 -0
  4. package/target/main/resources/report/json/config-v1.schema.json +41 -0
  5. package/target/main/resources/report/json/file-metrics-v1.schema.json +23 -1
  6. package/target/main/resources/report/json/pull-review-v2.schema.json +100 -0
  7. package/target/main/ts/api/cache/root.d.ts +1 -1
  8. package/target/main/ts/api/cache/root.js +2 -2
  9. package/target/main/ts/api/gh/github.d.ts +0 -4
  10. package/target/main/ts/api/gh/github.js +3 -33
  11. package/target/main/ts/api/git/commit-metadata.d.ts +0 -1
  12. package/target/main/ts/api/git/commit-metadata.js +1 -10
  13. package/target/main/ts/api/import/cobertura.d.ts +2 -0
  14. package/target/main/ts/api/import/cobertura.js +160 -0
  15. package/target/main/ts/api/import/coverage-xml.d.ts +7 -0
  16. package/target/main/ts/api/import/coverage-xml.js +135 -0
  17. package/target/main/ts/api/import/lcov-files.d.ts +3 -1
  18. package/target/main/ts/api/import/lcov-files.js +23 -4
  19. package/target/main/ts/cli/arguments.js +2 -4
  20. package/target/main/ts/cli/config.d.ts +10 -6
  21. package/target/main/ts/cli/config.js +36 -6
  22. package/target/main/ts/cli/imports.d.ts +1 -0
  23. package/target/main/ts/cli/imports.js +6 -2
  24. package/target/main/ts/cli/main.js +47 -139
  25. package/target/main/ts/cli/range-inspection.d.ts +0 -3
  26. package/target/main/ts/cli/range-inspection.js +5 -17
  27. package/target/main/ts/cli/range-jobs.js +1 -3
  28. package/target/main/ts/cli/reporting.d.ts +2 -7
  29. package/target/main/ts/cli/reporting.js +23 -37
  30. package/target/main/ts/compose/analysis-report.d.ts +1 -1
  31. package/target/main/ts/compose/analysis-report.js +4 -5
  32. package/target/main/ts/compose/analysis-results.d.ts +1 -1
  33. package/target/main/ts/compose/analysis-results.js +4 -6
  34. package/target/main/ts/compose/analysis-steps.d.ts +23 -0
  35. package/target/main/ts/compose/analysis-steps.js +215 -0
  36. package/target/main/ts/compose/analyze-snapshot.d.ts +1 -1
  37. package/target/main/ts/compose/analyze-snapshot.js +8 -12
  38. package/target/main/ts/compose/built-ins.d.ts +3 -0
  39. package/target/main/ts/compose/built-ins.js +5 -0
  40. package/target/main/ts/compose/diff-coverage.d.ts +2 -4
  41. package/target/main/ts/compose/diff-coverage.js +15 -12
  42. package/target/main/ts/compose/history-cache.d.ts +1 -1
  43. package/target/main/ts/compose/inspect.d.ts +6 -9
  44. package/target/main/ts/compose/inspect.js +8 -9
  45. package/target/main/ts/compose/languages.d.ts +4 -1
  46. package/target/main/ts/compose/languages.js +9 -6
  47. package/target/main/ts/compose/native-language-plugins.d.ts +0 -1
  48. package/target/main/ts/compose/native-language-plugins.js +4 -11
  49. package/target/main/ts/compose/phases.d.ts +126 -0
  50. package/target/main/ts/compose/phases.js +154 -0
  51. package/target/main/ts/compose/plugin-list.d.ts +8 -2
  52. package/target/main/ts/compose/plugin-list.js +4 -13
  53. package/target/main/ts/compose/process-plugins.js +1 -1
  54. package/target/main/ts/compose/review.d.ts +2 -4
  55. package/target/main/ts/compose/review.js +10 -9
  56. package/target/main/ts/compose/sources.d.ts +1 -2
  57. package/target/main/ts/compose/sources.js +7 -7
  58. package/target/main/ts/core/engine/execute.d.ts +4 -1
  59. package/target/main/ts/core/engine/execute.js +1 -1
  60. package/target/main/ts/core/engine/manifest.d.ts +0 -1
  61. package/target/main/ts/core/engine/manifest.js +9 -13
  62. package/target/main/ts/core/engine/plugin.d.ts +1 -1
  63. package/target/main/ts/core/engine/report-products.js +3 -2
  64. package/target/main/ts/core/model/changes.d.ts +2 -0
  65. package/target/main/ts/core/model/changes.js +5 -1
  66. package/target/main/ts/core/model/clone-source.d.ts +2 -0
  67. package/target/main/ts/core/model/clone-source.js +4 -0
  68. package/target/main/ts/core/model/code-structure.d.ts +4 -1
  69. package/target/main/ts/core/model/code-structure.js +3 -1
  70. package/target/main/ts/core/model/coverage-input.d.ts +12 -0
  71. package/target/main/ts/core/model/coverage-input.js +11 -0
  72. package/target/main/ts/core/model/diff-coverage.d.ts +2 -0
  73. package/target/main/ts/core/model/diff-coverage.js +9 -1
  74. package/target/main/ts/core/model/language.d.ts +28 -0
  75. package/target/main/ts/core/model/language.js +25 -1
  76. package/target/main/ts/core/model/quality-summary.js +1 -1
  77. package/target/main/ts/core/model/report.d.ts +0 -2
  78. package/target/main/ts/core/model/report.js +0 -20
  79. package/target/main/ts/core/ports/tool-runner.d.ts +13 -0
  80. package/target/main/ts/core/usecases/inspect.d.ts +1 -2
  81. package/target/main/ts/core/usecases/review.js +11 -3
  82. package/target/main/ts/index.d.ts +6 -33
  83. package/target/main/ts/index.js +3 -18
  84. package/target/main/ts/plugin.d.ts +7 -3
  85. package/target/main/ts/plugin.js +3 -0
  86. package/target/main/ts/plugins/built-in.d.ts +6 -0
  87. package/target/main/ts/plugins/built-in.js +39 -0
  88. package/target/main/ts/plugins/coverage/coverage.d.ts +3 -24
  89. package/target/main/ts/plugins/coverage/coverage.js +8 -11
  90. package/target/main/ts/plugins/coverage/diff-coverage.d.ts +1 -5
  91. package/target/main/ts/plugins/coverage/diff-coverage.js +5 -14
  92. package/target/main/ts/plugins/duplication/duplication.d.ts +1 -3
  93. package/target/main/ts/plugins/duplication/duplication.js +2 -6
  94. package/target/main/ts/plugins/language-js/babel-provider.js +3 -2
  95. package/target/main/ts/plugins/language-js/structural-observations.js +1 -1
  96. package/target/main/ts/plugins/language-js/syntax.d.ts +2 -0
  97. package/target/main/ts/plugins/language-js/syntax.js +11 -0
  98. package/target/main/ts/plugins/maintainability/maintainability.d.ts +1 -8
  99. package/target/main/ts/plugins/maintainability/maintainability.js +4 -10
  100. package/target/main/ts/plugins/source/forges.js +1 -1
  101. package/target/main/ts/report/html/app/viewer-languages.d.ts +3 -1
  102. package/target/main/ts/report/html/app/viewer-languages.js +11 -1
  103. package/target/main/ts/report/html/app/viewer-metrics-view.js +1 -1
  104. package/target/main/ts/report/html/app/viewer-source-view.js +2 -2
  105. package/target/main/ts/report/html/app/viewer-tokenizer.d.ts +7 -6
  106. package/target/main/ts/report/html/app/viewer-tokenizer.js +72 -71
  107. package/target/main/ts/report/html/site/export-site.d.ts +1 -5
  108. package/target/main/ts/report/html/site/export-site.js +2 -6
  109. package/target/main/ts/report/html/site/projects.d.ts +1 -3
  110. package/target/main/ts/report/html/site/projects.js +2 -4
  111. package/target/main/ts/report/json/projections/file-metrics.js +1 -1
  112. package/target/main/ts/report/json/projections/inspection-context.d.ts +1 -0
  113. package/target/main/ts/report/json/projections/inspection-context.js +19 -1
  114. package/target/main/ts/report/json/projections/inspection-details.js +7 -2
  115. package/target/main/ts/report/json/store/local-store.js +2 -0
  116. package/target/main/ts/report/json/store/replace-file.d.ts +1 -1
  117. package/target/main/ts/report/json/store/replace-file.js +24 -3
  118. package/target/main/ts/report/json/store/store-check.js +10 -1
  119. package/target/main/ts/report/json/validation/metabranch.d.ts +1 -1
  120. package/target/main/ts/report/json/validation/metabranch.js +6 -3
  121. package/target/main/ts/report/json/wire/file-metrics-model.d.ts +3 -1
  122. package/target/main/ts/report.d.ts +13 -1
  123. package/target/main/ts/report.js +7 -1
  124. package/target/main/ts/api/git/metabranch-worktree.d.ts +0 -1
  125. package/target/main/ts/api/git/metabranch-worktree.js +0 -35
  126. package/target/main/ts/api/worker/remote-executor.d.ts +0 -2
  127. package/target/main/ts/api/worker/remote-executor.js +0 -46
  128. package/target/main/ts/api/worker/worker-protocol.d.ts +0 -7
  129. package/target/main/ts/api/worker/worker-protocol.js +0 -127
  130. package/target/main/ts/api/worker/worker.d.ts +0 -5
  131. package/target/main/ts/api/worker/worker.js +0 -86
  132. package/target/main/ts/compose/analysis-files.d.ts +0 -15
  133. package/target/main/ts/compose/analysis-files.js +0 -129
  134. package/target/main/ts/compose/analysis-imports.d.ts +0 -7
  135. package/target/main/ts/compose/analysis-imports.js +0 -36
  136. package/target/main/ts/compose/analysis-repository.d.ts +0 -7
  137. package/target/main/ts/compose/analysis-repository.js +0 -99
  138. package/target/main/ts/compose/analysis-sources.d.ts +0 -48
  139. package/target/main/ts/compose/analysis-sources.js +0 -54
  140. package/target/main/ts/compose/prepare-metabranch.d.ts +0 -9
  141. package/target/main/ts/compose/prepare-metabranch.js +0 -17
  142. package/target/main/ts/compose/security-plugins.d.ts +0 -1
  143. package/target/main/ts/compose/security-plugins.js +0 -7
  144. package/target/main/ts/core/usecases/compare.d.ts +0 -6
  145. package/target/main/ts/core/usecases/compare.js +0 -189
  146. package/target/main/ts/report/json/store/components.d.ts +0 -2
  147. package/target/main/ts/report/json/store/components.js +0 -32
@@ -1,99 +0,0 @@
1
- import { execute } from '../core/engine/execute.js';
2
- import { plan } from '../core/engine/plan.js';
3
- import { codeStructures } from '../core/model/code-structure.js';
4
- import { sourceFiles } from '../core/model/snapshot.js';
5
- import { isClaimedText } from '../core/model/source.js';
6
- import { inspectionKeys } from './analysis-sources.js';
7
- import { canReuseBatch } from './history-cache.js';
8
- const repositoryInput = new Map([['files', sourceFiles.id]]);
9
- export async function collectRepositorySyntax(sources, results, cache, history) {
10
- const providers = new Map(sources.languages.providers.filter(provider => provider.batch).map(provider => [provider.plugin.id, provider]));
11
- const facts = new Map();
12
- for (const { plugin } of sources.repository) {
13
- const provider = providers.get(plugin.id);
14
- if (!provider)
15
- continue;
16
- const files = sources.sources.filter(source => source.provider === provider).map(({ file }) => file);
17
- if (!files.length)
18
- continue;
19
- const reusable = canReuseBatch(provider) ? history : undefined;
20
- const outcomes = await runRepository(plugin, files, [provider.key, ...inspectionKeys(plugin)], results, cache, reusable);
21
- const syntax = outcomes.get(provider.key);
22
- if (syntax?.state === 'completed' && codeStructures.accepts(syntax.product.value)) {
23
- collectFacts(facts, syntax.product.value, files, provider.key, results);
24
- }
25
- }
26
- return facts;
27
- }
28
- export async function inspectRepositories(sources, results, cache) {
29
- for (const { plugin, matches } of sources.repository) {
30
- if (sources.languages.providers.some(provider => provider.batch && provider.plugin.id === plugin.id))
31
- continue;
32
- const select = inspectionKeys(plugin);
33
- if (!select.length)
34
- continue;
35
- const files = sources.sources.map(({ file }) => file).filter(file => matches(file.path) && isClaimedText(file.bytes));
36
- if (files.length)
37
- await runRepository(plugin, files, select, results, cache);
38
- }
39
- }
40
- async function runRepository(plugin, files, select, results, cache, history) {
41
- const tasks = plan({ plugins: [plugin], select, inputs: repositoryInput });
42
- const outcomes = history && tasks.length === 1
43
- ? await runIndependentProvider(tasks[0], files, history, cache) : await executeRepository(tasks, files, cache);
44
- const paths = files.map(({ path }) => path);
45
- for (const task of tasks) {
46
- results.remember(task);
47
- results.record(task, outcomes.get(task.key), undefined, paths);
48
- }
49
- return outcomes;
50
- }
51
- function executeRepository(tasks, files, cache) {
52
- return execute(tasks, new Map([['files', { contract: sourceFiles.id, value: files }]]), cache);
53
- }
54
- async function runIndependentProvider(task, files, history, cache) {
55
- const saved = new Map(files.flatMap(({ path }) => {
56
- const syntax = history.read(path)?.syntax;
57
- return syntax === undefined ? [] : [[path, syntax]];
58
- }));
59
- const missing = files.filter(({ path }) => !saved.has(path));
60
- const outcomes = missing.length === 0 ? undefined : await executeRepository([task], missing, cache);
61
- const fresh = outcomes === undefined ? [] : successfulBatch(outcomes.get(task.key), missing);
62
- // Preserve complete-batch diagnostics if an incremental run produces incomplete facts or a warning.
63
- if (!fresh)
64
- return saved.size ? executeRepository([task], files, cache) : outcomes;
65
- for (const syntax of fresh)
66
- saved.set(syntax.path, syntax);
67
- const values = files.map(({ path }) => saved.get(path));
68
- const { output } = task.operation;
69
- if (missing.length !== files.length && (!output.accepts(values) || (task.validateOutput && !task.validateOutput(values)))) {
70
- return executeRepository([task], files, cache);
71
- }
72
- for (const syntax of values)
73
- history.retain(syntax.path, { syntax });
74
- return missing.length === files.length ? outcomes : new Map([[task.key, {
75
- state: 'completed', product: { contract: output.id, value: values },
76
- }]]);
77
- }
78
- function successfulBatch(outcome, files) {
79
- if (outcome?.state !== 'completed' || outcome.diagnostics?.length || !codeStructures.accepts(outcome.product.value))
80
- return;
81
- const values = outcome.product.value;
82
- const paths = new Set(files.map(({ path }) => path));
83
- if (values.length === paths.size && values.every(({ path }) => paths.has(path)))
84
- return values;
85
- }
86
- function collectFacts(target, values, files, operation, results) {
87
- const planned = new Set(files.map(({ path }) => path));
88
- if (values.some(({ path }) => !planned.has(path))) {
89
- results.diagnostics.push({ operation, state: 'failed', message: 'Language provider returned a path outside its inputs' });
90
- return;
91
- }
92
- for (const facts of values)
93
- target.set(facts.path, facts);
94
- for (const path of planned) {
95
- if (!target.has(path))
96
- results.diagnostics.push({ operation, state: 'failed', path, message: 'Language provider returned no structure for this file' });
97
- }
98
- }
99
- //# sourceMappingURL=analysis-repository.js.map
@@ -1,48 +0,0 @@
1
- import type { Operation, Plugin } from '../core/engine/plugin.js';
2
- import type { SourceFile, SourceSnapshot } from '../core/model/source.js';
3
- import type { LanguageProvider } from './languages.js';
4
- export declare const structuralInspections: Plugin[];
5
- export declare const defaultProvider: LanguageProvider;
6
- export interface SelectedSource {
7
- readonly file: SourceFile;
8
- readonly provider: LanguageProvider | undefined;
9
- }
10
- export interface ClaimedPlugin {
11
- readonly plugin: Plugin;
12
- readonly matches: (path: string) => boolean;
13
- }
14
- export declare function inspectionFileMatcher(additional: readonly Plugin[], languages?: {
15
- select(path: string): LanguageProvider | undefined;
16
- isSource(path: string): boolean;
17
- id(path: string): string;
18
- readonly extensions: readonly string[];
19
- readonly globs: readonly string[];
20
- readonly catalog: readonly import("../plugin.js").LanguageDisplay[];
21
- readonly providers: readonly LanguageProvider[];
22
- readonly native: readonly import("./native-language-plugins.js").NativeLanguagePlugin[];
23
- skipped(path: string): boolean;
24
- }): (path: string) => boolean;
25
- export declare function selectAnalysisSources(snapshot: SourceSnapshot, additional: readonly Plugin[], withCoverage: boolean): {
26
- languages: {
27
- select(path: string): LanguageProvider | undefined;
28
- isSource(path: string): boolean;
29
- id(path: string): string;
30
- readonly extensions: readonly string[];
31
- readonly globs: readonly string[];
32
- readonly catalog: readonly import("../plugin.js").LanguageDisplay[];
33
- readonly providers: readonly LanguageProvider[];
34
- readonly native: readonly import("./native-language-plugins.js").NativeLanguagePlugin[];
35
- skipped(path: string): boolean;
36
- };
37
- sources: SelectedSource[];
38
- sourceFiles: SourceFile[];
39
- unavailableFiles: Set<string>;
40
- providersByPath: Map<string, LanguageProvider>;
41
- plugins: Plugin[];
42
- claimedPlugins: Plugin[];
43
- perFile: ClaimedPlugin[];
44
- repository: ClaimedPlugin[];
45
- };
46
- export type AnalysisSources = ReturnType<typeof selectAnalysisSources>;
47
- export declare function pluginForScope(plugin: Plugin, scope: NonNullable<Operation['scope']>): Plugin;
48
- export declare function inspectionKeys(plugin: Plugin): string[];
@@ -1,54 +0,0 @@
1
- import { plan } from '../core/engine/plan.js';
2
- import { coverage } from '../plugins/coverage/coverage.js';
3
- import { duplication } from '../plugins/duplication/duplication.js';
4
- import { maintainability } from '../plugins/maintainability/maintainability.js';
5
- import { structure } from '../plugins/structure/structure.js';
6
- import { claimMatcher, defaultLanguages, languageRegistry } from './languages.js';
7
- import { securityPlugins } from './security-plugins.js';
8
- export const structuralInspections = [structure, maintainability];
9
- export const defaultProvider = defaultLanguages.providers[0];
10
- export function inspectionFileMatcher(additional, languages = defaultLanguages) {
11
- const matches = [...securityPlugins, ...additional].filter(plugin => !plugin.kinds.includes('language'))
12
- .map(plugin => claimMatcher(plugin.claims, languages.id));
13
- return path => matches.some(match => match(path));
14
- }
15
- export function selectAnalysisSources(snapshot, additional, withCoverage) {
16
- const languages = languageRegistry(additional);
17
- const sources = snapshot.files.map(file => ({ file, provider: languages.select(file.path) }));
18
- const providersByPath = new Map(sources.flatMap(({ file, provider }) => provider ? [[file.path, provider]] : []));
19
- const unavailableFiles = new Set(sources.filter(({ file, provider }) => !provider && languages.skipped(file.path))
20
- .map(({ file }) => file.path));
21
- const sourceFiles = sources.flatMap(({ file, provider }) => provider ? [file] : []);
22
- const bound = new Map(languages.providers.map(({ plugin }) => [plugin.id, plugin]));
23
- const native = languages.native.flatMap(({ id }) => {
24
- const plugin = bound.get(id);
25
- return plugin ? [plugin] : [];
26
- });
27
- const claimedPlugins = [...securityPlugins.filter(plugin => !additional.includes(plugin)), ...native,
28
- ...additional.map(plugin => bound.get(plugin.id) ?? plugin)];
29
- const plugins = [defaultProvider.plugin, ...structuralInspections, duplication, ...(withCoverage ? [coverage] : []), ...claimedPlugins];
30
- validateRegistration(plugins, additional, withCoverage);
31
- const claims = claimedPlugins.map(plugin => ({ plugin, matches: plugin.kinds.includes('language')
32
- ? path => providersByPath.get(path)?.plugin.id === plugin.id : claimMatcher(plugin.claims, languages.id) }));
33
- return { languages, sources, sourceFiles, unavailableFiles, providersByPath, plugins, claimedPlugins,
34
- perFile: claimsForScope(claims, 'file'), repository: claimsForScope(claims, 'repository') };
35
- }
36
- function validateRegistration(plugins, additional, withCoverage) {
37
- if (additional.length)
38
- plan({ plugins, select: [], inputs: new Map() });
39
- if (!withCoverage && additional.some(plugin => plugin.id === coverage.id)) {
40
- throw new Error('An additional plugin uses a built-in plugin ID');
41
- }
42
- }
43
- function claimsForScope(claims, scope) {
44
- return claims.map(({ plugin, matches }) => ({ plugin: pluginForScope(plugin, scope), matches }))
45
- .filter(({ plugin }) => plugin.operations.length > 0);
46
- }
47
- export function pluginForScope(plugin, scope) {
48
- const operations = plugin.operations.filter(operation => (operation.scope ?? 'file') === scope);
49
- return operations.length === plugin.operations.length ? plugin : { ...plugin, operations };
50
- }
51
- export function inspectionKeys(plugin) {
52
- return plugin.operations.filter(operation => operation.role === 'inspection').map(operation => `${plugin.id}/${operation.id}`);
53
- }
54
- //# sourceMappingURL=analysis-sources.js.map
@@ -1,9 +0,0 @@
1
- import type { Report } from '../report/json/validation/report.js';
2
- interface MetabranchRequest {
3
- readonly repository: string;
4
- readonly worktree: string;
5
- readonly branch: string;
6
- readonly report: Report;
7
- }
8
- export declare function prepareMetabranch({ repository, worktree, branch, report }: MetabranchRequest): Promise<readonly string[]>;
9
- export {};
@@ -1,17 +0,0 @@
1
- import { isSensitiveFinding } from '../core/model/finding.js';
2
- import { findingImportMethods } from '../core/model/scanner-import.js';
3
- import { openMetabranchWorktree } from '../api/git/metabranch-worktree.js';
4
- import { LocalReportStore } from '../report/json/store/local-store.js';
5
- export async function prepareMetabranch({ repository, worktree, branch, report }) {
6
- if (report.subject.kind !== 'commit')
7
- throw new Error('Only reports for source commits can go into a metabranch');
8
- if (report.findings?.some(finding => isSensitiveFinding(finding.category))
9
- || report.ignoredFindings?.some(({ finding }) => isSensitiveFinding(finding.category))
10
- || findingImportMethods(report.appliedConfig.findingImports).some(method => isSensitiveFinding(method.category))) {
11
- throw new Error('Security scanner imports belong in the local report store');
12
- }
13
- const target = await openMetabranchWorktree(repository, worktree, branch, report.subject.id);
14
- await new LocalReportStore(target).save(report);
15
- return ['manifest.json', 'summary.json', 'objects', `commits/${report.subject.id}/report.json`];
16
- }
17
- //# sourceMappingURL=prepare-metabranch.js.map
@@ -1 +0,0 @@
1
- export declare const securityPlugins: import("../index.js").Plugin[];
@@ -1,7 +0,0 @@
1
- import { jsSecurity } from '../plugins/language-js/js-security.js';
2
- import { actionsSecurity } from '../plugins/security/actions-security.js';
3
- import { dockerfile } from '../plugins/security/dockerfile.js';
4
- import { npmSupplyChain } from '../plugins/security/npm-supply-chain.js';
5
- import { secrets } from '../plugins/security/secrets.js';
6
- export const securityPlugins = [secrets, jsSecurity, actionsSecurity, npmSupplyChain, dockerfile];
7
- //# sourceMappingURL=security-plugins.js.map
@@ -1,6 +0,0 @@
1
- import type { Report } from '../model/report.js';
2
- import type { InspectionComparison, Observation } from '../model/comparison.js';
3
- export { comparisonSchema } from '../model/comparison.js';
4
- export type { InspectionComparison } from '../model/comparison.js';
5
- export declare function compareInspections(baseline: Report, current: Report): InspectionComparison;
6
- export declare function observeCoverage(report: Report): Observation;
@@ -1,189 +0,0 @@
1
- import { isDeepStrictEqual } from 'node:util';
2
- import { isRecord } from '../engine/plugin.js';
3
- import { canonicalMetricId, definitions } from '../model/measurement.js';
4
- import { historicalPluginTools, legacySyntaxPlugin } from '../model/report.js';
5
- import { comparePaths } from '../model/snapshot.js';
6
- import { comparisonSchema } from '../model/comparison.js';
7
- export { comparisonSchema } from '../model/comparison.js';
8
- const metrics = {
9
- physicalLines: { definition: definitions.lines, operation: 'structure/size' },
10
- functions: { definition: definitions.functions, operation: 'structure/size' },
11
- maxCyclomaticComplexity: { definition: definitions.complexity, operation: 'structure/complexity' },
12
- lineCoverage: { definition: definitions.coverage, operation: 'lcov/import' },
13
- };
14
- export function compareInspections(baseline, current) {
15
- const scopes = [sourceScope(baseline), sourceScope(current)];
16
- const scopeReason = scopes.some(scope => scope === null) ? 'source-scope-unknown'
17
- : isDeepStrictEqual(scopes[0], scopes[1]) ? null : 'source-scope-changed';
18
- const compare = (metric) => compareMetric(metric, baseline, current, scopeReason);
19
- return { schema: comparisonSchema, baseline: subject(baseline), current: subject(current), metrics: {
20
- physicalLines: compare(metrics.physicalLines), functions: compare(metrics.functions),
21
- maxCyclomaticComplexity: compare(metrics.maxCyclomaticComplexity), lineCoverage: compare(metrics.lineCoverage),
22
- } };
23
- }
24
- function compareMetric(metric, baseline, current, scopeReason) {
25
- const before = observe(baseline, metric);
26
- const after = observe(current, metric);
27
- const unit = metric.definition === definitions.coverage ? 'percent' : 'count';
28
- const base = { definition: metric.definition, unit, baseline: before, current: after, delta: null };
29
- if (before.status !== 'complete' || after.status !== 'complete' || before.value === null || after.value === null) {
30
- return { ...base, status: 'unavailable', reason: 'observations-unavailable' };
31
- }
32
- if (scopeReason) {
33
- return { ...base, status: scopeReason === 'source-scope-unknown' ? 'unavailable' : 'incompatible', reason: scopeReason };
34
- }
35
- const beforeMethod = method(baseline, metric);
36
- const afterMethod = method(current, metric);
37
- if (!beforeMethod || !afterMethod)
38
- return { ...base, status: 'unavailable', reason: 'method-unknown' };
39
- if (!isDeepStrictEqual(beforeMethod, afterMethod))
40
- return { ...base, status: 'incompatible', reason: 'method-changed' };
41
- return { ...base, status: 'comparable', reason: null, delta: after.value - before.value };
42
- }
43
- function observe(report, metric) {
44
- if (metric.definition === definitions.coverage)
45
- return observeCoverage(report);
46
- const maximum = metric.definition === definitions.complexity;
47
- const target = maximum ? 'function' : 'file';
48
- const rows = report.measurements.filter(row => row.target === target && canonicalMetricId(row.definition) === metric.definition);
49
- const partial = report.scope.parsed < report.scope.files || hasDiagnostic(report, metric.operation) || hasParserDiagnostic(report);
50
- const expected = maximum ? fileCount(report.measurements, definitions.functions, report.scope.files) : report.scope.files;
51
- const value = integerAggregate(rows, maximum);
52
- if (partial)
53
- return { status: 'partial', value };
54
- if (expected === null || rows.length !== expected || (!maximum && !distinctPaths(rows))) {
55
- return { status: 'unavailable', value: null };
56
- }
57
- if (expected === 0)
58
- return { status: 'not-applicable', value: null };
59
- return { status: value === null ? 'unavailable' : 'complete', value };
60
- }
61
- export function observeCoverage(report) {
62
- const rows = report.measurements.filter(row => row.definition === definitions.coverage && row.target === 'repository');
63
- const row = rows.length === 1 ? rows[0] : undefined;
64
- const partial = hasDiagnostic(report, 'lcov/import');
65
- if (row?.covered === undefined || row.total === undefined)
66
- return { status: partial ? 'partial' : 'unavailable', value: null };
67
- const value = row.total > 0 ? 100 * row.covered / row.total : null;
68
- return { status: partial ? 'partial' : value === null ? 'not-applicable' : 'complete', value, covered: row.covered, total: row.total };
69
- }
70
- function fileCount(measurements, definition, expected) {
71
- const rows = measurements.filter(row => row.definition === definition && row.target === 'file');
72
- if (rows.length !== expected || !distinctPaths(rows))
73
- return null;
74
- return rows.length === 0 ? 0 : integerAggregate(rows, false);
75
- }
76
- function distinctPaths(rows) {
77
- const paths = new Set(rows.map(row => row.path));
78
- return !paths.has(undefined) && paths.size === rows.length;
79
- }
80
- function integerAggregate(rows, maximum) {
81
- if (rows.length === 0)
82
- return null;
83
- let result = 0;
84
- for (const { value } of rows) {
85
- if (value === null || !Number.isSafeInteger(value) || value < 0)
86
- return null;
87
- result = maximum ? Math.max(result, value) : result + value;
88
- }
89
- return Number.isSafeInteger(result) ? result : null;
90
- }
91
- function hasDiagnostic(report, ...operations) {
92
- return report.diagnostics.some(item => operations.includes(item.operation));
93
- }
94
- function hasParserDiagnostic(report) {
95
- const references = parserReferences(report);
96
- const operations = new Set(references.values());
97
- return report.diagnostics.some(({ path, operation }) => path === undefined
98
- ? operations.has(operation) : references.get(path) === operation);
99
- }
100
- function parserReferences(report) {
101
- return new Map((report.pluginData?.inventory ?? []).flatMap(({ path, provider }) => provider === undefined ? [] : [[path, provider]]));
102
- }
103
- function sourceScope(report) {
104
- const { source, profile } = report.appliedConfig;
105
- if (!isRecord(source))
106
- return null;
107
- const paths = orderedStrings(source.excludedPaths === undefined && profile === 'js-ts/v1' ? [] : source.excludedPaths);
108
- const defaults = orderedStrings(source.defaultExclusions ?? []);
109
- const directories = orderedStrings(source.excludedDirectories);
110
- const extensions = orderedStrings(source.extensions);
111
- const globs = orderedStrings(source.globs ?? []);
112
- const excludedOutput = source.excludedOutput;
113
- if (!paths || !defaults || !directories || !extensions || !globs || (excludedOutput !== null && typeof excludedOutput !== 'string'))
114
- return null;
115
- return { kind: report.subject.kind, paths: orderedStrings([...paths, ...defaults]), directories, extensions, globs, excludedOutput,
116
- generatedSourcePolicy: source.generatedSourcePolicy ?? null };
117
- }
118
- function orderedStrings(value) {
119
- if (!Array.isArray(value) || !value.every((item) => typeof item === 'string'))
120
- return null;
121
- return [...new Set(value)].sort(comparePaths);
122
- }
123
- function method(report, metric) {
124
- const definition = report.definitions[metric.definition] ?? Object.entries(report.definitions)
125
- .find(([id]) => canonicalMetricId(id) === metric.definition)?.[1];
126
- if (typeof definition !== 'string')
127
- return null;
128
- if (metric.definition !== definitions.coverage) {
129
- const details = structureMethod(report, metric.operation);
130
- return details === null ? null : { definition, ...details };
131
- }
132
- const { plugins, operations, coverage: settings } = report.appliedConfig;
133
- const toolchain = recordedEntries(plugins, 'id', ['lcov']);
134
- const bindings = recordedEntries(operations, 'key', [metric.operation]);
135
- if (!toolchain || !bindings || !isRecord(settings) || typeof settings.merge !== 'string')
136
- return null;
137
- const { inputDigest, inputDigests, pathBase, ...importSettings } = settings;
138
- return { definition, toolchain, bindings, settings: importSettings };
139
- }
140
- function structureMethod(report, operation) {
141
- const { plugins, operations, parser } = report.appliedConfig;
142
- if (!Array.isArray(operations))
143
- return null;
144
- const scopes = new Set(parserReferences(report).values());
145
- const candidates = operations.filter(isRecord).filter(entry => entry.key === operation);
146
- const bindings = [];
147
- const providerKeys = new Set();
148
- for (const candidate of candidates) {
149
- const port = isRecord(candidate.inputs) ? candidate.inputs.syntax : undefined;
150
- if (!isRecord(port))
151
- return null;
152
- const provider = typeof candidate.syntaxProvider === 'string' ? candidate.syntaxProvider : port.operation;
153
- if (typeof provider !== 'string' || !provider.includes('/'))
154
- return null;
155
- if (scopes.size && !scopes.has(provider))
156
- continue;
157
- providerKeys.add(provider);
158
- bindings.push(candidate);
159
- }
160
- if (providerKeys.size === 0 || [...scopes].some(provider => !providerKeys.has(provider)))
161
- return null;
162
- const providerBindings = recordedEntries(operations, 'key', [...providerKeys].sort(comparePaths));
163
- const pluginIds = [...new Set([operation, ...providerKeys].map(key => key.slice(0, key.indexOf('/'))))].sort(comparePaths);
164
- const toolchain = recordedEntries(historicalPluginTools(plugins), 'id', pluginIds);
165
- if (!providerBindings || !toolchain)
166
- return null;
167
- // The original reports carried the Babel configuration at report level.
168
- const configured = toolchain.map(({ id, version, api, tools, settings }) => ({
169
- id, version, api, tools, settings: id === legacySyntaxPlugin && isRecord(parser) ? parser : settings ?? null,
170
- }));
171
- return { toolchain: configured, bindings: [...providerBindings, ...bindings.sort((a, b) => comparePaths(JSON.stringify(a), JSON.stringify(b)))] };
172
- }
173
- function recordedEntries(value, key, names) {
174
- if (!Array.isArray(value))
175
- return null;
176
- const entries = value.filter(isRecord);
177
- const matches = names.map(name => entries.filter(entry => entry[key] === name));
178
- if (matches.some(group => group.length !== 1))
179
- return null;
180
- const recorded = matches.map(group => group[0]);
181
- const valid = key === 'id'
182
- ? recorded.every(entry => typeof entry.version === 'string' && typeof entry.api === 'string' && isRecord(entry.tools))
183
- : recorded.every(entry => isRecord(entry.inputs));
184
- return valid ? recorded : null;
185
- }
186
- function subject({ subject, generatedAt, status, scope }) {
187
- return { subject, generatedAt, status, scope };
188
- }
189
- //# sourceMappingURL=compare.js.map
@@ -1,2 +0,0 @@
1
- import type { Component } from '../wire/component-model.js';
2
- export declare function readComponents(file: string, optional: boolean): Promise<readonly Component[]>;
@@ -1,32 +0,0 @@
1
- import { readFile } from 'node:fs/promises';
2
- import { isRecord } from '../../../core/engine/plugin.js';
3
- export async function readComponents(file, optional) {
4
- try {
5
- const config = JSON.parse(await readFile(file, 'utf8'));
6
- if (!Array.isArray(config))
7
- throw new Error('Expected an array of component definitions');
8
- const names = new Set();
9
- return config.map((entry) => {
10
- if (!isRecord(entry) || typeof entry.name !== 'string' || !entry.name.trim() || entry.name.length > 100
11
- || !Array.isArray(entry.pathGlobs) || entry.pathGlobs.length === 0 || !entry.pathGlobs.every(validPattern)
12
- || (entry.description !== undefined && typeof entry.description !== 'string')) {
13
- throw new Error('Each component requires a name and one or more root-relative pathGlobs');
14
- }
15
- const name = entry.name.trim();
16
- if (names.has(name))
17
- throw new Error(`Duplicate component name: ${name}`);
18
- names.add(name);
19
- return { name, pathGlobs: [...new Set(entry.pathGlobs)], description: entry.description };
20
- });
21
- }
22
- catch (error) {
23
- if (optional && error instanceof Error && 'code' in error && error.code === 'ENOENT')
24
- return [];
25
- throw error;
26
- }
27
- }
28
- function validPattern(pattern) {
29
- return typeof pattern === 'string' && !/^[A-Za-z]:|[\\\0]/.test(pattern)
30
- && pattern.split('/').every(part => part !== '' && part !== '.' && part !== '..');
31
- }
32
- //# sourceMappingURL=components.js.map