@repometry/cli 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.
- package/README.md +1 -0
- package/package.json +2 -2
- package/target/main/resources/report/json/report-v2.schema.json +1 -0
- package/target/main/resources/report/json/repository-summary-v1.schema.json +12 -0
- package/target/main/resources/report/json/viewer-inspection-v1.schema.json +31 -0
- package/target/main/resources/viewer/index.html +9 -9
- package/target/main/resources/viewer/styles.css +8 -8
- package/target/main/ts/cli/imports.js +21 -17
- package/target/main/ts/compose/analysis-inventory.d.ts +12 -0
- package/target/main/ts/compose/analysis-inventory.js +18 -0
- package/target/main/ts/compose/analysis-report.js +3 -16
- package/target/main/ts/compose/analysis-results.d.ts +1 -0
- package/target/main/ts/compose/analysis-results.js +14 -12
- package/target/main/ts/compose/built-ins.d.ts +2 -2
- package/target/main/ts/compose/built-ins.js +2 -2
- package/target/main/ts/compose/load-plugins.js +9 -6
- package/target/main/ts/plugins/built-in.d.ts +2 -0
- package/target/main/ts/plugins/built-in.js +2 -1
- package/target/main/ts/plugins/json-spans.js +56 -42
- package/target/main/ts/plugins/legal/composer-lock.js +1 -1
- package/target/main/ts/plugins/legal/cyclonedx.d.ts +2 -0
- package/target/main/ts/plugins/legal/cyclonedx.js +61 -0
- package/target/main/ts/plugins/legal/dependencies.d.ts +53 -7
- package/target/main/ts/plugins/legal/dependencies.js +34 -14
- package/target/main/ts/plugins/legal/expression.d.ts +2 -0
- package/target/main/ts/plugins/legal/expression.js +69 -0
- package/target/main/ts/plugins/legal/licenses.d.ts +1 -0
- package/target/main/ts/plugins/legal/licenses.js +55 -28
- package/target/main/ts/plugins/legal/npm-lock.js +2 -1
- package/target/main/ts/plugins/legal/policy.d.ts +7 -11
- package/target/main/ts/plugins/legal/policy.js +23 -102
- package/target/main/ts/plugins/legal/sbom-model.d.ts +7 -0
- package/target/main/ts/plugins/legal/sbom-model.js +11 -0
- package/target/main/ts/plugins/legal/sbom.js +2 -116
- package/target/main/ts/plugins/legal/spdx-catalog.d.ts +9 -0
- package/target/main/ts/plugins/legal/spdx-catalog.js +28 -0
- package/target/main/ts/plugins/legal/spdx-sbom.d.ts +2 -0
- package/target/main/ts/plugins/legal/spdx-sbom.js +65 -0
- package/target/main/ts/report/html/app/viewer-metric-format.d.ts +2 -0
- package/target/main/ts/report/html/app/viewer-metric-format.js +17 -0
- package/target/main/ts/report/html/app/viewer-metrics.d.ts +1 -2
- package/target/main/ts/report/html/app/viewer-metrics.js +1 -17
- package/target/main/ts/report/html/app/viewer-overview-cards.js +15 -19
- package/target/main/ts/report/html/app/viewer-overview-lead.js +1 -1
- package/target/main/ts/report/html/site/asset-versions.d.ts +2 -0
- package/target/main/ts/report/html/site/asset-versions.js +36 -0
- package/target/main/ts/report/html/site/badges.d.ts +5 -1
- package/target/main/ts/report/html/site/badges.js +17 -11
- package/target/main/ts/report/html/site/export-site.js +2 -1
- package/target/main/ts/report/html/site/local-server.js +2 -0
- package/target/main/ts/report/html/site/projects.js +4 -3
- package/target/main/ts/report/json/projections/inspection-details.js +3 -0
- package/target/main/ts/report/json/wire/inspection-details-model.d.ts +2 -0
|
@@ -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,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
|
-
|
|
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
|
-
|
|
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,6 +1,6 @@
|
|
|
1
1
|
import { byId, count, percent, quantity } from './viewer-dom.js';
|
|
2
2
|
import { codeSmellCategories, securityCategories } from './viewer-files.js';
|
|
3
|
-
import { coverageGrade,
|
|
3
|
+
import { coverageGrade, legalFindings, securityGrades, securityRisks } from './viewer-metrics.js';
|
|
4
4
|
import { href } from './viewer-route.js';
|
|
5
5
|
/** A detail that counts something leads to exactly what it counts, where the report has a page for it. */
|
|
6
6
|
export function detailText(id, text, link) {
|
|
@@ -26,7 +26,7 @@ export function legalLink(sha) {
|
|
|
26
26
|
export function uncoveredLink(sha) {
|
|
27
27
|
return href({ page: 'hotspots', sha, rank: 'missedLines' });
|
|
28
28
|
}
|
|
29
|
-
/** A
|
|
29
|
+
/** A progress ring for measured coverage. */
|
|
30
30
|
function ring(ratio) {
|
|
31
31
|
const namespace = 'http://www.w3.org/2000/svg';
|
|
32
32
|
const svg = document.createElementNS(namespace, 'svg');
|
|
@@ -41,10 +41,10 @@ function ring(ratio) {
|
|
|
41
41
|
track.setAttribute('class', 'ring-track');
|
|
42
42
|
arc.setAttribute('class', 'ring-arc');
|
|
43
43
|
const length = 2 * Math.PI * 16;
|
|
44
|
-
arc.setAttribute('stroke-dasharray', `${
|
|
44
|
+
arc.setAttribute('stroke-dasharray', `${ratio * length} ${length}`);
|
|
45
45
|
// Flat ends keep the gap true to the value: a round cap would close 95.9% into a full circle and turn
|
|
46
|
-
// a zero into a dot.
|
|
47
|
-
svg.append(...(ratio
|
|
46
|
+
// a zero into a dot. A measured zero shows the track alone.
|
|
47
|
+
svg.append(...(ratio > 0 ? [track, arc] : [track]));
|
|
48
48
|
return svg;
|
|
49
49
|
}
|
|
50
50
|
export function renderInspection(report) {
|
|
@@ -55,12 +55,8 @@ export function renderInspection(report) {
|
|
|
55
55
|
else
|
|
56
56
|
detailText('coverage-detail', `${percent(coverage)} of ${count(lines.total)} lines`, coverage < 1 ? uncoveredLink(report.sha) : undefined);
|
|
57
57
|
const mark = byId('coverage-mark');
|
|
58
|
-
mark.replaceChildren(ring(coverage));
|
|
59
|
-
|
|
60
|
-
if (coverage === null)
|
|
61
|
-
delete mark.dataset.grade;
|
|
62
|
-
else
|
|
63
|
-
mark.dataset.grade = coverageGrade(coverage);
|
|
58
|
+
mark.replaceChildren(coverage === null ? '–' : ring(coverage));
|
|
59
|
+
mark.dataset.grade = coverage === null ? 'none' : coverageGrade(coverage);
|
|
64
60
|
}
|
|
65
61
|
export function renderQuality(report, quality) {
|
|
66
62
|
const maintainability = quality?.maintainability ?? null;
|
|
@@ -71,25 +67,25 @@ export function renderQuality(report, quality) {
|
|
|
71
67
|
detailText('maintainability-detail', 'Not measured');
|
|
72
68
|
else
|
|
73
69
|
detailText('maintainability-detail', quantity(maintainability.smells, 'code smell'), maintainability.smells > 0 ? smellsLink(report.sha) : undefined);
|
|
74
|
-
const scope = byId('maintainability-scope');
|
|
75
|
-
scope.textContent = gradeScope(quality) ?? '';
|
|
76
|
-
scope.hidden = !scope.textContent;
|
|
77
70
|
renderLegal(report.sha, quality?.legal);
|
|
78
71
|
}
|
|
79
72
|
function renderLegal(sha, legal) {
|
|
80
73
|
const mark = byId('legal-mark');
|
|
81
74
|
mark.textContent = legal?.grade ?? '–';
|
|
82
75
|
mark.dataset.grade = legal?.grade ?? 'none';
|
|
83
|
-
const scope = byId('legal-scope');
|
|
84
76
|
if (legal === undefined) {
|
|
85
|
-
scope.textContent = 'Add a lockfile with license data or import an SBOM.';
|
|
86
77
|
detailText('legal-detail', 'No license data');
|
|
87
78
|
return;
|
|
88
79
|
}
|
|
89
|
-
const { checked } = legal;
|
|
90
|
-
scope.textContent = count(checked) + (checked === 1 ? ' dependency checked' : ' dependencies checked');
|
|
91
80
|
const findings = legalFindings(legal);
|
|
92
|
-
|
|
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);
|
|
93
89
|
}
|
|
94
90
|
/** The words of the five steps, as every grade has them: clear A, low B, medium C, high D, critical F. */
|
|
95
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,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
|
|
@@ -7,5 +7,9 @@ export interface SecurityCounts {
|
|
|
7
7
|
readonly low: number;
|
|
8
8
|
readonly unknown: number;
|
|
9
9
|
}
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* The README badges, all always written. A category is measured when its input exists: coverage lines,
|
|
12
|
+
* a maintainability grade, scanner counts (zero findings grade A) and a Legal summary (checked dependencies).
|
|
13
|
+
* The repometry badge shows the lowest measured grade.
|
|
14
|
+
*/
|
|
11
15
|
export declare function badges(report: PublicHistoryEntry | undefined, quality: QualitySummary | undefined, security?: SecurityCounts): Map<string, Buffer>;
|
|
@@ -1,21 +1,27 @@
|
|
|
1
|
-
import { coverageGrade, securityGrade } from '@repometry/core/internal/model/quality-summary.js';
|
|
1
|
+
import { coverageGrade, lowestGrade, securityGrade } from '@repometry/core/internal/model/quality-summary.js';
|
|
2
2
|
const colors = { A: '#5ec269', B: '#74a83a', C: '#d9a400', D: '#ec8a2c', F: '#db4a3f' };
|
|
3
3
|
const unavailable = '#6b7684';
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* The README badges, all always written. A category is measured when its input exists: coverage lines,
|
|
6
|
+
* a maintainability grade, scanner counts (zero findings grade A) and a Legal summary (checked dependencies).
|
|
7
|
+
* The repometry badge shows the lowest measured grade.
|
|
8
|
+
*/
|
|
5
9
|
export function badges(report, quality, security) {
|
|
6
10
|
const lines = report?.lineCoverage;
|
|
7
11
|
const ratio = lines && lines.total > 0 ? lines.covered / lines.total : null;
|
|
8
|
-
const
|
|
12
|
+
const maintainability = quality?.maintainability?.grade ?? null;
|
|
9
13
|
const coverage = lines && lines.total > 0 ? `${BigInt(lines.covered) * 100n / BigInt(lines.total)}%` : '—';
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
const coverageLetter = ratio === null ? null : coverageGrade(ratio);
|
|
15
|
+
const securityLetter = security ? securityGrade(security) : null;
|
|
16
|
+
const legalLetter = quality?.legal?.grade ?? null;
|
|
17
|
+
const overall = lowestGrade([maintainability, coverageLetter, securityLetter, legalLetter]);
|
|
18
|
+
return new Map([
|
|
19
|
+
['coverage.svg', badge('coverage', coverage, coverageLetter)],
|
|
20
|
+
['legal.svg', badge('legal', legalLetter ?? '—', legalLetter)],
|
|
21
|
+
['maintainability.svg', badge('maintainability', maintainability ?? '—', maintainability)],
|
|
22
|
+
['repometry.svg', badge('repometry', overall ?? '—', overall)],
|
|
23
|
+
['security.svg', badge('security', securityLetter ?? '—', securityLetter)],
|
|
13
24
|
]);
|
|
14
|
-
if (security) {
|
|
15
|
-
const grade = securityGrade(security);
|
|
16
|
-
files.set('security.svg', badge('security', grade, grade));
|
|
17
|
-
}
|
|
18
|
-
return files;
|
|
19
25
|
}
|
|
20
26
|
function badge(name, value, grade) {
|
|
21
27
|
const fill = grade ? colors[grade] : unavailable;
|
|
@@ -8,6 +8,7 @@ import { packJson } from '../../json/wire/compact-json.js';
|
|
|
8
8
|
import { comparePaths, digest } from '@repometry/core/internal/model/snapshot.js';
|
|
9
9
|
import { pullReviewsSchema } from '../../json/wire/pull-review-model.js';
|
|
10
10
|
import { badges } from './badges.js';
|
|
11
|
+
import { versionAssets } from './asset-versions.js';
|
|
11
12
|
const appDirectory = new URL('../app/', import.meta.url);
|
|
12
13
|
const wireDirectory = new URL('../../json/wire/', import.meta.url);
|
|
13
14
|
const resourceDirectory = new URL('../../../../resources/viewer/', import.meta.url);
|
|
@@ -59,7 +60,7 @@ export async function siteFiles(reports, options = {}) {
|
|
|
59
60
|
files.set(name, Buffer.from(data));
|
|
60
61
|
}
|
|
61
62
|
files.set('summary.json', siteSummary(rows, options, row => details.get(row.sha)));
|
|
62
|
-
return files;
|
|
63
|
+
return versionAssets(files);
|
|
63
64
|
}
|
|
64
65
|
export function siteSummary(rows, { components, pulls = [], sources, branch }, inspectionPath) {
|
|
65
66
|
const ordered = orderSummaries(rows);
|
|
@@ -3,6 +3,7 @@ import { siteSummary, viewerAssets } from './export-site.js';
|
|
|
3
3
|
import { inspectionAsset } from '../../json/projections/inspection-details.js';
|
|
4
4
|
import { packJson } from '../../json/wire/compact-json.js';
|
|
5
5
|
import { commitSummary, orderSummaries, withCommitMetadata } from '../../json/projections/commit-summary.js';
|
|
6
|
+
import { versionAssets } from './asset-versions.js';
|
|
6
7
|
import { serveAssets } from './server.js';
|
|
7
8
|
import { sourceResponse } from './source-route.js';
|
|
8
9
|
export async function serveSite(reader, port, options = {}, source) {
|
|
@@ -14,6 +15,7 @@ export async function serveSite(reader, port, options = {}, source) {
|
|
|
14
15
|
files.set('index.html', Buffer.from(files.get('index.html').toString('utf8')
|
|
15
16
|
.replace('name="repometry-view" content="private"', 'name="repometry-view" content="local"')));
|
|
16
17
|
files.set('summary.json', siteSummary(rows, options, liveInspectionPath));
|
|
18
|
+
versionAssets(files);
|
|
17
19
|
async function read(sha) {
|
|
18
20
|
if (!validSubjectId('commit', sha))
|
|
19
21
|
return undefined;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import { lstat, mkdir, readFile, readdir, rename, rm, writeFile } from 'node:fs/promises';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
|
+
import { versionAssets } from './asset-versions.js';
|
|
4
5
|
import { readExportedSummary } from './exported-server.js';
|
|
5
6
|
const indexMarker = '<meta name="repometry-projects" content="1">';
|
|
6
7
|
const resources = '../../../../resources/viewer/';
|
|
@@ -11,12 +12,12 @@ export async function exportProjects(directory) {
|
|
|
11
12
|
.filter(entry => entry !== null);
|
|
12
13
|
entries.sort((left, right) => left.name.localeCompare(right.name));
|
|
13
14
|
const marker = await readOptional(join(directory, 'index.html'));
|
|
14
|
-
const files = new Map([
|
|
15
|
+
const files = versionAssets(new Map([
|
|
15
16
|
['styles.css', await readFile(new URL(resources + 'styles.css', import.meta.url))],
|
|
16
17
|
['projects.js', await readFile(new URL('../app/viewer-projects.js', import.meta.url))],
|
|
17
|
-
['projects.json', JSON.stringify({ schema: 'urn:repometry:schema:projects:1', projects: entries }) + '\n'],
|
|
18
|
+
['projects.json', Buffer.from(JSON.stringify({ schema: 'urn:repometry:schema:projects:1', projects: entries }) + '\n')],
|
|
18
19
|
['index.html', await readFile(new URL(resources + 'projects.html', import.meta.url))],
|
|
19
|
-
]);
|
|
20
|
+
]));
|
|
20
21
|
if (marker !== null && !marker.includes(indexMarker))
|
|
21
22
|
throw new Error('Directory already contains another site index');
|
|
22
23
|
for (const name of files.keys()) {
|
|
@@ -3,6 +3,7 @@ import { javascriptType, typescriptType } from '@repometry/core/internal/model/f
|
|
|
3
3
|
import { isRecord } from '@repometry/core/internal/model/plugin-data.js';
|
|
4
4
|
import { legacySyntaxPlugin } from './inspection-context.js';
|
|
5
5
|
import { canonicalMetricId, definitions } from '@repometry/core/internal/model/measurement.js';
|
|
6
|
+
import { licenseInputSummaries } from '@repometry/core/internal/model/license-evidence.js';
|
|
6
7
|
import { lcovLines } from '@repometry/core/internal/model/line-coverage.js';
|
|
7
8
|
import { comparePaths } from '@repometry/core/internal/model/snapshot.js';
|
|
8
9
|
import { fileMetrics } from './file-metrics.js';
|
|
@@ -21,6 +22,7 @@ export function inspectionDetails(report, { components = [], languages } = {}) {
|
|
|
21
22
|
});
|
|
22
23
|
const metrics = display === undefined ? files : { ...files, languages: display };
|
|
23
24
|
const lineCoverage = report.pluginData?.products[lcovLines.id]?.[0]?.value;
|
|
25
|
+
const licenseInputs = licenseInputSummaries(report.pluginData?.products);
|
|
24
26
|
const profile = profileSettings(report.appliedConfig);
|
|
25
27
|
const ruleCatalog = report.pluginData?.rules.flatMap(({ plugin, rules }) => rules.map(rule => ({
|
|
26
28
|
source: plugin, kind: 'check', rule: rule.id, category: rule.category,
|
|
@@ -29,6 +31,7 @@ export function inspectionDetails(report, { components = [], languages } = {}) {
|
|
|
29
31
|
...(rule.defaults?.cost === undefined ? {} : { minutesPerExcess: rule.defaults.cost }),
|
|
30
32
|
})));
|
|
31
33
|
return { metrics, functions: complexFunctions(report), diagnostics: report.diagnostics, findings: report.findings,
|
|
34
|
+
...(licenseInputs === undefined ? {} : { licenseInputs }),
|
|
32
35
|
components: components.length ? componentFiles(components, metrics) : undefined,
|
|
33
36
|
...(lcovLines.accepts(lineCoverage) ? { lineCoverage } : {}),
|
|
34
37
|
...(profile ? { profile: { ...profile, ...(ruleCatalog?.length ? { ruleCatalog } : {}) } } : {}) };
|
|
@@ -3,12 +3,14 @@ import type { FileMetricsReport } from './file-metrics-model.js';
|
|
|
3
3
|
import type { InspectionContext } from './inspection-context-model.js';
|
|
4
4
|
import type { ComplexFunction } from './public-history-model.js';
|
|
5
5
|
import type { ComponentMetrics } from './component-model.js';
|
|
6
|
+
import type { LicenseInputSummary } from '@repometry/core/internal/model/license-evidence.js';
|
|
6
7
|
import type { LineCoverage } from '@repometry/core/internal/model/line-coverage.js';
|
|
7
8
|
export interface InspectionDetails {
|
|
8
9
|
readonly metrics: FileMetricsReport;
|
|
9
10
|
readonly functions: readonly ComplexFunction[];
|
|
10
11
|
readonly diagnostics: Report['diagnostics'];
|
|
11
12
|
readonly findings?: Report['findings'];
|
|
13
|
+
readonly licenseInputs?: readonly LicenseInputSummary[];
|
|
12
14
|
readonly components?: readonly ComponentMetrics[];
|
|
13
15
|
readonly lineCoverage?: LineCoverage;
|
|
14
16
|
/**
|