@repometry/cli 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/README.md +10 -5
  2. package/package.json +3 -3
  3. package/target/main/resources/licenses/spdx.json +746 -0
  4. package/target/main/resources/report/json/config-v2.schema.json +2 -1
  5. package/target/main/resources/report/json/file-metrics-v1.schema.json +2 -0
  6. package/target/main/resources/report/json/report-v2.schema.json +6 -3
  7. package/target/main/resources/report/json/repository-summary-v1.schema.json +14 -0
  8. package/target/main/resources/viewer/index.html +5 -1
  9. package/target/main/resources/viewer/styles.css +7 -3
  10. package/target/main/ts/api/git/git.d.ts +2 -1
  11. package/target/main/ts/api/git/git.js +4 -4
  12. package/target/main/ts/api/git/inspection-source.js +2 -2
  13. package/target/main/ts/api/git/local.d.ts +1 -1
  14. package/target/main/ts/api/git/local.js +5 -4
  15. package/target/main/ts/api/import/finding-import.js +2 -9
  16. package/target/main/ts/api/import/license-import.d.ts +2 -0
  17. package/target/main/ts/api/import/license-import.js +36 -0
  18. package/target/main/ts/api/import/repository-path.d.ts +1 -0
  19. package/target/main/ts/api/import/repository-path.js +10 -0
  20. package/target/main/ts/cli/distribution.d.ts +8 -0
  21. package/target/main/ts/cli/distribution.js +23 -0
  22. package/target/main/ts/cli/imports.d.ts +2 -0
  23. package/target/main/ts/cli/imports.js +6 -2
  24. package/target/main/ts/cli/run.d.ts +2 -2
  25. package/target/main/ts/cli/run.js +17 -8
  26. package/target/main/ts/compose/analysis-report.js +5 -2
  27. package/target/main/ts/compose/analysis-results.d.ts +3 -2
  28. package/target/main/ts/compose/analysis-results.js +15 -6
  29. package/target/main/ts/compose/analysis-steps.js +3 -0
  30. package/target/main/ts/compose/analyze-snapshot.d.ts +1 -1
  31. package/target/main/ts/compose/analyze-snapshot.js +7 -4
  32. package/target/main/ts/compose/built-ins.d.ts +2 -2
  33. package/target/main/ts/compose/built-ins.js +2 -2
  34. package/target/main/ts/compose/inspect.d.ts +2 -0
  35. package/target/main/ts/compose/inspect.js +7 -4
  36. package/target/main/ts/compose/load-plugins.js +4 -2
  37. package/target/main/ts/compose/phases.d.ts +7 -3
  38. package/target/main/ts/compose/phases.js +26 -10
  39. package/target/main/ts/plugins/built-in.d.ts +2 -0
  40. package/target/main/ts/plugins/built-in.js +4 -1
  41. package/target/main/ts/plugins/json-spans.d.ts +11 -0
  42. package/target/main/ts/plugins/json-spans.js +86 -0
  43. package/target/main/ts/plugins/legal/composer-lock.d.ts +2 -0
  44. package/target/main/ts/plugins/legal/composer-lock.js +24 -0
  45. package/target/main/ts/plugins/legal/dependencies.d.ts +73 -0
  46. package/target/main/ts/plugins/legal/dependencies.js +27 -0
  47. package/target/main/ts/plugins/legal/licenses.d.ts +19 -0
  48. package/target/main/ts/plugins/legal/licenses.js +112 -0
  49. package/target/main/ts/plugins/legal/npm-lock.d.ts +3 -0
  50. package/target/main/ts/plugins/legal/npm-lock.js +30 -0
  51. package/target/main/ts/plugins/legal/policy.d.ts +72 -0
  52. package/target/main/ts/plugins/legal/policy.js +149 -0
  53. package/target/main/ts/plugins/legal/sbom.d.ts +3 -0
  54. package/target/main/ts/plugins/legal/sbom.js +131 -0
  55. package/target/main/ts/plugins/legal/unverified-lock.d.ts +1 -0
  56. package/target/main/ts/plugins/legal/unverified-lock.js +21 -0
  57. package/target/main/ts/plugins/security/npm-supply-chain.js +2 -86
  58. package/target/main/ts/report/html/app/viewer-issue-group.js +1 -1
  59. package/target/main/ts/report/html/app/viewer-metric-registry.js +1 -1
  60. package/target/main/ts/report/html/app/viewer-metrics.d.ts +2 -1
  61. package/target/main/ts/report/html/app/viewer-metrics.js +7 -2
  62. package/target/main/ts/report/html/app/viewer-overview-cards.d.ts +1 -0
  63. package/target/main/ts/report/html/app/viewer-overview-cards.js +20 -19
  64. package/target/main/ts/report/html/app/viewer-overview-lead.js +4 -1
  65. package/target/main/ts/report/html/app/viewer-shell.js +3 -1
  66. package/target/main/ts/report/html/app/viewer-tokenizer.js +35 -8
  67. package/target/main/ts/report/html/app/viewer-trend-data.js +1 -0
  68. package/target/main/ts/report/html/app/viewer.js +5 -2
  69. package/target/main/ts/report/json/validation/report.js +2 -2
