@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
|
@@ -58,9 +58,11 @@
|
|
|
58
58
|
"lineComments": { "type": "array", "items": { "$ref": "#/$defs/syntax/$defs/marker" } },
|
|
59
59
|
"blockComments": { "type": "array", "items": { "type": "array", "minItems": 2, "maxItems": 2,
|
|
60
60
|
"items": { "$ref": "#/$defs/syntax/$defs/marker" } } },
|
|
61
|
+
"nestedBlockComments": { "type": "boolean" },
|
|
61
62
|
"strings": { "type": "array", "items": {
|
|
62
63
|
"type": "object", "required": ["quote"], "additionalProperties": false,
|
|
63
64
|
"properties": { "quote": { "$ref": "#/$defs/syntax/$defs/marker" },
|
|
65
|
+
"end": { "$ref": "#/$defs/syntax/$defs/marker" }, "doubleEnd": { "type": "boolean" },
|
|
64
66
|
"multiline": { "type": "boolean" }, "raw": { "type": "boolean" } }
|
|
65
67
|
} },
|
|
66
68
|
"stringPrefixes": { "type": "array", "items": { "$ref": "#/$defs/syntax/$defs/word" } },
|
|
@@ -193,10 +193,12 @@
|
|
|
193
193
|
"type": "array",
|
|
194
194
|
"items": {
|
|
195
195
|
"type": "object",
|
|
196
|
-
"required": ["finding"
|
|
196
|
+
"required": ["finding"],
|
|
197
|
+
"oneOf": [{ "required": ["matchedRule"] }, { "required": ["reason"] }],
|
|
197
198
|
"properties": {
|
|
198
199
|
"finding": { "$ref": "#/$defs/finding" },
|
|
199
|
-
"matchedRule": { "$ref": "#/$defs/count" }
|
|
200
|
+
"matchedRule": { "$ref": "#/$defs/count" },
|
|
201
|
+
"reason": { "type": "string", "pattern": "\\S" }
|
|
200
202
|
},
|
|
201
203
|
"additionalProperties": false
|
|
202
204
|
}
|
|
@@ -404,7 +406,8 @@
|
|
|
404
406
|
"security",
|
|
405
407
|
"dependency",
|
|
406
408
|
"secret",
|
|
407
|
-
"infrastructure"
|
|
409
|
+
"infrastructure",
|
|
410
|
+
"legal"
|
|
408
411
|
]
|
|
409
412
|
},
|
|
410
413
|
"level": {
|
|
@@ -69,6 +69,20 @@
|
|
|
69
69
|
"maintainability"
|
|
70
70
|
],
|
|
71
71
|
"properties": {
|
|
72
|
+
"legal": {
|
|
73
|
+
"type": "object",
|
|
74
|
+
"required": ["grade", "checked", "inputs", "low", "medium", "high", "unknown"],
|
|
75
|
+
"additionalProperties": false,
|
|
76
|
+
"properties": {
|
|
77
|
+
"grade": { "enum": ["A", "B", "C", "D", "F"] },
|
|
78
|
+
"checked": { "type": "integer", "minimum": 0 },
|
|
79
|
+
"inputs": { "type": "integer", "minimum": 1 },
|
|
80
|
+
"low": { "type": "integer", "minimum": 0 },
|
|
81
|
+
"medium": { "type": "integer", "minimum": 0 },
|
|
82
|
+
"high": { "type": "integer", "minimum": 0 },
|
|
83
|
+
"unknown": { "type": "integer", "minimum": 0 }
|
|
84
|
+
}
|
|
85
|
+
},
|
|
72
86
|
"codeLines": {
|
|
73
87
|
"$ref": "#/$defs/nullableCount"
|
|
74
88
|
},
|
|
@@ -61,6 +61,10 @@
|
|
|
61
61
|
<span id="security-mark" class="mark severity"></span>
|
|
62
62
|
<span class="verdict-text"><button type="button" role="tab" class="verdict-tab" data-metric="security" aria-controls="trend" aria-describedby="security-mark security-detail">Security</button><span id="security-detail" class="verdict-detail"></span></span>
|
|
63
63
|
</div>
|
|
64
|
+
<div class="verdict" id="legal-verdict">
|
|
65
|
+
<span id="legal-mark" class="mark grade"></span>
|
|
66
|
+
<span class="verdict-text"><button type="button" role="tab" class="verdict-tab" data-metric="legal" aria-controls="trend" aria-describedby="legal-mark legal-detail legal-scope">Legal</button><span id="legal-detail" class="verdict-detail"></span><span id="legal-scope" class="verdict-detail verdict-more"></span></span>
|
|
67
|
+
</div>
|
|
64
68
|
</div>
|
|
65
69
|
<section id="trend" class="trend" role="tabpanel" aria-labelledby="trend-title">
|
|
66
70
|
<h3 id="trend-title" class="visually-hidden"></h3>
|
|
@@ -245,7 +245,7 @@ main:focus { outline: none; }
|
|
|
245
245
|
/* Overview */
|
|
246
246
|
.overview-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 2rem 2.5rem; align-items: start; }
|
|
247
247
|
.overview-grid:has(> aside:not([hidden])) { grid-template-columns: minmax(0, 1fr) minmax(19rem, 24rem); }
|
|
248
|
-
.verdict-card { overflow: hidden; }
|
|
248
|
+
.verdict-card { overflow: hidden; container-type: inline-size; }
|
|
249
249
|
.verdicts { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); border-bottom: 1px solid var(--rule); }
|
|
250
250
|
.verdict {
|
|
251
251
|
display: flex;
|
|
@@ -274,6 +274,11 @@ main:focus { outline: none; }
|
|
|
274
274
|
.verdict-more > span { white-space: nowrap; }
|
|
275
275
|
/* A detail that counts something leads to exactly what it counts. */
|
|
276
276
|
.verdict-detail a { position: relative; z-index: 1; color: inherit; text-decoration-color: var(--rule-strong); }
|
|
277
|
+
@container (min-width: 33rem) and (max-width: 49rem) {
|
|
278
|
+
.verdicts { grid-auto-flow: row; grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
|
279
|
+
.verdicts > .verdict:nth-child(odd) { border-left: 0; }
|
|
280
|
+
.verdicts > .verdict:nth-child(n + 3) { border-top: 1px solid var(--rule); }
|
|
281
|
+
}
|
|
277
282
|
.verdict-detail a:hover { color: var(--accent-strong); text-decoration-color: currentColor; }
|
|
278
283
|
.mark { flex: none; display: inline-grid; place-items: center; width: 2.5rem; height: 2.5rem; border-radius: 8px; font-size: 1.25rem; font-weight: 650; color: #fff; font-variant-numeric: tabular-nums; }
|
|
279
284
|
.grade { background: var(--grade-a); }
|
|
@@ -485,7 +490,7 @@ tbody tr:last-child > * { border-bottom: 0; }
|
|
|
485
490
|
.overview-aside #overview-sunburst { grid-row: 1 / span 4; }
|
|
486
491
|
}
|
|
487
492
|
@media (max-width: 52rem) {
|
|
488
|
-
.verdicts { grid-auto-flow: row; }
|
|
493
|
+
.verdicts { grid-auto-flow: row; grid-template-columns: minmax(0, 1fr); }
|
|
489
494
|
.verdict { border-left: 0; border-top: 1px solid var(--rule); min-height: 4.5rem; }
|
|
490
495
|
.verdict:first-child { border-top: 0; }
|
|
491
496
|
.verdict:has(.verdict-tab[aria-selected="true"]) { box-shadow: inset 3px 0 0 var(--accent); }
|
|
@@ -41,7 +41,8 @@ export interface GitSelection {
|
|
|
41
41
|
readonly excludes: (path: string) => boolean;
|
|
42
42
|
readonly isSource: (path: string) => boolean;
|
|
43
43
|
readonly claims?: (path: string) => boolean;
|
|
44
|
+
readonly claimLimit?: (path: string) => number;
|
|
44
45
|
readonly history?: GitBlobHistory;
|
|
45
46
|
}
|
|
46
|
-
export declare function readGitCommit(directory: string, revision: string, { excludes, isSource, claims, history }: GitSelection): Promise<SourceSnapshot>;
|
|
47
|
+
export declare function readGitCommit(directory: string, revision: string, { excludes, isSource, claims, claimLimit, history }: GitSelection): Promise<SourceSnapshot>;
|
|
47
48
|
export {};
|
|
@@ -7,7 +7,7 @@ import { isGeneratedSource } from '@repometry/core/internal/profile/exclusions.j
|
|
|
7
7
|
import { gitExecutable } from './git-executable.js';
|
|
8
8
|
import { GitBlobHistory, gitBlobBatchBytes } from './blob-history.js';
|
|
9
9
|
const git = promisify(execFile);
|
|
10
|
-
const maxBuffer = gitBlobBatchBytes;
|
|
10
|
+
const maxBuffer = gitBlobBatchBytes + 128;
|
|
11
11
|
const oidPattern = /^(?:[a-f0-9]{40}|[a-f0-9]{64})$/;
|
|
12
12
|
const baseEnv = { ...process.env, GIT_NO_LAZY_FETCH: '1' };
|
|
13
13
|
function gitEnvironment() {
|
|
@@ -189,12 +189,12 @@ function setHeld(child, held) {
|
|
|
189
189
|
handle.unref();
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
|
-
export async function readGitCommit(directory, revision, { excludes, isSource, claims, history }) {
|
|
192
|
+
export async function readGitCommit(directory, revision, { excludes, isSource, claims, claimLimit = () => maxClaimedFileBytes, history }) {
|
|
193
193
|
const id = await resolveGitCommit(directory, revision);
|
|
194
194
|
const tracked = (await gitTreeFiles(directory, id, undefined, true)).filter(({ path }) => !path.split('/').slice(0, -1).some(isExcludedDirectory) && !excludes(path));
|
|
195
195
|
const entries = tracked.filter(({ path }) => isSource(path));
|
|
196
196
|
const claimed = tracked.filter(({ path }) => !isSource(path) && claims?.(path));
|
|
197
|
-
const large = claimed.filter(({ size }) => size !== undefined && size >
|
|
197
|
+
const large = claimed.filter(({ size, path }) => size !== undefined && size > claimLimit(path));
|
|
198
198
|
const binary = new Set();
|
|
199
199
|
for (const { path, oid } of large)
|
|
200
200
|
if (await isBinaryBlob(directory, oid))
|
|
@@ -215,7 +215,7 @@ export async function readGitCommit(directory, revision, { excludes, isSource, c
|
|
|
215
215
|
});
|
|
216
216
|
for (const { path, oid } of requested) {
|
|
217
217
|
const bytes = blobs.get(oid)?.bytes;
|
|
218
|
-
if (bytes && isClaimedText(bytes))
|
|
218
|
+
if (bytes && isClaimedText(bytes, claimLimit(path)))
|
|
219
219
|
files.push({ path, bytes: snapshotBytes(bytes, history) });
|
|
220
220
|
}
|
|
221
221
|
files.sort((left, right) => comparePaths(left.path, right.path));
|
|
@@ -3,14 +3,14 @@ import { basename, dirname, join, relative, resolve, sep } from 'node:path';
|
|
|
3
3
|
import { gitRoot, gitWorkingTreePaths, readGitCommit } from './git.js';
|
|
4
4
|
import { containsPath, readWorkingTree } from './local.js';
|
|
5
5
|
export async function readInspectionSource(request, selection, inventory) {
|
|
6
|
-
const { excludes, isSource, claims } = selection;
|
|
6
|
+
const { excludes, isSource, claims, claimLimit } = selection;
|
|
7
7
|
const root = await realpath('workingTree' in request.source ? request.directory : await gitRoot(request.directory));
|
|
8
8
|
const output = await physicalPath(resolve(request.output));
|
|
9
9
|
if (containsPath(output, root) || output.split(sep).includes('.git')) {
|
|
10
10
|
throw new Error('Choose a dedicated report directory outside Git metadata');
|
|
11
11
|
}
|
|
12
12
|
const snapshot = 'workingTree' in request.source
|
|
13
|
-
? await readWorkingTree(root, output, excludes, isSource, claims, await gitWorkingTreePaths(root), inventory)
|
|
13
|
+
? await readWorkingTree(root, output, excludes, isSource, claims, await gitWorkingTreePaths(root), inventory, claimLimit)
|
|
14
14
|
: await readGitCommit(root, request.source.revision, selection);
|
|
15
15
|
if (inventory && snapshot.subject.kind === 'commit') {
|
|
16
16
|
for (const { path } of snapshot.inventory ?? [])
|
|
@@ -4,4 +4,4 @@ export interface InventoryObserver {
|
|
|
4
4
|
candidate(path: string): boolean;
|
|
5
5
|
record(path: string): void;
|
|
6
6
|
}
|
|
7
|
-
export declare function readWorkingTree(directory: string, output: string, excludes: (path: string) => boolean, isSource: (path: string) => boolean, claims?: (path: string) => boolean, gitPaths?: readonly string[], inventory?: InventoryObserver): Promise<SourceSnapshot>;
|
|
7
|
+
export declare function readWorkingTree(directory: string, output: string, excludes: (path: string) => boolean, isSource: (path: string) => boolean, claims?: (path: string) => boolean, gitPaths?: readonly string[], inventory?: InventoryObserver, claimLimit?: (path: string) => number): Promise<SourceSnapshot>;
|
|
@@ -7,7 +7,7 @@ export function containsPath(parent, path) {
|
|
|
7
7
|
const rest = relative(parent, path);
|
|
8
8
|
return rest === '' || (!isAbsolute(rest) && rest !== '..' && !rest.startsWith(`..${sep}`));
|
|
9
9
|
}
|
|
10
|
-
export async function readWorkingTree(directory, output, excludes, isSource, claims, gitPaths, inventory) {
|
|
10
|
+
export async function readWorkingTree(directory, output, excludes, isSource, claims, gitPaths, inventory, claimLimit = () => maxClaimedFileBytes) {
|
|
11
11
|
const root = await realpath(directory);
|
|
12
12
|
const files = [];
|
|
13
13
|
const generatedExcluded = [];
|
|
@@ -39,17 +39,18 @@ export async function readWorkingTree(directory, output, excludes, isSource, cla
|
|
|
39
39
|
}
|
|
40
40
|
if (!claims?.(path))
|
|
41
41
|
return;
|
|
42
|
-
|
|
42
|
+
const limit = claimLimit(path);
|
|
43
|
+
if ((size ?? (await lstat(absolute)).size) > limit) {
|
|
43
44
|
if (!await isBinaryHead(absolute))
|
|
44
45
|
oversizedClaims.push(path);
|
|
45
46
|
return;
|
|
46
47
|
}
|
|
47
48
|
const bytes = await readFile(absolute);
|
|
48
|
-
if (bytes.length >
|
|
49
|
+
if (bytes.length > limit) {
|
|
49
50
|
if (!bytes.subarray(0, binaryProbeBytes).includes(0))
|
|
50
51
|
oversizedClaims.push(path);
|
|
51
52
|
}
|
|
52
|
-
else if (isClaimedText(bytes))
|
|
53
|
+
else if (isClaimedText(bytes, limit))
|
|
53
54
|
files.push({ path, bytes });
|
|
54
55
|
}
|
|
55
56
|
if (gitPaths === undefined) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { readFile } from 'node:fs/promises';
|
|
2
|
-
import {
|
|
2
|
+
import { sep } from 'node:path';
|
|
3
3
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
4
|
+
import { repositoryPath } from './repository-path.js';
|
|
4
5
|
import { isRecord } from '@repometry/core/internal/engine/plugin.js';
|
|
5
6
|
import { digest } from '@repometry/core/internal/model/snapshot.js';
|
|
6
7
|
import { uniqueScanners, scannerText as text } from '@repometry/core/internal/model/scanner-import.js';
|
|
@@ -194,14 +195,6 @@ function range(first, last) {
|
|
|
194
195
|
return {};
|
|
195
196
|
return { line: first, endLine: safeIndex(last) && last >= first ? last : first };
|
|
196
197
|
}
|
|
197
|
-
function repositoryPath(root, path) {
|
|
198
|
-
if (/[\0\r\n]/.test(path))
|
|
199
|
-
return null;
|
|
200
|
-
const result = relative(root, resolve(root, path));
|
|
201
|
-
if (result === '' || isAbsolute(result) || result === '..' || result.startsWith(`..${sep}`))
|
|
202
|
-
return null;
|
|
203
|
-
return result.split(sep).join('/');
|
|
204
|
-
}
|
|
205
198
|
function requiredText(value) {
|
|
206
199
|
const result = text(value);
|
|
207
200
|
if (result === undefined)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { open, realpath } from 'node:fs/promises';
|
|
2
|
+
import { basename } from 'node:path';
|
|
3
|
+
import { maxLicenseFileBytes } from '@repometry/core/internal/model/license-evidence.js';
|
|
4
|
+
import { repositoryPath } from './repository-path.js';
|
|
5
|
+
export async function readLicenseImports(inputs, root) {
|
|
6
|
+
const files = [];
|
|
7
|
+
const skipped = [];
|
|
8
|
+
for (const [index, { format, file }] of inputs.entries()) {
|
|
9
|
+
const path = repositoryPath(root, await realpath(file)) ?? 'imports/' + (index + 1) + '/' + basename(file).replace(/[\0\r\n]/g, '_');
|
|
10
|
+
const handle = await open(file, 'r');
|
|
11
|
+
try {
|
|
12
|
+
const stat = await handle.stat();
|
|
13
|
+
if (!stat.isFile())
|
|
14
|
+
throw new Error('Expected an SBOM file: ' + path);
|
|
15
|
+
const parts = [];
|
|
16
|
+
if (stat.size <= maxLicenseFileBytes) {
|
|
17
|
+
for await (const part of handle.createReadStream({ autoClose: false, start: 0, end: maxLicenseFileBytes })) {
|
|
18
|
+
parts.push(part);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const length = parts.reduce((size, part) => size + part.byteLength, 0);
|
|
22
|
+
if (stat.size > maxLicenseFileBytes || length > maxLicenseFileBytes) {
|
|
23
|
+
skipped.push({ path, message: 'SBOM exceeds the 64 MiB license input limit.' });
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
files.push({ path, bytes: Buffer.concat(parts, length), format });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
finally {
|
|
30
|
+
await handle.close();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const formats = [...new Set(inputs.map(({ format }) => format))].sort();
|
|
34
|
+
return { formats, files, skipped };
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=license-import.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function repositoryPath(root: string, path: string): string | null;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { isAbsolute, relative, resolve, sep } from 'node:path';
|
|
2
|
+
export function repositoryPath(root, path) {
|
|
3
|
+
if (/[\0\r\n]/.test(path))
|
|
4
|
+
return null;
|
|
5
|
+
const result = relative(root, resolve(root, path));
|
|
6
|
+
if (result === '' || isAbsolute(result) || result === '..' || result.startsWith(`..${sep}`))
|
|
7
|
+
return null;
|
|
8
|
+
return result.split(sep).join('/');
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=repository-path.js.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { LicenseInput } from '@repometry/core/internal/model/license-evidence.js';
|
|
1
2
|
import type { FindingInput } from '../api/import/finding-import.js';
|
|
2
3
|
export declare const importerIds: string[];
|
|
3
4
|
/** Typed imports resolve against the invocation directory, imports from the config against the repository root. */
|
|
@@ -6,4 +7,5 @@ export declare function readInputs(base: string, inputs: readonly string[]): {
|
|
|
6
7
|
goCover: string[] | undefined;
|
|
7
8
|
cobertura: string[] | undefined;
|
|
8
9
|
findings: FindingInput[];
|
|
10
|
+
licenseInputs?: LicenseInput[] | undefined;
|
|
9
11
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { licenseImportFormats } from '@repometry/core/internal/model/license-evidence.js';
|
|
1
2
|
import { resolve } from 'node:path';
|
|
2
3
|
const scanners = {
|
|
3
4
|
sarif: { format: 'sarif', category: 'lint' },
|
|
@@ -6,13 +7,14 @@ const scanners = {
|
|
|
6
7
|
eslint: { format: 'eslint', category: 'lint' },
|
|
7
8
|
osv: { format: 'osv', category: 'dependency' },
|
|
8
9
|
};
|
|
9
|
-
export const importerIds = ['lcov', 'go-cover', 'cobertura', ...Object.keys(scanners)];
|
|
10
|
+
export const importerIds = ['lcov', 'go-cover', 'cobertura', ...Object.keys(scanners), ...licenseImportFormats];
|
|
10
11
|
/** Typed imports resolve against the invocation directory, imports from the config against the repository root. */
|
|
11
12
|
export function readInputs(base, inputs) {
|
|
12
13
|
const lcov = [];
|
|
13
14
|
const goCover = [];
|
|
14
15
|
const cobertura = [];
|
|
15
16
|
const findings = [];
|
|
17
|
+
const licenseInputs = [];
|
|
16
18
|
for (const value of inputs) {
|
|
17
19
|
const equal = value.indexOf('=');
|
|
18
20
|
const format = value.slice(0, equal);
|
|
@@ -25,6 +27,8 @@ export function readInputs(base, inputs) {
|
|
|
25
27
|
goCover.push(resolve(base, file));
|
|
26
28
|
else if (format === 'cobertura')
|
|
27
29
|
cobertura.push(resolve(base, file));
|
|
30
|
+
else if (format === 'cyclonedx' || format === 'spdx')
|
|
31
|
+
licenseInputs.push({ format, file: resolve(base, file) });
|
|
28
32
|
else {
|
|
29
33
|
if (!Object.hasOwn(scanners, format))
|
|
30
34
|
throw new Error(`Unknown import format: ${format}. Choose ${importerIds.join(', ')}.`);
|
|
@@ -32,6 +36,6 @@ export function readInputs(base, inputs) {
|
|
|
32
36
|
}
|
|
33
37
|
}
|
|
34
38
|
return { lcov: lcov.length ? lcov : undefined, goCover: goCover.length ? goCover : undefined,
|
|
35
|
-
cobertura: cobertura.length ? cobertura : undefined, findings };
|
|
39
|
+
cobertura: cobertura.length ? cobertura : undefined, findings, ...(licenseInputs.length ? { licenseInputs } : {}) };
|
|
36
40
|
}
|
|
37
41
|
//# sourceMappingURL=imports.js.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { legalSummary } from '@repometry/core/internal/model/quality-summary.js';
|
|
1
2
|
import { readFile, writeFile } from 'node:fs/promises';
|
|
2
3
|
import { relative, resolve, sep } from 'node:path';
|
|
3
4
|
import { firstParentRange, gitRoot, gitTreeFiles, resolveGitCommit } from '../api/git/git.js';
|
|
@@ -150,7 +151,7 @@ async function analyze(input, distribution) {
|
|
|
150
151
|
const config = await readConfig(root, input, false, distribution);
|
|
151
152
|
const revision = input.args[0] ?? 'HEAD';
|
|
152
153
|
const imports = input.many('import');
|
|
153
|
-
const { findings, ...coverage } = imports.length ? readInputs(directory, imports) : readInputs(root, config.imports);
|
|
154
|
+
const { findings, licenseInputs, ...coverage } = imports.length ? readInputs(directory, imports) : readInputs(root, config.imports);
|
|
154
155
|
const importRoot = input.text('import-root');
|
|
155
156
|
if (importRoot && findings.length === 0)
|
|
156
157
|
throw new Error('--import-root requires a scanner report');
|
|
@@ -160,7 +161,7 @@ async function analyze(input, distribution) {
|
|
|
160
161
|
const report = skipped ? await store.reader.read({ kind: 'commit', id: savedId })
|
|
161
162
|
: await inspectWithOptions({ directory, output, source: workingTree ? { workingTree: true } : { revision },
|
|
162
163
|
...coverage, exclude: listOption(input, 'exclude', config.exclude), ignore: config.ignore, plugins: config.plugins, parsers: config.parsers,
|
|
163
|
-
findingInputs: findings, findingRoot: importRoot ? resolve(directory, importRoot) : undefined }, { inventory });
|
|
164
|
+
licenseInputs, findingInputs: findings, findingRoot: importRoot ? resolve(directory, importRoot) : undefined }, { inventory });
|
|
164
165
|
announceMissingLanguages(inventory.results());
|
|
165
166
|
print({ schema: 'urn:repometry:schema:analysis-result:1', ...inspectionSummary(report), ...(skipped ? { skipped: true } : {}),
|
|
166
167
|
store: output });
|
|
@@ -233,7 +234,11 @@ async function review(input, distribution) {
|
|
|
233
234
|
const github = useGitHub(input);
|
|
234
235
|
const config = await readConfig(root, input, false, distribution);
|
|
235
236
|
const imports = input.many('import');
|
|
236
|
-
const { findings, ...coverage } = imports.length ? readInputs(directory, imports) : readInputs(root, config.imports);
|
|
237
|
+
const { findings, licenseInputs = [], ...coverage } = imports.length ? readInputs(directory, imports) : readInputs(root, config.imports);
|
|
238
|
+
if (licenseInputs.length && imports.length)
|
|
239
|
+
throw new Error('review compares both sides of a change; SBOM imports apply to full inspections only');
|
|
240
|
+
if (licenseInputs.length)
|
|
241
|
+
process.stderr.write('SBOM imports from the config are skipped: review compares both sides of a change.\n');
|
|
237
242
|
if (findings.length && imports.length)
|
|
238
243
|
throw new Error('review compares both sides of a change; scanner imports apply to full inspections only');
|
|
239
244
|
if (findings.length)
|
|
@@ -286,8 +291,9 @@ function announce(server) {
|
|
|
286
291
|
process.stderr.write(`Serving${server.label ? ' ' + server.label : ''} at ${server.url}\n`);
|
|
287
292
|
}
|
|
288
293
|
function inspectionSummary(report) {
|
|
294
|
+
const legal = legalSummary(report);
|
|
289
295
|
return { subject: report.subject, generatedAt: report.generatedAt, status: report.status, scope: report.scope,
|
|
290
|
-
measurements: report.measurements.length, diagnostics: report.diagnostics.length };
|
|
296
|
+
measurements: report.measurements.length, diagnostics: report.diagnostics.length, ...(legal === undefined ? {} : { legal }) };
|
|
291
297
|
}
|
|
292
298
|
function print(value) {
|
|
293
299
|
process.stdout.write(JSON.stringify(value, null, 2) + '\n');
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { codeStructure, codeStructures, structureMeasures } from '@repometry/core/internal/model/code-structure.js';
|
|
2
2
|
import { pluginRegistration } from './registered-plugin.js';
|
|
3
3
|
import { pluginScope } from './plugin-scope.js';
|
|
4
|
+
import { checkedDependencies } from '@repometry/core/internal/model/license-evidence.js';
|
|
4
5
|
import { definitions } from '@repometry/core/internal/model/measurement.js';
|
|
5
6
|
import { debtModel } from '@repometry/core/internal/model/quality-summary.js';
|
|
6
7
|
import { reportSchema } from '@repometry/core/internal/model/report.js';
|
|
@@ -35,16 +36,17 @@ export function assembleAnalysisReport(input, sources, results) {
|
|
|
35
36
|
...measurementDefinitions },
|
|
36
37
|
scope: { files: fileCount, parsed: results.parsed.size,
|
|
37
38
|
...(results.recovered.size ? { recovered: results.recovered.size } : {}) },
|
|
38
|
-
status: inspectionStatus(fileCount > 0, results),
|
|
39
|
+
status: inspectionStatus(fileCount > 0 || results.measurements.some(row => row.definition === checkedDependencies), results),
|
|
39
40
|
measurements: results.measurements,
|
|
40
41
|
diagnostics: results.diagnostics,
|
|
41
42
|
findings: results.findings,
|
|
43
|
+
...(results.ignoredFindings.length ? { ignoredFindings: results.ignoredFindings } : {}),
|
|
42
44
|
...(results.ruleSkips.length === 0 ? {} : { ruleSkips: results.ruleSkips }),
|
|
43
45
|
...(pluginData === undefined ? {} : { pluginData: { ...pluginData, languages: selectors.catalog,
|
|
44
46
|
inventory: reportInventory(snapshot, sources, results) } }),
|
|
45
47
|
};
|
|
46
48
|
}
|
|
47
|
-
function appliedConfiguration({ snapshot, excludedOutput, excludedPaths = [], coverage }, sources, results, selectors) {
|
|
49
|
+
function appliedConfiguration({ snapshot, excludedOutput, excludedPaths = [], coverage, licenseImport }, sources, results, selectors) {
|
|
48
50
|
const { languages, plugins, providersByPath } = sources;
|
|
49
51
|
const securityScanners = results.securityScanners(plugins);
|
|
50
52
|
const active = new Set(plugins.map(plugin => plugin.id));
|
|
@@ -67,6 +69,7 @@ function appliedConfiguration({ snapshot, excludedOutput, excludedPaths = [], co
|
|
|
67
69
|
source: { extensions: selectors.extensions, ...(selectors.globs.length ? { globs: selectors.globs } : {}),
|
|
68
70
|
excludedDirectories: sourceDirectoriesExcluded, excludedOutput, excludedPaths,
|
|
69
71
|
defaultExclusions: defaultSourceExclusions, generatedSourcePolicy, generatedExcluded: snapshot.generatedExcluded ?? [] },
|
|
72
|
+
...(licenseImport === undefined ? {} : { licenseImports: licenseImport.formats }),
|
|
70
73
|
parser: defaultParser && parsed.has(defaultParser.id) ? defaultParser.settings : undefined,
|
|
71
74
|
maintainability: { structuralRules, duplication: duplicationSettings, debtModel, remediation: 'nonoverlapping-complexity/v1' },
|
|
72
75
|
coverage: coverage === undefined ? null : { inputDigest: digest(coverage.text), pathBase: coverage.sourceRoot,
|
|
@@ -7,6 +7,7 @@ import type { Diagnostic, Report } from '@repometry/core/internal/model/report.j
|
|
|
7
7
|
export declare class AnalysisResults {
|
|
8
8
|
readonly measurements: Measurement[];
|
|
9
9
|
readonly findings: Finding[];
|
|
10
|
+
readonly ignoredFindings: NonNullable<Report['ignoredFindings']>[number][];
|
|
10
11
|
readonly diagnostics: Diagnostic[];
|
|
11
12
|
readonly parsed: Set<string>;
|
|
12
13
|
readonly recovered: Map<string, Diagnostic>;
|
|
@@ -21,7 +22,7 @@ export declare class AnalysisResults {
|
|
|
21
22
|
private readonly securityOperations;
|
|
22
23
|
private readonly recoveryOperations;
|
|
23
24
|
private readonly usedPlans;
|
|
24
|
-
constructor(plugins: readonly Plugin[], oversized: readonly string[]);
|
|
25
|
+
constructor(plugins: readonly Plugin[], oversized: readonly string[], limit?: (path: string) => number);
|
|
25
26
|
remember(task: PlannedOperation, syntaxProvider?: string): void;
|
|
26
27
|
operationRecords(): readonly ReturnType<typeof operationProvenance>[];
|
|
27
28
|
pluginData(): import("@repometry/core/internal/model/plugin-data.js").PluginData | undefined;
|
|
@@ -43,4 +44,4 @@ export declare function operationProvenance(task: PlannedOperation, syntaxProvid
|
|
|
43
44
|
scope?: "repository" | undefined;
|
|
44
45
|
syntaxProvider?: string | undefined;
|
|
45
46
|
};
|
|
46
|
-
export declare function oversizedClaim(path: string): Diagnostic;
|
|
47
|
+
export declare function oversizedClaim(path: string, limit?: number): Diagnostic;
|
|
@@ -2,9 +2,11 @@ import { isRecord } from '@repometry/core/internal/engine/plugin.js';
|
|
|
2
2
|
import { ReportProducts } from '@repometry/core/internal/engine/report-products.js';
|
|
3
3
|
import { codeStructure, recoveredSyntax } from '@repometry/core/internal/model/code-structure.js';
|
|
4
4
|
import { recoveredSourceOperation } from '@repometry/core/internal/model/report.js';
|
|
5
|
+
import { maxClaimedFileBytes } from '@repometry/core/internal/model/source.js';
|
|
5
6
|
export class AnalysisResults {
|
|
6
7
|
measurements = [];
|
|
7
8
|
findings = [];
|
|
9
|
+
ignoredFindings = [];
|
|
8
10
|
diagnostics;
|
|
9
11
|
parsed = new Set();
|
|
10
12
|
recovered = new Map();
|
|
@@ -19,9 +21,9 @@ export class AnalysisResults {
|
|
|
19
21
|
securityOperations;
|
|
20
22
|
recoveryOperations;
|
|
21
23
|
usedPlans = new Map();
|
|
22
|
-
constructor(plugins, oversized) {
|
|
24
|
+
constructor(plugins, oversized, limit = () => maxClaimedFileBytes) {
|
|
23
25
|
this.products = new ReportProducts(plugins);
|
|
24
|
-
this.diagnostics = oversized.map(oversizedClaim);
|
|
26
|
+
this.diagnostics = oversized.map(path => oversizedClaim(path, limit(path)));
|
|
25
27
|
this.recoveryOperations = new Set(plugins.filter(plugin => plugin.languageProvenanceRequiresSource && plugin.kinds.includes('language')).flatMap(({ id, operations }) => operations.filter(operation => operation.role === 'provider' && operation.output.id === codeStructure.id)
|
|
26
28
|
.map(operation => id + '/' + operation.id)));
|
|
27
29
|
this.scanOnly = new Set(plugins.filter(plugin => plugin.claims?.scanOnly).flatMap(({ id, operations }) => operations.map(operation => `${id}/${operation.id}`)));
|
|
@@ -54,8 +56,14 @@ export class AnalysisResults {
|
|
|
54
56
|
if (stored) {
|
|
55
57
|
for (const measurement of stored.measurements)
|
|
56
58
|
this.measurements.push(measurement);
|
|
57
|
-
|
|
58
|
-
|
|
59
|
+
const reasons = new Map(stored.ignored?.map(({ index, reason }) => [index, reason]));
|
|
60
|
+
for (const [index, finding] of stored.findings.entries()) {
|
|
61
|
+
const reason = reasons.get(index);
|
|
62
|
+
if (reason === undefined)
|
|
63
|
+
this.findings.push(finding);
|
|
64
|
+
else
|
|
65
|
+
this.ignoredFindings.push({ finding, reason });
|
|
66
|
+
}
|
|
59
67
|
}
|
|
60
68
|
}
|
|
61
69
|
catch (error) {
|
|
@@ -113,7 +121,8 @@ export function operationProvenance(task, syntaxProvider) {
|
|
|
113
121
|
...(task.operation.scope === 'repository' ? { scope: task.operation.scope } : {}),
|
|
114
122
|
...(syntaxProvider === undefined ? {} : { syntaxProvider }) };
|
|
115
123
|
}
|
|
116
|
-
export function oversizedClaim(path) {
|
|
117
|
-
|
|
124
|
+
export function oversizedClaim(path, limit = maxClaimedFileBytes) {
|
|
125
|
+
const limitMiB = limit / (1024 * 1024);
|
|
126
|
+
return { operation: 'source/claims', state: 'partial', path, message: `Plugin inspection skipped a file larger than ${limitMiB} MiB` };
|
|
118
127
|
}
|
|
119
128
|
//# sourceMappingURL=analysis-results.js.map
|
|
@@ -2,6 +2,7 @@ import { execute } from '@repometry/core/internal/engine/execute.js';
|
|
|
2
2
|
import { plan } from '@repometry/core/internal/engine/plan.js';
|
|
3
3
|
import { cloneSources as cloneSourcesContract } from '@repometry/core/internal/model/clone-source.js';
|
|
4
4
|
import { codeStructure, codeStructures, ruleCategoryMeasures, structureCodeLines } from '@repometry/core/internal/model/code-structure.js';
|
|
5
|
+
import { licenseFiles } from '@repometry/core/internal/model/license-evidence.js';
|
|
5
6
|
import { lcovInput } from '@repometry/core/internal/model/coverage-input.js';
|
|
6
7
|
import { sourceFile, sourceFiles, sourceLineCounts } from '@repometry/core/internal/model/snapshot.js';
|
|
7
8
|
import { isClaimedText, maxClaimedFileBytes } from '@repometry/core/internal/model/source.js';
|
|
@@ -71,6 +72,8 @@ export async function inspectRepositories(sources, results, cache) {
|
|
|
71
72
|
export async function inspectAfterFiles({ coverage: input, excludedPaths = [], snapshot, ignoresCoverage }, sources, parsed, results, cache) {
|
|
72
73
|
const clones = parsed.flatMap(({ structure: { clones }, parser }) => clones ? [{ ...clones, scheme: clones.scheme ?? parser }] : []);
|
|
73
74
|
const products = new Map([['sources', { contract: cloneSourcesContract.id, value: clones }]]);
|
|
75
|
+
if (sources.licenseInputs.length)
|
|
76
|
+
products.set('licenseFiles', { contract: licenseFiles.id, value: sources.licenseInputs });
|
|
74
77
|
if (input !== undefined) {
|
|
75
78
|
const unclassified = new Set([...results.unmeasured].filter(([, missing]) => missing.includes('codeLines')).map(([path]) => path));
|
|
76
79
|
const excludes = sourceExclusionMatcher(excludedPaths, snapshot.generatedExcluded);
|
|
@@ -3,5 +3,5 @@ import type { Report } from '@repometry/core/internal/model/report.js';
|
|
|
3
3
|
import type { AnalysisInput } from '@repometry/core/internal/usecases/inspect.js';
|
|
4
4
|
import type { HistoryCache } from './history-cache.js';
|
|
5
5
|
import type { LanguageRegistry } from './languages.js';
|
|
6
|
-
export { inspectionFileMatcher } from './phases.js';
|
|
6
|
+
export { inspectionFileLimit, inspectionFileMatcher } from './phases.js';
|
|
7
7
|
export declare function analyzeSnapshot(input: AnalysisInput, languages: LanguageRegistry, cache?: OperationCacheOptions, history?: HistoryCache): Promise<Report>;
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { collectRepositorySyntax, defaultFilePlan, inspectAfterFiles, inspectFiles, inspectRepositories } from './analysis-steps.js';
|
|
2
2
|
import { assembleAnalysisReport } from './analysis-report.js';
|
|
3
3
|
import { AnalysisResults } from './analysis-results.js';
|
|
4
|
-
import { selectAnalysisSources } from './phases.js';
|
|
4
|
+
import { inspectionFileLimit, selectAnalysisSources } from './phases.js';
|
|
5
5
|
import { historyProfile } from './history-cache.js';
|
|
6
6
|
import { pluginScope } from './plugin-scope.js';
|
|
7
|
-
export { inspectionFileMatcher } from './phases.js';
|
|
7
|
+
export { inspectionFileLimit, inspectionFileMatcher } from './phases.js';
|
|
8
8
|
export async function analyzeSnapshot(input, languages, cache, history) {
|
|
9
|
-
const sources = selectAnalysisSources(input.snapshot, input.coverage !== undefined, languages);
|
|
9
|
+
const sources = selectAnalysisSources(input.snapshot, input.coverage !== undefined, languages, input.licenseImport);
|
|
10
10
|
const reusable = history?.begin(input.snapshot, historyProfile(input, sources, cache?.configurationDigest));
|
|
11
|
-
const results = new AnalysisResults(sources.plugins, input.snapshot.oversizedClaims ?? []);
|
|
11
|
+
const results = new AnalysisResults(sources.plugins, input.snapshot.oversizedClaims ?? [], inspectionFileLimit(languages, input.licenseImport === undefined));
|
|
12
|
+
for (const skipped of input.licenseImport?.skipped ?? []) {
|
|
13
|
+
results.diagnostics.push({ ...skipped, operation: 'legal/import', state: 'partial' });
|
|
14
|
+
}
|
|
12
15
|
const defaults = languages.plugins.some(pluginScope) ? [] : defaultFilePlan(sources);
|
|
13
16
|
for (const task of defaults)
|
|
14
17
|
results.remember(task);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Plugin } from '@repometry/core/internal/engine/plugin.js';
|
|
2
|
-
import { builtInPlugins } from '../plugins/built-in.js';
|
|
3
|
-
export { builtInPlugins };
|
|
2
|
+
import { builtInConfigurations, builtInPlugins } from '../plugins/built-in.js';
|
|
3
|
+
export { builtInConfigurations, builtInPlugins };
|
|
4
4
|
export declare const builtInPluginIds: ReadonlySet<string>;
|
|
5
5
|
/** Configured built-ins replace their defaults in registration order. */
|
|
6
6
|
export declare function registeredPlugins(additional: readonly Plugin[]): readonly Plugin[];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { pluginRegistration } from './registered-plugin.js';
|
|
2
|
-
import { builtInPlugins } from '../plugins/built-in.js';
|
|
2
|
+
import { builtInConfigurations, builtInPlugins } from '../plugins/built-in.js';
|
|
3
3
|
// The one edge from compose to plugins: everything else in compose reads the built-ins from here.
|
|
4
|
-
export { builtInPlugins };
|
|
4
|
+
export { builtInConfigurations, builtInPlugins };
|
|
5
5
|
export const builtInPluginIds = new Set(builtInPlugins.map(({ id }) => id));
|
|
6
6
|
/** Configured built-ins replace their defaults in registration order. */
|
|
7
7
|
export function registeredPlugins(additional) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { InventoryObserver } from '../api/git/local.js';
|
|
2
|
+
import type { LicenseInput } from '@repometry/core/internal/model/license-evidence.js';
|
|
2
3
|
import type { CoverageInputs } from '../api/import/lcov-files.js';
|
|
3
4
|
import type { OperationCacheOptions } from '@repometry/core/internal/engine/operation-cache.js';
|
|
4
5
|
import type { Plugin } from '@repometry/core/internal/engine/plugin.js';
|
|
@@ -16,6 +17,7 @@ export interface InspectRequest extends CoverageInputs {
|
|
|
16
17
|
readonly revision: string;
|
|
17
18
|
};
|
|
18
19
|
readonly exclude?: readonly string[];
|
|
20
|
+
readonly licenseInputs?: readonly LicenseInput[];
|
|
19
21
|
readonly findingInputs?: readonly FindingInput[];
|
|
20
22
|
readonly findingRoot?: string;
|
|
21
23
|
readonly ignore?: readonly FindingIgnoreRule[];
|