@repometry/cli 0.3.0 → 0.4.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 +3 -0
- package/package.json +2 -2
- package/target/main/resources/licenses/spdx.json +746 -0
- package/target/main/resources/report/json/config-v2.schema.json +2 -1
- package/target/main/resources/report/json/file-metrics-v1.schema.json +2 -0
- package/target/main/resources/report/json/report-v2.schema.json +6 -3
- package/target/main/resources/report/json/repository-summary-v1.schema.json +14 -0
- package/target/main/resources/viewer/index.html +4 -0
- package/target/main/resources/viewer/styles.css +7 -2
- package/target/main/ts/api/git/git.d.ts +2 -1
- package/target/main/ts/api/git/git.js +4 -4
- package/target/main/ts/api/git/inspection-source.js +2 -2
- package/target/main/ts/api/git/local.d.ts +1 -1
- package/target/main/ts/api/git/local.js +5 -4
- package/target/main/ts/api/import/finding-import.js +2 -9
- package/target/main/ts/api/import/license-import.d.ts +2 -0
- package/target/main/ts/api/import/license-import.js +36 -0
- package/target/main/ts/api/import/repository-path.d.ts +1 -0
- package/target/main/ts/api/import/repository-path.js +10 -0
- package/target/main/ts/cli/imports.d.ts +2 -0
- package/target/main/ts/cli/imports.js +6 -2
- package/target/main/ts/cli/run.js +10 -4
- package/target/main/ts/compose/analysis-report.js +5 -2
- package/target/main/ts/compose/analysis-results.d.ts +3 -2
- package/target/main/ts/compose/analysis-results.js +15 -6
- package/target/main/ts/compose/analysis-steps.js +3 -0
- package/target/main/ts/compose/analyze-snapshot.d.ts +1 -1
- package/target/main/ts/compose/analyze-snapshot.js +7 -4
- 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/inspect.d.ts +2 -0
- package/target/main/ts/compose/inspect.js +7 -4
- package/target/main/ts/compose/load-plugins.js +4 -2
- package/target/main/ts/compose/phases.d.ts +7 -3
- package/target/main/ts/compose/phases.js +26 -10
- package/target/main/ts/plugins/built-in.d.ts +2 -0
- package/target/main/ts/plugins/built-in.js +4 -1
- package/target/main/ts/plugins/json-spans.d.ts +11 -0
- package/target/main/ts/plugins/json-spans.js +86 -0
- package/target/main/ts/plugins/legal/composer-lock.d.ts +2 -0
- package/target/main/ts/plugins/legal/composer-lock.js +24 -0
- package/target/main/ts/plugins/legal/dependencies.d.ts +73 -0
- package/target/main/ts/plugins/legal/dependencies.js +27 -0
- package/target/main/ts/plugins/legal/licenses.d.ts +19 -0
- package/target/main/ts/plugins/legal/licenses.js +112 -0
- package/target/main/ts/plugins/legal/npm-lock.d.ts +3 -0
- package/target/main/ts/plugins/legal/npm-lock.js +30 -0
- package/target/main/ts/plugins/legal/policy.d.ts +72 -0
- package/target/main/ts/plugins/legal/policy.js +149 -0
- package/target/main/ts/plugins/legal/sbom.d.ts +3 -0
- package/target/main/ts/plugins/legal/sbom.js +131 -0
- package/target/main/ts/plugins/legal/unverified-lock.d.ts +1 -0
- package/target/main/ts/plugins/legal/unverified-lock.js +21 -0
- package/target/main/ts/plugins/security/npm-supply-chain.js +2 -86
- package/target/main/ts/report/html/app/viewer-issue-group.js +1 -1
- package/target/main/ts/report/html/app/viewer-metric-registry.js +1 -1
- package/target/main/ts/report/html/app/viewer-metrics.d.ts +2 -1
- package/target/main/ts/report/html/app/viewer-metrics.js +7 -2
- package/target/main/ts/report/html/app/viewer-overview-cards.d.ts +1 -0
- package/target/main/ts/report/html/app/viewer-overview-cards.js +20 -1
- package/target/main/ts/report/html/app/viewer-overview-lead.js +4 -1
- package/target/main/ts/report/html/app/viewer-shell.js +3 -1
- package/target/main/ts/report/html/app/viewer-tokenizer.js +35 -8
- package/target/main/ts/report/html/app/viewer-trend-data.js +1 -0
- package/target/main/ts/report/html/app/viewer.js +5 -2
- package/target/main/ts/report/json/validation/report.js +2 -2
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { resolve } from 'node:path';
|
|
2
2
|
import { gitTreeFiles } from '../api/git/git.js';
|
|
3
3
|
import { readInspectionSource } from '../api/git/inspection-source.js';
|
|
4
|
+
import { readLicenseImports } from '../api/import/license-import.js';
|
|
4
5
|
import { importFindings } from '../api/import/finding-import.js';
|
|
5
6
|
import { hasCoverageInputs } from '../api/import/lcov-files.js';
|
|
6
7
|
import { readInspectionCoverage } from './inspection-coverage.js';
|
|
@@ -8,19 +9,21 @@ import { reportSchema } from '@repometry/core/internal/model/report.js';
|
|
|
8
9
|
import { isExcludedDirectory } from '@repometry/core/internal/model/snapshot.js';
|
|
9
10
|
import { executeInspection } from '@repometry/core/internal/usecases/inspect.js';
|
|
10
11
|
import { LocalReportStore } from '../report/json/store/local-store.js';
|
|
11
|
-
import { analyzeSnapshot, inspectionFileMatcher } from './analyze-snapshot.js';
|
|
12
|
+
import { analyzeSnapshot, inspectionFileLimit, inspectionFileMatcher } from './analyze-snapshot.js';
|
|
12
13
|
import { attachChurn } from './attach-churn.js';
|
|
13
14
|
import { languageRegistry } from './languages.js';
|
|
14
15
|
export function inspect(request) {
|
|
15
16
|
return inspectWithOptions(request);
|
|
16
17
|
}
|
|
17
18
|
export async function inspectWithOptions(request, { history, deferSummary = false, recordChurn = true, inventory } = {}) {
|
|
18
|
-
const { findingInputs = [], plugins = [], operationCache } = request;
|
|
19
|
+
const { findingInputs = [], licenseInputs = [], plugins = [], operationCache } = request;
|
|
19
20
|
const languages = languageRegistry(plugins, request.parsers);
|
|
20
|
-
const
|
|
21
|
+
const fromLockfiles = licenseInputs.length === 0;
|
|
22
|
+
const claims = inspectionFileMatcher(languages, fromLockfiles);
|
|
21
23
|
const { isSource } = languages;
|
|
22
24
|
const ports = {
|
|
23
|
-
readSource: excludes => readSource(request, { excludes, isSource, claims, history: history?.blobs }, deferSummary, inventory),
|
|
25
|
+
readSource: excludes => readSource(request, { excludes, isSource, claims, claimLimit: inspectionFileLimit(languages, fromLockfiles), history: history?.blobs }, deferSummary, inventory),
|
|
26
|
+
...(!fromLockfiles ? { readLicenseImports: source => readLicenseImports(licenseInputs, source.root) } : {}),
|
|
24
27
|
analyze: input => analyzeSnapshot(input, languages, operationCache, history),
|
|
25
28
|
...(hasCoverageInputs(request) ? { readCoverage: source => readInspectionCoverage(request, source) } : {}),
|
|
26
29
|
...(findingInputs.length === 0 ? {} : { importFindings: (report, root, excludes) => attachFindings(report, findingInputs, root, request.findingRoot === undefined ? root : resolve(request.findingRoot), excludes) }),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { dirname, resolve } from 'node:path';
|
|
2
|
-
import { builtInPlugins } from './built-ins.js';
|
|
2
|
+
import { builtInConfigurations, builtInPlugins } from './built-ins.js';
|
|
3
3
|
import { installedModule, javaScriptManifest, localModule } from './js-plugin.js';
|
|
4
4
|
import { validatePluginOptions } from './plugin-options.js';
|
|
5
5
|
import { dockerPluginFile, dockerPluginImage } from './process-plugins.js';
|
|
@@ -61,7 +61,9 @@ async function resolvePlugin(input, entry, folder, context, builtIns) {
|
|
|
61
61
|
const builtIn = builtIns.get(use) ?? alias;
|
|
62
62
|
if (builtIn !== undefined) {
|
|
63
63
|
validatePluginOptions(builtIn.config, entry.options, base);
|
|
64
|
-
|
|
64
|
+
const configure = builtInConfigurations.get(builtIn.id);
|
|
65
|
+
const plugin = configure && entry.options !== undefined ? configure(entry.options) : builtIn;
|
|
66
|
+
return { plugin, versionSource: 'built-in', builtIn: true, include: undefined, exclude: undefined, requires: undefined };
|
|
65
67
|
}
|
|
66
68
|
const installed = await installedModule(pkg, entry, context);
|
|
67
69
|
const plugin = pkg.startsWith('@repometry/language-') && pkg === '@repometry/' + installed.plugin.id
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { DataContract, Operation, Plugin } from '@repometry/core/internal/engine/plugin.js';
|
|
2
|
+
import type { ImportedLicenseEvidence } from '@repometry/core/internal/model/license-evidence.js';
|
|
2
3
|
import type { SourceFile, SourceSnapshot } from '@repometry/core/internal/model/source.js';
|
|
3
4
|
import type { LanguageProvider, LanguageRegistry } from './languages.js';
|
|
4
5
|
/**
|
|
@@ -10,7 +11,7 @@ export type Phase = Readonly<{
|
|
|
10
11
|
task: 'file' | 'repository' | 'run';
|
|
11
12
|
}>;
|
|
12
13
|
/** The phases of an analysis in run order. The coverage input is offered only when coverage is given. */
|
|
13
|
-
export declare function analysisPhases(withCoverage: boolean): {
|
|
14
|
+
export declare function analysisPhases(withCoverage: boolean, withLicenseFiles?: boolean): {
|
|
14
15
|
readonly files: {
|
|
15
16
|
readonly task: 'file';
|
|
16
17
|
readonly offers: {
|
|
@@ -29,6 +30,7 @@ export declare function analysisPhases(withCoverage: boolean): {
|
|
|
29
30
|
readonly offers: {
|
|
30
31
|
readonly sources: DataContract<readonly import("@repometry/core/internal/model/clone-source.js").CloneSource[]>;
|
|
31
32
|
readonly lcov?: DataContract<import("@repometry/core/internal/model/coverage-input.js").CoverageInput> | undefined;
|
|
33
|
+
readonly licenseFiles?: DataContract<readonly import("@repometry/core/internal/model/license-evidence.js").LicenseEvidenceFile[]> | undefined;
|
|
32
34
|
};
|
|
33
35
|
};
|
|
34
36
|
};
|
|
@@ -78,9 +80,11 @@ export type SelectedSource = Readonly<{
|
|
|
78
80
|
provider: LanguageProvider | undefined;
|
|
79
81
|
}>;
|
|
80
82
|
/** Whether a file is claimed by an inspection that runs on claimed files rather than on every parsed one. */
|
|
81
|
-
export declare function inspectionFileMatcher(languages: LanguageRegistry): (path: string) => boolean;
|
|
83
|
+
export declare function inspectionFileMatcher(languages: LanguageRegistry, fromLockfiles?: boolean): (path: string) => boolean;
|
|
84
|
+
export declare function inspectionFileLimit(languages: LanguageRegistry, fromLockfiles?: boolean): (path: string) => number;
|
|
82
85
|
/** The files of a snapshot with their language providers, and the steps that analyse them. */
|
|
83
|
-
export declare function selectAnalysisSources(snapshot: SourceSnapshot, withCoverage: boolean, languages: LanguageRegistry): {
|
|
86
|
+
export declare function selectAnalysisSources(snapshot: SourceSnapshot, withCoverage: boolean, languages: LanguageRegistry, imported?: ImportedLicenseEvidence): {
|
|
87
|
+
licenseInputs: SourceFile[] | readonly import("@repometry/core/internal/model/license-evidence.js").LicenseImportFile[];
|
|
84
88
|
languages: {
|
|
85
89
|
select: (path: string) => LanguageProvider | undefined;
|
|
86
90
|
isSource: (path: string) => boolean;
|
|
@@ -2,23 +2,26 @@ import { changesInput } from '@repometry/core/internal/model/changes.js';
|
|
|
2
2
|
import { cloneSources } from '@repometry/core/internal/model/clone-source.js';
|
|
3
3
|
import { codeStructure, codeStructures } from '@repometry/core/internal/model/code-structure.js';
|
|
4
4
|
import { lcovInput } from '@repometry/core/internal/model/coverage-input.js';
|
|
5
|
+
import { isLicenseLockfile, licenseFiles, maxLicenseFileBytes } from '@repometry/core/internal/model/license-evidence.js';
|
|
6
|
+
import { isClaimedText, maxClaimedFileBytes } from '@repometry/core/internal/model/source.js';
|
|
5
7
|
import { sourceFile, sourceFiles } from '@repometry/core/internal/model/snapshot.js';
|
|
6
8
|
import { builtInPluginIds } from './built-ins.js';
|
|
7
9
|
import { claimMatcher } from './languages.js';
|
|
8
10
|
import { inspectionClaims } from './parser-order.js';
|
|
9
11
|
import { scopedMatcher, scopeOperation } from './plugin-scope.js';
|
|
10
12
|
/** The phases of an analysis in run order. The coverage input is offered only when coverage is given. */
|
|
11
|
-
export function analysisPhases(withCoverage) {
|
|
13
|
+
export function analysisPhases(withCoverage, withLicenseFiles = false) {
|
|
12
14
|
return {
|
|
13
15
|
files: { task: 'file', offers: { file: sourceFile, syntax: codeStructure } },
|
|
14
16
|
repository: { task: 'repository', offers: { files: sourceFiles } },
|
|
15
|
-
afterFiles: { task: 'run', offers: { sources: cloneSources, ...(withCoverage ? { lcov: lcovInput } : {})
|
|
17
|
+
afterFiles: { task: 'run', offers: { sources: cloneSources, ...(withCoverage ? { lcov: lcovInput } : {}),
|
|
18
|
+
...(withLicenseFiles ? { licenseFiles } : {}) } },
|
|
16
19
|
};
|
|
17
20
|
}
|
|
18
21
|
/** The one phase of a diff coverage run. */
|
|
19
22
|
export const diffCoveragePhases = { changedLines: { task: 'run', offers: { changes: changesInput, lcov: lcovInput } } };
|
|
20
23
|
/** The phases of each kind of run, with all their optional host inputs. Every plugin takes part in an analysis; only built-ins in diff coverage. */
|
|
21
|
-
const analysisRun = Object.values(analysisPhases(true));
|
|
24
|
+
const analysisRun = Object.values(analysisPhases(true, true));
|
|
22
25
|
const diffCoverageRun = Object.values(diffCoveragePhases);
|
|
23
26
|
/** The closed list of host contracts: every contract some host run offers. */
|
|
24
27
|
const hostContracts = new Set([...analysisRun, ...diffCoverageRun].flatMap(({ offers }) => Object.values(offers).map(({ id }) => id)));
|
|
@@ -82,8 +85,8 @@ function rejectUnsatisfiable(all) {
|
|
|
82
85
|
throw new Error(`${dependent.key} reads ${unread(dependent, reachable).join(', ')}, which only operations that never run output`);
|
|
83
86
|
}
|
|
84
87
|
/** What runs where in an analysis: the active plugins and the four steps. */
|
|
85
|
-
function analysisSteps(plugins, languages, withCoverage) {
|
|
86
|
-
const { files, repository, afterFiles } = selectOperations(plugins, analysisPhases(withCoverage), new Set(languages.providers.map(({ key }) => key)));
|
|
88
|
+
function analysisSteps(plugins, languages, withCoverage, withLicenseFiles = false) {
|
|
89
|
+
const { files, repository, afterFiles } = selectOperations(plugins, analysisPhases(withCoverage, withLicenseFiles), new Set(languages.providers.map(({ key }) => key)));
|
|
87
90
|
// Those that read the code structure, directly or through the products of others, run on the parsed files their plugin claims.
|
|
88
91
|
const readers = new Set(reached(files, [codeStructure.id], 'some'));
|
|
89
92
|
const claims = new Map(plugins.map(plugin => [plugin.id, claimsOf(plugin, languages)]));
|
|
@@ -129,19 +132,32 @@ export function phaseInputs({ offers }, omit) {
|
|
|
129
132
|
return new Map(Object.entries(offers).filter(([, contract]) => contract !== omit).map(([port, { id }]) => [port, id]));
|
|
130
133
|
}
|
|
131
134
|
/** Whether a file is claimed by an inspection that runs on claimed files rather than on every parsed one. */
|
|
132
|
-
export function inspectionFileMatcher(languages) {
|
|
135
|
+
export function inspectionFileMatcher(languages, fromLockfiles = true) {
|
|
133
136
|
const { files, repository } = analysisSteps(languages.plugins, languages, false);
|
|
134
137
|
const claimed = [...files.inspections, ...repository.inspections].filter(({ parsed }) => !parsed);
|
|
135
|
-
|
|
138
|
+
const lockfile = licenseFileMatcher(languages);
|
|
139
|
+
return path => (fromLockfiles && lockfile(path)) || claimed.some(({ matches }) => matches(path, false));
|
|
140
|
+
}
|
|
141
|
+
function licenseFileMatcher(languages) {
|
|
142
|
+
const checks = languages.plugins.filter(plugin => plugin.kinds.includes('legal')
|
|
143
|
+
&& plugin.operations.some(operation => Object.values(operation.inputs).some(contract => contract.id === licenseFiles.id)))
|
|
144
|
+
.map(plugin => claimsOf(plugin, languages));
|
|
145
|
+
return path => isLicenseLockfile(path) && checks.some(matches => matches(path));
|
|
146
|
+
}
|
|
147
|
+
export function inspectionFileLimit(languages, fromLockfiles = true) {
|
|
148
|
+
const license = licenseFileMatcher(languages);
|
|
149
|
+
return path => fromLockfiles && license(path) ? maxLicenseFileBytes : maxClaimedFileBytes;
|
|
136
150
|
}
|
|
137
151
|
/** The files of a snapshot with their language providers, and the steps that analyse them. */
|
|
138
|
-
export function selectAnalysisSources(snapshot, withCoverage, languages) {
|
|
152
|
+
export function selectAnalysisSources(snapshot, withCoverage, languages, imported) {
|
|
139
153
|
const sources = snapshot.files.map(file => ({ file, provider: languages.select(file.path) }));
|
|
140
154
|
const providersByPath = new Map(sources.flatMap(({ file, provider }) => provider ? [[file.path, provider]] : []));
|
|
141
155
|
const unavailableFiles = new Set(sources.filter(({ file, provider }) => !provider && languages.skipped(file.path))
|
|
142
156
|
.map(({ file }) => file.path));
|
|
143
157
|
const sourceFiles = sources.flatMap(({ file, provider }) => provider ? [file] : []);
|
|
144
|
-
const
|
|
145
|
-
|
|
158
|
+
const matchesLicense = licenseFileMatcher(languages);
|
|
159
|
+
const licenseInputs = imported?.files ?? snapshot.files.filter(file => matchesLicense(file.path) && isClaimedText(file.bytes, maxLicenseFileBytes));
|
|
160
|
+
const steps = analysisSteps(languages.plugins, languages, withCoverage, licenseInputs.length > 0);
|
|
161
|
+
return { licenseInputs, languages, sources, sourceFiles, unavailableFiles, providersByPath, steps, plugins: steps.plugins };
|
|
146
162
|
}
|
|
147
163
|
//# sourceMappingURL=phases.js.map
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { JsonValue } from '@repometry/core/internal/model/plugin-data.js';
|
|
1
2
|
import type { Plugin } from '@repometry/core/internal/engine/plugin.js';
|
|
3
|
+
export declare const builtInConfigurations: Map<string, (options: JsonValue) => Plugin>;
|
|
2
4
|
/** The built-in plugins in run order. The first language plugin is the default provider. */
|
|
3
5
|
export declare const builtInPlugins: readonly Plugin[];
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { licenses } from './legal/licenses.js';
|
|
1
2
|
import { bundledPlugin } from '@repometry/core/internal/engine/plugin-manifest.js';
|
|
2
3
|
import { coverage } from './coverage/coverage.js';
|
|
3
4
|
import { diffCoverage } from './coverage/diff-coverage.js';
|
|
@@ -12,8 +13,10 @@ import { secrets } from './security/secrets.js';
|
|
|
12
13
|
import { githubSource, gitlabSource, localSource } from './source/forges.js';
|
|
13
14
|
import { structure } from './structure/structure.js';
|
|
14
15
|
// The review path uses the importer kind, which is also part of existing inspection profiles.
|
|
16
|
+
const licensePlugin = licenses();
|
|
17
|
+
export const builtInConfigurations = new Map([[licensePlugin.id, licenses]]);
|
|
15
18
|
const lcov = { ...bundledPlugin(coverage), kinds: ['coverage', 'import'] };
|
|
16
19
|
/** The built-in plugins in run order. The first language plugin is the default provider. */
|
|
17
20
|
export const builtInPlugins = [babelProvider, bundledPlugin(structure), maintainability, duplication, lcov, bundledPlugin(diffCoverage),
|
|
18
|
-
secrets, jsSecurity, actionsSecurity, npmSupplyChain, dockerfile, githubSource, gitlabSource, localSource];
|
|
21
|
+
secrets, jsSecurity, actionsSecurity, npmSupplyChain, dockerfile, licensePlugin, githubSource, gitlabSource, localSource];
|
|
19
22
|
//# sourceMappingURL=built-in.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare function pointer(path: readonly (string | number)[]): string;
|
|
2
|
+
interface Span {
|
|
3
|
+
readonly line: number;
|
|
4
|
+
readonly endLine: number;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Find the lines of the wanted values in JSON text that JSON.parse has already accepted. A member starts on the line
|
|
8
|
+
* of its key and ends on the line where its value ends. Only paths up to `depth` keys deep are tracked.
|
|
9
|
+
*/
|
|
10
|
+
export declare function locateJsonSpans(text: string, wanted: ReadonlySet<string>, depth: number): ReadonlyMap<string, Span>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
export function pointer(path) {
|
|
2
|
+
return path.map(segment => typeof segment === 'number' ? '#' + segment : JSON.stringify(segment)).join('');
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Find the lines of the wanted values in JSON text that JSON.parse has already accepted. A member starts on the line
|
|
6
|
+
* of its key and ends on the line where its value ends. Only paths up to `depth` keys deep are tracked.
|
|
7
|
+
*/
|
|
8
|
+
export function locateJsonSpans(text, wanted, depth) {
|
|
9
|
+
const spans = new Map();
|
|
10
|
+
const stack = [];
|
|
11
|
+
let line = 1;
|
|
12
|
+
const child = () => {
|
|
13
|
+
const parent = stack.at(-1);
|
|
14
|
+
if (!parent)
|
|
15
|
+
return { path: '', line };
|
|
16
|
+
const path = parent.path === undefined || stack.length > depth ? undefined
|
|
17
|
+
: parent.path + (parent.array ? `#${parent.index}` : JSON.stringify(parent.key));
|
|
18
|
+
return { path, line: parent.array ? line : parent.keyLine };
|
|
19
|
+
};
|
|
20
|
+
const scalar = () => {
|
|
21
|
+
const { path, line: start } = child();
|
|
22
|
+
if (path !== undefined && wanted.has(path))
|
|
23
|
+
spans.set(path, { line: start, endLine: line });
|
|
24
|
+
};
|
|
25
|
+
for (let index = 0; index < text.length;) {
|
|
26
|
+
const char = text[index];
|
|
27
|
+
if (char === '\n')
|
|
28
|
+
line++;
|
|
29
|
+
if (char === '\n' || char === ' ' || char === '\t' || char === '\r' || char === ':') {
|
|
30
|
+
index++;
|
|
31
|
+
}
|
|
32
|
+
else if (char === ',') {
|
|
33
|
+
const parent = stack.at(-1);
|
|
34
|
+
if (parent?.array)
|
|
35
|
+
parent.index++;
|
|
36
|
+
else if (parent)
|
|
37
|
+
parent.expectKey = true;
|
|
38
|
+
index++;
|
|
39
|
+
}
|
|
40
|
+
else if (char === '"') {
|
|
41
|
+
const end = stringEnd(text, index);
|
|
42
|
+
const parent = stack.at(-1);
|
|
43
|
+
if (parent && !parent.array && parent.expectKey) {
|
|
44
|
+
const raw = text.slice(index + 1, end);
|
|
45
|
+
parent.key = raw.includes('\\') ? JSON.parse(text.slice(index, end + 1)) : raw;
|
|
46
|
+
parent.keyLine = line;
|
|
47
|
+
parent.expectKey = false;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
scalar();
|
|
51
|
+
}
|
|
52
|
+
index = end + 1;
|
|
53
|
+
}
|
|
54
|
+
else if (char === '{' || char === '[') {
|
|
55
|
+
const { path, line: start } = child();
|
|
56
|
+
stack.push({ path, line: start, array: char === '[', index: 0, key: '', keyLine: line, expectKey: char === '{' });
|
|
57
|
+
index++;
|
|
58
|
+
}
|
|
59
|
+
else if (char === '}' || char === ']') {
|
|
60
|
+
const frame = stack.pop();
|
|
61
|
+
if (frame?.path !== undefined && wanted.has(frame.path))
|
|
62
|
+
spans.set(frame.path, { line: frame.line, endLine: line });
|
|
63
|
+
index++;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
scalar();
|
|
67
|
+
while (index < text.length && !/[\s,\]}]/.test(text[index]))
|
|
68
|
+
index++;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return spans;
|
|
72
|
+
}
|
|
73
|
+
function stringEnd(text, start) {
|
|
74
|
+
for (let from = start + 1;;) {
|
|
75
|
+
const quote = text.indexOf('"', from);
|
|
76
|
+
if (quote < 0)
|
|
77
|
+
return text.length;
|
|
78
|
+
let slashes = 0;
|
|
79
|
+
while (text[quote - 1 - slashes] === '\\')
|
|
80
|
+
slashes++;
|
|
81
|
+
if (slashes % 2 === 0)
|
|
82
|
+
return quote;
|
|
83
|
+
from = quote + 1;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=json-spans.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
export function readComposerLock(text) {
|
|
5
|
+
const lock = JSON.parse(text);
|
|
6
|
+
if (!isRecord(lock) || !Array.isArray(lock.packages)
|
|
7
|
+
|| (lock['packages-dev'] != null && !Array.isArray(lock['packages-dev']))) {
|
|
8
|
+
throw new Error('The Composer lockfile must contain packages and a packages-dev array when present');
|
|
9
|
+
}
|
|
10
|
+
const packages = Object.entries({ packages: lock.packages, 'packages-dev': lock['packages-dev'] ?? [] })
|
|
11
|
+
.flatMap(([section, entries]) => entries.flatMap((entry, index) => {
|
|
12
|
+
if (!isRecord(entry) || typeof entry.name !== 'string' || !entry.name.trim())
|
|
13
|
+
return [];
|
|
14
|
+
const license = declaredLicense(entry.license);
|
|
15
|
+
return [{ at: pointer([section, index]), name: entry.name, dev: section === 'packages-dev',
|
|
16
|
+
...(typeof entry.version === 'string' ? { version: entry.version } : {}),
|
|
17
|
+
...(license === undefined ? {} : { license }) }];
|
|
18
|
+
}));
|
|
19
|
+
if (packages.length === 0)
|
|
20
|
+
return [];
|
|
21
|
+
const spans = locateJsonSpans(text, new Set(packages.map(({ at }) => at)), 2);
|
|
22
|
+
return packages.map(({ at, ...entry }) => ({ ...entry, ...spans.get(at) ?? { line: 1, endLine: 1 } }));
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=composer-lock.js.map
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { LicenseImportFormat } from '@repometry/core/internal/model/license-evidence.js';
|
|
2
|
+
import type { DataContract } from '@repometry/core/internal/engine/plugin.js';
|
|
3
|
+
export declare const maxLicenseLength = 256;
|
|
4
|
+
export interface Dependency {
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly version?: string;
|
|
7
|
+
readonly license?: string;
|
|
8
|
+
readonly overlongLicense?: true;
|
|
9
|
+
readonly dev: boolean;
|
|
10
|
+
readonly line: number;
|
|
11
|
+
readonly endLine: number;
|
|
12
|
+
}
|
|
13
|
+
export interface DependencySource {
|
|
14
|
+
readonly path: string;
|
|
15
|
+
readonly packages: readonly Dependency[];
|
|
16
|
+
readonly unverified?: true;
|
|
17
|
+
readonly format?: LicenseImportFormat;
|
|
18
|
+
}
|
|
19
|
+
export declare const dependencySources: DataContract<readonly DependencySource[]>;
|
|
20
|
+
export declare const dependencySourcesSchema: {
|
|
21
|
+
readonly type: 'array';
|
|
22
|
+
readonly items: {
|
|
23
|
+
readonly type: 'object';
|
|
24
|
+
readonly additionalProperties: false;
|
|
25
|
+
readonly required: readonly ['path', 'packages'];
|
|
26
|
+
readonly properties: {
|
|
27
|
+
readonly path: {
|
|
28
|
+
readonly type: 'string';
|
|
29
|
+
readonly minLength: 1;
|
|
30
|
+
};
|
|
31
|
+
readonly packages: {
|
|
32
|
+
readonly type: 'array';
|
|
33
|
+
readonly items: {
|
|
34
|
+
readonly type: 'object';
|
|
35
|
+
readonly additionalProperties: false;
|
|
36
|
+
readonly required: readonly ['name', 'dev', 'line', 'endLine'];
|
|
37
|
+
readonly properties: {
|
|
38
|
+
readonly name: {
|
|
39
|
+
readonly type: 'string';
|
|
40
|
+
readonly minLength: 1;
|
|
41
|
+
};
|
|
42
|
+
readonly version: {
|
|
43
|
+
readonly type: 'string';
|
|
44
|
+
};
|
|
45
|
+
readonly license: {
|
|
46
|
+
readonly type: 'string';
|
|
47
|
+
};
|
|
48
|
+
readonly overlongLicense: {
|
|
49
|
+
readonly const: true;
|
|
50
|
+
};
|
|
51
|
+
readonly dev: {
|
|
52
|
+
readonly type: 'boolean';
|
|
53
|
+
};
|
|
54
|
+
readonly line: {
|
|
55
|
+
readonly type: 'integer';
|
|
56
|
+
readonly minimum: 1;
|
|
57
|
+
};
|
|
58
|
+
readonly endLine: {
|
|
59
|
+
readonly type: 'integer';
|
|
60
|
+
readonly minimum: 1;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
readonly unverified: {
|
|
66
|
+
readonly const: true;
|
|
67
|
+
};
|
|
68
|
+
readonly format: {
|
|
69
|
+
readonly enum: readonly ["cyclonedx", "spdx"];
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { licenseImportFormats } from '@repometry/core/internal/model/license-evidence.js';
|
|
2
|
+
import { isRecord } from '@repometry/core/internal/engine/plugin.js';
|
|
3
|
+
export const maxLicenseLength = 256;
|
|
4
|
+
const dependency = {
|
|
5
|
+
type: 'object', additionalProperties: false, required: ['name', 'dev', 'line', 'endLine'],
|
|
6
|
+
properties: {
|
|
7
|
+
name: { type: 'string', minLength: 1 }, version: { type: 'string' }, license: { type: 'string' }, overlongLicense: { const: true },
|
|
8
|
+
dev: { type: 'boolean' }, line: { type: 'integer', minimum: 1 }, endLine: { type: 'integer', minimum: 1 },
|
|
9
|
+
},
|
|
10
|
+
};
|
|
11
|
+
export const dependencySources = {
|
|
12
|
+
id: 'repometry.license-dependencies/v1',
|
|
13
|
+
accepts: (value) => Array.isArray(value) && value.every(source => isRecord(source)
|
|
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)),
|
|
21
|
+
};
|
|
22
|
+
export const dependencySourcesSchema = {
|
|
23
|
+
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 } } },
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=dependencies.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { JsonValue } from '@repometry/core/internal/model/plugin-data.js';
|
|
2
|
+
export declare function licenses(options?: JsonValue | undefined): {
|
|
3
|
+
id: string;
|
|
4
|
+
version: string;
|
|
5
|
+
api: string;
|
|
6
|
+
tools?: Readonly<Record<string, string>>;
|
|
7
|
+
operations: readonly import("@repometry/core").Operation[];
|
|
8
|
+
rules?: readonly import("@repometry/core/internal/engine/plugin.js").RuleDescriptor[];
|
|
9
|
+
config?: import("@repometry/core/internal/engine/plugin.js").PluginConfigSchema;
|
|
10
|
+
settings?: JsonValue;
|
|
11
|
+
kinds: readonly import("@repometry/core/internal/engine/plugin.js").PluginKind[];
|
|
12
|
+
providesLanguages?: readonly import("@repometry/core/internal/model/language.js").ProvidedLanguage[];
|
|
13
|
+
languageProvenanceRequiresSource?: true;
|
|
14
|
+
produces: readonly import("@repometry/core/internal/engine/plugin.js").ProductDeclaration[];
|
|
15
|
+
claims: {
|
|
16
|
+
globs: string[];
|
|
17
|
+
scanOnly: boolean;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { checkedDependencies, licenseFiles, licenseLockKind, licenseLockNames } from '@repometry/core/internal/model/license-evidence.js';
|
|
2
|
+
import { bundledPlugin, pluginManifestSchema } from '@repometry/core/internal/engine/plugin-manifest.js';
|
|
3
|
+
import { findingResult } from '@repometry/core/internal/engine/author-contracts.js';
|
|
4
|
+
import { dependencySources, dependencySourcesSchema, maxLicenseLength } from './dependencies.js';
|
|
5
|
+
import { readComposerLock } from './composer-lock.js';
|
|
6
|
+
import { listsDependencies } from './unverified-lock.js';
|
|
7
|
+
import { readSbom } from './sbom.js';
|
|
8
|
+
import { readNpmLock } from './npm-lock.js';
|
|
9
|
+
import { licenseDecision, licenseListVersion, licensePolicy, policySchema } from './policy.js';
|
|
10
|
+
const id = 'licenses';
|
|
11
|
+
const checks = [
|
|
12
|
+
{ id: 'denied-license', description: 'A dependency declares a license outside the configured policy.' },
|
|
13
|
+
{ id: 'unknown-license', description: 'A dependency license is missing or could not be identified.' },
|
|
14
|
+
{ id: 'unverified-dependencies', description: 'A lockfile lists dependencies without license metadata.' },
|
|
15
|
+
];
|
|
16
|
+
const checked = {
|
|
17
|
+
id: checkedDependencies, label: 'Checked dependencies', unit: 'count', scope: 'file',
|
|
18
|
+
aggregate: 'sum', better: 'none', group: 'Legal',
|
|
19
|
+
};
|
|
20
|
+
export function licenses(options = undefined) {
|
|
21
|
+
const policy = licensePolicy(options);
|
|
22
|
+
return {
|
|
23
|
+
...bundledPlugin({
|
|
24
|
+
schema: pluginManifestSchema, id, version: '1.0.0', category: 'legal', optionsSchema: policySchema,
|
|
25
|
+
include: licenseLockNames.map(name => '**/' + name), tools: { 'spdx-license-list': licenseListVersion }, checks,
|
|
26
|
+
create: () => ({
|
|
27
|
+
produces: [
|
|
28
|
+
{ contract: dependencySources.id, persistence: 'report', valueSchema: dependencySourcesSchema },
|
|
29
|
+
{ contract: findingResult.id, persistence: 'report', metrics: [checked] },
|
|
30
|
+
],
|
|
31
|
+
operations: [{
|
|
32
|
+
id: 'read', role: 'provider', scope: 'repository', inputs: { licenseFiles }, output: dependencySources,
|
|
33
|
+
execute(context) {
|
|
34
|
+
return context.read('licenseFiles', licenseFiles).flatMap(({ path, bytes, format }) => {
|
|
35
|
+
try {
|
|
36
|
+
const text = new TextDecoder('utf-8', { fatal: true }).decode(bytes);
|
|
37
|
+
const sources = format === undefined ? readLockfile(path, text) : [{ path, format, packages: readSbom(format, text) }];
|
|
38
|
+
return sources.map(source => ({ ...source, packages: source.packages.map(boundLicense) }));
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
context.emitDiagnostic?.('Unable to read ' + (format ?? 'lockfile') + ' license metadata: ' + (error instanceof Error ? error.message : String(error)), path);
|
|
42
|
+
return [];
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
},
|
|
46
|
+
}, {
|
|
47
|
+
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
|
+
},
|
|
74
|
+
}],
|
|
75
|
+
}),
|
|
76
|
+
}),
|
|
77
|
+
claims: { globs: licenseLockNames.map(name => '**/' + name), scanOnly: true },
|
|
78
|
+
...(options === undefined ? {} : { settings: options }),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function boundLicense(dependency) {
|
|
82
|
+
if ((dependency.license?.length ?? 0) <= maxLicenseLength)
|
|
83
|
+
return dependency;
|
|
84
|
+
const { license: _, ...rest } = dependency;
|
|
85
|
+
return { ...rest, overlongLicense: true };
|
|
86
|
+
}
|
|
87
|
+
function findingMessage(label, { license, overlongLicense }, decision, preset) {
|
|
88
|
+
if (overlongLicense)
|
|
89
|
+
return `${label} declares a license expression longer than ${maxLicenseLength} characters.`;
|
|
90
|
+
if (license === undefined)
|
|
91
|
+
return `${label} declares no license.`;
|
|
92
|
+
if (license === 'UNLICENSED')
|
|
93
|
+
return `${label} is unlicensed, which the ${preset} policy does not allow.`;
|
|
94
|
+
if (decision === 'denied')
|
|
95
|
+
return `${label} is licensed under ${license}, which the ${preset} policy does not allow.`;
|
|
96
|
+
if (decision === 'unclassified')
|
|
97
|
+
return `${label} declares ${license}, which the ${preset} policy could not classify. Add the unclassified SPDX identifier to allow or deny.`;
|
|
98
|
+
return `${label} declares ${license}, which could not be identified as a valid SPDX expression.`;
|
|
99
|
+
}
|
|
100
|
+
function readLockfile(path, text) {
|
|
101
|
+
const name = path.slice(path.lastIndexOf('/') + 1);
|
|
102
|
+
switch (licenseLockKind(name)) {
|
|
103
|
+
case 'npm': {
|
|
104
|
+
const packages = readNpmLock(text);
|
|
105
|
+
return [packages === undefined ? { path, packages: [], unverified: true } : { path, packages }];
|
|
106
|
+
}
|
|
107
|
+
case 'composer': return [{ path, packages: readComposerLock(text) }];
|
|
108
|
+
case 'unverified': return listsDependencies(name, text) ? [{ path, packages: [], unverified: true }] : [];
|
|
109
|
+
}
|
|
110
|
+
return [];
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=licenses.js.map
|
|
@@ -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
|