@repometry/cli 0.3.0 → 0.5.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 (69) hide show
  1. package/README.md +10 -5
  2. package/package.json +3 -3
  3. package/target/main/resources/licenses/spdx.json +746 -0
  4. package/target/main/resources/report/json/config-v2.schema.json +2 -1
  5. package/target/main/resources/report/json/file-metrics-v1.schema.json +2 -0
  6. package/target/main/resources/report/json/report-v2.schema.json +6 -3
  7. package/target/main/resources/report/json/repository-summary-v1.schema.json +14 -0
  8. package/target/main/resources/viewer/index.html +5 -1
  9. package/target/main/resources/viewer/styles.css +7 -3
  10. package/target/main/ts/api/git/git.d.ts +2 -1
  11. package/target/main/ts/api/git/git.js +4 -4
  12. package/target/main/ts/api/git/inspection-source.js +2 -2
  13. package/target/main/ts/api/git/local.d.ts +1 -1
  14. package/target/main/ts/api/git/local.js +5 -4
  15. package/target/main/ts/api/import/finding-import.js +2 -9
  16. package/target/main/ts/api/import/license-import.d.ts +2 -0
  17. package/target/main/ts/api/import/license-import.js +36 -0
  18. package/target/main/ts/api/import/repository-path.d.ts +1 -0
  19. package/target/main/ts/api/import/repository-path.js +10 -0
  20. package/target/main/ts/cli/distribution.d.ts +8 -0
  21. package/target/main/ts/cli/distribution.js +23 -0
  22. package/target/main/ts/cli/imports.d.ts +2 -0
  23. package/target/main/ts/cli/imports.js +6 -2
  24. package/target/main/ts/cli/run.d.ts +2 -2
  25. package/target/main/ts/cli/run.js +17 -8
  26. package/target/main/ts/compose/analysis-report.js +5 -2
  27. package/target/main/ts/compose/analysis-results.d.ts +3 -2
  28. package/target/main/ts/compose/analysis-results.js +15 -6
  29. package/target/main/ts/compose/analysis-steps.js +3 -0
  30. package/target/main/ts/compose/analyze-snapshot.d.ts +1 -1
  31. package/target/main/ts/compose/analyze-snapshot.js +7 -4
  32. package/target/main/ts/compose/built-ins.d.ts +2 -2
  33. package/target/main/ts/compose/built-ins.js +2 -2
  34. package/target/main/ts/compose/inspect.d.ts +2 -0
  35. package/target/main/ts/compose/inspect.js +7 -4
  36. package/target/main/ts/compose/load-plugins.js +4 -2
  37. package/target/main/ts/compose/phases.d.ts +7 -3
  38. package/target/main/ts/compose/phases.js +26 -10
  39. package/target/main/ts/plugins/built-in.d.ts +2 -0
  40. package/target/main/ts/plugins/built-in.js +4 -1
  41. package/target/main/ts/plugins/json-spans.d.ts +11 -0
  42. package/target/main/ts/plugins/json-spans.js +86 -0
  43. package/target/main/ts/plugins/legal/composer-lock.d.ts +2 -0
  44. package/target/main/ts/plugins/legal/composer-lock.js +24 -0
  45. package/target/main/ts/plugins/legal/dependencies.d.ts +73 -0
  46. package/target/main/ts/plugins/legal/dependencies.js +27 -0
  47. package/target/main/ts/plugins/legal/licenses.d.ts +19 -0
  48. package/target/main/ts/plugins/legal/licenses.js +112 -0
  49. package/target/main/ts/plugins/legal/npm-lock.d.ts +3 -0
  50. package/target/main/ts/plugins/legal/npm-lock.js +30 -0
  51. package/target/main/ts/plugins/legal/policy.d.ts +72 -0
  52. package/target/main/ts/plugins/legal/policy.js +149 -0
  53. package/target/main/ts/plugins/legal/sbom.d.ts +3 -0
  54. package/target/main/ts/plugins/legal/sbom.js +131 -0
  55. package/target/main/ts/plugins/legal/unverified-lock.d.ts +1 -0
  56. package/target/main/ts/plugins/legal/unverified-lock.js +21 -0
  57. package/target/main/ts/plugins/security/npm-supply-chain.js +2 -86
  58. package/target/main/ts/report/html/app/viewer-issue-group.js +1 -1
  59. package/target/main/ts/report/html/app/viewer-metric-registry.js +1 -1
  60. package/target/main/ts/report/html/app/viewer-metrics.d.ts +2 -1
  61. package/target/main/ts/report/html/app/viewer-metrics.js +7 -2
  62. package/target/main/ts/report/html/app/viewer-overview-cards.d.ts +1 -0
  63. package/target/main/ts/report/html/app/viewer-overview-cards.js +20 -19
  64. package/target/main/ts/report/html/app/viewer-overview-lead.js +4 -1
  65. package/target/main/ts/report/html/app/viewer-shell.js +3 -1
  66. package/target/main/ts/report/html/app/viewer-tokenizer.js +35 -8
  67. package/target/main/ts/report/html/app/viewer-trend-data.js +1 -0
  68. package/target/main/ts/report/html/app/viewer.js +5 -2
  69. package/target/main/ts/report/json/validation/report.js +2 -2
