@repometry/cli 0.4.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 (57) hide show
  1. package/README.md +8 -5
  2. package/package.json +3 -3
  3. package/target/main/resources/report/json/report-v2.schema.json +1 -0
  4. package/target/main/resources/report/json/repository-summary-v1.schema.json +12 -0
  5. package/target/main/resources/report/json/viewer-inspection-v1.schema.json +31 -0
  6. package/target/main/resources/viewer/index.html +9 -9
  7. package/target/main/resources/viewer/styles.css +8 -9
  8. package/target/main/ts/cli/distribution.d.ts +8 -0
  9. package/target/main/ts/cli/distribution.js +23 -0
  10. package/target/main/ts/cli/imports.js +21 -17
  11. package/target/main/ts/cli/run.d.ts +2 -2
  12. package/target/main/ts/cli/run.js +7 -4
  13. package/target/main/ts/compose/analysis-inventory.d.ts +12 -0
  14. package/target/main/ts/compose/analysis-inventory.js +18 -0
  15. package/target/main/ts/compose/analysis-report.js +3 -16
  16. package/target/main/ts/compose/analysis-results.d.ts +1 -0
  17. package/target/main/ts/compose/analysis-results.js +14 -12
  18. package/target/main/ts/compose/built-ins.d.ts +2 -2
  19. package/target/main/ts/compose/built-ins.js +2 -2
  20. package/target/main/ts/compose/load-plugins.js +9 -6
  21. package/target/main/ts/plugins/built-in.d.ts +2 -0
  22. package/target/main/ts/plugins/built-in.js +2 -1
  23. package/target/main/ts/plugins/json-spans.js +56 -42
  24. package/target/main/ts/plugins/legal/composer-lock.js +1 -1
  25. package/target/main/ts/plugins/legal/cyclonedx.d.ts +2 -0
  26. package/target/main/ts/plugins/legal/cyclonedx.js +61 -0
  27. package/target/main/ts/plugins/legal/dependencies.d.ts +53 -7
  28. package/target/main/ts/plugins/legal/dependencies.js +34 -14
  29. package/target/main/ts/plugins/legal/expression.d.ts +2 -0
  30. package/target/main/ts/plugins/legal/expression.js +69 -0
  31. package/target/main/ts/plugins/legal/licenses.d.ts +1 -0
  32. package/target/main/ts/plugins/legal/licenses.js +55 -28
  33. package/target/main/ts/plugins/legal/npm-lock.js +2 -1
  34. package/target/main/ts/plugins/legal/policy.d.ts +7 -11
  35. package/target/main/ts/plugins/legal/policy.js +23 -102
  36. package/target/main/ts/plugins/legal/sbom-model.d.ts +7 -0
  37. package/target/main/ts/plugins/legal/sbom-model.js +11 -0
  38. package/target/main/ts/plugins/legal/sbom.js +2 -116
  39. package/target/main/ts/plugins/legal/spdx-catalog.d.ts +9 -0
  40. package/target/main/ts/plugins/legal/spdx-catalog.js +28 -0
  41. package/target/main/ts/plugins/legal/spdx-sbom.d.ts +2 -0
  42. package/target/main/ts/plugins/legal/spdx-sbom.js +65 -0
  43. package/target/main/ts/report/html/app/viewer-metric-format.d.ts +2 -0
  44. package/target/main/ts/report/html/app/viewer-metric-format.js +17 -0
  45. package/target/main/ts/report/html/app/viewer-metrics.d.ts +1 -2
  46. package/target/main/ts/report/html/app/viewer-metrics.js +1 -17
  47. package/target/main/ts/report/html/app/viewer-overview-cards.js +15 -37
  48. package/target/main/ts/report/html/app/viewer-overview-lead.js +1 -1
  49. package/target/main/ts/report/html/site/asset-versions.d.ts +2 -0
  50. package/target/main/ts/report/html/site/asset-versions.js +36 -0
  51. package/target/main/ts/report/html/site/badges.d.ts +5 -1
  52. package/target/main/ts/report/html/site/badges.js +17 -11
  53. package/target/main/ts/report/html/site/export-site.js +2 -1
  54. package/target/main/ts/report/html/site/local-server.js +2 -0
  55. package/target/main/ts/report/html/site/projects.js +4 -3
  56. package/target/main/ts/report/json/projections/inspection-details.js +3 -0
  57. package/target/main/ts/report/json/wire/inspection-details-model.d.ts +2 -0
@@ -1,24 +1,8 @@
1
1
  import { isRecord } from '@repometry/core/internal/engine/plugin.js';
