@pnpm/reviewing.dependencies-hierarchy 1001.2.5 → 1001.2.7
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/lib/PackageNode.d.ts +6 -0
- package/lib/TreeNodeId.js +2 -0
- package/lib/TreeNodeId.js.map +1 -1
- package/lib/buildDependenciesHierarchy.d.ts +1 -0
- package/lib/buildDependenciesHierarchy.js +38 -19
- package/lib/buildDependenciesHierarchy.js.map +1 -1
- package/lib/buildDependencyGraph.d.ts +29 -0
- package/lib/buildDependencyGraph.js +70 -0
- package/lib/buildDependencyGraph.js.map +1 -0
- package/lib/getPkgInfo.d.ts +11 -0
- package/lib/getPkgInfo.js +33 -1
- package/lib/getPkgInfo.js.map +1 -1
- package/lib/getTree.d.ts +25 -1
- package/lib/getTree.js +161 -143
- package/lib/getTree.js.map +1 -1
- package/package.json +6 -6
- package/lib/DependenciesCache.d.ts +0 -76
- package/lib/DependenciesCache.js +0 -83
- package/lib/DependenciesCache.js.map +0 -1
package/lib/PackageNode.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
export interface PackageNode {
|
|
2
2
|
alias: string;
|
|
3
3
|
circular?: true;
|
|
4
|
+
deduped?: true;
|
|
5
|
+
/**
|
|
6
|
+
* When `deduped` is true, the number of transitive dependencies that were
|
|
7
|
+
* elided because this subtree was already expanded elsewhere in the tree.
|
|
8
|
+
*/
|
|
9
|
+
dedupedDependenciesCount?: number;
|
|
4
10
|
dependencies?: PackageNode[];
|
|
5
11
|
dev?: boolean;
|
|
6
12
|
isPeer: boolean;
|
package/lib/TreeNodeId.js
CHANGED
|
@@ -13,6 +13,8 @@ function serializeTreeNodeId(treeNodeId) {
|
|
|
13
13
|
const { type, depPath } = treeNodeId;
|
|
14
14
|
return JSON.stringify({ type, depPath });
|
|
15
15
|
}
|
|
16
|
+
default:
|
|
17
|
+
throw new Error(`Unknown TreeNodeId type: ${treeNodeId.type}`);
|
|
16
18
|
}
|
|
17
19
|
}
|
|
18
20
|
//# sourceMappingURL=TreeNodeId.js.map
|
package/lib/TreeNodeId.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeNodeId.js","sourceRoot":"","sources":["../src/TreeNodeId.ts"],"names":[],"mappings":";;AAoBA,
|
|
1
|
+
{"version":3,"file":"TreeNodeId.js","sourceRoot":"","sources":["../src/TreeNodeId.ts"],"names":[],"mappings":";;AAoBA,kDAeC;AAfD,SAAgB,mBAAmB,CAAE,UAAsB;IACzD,QAAQ,UAAU,CAAC,IAAI,EAAE,CAAC;QAC1B,KAAK,UAAU,CAAC,CAAC,CAAC;YAChB,4EAA4E;YAC5E,uDAAuD;YACvD,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,UAAU,CAAA;YACvC,OAAO,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAA;QAC7C,CAAC;QACD,KAAK,SAAS,CAAC,CAAC,CAAC;YACf,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,UAAU,CAAA;YACpC,OAAO,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAA;QAC1C,CAAC;QACD;YACE,MAAM,IAAI,KAAK,CAAC,4BAA6B,UAA+B,CAAC,IAAI,EAAE,CAAC,CAAA;IACtF,CAAC;AACH,CAAC"}
|
|
@@ -15,6 +15,7 @@ export declare function buildDependenciesHierarchy(projectPaths: string[] | unde
|
|
|
15
15
|
registries?: Registries;
|
|
16
16
|
onlyProjects?: boolean;
|
|
17
17
|
search?: Finder;
|
|
18
|
+
showDedupedSearchMatches?: boolean;
|
|
18
19
|
lockfileDir: string;
|
|
19
20
|
checkWantedLockfileOnly?: boolean;
|
|
20
21
|
modulesDir?: string;
|
|
@@ -15,6 +15,7 @@ const types_1 = require("@pnpm/types");
|
|
|
15
15
|
const normalize_path_1 = __importDefault(require("normalize-path"));
|
|
16
16
|
const realpath_missing_1 = __importDefault(require("realpath-missing"));
|
|
17
17
|
const resolve_link_target_1 = __importDefault(require("resolve-link-target"));
|
|
18
|
+
const buildDependencyGraph_js_1 = require("./buildDependencyGraph.js");
|
|
18
19
|
const getTree_js_1 = require("./getTree.js");
|
|
19
20
|
const getTreeNodeChildId_js_1 = require("./getTreeNodeChildId.js");
|
|
20
21
|
const getPkgInfo_js_1 = require("./getPkgInfo.js");
|
|
@@ -56,8 +57,9 @@ async function buildDependenciesHierarchy(projectPaths, maybeOpts) {
|
|
|
56
57
|
onlyProjects: maybeOpts.onlyProjects,
|
|
57
58
|
registries,
|
|
58
59
|
search: maybeOpts.search,
|
|
60
|
+
showDedupedSearchMatches: maybeOpts.showDedupedSearchMatches,
|
|
59
61
|
skipped: new Set(modules?.skipped ?? []),
|
|
60
|
-
modulesDir
|
|
62
|
+
modulesDir,
|
|
61
63
|
virtualStoreDir: modules?.virtualStoreDir,
|
|
62
64
|
virtualStoreDirMaxLength: modules?.virtualStoreDirMaxLength ?? maybeOpts.virtualStoreDirMaxLength,
|
|
63
65
|
};
|
|
@@ -76,16 +78,20 @@ async function dependenciesHierarchyForPackage(projectPath, currentLockfile, wan
|
|
|
76
78
|
const importerId = (0, lockfile_fs_1.getLockfileImporterId)(opts.lockfileDir, projectPath);
|
|
77
79
|
if (!currentLockfile.importers[importerId])
|
|
78
80
|
return {};
|
|
79
|
-
const modulesDir = path_1.default.
|
|
81
|
+
const modulesDir = opts.modulesDir && path_1.default.isAbsolute(opts.modulesDir)
|
|
82
|
+
? opts.modulesDir
|
|
83
|
+
: path_1.default.join(projectPath, opts.modulesDir ?? 'node_modules');
|
|
80
84
|
const savedDeps = getAllDirectDependencies(currentLockfile.importers[importerId]);
|
|
81
85
|
const allDirectDeps = await (0, read_modules_dir_1.readModulesDir)(modulesDir) ?? [];
|
|
82
86
|
const unsavedDeps = allDirectDeps.filter((directDep) => !savedDeps[directDep]);
|
|
83
87
|
const depTypes = (0, lockfile_detect_dep_types_1.detectDepTypes)(currentLockfile);
|
|
84
|
-
const
|
|
85
|
-
|
|
88
|
+
const currentPackages = currentLockfile.packages ?? {};
|
|
89
|
+
const wantedPackages = wantedLockfile?.packages ?? {};
|
|
90
|
+
const getTreeOpts = {
|
|
91
|
+
currentPackages,
|
|
86
92
|
excludePeerDependencies: opts.excludePeerDependencies,
|
|
87
93
|
importers: currentLockfile.importers,
|
|
88
|
-
|
|
94
|
+
include: opts.include,
|
|
89
95
|
depTypes,
|
|
90
96
|
lockfileDir: opts.lockfileDir,
|
|
91
97
|
onlyProjects: opts.onlyProjects,
|
|
@@ -93,12 +99,24 @@ async function dependenciesHierarchyForPackage(projectPath, currentLockfile, wan
|
|
|
93
99
|
maxDepth: opts.depth,
|
|
94
100
|
registries: opts.registries,
|
|
95
101
|
search: opts.search,
|
|
102
|
+
showDedupedSearchMatches: opts.showDedupedSearchMatches,
|
|
96
103
|
skipped: opts.skipped,
|
|
97
|
-
wantedPackages
|
|
104
|
+
wantedPackages,
|
|
98
105
|
virtualStoreDir: opts.virtualStoreDir,
|
|
99
106
|
virtualStoreDirMaxLength: opts.virtualStoreDirMaxLength,
|
|
100
|
-
|
|
107
|
+
modulesDir,
|
|
108
|
+
};
|
|
101
109
|
const parentId = { type: 'importer', importerId };
|
|
110
|
+
// Build ONE shared graph and cache for the entire project, reused
|
|
111
|
+
// across all dependency fields and top-level deps.
|
|
112
|
+
const graph = (0, buildDependencyGraph_js_1.buildDependencyGraph)(parentId, {
|
|
113
|
+
currentPackages,
|
|
114
|
+
importers: currentLockfile.importers,
|
|
115
|
+
include: opts.include,
|
|
116
|
+
lockfileDir: opts.lockfileDir,
|
|
117
|
+
});
|
|
118
|
+
const materializationCache = new Map();
|
|
119
|
+
const getChildrenTree = (nodeId, parentDir) => (0, getTree_js_1.getTree)({ ...getTreeOpts, parentDir, graph, materializationCache }, nodeId);
|
|
102
120
|
const result = {};
|
|
103
121
|
for (const dependenciesField of types_1.DEPENDENCIES_FIELDS.sort().filter(dependenciesField => opts.include[dependenciesField])) {
|
|
104
122
|
const topDeps = currentLockfile.importers[importerId][dependenciesField] ?? {};
|
|
@@ -117,9 +135,10 @@ async function dependenciesHierarchyForPackage(projectPath, currentLockfile, wan
|
|
|
117
135
|
wantedPackages: wantedLockfile?.packages ?? {},
|
|
118
136
|
virtualStoreDir: opts.virtualStoreDir,
|
|
119
137
|
virtualStoreDirMaxLength: opts.virtualStoreDirMaxLength,
|
|
138
|
+
modulesDir,
|
|
120
139
|
});
|
|
121
140
|
let newEntry = null;
|
|
122
|
-
const
|
|
141
|
+
const searchMatch = opts.search?.({
|
|
123
142
|
alias,
|
|
124
143
|
name: packageInfo.name,
|
|
125
144
|
version: packageInfo.version,
|
|
@@ -135,27 +154,27 @@ async function dependenciesHierarchyForPackage(projectPath, currentLockfile, wan
|
|
|
135
154
|
continue;
|
|
136
155
|
}
|
|
137
156
|
else if (nodeId == null) {
|
|
138
|
-
if ((opts.search != null) && !
|
|
157
|
+
if ((opts.search != null) && !searchMatch)
|
|
139
158
|
continue;
|
|
140
159
|
newEntry = packageInfo;
|
|
141
160
|
}
|
|
142
161
|
else {
|
|
143
|
-
const dependencies = getChildrenTree(nodeId);
|
|
162
|
+
const dependencies = getChildrenTree(nodeId, packageInfo.path);
|
|
144
163
|
if (dependencies.length > 0) {
|
|
145
164
|
newEntry = {
|
|
146
165
|
...packageInfo,
|
|
147
166
|
dependencies,
|
|
148
167
|
};
|
|
149
168
|
}
|
|
150
|
-
else if ((opts.search == null) ||
|
|
169
|
+
else if ((opts.search == null) || searchMatch) {
|
|
151
170
|
newEntry = packageInfo;
|
|
152
171
|
}
|
|
153
172
|
}
|
|
154
173
|
if (newEntry != null) {
|
|
155
|
-
if (
|
|
174
|
+
if (searchMatch) {
|
|
156
175
|
newEntry.searched = true;
|
|
157
|
-
if (typeof
|
|
158
|
-
newEntry.searchMessage =
|
|
176
|
+
if (typeof searchMatch === 'string') {
|
|
177
|
+
newEntry.searchMessage = searchMatch;
|
|
159
178
|
}
|
|
160
179
|
}
|
|
161
180
|
result[dependenciesField].push(newEntry);
|
|
@@ -183,19 +202,19 @@ async function dependenciesHierarchyForPackage(projectPath, currentLockfile, wan
|
|
|
183
202
|
path: pkgPath,
|
|
184
203
|
version,
|
|
185
204
|
};
|
|
186
|
-
const
|
|
205
|
+
const searchMatch = opts.search?.({
|
|
187
206
|
alias: pkg.alias,
|
|
188
207
|
name: pkg.name,
|
|
189
208
|
version: pkg.version,
|
|
190
209
|
readManifest: () => (0, read_package_json_1.readPackageJsonFromDirSync)(pkgPath),
|
|
191
210
|
});
|
|
192
|
-
if ((opts.search != null) && !
|
|
211
|
+
if ((opts.search != null) && !searchMatch)
|
|
193
212
|
return;
|
|
194
213
|
const newEntry = pkg;
|
|
195
|
-
if (
|
|
214
|
+
if (searchMatch) {
|
|
196
215
|
newEntry.searched = true;
|
|
197
|
-
if (typeof
|
|
198
|
-
newEntry.searchMessage =
|
|
216
|
+
if (typeof searchMatch === 'string') {
|
|
217
|
+
newEntry.searchMessage = searchMatch;
|
|
199
218
|
}
|
|
200
219
|
}
|
|
201
220
|
result.unsavedDependencies = result.unsavedDependencies ?? [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildDependenciesHierarchy.js","sourceRoot":"","sources":["../src/buildDependenciesHierarchy.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"buildDependenciesHierarchy.js","sourceRoot":"","sources":["../src/buildDependenciesHierarchy.ts"],"names":[],"mappings":";;;;;AAgCA,gEAyEC;AAzGD,gDAAuB;AACvB,mDAO0B;AAC1B,+EAAgE;AAChE,qDAAwD;AACxD,qEAAgE;AAChE,6DAAuD;AACvD,+DAAgG;AAChG,uCAAuG;AACvG,oEAA0C;AAC1C,wEAA8C;AAC9C,8EAAmD;AAEnD,uEAAgE;AAChE,6CAAiE;AACjE,mEAA4D;AAC5D,mDAA4C;AAUrC,KAAK,UAAU,0BAA0B,CAC9C,YAAkC,EAClC,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AAE,KAAK;YAChB,IAAI,EAAE,UAAU;YAChB,IAAI,EAAE,OAAO;YACb,OAAO;SACR,CAAA;QACD,MAAM,WAAW,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;YAChC,KAAK,EAAE,GAAG,CAAC,KAAK;YAChB,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,YAAY,EAAE,GAAG,EAAE,CAAC,IAAA,8CAA0B,EAAC,OAAO,CAAC;SACxD,CAAC,CAAA;QACF,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,IAAI,CAAC,WAAW;YAAE,OAAM;QACjD,MAAM,QAAQ,GAAgB,GAAG,CAAA;QACjC,IAAI,WAAW,EAAE,CAAC;YAChB,QAAQ,CAAC,QAAQ,GAAG,IAAI,CAAA;YACxB,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE,CAAC;gBACpC,QAAQ,CAAC,aAAa,GAAG,WAAW,CAAA;YACtC,CAAC;QACH,CAAC;QACD,MAAM,CAAC,mBAAmB,GAAG,MAAM,CAAC,mBAAmB,IAAI,EAAE,CAAA;QAC7D,MAAM,CAAC,mBAAmB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IAC3C,CAAC,CAAC,CACH,CAAA;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AAED,SAAS,wBAAwB,CAAE,eAAgC;IACjE,OAAO;QACL,GAAG,eAAe,CAAC,YAAY;QAC/B,GAAG,eAAe,CAAC,eAAe;QAClC,GAAG,eAAe,CAAC,oBAAoB;KACxC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type PackageSnapshots, type ProjectSnapshot } from '@pnpm/lockfile.fs';
|
|
2
|
+
import { type TreeNodeId } from './TreeNodeId.js';
|
|
3
|
+
interface DependencyEdge {
|
|
4
|
+
alias: string;
|
|
5
|
+
ref: string;
|
|
6
|
+
target?: {
|
|
7
|
+
id: string;
|
|
8
|
+
nodeId: TreeNodeId;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
interface DependencyGraphNode {
|
|
12
|
+
nodeId: TreeNodeId;
|
|
13
|
+
edges: DependencyEdge[];
|
|
14
|
+
peers: Set<string>;
|
|
15
|
+
}
|
|
16
|
+
export interface DependencyGraph {
|
|
17
|
+
nodes: Map<string, DependencyGraphNode>;
|
|
18
|
+
}
|
|
19
|
+
export declare function buildDependencyGraph(rootId: TreeNodeId, opts: {
|
|
20
|
+
currentPackages: PackageSnapshots;
|
|
21
|
+
importers: Record<string, ProjectSnapshot>;
|
|
22
|
+
include: {
|
|
23
|
+
dependencies?: boolean;
|
|
24
|
+
devDependencies?: boolean;
|
|
25
|
+
optionalDependencies?: boolean;
|
|
26
|
+
};
|
|
27
|
+
lockfileDir: string;
|
|
28
|
+
}): DependencyGraph;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildDependencyGraph = buildDependencyGraph;
|
|
4
|
+
const getTreeNodeChildId_js_1 = require("./getTreeNodeChildId.js");
|
|
5
|
+
const TreeNodeId_js_1 = require("./TreeNodeId.js");
|
|
6
|
+
function buildDependencyGraph(rootId, opts) {
|
|
7
|
+
const graph = { nodes: new Map() };
|
|
8
|
+
const queue = [rootId];
|
|
9
|
+
let queueIdx = 0;
|
|
10
|
+
const visited = new Set();
|
|
11
|
+
while (queueIdx < queue.length) {
|
|
12
|
+
const nodeId = queue[queueIdx++];
|
|
13
|
+
const serialized = (0, TreeNodeId_js_1.serializeTreeNodeId)(nodeId);
|
|
14
|
+
if (visited.has(serialized))
|
|
15
|
+
continue;
|
|
16
|
+
visited.add(serialized);
|
|
17
|
+
const snapshot = getSnapshot(nodeId, opts);
|
|
18
|
+
if (!snapshot) {
|
|
19
|
+
graph.nodes.set(serialized, { nodeId, edges: [], peers: new Set() });
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
// For importers, only include the dependency fields the caller selected.
|
|
23
|
+
// For packages, devDependencies don't exist in the lockfile.
|
|
24
|
+
const deps = nodeId.type === 'importer'
|
|
25
|
+
? {
|
|
26
|
+
...(opts.include.dependencies !== false ? snapshot.dependencies : undefined),
|
|
27
|
+
...(opts.include.devDependencies !== false ? snapshot.devDependencies : undefined),
|
|
28
|
+
...(opts.include.optionalDependencies ? snapshot.optionalDependencies : undefined),
|
|
29
|
+
}
|
|
30
|
+
: !opts.include.optionalDependencies
|
|
31
|
+
? snapshot.dependencies
|
|
32
|
+
: {
|
|
33
|
+
...snapshot.dependencies,
|
|
34
|
+
...snapshot.optionalDependencies,
|
|
35
|
+
};
|
|
36
|
+
const peers = new Set(Object.keys(nodeId.type === 'package'
|
|
37
|
+
? (opts.currentPackages[nodeId.depPath]?.peerDependencies ?? {})
|
|
38
|
+
: {}));
|
|
39
|
+
const edges = [];
|
|
40
|
+
if (deps != null) {
|
|
41
|
+
for (const alias in deps) {
|
|
42
|
+
const ref = deps[alias];
|
|
43
|
+
const targetNodeId = (0, getTreeNodeChildId_js_1.getTreeNodeChildId)({
|
|
44
|
+
parentId: nodeId,
|
|
45
|
+
dep: { alias, ref },
|
|
46
|
+
lockfileDir: opts.lockfileDir,
|
|
47
|
+
importers: opts.importers,
|
|
48
|
+
});
|
|
49
|
+
const target = targetNodeId != null
|
|
50
|
+
? { id: (0, TreeNodeId_js_1.serializeTreeNodeId)(targetNodeId), nodeId: targetNodeId }
|
|
51
|
+
: undefined;
|
|
52
|
+
edges.push({ alias, ref, target });
|
|
53
|
+
if (target && !visited.has(target.id)) {
|
|
54
|
+
queue.push(target.nodeId);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
graph.nodes.set(serialized, { nodeId, edges, peers });
|
|
59
|
+
}
|
|
60
|
+
return graph;
|
|
61
|
+
}
|
|
62
|
+
function getSnapshot(treeNodeId, opts) {
|
|
63
|
+
switch (treeNodeId.type) {
|
|
64
|
+
case 'importer':
|
|
65
|
+
return opts.importers[treeNodeId.importerId];
|
|
66
|
+
case 'package':
|
|
67
|
+
return opts.currentPackages[treeNodeId.depPath];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=buildDependencyGraph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildDependencyGraph.js","sourceRoot":"","sources":["../src/buildDependencyGraph.ts"],"names":[],"mappings":";;AAuBA,oDA4EC;AAlGD,mEAA4D;AAC5D,mDAAsE;AAqBtE,SAAgB,oBAAoB,CAClC,MAAkB,EAClB,IASC;IAED,MAAM,KAAK,GAAoB,EAAE,KAAK,EAAE,IAAI,GAAG,EAAE,EAAE,CAAA;IACnD,MAAM,KAAK,GAAiB,CAAC,MAAM,CAAC,CAAA;IACpC,IAAI,QAAQ,GAAG,CAAC,CAAA;IAChB,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAA;IAEjC,OAAO,QAAQ,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;QAC/B,MAAM,MAAM,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAA;QAChC,MAAM,UAAU,GAAG,IAAA,mCAAmB,EAAC,MAAM,CAAC,CAAA;QAC9C,IAAI,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC;YAAE,SAAQ;QACrC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;QAEvB,MAAM,QAAQ,GAAG,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;QAC1C,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,GAAG,EAAE,EAAE,CAAC,CAAA;YACpE,SAAQ;QACV,CAAC;QAED,yEAAyE;QACzE,6DAA6D;QAC7D,MAAM,IAAI,GAAG,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AAI,CAAC,SAAS;iBAC1B,CAAC,CAAA;gBACF,MAAM,MAAM,GAAG,YAAY,IAAI,IAAI;oBACjC,CAAC,CAAC,EAAE,EAAE,EAAE,IAAA,mCAAmB,EAAC,YAAY,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE;oBACjE,CAAC,CAAC,SAAS,CAAA;gBACb,KAAK,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,CAAA;gBAElC,IAAI,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC;oBACtC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;gBAC3B,CAAC;YACH,CAAC;QACH,CAAC;QAED,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA;IACvD,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC;AAED,SAAS,WAAW,CAClB,UAAsB,EACtB,IAGC;IAED,QAAQ,UAAU,CAAC,IAAI,EAAE,CAAC;QAC1B,KAAK,UAAU;YACb,OAAO,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,UAAU,CAAC,CAAA;QAC9C,KAAK,SAAS;YACZ,OAAO,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,OAAO,CAAC,CAAA;IACjD,CAAC;AACH,CAAC"}
|
package/lib/getPkgInfo.d.ts
CHANGED
|
@@ -24,6 +24,17 @@ export interface GetPkgInfoOpts {
|
|
|
24
24
|
* version.
|
|
25
25
|
*/
|
|
26
26
|
readonly rewriteLinkVersionDir?: string;
|
|
27
|
+
/**
|
|
28
|
+
* The node_modules directory to resolve symlinks from when using global virtual store.
|
|
29
|
+
* This is used for top-level dependencies.
|
|
30
|
+
*/
|
|
31
|
+
readonly modulesDir?: string;
|
|
32
|
+
/**
|
|
33
|
+
* The resolved path of the parent package. When provided, the symlink resolution
|
|
34
|
+
* will use the parent's node_modules directory instead of the top-level modulesDir.
|
|
35
|
+
* This is needed for subdependencies when using global virtual store.
|
|
36
|
+
*/
|
|
37
|
+
readonly parentDir?: string;
|
|
27
38
|
}
|
|
28
39
|
export declare function getPkgInfo(opts: GetPkgInfoOpts): {
|
|
29
40
|
pkgInfo: PackageInfo;
|
package/lib/getPkgInfo.js
CHANGED
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getPkgInfo = getPkgInfo;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
9
|
const lockfile_utils_1 = require("@pnpm/lockfile.utils");
|
|
9
10
|
const lockfile_detect_dep_types_1 = require("@pnpm/lockfile.detect-dep-types");
|
|
10
11
|
const dependency_path_1 = require("@pnpm/dependency-path");
|
|
@@ -52,9 +53,40 @@ function getPkgInfo(opts) {
|
|
|
52
53
|
if (!version) {
|
|
53
54
|
version = opts.ref;
|
|
54
55
|
}
|
|
55
|
-
|
|
56
|
+
let fullPackagePath = depPath
|
|
56
57
|
? path_1.default.join(opts.virtualStoreDir ?? '.pnpm', (0, dependency_path_1.depPathToFilename)(depPath, opts.virtualStoreDirMaxLength), 'node_modules', name)
|
|
57
58
|
: path_1.default.join(opts.linkedPathBaseDir, opts.ref.slice(5));
|
|
59
|
+
// Resolve symlink for global virtual store.
|
|
60
|
+
// Global virtual store is detected when virtualStoreDir is outside the project's node_modules.
|
|
61
|
+
// We use path.resolve() to normalize paths for reliable comparison.
|
|
62
|
+
const resolvedVirtualStoreDir = opts.virtualStoreDir ? path_1.default.resolve(opts.virtualStoreDir) : undefined;
|
|
63
|
+
const resolvedModulesDir = opts.modulesDir ? path_1.default.resolve(opts.modulesDir) : undefined;
|
|
64
|
+
const isGlobalVirtualStore = resolvedVirtualStoreDir && resolvedModulesDir &&
|
|
65
|
+
!resolvedVirtualStoreDir.startsWith(resolvedModulesDir + path_1.default.sep) &&
|
|
66
|
+
resolvedVirtualStoreDir !== resolvedModulesDir;
|
|
67
|
+
// For global virtual store, resolve symlinks to get the actual path with hash
|
|
68
|
+
if (depPath && isGlobalVirtualStore) {
|
|
69
|
+
try {
|
|
70
|
+
let nodeModulesDir;
|
|
71
|
+
if (opts.parentDir) {
|
|
72
|
+
// parentDir example: /store/.../node_modules/express
|
|
73
|
+
// /store/.../node_modules/@scope/pkg
|
|
74
|
+
// We need the node_modules directory to find sibling packages
|
|
75
|
+
nodeModulesDir = path_1.default.dirname(opts.parentDir);
|
|
76
|
+
// For scoped packages (@org/pkg), go up one more level
|
|
77
|
+
if (path_1.default.basename(nodeModulesDir).startsWith('@')) {
|
|
78
|
+
nodeModulesDir = path_1.default.dirname(nodeModulesDir);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
nodeModulesDir = opts.modulesDir;
|
|
83
|
+
}
|
|
84
|
+
fullPackagePath = fs_1.default.realpathSync(path_1.default.join(nodeModulesDir, opts.alias));
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
// Fallback to constructed path if symlink doesn't exist
|
|
88
|
+
}
|
|
89
|
+
}
|
|
58
90
|
if (version.startsWith('link:') && opts.rewriteLinkVersionDir) {
|
|
59
91
|
version = `link:${(0, normalize_path_1.default)(path_1.default.relative(opts.rewriteLinkVersionDir, fullPackagePath))}`;
|
|
60
92
|
}
|
package/lib/getPkgInfo.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPkgInfo.js","sourceRoot":"","sources":["../src/getPkgInfo.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"getPkgInfo.js","sourceRoot":"","sources":["../src/getPkgInfo.ts"],"names":[],"mappings":";;;;;AAyDA,gCAsGC;AA/JD,gDAAuB;AACvB,4CAAmB;AAMnB,yDAG6B;AAC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CAAC,QAAQ,GAAG,QAAQ,CAAA;IACjC,CAAC;IACD,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;QACtB,WAAW,CAAC,QAAQ,GAAG,IAAI,CAAA;IAC7B,CAAC;IACD,IAAI,OAAO,KAAK,mCAAO,CAAC,OAAO,EAAE,CAAC;QAChC,WAAW,CAAC,GAAG,GAAG,IAAI,CAAA;IACxB,CAAC;SAAM,IAAI,OAAO,KAAK,mCAAO,CAAC,QAAQ,EAAE,CAAC;QACxC,WAAW,CAAC,GAAG,GAAG,KAAK,CAAA;IACzB,CAAC;IACD,OAAO;QACL,OAAO,EAAE,WAAW;QACpB,YAAY,EAAE,GAAG,EAAE,CAAC,IAAA,8CAA0B,EAAC,eAAe,CAAC;KAChE,CAAA;AACH,CAAC"}
|
package/lib/getTree.d.ts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import { type PackageSnapshots, type ProjectSnapshot } from '@pnpm/lockfile.fs';
|
|
2
2
|
import { type DepTypes } from '@pnpm/lockfile.detect-dep-types';
|
|
3
3
|
import { type Finder, type Registries } from '@pnpm/types';
|
|
4
|
+
import { type DependencyGraph } from './buildDependencyGraph.js';
|
|
4
5
|
import { type PackageNode } from './PackageNode.js';
|
|
5
6
|
import { type TreeNodeId } from './TreeNodeId.js';
|
|
6
7
|
interface GetTreeOpts {
|
|
7
8
|
maxDepth: number;
|
|
8
9
|
rewriteLinkVersionDir: string;
|
|
9
|
-
|
|
10
|
+
include: {
|
|
11
|
+
dependencies?: boolean;
|
|
12
|
+
devDependencies?: boolean;
|
|
13
|
+
optionalDependencies?: boolean;
|
|
14
|
+
};
|
|
10
15
|
excludePeerDependencies?: boolean;
|
|
11
16
|
lockfileDir: string;
|
|
12
17
|
onlyProjects?: boolean;
|
|
@@ -19,6 +24,25 @@ interface GetTreeOpts {
|
|
|
19
24
|
wantedPackages: PackageSnapshots;
|
|
20
25
|
virtualStoreDir?: string;
|
|
21
26
|
virtualStoreDirMaxLength: number;
|
|
27
|
+
modulesDir?: string;
|
|
28
|
+
parentDir?: string;
|
|
29
|
+
showDedupedSearchMatches?: boolean;
|
|
30
|
+
graph: DependencyGraph;
|
|
31
|
+
materializationCache: MaterializationCache;
|
|
22
32
|
}
|
|
33
|
+
interface CachedSubtree {
|
|
34
|
+
/** Total number of PackageNode objects in the subtree (recursive). */
|
|
35
|
+
count: number;
|
|
36
|
+
/** Whether any node in this subtree matched the search. */
|
|
37
|
+
hasSearchMatch: boolean;
|
|
38
|
+
/** Search match messages (string-typed matches) found in this subtree. */
|
|
39
|
+
searchMessages: string[];
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Caches already-materialized subtrees. When a subtree is encountered a
|
|
43
|
+
* second time (cache hit), an empty array is returned and the node is marked
|
|
44
|
+
* as deduped — bounding the total output to O(N) nodes.
|
|
45
|
+
*/
|
|
46
|
+
export type MaterializationCache = Map<string, CachedSubtree>;
|
|
23
47
|
export declare function getTree(opts: GetTreeOpts, parentId: TreeNodeId): PackageNode[];
|
|
24
48
|
export {};
|
package/lib/getTree.js
CHANGED
|
@@ -6,140 +6,139 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.getTree = getTree;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const getPkgInfo_js_1 = require("./getPkgInfo.js");
|
|
9
|
-
const getTreeNodeChildId_js_1 = require("./getTreeNodeChildId.js");
|
|
10
|
-
const DependenciesCache_js_1 = require("./DependenciesCache.js");
|
|
11
9
|
const TreeNodeId_js_1 = require("./TreeNodeId.js");
|
|
12
10
|
function getTree(opts, parentId) {
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
function getTreeHelper(dependenciesCache, opts, keypath, parentId) {
|
|
17
|
-
if (opts.maxDepth <= 0) {
|
|
18
|
-
return { dependencies: [], height: 'unknown' };
|
|
19
|
-
}
|
|
20
|
-
function getSnapshot(treeNodeId) {
|
|
21
|
-
switch (treeNodeId.type) {
|
|
22
|
-
case 'importer':
|
|
23
|
-
return opts.importers[treeNodeId.importerId];
|
|
24
|
-
case 'package':
|
|
25
|
-
return opts.currentPackages[treeNodeId.depPath];
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
const snapshot = getSnapshot(parentId);
|
|
29
|
-
if (!snapshot) {
|
|
30
|
-
return { dependencies: [], height: 0 };
|
|
31
|
-
}
|
|
32
|
-
const deps = !opts.includeOptionalDependencies
|
|
33
|
-
? snapshot.dependencies
|
|
34
|
-
: {
|
|
35
|
-
...snapshot.dependencies,
|
|
36
|
-
...snapshot.optionalDependencies,
|
|
37
|
-
};
|
|
38
|
-
if (deps == null) {
|
|
39
|
-
return { dependencies: [], height: 0 };
|
|
40
|
-
}
|
|
41
|
-
const childTreeMaxDepth = opts.maxDepth - 1;
|
|
42
|
-
const getChildrenTree = getTreeHelper.bind(null, dependenciesCache, {
|
|
11
|
+
const ancestors = new Set();
|
|
12
|
+
ancestors.add((0, TreeNodeId_js_1.serializeTreeNodeId)(parentId));
|
|
13
|
+
const ctx = {
|
|
43
14
|
...opts,
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
15
|
+
ancestors,
|
|
16
|
+
};
|
|
17
|
+
const { nodes: tree } = materializeChildren(ctx, parentId, opts.maxDepth, opts.parentDir);
|
|
18
|
+
// Mark circular back-edges. materializeChildren truncates dependencies
|
|
19
|
+
// at cycle boundaries but does not set the `circular` flag, so that cached
|
|
20
|
+
// subtrees stay context-independent. fixCircularRefs walks the final tree
|
|
21
|
+
// and adds `circular: true` wherever a node's path matches an ancestor.
|
|
22
|
+
//
|
|
23
|
+
// Seed the ancestors with parentDir (the filesystem path of parentId) so
|
|
24
|
+
// that back-edges to the root of this subtree are detected — the root
|
|
25
|
+
// itself does not appear as a node in the tree, only its children do.
|
|
26
|
+
const circularAncestors = new Set();
|
|
27
|
+
if (opts.parentDir) {
|
|
28
|
+
circularAncestors.add(opts.parentDir);
|
|
56
29
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
30
|
+
return fixCircularRefs(tree, circularAncestors);
|
|
31
|
+
}
|
|
32
|
+
// ---------------------------------------------------------------------------
|
|
33
|
+
// Materialize PackageNode[] tree from the graph
|
|
34
|
+
// ---------------------------------------------------------------------------
|
|
35
|
+
function materializeCacheKey(nodeId, depth) {
|
|
36
|
+
if (depth === Infinity)
|
|
37
|
+
return nodeId;
|
|
38
|
+
return `${nodeId}@d${depth}`;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Core materialization function. Walks the pre-built dependency graph to
|
|
42
|
+
* produce the `PackageNode[]` tree that downstream renderers expect.
|
|
43
|
+
*
|
|
44
|
+
* The cache is keyed by `(nodeId, remainingDepth)` and stores the
|
|
45
|
+
* `PackageNode[]` children of a given node. It is populated
|
|
46
|
+
* unconditionally, including results where recursion was truncated at a
|
|
47
|
+
* cycle boundary. Cycle detection uses a mutable `ancestors` Set to
|
|
48
|
+
* stop recursion but does NOT set the `circular` flag — that is handled
|
|
49
|
+
* by `fixCircularRefs` in a separate pass over the final tree. This
|
|
50
|
+
* keeps cached subtrees free of context-dependent circular markers.
|
|
51
|
+
*/
|
|
52
|
+
function materializeChildren(ctx, parentId, maxDepth, parentDir) {
|
|
53
|
+
if (maxDepth <= 0)
|
|
54
|
+
return { nodes: [], count: 0, hasSearchMatch: false, searchMessages: [] };
|
|
55
|
+
const parentSerialized = (0, TreeNodeId_js_1.serializeTreeNodeId)(parentId);
|
|
56
|
+
const graphNode = ctx.graph.nodes.get(parentSerialized);
|
|
57
|
+
if (!graphNode) {
|
|
58
|
+
throw new Error(`Node ${parentSerialized} not found in the dependency graph`);
|
|
68
59
|
}
|
|
69
|
-
const
|
|
60
|
+
const childTreeMaxDepth = maxDepth - 1;
|
|
61
|
+
const linkedPathBaseDir = parentId.type === 'importer'
|
|
62
|
+
? path_1.default.join(ctx.lockfileDir, parentId.importerId)
|
|
63
|
+
: ctx.lockfileDir;
|
|
70
64
|
const resultDependencies = [];
|
|
71
|
-
let
|
|
72
|
-
let
|
|
73
|
-
|
|
74
|
-
|
|
65
|
+
let resultCount = 0;
|
|
66
|
+
let resultHasSearchMatch = false;
|
|
67
|
+
const resultSearchMessages = ctx.showDedupedSearchMatches ? [] : undefined;
|
|
68
|
+
for (const edge of graphNode.edges) {
|
|
69
|
+
if (ctx.onlyProjects && edge.target?.nodeId.type !== 'importer') {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
75
72
|
const { pkgInfo: packageInfo, readManifest } = (0, getPkgInfo_js_1.getPkgInfo)({
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
73
|
+
...ctx,
|
|
74
|
+
alias: edge.alias,
|
|
75
|
+
ref: edge.ref,
|
|
76
|
+
peers: graphNode.peers,
|
|
80
77
|
linkedPathBaseDir,
|
|
81
|
-
|
|
82
|
-
ref,
|
|
83
|
-
registries: opts.registries,
|
|
84
|
-
skipped: opts.skipped,
|
|
85
|
-
wantedPackages: opts.wantedPackages,
|
|
86
|
-
virtualStoreDir: opts.virtualStoreDir,
|
|
87
|
-
virtualStoreDirMaxLength: opts.virtualStoreDirMaxLength,
|
|
78
|
+
parentDir,
|
|
88
79
|
});
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
alias,
|
|
80
|
+
const searchMatch = ctx.search?.({
|
|
81
|
+
alias: edge.alias,
|
|
92
82
|
name: packageInfo.name,
|
|
93
83
|
version: packageInfo.version,
|
|
94
84
|
readManifest,
|
|
95
85
|
});
|
|
96
86
|
let newEntry = null;
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if (opts.onlyProjects && nodeId?.type !== 'importer') {
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
-
else if (nodeId == null) {
|
|
107
|
-
circular = false;
|
|
108
|
-
if (opts.search == null || matchedSearched) {
|
|
87
|
+
let childCount = 0;
|
|
88
|
+
let dedupedHasSearchMatch = false;
|
|
89
|
+
let dedupedSearchMessages = [];
|
|
90
|
+
if (edge.target == null) {
|
|
91
|
+
// External link or unresolvable — no traversal possible
|
|
92
|
+
if (ctx.search == null || searchMatch) {
|
|
109
93
|
newEntry = packageInfo;
|
|
110
94
|
}
|
|
95
|
+
else {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
111
98
|
}
|
|
112
99
|
else {
|
|
113
100
|
let dependencies;
|
|
114
|
-
|
|
101
|
+
let childHasSearchMatch = false;
|
|
102
|
+
let childSearchMessages = [];
|
|
103
|
+
let dedupedCount;
|
|
104
|
+
const circular = ctx.ancestors.has(edge.target.id);
|
|
115
105
|
if (circular) {
|
|
116
106
|
dependencies = [];
|
|
117
107
|
}
|
|
118
108
|
else {
|
|
119
|
-
const
|
|
120
|
-
const
|
|
121
|
-
if (
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
109
|
+
const cacheKey = materializeCacheKey(edge.target.id, childTreeMaxDepth);
|
|
110
|
+
const cached = ctx.materializationCache.get(cacheKey);
|
|
111
|
+
if (cached !== undefined) {
|
|
112
|
+
// This subtree was already returned to a parent elsewhere in
|
|
113
|
+
// the output tree — elide it to avoid repeating the same nodes.
|
|
114
|
+
dependencies = [];
|
|
115
|
+
if (cached.count > 0) {
|
|
116
|
+
dedupedCount = cached.count;
|
|
127
117
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
height: children.height,
|
|
132
|
-
});
|
|
118
|
+
if (ctx.showDedupedSearchMatches) {
|
|
119
|
+
dedupedHasSearchMatch = cached.hasSearchMatch;
|
|
120
|
+
dedupedSearchMessages = cached.searchMessages;
|
|
133
121
|
}
|
|
134
122
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
123
|
+
else {
|
|
124
|
+
ctx.ancestors.add(edge.target.id);
|
|
125
|
+
const childResult = materializeChildren(ctx, edge.target.nodeId, childTreeMaxDepth, packageInfo.path);
|
|
126
|
+
ctx.ancestors.delete(edge.target.id);
|
|
127
|
+
dependencies = childResult.nodes;
|
|
128
|
+
childCount = childResult.count;
|
|
129
|
+
childHasSearchMatch = childResult.hasSearchMatch;
|
|
130
|
+
childSearchMessages = childResult.searchMessages;
|
|
131
|
+
// Always cache — even results with circular truncations.
|
|
132
|
+
ctx.materializationCache.set(cacheKey, {
|
|
133
|
+
count: childCount,
|
|
134
|
+
hasSearchMatch: childHasSearchMatch,
|
|
135
|
+
searchMessages: childSearchMessages,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
if (childHasSearchMatch || dedupedHasSearchMatch) {
|
|
139
|
+
resultHasSearchMatch = true;
|
|
140
|
+
}
|
|
141
|
+
resultSearchMessages?.push(...childSearchMessages, ...dedupedSearchMessages);
|
|
143
142
|
}
|
|
144
143
|
if (dependencies.length > 0) {
|
|
145
144
|
newEntry = {
|
|
@@ -147,51 +146,70 @@ function getTreeHelper(dependenciesCache, opts, keypath, parentId) {
|
|
|
147
146
|
dependencies,
|
|
148
147
|
};
|
|
149
148
|
}
|
|
150
|
-
else if (
|
|
149
|
+
else if (ctx.search == null || Boolean(searchMatch) || dedupedHasSearchMatch) {
|
|
151
150
|
newEntry = packageInfo;
|
|
152
151
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
if (circular) {
|
|
156
|
-
newEntry.circular = true;
|
|
157
|
-
resultCircular = true;
|
|
152
|
+
else {
|
|
153
|
+
continue;
|
|
158
154
|
}
|
|
159
|
-
if (
|
|
160
|
-
newEntry.
|
|
161
|
-
|
|
162
|
-
newEntry.searchMessage = matchedSearched;
|
|
163
|
-
}
|
|
155
|
+
if (dedupedCount != null) {
|
|
156
|
+
newEntry.deduped = true;
|
|
157
|
+
newEntry.dedupedDependenciesCount = dedupedCount;
|
|
164
158
|
}
|
|
165
|
-
|
|
166
|
-
|
|
159
|
+
}
|
|
160
|
+
if (searchMatch) {
|
|
161
|
+
newEntry.searched = true;
|
|
162
|
+
resultHasSearchMatch = true;
|
|
163
|
+
if (typeof searchMatch === 'string') {
|
|
164
|
+
newEntry.searchMessage = searchMatch;
|
|
165
|
+
resultSearchMessages?.push(searchMatch);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
else if (dedupedHasSearchMatch) {
|
|
169
|
+
newEntry.searched = true;
|
|
170
|
+
if (dedupedSearchMessages.length > 0) {
|
|
171
|
+
newEntry.searchMessage = dedupedSearchMessages.join('\n');
|
|
167
172
|
}
|
|
168
173
|
}
|
|
174
|
+
if (!newEntry.isPeer || !ctx.excludePeerDependencies || newEntry.dependencies?.length) {
|
|
175
|
+
resultDependencies.push(newEntry);
|
|
176
|
+
resultCount += 1 + (newEntry.dependencies?.length ? childCount : 0);
|
|
177
|
+
}
|
|
169
178
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
179
|
+
return {
|
|
180
|
+
count: resultCount,
|
|
181
|
+
hasSearchMatch: resultHasSearchMatch,
|
|
182
|
+
nodes: resultDependencies,
|
|
183
|
+
searchMessages: resultSearchMessages ?? [],
|
|
173
184
|
};
|
|
174
|
-
if (resultCircular) {
|
|
175
|
-
result.circular = resultCircular;
|
|
176
|
-
}
|
|
177
|
-
return result;
|
|
178
185
|
}
|
|
179
186
|
/**
|
|
180
|
-
*
|
|
187
|
+
* Walks the materialized PackageNode[] tree and marks circular back-edges.
|
|
188
|
+
* A node whose `path` matches an ancestor is a cycle — it gets
|
|
189
|
+
* `circular: true` and its dependencies (if any) are stripped.
|
|
190
|
+
*
|
|
191
|
+
* With deduplication in place (deduped nodes are leaves), the walk is O(N).
|
|
181
192
|
*/
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
193
|
+
function fixCircularRefs(nodes, ancestors) {
|
|
194
|
+
let changed = false;
|
|
195
|
+
const result = nodes.map(node => {
|
|
196
|
+
// A node whose path matches an ancestor is a circular back-edge.
|
|
197
|
+
if (node.path && ancestors.has(node.path)) {
|
|
198
|
+
changed = true;
|
|
199
|
+
const { dependencies: _, deduped: _d, dedupedDependenciesCount: _c, ...rest } = node;
|
|
200
|
+
return { ...rest, circular: true };
|
|
201
|
+
}
|
|
202
|
+
if (!node.dependencies?.length)
|
|
203
|
+
return node;
|
|
204
|
+
ancestors.add(node.path);
|
|
205
|
+
const fixedDeps = fixCircularRefs(node.dependencies, ancestors);
|
|
206
|
+
ancestors.delete(node.path);
|
|
207
|
+
if (fixedDeps !== node.dependencies) {
|
|
208
|
+
changed = true;
|
|
209
|
+
return { ...node, dependencies: fixedDeps };
|
|
210
|
+
}
|
|
211
|
+
return node;
|
|
212
|
+
});
|
|
213
|
+
return changed ? result : nodes;
|
|
196
214
|
}
|
|
197
215
|
//# sourceMappingURL=getTree.js.map
|
package/lib/getTree.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTree.js","sourceRoot":"","sources":["../src/getTree.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"getTree.js","sourceRoot":"","sources":["../src/getTree.ts"],"names":[],"mappings":";;;;;AAgEA,0BA2BC;AA3FD,gDAAuB;AAMvB,mDAA4C;AAC5C,mDAAsE;AAyDtE,SAAgB,OAAO,CACrB,IAAiB,EACjB,QAAoB;IAEpB,MAAM,SAAS,GAAG,IAAI,GAAG,EAAU,CAAA;IACnC,SAAS,CAAC,GA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G,CAAC,IAAI,CAAC,EAAE;QAC9B,iEAAiE;QACjE,IAAI,IAAI,CAAC,IAAI,IAAI,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YAC1C,OAAO,GAAG,IAAI,CAAA;YACd,MAAM,EAAE,YAAY,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,wBAAwB,EAAE,EAAE,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAA;YACpF,OAAO,EAAE,GAAG,IAAI,EAAE,QAAQ,EAAE,IAAa,EAAE,CAAA;QAC7C,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,MAAM;YAAE,OAAO,IAAI,CAAA;QAE3C,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACxB,MAAM,SAAS,GAAG,eAAe,CAAC,IAAI,CAAC,YAAY,EAAE,SAAS,CAAC,CAAA;QAC/D,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAE3B,IAAI,SAAS,KAAK,IAAI,CAAC,YAAY,EAAE,CAAC;YACpC,OAAO,GAAG,IAAI,CAAA;YACd,OAAO,EAAE,GAAG,IAAI,EAAE,YAAY,EAAE,SAAS,EAAE,CAAA;QAC7C,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC,CAAC,CAAA;IACF,OAAO,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAA;AACjC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pnpm/reviewing.dependencies-hierarchy",
|
|
3
|
-
"version": "1001.2.
|
|
3
|
+
"version": "1001.2.7",
|
|
4
4
|
"description": "Creates a dependencies hierarchy for a symlinked `node_modules`",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pnpm",
|
|
@@ -35,19 +35,19 @@
|
|
|
35
35
|
"@pnpm/dependency-path": "1001.1.9",
|
|
36
36
|
"@pnpm/lockfile.detect-dep-types": "1001.0.24",
|
|
37
37
|
"@pnpm/lockfile.fs": "1001.1.29",
|
|
38
|
-
"@pnpm/lockfile.utils": "1004.0.1",
|
|
39
|
-
"@pnpm/modules-yaml": "1001.0.2",
|
|
40
38
|
"@pnpm/matcher": "1000.1.0",
|
|
39
|
+
"@pnpm/lockfile.utils": "1004.0.1",
|
|
40
|
+
"@pnpm/modules-yaml": "1002.0.0",
|
|
41
41
|
"@pnpm/normalize-registries": "1000.1.9",
|
|
42
|
-
"@pnpm/read-modules-dir": "1000.0.0",
|
|
43
42
|
"@pnpm/read-package-json": "1000.1.7",
|
|
44
|
-
"@pnpm/types": "1001.3.0"
|
|
43
|
+
"@pnpm/types": "1001.3.0",
|
|
44
|
+
"@pnpm/read-modules-dir": "1000.0.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@types/normalize-path": "^3.0.2",
|
|
48
48
|
"@types/semver": "7.5.3",
|
|
49
|
+
"@pnpm/reviewing.dependencies-hierarchy": "1001.2.7",
|
|
49
50
|
"@pnpm/constants": "1001.3.1",
|
|
50
|
-
"@pnpm/reviewing.dependencies-hierarchy": "1001.2.5",
|
|
51
51
|
"@pnpm/test-fixtures": "1000.0.0"
|
|
52
52
|
},
|
|
53
53
|
"engines": {
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { type PackageNode } from './PackageNode.js';
|
|
2
|
-
import { type TreeNodeId } from './TreeNodeId.js';
|
|
3
|
-
export interface GetDependenciesCacheEntryArgs {
|
|
4
|
-
readonly parentId: TreeNodeId;
|
|
5
|
-
readonly requestedDepth: number;
|
|
6
|
-
}
|
|
7
|
-
export interface TraversalResultFullyVisited {
|
|
8
|
-
readonly dependencies: PackageNode[];
|
|
9
|
-
/**
|
|
10
|
-
* Describes the height of the parent node in the fully enumerated dependency
|
|
11
|
-
* tree. A height of 0 means no entries are present in the dependencies array.
|
|
12
|
-
* A height of 1 means entries in the dependencies array do not have any of
|
|
13
|
-
* their own dependencies.
|
|
14
|
-
*/
|
|
15
|
-
readonly height: number;
|
|
16
|
-
}
|
|
17
|
-
export interface TraversalResultPartiallyVisited {
|
|
18
|
-
readonly dependencies: PackageNode[];
|
|
19
|
-
/**
|
|
20
|
-
* Describes how deep the dependencies tree was previously traversed. Since
|
|
21
|
-
* the traversal result was limited by a max depth, there are likely more
|
|
22
|
-
* dependencies present deeper in the tree not shown.
|
|
23
|
-
*
|
|
24
|
-
* A depth of 0 would indicate no entries in the dependencies array. A depth
|
|
25
|
-
* of 1 means entries in the dependencies array do not have any of their own
|
|
26
|
-
* dependencies.
|
|
27
|
-
*/
|
|
28
|
-
readonly depth: number;
|
|
29
|
-
}
|
|
30
|
-
export interface CacheHit {
|
|
31
|
-
readonly dependencies: PackageNode[];
|
|
32
|
-
readonly height: number | 'unknown';
|
|
33
|
-
readonly circular: false;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* A cache for the dependencies of a package.
|
|
37
|
-
*
|
|
38
|
-
* ## Depth Considerations
|
|
39
|
-
*
|
|
40
|
-
* Since the enumerated dependency tree can be limited by a max depth argument,
|
|
41
|
-
* several considerations have to be made when caching.
|
|
42
|
-
*
|
|
43
|
-
* - If a package is visited with a requested depth greater than the cached
|
|
44
|
-
* depth, the cache cannot be used. The tree needs to be enumerated again
|
|
45
|
-
* deeper.
|
|
46
|
-
* - If a package is visited with a requested depth less than the cached
|
|
47
|
-
* depth, the cache probably can't be used. This depends on how strict the
|
|
48
|
-
* depth constraint is and whether it's acceptable to exceed the max depth.
|
|
49
|
-
* This cache assumes the max depth should not be exceeded.
|
|
50
|
-
* - Cycles may or may not be cached. It depends on whether the cycle is
|
|
51
|
-
* introduced by a package outside of the cached tree.
|
|
52
|
-
*
|
|
53
|
-
* This cache adds an optimization when a dependency tree has been fully
|
|
54
|
-
* enumerated and wasn't limited by a max depth argument. In that case,
|
|
55
|
-
* dependency trees cached can be used when the max depth argument is greater
|
|
56
|
-
* than or equal to the height of the tree root.
|
|
57
|
-
*
|
|
58
|
-
* ## Future Optimizations
|
|
59
|
-
*
|
|
60
|
-
* The necessity of this cache may be removed in the future with a refactor of
|
|
61
|
-
* the `pnpm list` command. This cache attempts to optimize runtime to O(# of
|
|
62
|
-
* unique packages), but the list command is O(# of nodes) anyway since every
|
|
63
|
-
* node needs to be printed. It's possible a generator function could be
|
|
64
|
-
* returned here to avoid computing large trees in-memory before passing to
|
|
65
|
-
* downstream commands.
|
|
66
|
-
*/
|
|
67
|
-
export declare class DependenciesCache {
|
|
68
|
-
private readonly fullyVisitedCache;
|
|
69
|
-
/**
|
|
70
|
-
* Maps cacheKey -> visitedDepth -> dependencies
|
|
71
|
-
*/
|
|
72
|
-
private readonly partiallyVisitedCache;
|
|
73
|
-
get(args: GetDependenciesCacheEntryArgs): CacheHit | undefined;
|
|
74
|
-
addFullyVisitedResult(treeNodeId: TreeNodeId, result: TraversalResultFullyVisited): void;
|
|
75
|
-
addPartiallyVisitedResult(treeNodeId: TreeNodeId, result: TraversalResultPartiallyVisited): void;
|
|
76
|
-
}
|
package/lib/DependenciesCache.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DependenciesCache = void 0;
|
|
4
|
-
const TreeNodeId_js_1 = require("./TreeNodeId.js");
|
|
5
|
-
/**
|
|
6
|
-
* A cache for the dependencies of a package.
|
|
7
|
-
*
|
|
8
|
-
* ## Depth Considerations
|
|
9
|
-
*
|
|
10
|
-
* Since the enumerated dependency tree can be limited by a max depth argument,
|
|
11
|
-
* several considerations have to be made when caching.
|
|
12
|
-
*
|
|
13
|
-
* - If a package is visited with a requested depth greater than the cached
|
|
14
|
-
* depth, the cache cannot be used. The tree needs to be enumerated again
|
|
15
|
-
* deeper.
|
|
16
|
-
* - If a package is visited with a requested depth less than the cached
|
|
17
|
-
* depth, the cache probably can't be used. This depends on how strict the
|
|
18
|
-
* depth constraint is and whether it's acceptable to exceed the max depth.
|
|
19
|
-
* This cache assumes the max depth should not be exceeded.
|
|
20
|
-
* - Cycles may or may not be cached. It depends on whether the cycle is
|
|
21
|
-
* introduced by a package outside of the cached tree.
|
|
22
|
-
*
|
|
23
|
-
* This cache adds an optimization when a dependency tree has been fully
|
|
24
|
-
* enumerated and wasn't limited by a max depth argument. In that case,
|
|
25
|
-
* dependency trees cached can be used when the max depth argument is greater
|
|
26
|
-
* than or equal to the height of the tree root.
|
|
27
|
-
*
|
|
28
|
-
* ## Future Optimizations
|
|
29
|
-
*
|
|
30
|
-
* The necessity of this cache may be removed in the future with a refactor of
|
|
31
|
-
* the `pnpm list` command. This cache attempts to optimize runtime to O(# of
|
|
32
|
-
* unique packages), but the list command is O(# of nodes) anyway since every
|
|
33
|
-
* node needs to be printed. It's possible a generator function could be
|
|
34
|
-
* returned here to avoid computing large trees in-memory before passing to
|
|
35
|
-
* downstream commands.
|
|
36
|
-
*/
|
|
37
|
-
class DependenciesCache {
|
|
38
|
-
fullyVisitedCache = new Map();
|
|
39
|
-
/**
|
|
40
|
-
* Maps cacheKey -> visitedDepth -> dependencies
|
|
41
|
-
*/
|
|
42
|
-
partiallyVisitedCache = new Map();
|
|
43
|
-
get(args) {
|
|
44
|
-
const cacheKey = (0, TreeNodeId_js_1.serializeTreeNodeId)(args.parentId);
|
|
45
|
-
// The fully visited cache is only usable if the height doesn't exceed the
|
|
46
|
-
// requested depth. Otherwise the final dependencies listing will print
|
|
47
|
-
// entries with a greater depth than requested.
|
|
48
|
-
//
|
|
49
|
-
// If that is the case, the partially visited cache should be checked to see
|
|
50
|
-
// if dependencies were requested at that exact depth before.
|
|
51
|
-
const fullyVisitedEntry = this.fullyVisitedCache.get(cacheKey);
|
|
52
|
-
if (fullyVisitedEntry !== undefined && fullyVisitedEntry.height <= args.requestedDepth) {
|
|
53
|
-
return {
|
|
54
|
-
dependencies: fullyVisitedEntry.dependencies,
|
|
55
|
-
height: fullyVisitedEntry.height,
|
|
56
|
-
circular: false,
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
const partiallyVisitedEntry = this.partiallyVisitedCache.get(cacheKey)?.get(args.requestedDepth);
|
|
60
|
-
if (partiallyVisitedEntry != null) {
|
|
61
|
-
return {
|
|
62
|
-
dependencies: partiallyVisitedEntry,
|
|
63
|
-
height: 'unknown',
|
|
64
|
-
circular: false,
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
return undefined;
|
|
68
|
-
}
|
|
69
|
-
addFullyVisitedResult(treeNodeId, result) {
|
|
70
|
-
const cacheKey = (0, TreeNodeId_js_1.serializeTreeNodeId)(treeNodeId);
|
|
71
|
-
this.fullyVisitedCache.set(cacheKey, result);
|
|
72
|
-
}
|
|
73
|
-
addPartiallyVisitedResult(treeNodeId, result) {
|
|
74
|
-
const cacheKey = (0, TreeNodeId_js_1.serializeTreeNodeId)(treeNodeId);
|
|
75
|
-
const dependenciesByDepth = this.partiallyVisitedCache.get(cacheKey) ?? new Map();
|
|
76
|
-
if (!this.partiallyVisitedCache.has(cacheKey)) {
|
|
77
|
-
this.partiallyVisitedCache.set(cacheKey, dependenciesByDepth);
|
|
78
|
-
}
|
|
79
|
-
dependenciesByDepth.set(result.depth, result.dependencies);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
exports.DependenciesCache = DependenciesCache;
|
|
83
|
-
//# sourceMappingURL=DependenciesCache.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DependenciesCache.js","sourceRoot":"","sources":["../src/DependenciesCache.ts"],"names":[],"mappings":";;;AACA,mDAAsE;AAyCtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAa,iBAAiB;IACX,iBAAiB,GAAG,IAAI,GAAG,EAAuC,CAAA;IAEnF;;OAEG;IACc,qBAAqB,GAAG,IAAI,GAAG,EAAsC,CAAA;IAE/E,GAAG,CAAE,IAAmC;Q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