cve-lite-cli 1.34.0 → 1.36.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 (42) hide show
  1. package/README.md +34 -0
  2. package/dist/cli/advisories-init.js +13 -0
  3. package/dist/cli/advisories-sync.js +30 -0
  4. package/dist/cli/config-command.js +15 -0
  5. package/dist/cli/config.js +29 -0
  6. package/dist/cli/help.js +4 -4
  7. package/dist/cli/overrides.js +10 -1
  8. package/dist/constants.js +52 -0
  9. package/dist/index.js +25 -719
  10. package/dist/osv/cache.js +19 -12
  11. package/dist/output/cyclonedx.js +12 -0
  12. package/dist/output/html-reporter.js +73 -38
  13. package/dist/output/multi-folder-html-reporter.js +16 -10
  14. package/dist/output/multi-folder-printer.js +1 -1
  15. package/dist/output/override-findings-sarif.js +1 -0
  16. package/dist/output/printers.js +460 -288
  17. package/dist/output/sarif.js +17 -1
  18. package/dist/output/sbom-dependency-edges.js +29 -19
  19. package/dist/overrides/admitted-scan.js +158 -0
  20. package/dist/overrides/api.js +16 -0
  21. package/dist/overrides/context-builder.js +4 -0
  22. package/dist/overrides/context.js +8 -1
  23. package/dist/overrides/detectors/index.js +2 -0
  24. package/dist/overrides/detectors/oa010-vulnerable-floor.js +123 -0
  25. package/dist/overrides/parsing/registry.js +53 -0
  26. package/dist/parsers/bun-lock-graph.js +182 -0
  27. package/dist/parsers/bun-lock.js +93 -132
  28. package/dist/parsers/index.js +132 -147
  29. package/dist/parsers/multi-package.js +5 -6
  30. package/dist/parsers/pnpm-lock-graph.js +94 -0
  31. package/dist/parsers/pnpm-lock.js +5 -5
  32. package/dist/parsers/yarn-lock-graph.js +148 -0
  33. package/dist/parsers/yarn-lock.js +3 -3
  34. package/dist/remediation/fix-commands.js +76 -20
  35. package/dist/scan/completeness.js +1 -1
  36. package/dist/scan/single-scan.js +643 -0
  37. package/dist/scanner.js +29 -8
  38. package/dist/utils/file.js +11 -14
  39. package/dist/utils/network.js +4 -0
  40. package/dist/utils/version.js +10 -0
  41. package/package.json +2 -1
  42. package/scripts/pr-scan-delta.mjs +315 -0
package/dist/scanner.js CHANGED
@@ -24,6 +24,12 @@ import { pluralize } from "./utils/string.js";
24
24
  import { extractErrorMessage } from "./utils/network.js";
25
25
  import { logWarn } from "./output/formatters.js";
26
26
  import { formatDiagnosticMessage } from "./scan/completeness.js";