@@ -22,7 +22,8 @@
22
22
  "enum": [
23
23
  "maintainability",
24
24
  "coverage",
25
- "security"
25
+ "security",
26
+ "legal"
26
27
  ]
27
28
  },
28
29
  "plugin": {
@@ -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", "matchedRule"],
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
  },
@@ -55,12 +55,16 @@
55
55
  </div>
56
56
  <div class="verdict">
57
57
  <span id="coverage-mark" class="mark ring" aria-hidden="true"></span>
58
- <span class="verdict-text"><button type="button" role="tab" class="verdict-tab" data-metric="coverage" aria-controls="trend" aria-describedby="coverage-detail coverage-kinds">Coverage</button><span id="coverage-detail" class="verdict-detail"></span><span id="coverage-kinds" class="verdict-detail verdict-more" hidden></span></span>
58
+ <span class="verdict-text"><button type="button" role="tab" class="verdict-tab" data-metric="coverage" aria-controls="trend" aria-describedby="coverage-detail">Coverage</button><span id="coverage-detail" class="verdict-detail"></span></span>
59
59
  </div>
60
60
  <div class="verdict" id="security-verdict" data-loaded hidden>
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;
@@ -271,9 +271,13 @@ main:focus { outline: none; }
271
271
  .verdict-detail { color: var(--secondary); font-size: .875rem; overflow-wrap: anywhere; }
272
272
  /* The coverage kinds beyond lines: a quieter second line under the headline's detail. */
273
273
  .verdict-more { font-size: .8125rem; color: var(--muted); font-variant-numeric: tabular-nums; }
274
- .verdict-more > span { white-space: nowrap; }
275
274
  /* A detail that counts something leads to exactly what it counts. */
276
275
  .verdict-detail a { position: relative; z-index: 1; color: inherit; text-decoration-color: var(--rule-strong); }
276
+ @container (min-width: 33rem) and (max-width: 49rem) {
277
+ .verdicts { grid-auto-flow: row; grid-template-columns: repeat(2, minmax(0, 1fr)); }
278
+ .verdicts > .verdict:nth-child(odd) { border-left: 0; }
279
+ .verdicts > .verdict:nth-child(n + 3) { border-top: 1px solid var(--rule); }
280
+ }
277
281
  .verdict-detail a:hover { color: var(--accent-strong); text-decoration-color: currentColor; }
278
282
  .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
283
  .grade { background: var(--grade-a); }
@@ -485,7 +489,7 @@ tbody tr:last-child > * { border-bottom: 0; }
485
489
  .overview-aside #overview-sunburst { grid-row: 1 / span 4; }
486
490
  }
