@pnpm/reviewing.dependencies-hierarchy 1001.2.6 → 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 +29 -15
- 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/getTree.d.ts +23 -1
- package/lib/getTree.js +161 -146
- package/lib/getTree.js.map +1 -1
- package/package.json +8 -8
- 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,6 +57,7 @@ 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
62
|
modulesDir,
|
|
61
63
|
virtualStoreDir: modules?.virtualStoreDir,
|
|
@@ -83,11 +85,13 @@ async function dependenciesHierarchyForPackage(projectPath, currentLockfile, wan
|
|
|
83
85
|
const allDirectDeps = await (0, read_modules_dir_1.readModulesDir)(modulesDir) ?? [];
|
|
84
86
|
const unsavedDeps = allDirectDeps.filter((directDep) => !savedDeps[directDep]);
|
|
85
87
|
const depTypes = (0, lockfile_detect_dep_types_1.detectDepTypes)(currentLockfile);
|
|
88
|
+
const currentPackages = currentLockfile.packages ?? {};
|
|
89
|
+
const wantedPackages = wantedLockfile?.packages ?? {};
|
|
86
90
|
const getTreeOpts = {
|
|
87
|
-
currentPackages
|
|
91
|
+
currentPackages,
|
|
88
92
|
excludePeerDependencies: opts.excludePeerDependencies,
|
|
89
93
|
importers: currentLockfile.importers,
|
|
90
|
-
|
|
94
|
+
include: opts.include,
|
|
91
95
|
depTypes,
|
|
92
96
|
lockfileDir: opts.lockfileDir,
|
|
93
97
|
onlyProjects: opts.onlyProjects,
|
|
@@ -95,14 +99,24 @@ async function dependenciesHierarchyForPackage(projectPath, currentLockfile, wan
|
|
|
95
99
|
maxDepth: opts.depth,
|
|
96
100
|
registries: opts.registries,
|
|
97
101
|
search: opts.search,
|
|
102
|
+
showDedupedSearchMatches: opts.showDedupedSearchMatches,
|
|
98
103
|
skipped: opts.skipped,
|
|
99
|
-
wantedPackages
|
|
104
|
+
wantedPackages,
|
|
100
105
|
virtualStoreDir: opts.virtualStoreDir,
|
|
101
106
|
virtualStoreDirMaxLength: opts.virtualStoreDirMaxLength,
|
|
102
107
|
modulesDir,
|
|
103
108
|
};
|
|
104
|
-
const getChildrenTree = (nodeId, parentDir) => (0, getTree_js_1.getTree)({ ...getTreeOpts, parentDir }, nodeId);
|
|
105
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);
|
|
106
120
|
const result = {};
|
|
107
121
|
for (const dependenciesField of types_1.DEPENDENCIES_FIELDS.sort().filter(dependenciesField => opts.include[dependenciesField])) {
|
|
108
122
|
const topDeps = currentLockfile.importers[importerId][dependenciesField] ?? {};
|
|
@@ -124,7 +138,7 @@ async function dependenciesHierarchyForPackage(projectPath, currentLockfile, wan
|
|
|
124
138
|
modulesDir,
|
|
125
139
|
});
|
|
126
140
|
let newEntry = null;
|
|
127
|
-
const
|
|
141
|
+
const searchMatch = opts.search?.({
|
|
128
142
|
alias,
|
|
129
143
|
name: packageInfo.name,
|
|
130
144
|
version: packageInfo.version,
|
|
@@ -140,7 +154,7 @@ async function dependenciesHierarchyForPackage(projectPath, currentLockfile, wan
|
|
|
140
154
|
continue;
|
|
141
155
|
}
|
|
142
156
|
else if (nodeId == null) {
|
|
143
|
-
if ((opts.search != null) && !
|
|
157
|
+
if ((opts.search != null) && !searchMatch)
|
|
144
158
|
continue;
|
|
145
159
|
newEntry = packageInfo;
|
|
146
160
|
}
|
|
@@ -152,15 +166,15 @@ async function dependenciesHierarchyForPackage(projectPath, currentLockfile, wan
|
|
|
152
166
|
dependencies,
|
|
153
167
|
};
|
|
154
168
|
}
|
|
155
|
-
else if ((opts.search == null) ||
|
|
169
|
+
else if ((opts.search == null) || searchMatch) {
|
|
156
170
|
newEntry = packageInfo;
|
|
157
171
|
}
|
|
158
172
|
}
|
|
159
173
|
if (newEntry != null) {
|
|
160
|
-
if (
|
|
174
|
+
if (searchMatch) {
|
|
161
175
|
newEntry.searched = true;
|
|
162
|
-
if (typeof
|
|
163
|
-
newEntry.searchMessage =
|
|
176
|
+
if (typeof searchMatch === 'string') {
|
|
177
|
+
newEntry.searchMessage = searchMatch;
|
|
164
178
|
}
|
|
165
179
|
}
|
|
166
180
|
result[dependenciesField].push(newEntry);
|
|
@@ -188,19 +202,19 @@ async function dependenciesHierarchyForPackage(projectPath, currentLockfile, wan
|
|
|
188
202
|
path: pkgPath,
|
|
189
203
|
version,
|
|
190
204
|
};
|
|
191
|
-
const
|
|
205
|
+
const searchMatch = opts.search?.({
|
|
192
206
|
alias: pkg.alias,
|
|
193
207
|
name: pkg.name,
|
|
194
208
|
version: pkg.version,
|
|
195
209
|
readManifest: () => (0, read_package_json_1.readPackageJsonFromDirSync)(pkgPath),
|
|
196
210
|
});
|
|
197
|
-
if ((opts.search != null) && !
|
|
211
|
+
if ((opts.search != null) && !searchMatch)
|
|
198
212
|
return;
|
|
199
213
|
const newEntry = pkg;
|
|
200
|
-
if (
|
|
214
|
+
if (searchMatch) {
|
|
201
215
|
newEntry.searched = true;
|
|
202
|
-
if (typeof
|
|
203
|
-
newEntry.searchMessage =
|
|
216
|
+
if (typeof searchMatch === 'string') {
|
|
217
|
+
newEntry.searchMessage = searchMatch;
|
|
204
218
|
}
|
|
205
219
|
}
|
|
206
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,SAYC;IAED,IAAI,CAAC,SAAS,EAAE,WAAW,EAAE,CAAC;QAC5B,MAAM,IAAI,SAAS,CAAC,8BAA8B,CAAC,CAAA;IACrD,CAAC;IACD,MAAM,UAAU,GAAG,MAAM,IAAA,0BAAe,EAAC,cAAI,CAAC,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,SAAS,CAAC,UAAU,IAAI,cAAc,CAAC,CAAC,CAAA;IAClH,MAAM,OAAO,GAAG,MAAM,IAAA,kCAAmB,EAAC,UAAU,CAAC,CAAA;IACrD,MAAM,UAAU,GAAG,IAAA,0CAAmB,EAAC;QACrC,GAAG,SAAS,EAAE,UAAU;QACxB,GAAG,OAAO,EAAE,UAAU;KACvB,CAAC,CAAA;IACF,MAAM,eAAe,GAAG,cAAI,CAAC,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA;IACtD,MAAM,eAAe,GAAG,MAAM,IAAA,iCAAmB,EAAC,eAAe,EAAE,EAAE,kBAAkB,EAAE,KAAK,EAAE,CAAC,CAAA;IACjG,MAAM,cAAc,GAAG,MAAM,IAAA,gCAAkB,EAAC,SAAS,CAA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,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,KA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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/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;
|
|
@@ -21,6 +26,23 @@ interface GetTreeOpts {
|
|
|
21
26
|
virtualStoreDirMaxLength: number;
|
|
22
27
|
modulesDir?: string;
|
|
23
28
|
parentDir?: string;
|
|
29
|
+
showDedupedSearchMatches?: boolean;
|
|
30
|
+
graph: DependencyGraph;
|
|
31
|
+
materializationCache: MaterializationCache;
|
|
24
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>;
|
|
25
47
|
export declare function getTree(opts: GetTreeOpts, parentId: TreeNodeId): PackageNode[];
|
|
26
48
|
export {};
|
package/lib/getTree.js
CHANGED
|
@@ -6,143 +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 = (keypath, nodeId, parentDir) => getTreeHelper(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
|
-
|
|
56
|
-
|
|
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);
|
|
57
29
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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`);
|
|
69
59
|
}
|
|
70
|
-
const
|
|
60
|
+
const childTreeMaxDepth = maxDepth - 1;
|
|
61
|
+
const linkedPathBaseDir = parentId.type === 'importer'
|
|
62
|
+
? path_1.default.join(ctx.lockfileDir, parentId.importerId)
|
|
63
|
+
: ctx.lockfileDir;
|
|
71
64
|
const resultDependencies = [];
|
|
72
|
-
let
|
|
73
|
-
let
|
|
74
|
-
|
|
75
|
-
|
|
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
|
+
}
|
|
76
72
|
const { pkgInfo: packageInfo, readManifest } = (0, getPkgInfo_js_1.getPkgInfo)({
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
73
|
+
...ctx,
|
|
74
|
+
alias: edge.alias,
|
|
75
|
+
ref: edge.ref,
|
|
76
|
+
peers: graphNode.peers,
|
|
81
77
|
linkedPathBaseDir,
|
|
82
|
-
|
|
83
|
-
ref,
|
|
84
|
-
registries: opts.registries,
|
|
85
|
-
skipped: opts.skipped,
|
|
86
|
-
wantedPackages: opts.wantedPackages,
|
|
87
|
-
virtualStoreDir: opts.virtualStoreDir,
|
|
88
|
-
virtualStoreDirMaxLength: opts.virtualStoreDirMaxLength,
|
|
89
|
-
modulesDir: opts.modulesDir,
|
|
90
|
-
parentDir: opts.parentDir,
|
|
78
|
+
parentDir,
|
|
91
79
|
});
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
alias,
|
|
80
|
+
const searchMatch = ctx.search?.({
|
|
81
|
+
alias: edge.alias,
|
|
95
82
|
name: packageInfo.name,
|
|
96
83
|
version: packageInfo.version,
|
|
97
84
|
readManifest,
|
|
98
85
|
});
|
|
99
86
|
let newEntry = null;
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
if (opts.onlyProjects && nodeId?.type !== 'importer') {
|
|
107
|
-
continue;
|
|
108
|
-
}
|
|
109
|
-
else if (nodeId == null) {
|
|
110
|
-
circular = false;
|
|
111
|
-
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) {
|
|
112
93
|
newEntry = packageInfo;
|
|
113
94
|
}
|
|
95
|
+
else {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
114
98
|
}
|
|
115
99
|
else {
|
|
116
100
|
let dependencies;
|
|
117
|
-
|
|
101
|
+
let childHasSearchMatch = false;
|
|
102
|
+
let childSearchMessages = [];
|
|
103
|
+
let dedupedCount;
|
|
104
|
+
const circular = ctx.ancestors.has(edge.target.id);
|
|
118
105
|
if (circular) {
|
|
119
106
|
dependencies = [];
|
|
120
107
|
}
|
|
121
108
|
else {
|
|
122
|
-
const
|
|
123
|
-
const
|
|
124
|
-
if (
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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;
|
|
130
117
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
height: children.height,
|
|
135
|
-
});
|
|
118
|
+
if (ctx.showDedupedSearchMatches) {
|
|
119
|
+
dedupedHasSearchMatch = cached.hasSearchMatch;
|
|
120
|
+
dedupedSearchMessages = cached.searchMessages;
|
|
136
121
|
}
|
|
137
122
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
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);
|
|
146
142
|
}
|
|
147
143
|
if (dependencies.length > 0) {
|
|
148
144
|
newEntry = {
|
|
@@ -150,51 +146,70 @@ function getTreeHelper(dependenciesCache, opts, keypath, parentId) {
|
|
|
150
146
|
dependencies,
|
|
151
147
|
};
|
|
152
148
|
}
|
|
153
|
-
else if (
|
|
149
|
+
else if (ctx.search == null || Boolean(searchMatch) || dedupedHasSearchMatch) {
|
|
154
150
|
newEntry = packageInfo;
|
|
155
151
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
if (circular) {
|
|
159
|
-
newEntry.circular = true;
|
|
160
|
-
resultCircular = true;
|
|
152
|
+
else {
|
|
153
|
+
continue;
|
|
161
154
|
}
|
|
162
|
-
if (
|
|
163
|
-
newEntry.
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
155
|
+
if (dedupedCount != null) {
|
|
156
|
+
newEntry.deduped = true;
|
|
157
|
+
newEntry.dedupedDependenciesCount = dedupedCount;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (searchMatch) {
|
|
161
|
+
newEntry.searched = true;
|
|
162
|
+
resultHasSearchMatch = true;
|
|
163
|
+
if (typeof searchMatch === 'string') {
|
|
164
|
+
newEntry.searchMessage = searchMatch;
|
|
165
|
+
resultSearchMessages?.push(searchMatch);
|
|
167
166
|
}
|
|
168
|
-
|
|
169
|
-
|
|
167
|
+
}
|
|
168
|
+
else if (dedupedHasSearchMatch) {
|
|
169
|
+
newEntry.searched = true;
|
|
170
|
+
if (dedupedSearchMessages.length > 0) {
|
|
171
|
+
newEntry.searchMessage = dedupedSearchMessages.join('\n');
|
|
170
172
|
}
|
|
171
173
|
}
|
|
174
|
+
if (!newEntry.isPeer || !ctx.excludePeerDependencies || newEntry.dependencies?.length) {
|
|
175
|
+
resultDependencies.push(newEntry);
|
|
176
|
+
resultCount += 1 + (newEntry.dependencies?.length ? childCount : 0);
|
|
177
|
+
}
|
|
172
178
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
179
|
+
return {
|
|
180
|
+
count: resultCount,
|
|
181
|
+
hasSearchMatch: resultHasSearchMatch,
|
|
182
|
+
nodes: resultDependencies,
|
|
183
|
+
searchMessages: resultSearchMessages ?? [],
|
|
176
184
|
};
|
|
177
|
-
if (resultCircular) {
|
|
178
|
-
result.circular = resultCircular;
|
|
179
|
-
}
|
|
180
|
-
return result;
|
|
181
185
|
}
|
|
182
186
|
/**
|
|
183
|
-
*
|
|
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).
|
|
184
192
|
*/
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
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;
|
|
199
214
|
}
|
|
200
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,GAAG,CAAC,IAAA,mCAAmB,EAAC,QAAQ,CAAC,CAAC,CAAA;IAE5C,MAAM,GAAG,GAA2B;QAClC,GAAG,IAAI;QACP,SAAS;KACV,CAAA;IAED,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,mBAAmB,CAAC,GAAG,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,CAAA;IAEzF,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I,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,20 +35,20 @@
|
|
|
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
38
|
"@pnpm/matcher": "1000.1.0",
|
|
40
|
-
"@pnpm/
|
|
39
|
+
"@pnpm/lockfile.utils": "1004.0.1",
|
|
41
40
|
"@pnpm/modules-yaml": "1002.0.0",
|
|
42
|
-
"@pnpm/
|
|
41
|
+
"@pnpm/normalize-registries": "1000.1.9",
|
|
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.
|
|
50
|
-
"@pnpm/
|
|
51
|
-
"@pnpm/
|
|
49
|
+
"@pnpm/reviewing.dependencies-hierarchy": "1001.2.7",
|
|
50
|
+
"@pnpm/constants": "1001.3.1",
|
|
51
|
+
"@pnpm/test-fixtures": "1000.0.0"
|
|
52
52
|
},
|
|
53
53
|
"engines": {
|
|
54
54
|
"node": ">=18.12"
|
|
@@ -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;QAC7C,MAAM,QAAQ,GAAG,IAAA,mCAAmB,EAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QAEnD,0EAA0E;QAC1E,uEAAuE;QACvE,+CAA+C;QAC/C,EAAE;QACF,4EAA4E;QAC5E,6DAA6D;QAC7D,MAAM,iBAAiB,GAAG,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,QAAQ,CAA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