27
+ /**
28
+ * Advisory id namespaces OSV does not serve. Ids with these prefixes come from
29
+ * a different source, so OSV failing to resolve them is expected and must not
30
+ * be reported as missing detail.
31
+ */
32
+ const OSV_FOREIGN_ID_PREFIXES = ["NPM-"];
27
33
  export function createAdvisorySource(options) {
28
34
  const offline = !!options?.offline || !!options?.offlineDb;
29
35
  if (offline) {
@@ -197,9 +203,17 @@ export async function scanPackages(packages, batchSize, options, context, debugL
197
203
  const key = getPackageCacheKey(pkg);
198
204
  const cached = cache.npmAdvisoryEntries[key];
199
205
  if (cached && !isEntryStale(cached, nowMs)) {
200
- const newCachedVulnIds = cached.vulnIds.filter(id => !existingVulnIds.has(id));
201
- if (newCachedVulnIds.length > 0) {
202
- results.push({ pkg, vulnIds: newCachedVulnIds });
206
+ const newCachedVulns = cached.vulns.filter(v => !existingVulnIds.has(v.id));
207
+ if (newCachedVulns.length > 0) {
208
+ results.push({ pkg, vulnIds: newCachedVulns.map(v => v.id) });
209
+ // Seed the detail map from the cache. These advisories come from the npm
210
+ // registry namespace, so nothing downstream can resolve them: OSV returns
211
+ // 404 for an NPM-prefixed id by definition. Restoring only the ids left
212
+ // them unresolvable, which dropped them from the CVE tally on every scan
213
+ // after the first and reported them as detail confirmed missing.
214
+ for (const vuln of newCachedVulns) {
215
+ vulnMap.set(vuln.id, vuln);
216
+ }
203
217
  }
204
218
  }
205
219
  else {
@@ -215,10 +229,11 @@ export async function scanPackages(packages, batchSize, options, context, debugL
215
229
  for (const pkg of uncachedForNpm) {
216
230
  const found = npmResults.find(r => r.pkg.name === pkg.name && r.pkg.version === pkg.version);
217
231
  const vulns = found?.vulns ?? [];
218
- const vulnIds = vulns.map(v => v.id);
219
- // Store the full list in cache (for cache correctness on future scans),
220
- // but only add genuinely new vulns to results - ones OSV did not already surface
221
- cache.npmAdvisoryEntries[getPackageCacheKey(pkg)] = { vulnIds, cachedAt };
232
+ // Store the full advisories in cache, not just their ids, so a later scan
233
+ // can restore the detail rather than going looking for it in OSV, which
234
+ // does not hold this namespace. Only genuinely new vulns go into results -
235
+ // ones OSV did not already surface.
236
+ cache.npmAdvisoryEntries[getPackageCacheKey(pkg)] = { vulns, cachedAt };
222
237
  const newVulns = vulns.filter(v => !existingVulnIds.has(v.id));
223
238
  const newVulnIds = newVulns.map(v => v.id);
224
239
  if (newVulns.length > 0) {
@@ -238,7 +253,13 @@ export async function scanPackages(packages, batchSize, options, context, debugL
238
253
  const offlineMissingDetailIds = new Set();
239
254
  const confirmedMissingDetailIds = new Set();
240
255
  if (idSet.size > 0 && !offline) {
241
- const ids = [...idSet];
256
+ // Only ask OSV for ids OSV can own. The npm registry advisory source
257
+ // (#1056) contributes NPM-prefixed ids from its own namespace, and
258
+ // api.osv.dev/v1/vulns/NPM-... is a 404 by definition. Sending them
259
+ // anyway made every online scan of a project carrying npm-sourced
260
+ // advisories report `partial` with "findings may be incomplete", when
261
+ // nothing was missing: the detail was looked for in the wrong database.
262
+ const ids = [...idSet].filter((id) => !OSV_FOREIGN_ID_PREFIXES.some((prefix) => id.startsWith(prefix)));
242
263
  const detailSpinner = createSpinner("Fetching vulnerability details...", options);
243
264
  try {
244
265
  const nowMs = Date.now();
@@ -1,6 +1,6 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
- import { EXCLUDED_DIRS } from "../constants.js";
3
+ import { EXCLUDED_DIRS, LOCKFILE_PRIORITY_NESTED } from "../constants.js";
4
4
  export function safeReadText(filePath) {
5
5
  try {
6
6
  return fs.readFileSync(filePath, "utf8");
@@ -59,18 +59,15 @@ export function chooseBestLockfile(candidates) {
59
59
  const bDepth = b.split(path.sep).length;
60
60
  if (aDepth !== bDepth)
61
61
  return aDepth - bDepth;
62
- const score = (file) => {
63
- const name = path.basename(file);
64
- if (name === "package-lock.json")
65
- return 0;
66
- if (name === "pnpm-lock.yaml")
67
- return 1;
68
- if (name === "yarn.lock")
69
- return 2;
70
- if (name === "bun.lock")
71
- return 3;
72
- return 4;
73
- };
74
- return score(a) - score(b);
62
+ return lockfileRank(a) - lockfileRank(b);
75
63
  })[0];
76
64
  }
65
+ /**
66
+ * Position in LOCKFILE_PRIORITY_NESTED, with anything unrecognised sorting last.
67
+ * Shared with root detection so both paths agree on precedence.
68
+ */
69
+ function lockfileRank(filePath) {
70
+ const name = path.basename(filePath);
71
+ const index = LOCKFILE_PRIORITY_NESTED.findIndex(candidate => candidate === name);
72
+ return index === -1 ? LOCKFILE_PRIORITY_NESTED.length : index;
73
+ }
@@ -152,6 +152,10 @@ export function getNetworkErrorHint(error, errorMessage) {
152
152
  return serverAdvisoryRequestHint();
153
153
  if (isLikelyBlockedAdvisoryRequestError(errorMessage))
154
154
  return blockedAdvisoryRequestHint();
155
+ // Local read/parse failures are stamped with this prefix by readInput() in
156
+ // src/parsers/index.ts. They are not network failures, so no CA hint.
157
+ if (errorMessage.startsWith("Failed to read "))
158
+ return [];
155
159
  return fetchErrorCaCertHint();
156
160
  }
157
161
  export function createCertAwareFetch(caCertPath) {
@@ -199,6 +199,16 @@ export function satisfiesRange(version, range) {
199
199
  if (!v)
200
200
  return false;
201
201
  const trimmedRange = range.trim();
202
+ // Compound range: space-separated comparators are ANDed, so `>=5.7.0 <6`
203
+ // means both. Operators may carry a space before their operand (`>= 5.7.0`),
204
+ // so glue those back on before splitting. Without this the first comparator
205
+ // won and every ceiling was silently discarded, which made `>=5.7.0 <6`
206
+ // accept 99.0.0.
207
+ const glued = trimmedRange.replace(/([<>]=?|=|\^|~)\s+/g, "$1");
208
+ if (/\s/.test(glued)) {
209
+ const parts = glued.split(/\s+/).filter(Boolean);
210
+ return parts.every((part) => satisfiesRange(version, part));
211
+ }
202
212
  // Exact match (no operator)
203
213
  if (/^\d/.test(trimmedRange)) {
204
214
  return compareVersions(v, coerceVersion(trimmedRange) ?? "") === 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cve-lite-cli",
3
- "version": "1.34.0",
3
+ "version": "1.36.0",
4
4
  "description": "Developer-friendly CLI for scanning JS/TS projects for dependency vulnerabilities using local lockfiles and OSV",
5
5
  "type": "module",
6
6
  "bin": {
@@ -59,6 +59,7 @@
59
59
  "homepage": "https://github.com/OWASP/cve-lite-cli#readme",
60
60
  "files": [
61
61
  "dist",
62
+ "scripts/pr-scan-delta.mjs",
62
63
  "README.md",
63
64
  "LICENSE",
64
65
  "assets/logo-with-title-removebg-preview.png",
@@ -0,0 +1,315 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Turn two scan JSON files (base and head of a PR) into a PR comment describing
4
+ * only what THIS PR changed.
5
+ *
6
+ * The scoping is the whole point. A comment that republishes every pre-existing
7
+ * finding on an unrelated PR is the reason people disable tools like this, so
8
+ * this reports the delta and stays silent when the finding set did not move.
9
+ *
10
+ * node scripts/pr-scan-delta.mjs base.json head.json
11
+ *
12
+ * Prints the comment body, or nothing at all when there is no delta.
13
+ */
14
+
15
+ const MARKER = "<!-- cve-lite-cli:pr-delta -->";
16
+
17
+ /**
18
+ * The wordmark on its own line, linked to the repository.
19
+ *
20
+ * Inline it cannot win: at a legible width the image is taller than the line
21
+ * box, so it either overhangs or has to shrink to about 24px. On its own line
22
+ * there is nothing to align against.
23
+ *
24
+ * The link is not decoration. Without an explicit href GitHub wraps the image
25
+ * in a link to the raw PNG, so clicking the logo opens a 217KB file, which is
26
+ * worse than no link at all.
27
+ */
28
+ const LOGO_URL =
29
+ "https://raw.githubusercontent.com/OWASP/cve-lite-cli/main/assets/logo-with-title-transparent.png";
30
+ const PROJECT_URL = "https://github.com/OWASP/cve-lite-cli";
31
+ const TITLE =
32
+ `<a href="${PROJECT_URL}"><img src="${LOGO_URL}" width="120" alt="CVE Lite CLI"></a>`;
33
+
34
+ /**
35
+ * Collapsed by default, so it costs one line until someone opens it. The badge
36
+ * is fenced rather than inlined: an inline badge renders as an image, and the
37
+ * point is to give people something they can copy into a README.
38
+ */
39
+ const SHARE = [
40
+ "<details>",
41
+ "<summary>\u2764\ufe0f Share</summary>",
42
+ "",
43
+ "If this caught something before it merged, a mention helps other maintainers find it.",
44
+ "",
45
+ `- [Post on X](https://twitter.com/intent/tweet?text=CVE%20Lite%20CLI%20caught%20a%20vulnerable%20transitive%20dependency%20in%20my%20PR%20before%20it%20merged.&url=${PROJECT_URL})`,
46
+ `- [Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=${PROJECT_URL})`,
47
+ "- Add the badge to your README:",
48
+ "",
49
+ " ```markdown",
50
+ ` [![Protected by CVE Lite CLI](https://img.shields.io/badge/Protected_by-CVE_Lite_CLI-brightgreen)](${PROJECT_URL})`,
51
+ " ```",
52
+ "",
53
+ "</details>",
54
+ ];
55
+
56
+ const SEVERITY_RANK = { critical: 4, high: 3, medium: 2, low: 1, unknown: 0, none: 0 };
57
+
58
+ /**
59
+ * Every string in the comment originates in a lockfile the PR author controls,
60
+ * and with fork PRs supported that author is untrusted. GitHub strips raw HTML
61
+ * in comments so this is not an XSS surface, but a crafted package name can
62
+ * still inject links, headings, or prose that reads as if a maintainer wrote it.
63
+ *
64
+ * Allowlist rather than escape: these fields have known, narrow shapes, so
65
+ * anything outside them is dropped rather than encoded. npm names allow
66
+ * `@scope/name`, semver allows dots, hyphens and plus, advisory ids are
67
+ * alphanumeric with separators.
68
+ */
69
+ const SAFE_CHARS = /[^A-Za-z0-9._@/+-]/g;
70
+ const MAX_FIELD = 120;
71
+
72
+ /**
73
+ * Commands are rendered inside a fenced block, so spaces must survive while
74
+ * anything that could close the fence or start a new directive must not.
75
+ */
76
+ function safeCommand(value) {
77
+ const raw = String(value ?? "");
78
+ return raw.replace(/[^A-Za-z0-9._@/+ -]/g, "").trim().slice(0, 200);
79
+ }
80
+
81
+ /**
82
+ * Post a command only when sanitising it changes nothing.
83
+ *
84
+ * safeCommand's allowlist is a trust boundary, not cosmetics: stage 1 built this
85
+ * JSON on a machine the PR author controls (see pr-delta-scan.yml), so the string
86
+ * is attacker-influenced. But the allowlist also rewrites legitimate commands. It
87
+ * excludes `&`, and runnableFixCommand genuinely contains `&&` because
88
+ * fix-commands.ts chains with " && " in three places, so a real
89
+ * `pnpm add a@1 && pnpm add -D b@2` was being posted as
90
+ * `pnpm add a@1 pnpm add -D b@2`, which does not work.
91
+ *
92
+ * Rather than loosen the boundary or rebuild the command here (a second
93
+ * implementation of the CLI's own logic, which is what mergeCommands was and why
94
+ * it corrupted pnpm workspace filters), only show commands that survive
95
+ * sanitisation byte for byte. Anything else degrades to no command, which is
96
+ * honest, rather than a wrong one, which is not.
97
+ *
98
+ * Returns the command, or null when one exists but cannot be shown safely, or
99
+ * undefined when the finding carries none (#1172).
100
+ */
101
+ function acceptCommand(value) {
102
+ if (!value) return undefined;
103
+ const raw = String(value);
104
+ return safeCommand(raw) === raw ? raw : null;
105
+ }
106
+
107
+ function safe(value) {
108
+ const raw = String(value ?? "");
109
+ const cleaned = raw.replace(SAFE_CHARS, "").slice(0, MAX_FIELD);
110
+ return cleaned.length > 0 ? cleaned : "(unnamed)";
111
+ }
112
+
113
+ function findingsOf(scan) {
114
+ if (!scan || typeof scan !== "object") return [];
115
+ return Array.isArray(scan.findings) ? scan.findings : [];
116
+ }
117
+
118
+ /**
119
+ * One row per (package, version), carrying every advisory id on it. A single
120
+ * finding routinely covers several ids (js-yaml 3.15.1 carries both
121
+ * GHSA-2883-xcg3-v3hh and NPM-1193726) and listing them as separate rows reads
122
+ * as two problems rather than one.
123
+ */
124
+ function index(scan) {
125
+ const rows = new Map();
126
+ for (const f of findingsOf(scan)) {
127
+ const pkg = f.package ?? f.pkg?.name;
128
+ const version = f.version ?? f.pkg?.version;
129
+ if (!pkg || !version) continue;
130
+
131
+ const key = `${pkg}@${version}`;
132
+ const row = rows.get(key) ?? {
133
+ package: safe(pkg),
134
+ version: safe(version),
135
+ severity: safe(f.severity ?? "unknown"),
136
+ relationship: safe(f.relationship ?? ""),
137
+ fixVersion: f.validatedFirstFixedVersion ?? f.firstFixedVersion
138
+ ? safe(f.validatedFirstFixedVersion ?? f.firstFixedVersion)
139
+ : undefined,
140
+ advisories: [],
141
+ cves: [],
142
+ fixCommand: acceptCommand(f.runnableFixCommand),
143
+ };
144
+ for (const v of f.vulnerabilities ?? []) {
145
+ if (v?.id && !row.advisories.includes(safe(v.id))) row.advisories.push(safe(v.id));
146
+ }
147
+ // Advisories whose detail could not be fetched still count as findings, and
148
+ // dropping them silently would understate the delta.
149
+ for (const id of f.unresolvedAdvisoryIds ?? []) {
150
+ if (id && !row.advisories.includes(safe(id))) row.advisories.push(safe(id));
151
+ }
152
+ // A CVE number is what a reader recognises; the GHSA id is what we key on.
153
+ for (const c of f.cves ?? []) {
154
+ if (c && !row.cves.includes(safe(c))) row.cves.push(safe(c));
155
+ }
156
+ rows.set(key, row);
157
+ }
158
+ return rows;
159
+ }
160
+
161
+ export function buildDelta(baseScan, headScan) {
162
+ const base = index(baseScan);
163
+ const head = index(headScan);
164
+
165
+ const bySeverity = (a, b) =>
166
+ (SEVERITY_RANK[b.severity] ?? 0) - (SEVERITY_RANK[a.severity] ?? 0) ||
167
+ a.package.localeCompare(b.package);
168
+
169
+ const introduced = [...head.entries()]
170
+ .filter(([k]) => !base.has(k))
171
+ .map(([, v]) => v)
172
+ .sort(bySeverity);
173
+ const resolved = [...base.entries()]
174
+ .filter(([k]) => !head.has(k))
175
+ .map(([, v]) => v)
176
+ .sort(bySeverity);
177
+
178
+ return { introduced, resolved, hasChanges: introduced.length > 0 || resolved.length > 0 };
179
+ }
180
+
181
+ /**
182
+ * "1 new high finding" when they are all one severity, otherwise
183
+ * "6 new findings (2 critical, 4 high)". Naming only the worst severity across
184
+ * a mixed set reads as though every finding were that severe, which is a
185
+ * material overstatement on a security comment.
186
+ */
187
+ function countPhrase(rows, { adjective } = {}) {
188
+ const n = rows.length;
189
+ const counts = new Map();
190
+ for (const r of rows) counts.set(r.severity, (counts.get(r.severity) ?? 0) + 1);
191
+
192
+ const parts = [String(n)];
193
+ if (adjective) parts.push(adjective);
194
+
195
+ if (counts.size === 1) {
196
+ const only = [...counts.keys()][0];
197
+ if (only !== "unknown") parts.push(only);
198
+ parts.push(`finding${n === 1 ? "" : "s"}`);
199
+ return parts.join(" ");
200
+ }
201
+
202
+ parts.push(`finding${n === 1 ? "" : "s"}`);
203
+ const breakdown = [...counts.entries()]
204
+ .sort((a, b) => (SEVERITY_RANK[b[0]] ?? 0) - (SEVERITY_RANK[a[0]] ?? 0))
205
+ .map(([sev, c]) => `${c} ${sev}`)
206
+ .join(", ");
207
+ return `${parts.join(" ")} (${breakdown})`;
208
+ }
209
+
210
+ /**
211
+ * "GHSA-xxx (CVE-2026-84375)", capped. A single package can carry dozens of
212
+ * advisories (tar@6.1.0 has 36), and listing them all produces a line nobody
213
+ * can read. CVEs are shown in preference to GHSA ids because they are what a
214
+ * reviewer recognises.
215
+ */
216
+ const MAX_IDS = 3;
217
+
218
+ function advisoryLabel(r) {
219
+ const cves = r.cves ?? [];
220
+ const primary = cves.length > 0 ? cves : r.advisories;
221
+ const shown = primary.slice(0, MAX_IDS).join(", ");
222
+ const hidden = primary.length - Math.min(primary.length, MAX_IDS);
223
+ return hidden > 0 ? `${shown} and ${hidden} more` : shown;
224
+ }
225
+
226
+
227
+ export function renderComment(delta) {
228
+ if (!delta.hasChanges) return null;
229
+
230
+ const lines = [MARKER, ""];
231
+ const { introduced, resolved } = delta;
232
+
233
+ if (introduced.length > 0) {
234
+ lines.push(TITLE);
235
+ lines.push("");
236
+ lines.push(`${countPhrase(introduced, { adjective: "new" })} introduced by this PR`);
237
+ lines.push("");
238
+ for (const r of introduced) {
239
+ const via = r.relationship === "transitive" ? " (transitive)" : "";
240
+ lines.push(`- \`${r.package}@${r.version}\`${via} · ${advisoryLabel(r)} · **${r.severity}**`);
241
+ if (r.fixVersion) lines.push(` Fixed in \`${r.fixVersion}\``);
242
+ }
243
+ // Verbatim and complete, or nothing. A partial set reads as the whole fix,
244
+ // and the CLI has already merged these into its plan, so re-merging them here
245
+ // is what corrupted pnpm workspace filters (#1172).
246
+ const raw = introduced.map((r) => r.fixCommand).filter((c) => c !== undefined);
247
+ const withheld = raw.some((c) => c === null);
248
+ const commands = [...new Set(raw.filter(Boolean))];
249
+ if (!withheld && commands.length > 0) {
250
+ lines.push("");
251
+ lines.push("```bash");
252
+ lines.push(...commands);
253
+ lines.push("```");
254
+ } else if (withheld) {
255
+ lines.push("");
256
+ lines.push("Run `cve-lite .` for the fix commands.");
257
+ }
258
+
259
+ if (resolved.length > 0) {
260
+ lines.push("");
261
+ lines.push(`Also resolves ${resolved.length} existing finding${resolved.length === 1 ? "" : "s"}.`);
262
+ }
263
+ } else {
264
+ lines.push(TITLE);
265
+ lines.push("");
266
+ lines.push(`${countPhrase(resolved)} resolved by this PR`);
267
+ lines.push("");
268
+ for (const r of resolved) {
269
+ lines.push(`- \`${r.package}@${r.version}\` · ${advisoryLabel(r)}`);
270
+ }
271
+ }
272
+
273
+ lines.push("");
274
+ lines.push("<sub>Only findings this PR changed are listed. Nothing is posted when the set is unchanged.</sub>");
275
+ lines.push("");
276
+ lines.push(
277
+ `<sub>Scanned by <a href="${PROJECT_URL}">CVE Lite CLI</a>, a free and open source OWASP project.</sub>`,
278
+ );
279
+ lines.push("");
280
+ lines.push(...SHARE);
281
+ return lines.join("\n");
282
+ }
283
+
284
+ export { MARKER };
285
+
286
+ // CLI entrypoint. Kept side-effect free on import so the tests can call the
287
+ // functions directly.
288
+ if (process.argv[1] && import.meta.url.endsWith(process.argv[1].split("/").pop())) {
289
+ const [basePath, headPath] = process.argv.slice(2);
290
+ if (!basePath || !headPath) {
291
+ console.error("usage: pr-scan-delta.mjs <base.json> <head.json>");
292
+ process.exit(2);
293
+ }
294
+ const { readFileSync } = await import("node:fs");
295
+ // Fail loudly. Treating an unreadable scan as "no findings" would print
296
+ // nothing, which is indistinguishable from "this PR changed nothing" and
297
+ // would quietly stop the check from ever reporting.
298
+ const read = (p) => {
299
+ let raw;
300
+ try {
301
+ raw = readFileSync(p, "utf8");
302
+ } catch (err) {
303
+ console.error(`pr-scan-delta: cannot read ${p}: ${err.message}`);
304
+ process.exit(1);
305
+ }
306
+ try {
307
+ return JSON.parse(raw);
308
+ } catch (err) {
309
+ console.error(`pr-scan-delta: ${p} is not valid JSON: ${err.message}`);
310
+ process.exit(1);
311
+ }
312
+ };
313
+ const body = renderComment(buildDelta(read(basePath), read(headPath)));
314
+ if (body) console.log(body);
315
+ }