487
491
  @media (max-width: 52rem) {
488
- .verdicts { grid-auto-flow: row; }
492
+ .verdicts { grid-auto-flow: row; grid-template-columns: minmax(0, 1fr); }
489
493
  .verdict { border-left: 0; border-top: 1px solid var(--rule); min-height: 4.5rem; }
490
494
  .verdict:first-child { border-top: 0; }
491
495
  .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 > maxClaimedFileBytes);
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
- if ((size ?? (await lstat(absolute)).size) > maxClaimedFileBytes) {
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 > maxClaimedFileBytes) {
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 { isAbsolute, relative, resolve, sep } from 'node:path';
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,2 @@
1
+ import type { ImportedLicenseEvidence, LicenseInput } from '@repometry/core/internal/model/license-evidence.js';
2
+ export declare function readLicenseImports(inputs: readonly LicenseInput[], root: string): Promise<ImportedLicenseEvidence>;
@@ -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
@@ -0,0 +1,8 @@
1
+ import type { Distribution } from '../compose/distribution.js';
2
+ declare const candidates: readonly [readonly ['all', '@repometry/all/internal/distribution'], readonly ['repometry', 'repometry/internal/distribution']];
3
+ export interface CliDistribution {
4
+ readonly name: 'cli' | (typeof candidates)[number][0];
5
+ readonly distribution?: Distribution;
6
+ }
7
+ export declare function installedDistribution(): Promise<CliDistribution>;
8
+ export {};
@@ -0,0 +1,23 @@
1
+ const candidates = [
2
+ ['all', '@repometry/all/internal/distribution'],
3
+ ['repometry', 'repometry/internal/distribution'],
4
+ ];
5
+ export async function installedDistribution() {
6
+ for (const [name, specifier] of candidates) {
7
+ let entry;
8
+ try {
9
+ entry = import.meta.resolve(specifier);
10
+ }
11
+ catch (error) {
12
+ // A distribution may be absent or predate the optional entry point.
13
+ if (error instanceof Error && 'code' in error
14
+ && (error.code === 'ERR_MODULE_NOT_FOUND' || error.code === 'ERR_PACKAGE_PATH_NOT_EXPORTED'))
15
+ continue;
16
+ throw error;
17
+ }
18
+ const { default: distribution } = await import(entry);
19
+ return { name, distribution };
20
+ }
21
+ return { name: 'cli' };
22
+ }
23
+ //# sourceMappingURL=distribution.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,2 +1,2 @@
1
- import type { Distribution } from '../compose/distribution.js';
2
- export declare function runCli(distribution?: Distribution): Promise<void>;
1
+ import type { CliDistribution } from './distribution.js';
2
+ export declare function runCli(explicit?: CliDistribution): Promise<void>;
@@ -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';
@@ -18,6 +19,7 @@ import { LocalObjectStore } from '../report/json/store/object-store.js';
18
19
  import { checkStore } from '../report/json/store/store-check.js';
19
20
  import { dispatch, flag, option } from './arguments.js';
20
21
  import { configFile, listOption, loadConfig, readConfig, readConfigValue, readDisplayConfig } from './config.js';
22
+ import { installedDistribution } from './distribution.js';
21
23
  import { analyzeCommits, isSaved } from './range-jobs.js';
22
24
  import { importerIds, readInputs } from './imports.js';
23
25
  import { displayLanguages, outputReports, reporterIds, viewTarget } from './reporting.js';
@@ -33,7 +35,7 @@ const storageOptions = { repo: repoOption, store: storeOption };
33
35
  const displayOptions = {
34
36
  ...configOptions, branch: option('NAME', 'Name the branch shown in the report.'), title: option('NAME', 'Set the report title.'),
35
37
  };
36
- function commands(distribution) {
38
+ function commands({ distribution, name }) {
37
39
  return {
38
40
  analyze: {
39
41
  description: 'Analyze and save one revision or a range of commits.', parameters: '[REVISION | BASE..[HEAD]]', max: 1,
@@ -84,7 +86,7 @@ function commands(distribution) {
84
86
  const { root, repository } = await repositoryContext(input);
85
87
  const config = await readConfig(root, input, true, distribution);
86
88
  const missingLanguagePlugins = repository === undefined ? [] : await discoverHead(repository, config);
87
- print({ schema: 'urn:repometry:schema:plugin-list:2', plugins: effectivePlugins(config.plugins, config.parsers),
89
+ print({ schema: 'urn:repometry:schema:plugin-list:2', distribution: name, plugins: effectivePlugins(config.plugins, config.parsers),
88
90
  importers: importerIds, reporters: reporterIds, ci: ['github'], stores: ['local', 'git'], missingLanguagePlugins });
89
91
  },
90
92
  },
@@ -150,7 +152,7 @@ async function analyze(input, distribution) {
150
152
  const config = await readConfig(root, input, false, distribution);
151
153
  const revision = input.args[0] ?? 'HEAD';
152
154
  const imports = input.many('import');
153
- const { findings, ...coverage } = imports.length ? readInputs(directory, imports) : readInputs(root, config.imports);
155
+ const { findings, licenseInputs, ...coverage } = imports.length ? readInputs(directory, imports) : readInputs(root, config.imports);
154
156
  const importRoot = input.text('import-root');
155
157
  if (importRoot && findings.length === 0)
156
158
  throw new Error('--import-root requires a scanner report');
@@ -160,7 +162,7 @@ async function analyze(input, distribution) {
160
162
  const report = skipped ? await store.reader.read({ kind: 'commit', id: savedId })
161
163
  : await inspectWithOptions({ directory, output, source: workingTree ? { workingTree: true } : { revision },
162
164
  ...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 });
165
+ licenseInputs, findingInputs: findings, findingRoot: importRoot ? resolve(directory, importRoot) : undefined }, { inventory });
164
166
  announceMissingLanguages(inventory.results());
165
167
  print({ schema: 'urn:repometry:schema:analysis-result:1', ...inspectionSummary(report), ...(skipped ? { skipped: true } : {}),
166
168
  store: output });
@@ -233,7 +235,11 @@ async function review(input, distribution) {
233
235
  const github = useGitHub(input);
234
236
  const config = await readConfig(root, input, false, distribution);
235
237
  const imports = input.many('import');
236
- const { findings, ...coverage } = imports.length ? readInputs(directory, imports) : readInputs(root, config.imports);
238
+ const { findings, licenseInputs = [], ...coverage } = imports.length ? readInputs(directory, imports) : readInputs(root, config.imports);
239
+ if (licenseInputs.length && imports.length)
240
+ throw new Error('review compares both sides of a change; SBOM imports apply to full inspections only');
241
+ if (licenseInputs.length)
242
+ process.stderr.write('SBOM imports from the config are skipped: review compares both sides of a change.\n');
237
243
  if (findings.length && imports.length)
238
244
  throw new Error('review compares both sides of a change; scanner imports apply to full inspections only');
239
245
  if (findings.length)
@@ -286,17 +292,20 @@ function announce(server) {
286
292
  process.stderr.write(`Serving${server.label ? ' ' + server.label : ''} at ${server.url}\n`);
287
293
  }
288
294
  function inspectionSummary(report) {
295
+ const legal = legalSummary(report);
289
296
  return { subject: report.subject, generatedAt: report.generatedAt, status: report.status, scope: report.scope,
290
- measurements: report.measurements.length, diagnostics: report.diagnostics.length };
297
+ measurements: report.measurements.length, diagnostics: report.diagnostics.length, ...(legal === undefined ? {} : { legal }) };
291
298
  }
292
299
  function print(value) {
293
300
  process.stdout.write(JSON.stringify(value, null, 2) + '\n');
294
301
  }
295
- export async function runCli(distribution) {
302
+ export async function runCli(explicit) {
296
303
  try {
304
+ const selection = explicit ?? await installedDistribution();
305
+ const { distribution, name } = selection;
297
306
  const packageUrl = new URL(distribution?.packageUrl ?? '../../../../package.json', import.meta.url);
298
307
  const manifest = JSON.parse(await readFile(packageUrl, 'utf8'));
299
- process.exitCode = await dispatch(commands(distribution), process.argv.slice(2), manifest.version);
308
+ process.exitCode = await dispatch(commands(selection), process.argv.slice(2), `${manifest.version} ${name}`);
300
309
  }
301
310
  catch (error) {
302
311
  process.stderr.write(`repometry: ${error instanceof Error ? error.message : String(error)}\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
- for (const finding of stored.findings)
58
- this.findings.push(finding);
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
- return { operation: 'source/claims', state: 'partial', path, message: 'Plugin inspection skipped a file larger than 1 MiB' };
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>;