cve-lite-cli 1.34.0 → 1.35.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/dist/cli/advisories-init.js +13 -0
- package/dist/cli/advisories-sync.js +30 -0
- package/dist/cli/config-command.js +15 -0
- package/dist/cli/config.js +29 -0
- package/dist/cli/help.js +4 -4
- package/dist/cli/overrides.js +10 -1
- package/dist/constants.js +52 -0
- package/dist/index.js +25 -719
- package/dist/output/cyclonedx.js +12 -0
- package/dist/output/html-reporter.js +73 -38
- package/dist/output/multi-folder-html-reporter.js +16 -10
- package/dist/output/multi-folder-printer.js +1 -1
- package/dist/output/override-findings-sarif.js +1 -0
- package/dist/output/printers.js +427 -270
- package/dist/output/sarif.js +17 -1
- package/dist/output/sbom-dependency-edges.js +29 -19
- package/dist/overrides/admitted-scan.js +158 -0
- package/dist/overrides/api.js +16 -0
- package/dist/overrides/context-builder.js +4 -0
- package/dist/overrides/context.js +8 -1
- package/dist/overrides/detectors/index.js +2 -0
- package/dist/overrides/detectors/oa010-vulnerable-floor.js +123 -0
- package/dist/overrides/parsing/registry.js +53 -0
- package/dist/parsers/bun-lock-graph.js +182 -0
- package/dist/parsers/bun-lock.js +93 -132
- package/dist/parsers/index.js +75 -149
- package/dist/parsers/multi-package.js +5 -6
- package/dist/parsers/pnpm-lock-graph.js +94 -0
- package/dist/parsers/pnpm-lock.js +5 -5
- package/dist/parsers/yarn-lock-graph.js +148 -0
- package/dist/parsers/yarn-lock.js +3 -3
- package/dist/remediation/fix-commands.js +48 -7
- package/dist/scan/completeness.js +1 -1
- package/dist/scan/single-scan.js +643 -0
- package/dist/utils/file.js +11 -14
- package/dist/utils/version.js +10 -0
- package/package.json +1 -1
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
/**
|
|
3
|
+
* Key resolution for `bun.lock`.
|
|
4
|
+
*
|
|
5
|
+
* Bun encodes duplicate versions in the package key the way npm encodes them in
|
|
6
|
+
* `node_modules` nesting: the top-level copy is keyed `lru-cache`, and a copy
|
|
7
|
+
* hoisted under a specific parent is keyed `@babel/helper-compilation-targets/lru-cache`.
|
|
8
|
+
* A dependency declaration only ever names the bare package, so resolving a
|
|
9
|
+
* declaration to the entry it actually installs means walking outward from the
|
|
10
|
+
* declaring package, exactly like Node's resolution algorithm.
|
|
11
|
+
*
|
|
12
|
+
* The parser previously looked children up by bare name against a map keyed by
|
|
13
|
+
* these full keys, so any nested copy resolved to the top-level entry instead of
|
|
14
|
+
* itself. See #1116.
|
|
15
|
+
*/
|
|
16
|
+
/** Dependency sections of a lockfile entry that represent real installed edges. */
|
|
17
|
+
const DEPENDENCY_SECTIONS = ["dependencies", "optionalDependencies", "devDependencies"];
|
|
18
|
+
/**
|
|
19
|
+
* Splits a package key into the key of the package it is nested under and the
|
|
20
|
+
* bare name of the package itself.
|
|
21
|
+
*
|
|
22
|
+
* The trailing name may be scoped, so the split cannot simply take the last
|
|
23
|
+
* segment: `@cline/hub/@types/node` is `@types/node` nested under `@cline/hub`,
|
|
24
|
+
* while `@types/node` on its own is a top-level scoped package with no parent.
|
|
25
|
+
*/
|
|
26
|
+
export function splitBunPackageKey(key) {
|
|
27
|
+
const parts = key.split("/");
|
|
28
|
+
if (parts.length === 1)
|
|
29
|
+
return { parentKey: null, childName: key };
|
|
30
|
+
const scopedChild = parts[parts.length - 2].startsWith("@");
|
|
31
|
+
const childName = scopedChild ? parts.slice(-2).join("/") : parts[parts.length - 1];
|
|
32
|
+
const parentKey = (scopedChild ? parts.slice(0, -2) : parts.slice(0, -1)).join("/");
|
|
33
|
+
return { parentKey: parentKey === "" ? null : parentKey, childName };
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Resolves a dependency declared by `parentKey` to the package key that satisfies
|
|
37
|
+
* it, preferring the copy nested closest to the declaring package and falling
|
|
38
|
+
* back to the top-level copy. Returns null when no entry satisfies it, which
|
|
39
|
+
* happens for declarations Bun did not install (an unmet optional peer, say).
|
|
40
|
+
*/
|
|
41
|
+
export function resolveBunChildKey(parentKey, childName, keys) {
|
|
42
|
+
let scope = parentKey;
|
|
43
|
+
while (scope !== null) {
|
|
44
|
+
const candidate = `${scope}/${childName}`;
|
|
45
|
+
if (keys.has(candidate))
|
|
46
|
+
return candidate;
|
|
47
|
+
scope = splitBunPackageKey(scope).parentKey;
|
|
48
|
+
}
|
|
49
|
+
return keys.has(childName) ? childName : null;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Reads the dependency names declared by one lockfile entry's metadata object.
|
|
53
|
+
*
|
|
54
|
+
* Bun writes the named sections, but also inlines some dependencies as bare
|
|
55
|
+
* `name: range` pairs alongside them, so both shapes count.
|
|
56
|
+
*/
|
|
57
|
+
export function extractChildDependencyNames(depMeta) {
|
|
58
|
+
if (!depMeta || typeof depMeta !== "object")
|
|
59
|
+
return [];
|
|
60
|
+
const names = new Set();
|
|
61
|
+
const meta = depMeta;
|
|
62
|
+
for (const section of DEPENDENCY_SECTIONS) {
|
|
63
|
+
const sectionObj = meta[section];
|
|
64
|
+
if (!sectionObj || typeof sectionObj !== "object")
|
|
65
|
+
continue;
|
|
66
|
+
for (const name of Object.keys(sectionObj))
|
|
67
|
+
names.add(name);
|
|
68
|
+
}
|
|
69
|
+
for (const [key, value] of Object.entries(meta)) {
|
|
70
|
+
if (DEPENDENCY_SECTIONS.includes(key))
|
|
71
|
+
continue;
|
|
72
|
+
if (typeof value === "string")
|
|
73
|
+
names.add(key);
|
|
74
|
+
}
|
|
75
|
+
return [...names];
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Builds the package-key dependency graph: every entry mapped to the keys of the
|
|
79
|
+
* entries it actually installs.
|
|
80
|
+
*
|
|
81
|
+
* Unlike the bare-name map this replaces, two versions of the same package are
|
|
82
|
+
* distinct nodes here, so a path through one is never attributed to the other.
|
|
83
|
+
*/
|
|
84
|
+
export function buildBunChildKeyGraph(packages) {
|
|
85
|
+
const keys = new Set(Object.keys(packages));
|
|
86
|
+
const graph = new Map();
|
|
87
|
+
for (const [key, entry] of Object.entries(packages)) {
|
|
88
|
+
if (!Array.isArray(entry))
|
|
89
|
+
continue;
|
|
90
|
+
const resolved = new Set();
|
|
91
|
+
for (const childName of extractChildDependencyNames(entry[2])) {
|
|
92
|
+
const childKey = resolveBunChildKey(key, childName, keys);
|
|
93
|
+
if (childKey)
|
|
94
|
+
resolved.add(childKey);
|
|
95
|
+
}
|
|
96
|
+
graph.set(key, [...resolved]);
|
|
97
|
+
}
|
|
98
|
+
return graph;
|
|
99
|
+
}
|
|
100
|
+
/** Maps each package key to the name and version its entry resolves to. */
|
|
101
|
+
export function buildBunKeyIndex(packages) {
|
|
102
|
+
const index = new Map();
|
|
103
|
+
for (const [key, entry] of Object.entries(packages)) {
|
|
104
|
+
if (!Array.isArray(entry) || entry.length < 1)
|
|
105
|
+
continue;
|
|
106
|
+
const nameAtVersion = String(entry[0] ?? "");
|
|
107
|
+
const atIndex = nameAtVersion.lastIndexOf("@");
|
|
108
|
+
if (atIndex <= 0)
|
|
109
|
+
continue;
|
|
110
|
+
const name = nameAtVersion.slice(0, atIndex);
|
|
111
|
+
const version = nameAtVersion.slice(atIndex + 1);
|
|
112
|
+
if (!name || !version)
|
|
113
|
+
continue;
|
|
114
|
+
index.set(key, { name, version });
|
|
115
|
+
}
|
|
116
|
+
return index;
|
|
117
|
+
}
|
|
118
|
+
/** Walks the key graph from a set of roots and returns every reachable key. */
|
|
119
|
+
export function collectReachableKeys(rootKeys, graph) {
|
|
120
|
+
const reachable = new Set();
|
|
121
|
+
const stack = [...rootKeys];
|
|
122
|
+
while (stack.length > 0) {
|
|
123
|
+
const key = stack.pop();
|
|
124
|
+
if (reachable.has(key))
|
|
125
|
+
continue;
|
|
126
|
+
reachable.add(key);
|
|
127
|
+
for (const child of graph.get(key) ?? []) {
|
|
128
|
+
if (!reachable.has(child))
|
|
129
|
+
stack.push(child);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return reachable;
|
|
133
|
+
}
|
|
134
|
+
/** Reads and parses a bun.lock. Bun writes JSONC, so trailing commas are stripped. */
|
|
135
|
+
export function readAndParseBunLock(filePath) {
|
|
136
|
+
return JSON.parse(fs.readFileSync(filePath, "utf8").replace(/,(\s*[}\]])/g, "$1"));
|
|
137
|
+
}
|
|
138
|
+
const EMPTY = Object.freeze([]);
|
|
139
|
+
/**
|
|
140
|
+
* Builds the complete child-to-parents map for a bun.lock.
|
|
141
|
+
*
|
|
142
|
+
* The parser walks this same structure, but `collectBunPaths` caps it at five
|
|
143
|
+
* paths of at most ten segments per package. Rebuilding edges from those
|
|
144
|
+
* truncated paths loses routes on any sizeable tree, and a package whose
|
|
145
|
+
* surviving routes all traverse filtered-out packages ends up with no parent at
|
|
146
|
+
* all. This keeps every edge.
|
|
147
|
+
*
|
|
148
|
+
* Returns null for a lockfile it cannot read, so the caller falls back to
|
|
149
|
+
* path-derived behaviour rather than emitting an SBOM with no edges.
|
|
150
|
+
*/
|
|
151
|
+
export function loadBunLockGraph(filePath) {
|
|
152
|
+
const raw = readAndParseBunLock(filePath);
|
|
153
|
+
const packages = raw?.packages;
|
|
154
|
+
if (!packages || typeof packages !== "object")
|
|
155
|
+
return null;
|
|
156
|
+
const keyIndex = buildBunKeyIndex(packages);
|
|
157
|
+
const childGraph = buildBunChildKeyGraph(packages);
|
|
158
|
+
const parentsByKey = new Map();
|
|
159
|
+
for (const [parentKey, childKeys] of childGraph) {
|
|
160
|
+
for (const childKey of childKeys) {
|
|
161
|
+
const parents = parentsByKey.get(childKey);
|
|
162
|
+
if (!parents)
|
|
163
|
+
parentsByKey.set(childKey, [parentKey]);
|
|
164
|
+
else if (!parents.includes(parentKey))
|
|
165
|
+
parents.push(parentKey);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
const keysByNameVersion = new Map();
|
|
169
|
+
for (const [key, node] of keyIndex) {
|
|
170
|
+
const id = `${node.name}@${node.version}`;
|
|
171
|
+
const keys = keysByNameVersion.get(id);
|
|
172
|
+
if (!keys)
|
|
173
|
+
keysByNameVersion.set(id, [key]);
|
|
174
|
+
else
|
|
175
|
+
keys.push(key);
|
|
176
|
+
}
|
|
177
|
+
return {
|
|
178
|
+
nodeIdsFor: (name, version) => keysByNameVersion.get(`${name}@${version ?? ""}`) ?? EMPTY,
|
|
179
|
+
parentsFor: nodeId => parentsByKey.get(nodeId) ?? EMPTY,
|
|
180
|
+
getNode: nodeId => keyIndex.get(nodeId) ?? null,
|
|
181
|
+
};
|
|
182
|
+
}
|
package/dist/parsers/bun-lock.js
CHANGED
|
@@ -1,83 +1,112 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
1
|
import { uniquePathArrays } from "../utils/array.js";
|
|
3
2
|
import { upsertPackage } from "./utils.js";
|
|
3
|
+
import { buildBunChildKeyGraph, buildBunKeyIndex, collectReachableKeys, readAndParseBunLock, resolveBunChildKey, } from "./bun-lock-graph.js";
|
|
4
4
|
const MAX_PATHS_PER_PACKAGE = 5;
|
|
5
5
|
const MAX_PATH_DEPTH = 10;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
6
|
+
const DEPENDENCY_SECTIONS = ["dependencies", "optionalDependencies", "devDependencies"];
|
|
7
|
+
/**
|
|
8
|
+
* Builds the traversal seeds for a lockfile.
|
|
9
|
+
*
|
|
10
|
+
* Seeds come from every workspace, not just the root. A workspace member's
|
|
11
|
+
* dependencies hang off `["project", <member name>]` so a transitive reachable
|
|
12
|
+
* only through that member resolves back to it rather than appearing to be a
|
|
13
|
+
* direct dependency of the root. Seeding from the root alone left anything
|
|
14
|
+
* declared by a member unvisited, which on a real monorepo is most of the tree
|
|
15
|
+
* (#1116).
|
|
16
|
+
*
|
|
17
|
+
* Each seed records whether its declaring edge was a devDependency, which drives
|
|
18
|
+
* the reachability-based dev classification below.
|
|
19
|
+
*/
|
|
20
|
+
function buildBunSeeds(workspaces, keys) {
|
|
21
|
+
const seeds = [];
|
|
22
|
+
for (const [workspacePath, workspace] of Object.entries(workspaces)) {
|
|
23
|
+
const workspaceName = typeof workspace?.name === "string" ? workspace.name : "";
|
|
24
|
+
const isRoot = workspacePath === "" || workspaceName === "";
|
|
25
|
+
const path = isRoot ? ["project"] : ["project", workspaceName];
|
|
26
|
+
// A member's own dependencies may be nested under its package key, so resolve
|
|
27
|
+
// from there when the member is itself an entry in the lockfile.
|
|
28
|
+
const scope = keys.has(workspaceName) ? workspaceName : null;
|
|
29
|
+
for (const section of DEPENDENCY_SECTIONS) {
|
|
30
|
+
const depSection = workspace?.[section];
|
|
31
|
+
if (!depSection || typeof depSection !== "object")
|
|
32
|
+
continue;
|
|
33
|
+
const dev = section === "devDependencies";
|
|
34
|
+
for (const depName of Object.keys(depSection)) {
|
|
35
|
+
const key = resolveBunChildKey(scope, depName, keys);
|
|
36
|
+
if (key)
|
|
37
|
+
seeds.push({ key, path, dev });
|
|
38
|
+
}
|
|
28
39
|
}
|
|
29
40
|
}
|
|
30
|
-
return
|
|
41
|
+
return seeds;
|
|
31
42
|
}
|
|
32
|
-
|
|
33
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Records a dependency path for every package reachable from the seeds.
|
|
45
|
+
*
|
|
46
|
+
* The walk is keyed by package key rather than bare name, so two versions of the
|
|
47
|
+
* same package accumulate their own paths instead of collapsing onto whichever
|
|
48
|
+
* one happened to sit at the top level.
|
|
49
|
+
*/
|
|
50
|
+
function collectBunPaths(seeds, graph, keyIndex, map) {
|
|
51
|
+
const queue = seeds.map(seed => ({ key: seed.key, path: seed.path }));
|
|
34
52
|
const visitedStates = new Set();
|
|
35
53
|
let head = 0;
|
|
36
54
|
while (head < queue.length) {
|
|
37
55
|
const current = queue[head++];
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
56
|
+
const entry = keyIndex.get(current.key);
|
|
57
|
+
if (!entry)
|
|
58
|
+
continue;
|
|
59
|
+
const nextPath = [...current.path, entry.name];
|
|
60
|
+
const stateKey = `${current.key}>${nextPath.join(">")}`;
|
|
41
61
|
if (visitedStates.has(stateKey))
|
|
42
62
|
continue;
|
|
43
63
|
visitedStates.add(stateKey);
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
pkg.paths = uniquePathArrays([...(pkg.paths ?? []), nextPath]).slice(0, MAX_PATHS_PER_PACKAGE);
|
|
48
|
-
}
|
|
64
|
+
const pkg = map.get(`${entry.name}@${entry.version}`);
|
|
65
|
+
if (pkg) {
|
|
66
|
+
pkg.paths = uniquePathArrays([...(pkg.paths ?? []), nextPath]).slice(0, MAX_PATHS_PER_PACKAGE);
|
|
49
67
|
}
|
|
50
68
|
if (nextPath.length >= MAX_PATH_DEPTH)
|
|
51
69
|
continue;
|
|
52
|
-
for (const child of
|
|
53
|
-
queue.push({
|
|
70
|
+
for (const child of graph.get(current.key) ?? []) {
|
|
71
|
+
queue.push({ key: child, path: nextPath });
|
|
54
72
|
}
|
|
55
73
|
}
|
|
56
74
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
75
|
+
/**
|
|
76
|
+
* Creates one package ref per lockfile entry, classifying dev vs prod by graph
|
|
77
|
+
* reachability: a package is dev when it is reachable from a devDependency seed
|
|
78
|
+
* but from no production seed. Reachability is computed over package keys, so a
|
|
79
|
+
* nested copy is classified on its own merits.
|
|
80
|
+
*/
|
|
81
|
+
function createPackageRefs(packages, keyIndex, prodReachable, devReachable, prodOnly, map) {
|
|
82
|
+
for (const [key, entry] of Object.entries(packages)) {
|
|
83
|
+
const parsed = keyIndex.get(key);
|
|
84
|
+
if (!parsed)
|
|
66
85
|
continue;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
86
|
+
const dev = devReachable.has(key) && !prodReachable.has(key);
|
|
87
|
+
if (prodOnly && dev)
|
|
88
|
+
continue;
|
|
89
|
+
const resolvedUrl = typeof entry[1] === "string" && entry[1] !== "" ? entry[1] : undefined;
|
|
90
|
+
upsertPackage(map, {
|
|
91
|
+
name: parsed.name,
|
|
92
|
+
version: parsed.version,
|
|
93
|
+
ecosystem: "npm",
|
|
94
|
+
dev,
|
|
95
|
+
paths: [],
|
|
96
|
+
resolvedUrl,
|
|
97
|
+
});
|
|
72
98
|
}
|
|
73
|
-
return reachable;
|
|
74
99
|
}
|
|
75
100
|
export function buildBunWorkspaceMap(filePath) {
|
|
76
|
-
const raw =
|
|
101
|
+
const raw = readAndParseBunLock(filePath);
|
|
77
102
|
const workspaces = raw?.workspaces ?? {};
|
|
78
103
|
const map = new Map();
|
|
79
|
-
for (const [
|
|
80
|
-
|
|
104
|
+
for (const [rawWorkspacePath, workspace] of Object.entries(workspaces)) {
|
|
105
|
+
// Bun keys the root workspace "", where npm keys it "" and normalises to ".".
|
|
106
|
+
// Consumers drop the root with `w !== "."`, so an unnormalised "" survives and
|
|
107
|
+
// renders as a valueless `--filter ` in the fix command.
|
|
108
|
+
const workspacePath = rawWorkspacePath === "" ? "." : rawWorkspacePath;
|
|
109
|
+
for (const depSectionName of DEPENDENCY_SECTIONS) {
|
|
81
110
|
const depSection = workspace?.[depSectionName];
|
|
82
111
|
if (!depSection || typeof depSection !== "object")
|
|
83
112
|
continue;
|
|
@@ -92,87 +121,19 @@ export function buildBunWorkspaceMap(filePath) {
|
|
|
92
121
|
return map;
|
|
93
122
|
}
|
|
94
123
|
export function loadFromBunLock(filePath, prodOnly) {
|
|
95
|
-
const raw =
|
|
124
|
+
const raw = readAndParseBunLock(filePath);
|
|
96
125
|
const packages = raw?.packages ?? {};
|
|
97
126
|
const workspaces = raw?.workspaces ?? {};
|
|
127
|
+
const keys = new Set(Object.keys(packages));
|
|
128
|
+
const keyIndex = buildBunKeyIndex(packages);
|
|
129
|
+
const graph = buildBunChildKeyGraph(packages);
|
|
130
|
+
const seeds = buildBunSeeds(workspaces, keys);
|
|
131
|
+
const prodReachable = collectReachableKeys(seeds.filter(seed => !seed.dev).map(seed => seed.key), graph);
|
|
132
|
+
const devReachable = collectReachableKeys(seeds.filter(seed => seed.dev).map(seed => seed.key), graph);
|
|
98
133
|
const map = new Map();
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const
|
|
102
|
-
const devRootNames = new Set();
|
|
103
|
-
const rootDepNames = [];
|
|
104
|
-
for (const workspace of Object.values(workspaces)) {
|
|
105
|
-
for (const name of Object.keys(workspace?.dependencies ?? {})) {
|
|
106
|
-
prodRootNames.add(name);
|
|
107
|
-
}
|
|
108
|
-
for (const name of Object.keys(workspace?.optionalDependencies ?? {})) {
|
|
109
|
-
prodRootNames.add(name);
|
|
110
|
-
}
|
|
111
|
-
for (const name of Object.keys(workspace?.devDependencies ?? {})) {
|
|
112
|
-
devRootNames.add(name);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
for (const [workspacePath, workspace] of Object.entries(workspaces)) {
|
|
116
|
-
if (workspacePath !== "")
|
|
117
|
-
continue;
|
|
118
|
-
for (const depSectionName of ["dependencies", "optionalDependencies", "devDependencies"]) {
|
|
119
|
-
if (prodOnly && depSectionName === "devDependencies")
|
|
120
|
-
continue;
|
|
121
|
-
const depSection = workspace?.[depSectionName];
|
|
122
|
-
if (!depSection || typeof depSection !== "object")
|
|
123
|
-
continue;
|
|
124
|
-
for (const depName of Object.keys(depSection)) {
|
|
125
|
-
rootDepNames.push(depName);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
// First pass: build the package graph (package key -> version, package key -> child dep names).
|
|
130
|
-
for (const [pkgName, entry] of Object.entries(packages)) {
|
|
131
|
-
if (!Array.isArray(entry) || entry.length < 1)
|
|
132
|
-
continue;
|
|
133
|
-
const nameAtVersion = String(entry[0] ?? "");
|
|
134
|
-
const atIndex = nameAtVersion.lastIndexOf("@");
|
|
135
|
-
if (atIndex <= 0)
|
|
136
|
-
continue;
|
|
137
|
-
const version = nameAtVersion.slice(atIndex + 1);
|
|
138
|
-
if (!version)
|
|
139
|
-
continue;
|
|
140
|
-
packageNameToVersion.set(pkgName, version);
|
|
141
|
-
childDepsByPackageName.set(pkgName, extractChildDependencyNames(entry[2]));
|
|
142
|
-
}
|
|
143
|
-
// Classify dev vs prod by graph reachability rather than by direct declaration only: a
|
|
144
|
-
// package is dev when it is reachable from a devDependency root but not from any production
|
|
145
|
-
// (dependencies/optionalDependencies) root. This correctly marks a transitive pulled in only
|
|
146
|
-
// through a devDependency as dev, while keeping any package used in production anywhere prod.
|
|
147
|
-
const prodReachable = collectReachableNames(prodRootNames, childDepsByPackageName);
|
|
148
|
-
const devReachable = collectReachableNames(devRootNames, childDepsByPackageName);
|
|
149
|
-
// Second pass: create package refs with the reachability-based dev flag.
|
|
150
|
-
for (const [, entry] of Object.entries(packages)) {
|
|
151
|
-
if (!Array.isArray(entry) || entry.length < 1)
|
|
152
|
-
continue;
|
|
153
|
-
const nameAtVersion = String(entry[0] ?? "");
|
|
154
|
-
const atIndex = nameAtVersion.lastIndexOf("@");
|
|
155
|
-
if (atIndex <= 0)
|
|
156
|
-
continue;
|
|
157
|
-
const name = nameAtVersion.slice(0, atIndex);
|
|
158
|
-
const version = nameAtVersion.slice(atIndex + 1);
|
|
159
|
-
if (!name || !version)
|
|
160
|
-
continue;
|
|
161
|
-
const dev = devReachable.has(name) && !prodReachable.has(name);
|
|
162
|
-
if (prodOnly && dev)
|
|
163
|
-
continue;
|
|
164
|
-
const resolvedUrl = typeof entry[1] === "string" && entry[1] !== "" ? entry[1] : undefined;
|
|
165
|
-
upsertPackage(map, {
|
|
166
|
-
name,
|
|
167
|
-
version,
|
|
168
|
-
ecosystem: "npm",
|
|
169
|
-
dev,
|
|
170
|
-
paths: [],
|
|
171
|
-
resolvedUrl,
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
collectBunPaths(rootDepNames, childDepsByPackageName, map, packageNameToVersion);
|
|
175
|
-
for (const [pkgKey, pkg] of map.entries()) {
|
|
134
|
+
createPackageRefs(packages, keyIndex, prodReachable, devReachable, prodOnly, map);
|
|
135
|
+
collectBunPaths(prodOnly ? seeds.filter(seed => !seed.dev) : seeds, graph, keyIndex, map);
|
|
136
|
+
for (const pkg of map.values()) {
|
|
176
137
|
if ((pkg.paths?.length ?? 0) === 0) {
|
|
177
138
|
pkg.paths = [["project", pkg.name]];
|
|
178
139
|
}
|