cve-lite-cli 1.28.0 → 1.30.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 +30 -4
- package/dist/advisory/osv-advisory-source.js +3 -0
- package/dist/cli/help.js +3 -2
- package/dist/cli/validate.js +6 -0
- package/dist/constants.js +1 -0
- package/dist/index.js +50 -7
- package/dist/maintenance/dm001-maintenance-risk.js +74 -15
- package/dist/maintenance/score.js +51 -0
- package/dist/output/formatters.js +21 -8
- package/dist/output/html-reporter.js +133 -12
- package/dist/output/maintenance-findings-html.js +4 -0
- package/dist/output/maintenance-findings-sarif.js +58 -0
- package/dist/output/maintenance-terminal.js +63 -5
- package/dist/output/multi-folder-html-reporter.js +64 -7
- package/dist/output/multi-folder-printer.js +11 -2
- package/dist/output/override-findings-html.js +6 -5
- package/dist/output/override-findings-terminal.js +2 -1
- package/dist/output/printers.js +92 -30
- package/dist/output/sarif.js +23 -7
- package/dist/output/write-outputs.js +4 -1
- package/dist/overrides/detectors/oa001-orphaned-target.js +2 -1
- package/dist/overrides/detectors/oa002-floating-tag.js +2 -1
- package/dist/overrides/detectors/oa003-wrong-section.js +2 -1
- package/dist/overrides/detectors/oa004-surpassed-pin.js +2 -1
- package/dist/overrides/detectors/oa005-nested-ineffective.js +2 -1
- package/dist/overrides/detectors/oa006-coupled-platform-binary.js +2 -1
- package/dist/overrides/detectors/oa007-frozen-latest.js +2 -1
- package/dist/overrides/detectors/oa009-stale-floor.js +2 -1
- package/dist/parsers/bun-lock.js +47 -7
- package/dist/parsers/npm-lock-graph.js +90 -12
- package/dist/parsers/pnpm-lock.js +60 -10
- package/dist/parsers/utils.js +0 -15
- package/dist/parsers/yarn-lock.js +140 -58
- package/dist/remediation/fix-commands.js +43 -12
- package/dist/remediation/npm-registry.js +69 -52
- package/dist/remediation/npm-transitive-resolution.js +5 -6
- package/dist/remediation/package-path-lookup.js +29 -0
- package/dist/remediation/parent-upgrade.js +2 -22
- package/dist/scan/completeness.js +49 -0
- package/dist/scan/multi-folder-scan.js +183 -15
- package/dist/scanner.js +210 -155
- package/dist/usage/scanner.js +12 -2
- package/dist/utils/finding.js +28 -0
- package/dist/utils/fix-runner.js +87 -50
- package/dist/utils/version.js +13 -4
- package/dist/utils/vuln.js +16 -0
- package/package.json +3 -3
|
@@ -174,7 +174,6 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
174
174
|
package: finding.recommendedNpmTransitiveRemediation.package,
|
|
175
175
|
currentVersion: finding.recommendedNpmTransitiveRemediation.currentVersion,
|
|
176
176
|
targetVersion: finding.recommendedNpmTransitiveRemediation.targetChildVersion,
|
|
177
|
-
displayTargetVersion: "npm install",
|
|
178
177
|
scannedVersions: null,
|
|
179
178
|
knownVulnerableVersions: null,
|
|
180
179
|
kind: "parent-update",
|
|
@@ -198,6 +197,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
198
197
|
const chainForNpmRemediation = finding.chainResolution?.directDep === finding.recommendedNpmTransitiveRemediation.package
|
|
199
198
|
? finding.chainResolution
|
|
200
199
|
: null;
|
|
200
|
+
const npmParentUpgradeWorkspaces = workspaceMap.get(finding.recommendedNpmTransitiveRemediation.package)?.filter(w => w !== ".") ?? [];
|
|
201
201
|
upsertTarget(targetsByPackage, {
|
|
202
202
|
package: finding.recommendedNpmTransitiveRemediation.package,
|
|
203
203
|
currentVersion: finding.recommendedNpmTransitiveRemediation.currentVersion,
|
|
@@ -215,6 +215,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
215
215
|
remainingPaths: coverage.remainingPaths,
|
|
216
216
|
usage: finding.usage ?? null,
|
|
217
217
|
isDev: devLookup.get(`${finding.recommendedNpmTransitiveRemediation.package}@${finding.recommendedNpmTransitiveRemediation.currentVersion}`) ?? false,
|
|
218
|
+
workspaces: npmParentUpgradeWorkspaces.length > 0 ? npmParentUpgradeWorkspaces : undefined,
|
|
218
219
|
chainProof: chainForNpmRemediation?.chain,
|
|
219
220
|
chainSafeVersion: chainForNpmRemediation?.safeVersion,
|
|
220
221
|
chainVulnerablePackage: chainForNpmRemediation ? finding.pkg.name : undefined,
|
|
@@ -228,6 +229,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
228
229
|
const chainForParentUpgrade = finding.chainResolution?.directDep === finding.recommendedParentUpgrade.package
|
|
229
230
|
? finding.chainResolution
|
|
230
231
|
: null;
|
|
232
|
+
const parentUpgradeWorkspaces = workspaceMap.get(finding.recommendedParentUpgrade.package)?.filter(w => w !== ".") ?? [];
|
|
231
233
|
upsertTarget(targetsByPackage, {
|
|
232
234
|
package: finding.recommendedParentUpgrade.package,
|
|
233
235
|
currentVersion: finding.recommendedParentUpgrade.currentVersion,
|
|
@@ -245,6 +247,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
245
247
|
remainingPaths: coverage.remainingPaths,
|
|
246
248
|
usage: finding.usage ?? null,
|
|
247
249
|
isDev: devLookup.get(`${finding.recommendedParentUpgrade.package}@${finding.recommendedParentUpgrade.currentVersion}`) ?? false,
|
|
250
|
+
workspaces: parentUpgradeWorkspaces.length > 0 ? parentUpgradeWorkspaces : undefined,
|
|
248
251
|
chainProof: chainForParentUpgrade?.chain,
|
|
249
252
|
chainSafeVersion: chainForParentUpgrade?.safeVersion,
|
|
250
253
|
chainVulnerablePackage: chainForParentUpgrade ? finding.pkg.name : undefined,
|
|
@@ -291,6 +294,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
291
294
|
if (finding.chainResolution) {
|
|
292
295
|
const isDev = devLookup.get(`${finding.chainResolution.directDep}@${finding.chainResolution.directDepCurrentVersion}`) ?? false;
|
|
293
296
|
const coverage = calculatePathCoverage(finding.dependencyPaths, [finding.chainResolution.directDep]);
|
|
297
|
+
const chainWorkspaces = workspaceMap.get(finding.chainResolution.directDep)?.filter(w => w !== ".") ?? [];
|
|
294
298
|
upsertTarget(targetsByPackage, {
|
|
295
299
|
package: finding.chainResolution.directDep,
|
|
296
300
|
currentVersion: finding.chainResolution.directDepCurrentVersion,
|
|
@@ -307,6 +311,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
307
311
|
chainVulnerablePackage: finding.pkg.name,
|
|
308
312
|
usage: finding.usage ?? null,
|
|
309
313
|
isDev,
|
|
314
|
+
workspaces: chainWorkspaces.length > 0 ? chainWorkspaces : undefined,
|
|
310
315
|
});
|
|
311
316
|
continue;
|
|
312
317
|
}
|
|
@@ -344,6 +349,17 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
344
349
|
return kindDelta;
|
|
345
350
|
return a.package.localeCompare(b.package);
|
|
346
351
|
});
|
|
352
|
+
// Some install targets carry an explicit `command` built without workspace
|
|
353
|
+
// context (e.g. a chain-resolution command). This raw field is exposed in JSON
|
|
354
|
+
// and embedded in the HTML report, so scope it to the declaring member too -
|
|
355
|
+
// parent-update commands are already workspace-aware and left untouched.
|
|
356
|
+
for (const target of targets) {
|
|
357
|
+
if (target.kind !== "parent-update" && target.command && target.workspaces?.length) {
|
|
358
|
+
const scoped = buildWorkspaceInstallCommands([target], packageManager);
|
|
359
|
+
if (scoped.length > 0)
|
|
360
|
+
target.command = scoped.join(" && ");
|
|
361
|
+
}
|
|
362
|
+
}
|
|
347
363
|
const nowMs = options?.nowMs ?? Date.now();
|
|
348
364
|
if (scanInput.filePath && (packageManager === "npm" || packageManager === "pnpm" || packageManager === "yarn")) {
|
|
349
365
|
const cooldown = readConfiguredCooldown(path.dirname(scanInput.filePath), packageManager);
|
|
@@ -422,7 +438,7 @@ function buildPnpmLockfileRefreshCommand(pkg, workspaces) {
|
|
|
422
438
|
if (workspace === ".") {
|
|
423
439
|
return `pnpm update --no-save ${pkg}`;
|
|
424
440
|
}
|
|
425
|
-
return `pnpm
|
|
441
|
+
return `pnpm --filter ./${workspace} update --no-save ${pkg}`;
|
|
426
442
|
}
|
|
427
443
|
export function commandPrefix(packageManager) {
|
|
428
444
|
if (packageManager === "npm")
|
|
@@ -462,19 +478,32 @@ export function findFixTargetForFinding(plan, finding) {
|
|
|
462
478
|
});
|
|
463
479
|
return target ?? null;
|
|
464
480
|
}
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
481
|
+
// The single command that applies (or refreshes) one fix target, workspace-scoped
|
|
482
|
+
// where the target declares a member. Shared by the displayed per-finding command
|
|
483
|
+
// and the --fix executor so both stay consistent.
|
|
484
|
+
export function buildTargetCommand(target, packageManager) {
|
|
485
|
+
// parent-update targets carry an explicit command that is already
|
|
486
|
+
// workspace-scoped (npm update --workspace / pnpm --filter ... update).
|
|
487
|
+
if (target.kind === "parent-update" && target.command)
|
|
470
488
|
return target.command;
|
|
489
|
+
// For install targets (direct / parent-upgrade), a workspace membership must
|
|
490
|
+
// win over any flat explicit command (e.g. a chain-resolution command built
|
|
491
|
+
// without workspace context), mirroring the plan-level command builder.
|
|
471
492
|
if (target.workspaces?.length) {
|
|
472
|
-
const commands = buildWorkspaceInstallCommands([target],
|
|
493
|
+
const commands = buildWorkspaceInstallCommands([target], packageManager);
|
|
473
494
|
if (commands.length > 0)
|
|
474
495
|
return commands.join(" && ");
|
|
475
496
|
}
|
|
476
|
-
|
|
477
|
-
|
|
497
|
+
if (target.command)
|
|
498
|
+
return target.command;
|
|
499
|
+
const flag = target.isDev ? ` ${devFlag(packageManager)}` : "";
|
|
500
|
+
return `${commandPrefix(packageManager)}${flag} ${target.package}@${target.targetVersion}`;
|
|
501
|
+
}
|
|
502
|
+
export function findSuggestedCommandForFinding(plan, finding) {
|
|
503
|
+
const target = findFixTargetForFinding(plan, finding);
|
|
504
|
+
if (!target)
|
|
505
|
+
return null;
|
|
506
|
+
return buildTargetCommand(target, plan.packageManager);
|
|
478
507
|
}
|
|
479
508
|
function packageManagerSourceLabel(scanInput) {
|
|
480
509
|
if (scanInput.filePath) {
|
|
@@ -507,7 +536,6 @@ function upsertTarget(targetsByPackage, next) {
|
|
|
507
536
|
: existing.kind === "parent-update" || next.kind === "parent-update"
|
|
508
537
|
? "parent-update"
|
|
509
538
|
: "parent-upgrade",
|
|
510
|
-
displayTargetVersion: existing.displayTargetVersion ?? next.displayTargetVersion,
|
|
511
539
|
command: existing.command ?? next.command,
|
|
512
540
|
isDev: (existing.isDev ?? false) && (next.isDev ?? false),
|
|
513
541
|
workspaces: mergeStringArrays(existing.workspaces, next.workspaces),
|
|
@@ -690,8 +718,11 @@ function buildWorkspaceInstallCommands(targets, packageManager) {
|
|
|
690
718
|
commands.push(`npm install${flag}${wsFlags ? " " + wsFlags : ""} ${pkgArgs}`);
|
|
691
719
|
}
|
|
692
720
|
else if (packageManager === "pnpm") {
|
|
721
|
+
// pnpm's --filter selector is a CLI-level flag that precedes the command
|
|
722
|
+
// (`pnpm --filter ./client add pkg`), not a trailing argument.
|
|
693
723
|
const wsFlags = workspaces.map(ws => `--filter ./${ws}`).join(" ");
|
|
694
|
-
|
|
724
|
+
const prefix = wsFlags ? `pnpm ${wsFlags} add` : "pnpm add";
|
|
725
|
+
commands.push(`${prefix}${flag} ${pkgArgs}`);
|
|
695
726
|
}
|
|
696
727
|
else if (packageManager === "yarn") {
|
|
697
728
|
if (workspaces.length === 0) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { compareVersions, isPreReleaseVersion, looksLikeVersion } from "../utils/version.js";
|
|
2
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
3
|
const packumentCache = new Map();
|
|
3
4
|
const DEFAULT_NPM_REGISTRY_URL = "https://registry.npmjs.org";
|
|
4
5
|
let registryDebugLog;
|
|
@@ -11,75 +12,91 @@ function nextRegistryBatchId() {
|
|
|
11
12
|
registryBatchCounter += 1;
|
|
12
13
|
return `r-${String(registryBatchCounter).padStart(2, "0")}`;
|
|
13
14
|
}
|
|
15
|
+
const observerStorage = new AsyncLocalStorage();
|
|
16
|
+
export async function runWithObserver(observer, fn) {
|
|
17
|
+
return observerStorage.run(observer, fn);
|
|
18
|
+
}
|
|
14
19
|
export function clearPackumentCache() {
|
|
15
20
|
packumentCache.clear();
|
|
16
21
|
}
|
|
22
|
+
function notifyPackumentObserver(result, packageName) {
|
|
23
|
+
const observer = observerStorage.getStore();
|
|
24
|
+
if (result.status === "transient-failure") {
|
|
25
|
+
observer?.onTransientFailure?.(packageName);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
observer?.onResolved?.(packageName);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
17
31
|
export async function fetchPackument(packageName) {
|
|
18
32
|
const cached = packumentCache.get(packageName);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if (
|
|
28
|
-
|
|
33
|
+
let result;
|
|
34
|
+
if (cached) {
|
|
35
|
+
result = await cached;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
const promise = doFetchPackument(packageName);
|
|
39
|
+
packumentCache.set(packageName, promise);
|
|
40
|
+
result = await promise;
|
|
41
|
+
if (result.status === "transient-failure") {
|
|
42
|
+
// A later call retries the fetch instead of reusing a cached failure.
|
|
43
|
+
packumentCache.delete(packageName);
|
|
29
44
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
transientFailure = true;
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
const json = (await response.json());
|
|
45
|
+
}
|
|
46
|
+
notifyPackumentObserver(result, packageName);
|
|
47
|
+
return result.packument;
|
|
48
|
+
}
|
|
49
|
+
async function doFetchPackument(packageName) {
|
|
50
|
+
const url = `${DEFAULT_NPM_REGISTRY_URL}/${encodeURIComponent(packageName)
|
|
51
|
+
.replace(/%40/g, "@")
|
|
52
|
+
.replace(/%2F/g, "/")}`;
|
|
53
|
+
const batchId = registryDebugLog ? nextRegistryBatchId() : "";
|
|
54
|
+
const startedAt = registryDebugLog ? Date.now() : 0;
|
|
55
|
+
if (registryDebugLog) {
|
|
56
|
+
registryDebugLog("Registry fetch", { batchId, package: packageName, url });
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
const response = await fetch(url);
|
|
60
|
+
if (!response.ok) {
|
|
50
61
|
if (registryDebugLog) {
|
|
51
62
|
registryDebugLog("Registry response", {
|
|
52
63
|
batchId,
|
|
53
64
|
package: packageName,
|
|
54
65
|
status: response.status,
|
|
55
66
|
durationMs: Date.now() - startedAt,
|
|
56
|
-
versionsCount:
|
|
67
|
+
versionsCount: 0,
|
|
57
68
|
});
|
|
58
69
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
catch (error) {
|
|
62
|
-
transientFailure = true;
|
|
63
|
-
if (registryDebugLog) {
|
|
64
|
-
registryDebugLog("Registry fetch failed", {
|
|
65
|
-
batchId,
|
|
66
|
-
package: packageName,
|
|
67
|
-
durationMs: Date.now() - startedAt,
|
|
68
|
-
error: error instanceof Error
|
|
69
|
-
? { message: error.message, stack: error.stack }
|
|
70
|
-
: String(error),
|
|
71
|
-
});
|
|
70
|
+
if (response.status === 404) {
|
|
71
|
+
return { status: "not-found", packument: null };
|
|
72
72
|
}
|
|
73
|
-
return null;
|
|
73
|
+
return { status: "transient-failure", packument: null };
|
|
74
74
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
const json = (await response.json());
|
|
76
|
+
if (registryDebugLog) {
|
|
77
|
+
registryDebugLog("Registry response", {
|
|
78
|
+
batchId,
|
|
79
|
+
package: packageName,
|
|
80
|
+
status: response.status,
|
|
81
|
+
durationMs: Date.now() - startedAt,
|
|
82
|
+
versionsCount: Object.keys(json.versions ?? {}).length,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return { status: "resolved", packument: json };
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
if (registryDebugLog) {
|
|
89
|
+
registryDebugLog("Registry fetch failed", {
|
|
90
|
+
batchId,
|
|
91
|
+
package: packageName,
|
|
92
|
+
durationMs: Date.now() - startedAt,
|
|
93
|
+
error: error instanceof Error
|
|
94
|
+
? { message: error.message, stack: error.stack }
|
|
95
|
+
: String(error),
|
|
96
|
+
});
|
|
79
97
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
return promise;
|
|
98
|
+
return { status: "transient-failure", packument: null };
|
|
99
|
+
}
|
|
83
100
|
}
|
|
84
101
|
export async function packageVersionExists(packageName, version) {
|
|
85
102
|
const packument = await fetchPackument(packageName);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { compareVersions, isPreReleaseVersion, looksLikeVersion } from "../utils/version.js";
|
|
2
2
|
import { fetchPackument } from "./npm-registry.js";
|
|
3
3
|
import { findSafeVersionWithinParentRange } from "./npm-transitive-graph.js";
|
|
4
|
+
import { findPackageAlongPath } from "./package-path-lookup.js";
|
|
4
5
|
export async function resolveTransitiveRemediationViaRegistry(args) {
|
|
5
6
|
if (args.finding.relationship !== "transitive")
|
|
6
7
|
return null;
|
|
@@ -14,7 +15,6 @@ export async function resolveTransitiveRemediationViaRegistry(args) {
|
|
|
14
15
|
const vulnerableName = args.finding.pkg.name;
|
|
15
16
|
const fixHint = args.finding.validatedFirstFixedVersion ?? args.finding.firstFixedVersion;
|
|
16
17
|
if (directParentName !== immediateParentName) {
|
|
17
|
-
const packagesByName = new Map(args.packages.map(p => [p.name, p]));
|
|
18
18
|
return resolveWithinRangeForDeepChainViaRegistry({
|
|
19
19
|
immediateParentName,
|
|
20
20
|
vulnerableName,
|
|
@@ -22,7 +22,6 @@ export async function resolveTransitiveRemediationViaRegistry(args) {
|
|
|
22
22
|
fixHint,
|
|
23
23
|
viaPath,
|
|
24
24
|
packages: args.packages,
|
|
25
|
-
packagesByName,
|
|
26
25
|
workspaceMap: args.workspaceMap,
|
|
27
26
|
});
|
|
28
27
|
}
|
|
@@ -70,7 +69,6 @@ export async function resolveNpmTransitiveRemediation(args) {
|
|
|
70
69
|
// immediate parent's declared range for the vulnerable package already covers a safe version.
|
|
71
70
|
// If so, a lockfile refresh of the vulnerable package itself is sufficient.
|
|
72
71
|
if (directParentName !== immediateParentName) {
|
|
73
|
-
const packagesByName = new Map(args.packages.map(p => [p.name, p]));
|
|
74
72
|
return resolveWithinRangeForDeepChain({
|
|
75
73
|
graph: args.graph,
|
|
76
74
|
immediateParentName,
|
|
@@ -79,7 +77,6 @@ export async function resolveNpmTransitiveRemediation(args) {
|
|
|
79
77
|
fixHint,
|
|
80
78
|
viaPath,
|
|
81
79
|
packages: args.packages,
|
|
82
|
-
packagesByName,
|
|
83
80
|
offline: args.offline,
|
|
84
81
|
});
|
|
85
82
|
}
|
|
@@ -305,7 +302,8 @@ function parseCoreVersion(version) {
|
|
|
305
302
|
return [Number(major), Number(minor), Number(patch)];
|
|
306
303
|
}
|
|
307
304
|
async function resolveWithinRangeForDeepChainViaRegistry(args) {
|
|
308
|
-
const
|
|
305
|
+
const immediateParentPathPrefix = args.viaPath.slice(0, -1);
|
|
306
|
+
const immediateParent = findPackageAlongPath(args.packages, args.immediateParentName, immediateParentPathPrefix);
|
|
309
307
|
if (!immediateParent || !looksLikeVersion(immediateParent.version))
|
|
310
308
|
return null;
|
|
311
309
|
const safeCandidates = await findSafeChildCandidates(args.vulnerableName, args.installedVersion, args.fixHint);
|
|
@@ -335,7 +333,8 @@ async function resolveWithinRangeForDeepChainViaRegistry(args) {
|
|
|
335
333
|
};
|
|
336
334
|
}
|
|
337
335
|
async function resolveWithinRangeForDeepChain(args) {
|
|
338
|
-
const
|
|
336
|
+
const immediateParentPathPrefix = args.viaPath.slice(0, -1);
|
|
337
|
+
const immediateParent = findPackageAlongPath(args.packages, args.immediateParentName, immediateParentPathPrefix);
|
|
339
338
|
if (!immediateParent || !looksLikeVersion(immediateParent.version))
|
|
340
339
|
return null;
|
|
341
340
|
const nodeIds = args.graph.nodeIdsFor(args.immediateParentName, immediateParent.version);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export function startsWithPath(path, prefix) {
|
|
2
|
+
if (prefix.length > path.length)
|
|
3
|
+
return false;
|
|
4
|
+
for (let i = 0; i < prefix.length; i++) {
|
|
5
|
+
if (path[i] !== prefix[i])
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Finds the specific installed instance of `name` reachable via `pathPrefix`.
|
|
12
|
+
* Cannot use a name-keyed Map here: the same package name is commonly
|
|
13
|
+
* installed at multiple different versions in an npm tree (e.g. minimatch
|
|
14
|
+
* nested under eslint at one version and used top-level at another), and a
|
|
15
|
+
* Map would collapse them to a single arbitrary entry. Path-aware iteration
|
|
16
|
+
* across all installed versions is required to find the one actually on
|
|
17
|
+
* this dependency chain.
|
|
18
|
+
*/
|
|
19
|
+
export function findPackageAlongPath(packages, name, pathPrefix) {
|
|
20
|
+
for (const pkg of packages) {
|
|
21
|
+
if (pkg.name !== name)
|
|
22
|
+
continue;
|
|
23
|
+
const paths = pkg.paths ?? [];
|
|
24
|
+
if (paths.some(path => startsWithPath(path, pathPrefix))) {
|
|
25
|
+
return pkg;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { compareVersions, isPreReleaseVersion, looksLikeVersion } from "../utils/version.js";
|
|
2
2
|
import { fetchPackument } from "./npm-registry.js";
|
|
3
|
+
import { findPackageAlongPath } from "./package-path-lookup.js";
|
|
3
4
|
export function isVerifiedUpgrade(confidence) {
|
|
4
5
|
return confidence === "verified";
|
|
5
6
|
}
|
|
@@ -84,28 +85,7 @@ function resolveDirectParentContext(viaPath, packages, directDependencyNames, pa
|
|
|
84
85
|
return { directParentName, immediateParentName, directParent };
|
|
85
86
|
}
|
|
86
87
|
function findPackageVersion(packages, name, pathPrefix) {
|
|
87
|
-
|
|
88
|
-
// multiple versions (e.g. lodash@3 and lodash@4 on different paths), a Map
|
|
89
|
-
// would only hold one entry. We need path-aware iteration across all installed
|
|
90
|
-
// versions to find the right one for this specific dependency chain.
|
|
91
|
-
for (const pkg of packages) {
|
|
92
|
-
if (pkg.name !== name)
|
|
93
|
-
continue;
|
|
94
|
-
const paths = pkg.paths ?? [];
|
|
95
|
-
if (paths.some(path => startsWithPath(path, pathPrefix))) {
|
|
96
|
-
return pkg.version;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return null;
|
|
100
|
-
}
|
|
101
|
-
function startsWithPath(path, prefix) {
|
|
102
|
-
if (prefix.length > path.length)
|
|
103
|
-
return false;
|
|
104
|
-
for (let i = 0; i < prefix.length; i++) {
|
|
105
|
-
if (path[i] !== prefix[i])
|
|
106
|
-
return false;
|
|
107
|
-
}
|
|
108
|
-
return true;
|
|
88
|
+
return findPackageAlongPath(packages, name, pathPrefix)?.version ?? null;
|
|
109
89
|
}
|
|
110
90
|
/**
|
|
111
91
|
* Highest published, non-prerelease version of `name` that satisfies `range`,
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { pluralize } from "../utils/string.js";
|
|
2
|
+
export function getCompletenessImpact(completeness) {
|
|
3
|
+
const diagnostics = completeness?.diagnostics ?? [];
|
|
4
|
+
return {
|
|
5
|
+
hasDetectionGap: diagnostics.some(diagnostic => diagnostic.impact === "detection"),
|
|
6
|
+
hasRemediationGap: diagnostics.some(diagnostic => diagnostic.impact === "remediation"),
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export function formatDiagnosticMessage(code, count, affectedPackageCount) {
|
|
10
|
+
switch (code) {
|
|
11
|
+
case "OSV_DETAIL_TRANSIENT_FAILURE":
|
|
12
|
+
return `${count} advisory detail ${pluralize(count, "lookup")} failed with a transient error — re-run to retry.`;
|
|
13
|
+
case "OSV_DETAIL_OFFLINE_MISSING":
|
|
14
|
+
return `${count} advisory detail ${pluralize(count, "record")} ${pluralize(count, "is", "are")} missing from the local advisory database — refresh to sync.`;
|
|
15
|
+
case "OSV_DETAIL_CONFIRMED_MISSING":
|
|
16
|
+
return `${count} advisory detail ${pluralize(count, "record")} ${pluralize(count, "is", "are")} confirmed missing from the OSV API — affected findings lack detail data.`;
|
|
17
|
+
case "PACKUMENT_FETCH_FAILURE":
|
|
18
|
+
return `${count} packument ${pluralize(count, "fetch", "fetches")} failed — remediation guidance may be incomplete.`;
|
|
19
|
+
case "REMEDIATION_FAILURE":
|
|
20
|
+
if (affectedPackageCount !== undefined) {
|
|
21
|
+
return `${count} transitive remediation ${pluralize(count, "attempt")} failed across ${affectedPackageCount} ${pluralize(affectedPackageCount, "package")} — some fix recommendations may be missing.`;
|
|
22
|
+
}
|
|
23
|
+
return `${count} transitive remediation ${pluralize(count, "attempt")} failed — some fix recommendations may be missing.`;
|
|
24
|
+
case "CHAIN_RESOLUTION_FAILURE":
|
|
25
|
+
return `${count} chain resolution ${pluralize(count, "attempt")} failed — some validated upgrade chains may be missing.`;
|
|
26
|
+
default:
|
|
27
|
+
return `${count} unknown diagnostic occurred.`;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export function aggregateMultiFolderCompleteness(results) {
|
|
31
|
+
const deduped = new Map();
|
|
32
|
+
for (const result of results) {
|
|
33
|
+
for (const diagnostic of result.completeness.diagnostics) {
|
|
34
|
+
const existing = deduped.get(diagnostic.code);
|
|
35
|
+
if (existing) {
|
|
36
|
+
existing.count += diagnostic.count;
|
|
37
|
+
if (diagnostic.affectedPackageCount !== undefined) {
|
|
38
|
+
existing.affectedPackageCount =
|
|
39
|
+
(existing.affectedPackageCount ?? 0) + diagnostic.affectedPackageCount;
|
|
40
|
+
}
|
|
41
|
+
existing.message = formatDiagnosticMessage(diagnostic.code, existing.count, existing.affectedPackageCount);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
deduped.set(diagnostic.code, { ...diagnostic });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return { complete: deduped.size === 0, diagnostics: [...deduped.values()] };
|
|
49
|
+
}
|