2
- import spdx from '../../../resources/licenses/spdx.json' with { type: 'json' };
3
- import { maxLicenseLength } from './dependencies.js';
4
- export const licenseListVersion = spdx.version;
5
- export const presets = ['open-source', 'weak-copyleft', 'permissive'];
6
- const catalog = new Map(Object.entries(spdx.licenses).map(([id, flags]) => [id.toLowerCase(),
7
- { id, open: flags[0] === true || flags[1] === true, kind: flags[2] }]));
8
- const exceptions = new Set(spdx.exceptions.map(id => id.toLowerCase()));
9
- const licenseReference = /^(?:DocumentRef-[A-Za-z0-9.-]+:)?LicenseRef-[A-Za-z0-9.-]+$/i;
10
- const gnuLegacy = /^((?:AGPL|GFDL|GPL|LGPL)-\d\.\d)(\+)?$/i;
11
- const legacyExceptions = {
12
- 'gpl-2.0-with-autoconf-exception': 'GPL-2.0-only',
13
- 'gpl-2.0-with-bison-exception': 'GPL-2.0-only',
14
- 'gpl-2.0-with-classpath-exception': 'GPL-2.0-only',
15
- 'gpl-2.0-with-font-exception': 'GPL-2.0-only',
16
- 'gpl-2.0-with-gcc-exception': 'GPL-2.0-only',
17
- 'gpl-3.0-with-autoconf-exception': 'GPL-3.0-only',
18
- 'gpl-3.0-with-gcc-exception': 'GPL-3.0-only',
19
- };
20
- const operators = new Set(['AND', 'OR', 'WITH', '(', ')']);
21
- const expressionToken = /\s+|[()]|(?:[A-Za-z0-9.-]+:)?[A-Za-z0-9.-]+\+?/y;
2
+ import { evaluateLicenseExpression } from './expression.js';
3
+ import { canonicalLicense, catalog } from './spdx-catalog.js';
4
+ export { licenseListVersion } from './spdx-catalog.js';
5
+ export const presets = ['open-source', 'weak-copyleft', 'permissive', 'osi-approved'];
22
6
  export const policySchema = {
23
7
  type: 'object', additionalProperties: false,
24
8
  properties: {
@@ -27,12 +11,11 @@ export const policySchema = {
27
11
  deny: { type: 'array', items: { type: 'string', minLength: 1 }, uniqueItems: true },
28
12
  exceptions: { type: 'array', items: { type: 'object', required: ['package', 'reason'], additionalProperties: false,
29
13
  properties: { package: { type: 'string', pattern: '\\S' }, reason: { type: 'string', pattern: '\\S' } } } },
30
- dev: { type: 'boolean' },
31
14
  },
32
15
  };
33
- export function licensePolicy({ policy: preset = 'open-source', allow = [], deny = [], exceptions = [], dev = false } = {}) {
16
+ export function licensePolicy({ policy: preset = 'open-source', allow = [], deny = [], exceptions = [] } = {}) {
34
17
  return { preset, allow: policyIds(allow), deny: policyIds(deny),
35
- exceptions: new Map(exceptions.map(entry => [entry.package.trim(), entry.reason.trim()])), dev };
18
+ exceptions: new Map(exceptions.map(entry => [entry.package.trim(), entry.reason.trim()])) };
36
19
  }
37
20
  function policyIds(ids) {
38
21
  return new Set(ids.map(value => {
@@ -42,17 +25,6 @@ function policyIds(ids) {
42
25
  return id;
43
26
  }));
44
27
  }
45
- function canonicalLicense(value) {
46
- if (value === 'UNLICENSED' || value === 'proprietary')
47
- return 'UNLICENSED';
48
- if (licenseReference.test(value))
49
- return value;
50
- const normalized = value.toLowerCase();
51
- const gnu = gnuLegacy.exec(value);
52
- const historical = legacyExceptions[normalized] ?? (gnu ? gnu[1] + (gnu[2] ? '-or-later' : '-only') : undefined);
53
- const id = historical?.toLowerCase() ?? normalized;
54
- return catalog.get(id)?.id ?? (id.endsWith('+') ? catalog.get(id.slice(0, -1))?.id : undefined);
55
- }
56
28
  export function declaredLicense(value) {
57
29
  if (typeof value === 'string')
58
30
  return value.trim() || undefined;
@@ -63,87 +35,36 @@ export function declaredLicense(value) {
63
35
  const choices = value.map(entry => typeof entry === 'string' || isRecord(entry) ? declaredLicense(entry) : undefined);
64
36
  return choices.every(choice => choice !== undefined) ? choices.map(choice => '(' + choice + ')').join(' OR ') : undefined;
65
37
  }
66
- export function licenseDecision(expression, policy) {
67
- if (expression === undefined || expression.length > maxLicenseLength)
68
- return 'unknown';
69
- const parsed = tokenize(expression);
70
- if (parsed === undefined)
71
- return 'unknown';
72
- const tokens = parsed;
73
- let cursor = 0;
74
- function operand(depth) {
75
- if (depth > 64)
76
- return undefined;
77
- const token = tokens[cursor++];
78
- if (token === '(') {
79
- const result = composite(depth + 1, 'OR');
80
- return tokens[cursor++] === ')' ? result : undefined;
81
- }
82
- if (token === undefined || operators.has(token))
83
- return undefined;
84
- if (tokens[cursor] === 'WITH') {
85
- cursor++;
86
- const exception = tokens[cursor++];
87
- if (!exception || !exceptions.has(exception.toLowerCase()))
88
- return undefined;
89
- }
90
- const id = canonicalLicense(token);
91
- return id === undefined ? undefined : decide(id, policy);
92
- }
93
- function composite(depth, operator) {
94
- const next = () => operator === 'AND' ? operand(depth) : composite(depth, 'AND');
95
- let result = next();
96
- while (result !== undefined && tokens[cursor] === operator) {
97
- cursor++;
98
- const right = next();
99
- if (right === undefined)
100
- return undefined;
101
- result = combine(result, right, operator);
102
- }
103
- return result;
104
- }
105
- const decision = composite(0, 'OR');
106
- return cursor === tokens.length ? decision ?? 'unknown' : 'unknown';
38
+ export function licenseKind(expression) {
39
+ const approved = evaluateLicenseExpression(expression, id => catalog.get(id.toLowerCase())?.osiApproved ? 'allowed' : 'unknown');
40
+ if (approved === 'allowed')
41
+ return 'osi';
42
+ const recognized = evaluateLicenseExpression(expression, id => id === 'UNLICENSED' || catalog.has(id.toLowerCase()) ? 'allowed' : 'unknown');
43
+ return recognized === 'allowed' ? 'other' : 'unknown';
107
44
  }
108
- function tokenize(text) {
109
- const tokens = [];
110
- for (let index = 0; index < text.length; index = expressionToken.lastIndex) {
111
- expressionToken.lastIndex = index;
112
- const token = expressionToken.exec(text)?.[0];
113
- if (!token)
114
- return undefined;
115
- if (token === 'WITH' && (!/\s/.test(text[index - 1] ?? '') || !/\s/.test(text[expressionToken.lastIndex] ?? '')))
116
- return undefined;
117
- if (token.trim())
118
- tokens.push(token);
119
- }
120
- return tokens;
45
+ export function licenseDecision(expression, policy) {
46
+ return evaluateLicenseExpression(expression, id => decide(id, policy));
121
47
  }
122
48
  function decide(id, { preset, allow, deny }) {
123
- if (id === 'UNLICENSED')
49
+ if (id === 'UNLICENSED' || deny.has(id))
124
50
  return 'denied';
125
51
  const entry = catalog.get(id.toLowerCase());
126
52
  if (entry === undefined)
127
53
  return 'unknown';
128
- const { open, kind } = entry;
129
- if (kind === 'source-available' || deny.has(id))
54
+ if (preset === 'osi-approved')
55
+ return entry.osiApproved ? 'allowed' : 'denied';
56
+ if (entry.kind === 'source-available')
130
57
  return 'denied';
131
58
  if (allow.has(id))
132
59
  return 'allowed';
60
+ return decideClass(entry, preset);
61
+ }
62
+ function decideClass({ open, kind }, preset) {
133
63
  if (preset === 'open-source')
134
64
  return open || kind !== undefined ? 'allowed' : 'denied';
135
65
  if (kind === undefined)
136
66
  return 'unclassified';
137
- if (kind === 'permissive' || kind === 'public-domain' || (preset === 'weak-copyleft' && kind === 'weak-copyleft'))
138
- return 'allowed';
139
- return 'denied';
140
- }
141
- function combine(left, right, operator) {
142
- const decisive = operator === 'AND' ? 'denied' : 'allowed';
143
- if (left === decisive || right === decisive)
144
- return decisive;
145
- if (left === right)
146
- return left;
147
- return left === 'unknown' || right === 'unknown' ? 'unknown' : 'unclassified';
67
+ const allowed = kind === 'permissive' || kind === 'public-domain' || (preset === 'weak-copyleft' && kind === 'weak-copyleft');
68
+ return allowed ? 'allowed' : 'denied';
148
69
  }
149
70
  //# sourceMappingURL=policy.js.map
@@ -0,0 +1,7 @@
1
+ import type { Dependency } from './dependencies.js';
2
+ export type JsonPath = readonly (string | number)[];
3
+ export type Positioned = Omit<Dependency, 'line' | 'endLine'> & {
4
+ readonly at: JsonPath;
5
+ };
6
+ export declare function entries(value: unknown, name: string): readonly unknown[];
7
+ export declare function text(value: unknown): string | undefined;
@@ -0,0 +1,11 @@
1
+ export function entries(value, name) {
2
+ if (value === undefined)
3
+ return [];
4
+ if (!Array.isArray(value))
5
+ throw new Error(name + ' must be an array');
6
+ return value;
7
+ }
8
+ export function text(value) {
9
+ return typeof value === 'string' && value.trim() ? value.trim() : undefined;
10
+ }
11
+ //# sourceMappingURL=sbom-model.js.map
@@ -1,5 +1,7 @@
1
1
  import { isRecord } from '@repometry/core/internal/engine/plugin.js';
2
2
  import { locateJsonSpans, pointer } from '../json-spans.js';
3
+ import { cyclone } from './cyclonedx.js';
4
+ import { spdx } from './spdx-sbom.js';
3
5
  export function readSbom(format, text) {
4
6
  const value = JSON.parse(text);
5
7
  if (!isRecord(value))
@@ -12,120 +14,4 @@ export function readSbom(format, text) {
12
14
  const ranges = locateJsonSpans(text, wanted, depth);
13
15
  return dependencies.map(({ at, ...entry }) => ({ ...entry, ...ranges.get(pointer(at)) ?? { line: 1, endLine: 1 } }));
14
16
  }
15
- function entries(value, name) {
16
- if (value === undefined)
17
- return [];
18
- if (!Array.isArray(value))
19
- throw new Error(name + ' must be an array');
20
- return value;
21
- }
22
- function text(value) {
23
- return typeof value === 'string' && value.trim() ? value.trim() : undefined;
24
- }
25
- function cyclone(value) {
26
- if (value.bomFormat !== 'CycloneDX' || !['1.4', '1.5', '1.6'].some(version => version === value.specVersion)) {
27
- throw new Error('Expected CycloneDX JSON version 1.4, 1.5 or 1.6');
28
- }
29
- const root = isRecord(value.metadata) && isRecord(value.metadata.component) ? value.metadata.component : undefined;
30
- const rootId = text(root?.['bom-ref']);
31
- const stack = [];
32
- function add(components, prefix) {
33
- const array = entries(components, 'CycloneDX components');
34
- for (let index = array.length - 1; index >= 0; index--)
35
- stack.push({ entry: array[index], at: [...prefix, index] });
36
- }
37
- add(root?.components, ['metadata', 'component', 'components']);
38
- add(value.components, ['components']);
39
- const dependencies = [];
40
- const seen = new Set();
41
- while (stack.length) {
42
- const { entry, at } = stack.pop();
43
- if (!isRecord(entry))
44
- throw new Error('A CycloneDX component must be an object');
45
- const name = text(entry.name);
46
- if (name === undefined)
47
- throw new Error('A CycloneDX component needs a name');
48
- const id = text(entry['bom-ref']);
49
- add(entry.components, [...at, 'components']);
50
- if (id !== undefined && (id === rootId || seen.has(id)))
51
- continue;
52
- if (id !== undefined)
53
- seen.add(id);
54
- const group = text(entry.group);
55
- const version = text(entry.version);
56
- const license = cycloneLicense(entry.licenses);
57
- dependencies.push({ at, name: group && !name.startsWith(group + '/') ? group + '/' + name : name,
58
- ...(version === undefined ? {} : { version }), ...(license === undefined ? {} : { license }), dev: entry.scope === 'excluded' });
59
- }
60
- return dependencies;
61
- }
62
- function cycloneLicense(value) {
63
- const licenses = entries(value, 'CycloneDX licenses');
64
- const declarations = new Set(licenses.flatMap(entry => {
65
- if (!isRecord(entry))
66
- return [];
67
- if (isRecord(entry.license)) {
68
- const license = entry.license;
69
- const value = text(license.id) ?? text(license.name);
70
- return license.acknowledgement !== 'concluded' && value !== undefined ? [value] : [];
71
- }
72
- const expression = text(entry.expression);
73
- return entry.acknowledgement !== 'concluded' && expression !== undefined ? [expression] : [];
74
- }));
75
- return declarations.size ? [...declarations].join(', ') : undefined;
76
- }
77
- function spdx(value) {
78
- if (value.spdxVersion !== 'SPDX-2.3')
79
- throw new Error('Expected SPDX 2.3 JSON');
80
- const roots = new Set(entries(value.documentDescribes, 'SPDX documentDescribes').filter(id => typeof id === 'string'));
81
- const runtime = new Set();
82
- const development = new Set();
83
- const document = text(value.SPDXID) ?? 'SPDXRef-DOCUMENT';
84
- for (const row of entries(value.relationships, 'SPDX relationships')) {
85
- if (!isRecord(row))
86
- continue;
87
- const from = text(row.spdxElementId);
88
- const to = text(row.relatedSpdxElement);
89
- if (from === undefined || to === undefined)
90
- continue;
91
- switch (row.relationshipType) {
92
- case 'DESCRIBES':
93
- if (from === document)
94
- roots.add(to);
95
- break;
96
- case 'DESCRIBED_BY':
97
- if (to === document)
98
- roots.add(from);
99
- break;
100
- case 'DEV_DEPENDENCY_OF':
101
- case 'TEST_DEPENDENCY_OF':
102
- development.add(from);
103
- break;
104
- case 'DEPENDENCY_OF':
105
- case 'RUNTIME_DEPENDENCY_OF':
106
- case 'OPTIONAL_DEPENDENCY_OF':
107
- case 'PROVIDED_DEPENDENCY_OF':
108
- case 'BUILD_DEPENDENCY_OF':
109
- runtime.add(from);
110
- break;
111
- case 'DEPENDS_ON':
112
- runtime.add(to);
113
- break;
114
- }
115
- }
116
- return entries(value.packages, 'SPDX packages').flatMap((entry, index) => {
117
- if (!isRecord(entry))
118
- throw new Error('An SPDX package must be an object');
119
- const name = text(entry.name);
120
- const id = text(entry.SPDXID);
121
- if (name === undefined || id === undefined)
122
- throw new Error('An SPDX package needs a name and SPDXID');
123
- if (roots.has(id))
124
- return [];
125
- const version = text(entry.versionInfo);
126
- const license = text(entry.licenseDeclared);
127
- return [{ at: ['packages', index], name, ...(version === undefined ? {} : { version }),
128
- ...(license === undefined ? {} : { license }), dev: development.has(id) && !runtime.has(id) }];
129
- });
130
- }
131
17
  //# sourceMappingURL=sbom.js.map
@@ -0,0 +1,9 @@
1
+ export declare const licenseListVersion: string;
2
+ export declare const exceptions: Set<string>;
3
+ export declare const catalog: Map<string, {
4
+ id: string;
5
+ osiApproved: boolean;
6
+ open: boolean;
7
+ kind: string | boolean | undefined;
8
+ }>;
9
+ export declare function canonicalLicense(value: string): string | undefined;
@@ -0,0 +1,28 @@
1
+ import spdx from '../../../resources/licenses/spdx.json' with { type: 'json' };
2
+ export const licenseListVersion = spdx.version;
3
+ export const exceptions = new Set(spdx.exceptions.map(id => id.toLowerCase()));
4
+ export const catalog = new Map(Object.entries(spdx.licenses).map(([id, flags]) => [id.toLowerCase(),
5
+ { id, osiApproved: flags[0] === true, open: flags[0] === true || flags[1] === true, kind: flags[2] }]));
6
+ const licenseReference = /^(?:DocumentRef-[A-Za-z0-9.-]+:)?LicenseRef-[A-Za-z0-9.-]+$/i;
7
+ const gnuLegacy = /^((?:AGPL|GFDL|GPL|LGPL)-\d\.\d)(\+)?$/i;
8
+ const legacyExceptions = {
9
+ 'gpl-2.0-with-autoconf-exception': 'GPL-2.0-only',
10
+ 'gpl-2.0-with-bison-exception': 'GPL-2.0-only',
11
+ 'gpl-2.0-with-classpath-exception': 'GPL-2.0-only',
12
+ 'gpl-2.0-with-font-exception': 'GPL-2.0-only',
13
+ 'gpl-2.0-with-gcc-exception': 'GPL-2.0-only',
14
+ 'gpl-3.0-with-autoconf-exception': 'GPL-3.0-only',
15
+ 'gpl-3.0-with-gcc-exception': 'GPL-3.0-only',
16
+ };
17
+ export function canonicalLicense(value) {
18
+ if (value === 'UNLICENSED' || value === 'proprietary')
19
+ return 'UNLICENSED';
20
+ if (licenseReference.test(value))
21
+ return value;
22
+ const normalized = value.toLowerCase();
23
+ const gnu = gnuLegacy.exec(value);
24
+ const historical = legacyExceptions[normalized] ?? (gnu ? gnu[1] + (gnu[2] ? '-or-later' : '-only') : undefined);
25
+ const id = historical?.toLowerCase() ?? normalized;
26
+ return catalog.get(id)?.id ?? (id.endsWith('+') ? catalog.get(id.slice(0, -1))?.id : undefined);
27
+ }
28
+ //# sourceMappingURL=spdx-catalog.js.map
@@ -0,0 +1,2 @@
1
+ import type { Positioned } from './sbom-model.js';
2
+ export declare function spdx(value: Record<string, unknown>): Positioned[];
@@ -0,0 +1,65 @@
1
+ import { isRecord } from '@repometry/core/internal/engine/plugin.js';
2
+ import { entries, text } from './sbom-model.js';
3
+ const inverse = new Set(['DEV_DEPENDENCY_OF', 'TEST_DEPENDENCY_OF', 'DEPENDENCY_OF', 'RUNTIME_DEPENDENCY_OF',
4
+ 'OPTIONAL_DEPENDENCY_OF', 'PROVIDED_DEPENDENCY_OF', 'BUILD_DEPENDENCY_OF']);
5
+ export function spdx(value) {
6
+ if (value.spdxVersion !== 'SPDX-2.3')
7
+ throw new Error('Expected SPDX 2.3 JSON');
8
+ const roots = new Set(entries(value.documentDescribes, 'SPDX documentDescribes').filter(item => typeof item === 'string'));
9
+ const document = text(value.SPDXID) ?? 'SPDXRef-DOCUMENT';
10
+ const groups = readRelationships(entries(value.relationships, 'SPDX relationships'), document, roots);
11
+ return entries(value.packages, 'SPDX packages').flatMap((entry, index) => {
12
+ const dependency = readPackage(entry, index, roots, groups);
13
+ return dependency === undefined ? [] : [dependency];
14
+ });
15
+ }
16
+ function readRelationships(relationships, document, roots) {
17
+ const groups = new Map();
18
+ for (const row of relationships) {
19
+ const relation = readRelationship(row);
20
+ if (relation === undefined)
21
+ continue;
22
+ recordRoot(roots, document, relation);
23
+ const { from, to, type } = relation;
24
+ const dependency = type === 'DEPENDS_ON' ? to : inverse.has(type) ? from : undefined;
25
+ if (dependency !== undefined)
26
+ addGroup(groups, dependency, type);
27
+ }
28
+ return groups;
29
+ }
30
+ function readRelationship(row) {
31
+ if (!isRecord(row))
32
+ return undefined;
33
+ const from = text(row.spdxElementId);
34
+ const to = text(row.relatedSpdxElement);
35
+ const type = text(row.relationshipType);
36
+ return from && to && type ? { from, to, type } : undefined;
37
+ }
38
+ function recordRoot(roots, document, { from, to, type }) {
39
+ if (type === 'DESCRIBES' && from === document)
40
+ roots.add(to);
41
+ if (type === 'DESCRIBED_BY' && to === document)
42
+ roots.add(from);
43
+ }
44
+ function addGroup(groups, dependency, label) {
45
+ const previous = groups.get(dependency);
46
+ if (previous)
47
+ previous.add(label);
48
+ else
49
+ groups.set(dependency, new Set([label]));
50
+ }
51
+ function readPackage(entry, index, roots, groups) {
52
+ if (!isRecord(entry))
53
+ throw new Error('An SPDX package must be an object');
54
+ const name = text(entry.name);
55
+ const id = text(entry.SPDXID);
56
+ if (name === undefined || id === undefined)
57
+ throw new Error('An SPDX package needs a name and SPDXID');
58
+ if (roots.has(id))
59
+ return undefined;
60
+ const version = text(entry.versionInfo);
61
+ const license = text(entry.licenseDeclared);
62
+ return { at: ['packages', index], name, ...(version === undefined ? {} : { version }),
63
+ ...(license === undefined ? {} : { license }), groups: [...groups.get(id) ?? []].sort() };
64
+ }
65
+ //# sourceMappingURL=spdx-sbom.js.map
@@ -21,3 +21,5 @@ export declare function bandScale(spec: MetricSpec): 'heat' | 'neutral';
21
21
  export declare function bandOf(spec: MetricSpec, value: number, highest: number): number;
22
22
  /** The legend's words, best band first; null where the bands are relative and the legend reads Lower … Higher. */
23
23
  export declare function bandLabels(spec: MetricSpec): string[] | null;
24
+ /** A size in bytes, in binary units named the way code hosts name them: 512 B, 4.8 KB, 340 KB, 1.2 MB. */
25
+ export declare function size(bytes: number | null | undefined): string;
@@ -91,3 +91,20 @@ export function bandLabels(spec) {
91
91
  const ranges = unit === 'count' ? countRanges(limits, labels[unit]) : spanRanges(limits, labels[unit], unit);
92
92
  return spec.descriptor.better === 'higher' ? ranges.reverse() : ranges;
93
93
  }
94
+ /** A size in bytes, in binary units named the way code hosts name them: 512 B, 4.8 KB, 340 KB, 1.2 MB. */
95
+ export function size(bytes) {
96
+ if (bytes === null || bytes === undefined)
97
+ return '—';
98
+ const units = ['B', 'KB', 'MB', 'GB', 'TB'];
99
+ let value = bytes;
100
+ let unit = 0;
101
+ while (value >= 1024 && unit < units.length - 1) {
102
+ value /= 1024;
103
+ unit++;
104
+ }
105
+ // Below ten of a unit one decimal tells sizes apart; above it, whole units read faster.
106
+ const shown = unit === 0 ? Math.round(value) : value < 10 ? Math.round(value * 10) / 10 : Math.round(value);
107
+ if (shown >= 1024 && unit < units.length - 1)
108
+ return `1 ${units[unit + 1]}`;
109
+ return `${shown.toLocaleString(undefined, { maximumFractionDigits: 1 })} ${units[unit]}`;
110
+ }
@@ -39,8 +39,7 @@ export declare function gradeScope(quality: QualitySummary | undefined): string
39
39
  export declare function metricValue(report: PublicHistoryEntry, metric: Metric, quality: QualitySummary | undefined, context?: InspectionContext): number | null;
40
40
  export declare function isPercent(metric: Metric): boolean;
41
41
  export declare function formatMetric(value: number, metric: Metric): string;
42
- /** A size in bytes, in binary units named the way code hosts name them: 512 B, 4.8 KB, 340 KB, 1.2 MB. */
43
- export declare function size(bytes: number | null | undefined): string;
42
+ export declare const size: typeof metricFormat.size;
44
43
  export declare function count(value: number | null): string;
45
44
  /** Remediation time in hours and minutes: 45 min, 2 h, 3 h 20 min. */
46
45
  export declare const duration: typeof metricFormat.duration;
@@ -151,23 +151,7 @@ export function formatMetric(value, metric) {
151
151
  return percent.format(value);
152
152
  return metric === 'effort' ? duration(value) : count(value);
153
153
  }
154
- /** A size in bytes, in binary units named the way code hosts name them: 512 B, 4.8 KB, 340 KB, 1.2 MB. */
155
- export function size(bytes) {
156
- if (bytes === null || bytes === undefined)
157
- return '—';
158
- const units = ['B', 'KB', 'MB', 'GB', 'TB'];
159
- let value = bytes;
160
- let unit = 0;
161
- while (value >= 1024 && unit < units.length - 1) {
162
- value /= 1024;
163
- unit++;
164
- }
165
- // Below ten of a unit one decimal tells sizes apart; above it, whole units read faster.
166
- const shown = unit === 0 ? Math.round(value) : value < 10 ? Math.round(value * 10) / 10 : Math.round(value);
167
- if (shown >= 1024 && unit < units.length - 1)
168
- return `1 ${units[unit + 1]}`;
169
- return `${shown.toLocaleString(undefined, { maximumFractionDigits: 1 })} ${units[unit]}`;
170
- }
154
+ export const size = metricFormat.size;
171
155
  export function count(value) {
172
156
  return value === null ? '—' : integers.format(value);
173
157
  }
@@ -1,9 +1,7 @@
1
1
  import { byId, count, percent, quantity } from './viewer-dom.js';
2
2
  import { codeSmellCategories, securityCategories } from './viewer-files.js';
3
- import { coverageGrade, formatMetric, gradeScope, legalFindings, metricValue, pluginSpec, securityGrades, securityRisks } from './viewer-metrics.js';
3
+ import { coverageGrade, legalFindings, securityGrades, securityRisks } from './viewer-metrics.js';
4
4
  import { href } from './viewer-route.js';
5
- /** Coverage kinds beyond lines, by their registry keys, in the words the Overview card uses for them. */
6
- const coverageKinds = [['branch-coverage', 'Branches'], ['function-coverage', 'Functions']];
7
5
  /** A detail that counts something leads to exactly what it counts, where the report has a page for it. */
8
6
  export function detailText(id, text, link) {
9
7
  if (link === undefined) {
@@ -28,7 +26,7 @@ export function legalLink(sha) {
28
26
  export function uncoveredLink(sha) {
29
27
  return href({ page: 'hotspots', sha, rank: 'missedLines' });
30
28
  }
31
- /** A small progress ring for a ratio; an empty ring when there is no value. */
29
+ /** A progress ring for measured coverage. */
32
30
  function ring(ratio) {
33
31
  const namespace = 'http://www.w3.org/2000/svg';
34
32
  const svg = document.createElementNS(namespace, 'svg');
@@ -43,27 +41,12 @@ function ring(ratio) {
43
41
  track.setAttribute('class', 'ring-track');
44
42
  arc.setAttribute('class', 'ring-arc');
45
43
  const length = 2 * Math.PI * 16;
46
- arc.setAttribute('stroke-dasharray', `${(ratio ?? 0) * length} ${length}`);
44
+ arc.setAttribute('stroke-dasharray', `${ratio * length} ${length}`);
47
45
  // Flat ends keep the gap true to the value: a round cap would close 95.9% into a full circle and turn
48
- // a zero into a dot. An unknown or zero ratio shows the track alone.
49
- svg.append(...(ratio !== null && ratio > 0 ? [track, arc] : [track]));
46
+ // a zero into a dot. A measured zero shows the track alone.
47
+ svg.append(...(ratio > 0 ? [track, arc] : [track]));
50
48
  return svg;
51
49
  }
52
- /** Line coverage leads; the other kinds the coverage report carries follow on a quieter line. */
53
- function renderCoverageKinds(report) {
54
- const kinds = coverageKinds.flatMap(([key, name]) => {
55
- const metric = key;
56
- const value = pluginSpec(metric) ? metricValue(report, metric, undefined) : null;
57
- if (value === null)
58
- return [];
59
- // Each kind keeps its number; a narrow card wraps between kinds, never inside one.
60
- const kind = document.createElement('span');
61
- kind.textContent = `${name} ${formatMetric(value, metric)}`;
62
- return [kind];
63
- });
64
- byId('coverage-kinds').replaceChildren(...kinds.flatMap((kind, index) => index ? [' · ', kind] : [kind]));
65
- byId('coverage-kinds').hidden = kinds.length === 0;
66
- }
67
50
  export function renderInspection(report) {
68
51
  const lines = report.lineCoverage;
69
52
  const coverage = lines && lines.total > 0 ? lines.covered / lines.total : null;
@@ -72,13 +55,8 @@ export function renderInspection(report) {
72
55
  else
73
56
  detailText('coverage-detail', `${percent(coverage)} of ${count(lines.total)} lines`, coverage < 1 ? uncoveredLink(report.sha) : undefined);
74
57
  const mark = byId('coverage-mark');
75
- mark.replaceChildren(ring(coverage));
76
- // The ring is coloured by the grade the coverage badge gives it.
77
- if (coverage === null)
78
- delete mark.dataset.grade;
79
- else
80
- mark.dataset.grade = coverageGrade(coverage);
81
- renderCoverageKinds(report);
58
+ mark.replaceChildren(coverage === null ? '–' : ring(coverage));
59
+ mark.dataset.grade = coverage === null ? 'none' : coverageGrade(coverage);
82
60
  }
83
61
  export function renderQuality(report, quality) {
84
62
  const maintainability = quality?.maintainability ?? null;
@@ -89,25 +67,25 @@ export function renderQuality(report, quality) {
89
67
  detailText('maintainability-detail', 'Not measured');
90
68
  else
91
69
  detailText('maintainability-detail', quantity(maintainability.smells, 'code smell'), maintainability.smells > 0 ? smellsLink(report.sha) : undefined);
92
- const scope = byId('maintainability-scope');
93
- scope.textContent = gradeScope(quality) ?? '';
94
- scope.hidden = !scope.textContent;
95
70
  renderLegal(report.sha, quality?.legal);
96
71
  }
97
72
  function renderLegal(sha, legal) {
98
73
  const mark = byId('legal-mark');
99
74
  mark.textContent = legal?.grade ?? '–';
100
75
  mark.dataset.grade = legal?.grade ?? 'none';
101
- const scope = byId('legal-scope');
102
76
  if (legal === undefined) {
103
- scope.textContent = 'Add a lockfile with license data or import an SBOM.';
104
77
  detailText('legal-detail', 'No license data');
105
78
  return;
106
79
  }
107
- const { checked } = legal;
108
- scope.textContent = count(checked) + (checked === 1 ? ' dependency checked' : ' dependencies checked');
109
80
  const findings = legalFindings(legal);
110
- detailText('legal-detail', findings ? quantity(findings, 'finding') : 'No findings', findings ? legalLink(sha) : undefined);
81
+ const { unknownLicenses = 0, deniedLicenses = 0 } = legal;
82
+ const other = findings - unknownLicenses - deniedLicenses;
83
+ const detail = unknownLicenses || deniedLicenses ? [
84
+ ...(unknownLicenses ? [`${count(unknownLicenses)} without a known license`] : []),
85
+ ...(deniedLicenses ? [`${count(deniedLicenses)} denied`] : []),
86
+ ...(other > 0 ? [quantity(other, 'other finding')] : []),
87
+ ].join(', ') : findings ? quantity(findings, 'finding') : 'No findings';
88
+ detailText('legal-detail', detail, findings ? legalLink(sha) : undefined);
111
89
  }
112
90
  /** The words of the five steps, as every grade has them: clear A, low B, medium C, high D, critical F. */
113
91
  const severities = ['clear', 'low', 'medium', 'high', 'critical'];
@@ -18,7 +18,7 @@ const areas = {
18
18
  const emptyAreas = {
19
19
  coverage: 'No coverage report for this commit.',
20
20
  security: 'No security scanner report for this commit.',
21
- legal: 'No license data for this commit.',
21
+ legal: 'No license data for this commit. Add a lockfile with license data or import an SBOM.',
22
22
  };
23
23
  /** The figures that count findings lead to them; uncovered lines lead to the files that hold them. */
24
24
  const findingLinks = {
@@ -0,0 +1,2 @@
1
+ /** A module's version includes the URLs of the dependencies it loads. */
2
+ export declare function versionAssets(files: Map<string, Buffer>): Map<string, Buffer>;
@@ -0,0 +1,36 @@
1
+ import { digest } from '@repometry/core/internal/model/snapshot.js';
2
+ /** A module's version includes the URLs of the dependencies it loads. */
3
+ export function versionAssets(files) {
4
+ const versions = new Map();
5
+ const active = new Set();
6
+ const url = (name) => './' + name + '?v=' + version(name);
7
+ function version(name) {
8
+ const cached = versions.get(name);
9
+ if (cached !== undefined)
10
+ return cached;
11
+ if (active.has(name))
12
+ throw new Error('Circular viewer asset reference: ' + name);
13
+ active.add(name);
14
+ const bytes = files.get(name);
15
+ const content = name.endsWith('.js') ? versionModule(bytes) : bytes;
16
+ const hash = digest(content);
17
+ files.set(name, content);
18
+ active.delete(name);
19
+ versions.set(name, hash);
20
+ return hash;
21
+ }
22
+ function versionModule(bytes) {
23
+ const text = bytes.toString('utf8');
24
+ return Buffer.from(text.replace(/(["'])\.\/([\w.-]+\.(?:js|css|json))\1/g, (literal, quote, name) => files.has(name) ? quote + url(name) + quote : literal));
25
+ }
26
+ for (const name of files.keys())
27
+ if (name.endsWith('.js'))
28
+ version(name);
29
+ const index = files.get('index.html');
30
+ if (index) {
31
+ const html = index.toString('utf8').replace(/\b(src|href)="\.\/([\w.-]+\.(?:js|css|json))"/g, (attribute, key, name) => files.has(name) ? key + '="' + url(name) + '"' : attribute);
32
+ files.set('index.html', Buffer.from(html));
33
+ }
34
+ return files;
35
+ }
36
+ //# sourceMappingURL=asset-versions.js.map