repometry 0.5.0 → 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 (115) hide show
  1. package/README.md +35 -17
  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 +197 -10
  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 +5 -0
  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 +1 -1
  14. package/target/main/ts/api/git/git.js +4 -4
  15. package/target/main/ts/api/git/inspection-source.d.ts +1 -1
  16. package/target/main/ts/api/git/inspection-source.js +3 -3
  17. package/target/main/ts/api/git/local.d.ts +1 -1
  18. package/target/main/ts/api/git/local.js +4 -4
  19. package/target/main/ts/api/worker/remote-executor.d.ts +1 -1
  20. package/target/main/ts/api/worker/remote-executor.js +2 -2
  21. package/target/main/ts/api/worker/worker-protocol.d.ts +2 -2
  22. package/target/main/ts/api/worker/worker-protocol.js +8 -8
  23. package/target/main/ts/api/worker/worker.d.ts +1 -1
  24. package/target/main/ts/api/worker/worker.js +4 -4
  25. package/target/main/ts/cli/main.js +4 -3
  26. package/target/main/ts/cli/reporting.d.ts +1 -1
  27. package/target/main/ts/cli/reporting.js +1 -1
  28. package/target/main/ts/compose/analysis-files.d.ts +13 -0
  29. package/target/main/ts/compose/analysis-files.js +95 -0
  30. package/target/main/ts/compose/analysis-imports.d.ts +7 -0
  31. package/target/main/ts/compose/analysis-imports.js +34 -0
  32. package/target/main/ts/compose/analysis-report.d.ts +5 -0
  33. package/target/main/ts/compose/analysis-report.js +78 -0
  34. package/target/main/ts/compose/analysis-repository.d.ts +6 -0
  35. package/target/main/ts/compose/analysis-repository.js +61 -0
  36. package/target/main/ts/compose/analysis-results.d.ts +38 -0
  37. package/target/main/ts/compose/analysis-results.js +78 -0
  38. package/target/main/ts/compose/analysis-sources.d.ts +73 -0
  39. package/target/main/ts/compose/analysis-sources.js +47 -0
  40. package/target/main/ts/compose/analyze-snapshot.d.ts +2 -2
  41. package/target/main/ts/compose/analyze-snapshot.js +19 -250
  42. package/target/main/ts/compose/diff-coverage.d.ts +2 -0
  43. package/target/main/ts/compose/diff-coverage.js +6 -4
  44. package/target/main/ts/compose/inspect.js +8 -5
  45. package/target/main/ts/compose/languages.d.ts +29 -0
  46. package/target/main/ts/compose/languages.js +87 -0
  47. package/target/main/ts/compose/sources.js +14 -12
  48. package/target/main/ts/core/engine/manifest.d.ts +2 -2
  49. package/target/main/ts/core/engine/manifest.js +25 -5
  50. package/target/main/ts/core/engine/plan.d.ts +2 -4
  51. package/target/main/ts/core/engine/plan.js +13 -15
  52. package/target/main/ts/core/engine/plugin.d.ts +2 -1
  53. package/target/main/ts/core/model/clone-source.d.ts +1 -0
  54. package/target/main/ts/core/model/clone-source.js +1 -0
  55. package/target/main/ts/core/model/code-structure.d.ts +2 -0
  56. package/target/main/ts/core/model/code-structure.js +6 -0
  57. package/target/main/ts/core/model/language.d.ts +10 -0
  58. package/target/main/ts/core/model/language.js +6 -0
  59. package/target/main/ts/core/model/measurement.d.ts +7 -6
  60. package/target/main/ts/core/model/measurement.js +17 -6
  61. package/target/main/ts/core/model/plugin-data.d.ts +3 -0
  62. package/target/main/ts/core/model/quality-summary.js +5 -4
  63. package/target/main/ts/core/model/report.d.ts +1 -2
  64. package/target/main/ts/core/model/report.js +0 -1
  65. package/target/main/ts/core/model/snapshot.d.ts +0 -2
  66. package/target/main/ts/core/model/snapshot.js +0 -6
  67. package/target/main/ts/core/usecases/compare.js +61 -17
  68. package/target/main/ts/core/usecases/inspect.js +2 -2
  69. package/target/main/ts/plugin.d.ts +3 -2
  70. package/target/main/ts/plugin.js +1 -1
  71. package/target/main/ts/plugins/duplication/duplication.js +10 -4
  72. package/target/main/ts/plugins/language-js/babel-provider.js +8 -2
  73. package/target/main/ts/plugins/language-js/extensions.d.ts +3 -0
  74. package/target/main/ts/plugins/language-js/extensions.js +4 -0
  75. package/target/main/ts/plugins/language-js/js-security.js +3 -2
  76. package/target/main/ts/report/html/app/viewer-data.d.ts +1 -1
  77. package/target/main/ts/report/html/app/viewer-data.js +2 -29
  78. package/target/main/ts/report/html/app/viewer-metric-registry.js +7 -7
  79. package/target/main/ts/report/html/app/viewer-overview-cards.js +8 -2
  80. package/target/main/ts/report/html/app/viewer-route.d.ts +2 -2
  81. package/target/main/ts/report/html/app/viewer-route.js +3 -3
  82. package/target/main/ts/report/html/app/viewer-trend-data.d.ts +6 -1
  83. package/target/main/ts/report/html/app/viewer-trend-data.js +6 -2
  84. package/target/main/ts/report/html/app/viewer.js +3 -3
  85. package/target/main/ts/report/html/site/export-site.d.ts +3 -4
  86. package/target/main/ts/report/html/site/export-site.js +24 -41
  87. package/target/main/ts/report/html/site/exported-server.js +2 -1
  88. package/target/main/ts/report/html/site/local-server.d.ts +1 -1
  89. package/target/main/ts/report/html/site/local-server.js +13 -19
  90. package/target/main/ts/report/html/site/projects.js +8 -17
  91. package/target/main/ts/report/json/projections/commit-summary.d.ts +2 -2
  92. package/target/main/ts/report/json/projections/commit-summary.js +18 -19
  93. package/target/main/ts/report/json/projections/file-metrics.js +31 -24
  94. package/target/main/ts/report/json/projections/inspection-context.js +10 -1
  95. package/target/main/ts/report/json/projections/inspection-details.d.ts +1 -1
  96. package/target/main/ts/report/json/projections/inspection-details.js +2 -2
  97. package/target/main/ts/report/json/projections/metric-values.d.ts +1 -0
  98. package/target/main/ts/report/json/projections/metric-values.js +15 -5
  99. package/target/main/ts/report/json/store/pull-review-store.js +1 -2
  100. package/target/main/ts/report/json/validation/report.d.ts +1 -1
  101. package/target/main/ts/report/json/validation/report.js +10 -8
  102. package/target/main/ts/report/json/validation/summary-validation.js +1 -3
  103. package/target/main/ts/report/json/wire/file-metrics-model.d.ts +2 -0
  104. package/target/main/ts/report/json/wire/inspection-details-model.d.ts +0 -5
  105. package/target/main/ts/report/json/wire/public-history-model.d.ts +0 -6
  106. package/target/main/ts/report/json/wire/public-history-model.js +0 -1
  107. package/target/main/ts/report.d.ts +2 -3
  108. package/target/main/ts/report.js +1 -2
  109. package/target/main/resources/report/json/inspection-context-v1.schema.json +0 -172
  110. package/target/main/resources/report/json/public-history-v1.schema.json +0 -50
  111. package/target/main/resources/report/json/quality-history-v1.schema.json +0 -51
  112. package/target/main/resources/report/json/report-v1.schema.json +0 -65
  113. package/target/main/resources/report/json/viewer-details-v1.schema.json +0 -346
  114. package/target/main/ts/report/json/projections/public-history.d.ts +0 -4
  115. package/target/main/ts/report/json/projections/public-history.js +0 -17
