cve-lite-cli 1.40.0 → 1.41.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 +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/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/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 +5 -2
- package/dist/parsers/yarn-lock.js +1 -2
- package/dist/remediation/fix-commands.js +105 -44
- 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/single-scan.js +41 -25
- package/dist/scanner.js +257 -58
- package/dist/usage/scanner.js +19 -8
- package/dist/utils/array.js +11 -3
- 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 +13 -9
- package/dist/utils/npm-lockfile.js +12 -0
- package/dist/utils/osv-fetch.js +70 -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 +1 -16
- 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,6 +2,7 @@ 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";
|
|
7
8
|
import { buildNpmWorkspaceMap } from "../parsers/package-lock.js";
|
|
@@ -10,20 +11,21 @@ import { buildYarnWorkspaceMap } from "../parsers/yarn-lock.js";
|
|
|
10
11
|
import { buildBunWorkspaceMap } from "../parsers/bun-lock.js";
|
|
11
12
|
import { readConfiguredCooldown, cooldownWarningFor } from "./cooldown.js";
|
|
12
13
|
import { isVerifiedUpgrade } from "./parent-upgrade.js";
|
|
14
|
+
import { installPackageSpec, packageInstanceKey, packageNameKey, registryPackageName } from "../utils/package-identity.js";
|
|
13
15
|
// Rendered next to a parent-upgrade fix target whose recommendedParentUpgrade
|
|
14
16
|
// could not be verified end-to-end (parent-upgrade.ts confidence: "unverified").
|
|
15
17
|
// Shared across terminal and HTML output so the wording stays in sync.
|
|
16
18
|
export const UNVERIFIED_PARENT_UPGRADE_NOTE = "⚠ unverified - rescan after upgrading to confirm this resolves the finding";
|
|
17
19
|
export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
18
|
-
const packageManager =
|
|
20
|
+
const packageManager = packageManagerForSource(scanInput.source);
|
|
19
21
|
if (!packageManager)
|
|
20
22
|
return null;
|
|
21
23
|
const offline = !!options?.offline;
|
|
22
24
|
let workspaceMap = new Map();
|
|
23
25
|
if (scanInput.filePath) {
|
|
24
26
|
try {
|
|
25
|
-
if (packageManager === "npm" && (scanInput.source
|
|
26
|
-
workspaceMap = buildNpmWorkspaceMap(scanInput.filePath);
|
|
27
|
+
if (packageManager === "npm" && isNpmLockSource(scanInput.source)) {
|
|
28
|
+
workspaceMap = buildNpmWorkspaceMap(scanInput.filePath, { includeAliasIdentities: true });
|
|
27
29
|
}
|
|
28
30
|
else if (packageManager === "pnpm" && scanInput.source === "pnpm-lock") {
|
|
29
31
|
workspaceMap = buildPnpmWorkspaceMap(scanInput.filePath);
|
|
@@ -102,7 +104,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
102
104
|
finding.validatedTargetScannedVersions > 0 &&
|
|
103
105
|
finding.validatedTargetKnownVulnerableVersions >= finding.validatedTargetScannedVersions;
|
|
104
106
|
if (directTarget && allVersionsVulnerable) {
|
|
105
|
-
skippedByKey.set(`direct:${finding.pkg
|
|
107
|
+
skippedByKey.set(`direct:${packageInstanceKey(finding.pkg)}`, {
|
|
106
108
|
package: finding.pkg.name,
|
|
107
109
|
version: finding.pkg.version,
|
|
108
110
|
relationship: finding.relationship,
|
|
@@ -113,9 +115,10 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
113
115
|
if (directTarget &&
|
|
114
116
|
isUpgradeTarget(finding.pkg.version, directTarget) &&
|
|
115
117
|
validatedFieldOk) {
|
|
116
|
-
const pkgWorkspaces = workspaceMap.get(finding.pkg
|
|
118
|
+
const pkgWorkspaces = workspaceMap.get(packageNameKey(finding.pkg))?.filter(w => w !== ".") ?? [];
|
|
117
119
|
upsertTarget(targetsByKey, finding, {
|
|
118
120
|
package: finding.pkg.name,
|
|
121
|
+
...(finding.pkg.registryName ? { registryName: finding.pkg.registryName } : {}),
|
|
119
122
|
currentVersion: finding.pkg.version,
|
|
120
123
|
targetVersion: directTarget,
|
|
121
124
|
scannedVersions: finding.validatedTargetScannedVersions ?? null,
|
|
@@ -140,7 +143,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
140
143
|
});
|
|
141
144
|
}
|
|
142
145
|
else if (finding.fixVersionValidationNote) {
|
|
143
|
-
skippedByKey.set(`${finding.relationship}:${finding.pkg
|
|
146
|
+
skippedByKey.set(`${finding.relationship}:${packageInstanceKey(finding.pkg)}`, {
|
|
144
147
|
package: finding.pkg.name,
|
|
145
148
|
version: finding.pkg.version,
|
|
146
149
|
relationship: finding.relationship,
|
|
@@ -149,7 +152,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
149
152
|
});
|
|
150
153
|
}
|
|
151
154
|
else if (finding.firstFixedVersion) {
|
|
152
|
-
skippedByKey.set(`${finding.relationship}:${finding.pkg
|
|
155
|
+
skippedByKey.set(`${finding.relationship}:${packageInstanceKey(finding.pkg)}`, {
|
|
153
156
|
package: finding.pkg.name,
|
|
154
157
|
version: finding.pkg.version,
|
|
155
158
|
relationship: finding.relationship,
|
|
@@ -157,7 +160,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
157
160
|
});
|
|
158
161
|
}
|
|
159
162
|
else {
|
|
160
|
-
skippedByKey.set(`${finding.relationship}:${finding.pkg
|
|
163
|
+
skippedByKey.set(`${finding.relationship}:${packageInstanceKey(finding.pkg)}`, {
|
|
161
164
|
package: finding.pkg.name,
|
|
162
165
|
version: finding.pkg.version,
|
|
163
166
|
relationship: finding.relationship,
|
|
@@ -169,7 +172,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
169
172
|
continue;
|
|
170
173
|
}
|
|
171
174
|
if (finding.relationship === "unknown") {
|
|
172
|
-
skippedByKey.set(`unknown:${finding.pkg
|
|
175
|
+
skippedByKey.set(`unknown:${packageInstanceKey(finding.pkg)}`, {
|
|
173
176
|
package: finding.pkg.name,
|
|
174
177
|
version: finding.pkg.version,
|
|
175
178
|
relationship: finding.relationship,
|
|
@@ -192,9 +195,21 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
192
195
|
// reason to re-resolve its subtree.
|
|
193
196
|
command: buildNpmUpdateCommand(finding.pkg.name, finding.recommendedNpmTransitiveRemediation.workspaces),
|
|
194
197
|
isDev: devLookup.get(`${finding.recommendedNpmTransitiveRemediation.package}@${finding.recommendedNpmTransitiveRemediation.currentVersion}`) ?? false,
|
|
198
|
+
workspaces: finding.recommendedNpmTransitiveRemediation.workspaces,
|
|
195
199
|
}));
|
|
196
200
|
continue;
|
|
197
201
|
}
|
|
202
|
+
// A parent upgrade that a direct dependency would undo is not a fix: that
|
|
203
|
+
// dependency keeps the vulnerable copy installed (#1457).
|
|
204
|
+
if (finding.relationship === "transitive" && finding.recommendedParentUpgrade && finding.parentUpgradeBlockers?.length) {
|
|
205
|
+
skippedByKey.set(`${finding.relationship}:${finding.pkg.name}@${finding.pkg.version}`, {
|
|
206
|
+
package: finding.pkg.name,
|
|
207
|
+
version: finding.pkg.version,
|
|
208
|
+
relationship: finding.relationship,
|
|
209
|
+
reason: formatParentUpgradeBlockedReason(finding),
|
|
210
|
+
});
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
198
213
|
if (packageManager === "npm" &&
|
|
199
214
|
finding.relationship === "transitive" &&
|
|
200
215
|
finding.recommendedNpmTransitiveRemediation?.kind === "upgrade-parent-to-version" &&
|
|
@@ -263,7 +278,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
263
278
|
continue;
|
|
264
279
|
}
|
|
265
280
|
if (finding.relationship === "transitive" && finding.recommendedParentUpgrade) {
|
|
266
|
-
skippedByKey.set(`${finding.relationship}:${finding.pkg
|
|
281
|
+
skippedByKey.set(`${finding.relationship}:${packageInstanceKey(finding.pkg)}`, {
|
|
267
282
|
package: finding.pkg.name,
|
|
268
283
|
version: finding.pkg.version,
|
|
269
284
|
relationship: finding.relationship,
|
|
@@ -277,14 +292,15 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
277
292
|
const lockfileRefreshCommand = packageManager === "pnpm"
|
|
278
293
|
? buildPnpmLockfileRefreshCommand(finding.pkg.name, finding.recommendedNpmTransitiveRemediation.workspaces)
|
|
279
294
|
: packageManager === "yarn"
|
|
280
|
-
?
|
|
281
|
-
:
|
|
295
|
+
? buildYarnUpgradeCommand(finding.pkg.name, finding.recommendedNpmTransitiveRemediation.workspaces)
|
|
296
|
+
: buildBunUpdateCommand(finding.pkg.name);
|
|
282
297
|
upsertTarget(targetsByKey, finding, parentUpdateTarget(finding, urgent, {
|
|
283
298
|
package: finding.pkg.name,
|
|
284
299
|
currentVersion: finding.pkg.version,
|
|
285
300
|
childTargetVersion: finding.recommendedNpmTransitiveRemediation.targetChildVersion,
|
|
286
301
|
reason: `${finding.pkg.name}@${finding.pkg.version} can be refreshed to ${finding.recommendedNpmTransitiveRemediation.targetChildVersion}+; no parent upgrade needed.`,
|
|
287
302
|
command: lockfileRefreshCommand,
|
|
303
|
+
workspaces: finding.recommendedNpmTransitiveRemediation?.workspaces,
|
|
288
304
|
}));
|
|
289
305
|
continue;
|
|
290
306
|
}
|
|
@@ -318,7 +334,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
318
334
|
const fixClause = fixHint
|
|
319
335
|
? ` - check for a release that resolves ${finding.pkg.name} to ${fixHint}+`
|
|
320
336
|
: "";
|
|
321
|
-
skippedByKey.set(`${finding.relationship}:${finding.pkg
|
|
337
|
+
skippedByKey.set(`${finding.relationship}:${packageInstanceKey(finding.pkg)}`, {
|
|
322
338
|
package: finding.pkg.name,
|
|
323
339
|
version: finding.pkg.version,
|
|
324
340
|
relationship: finding.relationship,
|
|
@@ -326,7 +342,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
326
342
|
});
|
|
327
343
|
continue;
|
|
328
344
|
}
|
|
329
|
-
skippedByKey.set(`${finding.relationship}:${finding.pkg
|
|
345
|
+
skippedByKey.set(`${finding.relationship}:${packageInstanceKey(finding.pkg)}`, {
|
|
330
346
|
package: finding.pkg.name,
|
|
331
347
|
version: finding.pkg.version,
|
|
332
348
|
relationship: finding.relationship,
|
|
@@ -350,10 +366,27 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
350
366
|
});
|
|
351
367
|
// Some install targets carry an explicit `command` built without workspace
|
|
352
368
|
// 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
|
-
//
|
|
369
|
+
// and embedded in the HTML report, so scope it to the declaring member too.
|
|
370
|
+
// Parent-update commands are rebuilt from the (possibly merged) workspace list
|
|
371
|
+
// so the printed plan matches what --fix will spawn.
|
|
355
372
|
for (const target of targets) {
|
|
356
|
-
if (target.kind
|
|
373
|
+
if (target.kind === "parent-update") {
|
|
374
|
+
const updatePkg = target.childPackage ?? target.package;
|
|
375
|
+
if (packageManager === "npm") {
|
|
376
|
+
target.command = buildNpmUpdateCommand(updatePkg, target.workspaces);
|
|
377
|
+
}
|
|
378
|
+
else if (packageManager === "pnpm") {
|
|
379
|
+
target.command = buildPnpmLockfileRefreshCommand(updatePkg, target.workspaces);
|
|
380
|
+
}
|
|
381
|
+
else if (packageManager === "yarn") {
|
|
382
|
+
target.command = buildYarnUpgradeCommand(updatePkg, target.workspaces);
|
|
383
|
+
}
|
|
384
|
+
else if (packageManager === "bun") {
|
|
385
|
+
target.command = buildBunUpdateCommand(updatePkg);
|
|
386
|
+
}
|
|
387
|
+
continue;
|
|
388
|
+
}
|
|
389
|
+
if (target.command && target.workspaces?.length) {
|
|
357
390
|
const scoped = buildWorkspaceInstallCommands([target], packageManager);
|
|
358
391
|
if (scoped.length > 0)
|
|
359
392
|
target.command = scoped.join(" && ");
|
|
@@ -408,36 +441,43 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
408
441
|
}
|
|
409
442
|
return plan;
|
|
410
443
|
}
|
|
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
444
|
function buildNpmUpdateCommand(pkg, workspaces) {
|
|
423
445
|
const nonRoot = (workspaces ?? []).filter(w => w !== ".");
|
|
446
|
+
const pkgQ = shellQuote(pkg);
|
|
424
447
|
if (nonRoot.length === 1) {
|
|
425
|
-
return `npm update --workspace=${nonRoot[0]} ${
|
|
448
|
+
return `npm update --workspace=${shellQuote(nonRoot[0])} ${pkgQ}`;
|
|
426
449
|
}
|
|
427
450
|
if (nonRoot.length > 1) {
|
|
428
|
-
return `npm update --workspaces ${
|
|
451
|
+
return `npm update --workspaces ${pkgQ}`;
|
|
429
452
|
}
|
|
430
|
-
return `npm update ${
|
|
453
|
+
return `npm update ${pkgQ}`;
|
|
431
454
|
}
|
|
432
455
|
function buildPnpmLockfileRefreshCommand(pkg, workspaces) {
|
|
456
|
+
const pkgQ = shellQuote(pkg);
|
|
433
457
|
if (!workspaces || workspaces.length === 0 || workspaces.length > 1) {
|
|
434
|
-
return `pnpm update --recursive --no-save ${
|
|
458
|
+
return `pnpm update --recursive --no-save ${pkgQ}`;
|
|
435
459
|
}
|
|
436
460
|
const workspace = workspaces[0];
|
|
437
461
|
if (workspace === ".") {
|
|
438
|
-
return `pnpm update --no-save ${
|
|
462
|
+
return `pnpm update --no-save ${pkgQ}`;
|
|
439
463
|
}
|
|
440
|
-
return `pnpm --filter
|
|
464
|
+
return `pnpm --filter ${shellQuote("./" + workspace)} update --no-save ${pkgQ}`;
|
|
465
|
+
}
|
|
466
|
+
function buildYarnUpgradeCommand(pkg, workspaces) {
|
|
467
|
+
const pkgQ = shellQuote(pkg);
|
|
468
|
+
const nonRoot = (workspaces ?? []).filter(w => w !== ".");
|
|
469
|
+
if (nonRoot.length === 0)
|
|
470
|
+
return `yarn upgrade ${pkgQ}`;
|
|
471
|
+
return nonRoot.map(ws => `yarn workspace ${shellQuote(ws)} upgrade ${pkgQ}`).join(" && ");
|
|
472
|
+
}
|
|
473
|
+
function buildBunUpdateCommand(pkg) {
|
|
474
|
+
return `bun update ${shellQuote(pkg)}`;
|
|
475
|
+
}
|
|
476
|
+
/** Quote a token for human-facing plan strings that users may paste into a shell. */
|
|
477
|
+
function shellQuote(token) {
|
|
478
|
+
if (/^[A-Za-z0-9_@%+./:=,-]+$/.test(token))
|
|
479
|
+
return token;
|
|
480
|
+
return "'" + token.replace(/'/g, "'\\''") + "'";
|
|
441
481
|
}
|
|
442
482
|
export function commandPrefix(packageManager) {
|
|
443
483
|
if (packageManager === "npm")
|
|
@@ -452,6 +492,10 @@ function devFlag(packageManager) {
|
|
|
452
492
|
return packageManager === "bun" ? "--dev" : "-D";
|
|
453
493
|
}
|
|
454
494
|
export function findFixTargetForFinding(plan, finding) {
|
|
495
|
+
// A sibling finding may share the parent upgrade, but a direct dependency
|
|
496
|
+
// keeps this copy installed, so no command in the plan fixes this one.
|
|
497
|
+
if (finding.recommendedParentUpgrade && finding.parentUpgradeBlockers?.length)
|
|
498
|
+
return null;
|
|
455
499
|
const target = plan.targets.find(item => {
|
|
456
500
|
if (finding.recommendedNpmTransitiveRemediation?.kind === "update-parent-within-range") {
|
|
457
501
|
const rem = finding.recommendedNpmTransitiveRemediation;
|
|
@@ -495,6 +539,9 @@ export function findFixTargetForFinding(plan, finding) {
|
|
|
495
539
|
const directTarget = finding.validatedFirstFixedVersion ?? finding.firstFixedVersion;
|
|
496
540
|
if (item.package !== finding.pkg.name)
|
|
497
541
|
return false;
|
|
542
|
+
if (registryPackageName({ name: item.package, registryName: item.registryName }) !== registryPackageName(finding.pkg)) {
|
|
543
|
+
return false;
|
|
544
|
+
}
|
|
498
545
|
// A transitive finding is only fixed through a remediation, and each kind of
|
|
499
546
|
// remediation has its own branch above. Falling through to here for one means
|
|
500
547
|
// nothing was resolved for it, so matching it against a direct install of the same
|
|
@@ -536,7 +583,7 @@ export function buildTargetCommand(target, packageManager) {
|
|
|
536
583
|
if (target.command)
|
|
537
584
|
return target.command;
|
|
538
585
|
const flag = target.isDev ? ` ${devFlag(packageManager)}` : "";
|
|
539
|
-
return `${commandPrefix(packageManager)}${flag} ${target
|
|
586
|
+
return `${commandPrefix(packageManager)}${flag} ${shellQuote(installPackageSpec(target))}`;
|
|
540
587
|
}
|
|
541
588
|
export function findSuggestedCommandForFinding(plan, finding) {
|
|
542
589
|
const target = findFixTargetForFinding(plan, finding);
|
|
@@ -577,7 +624,7 @@ function packageManagerSourceLabel(scanInput) {
|
|
|
577
624
|
function targetKey(finding, target) {
|
|
578
625
|
return target.kind === "parent-update"
|
|
579
626
|
? `parent-update:${target.package}>${finding.pkg.name}@${finding.pkg.version}`
|
|
580
|
-
: `install:${target.package}`;
|
|
627
|
+
: `install:${packageNameKey({ name: target.package, registryName: target.registryName })}`;
|
|
581
628
|
}
|
|
582
629
|
// Build a parent-update target whose targetVersion always belongs to `package`.
|
|
583
630
|
// When the named package is the parent of the finding, the child's version moves
|
|
@@ -587,6 +634,10 @@ function targetKey(finding, target) {
|
|
|
587
634
|
// the child's destination.
|
|
588
635
|
function parentUpdateTarget(finding, urgent, args) {
|
|
589
636
|
const namesParent = args.package !== finding.pkg.name;
|
|
637
|
+
// Keep "." in the list: pnpm treats a sole root workspace as a plain refresh
|
|
638
|
+
// (no --filter / no --recursive). Stripping it here collapsed that case into
|
|
639
|
+
// the empty-workspaces branch and emitted --recursive.
|
|
640
|
+
const workspaces = args.workspaces ?? [];
|
|
590
641
|
return {
|
|
591
642
|
package: args.package,
|
|
592
643
|
currentVersion: args.currentVersion,
|
|
@@ -604,6 +655,7 @@ function parentUpdateTarget(finding, urgent, args) {
|
|
|
604
655
|
command: args.command,
|
|
605
656
|
usage: finding.usage ?? null,
|
|
606
657
|
isDev: args.isDev,
|
|
658
|
+
workspaces: workspaces.length > 0 ? workspaces : undefined,
|
|
607
659
|
};
|
|
608
660
|
}
|
|
609
661
|
/**
|
|
@@ -854,16 +906,16 @@ function buildWorkspaceInstallCommands(targets, packageManager) {
|
|
|
854
906
|
for (const [targets, isDev] of [[prodTargets, false], [devTargets, true]]) {
|
|
855
907
|
if (targets.length === 0)
|
|
856
908
|
continue;
|
|
857
|
-
const pkgArgs = targets.map(t =>
|
|
909
|
+
const pkgArgs = targets.map(t => shellQuote(installPackageSpec(t))).join(" ");
|
|
858
910
|
const flag = isDev ? ` ${devFlag(packageManager)}` : "";
|
|
859
911
|
if (packageManager === "npm") {
|
|
860
|
-
const wsFlags = workspaces.map(ws => `-w ${ws}`).join(" ");
|
|
912
|
+
const wsFlags = workspaces.map(ws => `-w ${shellQuote(ws)}`).join(" ");
|
|
861
913
|
commands.push(`npm install${flag}${wsFlags ? " " + wsFlags : ""} ${pkgArgs}`);
|
|
862
914
|
}
|
|
863
915
|
else if (packageManager === "pnpm") {
|
|
864
916
|
// pnpm's --filter selector is a CLI-level flag that precedes the command
|
|
865
917
|
// (`pnpm --filter ./client add pkg`), not a trailing argument.
|
|
866
|
-
const wsFlags = workspaces.map(ws => `--filter
|
|
918
|
+
const wsFlags = workspaces.map(ws => `--filter ${shellQuote("./" + ws)}`).join(" ");
|
|
867
919
|
const prefix = wsFlags ? `pnpm ${wsFlags} add` : "pnpm add";
|
|
868
920
|
commands.push(`${prefix}${flag} ${pkgArgs}`);
|
|
869
921
|
}
|
|
@@ -873,12 +925,12 @@ function buildWorkspaceInstallCommands(targets, packageManager) {
|
|
|
873
925
|
}
|
|
874
926
|
else {
|
|
875
927
|
for (const ws of workspaces) {
|
|
876
|
-
commands.push(`yarn workspace ${ws} add${flag} ${pkgArgs}`);
|
|
928
|
+
commands.push(`yarn workspace ${shellQuote(ws)} add${flag} ${pkgArgs}`);
|
|
877
929
|
}
|
|
878
930
|
}
|
|
879
931
|
}
|
|
880
932
|
else if (packageManager === "bun") {
|
|
881
|
-
const wsFlags = workspaces.map(ws => `--filter ${ws}`).join(" ");
|
|
933
|
+
const wsFlags = workspaces.map(ws => `--filter ${shellQuote(ws)}`).join(" ");
|
|
882
934
|
commands.push(`bun add${flag}${wsFlags ? " " + wsFlags : ""} ${pkgArgs}`);
|
|
883
935
|
}
|
|
884
936
|
else {
|
|
@@ -899,7 +951,7 @@ function buildCommandForTargets(targets, packageManager) {
|
|
|
899
951
|
const updateCommands = explicitCommands.length > 0
|
|
900
952
|
? [...new Set(explicitCommands)]
|
|
901
953
|
: packageManager === "npm"
|
|
902
|
-
? [`npm update ${parentUpdateTargets.map(target => target.childPackage ?? target.package).join(" ")}`]
|
|
954
|
+
? [`npm update ${parentUpdateTargets.map(target => shellQuote(target.childPackage ?? target.package)).join(" ")}`]
|
|
903
955
|
: [];
|
|
904
956
|
commandParts.push(...updateCommands);
|
|
905
957
|
}
|
|
@@ -912,10 +964,10 @@ function buildCommandForTargets(targets, packageManager) {
|
|
|
912
964
|
const prodInstall = installTargets.filter(t => !t.isDev);
|
|
913
965
|
const devInstall = installTargets.filter(t => t.isDev);
|
|
914
966
|
if (prodInstall.length > 0) {
|
|
915
|
-
commandParts.push(`${commandPrefix(packageManager)} ${prodInstall.map(t =>
|
|
967
|
+
commandParts.push(`${commandPrefix(packageManager)} ${prodInstall.map(t => shellQuote(installPackageSpec(t))).join(" ")}`);
|
|
916
968
|
}
|
|
917
969
|
if (devInstall.length > 0) {
|
|
918
|
-
commandParts.push(`${commandPrefix(packageManager)} ${devFlag(packageManager)} ${devInstall.map(t =>
|
|
970
|
+
commandParts.push(`${commandPrefix(packageManager)} ${devFlag(packageManager)} ${devInstall.map(t => shellQuote(installPackageSpec(t))).join(" ")}`);
|
|
919
971
|
}
|
|
920
972
|
}
|
|
921
973
|
}
|
|
@@ -924,3 +976,12 @@ function buildCommandForTargets(targets, packageManager) {
|
|
|
924
976
|
function capitalize(value) {
|
|
925
977
|
return value.charAt(0).toUpperCase() + value.slice(1);
|
|
926
978
|
}
|
|
979
|
+
// Shared by the plan and the per-finding recommendation, so both say the same thing.
|
|
980
|
+
export function formatParentUpgradeBlockedReason(finding) {
|
|
981
|
+
const upgrade = finding.recommendedParentUpgrade;
|
|
982
|
+
const blockers = (finding.parentUpgradeBlockers ?? [])
|
|
983
|
+
.map(blocker => `${blocker.package}@${blocker.version} requires ${blocker.range}`)
|
|
984
|
+
.join(", ");
|
|
985
|
+
const parent = upgrade ? `${upgrade.package} to ${upgrade.targetVersion}` : "the parent";
|
|
986
|
+
return `Upgrading ${parent} alone leaves ${finding.pkg.name}@${finding.pkg.version} installed: ${blockers}. Those dependencies need upgrading too.`;
|
|
987
|
+
}
|
|
@@ -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
|
}
|