@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,4 +1,4 @@
|
|
|
1
|
-
import type { LicenseImportFormat } from '@repometry/core/internal/model/license-evidence.js';
|
|
1
|
+
import type { LicenseGroupCount, LicenseImportFormat, LicenseKindCounts } from '@repometry/core/internal/model/license-evidence.js';
|
|
2
2
|
import type { DataContract } from '@repometry/core/internal/engine/plugin.js';
|
|
3
3
|
export declare const maxLicenseLength = 256;
|
|
4
4
|
export interface Dependency {
|
|
@@ -6,23 +6,27 @@ export interface Dependency {
|
|
|
6
6
|
readonly version?: string;
|
|
7
7
|
readonly license?: string;
|
|
8
8
|
readonly overlongLicense?: true;
|
|
9
|
-
readonly
|
|
9
|
+
readonly groups: readonly string[];
|
|
10
10
|
readonly line: number;
|
|
11
11
|
readonly endLine: number;
|
|
12
12
|
}
|
|
13
|
-
export interface
|
|
13
|
+
export interface RawDependencySource {
|
|
14
14
|
readonly path: string;
|
|
15
15
|
readonly packages: readonly Dependency[];
|
|
16
16
|
readonly unverified?: true;
|
|
17
17
|
readonly format?: LicenseImportFormat;
|
|
18
18
|
}
|
|
19
|
+
export interface DependencySource extends RawDependencySource {
|
|
20
|
+
readonly groups: readonly LicenseGroupCount[];
|
|
21
|
+
readonly licenseKinds: LicenseKindCounts;
|
|
22
|
+
}
|
|
19
23
|
export declare const dependencySources: DataContract<readonly DependencySource[]>;
|
|
20
24
|
export declare const dependencySourcesSchema: {
|
|
21
25
|
readonly type: 'array';
|
|
22
26
|
readonly items: {
|
|
23
27
|
readonly type: 'object';
|
|
24
28
|
readonly additionalProperties: false;
|
|
25
|
-
readonly required: readonly ['path', 'packages'];
|
|
29
|
+
readonly required: readonly ['path', 'packages', 'groups', 'licenseKinds'];
|
|
26
30
|
readonly properties: {
|
|
27
31
|
readonly path: {
|
|
28
32
|
readonly type: 'string';
|
|
@@ -33,7 +37,7 @@ export declare const dependencySourcesSchema: {
|
|
|
33
37
|
readonly items: {
|
|
34
38
|
readonly type: 'object';
|
|
35
39
|
readonly additionalProperties: false;
|
|
36
|
-
readonly required: readonly ['name', '
|
|
40
|
+
readonly required: readonly ['name', 'groups', 'line', 'endLine'];
|
|
37
41
|
readonly properties: {
|
|
38
42
|
readonly name: {
|
|
39
43
|
readonly type: 'string';
|
|
@@ -48,8 +52,13 @@ export declare const dependencySourcesSchema: {
|
|
|
48
52
|
readonly overlongLicense: {
|
|
49
53
|
readonly const: true;
|
|
50
54
|
};
|
|
51
|
-
readonly
|
|
52
|
-
readonly type: '
|
|
55
|
+
readonly groups: {
|
|
56
|
+
readonly type: 'array';
|
|
57
|
+
readonly items: {
|
|
58
|
+
readonly type: 'string';
|
|
59
|
+
readonly minLength: 1;
|
|
60
|
+
};
|
|
61
|
+
readonly uniqueItems: true;
|
|
53
62
|
};
|
|
54
63
|
readonly line: {
|
|
55
64
|
readonly type: 'integer';
|
|
@@ -68,6 +77,43 @@ export declare const dependencySourcesSchema: {
|
|
|
68
77
|
readonly format: {
|
|
69
78
|
readonly enum: readonly ["cyclonedx", "spdx"];
|
|
70
79
|
};
|
|
80
|
+
readonly groups: {
|
|
81
|
+
readonly type: 'array';
|
|
82
|
+
readonly items: {
|
|
83
|
+
readonly type: 'object';
|
|
84
|
+
readonly additionalProperties: false;
|
|
85
|
+
readonly required: readonly ['name', 'count'];
|
|
86
|
+
readonly properties: {
|
|
87
|
+
readonly name: {
|
|
88
|
+
readonly type: 'string';
|
|
89
|
+
readonly minLength: 1;
|
|
90
|
+
};
|
|
91
|
+
readonly count: {
|
|
92
|
+
readonly type: 'integer';
|
|
93
|
+
readonly minimum: 0;
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
readonly licenseKinds: {
|
|
99
|
+
readonly type: 'object';
|
|
100
|
+
readonly additionalProperties: false;
|
|
101
|
+
readonly required: readonly ['osi', 'other', 'unknown'];
|
|
102
|
+
readonly properties: {
|
|
103
|
+
readonly osi: {
|
|
104
|
+
readonly type: 'integer';
|
|
105
|
+
readonly minimum: 0;
|
|
106
|
+
};
|
|
107
|
+
readonly other: {
|
|
108
|
+
readonly type: 'integer';
|
|
109
|
+
readonly minimum: 0;
|
|
110
|
+
};
|
|
111
|
+
readonly unknown: {
|
|
112
|
+
readonly type: 'integer';
|
|
113
|
+
readonly minimum: 0;
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
};
|
|
71
117
|
};
|
|
72
118
|
};
|
|
73
119
|
};
|
|
@@ -1,27 +1,47 @@
|
|
|
1
|
-
import { licenseImportFormats } from '@repometry/core/internal/model/license-evidence.js';
|
|
1
|
+
import { licenseDependencyInventory, licenseImportFormats, licenseInputSummary } from '@repometry/core/internal/model/license-evidence.js';
|
|
2
2
|
import { isRecord } from '@repometry/core/internal/engine/plugin.js';
|
|
3
3
|
export const maxLicenseLength = 256;
|
|
4
|
+
const count = { type: 'integer', minimum: 0 };
|
|
5
|
+
const group = { type: 'object', additionalProperties: false, required: ['name', 'count'],
|
|
6
|
+
properties: { name: { type: 'string', minLength: 1 }, count } };
|
|
7
|
+
const licenseKinds = { type: 'object', additionalProperties: false, required: ['osi', 'other', 'unknown'],
|
|
8
|
+
properties: { osi: count, other: count, unknown: count } };
|
|
4
9
|
const dependency = {
|
|
5
|
-
type: 'object', additionalProperties: false, required: ['name', '
|
|
10
|
+
type: 'object', additionalProperties: false, required: ['name', 'groups', 'line', 'endLine'],
|
|
6
11
|
properties: {
|
|
7
12
|
name: { type: 'string', minLength: 1 }, version: { type: 'string' }, license: { type: 'string' }, overlongLicense: { const: true },
|
|
8
|
-
|
|
13
|
+
groups: { type: 'array', items: { type: 'string', minLength: 1 }, uniqueItems: true }, line: { type: 'integer', minimum: 1 }, endLine: { type: 'integer', minimum: 1 },
|
|
9
14
|
},
|
|
10
15
|
};
|
|
11
16
|
export const dependencySources = {
|
|
12
|
-
id:
|
|
13
|
-
accepts: (value) => Array.isArray(value) && value.every(
|
|
14
|
-
&& (source.format === undefined || licenseImportFormats.some(format => format === source.format))
|
|
15
|
-
&& (source.unverified === undefined || source.unverified === true) && typeof source.path === 'string' && source.path.length > 0 && Array.isArray(source.packages)
|
|
16
|
-
&& source.packages.every(item => isRecord(item) && typeof item.name === 'string' && item.name.length > 0
|
|
17
|
-
&& (item.version === undefined || typeof item.version === 'string') && (item.license === undefined || typeof item.license === 'string')
|
|
18
|
-
&& (item.overlongLicense === undefined || item.overlongLicense === true)
|
|
19
|
-
&& typeof item.dev === 'boolean' && typeof item.line === 'number' && Number.isSafeInteger(item.line) && item.line >= 1
|
|
20
|
-
&& typeof item.endLine === 'number' && Number.isSafeInteger(item.endLine) && item.endLine >= item.line)),
|
|
17
|
+
id: licenseDependencyInventory,
|
|
18
|
+
accepts: (value) => Array.isArray(value) && value.every(isDependencySource),
|
|
21
19
|
};
|
|
20
|
+
function isDependencySource(value) {
|
|
21
|
+
if (!isRecord(value) || !Array.isArray(value.packages) || !licenseInputSummary(value))
|
|
22
|
+
return false;
|
|
23
|
+
const format = value.format === undefined || licenseImportFormats.some(format => format === value.format);
|
|
24
|
+
return format && (value.unverified === undefined || value.unverified === true) && value.packages.every(isDependency);
|
|
25
|
+
}
|
|
26
|
+
function isDependency(value) {
|
|
27
|
+
if (!isRecord(value) || typeof value.name !== 'string' || !value.name)
|
|
28
|
+
return false;
|
|
29
|
+
const groups = Array.isArray(value.groups) && value.groups.every(group => typeof group === 'string' && group.length > 0);
|
|
30
|
+
const declaration = optionalText(value.version) && optionalText(value.license) && (value.overlongLicense === undefined || value.overlongLicense === true);
|
|
31
|
+
return groups && declaration && validRange(value.line, value.endLine);
|
|
32
|
+
}
|
|
33
|
+
function optionalText(value) {
|
|
34
|
+
return value === undefined || typeof value === 'string';
|
|
35
|
+
}
|
|
36
|
+
function validRange(line, endLine) {
|
|
37
|
+
return isLine(line) && isLine(endLine) && endLine >= line;
|
|
38
|
+
}
|
|
39
|
+
function isLine(value) {
|
|
40
|
+
return typeof value === 'number' && Number.isSafeInteger(value) && value >= 1;
|
|
41
|
+
}
|
|
22
42
|
export const dependencySourcesSchema = {
|
|
23
43
|
type: 'array',
|
|
24
|
-
items: { type: 'object', additionalProperties: false, required: ['path', 'packages'],
|
|
25
|
-
properties: { path: { type: 'string', minLength: 1 }, packages: { type: 'array', items: dependency }, unverified: { const: true }, format: { enum: licenseImportFormats } } },
|
|
44
|
+
items: { type: 'object', additionalProperties: false, required: ['path', 'packages', 'groups', 'licenseKinds'],
|
|
45
|
+
properties: { path: { type: 'string', minLength: 1 }, packages: { type: 'array', items: dependency }, unverified: { const: true }, format: { enum: licenseImportFormats }, groups: { type: 'array', items: group }, licenseKinds } },
|
|
26
46
|
};
|
|
27
47
|
//# sourceMappingURL=dependencies.js.map
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { canonicalLicense, exceptions } from './spdx-catalog.js';
|
|
2
|
+
import { maxLicenseLength } from './dependencies.js';
|
|
3
|
+
const operators = new Set(['AND', 'OR', 'WITH', '(', ')']);
|
|
4
|
+
const expressionToken = /\s+|[()]|(?:[A-Za-z0-9.-]+:)?[A-Za-z0-9.-]+\+?/y;
|
|
5
|
+
export function evaluateLicenseExpression(expression, evaluate) {
|
|
6
|
+
if (expression === undefined || expression.length > maxLicenseLength)
|
|
7
|
+
return 'unknown';
|
|
8
|
+
const parsed = tokenize(expression);
|
|
9
|
+
if (parsed === undefined)
|
|
10
|
+
return 'unknown';
|
|
11
|
+
const tokens = parsed;
|
|
12
|
+
let cursor = 0;
|
|
13
|
+
function operand(depth) {
|
|
14
|
+
if (depth > 64)
|
|
15
|
+
return undefined;
|
|
16
|
+
const token = tokens[cursor++];
|
|
17
|
+
if (token === '(') {
|
|
18
|
+
const result = composite(depth + 1, 'OR');
|
|
19
|
+
return tokens[cursor++] === ')' ? result : undefined;
|
|
20
|
+
}
|
|
21
|
+
if (token === undefined || operators.has(token))
|
|
22
|
+
return undefined;
|
|
23
|
+
if (tokens[cursor] === 'WITH') {
|
|
24
|
+
cursor++;
|
|
25
|
+
const exception = tokens[cursor++];
|
|
26
|
+
if (!exception || !exceptions.has(exception.toLowerCase()))
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
const id = canonicalLicense(token);
|
|
30
|
+
return id === undefined ? undefined : evaluate(id);
|
|
31
|
+
}
|
|
32
|
+
function composite(depth, operator) {
|
|
33
|
+
const next = () => operator === 'AND' ? operand(depth) : composite(depth, 'AND');
|
|
34
|
+
let result = next();
|
|
35
|
+
while (result !== undefined && tokens[cursor] === operator) {
|
|
36
|
+
cursor++;
|
|
37
|
+
const right = next();
|
|
38
|
+
if (right === undefined)
|
|
39
|
+
return undefined;
|
|
40
|
+
result = combine(result, right, operator);
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
const decision = composite(0, 'OR');
|
|
45
|
+
return cursor === tokens.length ? decision ?? 'unknown' : 'unknown';
|
|
46
|
+
}
|
|
47
|
+
function tokenize(text) {
|
|
48
|
+
const tokens = [];
|
|
49
|
+
for (let index = 0; index < text.length; index = expressionToken.lastIndex) {
|
|
50
|
+
expressionToken.lastIndex = index;
|
|
51
|
+
const token = expressionToken.exec(text)?.[0];
|
|
52
|
+
if (!token)
|
|
53
|
+
return undefined;
|
|
54
|
+
if (token === 'WITH' && (!/\s/.test(text[index - 1] ?? '') || !/\s/.test(text[expressionToken.lastIndex] ?? '')))
|
|
55
|
+
return undefined;
|
|
56
|
+
if (token.trim())
|
|
57
|
+
tokens.push(token);
|
|
58
|
+
}
|
|
59
|
+
return tokens;
|
|
60
|
+
}
|
|
61
|
+
function combine(left, right, operator) {
|
|
62
|
+
const decisive = operator === 'AND' ? 'denied' : 'allowed';
|
|
63
|
+
if (left === decisive || right === decisive)
|
|
64
|
+
return decisive;
|
|
65
|
+
if (left === right)
|
|
66
|
+
return left;
|
|
67
|
+
return left === 'unknown' || right === 'unknown' ? 'unknown' : 'unclassified';
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=expression.js.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { JsonValue } from '@repometry/core/internal/model/plugin-data.js';
|
|
2
|
+
export declare function rejectRemovedLicenseOptions(options: JsonValue | undefined): void;
|
|
2
3
|
export declare function licenses(options?: JsonValue | undefined): {
|
|
3
4
|
id: string;
|
|
4
5
|
version: string;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { checkedDependencies, licenseFiles, licenseLockKind, licenseLockNames } from '@repometry/core/internal/model/license-evidence.js';
|
|
2
2
|
import { bundledPlugin, pluginManifestSchema } from '@repometry/core/internal/engine/plugin-manifest.js';
|
|
3
3
|
import { findingResult } from '@repometry/core/internal/engine/author-contracts.js';
|
|
4
|
+
import { isRecord } from '@repometry/core/internal/model/plugin-data.js';
|
|
4
5
|
import { dependencySources, dependencySourcesSchema, maxLicenseLength } from './dependencies.js';
|
|
5
6
|
import { readComposerLock } from './composer-lock.js';
|
|
6
7
|
import { listsDependencies } from './unverified-lock.js';
|
|
7
8
|
import { readSbom } from './sbom.js';
|
|
8
9
|
import { readNpmLock } from './npm-lock.js';
|
|
9
|
-
import { licenseDecision, licenseListVersion, licensePolicy, policySchema } from './policy.js';
|
|
10
|
+
import { licenseDecision, licenseKind, licenseListVersion, licensePolicy, policySchema } from './policy.js';
|
|
10
11
|
const id = 'licenses';
|
|
11
12
|
const checks = [
|
|
12
13
|
{ id: 'denied-license', description: 'A dependency declares a license outside the configured policy.' },
|
|
@@ -17,7 +18,13 @@ const checked = {
|
|
|
17
18
|
id: checkedDependencies, label: 'Checked dependencies', unit: 'count', scope: 'file',
|
|
18
19
|
aggregate: 'sum', better: 'none', group: 'Legal',
|
|
19
20
|
};
|
|
21
|
+
export function rejectRemovedLicenseOptions(options) {
|
|
22
|
+
if (isRecord(options) && Object.hasOwn(options, 'dev')) {
|
|
23
|
+
throw new Error('The licenses dev option was removed. Every dependency is inspected. Switch categories in the report view.');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
20
26
|
export function licenses(options = undefined) {
|
|
27
|
+
rejectRemovedLicenseOptions(options);
|
|
21
28
|
const policy = licensePolicy(options);
|
|
22
29
|
return {
|
|
23
30
|
...bundledPlugin({
|
|
@@ -35,7 +42,7 @@ export function licenses(options = undefined) {
|
|
|
35
42
|
try {
|
|
36
43
|
const text = new TextDecoder('utf-8', { fatal: true }).decode(bytes);
|
|
37
44
|
const sources = format === undefined ? readLockfile(path, text) : [{ path, format, packages: readSbom(format, text) }];
|
|
38
|
-
return sources.map(
|
|
45
|
+
return sources.map(inventorySource);
|
|
39
46
|
}
|
|
40
47
|
catch (error) {
|
|
41
48
|
context.emitDiagnostic?.('Unable to read ' + (format ?? 'lockfile') + ' license metadata: ' + (error instanceof Error ? error.message : String(error)), path);
|
|
@@ -45,32 +52,7 @@ export function licenses(options = undefined) {
|
|
|
45
52
|
},
|
|
46
53
|
}, {
|
|
47
54
|
id: 'check', role: 'inspection', scope: 'repository', inputs: { dependencies: dependencySources }, output: findingResult,
|
|
48
|
-
execute(context)
|
|
49
|
-
const findings = [];
|
|
50
|
-
const measurements = [];
|
|
51
|
-
const ignored = [];
|
|
52
|
-
for (const { path, packages, unverified } of context.read('dependencies', dependencySources)) {
|
|
53
|
-
const inspected = policy.dev ? packages : packages.filter(dependency => !dependency.dev);
|
|
54
|
-
measurements.push({ definition: checkedDependencies, target: 'file', path, value: inspected.length });
|
|
55
|
-
if (unverified)
|
|
56
|
-
findings.push({ check: 'unverified-dependencies', level: 'low', path, anchor: '(file)',
|
|
57
|
-
message: 'This lockfile has no supported dependency license data. Import an SBOM to check the dependencies.' });
|
|
58
|
-
for (const dependency of inspected) {
|
|
59
|
-
const { name, version, license, line, endLine } = dependency;
|
|
60
|
-
const decision = licenseDecision(license, policy);
|
|
61
|
-
if (decision === 'allowed')
|
|
62
|
-
continue;
|
|
63
|
-
const check = decision === 'denied' ? 'denied-license' : 'unknown-license';
|
|
64
|
-
const label = version === undefined ? name : name + '@' + version;
|
|
65
|
-
const reason = policy.exceptions.get(label) ?? policy.exceptions.get(name);
|
|
66
|
-
if (reason !== undefined)
|
|
67
|
-
ignored.push({ index: findings.length, reason });
|
|
68
|
-
findings.push({ check, level: decision === 'denied' ? 'high' : 'medium', path, line, endLine, anchor: name,
|
|
69
|
-
message: findingMessage(label, dependency, decision, policy.preset) });
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return { findings, measurements, ...(ignored.length ? { ignored } : {}) };
|
|
73
|
-
},
|
|
55
|
+
execute: context => checkDependencies(context.read('dependencies', dependencySources), policy),
|
|
74
56
|
}],
|
|
75
57
|
}),
|
|
76
58
|
}),
|
|
@@ -78,6 +60,51 @@ export function licenses(options = undefined) {
|
|
|
78
60
|
...(options === undefined ? {} : { settings: options }),
|
|
79
61
|
};
|
|
80
62
|
}
|
|
63
|
+
function inventorySource(source) {
|
|
64
|
+
const kinds = { osi: 0, other: 0, unknown: 0 };
|
|
65
|
+
const groups = new Map();
|
|
66
|
+
const packages = source.packages.map(boundLicense);
|
|
67
|
+
for (const item of packages) {
|
|
68
|
+
kinds[licenseKind(item.license)]++;
|
|
69
|
+
for (const group of item.groups)
|
|
70
|
+
groups.set(group, (groups.get(group) ?? 0) + 1);
|
|
71
|
+
}
|
|
72
|
+
return { ...source, packages, groups: [...groups].map(([name, count]) => ({ name, count })), licenseKinds: kinds };
|
|
73
|
+
}
|
|
74
|
+
function checkDependencies(sources, policy) {
|
|
75
|
+
const findings = [];
|
|
76
|
+
const measurements = [];
|
|
77
|
+
const ignored = [];
|
|
78
|
+
for (const { path, packages, unverified } of sources) {
|
|
79
|
+
measurements.push({ definition: checkedDependencies, target: 'file', path, value: packages.length });
|
|
80
|
+
if (unverified)
|
|
81
|
+
findings.push({ check: 'unverified-dependencies', level: 'low', path, anchor: '(file)',
|
|
82
|
+
message: 'This lockfile has no supported dependency license data. Import an SBOM to check the dependencies.' });
|
|
83
|
+
for (const dependency of packages) {
|
|
84
|
+
const finding = dependencyFinding(path, dependency, policy);
|
|
85
|
+
if (finding === undefined)
|
|
86
|
+
continue;
|
|
87
|
+
const label = dependencyLabel(dependency);
|
|
88
|
+
const reason = policy.exceptions.get(label) ?? policy.exceptions.get(dependency.name);
|
|
89
|
+
if (reason !== undefined)
|
|
90
|
+
ignored.push({ index: findings.length, reason });
|
|
91
|
+
findings.push(finding);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return { findings, measurements, ...(ignored.length ? { ignored } : {}) };
|
|
95
|
+
}
|
|
96
|
+
function dependencyFinding(path, dependency, policy) {
|
|
97
|
+
const { name, license, line, endLine, groups } = dependency;
|
|
98
|
+
const decision = licenseDecision(license, policy);
|
|
99
|
+
if (decision === 'allowed')
|
|
100
|
+
return undefined;
|
|
101
|
+
const denied = decision === 'denied';
|
|
102
|
+
return { check: denied ? 'denied-license' : 'unknown-license', level: denied ? 'high' : 'medium',
|
|
103
|
+
path, line, endLine, anchor: name, groups, message: findingMessage(dependencyLabel(dependency), dependency, decision, policy.preset) };
|
|
104
|
+
}
|
|
105
|
+
function dependencyLabel({ name, version }) {
|
|
106
|
+
return version === undefined ? name : name + '@' + version;
|
|
107
|
+
}
|
|
81
108
|
function boundLicense(dependency) {
|
|
82
109
|
if ((dependency.license?.length ?? 0) <= maxLicenseLength)
|
|
83
110
|
return dependency;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isRecord } from '@repometry/core/internal/engine/plugin.js';
|
|
2
2
|
import { locateJsonSpans, pointer } from '../json-spans.js';
|
|
3
3
|
import { declaredLicense } from './policy.js';
|
|
4
|
+
const categories = ['dev', 'optional', 'peer', 'devOptional', 'inBundle'];
|
|
4
5
|
/** Older and unknown versions lack the supported package metadata. */
|
|
5
6
|
export function readNpmLock(text) {
|
|
6
7
|
const lock = JSON.parse(text);
|
|
@@ -20,7 +21,7 @@ export function readNpmLock(text) {
|
|
|
20
21
|
const version = typeof entry.version === 'string' ? entry.version : undefined;
|
|
21
22
|
const license = declaredLicense(entry.license ?? entry.licenses);
|
|
22
23
|
return [{ at: pointer(['packages', path]), name, ...(version === undefined ? {} : { version }),
|
|
23
|
-
...(license === undefined ? {} : { license }),
|
|
24
|
+
...(license === undefined ? {} : { license }), groups: categories.filter(category => entry[category] === true) }];
|
|
24
25
|
});
|
|
25
26
|
if (!dependencies.length)
|
|
26
27
|
return [];
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import type { LicenseKind } from '@repometry/core/internal/model/license-evidence.js';
|
|
2
|
+
import type { Decision } from './expression.js';
|
|
3
|
+
export { licenseListVersion } from './spdx-catalog.js';
|
|
4
|
+
export declare const presets: readonly ['open-source', 'weak-copyleft', 'permissive', 'osi-approved'];
|
|
3
5
|
type Preset = typeof presets[number];
|
|
4
|
-
type Decision = 'allowed' | 'denied' | 'unknown' | 'unclassified';
|
|
5
6
|
interface Exception {
|
|
6
7
|
readonly package: string;
|
|
7
8
|
readonly reason: string;
|
|
@@ -11,21 +12,19 @@ export interface PolicyOptions {
|
|
|
11
12
|
readonly allow?: readonly string[];
|
|
12
13
|
readonly deny?: readonly string[];
|
|
13
14
|
readonly exceptions?: readonly Exception[];
|
|
14
|
-
readonly dev?: boolean;
|
|
15
15
|
}
|
|
16
16
|
interface Policy {
|
|
17
17
|
readonly preset: Preset;
|
|
18
18
|
readonly allow: ReadonlySet<string>;
|
|
19
19
|
readonly deny: ReadonlySet<string>;
|
|
20
20
|
readonly exceptions: ReadonlyMap<string, string>;
|
|
21
|
-
readonly dev: boolean;
|
|
22
21
|
}
|
|
23
22
|
export declare const policySchema: {
|
|
24
23
|
readonly type: 'object';
|
|
25
24
|
readonly additionalProperties: false;
|
|
26
25
|
readonly properties: {
|
|
27
26
|
readonly policy: {
|
|
28
|
-
readonly enum: readonly ["open-source", "weak-copyleft", "permissive"];
|
|
27
|
+
readonly enum: readonly ["open-source", "weak-copyleft", "permissive", "osi-approved"];
|
|
29
28
|
};
|
|
30
29
|
readonly allow: {
|
|
31
30
|
readonly type: 'array';
|
|
@@ -61,12 +60,9 @@ export declare const policySchema: {
|
|
|
61
60
|
};
|
|
62
61
|
};
|
|
63
62
|
};
|
|
64
|
-
readonly dev: {
|
|
65
|
-
readonly type: 'boolean';
|
|
66
|
-
};
|
|
67
63
|
};
|
|
68
64
|
};
|
|
69
|
-
export declare function licensePolicy({ policy: preset, allow, deny, exceptions
|
|
65
|
+
export declare function licensePolicy({ policy: preset, allow, deny, exceptions }?: PolicyOptions): Policy;
|
|
70
66
|
export declare function declaredLicense(value: unknown): string | undefined;
|
|
67
|
+
export declare function licenseKind(expression: string | undefined): LicenseKind;
|
|
71
68
|
export declare function licenseDecision(expression: string | undefined, policy: Policy): Decision;
|
|
72
|
-
export {};
|
|
@@ -1,24 +1,8 @@
|
|
|
1
1
|
import { isRecord } from '@repometry/core/internal/engine/plugin.js';
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
export
|
|
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 = []
|
|
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()]))
|
|
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
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
|
109
|
-
|
|
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
|
-
|
|
129
|
-
|
|
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
|
-
|
|
138
|
-
|
|
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
|