@@ -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,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)))
@@ -1,16 +1,14 @@
1
- import type { LegacyPlugin, Operation, Plugin, ProductDeclaration } from './plugin.js';
1
+ import type { Operation, Plugin, ProductDeclaration } from './plugin.js';
2
2
  export type InputBinding = {
3
3
  readonly external: string;
4
4
  } | {
5
5
  readonly operation: string;
6
6
  };
7
7
  export interface PlanRequest {
8
- readonly plugins: readonly (Plugin | LegacyPlugin)[];
8
+ readonly plugins: readonly Plugin[];
9
9
  readonly select: readonly string[];
10
10
  readonly inputs: ReadonlyMap<string, string>;
11
11
  readonly bindings?: ReadonlyMap<string, Readonly<Record<string, InputBinding>>>;
12
- /** Explicit migration exception for named v1 plugins that predate the manifest. */
13
- readonly legacyPluginIds?: readonly string[];
14
12
  }
15
13
  export interface PlannedOperation {
16
14
  readonly key: string;
@@ -3,7 +3,7 @@ import { isJsonValue } from '../model/plugin-data.js';
3
3
  import { pluginApi } from './plugin.js';
4
4
  import { manifestProducts } from './manifest.js';
5
5
  export function plan(request) {
6
- const { operations, declarations, cacheIdentities } = indexOperations(request.plugins, new Set(request.legacyPluginIds));
6
+ const { operations, declarations, cacheIdentities } = indexOperations(request.plugins);
7
7
  const resolved = new Map();
8
8
  const path = [];
9
9
  function visit(key) {
@@ -61,7 +61,7 @@ function validateSchema(schema, key) {
61
61
  throw new Error(`Invalid product schema for ${key}`, { cause: error });
62
62
  }
63
63
  }
64
- function indexOperations(plugins, legacyPlugins) {
64
+ function indexOperations(plugins) {
65
65
  const ids = new Set();
66
66
  const operations = new Map();
67
67
  const declarations = new Map();
@@ -73,7 +73,7 @@ function indexOperations(plugins, legacyPlugins) {
73
73
  if (ids.has(plugin.id) || !plugin.id || plugin.id.includes('/'))
74
74
  throw new Error(`Invalid or duplicate plugin ID: ${plugin.id}`);
75
75
  ids.add(plugin.id);
76
- const products = manifestProducts(plugin, legacyPlugins.has(plugin.id));
76
+ const products = manifestProducts(plugin);
77
77
  if (plugin.settings !== undefined) {
78
78
  if (!isJsonValue(plugin.settings))
79
79
  throw new Error(`Plugin settings must be JSON data: ${plugin.id}`);
@@ -81,7 +81,7 @@ function indexOperations(plugins, legacyPlugins) {
81
81
  throw new Error(`Plugin settings violate the configuration schema: ${plugin.id}`);
82
82
  }
83
83
  }
84
- for (const declaration of products?.values() ?? []) {
84
+ for (const declaration of products.values()) {
85
85
  for (const metric of declaration.metrics ?? []) {
86
86
  const owner = metricOwners.get(metric.id);
87
87
  if (owner !== undefined)
@@ -96,17 +96,15 @@ function indexOperations(plugins, legacyPlugins) {
96
96
  if (operation.scope !== undefined && operation.scope !== 'file' && operation.scope !== 'repository') {
97
97
  throw new Error(`Invalid operation scope: ${key}`);
98
98
  }
99
- if (products !== undefined) {
100
- const declaration = products.get(operation.output.id);
101
- if (!declaration)
102
- throw new Error(`Undeclared output for ${key}: ${operation.output.id}`);
103
- declarations.set(key, declaration);
104
- if (declaration.persistence === 'cache') {
105
- cacheIdentities.set(key, JSON.stringify([
106
- plugin.api, plugin.version, Object.entries(plugin.tools ?? {}).sort(), plugin.settings, operation.scope, operation.implementation,
107
- declaration.contract, declaration.schema,
108
- ]));
109
- }
99
+ const declaration = products.get(operation.output.id);
100
+ if (!declaration)
101
+ throw new Error(`Undeclared output for ${key}: ${operation.output.id}`);
102
+ declarations.set(key, declaration);
103
+ if (declaration.persistence === 'cache') {
104
+ cacheIdentities.set(key, JSON.stringify([
105
+ plugin.api, plugin.version, Object.entries(plugin.tools ?? {}).sort(), plugin.settings, operation.scope, operation.implementation,
106
+ declaration.contract, declaration.schema,
107
+ ]));
110
108
  }
111
109
  operations.set(key, operation);
112
110
  }
@@ -1,4 +1,5 @@
1
1
  import type { MetricDescriptor } from '../model/metric-descriptor.js';
2
+ import type { ProvidedLanguage } from '../model/language.js';
2
3
  import type { JsonValue } from '../model/plugin-data.js';
3
4
  export type { MetricDescriptor, MetricScope } from '../model/metric-descriptor.js';
4
5
  export { isRecord } from '../model/plugin-data.js';
@@ -63,6 +64,6 @@ export interface Plugin {
63
64
  readonly settings?: JsonValue;
64
65
  readonly kinds: readonly PluginKind[];
65
66
  readonly claims?: FileClaims;
67
+ readonly providesLanguages?: readonly ProvidedLanguage[];
66
68
  readonly produces: readonly ProductDeclaration[];
67
69
  }
68
- export type LegacyPlugin = Omit<Plugin, 'kinds' | 'claims' | 'produces'>;
@@ -10,6 +10,7 @@ export interface Candidate {
10
10
  }
11
11
  export interface CloneSource {
12
12
  readonly path: string;
13
+ readonly scheme?: string;
13
14
  readonly codeLines: readonly number[];
14
15
  readonly candidates: readonly Candidate[];
15
16
  }
@@ -9,6 +9,7 @@ function isCount(value) {
9
9
  }
10
10
  export function isCloneSource(value) {
11
11
  return isRecord(value) && typeof value.path === 'string' && Array.isArray(value.codeLines)
12
+ && (value.scheme === undefined || typeof value.scheme === 'string' && value.scheme.length > 0)
12
13
  && value.codeLines.every((line, index, lines) => isCount(line) && line > (lines[index - 1] ?? 0))
13
14
  && Array.isArray(value.candidates) && value.candidates.every(isCandidate);
14
15
  }
@@ -31,3 +31,5 @@ export interface CodeStructure {
31
31
  readonly clones: CloneSource;
32
32
  }
33
33
  export declare const codeStructure: DataContract<CodeStructure>;
34
+ /** A repository provider returns at most one structure per input path. */
35
+ export declare const codeStructures: DataContract<readonly CodeStructure[]>;
@@ -32,4 +32,10 @@ export const codeStructure = {
32
32
  && Array.isArray(value.observations) && value.observations.every(isObservation)
33
33
  && isCloneSource(value.clones) && value.clones.path === value.path,
34
34
  };
35
+ /** A repository provider returns at most one structure per input path. */
36
+ export const codeStructures = {
37
+ id: 'repometry.code-structures/v1',
38
+ accepts: (value) => Array.isArray(value) && value.every(codeStructure.accepts)
39
+ && new Set(value.map(({ path }) => path)).size === value.length,
40
+ };
35
41
  //# sourceMappingURL=code-structure.js.map
@@ -0,0 +1,10 @@
1
+ export interface LanguageDisplay {
2
+ readonly id: string;
3
+ readonly label: string;
4
+ readonly color?: string;
5
+ }
6
+ export interface ProvidedLanguage extends LanguageDisplay {
7
+ readonly extensions?: readonly string[];
8
+ readonly globs?: readonly string[];
9
+ }
10
+ export declare function isLanguageDisplay(value: unknown): value is LanguageDisplay;
@@ -0,0 +1,6 @@
1
+ import { isRecord } from './plugin-data.js';
2
+ export function isLanguageDisplay(value) {
3
+ return isRecord(value) && typeof value.id === 'string' && /^[a-z][a-z0-9-]*$/.test(value.id)
4
+ && typeof value.label === 'string' && value.label.trim().length > 0
5
+ && (value.color === undefined || typeof value.color === 'string' && /^#[a-f\d]{6}$/i.test(value.color));
6
+ }
@@ -2,7 +2,7 @@ import type { DataContract } from '../engine/plugin.js';
2
2
  export declare const definitions: {
3
3
  readonly lines: 'repometry.physical-lines/v1';
4
4
  readonly functions: 'repometry.functions/v1';
5
- readonly complexity: 'repometry.cyclomatic-babel/v1';
5
+ readonly complexity: 'repometry.cyclomatic-complexity/v1';
6
6
  readonly coverage: 'repometry.lcov-line-coverage/v1';
7
7
  readonly coveredLines: 'repometry.lcov-covered-lines/v1';
8
8
  readonly coverableLines: 'repometry.lcov-coverable-lines/v1';
@@ -12,13 +12,14 @@ export declare const definitions: {
12
12
  readonly functionCoverage: 'repometry.lcov-function-coverage/v1';
13
13
  readonly coveredFunctions: 'repometry.lcov-covered-functions/v1';
14
14
  readonly coverableFunctions: 'repometry.lcov-coverable-functions/v1';
15
- readonly codeLines: 'repometry.code-lines-babel/v1';
16
- readonly comments: 'repometry.comment-lines-babel/v1';
17
- readonly classes: 'repometry.classes-babel/v1';
18
- readonly cognitiveComplexity: 'repometry.cognitive-babel/v1';
19
- readonly duplicatedLines: 'repometry.duplicated-lines-babel/v1';
15
+ readonly codeLines: 'repometry.code-lines/v1';
16
+ readonly comments: 'repometry.comment-lines/v1';
17
+ readonly classes: 'repometry.classes/v1';
18
+ readonly cognitiveComplexity: 'repometry.cognitive-complexity/v1';
19
+ readonly duplicatedLines: 'repometry.duplicated-lines/v1';
20
20
  readonly churn: 'repometry.git-change-frequency/v1';
21
21
  };
22
+ export declare function canonicalMetricId(id: string): string;
22
23
  export interface Measurement {
23
24
  readonly definition: string;
24
25
  readonly target: 'repository' | 'file' | 'function';
@@ -2,7 +2,7 @@ import { isRecord } from './plugin-data.js';
2
2
  export const definitions = {
3
3
  lines: 'repometry.physical-lines/v1',
4
4
  functions: 'repometry.functions/v1',
5
- complexity: 'repometry.cyclomatic-babel/v1',
5
+ complexity: 'repometry.cyclomatic-complexity/v1',
6
6
  coverage: 'repometry.lcov-line-coverage/v1',
7
7
  coveredLines: 'repometry.lcov-covered-lines/v1',
8
8
  coverableLines: 'repometry.lcov-coverable-lines/v1',
@@ -12,13 +12,24 @@ export const definitions = {
12
12
  functionCoverage: 'repometry.lcov-function-coverage/v1',
13
13
  coveredFunctions: 'repometry.lcov-covered-functions/v1',
14
14
  coverableFunctions: 'repometry.lcov-coverable-functions/v1',
15
- codeLines: 'repometry.code-lines-babel/v1',
16
- comments: 'repometry.comment-lines-babel/v1',
17
- classes: 'repometry.classes-babel/v1',
18
- cognitiveComplexity: 'repometry.cognitive-babel/v1',
19
- duplicatedLines: 'repometry.duplicated-lines-babel/v1',
15
+ codeLines: 'repometry.code-lines/v1',
16
+ comments: 'repometry.comment-lines/v1',
17
+ classes: 'repometry.classes/v1',
18
+ cognitiveComplexity: 'repometry.cognitive-complexity/v1',
19
+ duplicatedLines: 'repometry.duplicated-lines/v1',
20
20
  churn: 'repometry.git-change-frequency/v1',
21
21
  };
22
+ const earlierMetricIds = new Map([
23
+ ['repometry.cyclomatic-babel/v1', definitions.complexity],
24
+ ['repometry.code-lines-babel/v1', definitions.codeLines],
25
+ ['repometry.comment-lines-babel/v1', definitions.comments],
26
+ ['repometry.classes-babel/v1', definitions.classes],
27
+ ['repometry.cognitive-babel/v1', definitions.cognitiveComplexity],
28
+ ['repometry.duplicated-lines-babel/v1', definitions.duplicatedLines],
29
+ ]);
30
+ export function canonicalMetricId(id) {
31
+ return earlierMetricIds.get(id) ?? id;
32
+ }
22
33
  function isMeasurement(value) {
23
34
  return isRecord(value) && typeof value.definition === 'string'
24
35
  && (value.target === 'repository' || value.target === 'file' || value.target === 'function')
@@ -1,5 +1,6 @@
1
1
  import type { MetricDescriptor, PluginConfigSchema, RuleDescriptor } from '../engine/plugin.js';
2
2
  import type { InventoryFile } from './source.js';
3
+ import type { LanguageDisplay } from './language.js';
3
4
  export type JsonValue = null | boolean | number | string | readonly JsonValue[] | {
4
5
  readonly [key: string]: JsonValue;
5
6
  };
@@ -20,8 +21,10 @@ export interface PluginData {
20
21
  }[];
21
22
  readonly products: Readonly<Record<string, readonly PersistedProduct[]>>;
22
23
  readonly contracts?: Readonly<Record<string, PluginConfigSchema>>;
24
+ readonly languages?: readonly LanguageDisplay[];
23
25
  readonly inventory?: readonly (InventoryFile & {
24
26
  readonly language: string;
25
27
  readonly analysed: boolean;
28
+ readonly provider?: string;
26
29
  })[];
27
30
  }
@@ -1,5 +1,5 @@
1
1
  import { isRecord } from './plugin-data.js';
2
- import { definitions } from './measurement.js';
2
+ import { canonicalMetricId, definitions } from './measurement.js';
3
3
  export const debtModel = { name: 'basic-cocomo-organic', scale: 2.4, exponent: 1.05, minutesPerPersonMonth: 9600 };
4
4
  export function qualitySummary(report) {
5
5
  const totals = new Map();
@@ -8,11 +8,12 @@ export function qualitySummary(report) {
8
8
  for (const item of report.measurements) {
9
9
  if (item.target !== 'file' || item.value === null || !Number.isSafeInteger(item.value) || item.value < 0)
10
10
  continue;
11
- if (item.definition === definitions.codeLines)
11
+ const id = canonicalMetricId(item.definition);
12
+ if (id === definitions.codeLines)
12
13
  codeMeasuredFiles++;
13
- if (item.definition === definitions.duplicatedLines)
14
+ if (id === definitions.duplicatedLines)
14
15
  duplicationMeasuredFiles++;
15
- totals.set(item.definition, (totals.get(item.definition) ?? 0) + item.value);
16
+ totals.set(id, (totals.get(id) ?? 0) + item.value);
16
17
  }
17
18
  const codeLines = totals.get(definitions.codeLines) ?? null;
18
19
  const duplicatedLines = totals.get(definitions.duplicatedLines) ?? null;
@@ -3,7 +3,6 @@ import type { Finding } from './finding.js';
3
3
  import type { IgnoredFinding } from './ignore-rule.js';
4
4
  import type { PluginData } from './plugin-data.js';
5
5
  import type { Subject } from './source.js';
6
- export declare const legacyReportSchema = "urn:repometry:schema:report:1";
7
6
  export declare const reportSchema = "urn:repometry:schema:report:2";
8
7
  export interface Diagnostic {
9
8
  readonly operation: string;
@@ -12,7 +11,7 @@ export interface Diagnostic {
12
11
  readonly path?: string;
13
12
  }
14
13
  export interface Report {
15
- readonly schema: typeof reportSchema | typeof legacyReportSchema;
14
+ readonly schema: typeof reportSchema;
16
15
  readonly subject: Subject;
17
16
  readonly generatedAt: string;
18
17
  readonly committedAt?: string;
@@ -1,4 +1,3 @@
1
- export const legacyReportSchema = 'urn:repometry:schema:report:1';
2
1
  export const reportSchema = 'urn:repometry:schema:report:2';
3
2
  export function validSubjectId(kind, id) {
4
3
  return /^[a-f0-9]{64}$/.test(id) || (kind === 'commit' && /^[a-f0-9]{40}$/.test(id));
@@ -4,8 +4,6 @@ export type { Subject, SourceFile, SourceSnapshot } from './source.js';
4
4
  export declare const sourceFile: DataContract<SourceFile>;
5
5
  export declare const sourceFiles: DataContract<readonly SourceFile[]>;
6
6
  export declare const sourceDirectoriesExcluded: readonly ['.git', '.repometry', 'node_modules', 'target'];
7
- export declare const sourceExtensions: readonly ['.js', '.mjs', '.cjs', '.jsx', '.ts', '.mts', '.cts', '.tsx'];
8
- export declare function isSourcePath(path: string): boolean;
9
7
  export declare function isExcludedDirectory(name: string): boolean;
10
8
  export declare function digest(bytes: Uint8Array | string): string;
11
9
  export declare function utf8(bytes: Uint8Array): string;
@@ -1,5 +1,4 @@
1
1
  import { createHash } from 'node:crypto';
2
- import { extname } from 'node:path';
3
2
  import { isRecord } from './plugin-data.js';
4
3
  export const sourceFile = {
5
4
  id: 'repometry.source-file/v1',
@@ -10,12 +9,7 @@ export const sourceFiles = {
10
9
  accepts: (value) => Array.isArray(value) && value.every(sourceFile.accepts),
11
10
  };
12
11
  export const sourceDirectoriesExcluded = ['.git', '.repometry', 'node_modules', 'target'];
13
- export const sourceExtensions = ['.js', '.mjs', '.cjs', '.jsx', '.ts', '.mts', '.cts', '.tsx'];
14
12
  const excluded = new Set(sourceDirectoriesExcluded);
15
- const extensions = new Set(sourceExtensions);
16
- export function isSourcePath(path) {
17
- return extensions.has(extname(path)) && !path.split('/').slice(0, -1).some(isExcludedDirectory);
18
- }
19
13
  export function isExcludedDirectory(name) {
20
14
  return excluded.has(name);
21
15
  }
@@ -1,6 +1,6 @@
1
1
  import { isDeepStrictEqual } from 'node:util';
2
2
  import { isRecord } from '../engine/plugin.js';
3
- import { definitions } from '../model/measurement.js';
3
+ import { canonicalMetricId, definitions } from '../model/measurement.js';
4
4
  import { comparePaths } from '../model/snapshot.js';
5
5
  import { comparisonSchema } from '../model/comparison.js';
6
6
  export { comparisonSchema } from '../model/comparison.js';
@@ -44,8 +44,8 @@ function observe(report, metric) {
44
44
  return observeCoverage(report);
45
45
  const maximum = metric.definition === definitions.complexity;
46
46
  const target = maximum ? 'function' : 'file';
47
- const rows = report.measurements.filter(row => row.definition === metric.definition && row.target === target);
48
- const partial = report.scope.parsed < report.scope.files || hasDiagnostic(report, metric.operation, 'babel-syntax/parse');
47
+ const rows = report.measurements.filter(row => row.target === target && canonicalMetricId(row.definition) === metric.definition);
48
+ const partial = report.scope.parsed < report.scope.files || hasDiagnostic(report, metric.operation) || hasParserDiagnostic(report);
49
49
  const expected = maximum ? fileCount(report.measurements, definitions.functions, report.scope.files) : report.scope.files;
50
50
  const value = integerAggregate(rows, maximum);
51
51
  if (partial)
@@ -90,6 +90,17 @@ function integerAggregate(rows, maximum) {
90
90
  function hasDiagnostic(report, ...operations) {
91
91
  return report.diagnostics.some(item => operations.includes(item.operation));
92
92
  }
93
+ function hasParserDiagnostic(report) {
94
+ const references = parserReferences(report);
95
+ if (references.size === 0)
96
+ return hasDiagnostic(report, 'babel-syntax/parse');
97
+ const operations = new Set(references.values());
98
+ return report.diagnostics.some(({ path, operation }) => path === undefined
99
+ ? operations.has(operation) : references.get(path) === operation);
100
+ }
101
+ function parserReferences(report) {
102
+ return new Map((report.pluginData?.inventory ?? []).flatMap(({ path, provider }) => provider === undefined ? [] : [[path, provider]]));
103
+ }
93
104
  function sourceScope(report) {
94
105
  const { source, profile } = report.appliedConfig;
95
106
  if (!isRecord(source))
@@ -98,10 +109,11 @@ function sourceScope(report) {
98
109
  const defaults = orderedStrings(source.defaultExclusions ?? []);
99
110
  const directories = orderedStrings(source.excludedDirectories);
100
111
  const extensions = orderedStrings(source.extensions);
112
+ const globs = orderedStrings(source.globs ?? []);
101
113
  const excludedOutput = source.excludedOutput;
102
- if (!paths || !defaults || !directories || !extensions || (excludedOutput !== null && typeof excludedOutput !== 'string'))
114
+ if (!paths || !defaults || !directories || !extensions || !globs || (excludedOutput !== null && typeof excludedOutput !== 'string'))
103
115
  return null;
104
- return { kind: report.subject.kind, paths: orderedStrings([...paths, ...defaults]), directories, extensions, excludedOutput,
116
+ return { kind: report.subject.kind, paths: orderedStrings([...paths, ...defaults]), directories, extensions, globs, excludedOutput,
105
117
  generatedSourcePolicy: source.generatedSourcePolicy ?? null };
106
118
  }
107
119
  function orderedStrings(value) {
@@ -110,23 +122,55 @@ function orderedStrings(value) {
110
122
  return [...new Set(value)].sort(comparePaths);
111
123
  }
112
124
  function method(report, metric) {
113
- const definition = report.definitions[metric.definition];
114
- const { plugins, operations, parser, coverage } = report.appliedConfig;
115
- const importsCoverage = metric.definition === definitions.coverage;
116
- const pluginIds = importsCoverage ? ['lcov'] : ['babel-syntax', 'structure'];
117
- const operationKeys = importsCoverage ? [metric.operation] : ['babel-syntax/parse', metric.operation];
118
- const toolchain = recordedEntries(plugins, 'id', pluginIds);
119
- const bindings = recordedEntries(operations, 'key', operationKeys);
120
- const settings = importsCoverage ? coverage : parser;
121
- if (typeof definition !== 'string' || !toolchain || !bindings || !isRecord(settings))
125
+ const definition = report.definitions[metric.definition] ?? Object.entries(report.definitions)
126
+ .find(([id]) => canonicalMetricId(id) === metric.definition)?.[1];
127
+ if (typeof definition !== 'string')
122
128
  return null;
123
- if (importsCoverage && typeof settings.merge !== 'string')
129
+ if (metric.definition !== definitions.coverage) {
130
+ const details = structureMethod(report, metric.operation);
131
+ return details === null ? null : { definition, ...details };
132
+ }
133
+ const { plugins, operations, coverage: settings } = report.appliedConfig;
134
+ const toolchain = recordedEntries(plugins, 'id', ['lcov']);
135
+ const bindings = recordedEntries(operations, 'key', [metric.operation]);
136
+ if (!toolchain || !bindings || !isRecord(settings) || typeof settings.merge !== 'string')
124
137
  return null;
125
- if (!importsCoverage)
126
- return { definition, toolchain, bindings, settings };
127
138
  const { inputDigest, inputDigests, pathBase, ...importSettings } = settings;
128
139
  return { definition, toolchain, bindings, settings: importSettings };
129
140
  }
141
+ function structureMethod(report, operation) {
142
+ const { plugins, operations, parser } = report.appliedConfig;
143
+ if (!Array.isArray(operations))
144
+ return null;
145
+ const scopes = new Set(parserReferences(report).values());
146
+ const candidates = operations.filter(isRecord).filter(entry => entry.key === operation);
147
+ const bindings = [];
148
+ const providerKeys = new Set();
149
+ for (const candidate of candidates) {
150
+ const port = isRecord(candidate.inputs) ? candidate.inputs.syntax : undefined;
151
+ if (!isRecord(port))
152
+ return null;
153
+ const provider = typeof candidate.syntaxProvider === 'string' ? candidate.syntaxProvider : port.operation;
154
+ if (typeof provider !== 'string' || !provider.includes('/'))
155
+ return null;
156
+ if (scopes.size && !scopes.has(provider))
157
+ continue;
158
+ providerKeys.add(provider);
159
+ bindings.push(candidate);
160
+ }
161
+ if (providerKeys.size === 0 || [...scopes].some(provider => !providerKeys.has(provider)))
162
+ return null;
163
+ const providerBindings = recordedEntries(operations, 'key', [...providerKeys].sort(comparePaths));
164
+ const pluginIds = [...new Set([operation, ...providerKeys].map(key => key.slice(0, key.indexOf('/'))))].sort(comparePaths);
165
+ const toolchain = recordedEntries(plugins, 'id', pluginIds);
166
+ if (!providerBindings || !toolchain)
167
+ return null;
168
+ // The original reports carried the Babel configuration at report level.
169
+ const configured = toolchain.map(({ id, version, api, tools, settings }) => ({
170
+ id, version, api, tools, settings: id === 'babel-syntax' && isRecord(parser) ? parser : settings ?? null,
171
+ }));
172
+ return { toolchain: configured, bindings: [...providerBindings, ...bindings.sort((a, b) => comparePaths(JSON.stringify(a), JSON.stringify(b)))] };
173
+ }
130
174
  function recordedEntries(value, key, names) {
131
175
  if (!Array.isArray(value))
132
176
  return null;