cve-lite-cli 1.40.0 → 1.41.1
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 +17 -11
- package/dist/advisory/local-advisory-source.js +9 -5
- package/dist/advisory/local-db.js +91 -13
- package/dist/advisory/osv-sync.js +187 -56
- package/dist/advisory/staging-directory.js +112 -0
- package/dist/cli/advisories-sync.js +16 -2
- package/dist/cli/args.js +46 -35
- package/dist/cli/config.js +4 -1
- package/dist/cli/help.js +4 -3
- package/dist/cli/validate.js +23 -1
- package/dist/constants.js +11 -25
- package/dist/index.js +8 -3
- package/dist/output/cyclonedx.js +23 -14
- package/dist/output/debug.js +68 -18
- package/dist/output/formatters.js +33 -5
- package/dist/output/html-reporter.js +55 -5
- package/dist/output/multi-folder-html-reporter.js +59 -3
- package/dist/output/output-dir.js +193 -7
- package/dist/output/override-fix-command.js +5 -7
- package/dist/output/printers.js +16 -5
- package/dist/output/sarif.js +131 -48
- package/dist/output/sbom-dependency-edges.js +16 -10
- package/dist/output/sbom-file.js +14 -6
- package/dist/output/scan-json.js +21 -3
- package/dist/output/spdx.js +61 -23
- package/dist/output/spinner.js +2 -1
- package/dist/output/write-outputs.js +142 -52
- package/dist/overrides/context-builder.js +23 -70
- package/dist/overrides/parsing/registry.js +19 -69
- package/dist/parsers/bun-lock.js +1 -2
- package/dist/parsers/index.js +22 -1
- package/dist/parsers/npm-lock-graph.js +39 -1
- package/dist/parsers/package-lock.js +25 -5
- package/dist/parsers/pnpm-lock.js +3 -2
- package/dist/parsers/utils.js +5 -3
- package/dist/parsers/yarn-lock-graph.js +36 -17
- package/dist/parsers/yarn-lock.js +92 -25
- package/dist/remediation/fix-commands.js +101 -45
- package/dist/remediation/npm-registry.js +10 -2
- package/dist/remediation/npm-transitive-graph.js +30 -72
- package/dist/remediation/npm-transitive-resolution.js +24 -77
- package/dist/remediation/parent-upgrade-blockers.js +51 -0
- package/dist/remediation/parent-upgrade.js +5 -79
- package/dist/remediation/registry-parent-ranges.js +21 -0
- package/dist/remediation/transitive-chain-resolver.js +3 -3
- package/dist/scan/completeness.js +10 -4
- package/dist/scan/multi-folder-scan.js +133 -58
- package/dist/scan/override-audit.js +6 -4
- package/dist/scan/single-scan.js +41 -25
- package/dist/scanner.js +263 -58
- package/dist/usage/scanner.js +19 -8
- package/dist/utils/array.js +11 -3
- package/dist/utils/checked-address-policy.js +44 -0
- package/dist/utils/debug-bundle.js +118 -0
- package/dist/utils/debug-project.js +102 -0
- package/dist/utils/debug-redaction.js +117 -0
- package/dist/utils/file.js +2 -1
- package/dist/utils/fix-runner.js +95 -13
- package/dist/utils/import-type-queries.js +322 -0
- package/dist/utils/network.js +14 -9
- package/dist/utils/npm-lockfile.js +12 -0
- package/dist/utils/osv-fetch.js +34 -0
- package/dist/utils/package-identity.js +43 -0
- package/dist/utils/package-manager-source.js +24 -0
- package/dist/utils/purl.js +37 -0
- package/dist/utils/registry-config.js +47 -15
- package/dist/utils/registry-fetch.js +42 -0
- package/dist/utils/shell-quote.js +12 -0
- package/dist/utils/string.js +8 -0
- package/dist/utils/validate-url.js +1 -1
- package/dist/utils/version.js +30 -7
- package/dist/utils/versions/osv-range.js +191 -0
- package/dist/utils/versions/pep440.js +246 -0
- package/dist/utils/versions/scheme.js +10 -0
- package/package.json +3 -2
|
@@ -2,28 +2,31 @@ import path from "node:path";
|
|
|
2
2
|
import { severityOrder } from "../constants.js";
|
|
3
3
|
import { compareVersions, looksLikeVersion } from "../utils/version.js";
|
|
4
4
|
import { getPrimaryParent } from "../utils/finding.js";
|
|
5
|
+
import { isNpmLockSource, packageManagerForSource } from "../utils/package-manager-source.js";
|
|
5
6
|
import { calculatePathCoverage, formatDependencyPath } from "../utils/path-coverage.js";
|
|
6
7
|
import { pluralize } from "../utils/string.js";
|
|
8
|
+
import { quoteShellPath, shellQuote } from "../utils/shell-quote.js";
|
|
7
9
|
import { buildNpmWorkspaceMap } from "../parsers/package-lock.js";
|
|
8
10
|
import { buildPnpmWorkspaceMap } from "../parsers/pnpm-lock.js";
|
|
9
11
|
import { buildYarnWorkspaceMap } from "../parsers/yarn-lock.js";
|
|
10
12
|
import { buildBunWorkspaceMap } from "../parsers/bun-lock.js";
|
|
11
13
|
import { readConfiguredCooldown, cooldownWarningFor } from "./cooldown.js";
|
|
12
14
|
import { isVerifiedUpgrade } from "./parent-upgrade.js";
|
|
15
|
+
import { installPackageSpec, packageInstanceKey, packageNameKey, registryPackageName } from "../utils/package-identity.js";
|
|
13
16
|
// Rendered next to a parent-upgrade fix target whose recommendedParentUpgrade
|
|
14
17
|
// could not be verified end-to-end (parent-upgrade.ts confidence: "unverified").
|
|
15
18
|
// Shared across terminal and HTML output so the wording stays in sync.
|
|
16
19
|
export const UNVERIFIED_PARENT_UPGRADE_NOTE = "⚠ unverified - rescan after upgrading to confirm this resolves the finding";
|
|
17
20
|
export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
18
|
-
const packageManager =
|
|
21
|
+
const packageManager = packageManagerForSource(scanInput.source);
|
|
19
22
|
if (!packageManager)
|
|
20
23
|
return null;
|
|
21
24
|
const offline = !!options?.offline;
|
|
22
25
|
let workspaceMap = new Map();
|
|
23
26
|
if (scanInput.filePath) {
|
|
24
27
|
try {
|
|
25
|
-
if (packageManager === "npm" && (scanInput.source
|
|
26
|
-
workspaceMap = buildNpmWorkspaceMap(scanInput.filePath);
|
|
28
|
+
if (packageManager === "npm" && isNpmLockSource(scanInput.source)) {
|
|
29
|
+
workspaceMap = buildNpmWorkspaceMap(scanInput.filePath, { includeAliasIdentities: true });
|
|
27
30
|
}
|
|
28
31
|
else if (packageManager === "pnpm" && scanInput.source === "pnpm-lock") {
|
|
29
32
|
workspaceMap = buildPnpmWorkspaceMap(scanInput.filePath);
|
|
@@ -102,7 +105,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
102
105
|
finding.validatedTargetScannedVersions > 0 &&
|
|
103
106
|
finding.validatedTargetKnownVulnerableVersions >= finding.validatedTargetScannedVersions;
|
|
104
107
|
if (directTarget && allVersionsVulnerable) {
|
|
105
|
-
skippedByKey.set(`direct:${finding.pkg
|
|
108
|
+
skippedByKey.set(`direct:${packageInstanceKey(finding.pkg)}`, {
|
|
106
109
|
package: finding.pkg.name,
|
|
107
110
|
version: finding.pkg.version,
|
|
108
111
|
relationship: finding.relationship,
|
|
@@ -113,9 +116,10 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
113
116
|
if (directTarget &&
|
|
114
117
|
isUpgradeTarget(finding.pkg.version, directTarget) &&
|
|
115
118
|
validatedFieldOk) {
|
|
116
|
-
const pkgWorkspaces = workspaceMap.get(finding.pkg
|
|
119
|
+
const pkgWorkspaces = workspaceMap.get(packageNameKey(finding.pkg))?.filter(w => w !== ".") ?? [];
|
|
117
120
|
upsertTarget(targetsByKey, finding, {
|
|
118
121
|
package: finding.pkg.name,
|
|
122
|
+
...(finding.pkg.registryName ? { registryName: finding.pkg.registryName } : {}),
|
|
119
123
|
currentVersion: finding.pkg.version,
|
|
120
124
|
targetVersion: directTarget,
|
|
121
125
|
scannedVersions: finding.validatedTargetScannedVersions ?? null,
|
|
@@ -140,7 +144,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
140
144
|
});
|
|
141
145
|
}
|
|
142
146
|
else if (finding.fixVersionValidationNote) {
|
|
143
|
-
skippedByKey.set(`${finding.relationship}:${finding.pkg
|
|
147
|
+
skippedByKey.set(`${finding.relationship}:${packageInstanceKey(finding.pkg)}`, {
|
|
144
148
|
package: finding.pkg.name,
|
|
145
149
|
version: finding.pkg.version,
|
|
146
150
|
relationship: finding.relationship,
|
|
@@ -149,7 +153,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
149
153
|
});
|
|
150
154
|
}
|
|
151
155
|
else if (finding.firstFixedVersion) {
|
|
152
|
-
skippedByKey.set(`${finding.relationship}:${finding.pkg
|
|
156
|
+
skippedByKey.set(`${finding.relationship}:${packageInstanceKey(finding.pkg)}`, {
|
|
153
157
|
package: finding.pkg.name,
|
|
154
158
|
version: finding.pkg.version,
|
|
155
159
|
relationship: finding.relationship,
|
|
@@ -157,7 +161,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
157
161
|
});
|
|
158
162
|
}
|
|
159
163
|
else {
|
|
160
|
-
skippedByKey.set(`${finding.relationship}:${finding.pkg
|
|
164
|
+
skippedByKey.set(`${finding.relationship}:${packageInstanceKey(finding.pkg)}`, {
|
|
161
165
|
package: finding.pkg.name,
|
|
162
166
|
version: finding.pkg.version,
|
|
163
167
|
relationship: finding.relationship,
|
|
@@ -169,7 +173,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
169
173
|
continue;
|
|
170
174
|
}
|
|
171
175
|
if (finding.relationship === "unknown") {
|
|
172
|
-
skippedByKey.set(`unknown:${finding.pkg
|
|
176
|
+
skippedByKey.set(`unknown:${packageInstanceKey(finding.pkg)}`, {
|
|
173
177
|
package: finding.pkg.name,
|
|
174
178
|
version: finding.pkg.version,
|
|
175
179
|
relationship: finding.relationship,
|
|
@@ -192,9 +196,21 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
192
196
|
// reason to re-resolve its subtree.
|
|
193
197
|
command: buildNpmUpdateCommand(finding.pkg.name, finding.recommendedNpmTransitiveRemediation.workspaces),
|
|
194
198
|
isDev: devLookup.get(`${finding.recommendedNpmTransitiveRemediation.package}@${finding.recommendedNpmTransitiveRemediation.currentVersion}`) ?? false,
|
|
199
|
+
workspaces: finding.recommendedNpmTransitiveRemediation.workspaces,
|
|
195
200
|
}));
|
|
196
201
|
continue;
|
|
197
202
|
}
|
|
203
|
+
// A parent upgrade that a direct dependency would undo is not a fix: that
|
|
204
|
+
// dependency keeps the vulnerable copy installed (#1457).
|
|
205
|
+
if (finding.relationship === "transitive" && finding.recommendedParentUpgrade && finding.parentUpgradeBlockers?.length) {
|
|
206
|
+
skippedByKey.set(`${finding.relationship}:${finding.pkg.name}@${finding.pkg.version}`, {
|
|
207
|
+
package: finding.pkg.name,
|
|
208
|
+
version: finding.pkg.version,
|
|
209
|
+
relationship: finding.relationship,
|
|
210
|
+
reason: formatParentUpgradeBlockedReason(finding),
|
|
211
|
+
});
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
198
214
|
if (packageManager === "npm" &&
|
|
199
215
|
finding.relationship === "transitive" &&
|
|
200
216
|
finding.recommendedNpmTransitiveRemediation?.kind === "upgrade-parent-to-version" &&
|
|
@@ -263,7 +279,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
263
279
|
continue;
|
|
264
280
|
}
|
|
265
281
|
if (finding.relationship === "transitive" && finding.recommendedParentUpgrade) {
|
|
266
|
-
skippedByKey.set(`${finding.relationship}:${finding.pkg
|
|
282
|
+
skippedByKey.set(`${finding.relationship}:${packageInstanceKey(finding.pkg)}`, {
|
|
267
283
|
package: finding.pkg.name,
|
|
268
284
|
version: finding.pkg.version,
|
|
269
285
|
relationship: finding.relationship,
|
|
@@ -277,14 +293,15 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
277
293
|
const lockfileRefreshCommand = packageManager === "pnpm"
|
|
278
294
|
? buildPnpmLockfileRefreshCommand(finding.pkg.name, finding.recommendedNpmTransitiveRemediation.workspaces)
|
|
279
295
|
: packageManager === "yarn"
|
|
280
|
-
?
|
|
281
|
-
:
|
|
296
|
+
? buildYarnUpgradeCommand(finding.pkg.name, finding.recommendedNpmTransitiveRemediation.workspaces)
|
|
297
|
+
: buildBunUpdateCommand(finding.pkg.name);
|
|
282
298
|
upsertTarget(targetsByKey, finding, parentUpdateTarget(finding, urgent, {
|
|
283
299
|
package: finding.pkg.name,
|
|
284
300
|
currentVersion: finding.pkg.version,
|
|
285
301
|
childTargetVersion: finding.recommendedNpmTransitiveRemediation.targetChildVersion,
|
|
286
302
|
reason: `${finding.pkg.name}@${finding.pkg.version} can be refreshed to ${finding.recommendedNpmTransitiveRemediation.targetChildVersion}+; no parent upgrade needed.`,
|
|
287
303
|
command: lockfileRefreshCommand,
|
|
304
|
+
workspaces: finding.recommendedNpmTransitiveRemediation?.workspaces,
|
|
288
305
|
}));
|
|
289
306
|
continue;
|
|
290
307
|
}
|
|
@@ -318,7 +335,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
318
335
|
const fixClause = fixHint
|
|
319
336
|
? ` - check for a release that resolves ${finding.pkg.name} to ${fixHint}+`
|
|
320
337
|
: "";
|
|
321
|
-
skippedByKey.set(`${finding.relationship}:${finding.pkg
|
|
338
|
+
skippedByKey.set(`${finding.relationship}:${packageInstanceKey(finding.pkg)}`, {
|
|
322
339
|
package: finding.pkg.name,
|
|
323
340
|
version: finding.pkg.version,
|
|
324
341
|
relationship: finding.relationship,
|
|
@@ -326,7 +343,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
326
343
|
});
|
|
327
344
|
continue;
|
|
328
345
|
}
|
|
329
|
-
skippedByKey.set(`${finding.relationship}:${finding.pkg
|
|
346
|
+
skippedByKey.set(`${finding.relationship}:${packageInstanceKey(finding.pkg)}`, {
|
|
330
347
|
package: finding.pkg.name,
|
|
331
348
|
version: finding.pkg.version,
|
|
332
349
|
relationship: finding.relationship,
|
|
@@ -350,10 +367,27 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
350
367
|
});
|
|
351
368
|
// Some install targets carry an explicit `command` built without workspace
|
|
352
369
|
// context (e.g. a chain-resolution command). This raw field is exposed in JSON
|
|
353
|
-
// and embedded in the HTML report, so scope it to the declaring member too
|
|
354
|
-
//
|
|
370
|
+
// and embedded in the HTML report, so scope it to the declaring member too.
|
|
371
|
+
// Parent-update commands are rebuilt from the (possibly merged) workspace list
|
|
372
|
+
// so the printed plan matches what --fix will spawn.
|
|
355
373
|
for (const target of targets) {
|
|
356
|
-
if (target.kind
|
|
374
|
+
if (target.kind === "parent-update") {
|
|
375
|
+
const updatePkg = target.childPackage ?? target.package;
|
|
376
|
+
if (packageManager === "npm") {
|
|
377
|
+
target.command = buildNpmUpdateCommand(updatePkg, target.workspaces);
|
|
378
|
+
}
|
|
379
|
+
else if (packageManager === "pnpm") {
|
|
380
|
+
target.command = buildPnpmLockfileRefreshCommand(updatePkg, target.workspaces);
|
|
381
|
+
}
|
|
382
|
+
else if (packageManager === "yarn") {
|
|
383
|
+
target.command = buildYarnUpgradeCommand(updatePkg, target.workspaces);
|
|
384
|
+
}
|
|
385
|
+
else if (packageManager === "bun") {
|
|
386
|
+
target.command = buildBunUpdateCommand(updatePkg);
|
|
387
|
+
}
|
|
388
|
+
continue;
|
|
389
|
+
}
|
|
390
|
+
if (target.command && target.workspaces?.length) {
|
|
357
391
|
const scoped = buildWorkspaceInstallCommands([target], packageManager);
|
|
358
392
|
if (scoped.length > 0)
|
|
359
393
|
target.command = scoped.join(" && ");
|
|
@@ -399,7 +433,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
399
433
|
return true;
|
|
400
434
|
}).length;
|
|
401
435
|
if (options?.subfolder) {
|
|
402
|
-
const prefix = `cd ${options.subfolder} && `;
|
|
436
|
+
const prefix = `cd ${quoteShellPath(options.subfolder)} && `;
|
|
403
437
|
if (plan.command)
|
|
404
438
|
plan.command = prefix + plan.command;
|
|
405
439
|
for (const section of plan.sections) {
|
|
@@ -408,36 +442,37 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
408
442
|
}
|
|
409
443
|
return plan;
|
|
410
444
|
}
|
|
411
|
-
function inferPackageManager(scanInput) {
|
|
412
|
-
if (scanInput.source === "package-lock")
|
|
413
|
-
return "npm";
|
|
414
|
-
if (scanInput.source === "pnpm-lock")
|
|
415
|
-
return "pnpm";
|
|
416
|
-
if (scanInput.source === "yarn-lock")
|
|
417
|
-
return "yarn";
|
|
418
|
-
if (scanInput.source === "bun-lock")
|
|
419
|
-
return "bun";
|
|
420
|
-
return null;
|
|
421
|
-
}
|
|
422
445
|
function buildNpmUpdateCommand(pkg, workspaces) {
|
|
423
446
|
const nonRoot = (workspaces ?? []).filter(w => w !== ".");
|
|
447
|
+
const pkgQ = shellQuote(pkg);
|
|
424
448
|
if (nonRoot.length === 1) {
|
|
425
|
-
return `npm update --workspace=${nonRoot[0]} ${
|
|
449
|
+
return `npm update --workspace=${shellQuote(nonRoot[0])} ${pkgQ}`;
|
|
426
450
|
}
|
|
427
451
|
if (nonRoot.length > 1) {
|
|
428
|
-
return `npm update --workspaces ${
|
|
452
|
+
return `npm update --workspaces ${pkgQ}`;
|
|
429
453
|
}
|
|
430
|
-
return `npm update ${
|
|
454
|
+
return `npm update ${pkgQ}`;
|
|
431
455
|
}
|
|
432
456
|
function buildPnpmLockfileRefreshCommand(pkg, workspaces) {
|
|
457
|
+
const pkgQ = shellQuote(pkg);
|
|
433
458
|
if (!workspaces || workspaces.length === 0 || workspaces.length > 1) {
|
|
434
|
-
return `pnpm update --recursive --no-save ${
|
|
459
|
+
return `pnpm update --recursive --no-save ${pkgQ}`;
|
|
435
460
|
}
|
|
436
461
|
const workspace = workspaces[0];
|
|
437
462
|
if (workspace === ".") {
|
|
438
|
-
return `pnpm update --no-save ${
|
|
463
|
+
return `pnpm update --no-save ${pkgQ}`;
|
|
439
464
|
}
|
|
440
|
-
return `pnpm --filter
|
|
465
|
+
return `pnpm --filter ${shellQuote("./" + workspace)} update --no-save ${pkgQ}`;
|
|
466
|
+
}
|
|
467
|
+
function buildYarnUpgradeCommand(pkg, workspaces) {
|
|
468
|
+
const pkgQ = shellQuote(pkg);
|
|
469
|
+
const nonRoot = (workspaces ?? []).filter(w => w !== ".");
|
|
470
|
+
if (nonRoot.length === 0)
|
|
471
|
+
return `yarn upgrade ${pkgQ}`;
|
|
472
|
+
return nonRoot.map(ws => `yarn workspace ${shellQuote(ws)} upgrade ${pkgQ}`).join(" && ");
|
|
473
|
+
}
|
|
474
|
+
function buildBunUpdateCommand(pkg) {
|
|
475
|
+
return `bun update ${shellQuote(pkg)}`;
|
|
441
476
|
}
|
|
442
477
|
export function commandPrefix(packageManager) {
|
|
443
478
|
if (packageManager === "npm")
|
|
@@ -452,6 +487,10 @@ function devFlag(packageManager) {
|
|
|
452
487
|
return packageManager === "bun" ? "--dev" : "-D";
|
|
453
488
|
}
|
|
454
489
|
export function findFixTargetForFinding(plan, finding) {
|
|
490
|
+
// A sibling finding may share the parent upgrade, but a direct dependency
|
|
491
|
+
// keeps this copy installed, so no command in the plan fixes this one.
|
|
492
|
+
if (finding.recommendedParentUpgrade && finding.parentUpgradeBlockers?.length)
|
|
493
|
+
return null;
|
|
455
494
|
const target = plan.targets.find(item => {
|
|
456
495
|
if (finding.recommendedNpmTransitiveRemediation?.kind === "update-parent-within-range") {
|
|
457
496
|
const rem = finding.recommendedNpmTransitiveRemediation;
|
|
@@ -495,6 +534,9 @@ export function findFixTargetForFinding(plan, finding) {
|
|
|
495
534
|
const directTarget = finding.validatedFirstFixedVersion ?? finding.firstFixedVersion;
|
|
496
535
|
if (item.package !== finding.pkg.name)
|
|
497
536
|
return false;
|
|
537
|
+
if (registryPackageName({ name: item.package, registryName: item.registryName }) !== registryPackageName(finding.pkg)) {
|
|
538
|
+
return false;
|
|
539
|
+
}
|
|
498
540
|
// A transitive finding is only fixed through a remediation, and each kind of
|
|
499
541
|
// remediation has its own branch above. Falling through to here for one means
|
|
500
542
|
// nothing was resolved for it, so matching it against a direct install of the same
|
|
@@ -536,7 +578,7 @@ export function buildTargetCommand(target, packageManager) {
|
|
|
536
578
|
if (target.command)
|
|
537
579
|
return target.command;
|
|
538
580
|
const flag = target.isDev ? ` ${devFlag(packageManager)}` : "";
|
|
539
|
-
return `${commandPrefix(packageManager)}${flag} ${target
|
|
581
|
+
return `${commandPrefix(packageManager)}${flag} ${shellQuote(installPackageSpec(target))}`;
|
|
540
582
|
}
|
|
541
583
|
export function findSuggestedCommandForFinding(plan, finding) {
|
|
542
584
|
const target = findFixTargetForFinding(plan, finding);
|
|
@@ -577,7 +619,7 @@ function packageManagerSourceLabel(scanInput) {
|
|
|
577
619
|
function targetKey(finding, target) {
|
|
578
620
|
return target.kind === "parent-update"
|
|
579
621
|
? `parent-update:${target.package}>${finding.pkg.name}@${finding.pkg.version}`
|
|
580
|
-
: `install:${target.package}`;
|
|
622
|
+
: `install:${packageNameKey({ name: target.package, registryName: target.registryName })}`;
|
|
581
623
|
}
|
|
582
624
|
// Build a parent-update target whose targetVersion always belongs to `package`.
|
|
583
625
|
// When the named package is the parent of the finding, the child's version moves
|
|
@@ -587,6 +629,10 @@ function targetKey(finding, target) {
|
|
|
587
629
|
// the child's destination.
|
|
588
630
|
function parentUpdateTarget(finding, urgent, args) {
|
|
589
631
|
const namesParent = args.package !== finding.pkg.name;
|
|
632
|
+
// Keep "." in the list: pnpm treats a sole root workspace as a plain refresh
|
|
633
|
+
// (no --filter / no --recursive). Stripping it here collapsed that case into
|
|
634
|
+
// the empty-workspaces branch and emitted --recursive.
|
|
635
|
+
const workspaces = args.workspaces ?? [];
|
|
590
636
|
return {
|
|
591
637
|
package: args.package,
|
|
592
638
|
currentVersion: args.currentVersion,
|
|
@@ -604,6 +650,7 @@ function parentUpdateTarget(finding, urgent, args) {
|
|
|
604
650
|
command: args.command,
|
|
605
651
|
usage: finding.usage ?? null,
|
|
606
652
|
isDev: args.isDev,
|
|
653
|
+
workspaces: workspaces.length > 0 ? workspaces : undefined,
|
|
607
654
|
};
|
|
608
655
|
}
|
|
609
656
|
/**
|
|
@@ -854,16 +901,16 @@ function buildWorkspaceInstallCommands(targets, packageManager) {
|
|
|
854
901
|
for (const [targets, isDev] of [[prodTargets, false], [devTargets, true]]) {
|
|
855
902
|
if (targets.length === 0)
|
|
856
903
|
continue;
|
|
857
|
-
const pkgArgs = targets.map(t =>
|
|
904
|
+
const pkgArgs = targets.map(t => shellQuote(installPackageSpec(t))).join(" ");
|
|
858
905
|
const flag = isDev ? ` ${devFlag(packageManager)}` : "";
|
|
859
906
|
if (packageManager === "npm") {
|
|
860
|
-
const wsFlags = workspaces.map(ws => `-w ${ws}`).join(" ");
|
|
907
|
+
const wsFlags = workspaces.map(ws => `-w ${shellQuote(ws)}`).join(" ");
|
|
861
908
|
commands.push(`npm install${flag}${wsFlags ? " " + wsFlags : ""} ${pkgArgs}`);
|
|
862
909
|
}
|
|
863
910
|
else if (packageManager === "pnpm") {
|
|
864
911
|
// pnpm's --filter selector is a CLI-level flag that precedes the command
|
|
865
912
|
// (`pnpm --filter ./client add pkg`), not a trailing argument.
|
|
866
|
-
const wsFlags = workspaces.map(ws => `--filter
|
|
913
|
+
const wsFlags = workspaces.map(ws => `--filter ${shellQuote("./" + ws)}`).join(" ");
|
|
867
914
|
const prefix = wsFlags ? `pnpm ${wsFlags} add` : "pnpm add";
|
|
868
915
|
commands.push(`${prefix}${flag} ${pkgArgs}`);
|
|
869
916
|
}
|
|
@@ -873,12 +920,12 @@ function buildWorkspaceInstallCommands(targets, packageManager) {
|
|
|
873
920
|
}
|
|
874
921
|
else {
|
|
875
922
|
for (const ws of workspaces) {
|
|
876
|
-
commands.push(`yarn workspace ${ws} add${flag} ${pkgArgs}`);
|
|
923
|
+
commands.push(`yarn workspace ${shellQuote(ws)} add${flag} ${pkgArgs}`);
|
|
877
924
|
}
|
|
878
925
|
}
|
|
879
926
|
}
|
|
880
927
|
else if (packageManager === "bun") {
|
|
881
|
-
const wsFlags = workspaces.map(ws => `--filter ${ws}`).join(" ");
|
|
928
|
+
const wsFlags = workspaces.map(ws => `--filter ${shellQuote(ws)}`).join(" ");
|
|
882
929
|
commands.push(`bun add${flag}${wsFlags ? " " + wsFlags : ""} ${pkgArgs}`);
|
|
883
930
|
}
|
|
884
931
|
else {
|
|
@@ -899,7 +946,7 @@ function buildCommandForTargets(targets, packageManager) {
|
|
|
899
946
|
const updateCommands = explicitCommands.length > 0
|
|
900
947
|
? [...new Set(explicitCommands)]
|
|
901
948
|
: packageManager === "npm"
|
|
902
|
-
? [`npm update ${parentUpdateTargets.map(target => target.childPackage ?? target.package).join(" ")}`]
|
|
949
|
+
? [`npm update ${parentUpdateTargets.map(target => shellQuote(target.childPackage ?? target.package)).join(" ")}`]
|
|
903
950
|
: [];
|
|
904
951
|
commandParts.push(...updateCommands);
|
|
905
952
|
}
|
|
@@ -912,10 +959,10 @@ function buildCommandForTargets(targets, packageManager) {
|
|
|
912
959
|
const prodInstall = installTargets.filter(t => !t.isDev);
|
|
913
960
|
const devInstall = installTargets.filter(t => t.isDev);
|
|
914
961
|
if (prodInstall.length > 0) {
|
|
915
|
-
commandParts.push(`${commandPrefix(packageManager)} ${prodInstall.map(t =>
|
|
962
|
+
commandParts.push(`${commandPrefix(packageManager)} ${prodInstall.map(t => shellQuote(installPackageSpec(t))).join(" ")}`);
|
|
916
963
|
}
|
|
917
964
|
if (devInstall.length > 0) {
|
|
918
|
-
commandParts.push(`${commandPrefix(packageManager)} ${devFlag(packageManager)} ${devInstall.map(t =>
|
|
965
|
+
commandParts.push(`${commandPrefix(packageManager)} ${devFlag(packageManager)} ${devInstall.map(t => shellQuote(installPackageSpec(t))).join(" ")}`);
|
|
919
966
|
}
|
|
920
967
|
}
|
|
921
968
|
}
|
|
@@ -924,3 +971,12 @@ function buildCommandForTargets(targets, packageManager) {
|
|
|
924
971
|
function capitalize(value) {
|
|
925
972
|
return value.charAt(0).toUpperCase() + value.slice(1);
|
|
926
973
|
}
|
|
974
|
+
// Shared by the plan and the per-finding recommendation, so both say the same thing.
|
|
975
|
+
export function formatParentUpgradeBlockedReason(finding) {
|
|
976
|
+
const upgrade = finding.recommendedParentUpgrade;
|
|
977
|
+
const blockers = (finding.parentUpgradeBlockers ?? [])
|
|
978
|
+
.map(blocker => `${blocker.package}@${blocker.version} requires ${blocker.range}`)
|
|
979
|
+
.join(", ");
|
|
980
|
+
const parent = upgrade ? `${upgrade.package} to ${upgrade.targetVersion}` : "the parent";
|
|
981
|
+
return `Upgrading ${parent} alone leaves ${finding.pkg.name}@${finding.pkg.version} installed: ${blockers}. Those dependencies need upgrading too.`;
|
|
982
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { compareVersions, isPreReleaseVersion, looksLikeVersion } from "../utils/version.js";
|
|
2
2
|
import { registryForPackage } from "../utils/registry-config.js";
|
|
3
|
+
import { fetchRegistryMetadata, RegistryNetworkPolicyError } from "../utils/registry-fetch.js";
|
|
3
4
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
4
5
|
const packumentCache = new Map();
|
|
5
6
|
const DEFAULT_NPM_REGISTRY_URL = "https://registry.npmjs.org";
|
|
@@ -24,6 +25,8 @@ function notifyPackumentObserver(result, packageName) {
|
|
|
24
25
|
const observer = observerStorage.getStore();
|
|
25
26
|
if (result.status === "transient-failure") {
|
|
26
27
|
observer?.onTransientFailure?.(packageName);
|
|
28
|
+
if (result.policyBlocked)
|
|
29
|
+
observer?.onPolicyBlocked?.();
|
|
27
30
|
}
|
|
28
31
|
else {
|
|
29
32
|
observer?.onResolved?.(packageName);
|
|
@@ -61,6 +64,7 @@ let registryConfig = null;
|
|
|
61
64
|
*/
|
|
62
65
|
export function configureNpmRegistry(config) {
|
|
63
66
|
registryConfig = config;
|
|
67
|
+
clearPackumentCache();
|
|
64
68
|
}
|
|
65
69
|
/**
|
|
66
70
|
* Names the registry a lookup for this package actually went to, for use inside
|
|
@@ -99,7 +103,7 @@ async function doFetchPackument(packageName) {
|
|
|
99
103
|
registryDebugLog("Registry fetch", { batchId, package: packageName, url });
|
|
100
104
|
}
|
|
101
105
|
try {
|
|
102
|
-
const response = await
|
|
106
|
+
const response = await fetchRegistryMetadata(base, url, !!registryConfig?.allowPrivate);
|
|
103
107
|
if (!response.ok) {
|
|
104
108
|
if (registryDebugLog) {
|
|
105
109
|
registryDebugLog("Registry response", {
|
|
@@ -138,7 +142,11 @@ async function doFetchPackument(packageName) {
|
|
|
138
142
|
: String(error),
|
|
139
143
|
});
|
|
140
144
|
}
|
|
141
|
-
return {
|
|
145
|
+
return {
|
|
146
|
+
status: "transient-failure",
|
|
147
|
+
packument: null,
|
|
148
|
+
policyBlocked: error instanceof RegistryNetworkPolicyError,
|
|
149
|
+
};
|
|
142
150
|
}
|
|
143
151
|
}
|
|
144
152
|
export async function packageVersionExists(packageName, version) {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { compareVersions, looksLikeVersion } from "../utils/version.js";
|
|
1
|
+
import { compareVersions, looksLikeVersion, satisfiesRange } from "../utils/version.js";
|
|
2
2
|
export function createNpmTransitiveGraph(args) {
|
|
3
3
|
const nodesById = new Map();
|
|
4
4
|
const nodeIdsByPackageKey = new Map();
|
|
5
5
|
const childNodeIdsByParentNodeId = new Map();
|
|
6
6
|
const rangeByParentNodeId = new Map();
|
|
7
|
+
const parentNodeIdsByChildNodeId = new Map();
|
|
7
8
|
for (const node of args.nodes) {
|
|
8
9
|
nodesById.set(node.id, { ...node });
|
|
9
10
|
nodeIdsByPackageKey.set(buildPackageKey(node.name, node.version), [
|
|
@@ -16,6 +17,10 @@ export function createNpmTransitiveGraph(args) {
|
|
|
16
17
|
...(childNodeIdsByParentNodeId.get(edge.parentNodeId) ?? []),
|
|
17
18
|
edge.childNodeId,
|
|
18
19
|
]);
|
|
20
|
+
parentNodeIdsByChildNodeId.set(edge.childNodeId, [
|
|
21
|
+
...(parentNodeIdsByChildNodeId.get(edge.childNodeId) ?? []),
|
|
22
|
+
edge.parentNodeId,
|
|
23
|
+
]);
|
|
19
24
|
const ranges = rangeByParentNodeId.get(edge.parentNodeId) ?? new Map();
|
|
20
25
|
ranges.set(edge.childName, edge.range);
|
|
21
26
|
rangeByParentNodeId.set(edge.parentNodeId, ranges);
|
|
@@ -34,90 +39,43 @@ export function createNpmTransitiveGraph(args) {
|
|
|
34
39
|
rangeFor(parentNodeId, childName) {
|
|
35
40
|
return rangeByParentNodeId.get(parentNodeId)?.get(childName) ?? null;
|
|
36
41
|
},
|
|
42
|
+
parentsFor(nodeId) {
|
|
43
|
+
return Object.freeze([...(parentNodeIdsByChildNodeId.get(nodeId) ?? [])]);
|
|
44
|
+
},
|
|
37
45
|
};
|
|
38
46
|
}
|
|
39
47
|
function buildPackageKey(name, version) {
|
|
40
48
|
return `${name}@${version ?? "null"}`;
|
|
41
49
|
}
|
|
50
|
+
// A within-range update re-resolves the installed copy of the child, so the
|
|
51
|
+
// target has to satisfy every parent holding that copy, not only the parent the
|
|
52
|
+
// path led to (#1291). When `childVersion` is given, every parent's declared
|
|
53
|
+
// range is applied as well as the chosen parent's.
|
|
42
54
|
export function findSafeVersionWithinParentRange(args) {
|
|
43
55
|
const allowedRange = args.graph.rangeFor(args.parentNodeId, args.childName);
|
|
44
56
|
if (!allowedRange)
|
|
45
57
|
return null;
|
|
58
|
+
const ranges = [
|
|
59
|
+
allowedRange,
|
|
60
|
+
...(args.childVersion ? rangesFromEveryParent(args.graph, args.childName, args.childVersion) : []),
|
|
61
|
+
];
|
|
46
62
|
const matchingCandidates = args.candidates
|
|
47
63
|
.filter(looksLikeVersion)
|
|
48
|
-
.filter(candidate =>
|
|
64
|
+
.filter(candidate => ranges.every(range => satisfiesRange(candidate, range)))
|
|
49
65
|
.sort(compareVersions);
|
|
50
66
|
return matchingCandidates.at(-1) ?? null;
|
|
51
67
|
}
|
|
52
|
-
function
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if (!normalized)
|
|
64
|
-
return false;
|
|
65
|
-
const tokens = normalized.split(/\s+/).filter(Boolean);
|
|
66
|
-
return tokens.every(token => satisfiesComparator(version, token));
|
|
67
|
-
}
|
|
68
|
-
function normalizeRange(range) {
|
|
69
|
-
const trimmed = range.trim();
|
|
70
|
-
if (!trimmed)
|
|
71
|
-
return null;
|
|
72
|
-
if (looksLikeVersion(trimmed)) {
|
|
73
|
-
return `=${trimmed}`;
|
|
74
|
-
}
|
|
75
|
-
if (trimmed.startsWith("^")) {
|
|
76
|
-
const base = trimmed.slice(1);
|
|
77
|
-
if (!looksLikeVersion(base))
|
|
78
|
-
return null;
|
|
79
|
-
const [major, minor, patch] = parseCoreVersion(base);
|
|
80
|
-
if (major > 0)
|
|
81
|
-
return `>=${base} <${major + 1}.0.0`;
|
|
82
|
-
if (minor > 0)
|
|
83
|
-
return `>=${base} <0.${minor + 1}.0`;
|
|
84
|
-
return `>=${base} <0.0.${patch + 1}`;
|
|
85
|
-
}
|
|
86
|
-
if (trimmed.startsWith("~")) {
|
|
87
|
-
const base = trimmed.slice(1);
|
|
88
|
-
if (!looksLikeVersion(base))
|
|
89
|
-
return null;
|
|
90
|
-
const [major, minor] = parseCoreVersion(base);
|
|
91
|
-
return `>=${base} <${major}.${minor + 1}.0`;
|
|
92
|
-
}
|
|
93
|
-
return trimmed;
|
|
94
|
-
}
|
|
95
|
-
function satisfiesComparator(version, comparator) {
|
|
96
|
-
const token = comparator.trim();
|
|
97
|
-
if (!token)
|
|
98
|
-
return true;
|
|
99
|
-
const match = token.match(/^(<=|>=|<|>|=)?\s*([0-9]+\.[0-9]+\.[0-9]+(?:[-+][^\s]+)?)$/);
|
|
100
|
-
if (!match)
|
|
101
|
-
return false;
|
|
102
|
-
const operator = match[1] ?? "=";
|
|
103
|
-
const target = match[2];
|
|
104
|
-
const cmp = compareVersions(version, target);
|
|
105
|
-
switch (operator) {
|
|
106
|
-
case "<":
|
|
107
|
-
return cmp < 0;
|
|
108
|
-
case "<=":
|
|
109
|
-
return cmp <= 0;
|
|
110
|
-
case ">":
|
|
111
|
-
return cmp > 0;
|
|
112
|
-
case ">=":
|
|
113
|
-
return cmp >= 0;
|
|
114
|
-
case "=":
|
|
115
|
-
return cmp === 0;
|
|
116
|
-
default:
|
|
117
|
-
return false;
|
|
68
|
+
function rangesFromEveryParent(graph, childName, childVersion) {
|
|
69
|
+
if (!graph.parentsFor)
|
|
70
|
+
return [];
|
|
71
|
+
const ranges = [];
|
|
72
|
+
for (const childNodeId of graph.nodeIdsFor(childName, childVersion)) {
|
|
73
|
+
for (const parentNodeId of graph.parentsFor(childNodeId)) {
|
|
74
|
+
const range = graph.rangeFor(parentNodeId, childName);
|
|
75
|
+
if (range)
|
|
76
|
+
ranges.push(range);
|
|
77
|
+
}
|
|
78
|
+
ranges.push(...(graph.peerRangesFor?.(childNodeId) ?? []));
|
|
118
79
|
}
|
|
119
|
-
|
|
120
|
-
function parseCoreVersion(version) {
|
|
121
|
-
const [major = "0", minor = "0", patch = "0"] = version.split(/[+-]/)[0].split(".");
|
|
122
|
-
return [Number(major), Number(minor), Number(patch)];
|
|
80
|
+
return ranges;
|
|
123
81
|
}
|