@@ -0,0 +1,30 @@
1
+ import { isRecord } from '@repometry/core/internal/engine/plugin.js';
2
+ import { locateJsonSpans, pointer } from '../json-spans.js';
3
+ import { declaredLicense } from './policy.js';
4
+ /** Older and unknown versions lack the supported package metadata. */
5
+ export function readNpmLock(text) {
6
+ const lock = JSON.parse(text);
7
+ if (!isRecord(lock))
8
+ throw new Error('The npm lockfile must be a JSON object');
9
+ if (lock.lockfileVersion !== 2 && lock.lockfileVersion !== 3)
10
+ return undefined;
11
+ if (!isRecord(lock.packages))
12
+ throw new Error('The npm lockfile must contain a packages object');
13
+ const dependencies = Object.entries(lock.packages).flatMap(([path, entry]) => {
14
+ const prefix = path.lastIndexOf('node_modules/');
15
+ if (prefix === -1 || !isRecord(entry) || entry.link === true)
16
+ return [];
17
+ const name = (typeof entry.name === 'string' ? entry.name.trim() : '') || path.slice(prefix + 'node_modules/'.length);
18
+ if (!name)
19
+ return [];
20
+ const version = typeof entry.version === 'string' ? entry.version : undefined;
21
+ const license = declaredLicense(entry.license ?? entry.licenses);
22
+ return [{ at: pointer(['packages', path]), name, ...(version === undefined ? {} : { version }),
23
+ ...(license === undefined ? {} : { license }), dev: entry.dev === true }];
24
+ });
25
+ if (!dependencies.length)
26
+ return [];
27
+ const spans = locateJsonSpans(text, new Set(dependencies.map(({ at }) => at)), 2);
28
+ return dependencies.map(({ at, ...dependency }) => ({ ...dependency, ...spans.get(at) ?? { line: 1, endLine: 1 } }));
29
+ }
30
+ //# sourceMappingURL=npm-lock.js.map
@@ -0,0 +1,72 @@
1
+ export declare const licenseListVersion: string;
2
+ export declare const presets: readonly ['open-source', 'weak-copyleft', 'permissive'];
3
+ type Preset = typeof presets[number];
4
+ type Decision = 'allowed' | 'denied' | 'unknown' | 'unclassified';
5
+ interface Exception {
6
+ readonly package: string;
7
+ readonly reason: string;
8
+ }
9
+ export interface PolicyOptions {
10
+ readonly policy?: Preset;
11
+ readonly allow?: readonly string[];
12
+ readonly deny?: readonly string[];
13
+ readonly exceptions?: readonly Exception[];
14
+ readonly dev?: boolean;
15
+ }
16
+ interface Policy {
17
+ readonly preset: Preset;
18
+ readonly allow: ReadonlySet<string>;
19
+ readonly deny: ReadonlySet<string>;
20
+ readonly exceptions: ReadonlyMap<string, string>;
21
+ readonly dev: boolean;
22
+ }
23
+ export declare const policySchema: {
24
+ readonly type: 'object';
25
+ readonly additionalProperties: false;
26
+ readonly properties: {
27
+ readonly policy: {
28
+ readonly enum: readonly ["open-source", "weak-copyleft", "permissive"];
29
+ };
30
+ readonly allow: {
31
+ readonly type: 'array';
32
+ readonly items: {
33
+ readonly type: 'string';
34
+ readonly minLength: 1;
35
+ };
36
+ readonly uniqueItems: true;
37
+ };
38
+ readonly deny: {
39
+ readonly type: 'array';
40
+ readonly items: {
41
+ readonly type: 'string';
42
+ readonly minLength: 1;
43
+ };
44
+ readonly uniqueItems: true;
45
+ };
46
+ readonly exceptions: {
47
+ readonly type: 'array';
48
+ readonly items: {
49
+ readonly type: 'object';
50
+ readonly required: readonly ['package', 'reason'];
51
+ readonly additionalProperties: false;
52
+ readonly properties: {
53
+ readonly package: {
54
+ readonly type: 'string';
55
+ readonly pattern: '\\S';
56
+ };
57
+ readonly reason: {
58
+ readonly type: 'string';
59
+ readonly pattern: '\\S';
60
+ };
61
+ };
62
+ };
63
+ };
64
+ readonly dev: {
65
+ readonly type: 'boolean';
66
+ };
67
+ };
68
+ };
69
+ export declare function licensePolicy({ policy: preset, allow, deny, exceptions, dev }?: PolicyOptions): Policy;
70
+ export declare function declaredLicense(value: unknown): string | undefined;
71
+ export declare function licenseDecision(expression: string | undefined, policy: Policy): Decision;
72
+ export {};
@@ -0,0 +1,149 @@
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;
22
+ export const policySchema = {
23
+ type: 'object', additionalProperties: false,
24
+ properties: {
25
+ policy: { enum: presets },
26
+ allow: { type: 'array', items: { type: 'string', minLength: 1 }, uniqueItems: true },
27
+ deny: { type: 'array', items: { type: 'string', minLength: 1 }, uniqueItems: true },
28
+ exceptions: { type: 'array', items: { type: 'object', required: ['package', 'reason'], additionalProperties: false,
29
+ properties: { package: { type: 'string', pattern: '\\S' }, reason: { type: 'string', pattern: '\\S' } } } },
30
+ dev: { type: 'boolean' },
31
+ },
32
+ };
33
+ export function licensePolicy({ policy: preset = 'open-source', allow = [], deny = [], exceptions = [], dev = false } = {}) {
34
+ return { preset, allow: policyIds(allow), deny: policyIds(deny),
35
+ exceptions: new Map(exceptions.map(entry => [entry.package.trim(), entry.reason.trim()])), dev };
36
+ }
37
+ function policyIds(ids) {
38
+ return new Set(ids.map(value => {
39
+ const id = canonicalLicense(value.trim());
40
+ if (!id || !catalog.has(id.toLowerCase()))
41
+ throw new Error('Expected an SPDX license identifier, received ' + JSON.stringify(value));
42
+ return id;
43
+ }));
44
+ }
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
+ export function declaredLicense(value) {
57
+ if (typeof value === 'string')
58
+ return value.trim() || undefined;
59
+ if (isRecord(value) && typeof value.type === 'string')
60
+ return declaredLicense(value.type);
61
+ if (!Array.isArray(value) || !value.length)
62
+ return undefined;
63
+ const choices = value.map(entry => typeof entry === 'string' || isRecord(entry) ? declaredLicense(entry) : undefined);
64
+ return choices.every(choice => choice !== undefined) ? choices.map(choice => '(' + choice + ')').join(' OR ') : undefined;
65
+ }
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';
107
+ }
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;
121
+ }
122
+ function decide(id, { preset, allow, deny }) {
123
+ if (id === 'UNLICENSED')
124
+ return 'denied';
125
+ const entry = catalog.get(id.toLowerCase());
126
+ if (entry === undefined)
127
+ return 'unknown';
128
+ const { open, kind } = entry;
129
+ if (kind === 'source-available' || deny.has(id))
130
+ return 'denied';
131
+ if (allow.has(id))
132
+ return 'allowed';
133
+ if (preset === 'open-source')
134
+ return open || kind !== undefined ? 'allowed' : 'denied';
135
+ if (kind === undefined)
136
+ 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';
148
+ }
149
+ //# sourceMappingURL=policy.js.map
@@ -0,0 +1,3 @@
1
+ import type { LicenseImportFormat } from '@repometry/core/internal/model/license-evidence.js';
2
+ import type { Dependency } from './dependencies.js';
3
+ export declare function readSbom(format: LicenseImportFormat, text: string): Dependency[];
@@ -0,0 +1,131 @@
1
+ import { isRecord } from '@repometry/core/internal/engine/plugin.js';
2
+ import { locateJsonSpans, pointer } from '../json-spans.js';
3
+ export function readSbom(format, text) {
4
+ const value = JSON.parse(text);
5
+ if (!isRecord(value))
6
+ throw new Error('The SBOM must be a JSON object');
7
+ const dependencies = format === 'cyclonedx' ? cyclone(value) : spdx(value);
8
+ const wanted = new Set(dependencies.map(({ at }) => pointer(at)));
9
+ if (wanted.size === 0)
10
+ return [];
11
+ const depth = dependencies.reduce((max, { at }) => Math.max(max, at.length), 0);
12
+ const ranges = locateJsonSpans(text, wanted, depth);
13
+ return dependencies.map(({ at, ...entry }) => ({ ...entry, ...ranges.get(pointer(at)) ?? { line: 1, endLine: 1 } }));
14
+ }
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
+ //# sourceMappingURL=sbom.js.map
@@ -0,0 +1 @@
1
+ export declare function listsDependencies(name: string, text: string): boolean;
@@ -0,0 +1,21 @@
1
+ import { isRecord } from '@repometry/core/internal/engine/plugin.js';
2
+ const packageMarkers = {
3
+ 'poetry.lock': /^\[\[package\]\]\s*$/m,
4
+ 'go.sum': /^\S+\s+v\S+\s+h1:\S+/m,
5
+ 'Gemfile.lock': /^DEPENDENCIES\r?\n {2}\S/m,
6
+ 'pnpm-lock.yaml': /^(?:packages|snapshots):[ \t]*\r?\n(?:\s*\r?\n)* {2}\S/m,
7
+ 'yarn.lock': /^(?![#\s]|[^\r\n]*@workspace:)[^\r\n]*@[^\r\n]*:[ \t]*\r?$/m,
8
+ };
9
+ export function listsDependencies(name, text) {
10
+ if (name === 'Cargo.lock')
11
+ return /^source\s*=\s*"|^dependencies\s*=\s*\[\s*"/m.test(text);
12
+ if (name === 'uv.lock')
13
+ return /^source\s*=\s*\{\s*(registry|git|url|path)\s*=|^dependencies\s*=\s*\[\s*\{/m.test(text);
14
+ if (name !== 'Pipfile.lock')
15
+ return packageMarkers[name]?.test(text) ?? false;
16
+ const lock = JSON.parse(text);
17
+ if (!isRecord(lock))
18
+ throw new Error('The Pipfile lock must contain a JSON object');
19
+ return [lock.default, lock.develop].some(group => isRecord(group) && Object.keys(group).length > 0);
20
+ }
21
+ //# sourceMappingURL=unverified-lock.js.map
@@ -2,6 +2,7 @@ import { isRecord } from '@repometry/core/internal/engine/plugin.js';
2
2
  import { findingResult } from '@repometry/core/internal/engine/author-contracts.js';
3
3
  import { bundledPlugin, pluginManifestSchema } from '@repometry/core/internal/engine/plugin-manifest.js';
4
4
  import { sourceFile } from '@repometry/core/internal/model/snapshot.js';
5
+ import { locateJsonSpans, pointer } from '../json-spans.js';
5
6
  const tool = 'npm-supply-chain';
6
7
  const ruleDescriptions = {
7
8
  'dependency-from-url': 'A package.json dependency is installed from a URL, git repository or tarball instead of a registry version.',
@@ -76,7 +77,7 @@ function jsonHits(name, text, analyse) {
76
77
  const found = analyse(value);
77
78
  if (found.length === 0)
78
79
  return [];
79
- const spans = locate(text, new Set(found.map(hit => pointer(hit.at))), Math.max(...found.map(hit => hit.at.length)));
80
+ const spans = locateJsonSpans(text, new Set(found.map(hit => pointer(hit.at))), Math.max(...found.map(hit => hit.at.length)));
80
81
  return found.map(({ at, ...hit }) => ({ ...hit, ...spans.get(pointer(at)) }));
81
82
  }
82
83
  function manifestHits(manifest) {
@@ -286,89 +287,4 @@ function display(url) {
286
287
  function abbreviate(text, limit) {
287
288
  return text.length > limit ? `${text.slice(0, limit - 1)}…` : text;
288
289
  }
289
- function pointer(path) {
290
- return path.map(segment => JSON.stringify(segment)).join('');
291
- }
292
- /**
293
- * Find the lines of the wanted values in JSON text that JSON.parse has already accepted. A member starts on the line
294
- * of its key and ends on the line where its value ends. Only paths up to `depth` keys deep are tracked.
295
- */
296
- function locate(text, wanted, depth) {
297
- const spans = new Map();
298
- const stack = [];
299
- let line = 1;
300
- const child = () => {
301
- const parent = stack.at(-1);
302
- if (!parent)
303
- return { path: '', line };
304
- const path = parent.path === undefined || stack.length > depth ? undefined
305
- : parent.path + (parent.array ? `#${parent.index}` : JSON.stringify(parent.key));
306
- return { path, line: parent.array ? line : parent.keyLine };
307
- };
308
- const scalar = () => {
309
- const { path, line: start } = child();
310
- if (path !== undefined && wanted.has(path))
311
- spans.set(path, { line: start, endLine: line });
312
- };
313
- for (let index = 0; index < text.length;) {
314
- const char = text[index];
315
- if (char === '\n')
316
- line++;
317
- if (char === '\n' || char === ' ' || char === '\t' || char === '\r' || char === ':') {
318
- index++;
319
- }
320
- else if (char === ',') {
321
- const parent = stack.at(-1);
322
- if (parent?.array)
323
- parent.index++;
324
- else if (parent)
325
- parent.expectKey = true;
326
- index++;
327
- }
328
- else if (char === '"') {
329
- const end = stringEnd(text, index);
330
- const parent = stack.at(-1);
331
- if (parent && !parent.array && parent.expectKey) {
332
- const raw = text.slice(index + 1, end);
333
- parent.key = raw.includes('\\') ? JSON.parse(text.slice(index, end + 1)) : raw;
334
- parent.keyLine = line;
335
- parent.expectKey = false;
336
- }
337
- else {
338
- scalar();
339
- }
340
- index = end + 1;
341
- }
342
- else if (char === '{' || char === '[') {
343
- const { path, line: start } = child();
344
- stack.push({ path, line: start, array: char === '[', index: 0, key: '', keyLine: line, expectKey: char === '{' });
345
- index++;
346
- }
347
- else if (char === '}' || char === ']') {
348
- const frame = stack.pop();
349
- if (frame?.path !== undefined && wanted.has(frame.path))
350
- spans.set(frame.path, { line: frame.line, endLine: line });
351
- index++;
352
- }
353
- else {
354
- scalar();
355
- while (index < text.length && !/[\s,\]}]/.test(text[index]))
356
- index++;
357
- }
358
- }
359
- return spans;
360
- }
361
- function stringEnd(text, start) {
362
- for (let from = start + 1;;) {
363
- const quote = text.indexOf('"', from);
364
- if (quote < 0)
365
- return text.length;
366
- let slashes = 0;
367
- while (text[quote - 1 - slashes] === '\\')
368
- slashes++;
369
- if (slashes % 2 === 0)
370
- return quote;
371
- from = quote + 1;
372
- }
373
- }
374
290
  //# sourceMappingURL=npm-supply-chain.js.map
@@ -5,7 +5,7 @@ import { duration } from './viewer-metrics.js';
5
5
  import { lineSnippet, renderExcerpt } from './viewer-source-view.js';
6
6
  import { highlighter } from './viewer-tokenizer.js';
7
7
  export const issueCategories = {
8
- structure: 'Structure', duplication: 'Duplication', lint: 'Lint', security: 'Security',
8
+ structure: 'Structure', duplication: 'Duplication', lint: 'Lint', security: 'Security', legal: 'Legal',
9
9
  dependency: 'Dependencies', secret: 'Secrets', infrastructure: 'Infrastructure',
10
10
  };
11
11
  export const issueLevels = { high: 'High', medium: 'Medium', low: 'Low', unknown: 'Unknown' };
@@ -23,7 +23,7 @@ const handDrawn = new Set([
23
23
  ]);
24
24
  /** Words that already mean something: query keys, Trends views and the series the viewer draws by hand. */
25
25
  const reserved = new Set(['lang', 'language', 'component', 'path', 'in', 'has', 'analysed', 'ignored', 'lockfile', 'lockfiles', 'remediation', 'missedlines', 'churn',
26
- 'debt', 'debt-changes', 'diff-coverage', 'effort', 'smells', 'files', 'classes', 'comments', 'code-lines', 'security',
26
+ 'debt', 'debt-changes', 'diff-coverage', 'effort', 'smells', 'files', 'classes', 'comments', 'code-lines', 'security', 'legal',
27
27
  'coverable-lines', 'covered-lines', 'uncovered-lines', 'security-high', 'security-medium', 'security-low',
28
28
  ...Object.values(builtinKeys)]);
29
29
  /** Curated groups first, in this order; groups named by plugins follow in catalog order. */
@@ -4,7 +4,7 @@ import type { PublicHistoryEntry } from '../../json/wire/public-history-model.js
4
4
  import type { MetricDescriptor } from '../../json/wire/summary-model.js';
5
5
  import * as metricFormat from './viewer-metric-format.js';
6
6
  import type { MetricSpec } from './viewer-metric-registry.js';
7
- export type BuiltinMetric = 'coverage' | 'lines' | 'files' | 'functions' | 'complexity' | 'cognitive' | 'duplication' | 'debt' | 'effort' | 'smells' | 'code-lines' | 'classes' | 'comments' | 'security' | 'coverable-lines' | 'covered-lines' | 'uncovered-lines' | 'security-high' | 'security-medium' | 'security-low';
7
+ export type BuiltinMetric = 'coverage' | 'lines' | 'files' | 'functions' | 'complexity' | 'cognitive' | 'duplication' | 'debt' | 'effort' | 'smells' | 'code-lines' | 'classes' | 'comments' | 'security' | 'legal' | 'coverable-lines' | 'covered-lines' | 'uncovered-lines' | 'security-high' | 'security-medium' | 'security-low';
8
8
  /** Another plugin's metric, by the key the registry gives it. */
9
9
  export type PluginMetric = string & {
10
10
  readonly plugin: unique symbol;
@@ -32,6 +32,7 @@ export declare function labelOf(metric: Metric): string;
32
32
  export declare function definitionOf(metric: Metric): string;
33
33
  /** Which way is better: the green and red of changes and the flags on a chart follow it. */
34
34
  export declare function betterOf(metric: Metric): 'lower' | 'higher' | 'none';
35
+ export declare function legalFindings({ high, medium, low, unknown }: NonNullable<QualitySummary['legal']>): number;
35
36
  /** Where the maintainability grade covers only some files, as in a repository some plugins cannot measure, it says so. */
36
37
  export declare function gradeScope(quality: QualitySummary | undefined): string | undefined;
37
38
  /** A metric's value at a commit; null where the commit has no such measurement. */
@@ -5,7 +5,7 @@ export const metricLabels = {
5
5
  coverage: 'Line coverage', lines: 'Physical lines', files: 'Analysed files', functions: 'Functions',
6
6
  complexity: 'Peak cyclomatic', cognitive: 'Cognitive complexity', duplication: 'Duplication',
7
7
  debt: 'Technical debt ratio', effort: 'Remediation time', smells: 'Code smells', 'code-lines': 'Code lines',
8
- classes: 'Classes', comments: 'Comment lines', security: 'Security findings',
8
+ classes: 'Classes', comments: 'Comment lines', security: 'Security findings', legal: 'Legal findings',
9
9
  'coverable-lines': 'Measured lines', 'covered-lines': 'Covered lines', 'uncovered-lines': 'Uncovered lines',
10
10
  'security-high': 'High severity', 'security-medium': 'Medium severity', 'security-low': 'Low severity',
11
11
  };
@@ -37,6 +37,7 @@ export const metricDefinitions = {
37
37
  classes: 'Classes found in inspected source files.',
38
38
  comments: 'Lines that contain only comments.',
39
39
  security: 'Findings from imported security scanners, all severities.',
40
+ legal: 'Findings from the dependency license policy check.',
40
41
  'coverable-lines': 'Lines the coverage report measured.',
41
42
  'covered-lines': 'Measured lines executed by tests.',
42
43
  'uncovered-lines': 'Measured lines no test executed.',
@@ -45,7 +46,7 @@ export const metricDefinitions = {
45
46
  'security-low': 'Low-severity findings from imported security scanners.',
46
47
  };
47
48
  /** Metrics where a lower value is better. Coverage is better higher; the rest are neutral. */
48
- const lowerIsBetter = new Set(['complexity', 'cognitive', 'duplication', 'debt', 'effort', 'smells', 'security',
49
+ const lowerIsBetter = new Set(['complexity', 'cognitive', 'duplication', 'debt', 'effort', 'smells', 'security', 'legal',
49
50
  'uncovered-lines', 'security-high', 'security-medium', 'security-low']);
50
51
  const integers = new Intl.NumberFormat();
51
52
  const percent = new Intl.NumberFormat(undefined, { style: 'percent', maximumFractionDigits: 1 });
@@ -94,6 +95,9 @@ export function betterOf(metric) {
94
95
  return spec.descriptor.better;
95
96
  return lowerIsBetter.has(metric) ? 'lower' : metric === 'coverage' ? 'higher' : 'none';
96
97
  }
98
+ export function legalFindings({ high, medium, low, unknown }) {
99
+ return high + medium + low + unknown;
100
+ }
97
101
  function securityTotal(context) {
98
102
  return context?.security ? Object.values(context.security).reduce((total, value) => total + value, 0) : null;
99
103
  }
@@ -113,6 +117,7 @@ const readers = {
113
117
  classes: (_, quality) => quality?.classes,
114
118
  comments: (_, quality) => quality?.comments,
115
119
  security: (_, __, context) => securityTotal(context),
120
+ legal: (_, quality) => quality?.legal === undefined ? null : legalFindings(quality.legal),
116
121
  'coverable-lines': report => report.lineCoverage?.total,
117
122
  'covered-lines': report => report.lineCoverage?.covered,
118
123
  'uncovered-lines': report => report.lineCoverage ? report.lineCoverage.total - report.lineCoverage.covered : null,
@@ -6,6 +6,7 @@ export declare function detailText(id: string, text: string, link?: string): voi
6
6
  /** Where each Overview figure leads: the findings it counts, the files it ranks, the function it names. */
7
7
  export declare function smellsLink(sha: string): string;
8
8
  export declare function securityLink(sha: string, level?: string): string;
9
+ export declare function legalLink(sha: string): string;
9
10
  export declare function uncoveredLink(sha: string): string;
10
11
  export declare function renderInspection(report: PublicHistoryEntry): void;
11
12
  export declare function renderQuality(report: PublicHistoryEntry, quality: QualitySummary | undefined): void;