@vltpkg/graph 0.0.0-22 → 0.0.0-23
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/esm/ideal/append-nodes.d.ts +7 -0
- package/dist/esm/ideal/append-nodes.d.ts.map +1 -1
- package/dist/esm/ideal/append-nodes.js +122 -29
- package/dist/esm/ideal/append-nodes.js.map +1 -1
- package/dist/esm/visualization/human-readable-output.d.ts.map +1 -1
- package/dist/esm/visualization/human-readable-output.js +2 -2
- package/dist/esm/visualization/human-readable-output.js.map +1 -1
- package/package.json +24 -24
|
@@ -6,5 +6,12 @@ import type { Dependency } from '../dependencies.ts';
|
|
|
6
6
|
import type { Graph } from '../graph.ts';
|
|
7
7
|
import type { Node } from '../node.ts';
|
|
8
8
|
import type { GraphModifier, ModifierActiveEntry } from '../modifiers.ts';
|
|
9
|
+
/**
|
|
10
|
+
* Append new nodes in the given `graph` for dependencies specified at `add`
|
|
11
|
+
* and missing dependencies from the `deps` parameter.
|
|
12
|
+
*
|
|
13
|
+
* It also applies any modifiers that applies to a given node as it processes
|
|
14
|
+
* and builds the graph.
|
|
15
|
+
*/
|
|
9
16
|
export declare const appendNodes: (add: Map<string, Dependency>, packageInfo: PackageInfoClient, graph: Graph, fromNode: Node, deps: Dependency[], scurry: PathScurry, options: SpecOptions, seen: Set<DepID>, modifiers?: GraphModifier, modifierRefs?: Map<string, ModifierActiveEntry>) => Promise<void>;
|
|
10
17
|
//# sourceMappingURL=append-nodes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"append-nodes.d.ts","sourceRoot":"","sources":["../../../src/ideal/append-nodes.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAE3C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAE7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"append-nodes.d.ts","sourceRoot":"","sources":["../../../src/ideal/append-nodes.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAE3C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAE7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAO/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAE7C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAEtC,OAAO,KAAK,EACV,aAAa,EACb,mBAAmB,EACpB,MAAM,iBAAiB,CAAA;AA4TxB;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,QACjB,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,eACf,iBAAiB,SACvB,KAAK,YACF,IAAI,QACR,UAAU,EAAE,UACV,UAAU,WACT,WAAW,QACd,GAAG,CAAC,KAAK,CAAC,cACJ,aAAa,iBACV,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,kBAqEhD,CAAA"}
|
|
@@ -36,13 +36,14 @@ const getFileTypeInfo = (spec, fromNode, scurry) => {
|
|
|
36
36
|
};
|
|
37
37
|
};
|
|
38
38
|
const isStringArray = (a) => Array.isArray(a) && !a.some(b => typeof b !== 'string');
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Fetch manifests for dependencies and create placement tasks.
|
|
41
|
+
*/
|
|
42
|
+
const fetchManifestsForDeps = async (packageInfo, graph, fromNode, deps, scurry, modifierRefs, depth = 0) => {
|
|
43
|
+
// Create fetch tasks for all dependencies at this level
|
|
44
|
+
const fetchTasks = [];
|
|
45
|
+
for (const { spec: originalSpec, type } of deps) {
|
|
46
|
+
let spec = originalSpec;
|
|
46
47
|
const fileTypeInfo = getFileTypeInfo(spec, fromNode, scurry);
|
|
47
48
|
const activeModifier = modifierRefs?.get(spec.name);
|
|
48
49
|
// here is the place we swap specs if a edge modifier was defined
|
|
@@ -55,17 +56,19 @@ export const appendNodes = async (add, packageInfo, graph, fromNode, deps, scurr
|
|
|
55
56
|
'spec' in activeModifier.modifier) {
|
|
56
57
|
spec = activeModifier.modifier.spec;
|
|
57
58
|
if (spec.bareSpec === '-') {
|
|
58
|
-
|
|
59
|
+
continue;
|
|
59
60
|
}
|
|
60
61
|
}
|
|
61
62
|
const existingNode = graph.findResolution(spec, fromNode, queryModifier);
|
|
62
63
|
if (existingNode) {
|
|
63
64
|
graph.addEdge(type, spec, fromNode, existingNode);
|
|
64
|
-
|
|
65
|
+
continue;
|
|
65
66
|
}
|
|
66
67
|
const edgeOptional = type === 'optional' || type === 'peerOptional';
|
|
67
|
-
|
|
68
|
+
// Start manifest fetch immediately for parallel processing
|
|
69
|
+
const manifestPromise = packageInfo
|
|
68
70
|
.manifest(spec, { from: scurry.resolve(fromNode.location) })
|
|
71
|
+
.then(manifest => manifest)
|
|
69
72
|
.catch((er) => {
|
|
70
73
|
// optional deps ignored if inaccessible
|
|
71
74
|
if (edgeOptional || fromNode.optional) {
|
|
@@ -73,36 +76,72 @@ export const appendNodes = async (add, packageInfo, graph, fromNode, deps, scurr
|
|
|
73
76
|
}
|
|
74
77
|
throw er;
|
|
75
78
|
});
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
const fetchTask = {
|
|
80
|
+
spec,
|
|
81
|
+
type,
|
|
82
|
+
fromNode,
|
|
83
|
+
fileTypeInfo,
|
|
84
|
+
activeModifier,
|
|
85
|
+
queryModifier,
|
|
86
|
+
edgeOptional,
|
|
87
|
+
manifestPromise,
|
|
88
|
+
depth,
|
|
89
|
+
};
|
|
90
|
+
fetchTasks.push(fetchTask);
|
|
91
|
+
}
|
|
92
|
+
// Create placement tasks
|
|
93
|
+
const placementTasks = [];
|
|
94
|
+
for (const fetchTask of fetchTasks) {
|
|
95
|
+
const manifest = await fetchTask.manifestPromise;
|
|
96
|
+
placementTasks.push({
|
|
97
|
+
fetchTask,
|
|
98
|
+
manifest,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
return placementTasks;
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Process placement tasks and collect child dependencies
|
|
105
|
+
*/
|
|
106
|
+
const processPlacementTasks = async (add, graph, options, placementTasks, modifiers) => {
|
|
107
|
+
const childDepsToProcess = [];
|
|
108
|
+
for (const placementTask of placementTasks) {
|
|
109
|
+
const { fetchTask, manifest } = placementTask;
|
|
110
|
+
let { spec } = fetchTask;
|
|
111
|
+
const type = fetchTask.type;
|
|
112
|
+
const fromNode = fetchTask.fromNode;
|
|
113
|
+
const fileTypeInfo = fetchTask.fileTypeInfo;
|
|
114
|
+
const activeModifier = fetchTask.activeModifier;
|
|
115
|
+
const queryModifier = fetchTask.queryModifier;
|
|
116
|
+
const edgeOptional = fetchTask.edgeOptional;
|
|
117
|
+
// Handle nameless dependencies
|
|
118
|
+
if (manifest?.name && spec.name === '(unknown)') {
|
|
81
119
|
const s = add.get(String(spec));
|
|
82
120
|
if (s) {
|
|
83
121
|
// removes the previous, placeholder entry key
|
|
84
122
|
add.delete(String(spec));
|
|
85
123
|
// replaces spec with a version with the correct name
|
|
86
|
-
spec = Spec.parse(
|
|
124
|
+
spec = Spec.parse(manifest.name, spec.bareSpec, options);
|
|
87
125
|
// updates the add map with the fixed up spec
|
|
88
126
|
const n = asDependency({
|
|
89
127
|
...s,
|
|
90
128
|
spec,
|
|
91
129
|
});
|
|
92
|
-
add.set(
|
|
130
|
+
add.set(manifest.name, n);
|
|
93
131
|
}
|
|
94
132
|
}
|
|
95
|
-
|
|
133
|
+
// handles missing manifest resolution
|
|
134
|
+
if (!manifest) {
|
|
96
135
|
if (!edgeOptional && fromNode.isOptional()) {
|
|
97
136
|
// failed resolution of a non-optional dep of an optional node
|
|
98
137
|
// have to clean up the dependents
|
|
99
138
|
removeOptionalSubgraph(graph, fromNode);
|
|
100
|
-
|
|
139
|
+
continue;
|
|
101
140
|
}
|
|
102
141
|
else if (edgeOptional) {
|
|
103
142
|
// failed resolution of an optional dep, just ignore it,
|
|
104
143
|
// nothing to prune because we never added it in the first place.
|
|
105
|
-
|
|
144
|
+
continue;
|
|
106
145
|
}
|
|
107
146
|
else {
|
|
108
147
|
throw error('failed to resolve dependency', {
|
|
@@ -111,7 +150,8 @@ export const appendNodes = async (add, packageInfo, graph, fromNode, deps, scurr
|
|
|
111
150
|
});
|
|
112
151
|
}
|
|
113
152
|
}
|
|
114
|
-
|
|
153
|
+
// places a new node in the graph representing a newly seen dependency
|
|
154
|
+
const node = graph.placePackage(fromNode, type, spec, normalizeManifest(manifest), fileTypeInfo?.id, queryModifier);
|
|
115
155
|
/* c8 ignore start - not possible, already ensured manifest */
|
|
116
156
|
if (!node) {
|
|
117
157
|
throw error('failed to place package', {
|
|
@@ -120,29 +160,32 @@ export const appendNodes = async (add, packageInfo, graph, fromNode, deps, scurr
|
|
|
120
160
|
});
|
|
121
161
|
}
|
|
122
162
|
/* c8 ignore stop */
|
|
163
|
+
// update the node modifier tracker
|
|
123
164
|
if (activeModifier) {
|
|
124
165
|
modifiers?.updateActiveEntry(node, activeModifier);
|
|
125
166
|
}
|
|
167
|
+
// updates graph node information
|
|
126
168
|
if (fileTypeInfo?.path && fileTypeInfo.isDirectory) {
|
|
127
169
|
node.location = fileTypeInfo.path;
|
|
128
170
|
}
|
|
129
171
|
node.setResolved();
|
|
130
|
-
|
|
131
|
-
const bundleDeps =
|
|
172
|
+
// Collect child dependencies for processing in the next level
|
|
173
|
+
const bundleDeps = manifest.bundleDependencies;
|
|
132
174
|
const bundled = new Set((node.id.startsWith('git') ||
|
|
133
175
|
node.importer ||
|
|
134
176
|
!isStringArray(bundleDeps)) ?
|
|
135
177
|
[]
|
|
136
178
|
: bundleDeps);
|
|
179
|
+
// recursively process all child dependencies in the manifest
|
|
137
180
|
const nextDeps = [];
|
|
138
181
|
for (const depTypeName of longDependencyTypes) {
|
|
139
|
-
const depRecord =
|
|
182
|
+
const depRecord = manifest[depTypeName];
|
|
140
183
|
if (depRecord && shouldInstallDepType(node, depTypeName)) {
|
|
141
184
|
for (const [name, bareSpec] of Object.entries(depRecord)) {
|
|
142
185
|
if (bundled.has(name))
|
|
143
186
|
continue;
|
|
144
187
|
nextDeps.push({
|
|
145
|
-
type: shorten(depTypeName, name,
|
|
188
|
+
type: shorten(depTypeName, name, manifest),
|
|
146
189
|
spec: Spec.parse(name, bareSpec, {
|
|
147
190
|
...options,
|
|
148
191
|
registry: spec.registry,
|
|
@@ -151,10 +194,60 @@ export const appendNodes = async (add, packageInfo, graph, fromNode, deps, scurr
|
|
|
151
194
|
}
|
|
152
195
|
}
|
|
153
196
|
}
|
|
154
|
-
if (nextDeps.length) {
|
|
155
|
-
|
|
197
|
+
if (nextDeps.length > 0) {
|
|
198
|
+
childDepsToProcess.push({
|
|
199
|
+
node,
|
|
200
|
+
deps: nextDeps,
|
|
201
|
+
modifierRefs: modifiers?.tryDependencies(node, nextDeps),
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return { childDepsToProcess };
|
|
206
|
+
};
|
|
207
|
+
/**
|
|
208
|
+
* Append new nodes in the given `graph` for dependencies specified at `add`
|
|
209
|
+
* and missing dependencies from the `deps` parameter.
|
|
210
|
+
*
|
|
211
|
+
* It also applies any modifiers that applies to a given node as it processes
|
|
212
|
+
* and builds the graph.
|
|
213
|
+
*/
|
|
214
|
+
export const appendNodes = async (add, packageInfo, graph, fromNode, deps, scurry, options, seen, modifiers, modifierRefs) => {
|
|
215
|
+
/* c8 ignore next */
|
|
216
|
+
if (seen.has(fromNode.id))
|
|
217
|
+
return;
|
|
218
|
+
seen.add(fromNode.id);
|
|
219
|
+
// Use a queue for breadth-first processing
|
|
220
|
+
let currentLevelDeps = [
|
|
221
|
+
{ node: fromNode, deps, modifierRefs, depth: 0 },
|
|
222
|
+
];
|
|
223
|
+
while (currentLevelDeps.length > 0) {
|
|
224
|
+
const nextLevelDeps = [];
|
|
225
|
+
// Process all nodes at the current level in parallel
|
|
226
|
+
const levelResults = await Promise.all(currentLevelDeps.map(async ({ node, deps: nodeDeps, modifierRefs: nodeModifierRefs, depth, }) => {
|
|
227
|
+
// Mark node as seen when we start processing its dependencies
|
|
228
|
+
seen.add(node.id);
|
|
229
|
+
// Fetch manifests for this node's dependencies
|
|
230
|
+
const placementTasks = await fetchManifestsForDeps(packageInfo, graph, node,
|
|
231
|
+
// Sort dependencies by spec.name for deterministic ordering
|
|
232
|
+
nodeDeps.sort((a, b) => a.spec.name.localeCompare(b.spec.name, 'en')), scurry, nodeModifierRefs, depth);
|
|
233
|
+
// Process the placement tasks and get child dependencies
|
|
234
|
+
return await processPlacementTasks(add, graph, options, placementTasks, modifiers);
|
|
235
|
+
}));
|
|
236
|
+
// Collect all child dependencies for the next level
|
|
237
|
+
for (const { childDepsToProcess } of levelResults) {
|
|
238
|
+
for (const childDep of childDepsToProcess) {
|
|
239
|
+
if (!seen.has(childDep.node.id)) {
|
|
240
|
+
/* c8 ignore next */
|
|
241
|
+
const currentDepth = currentLevelDeps[0]?.depth ?? 0;
|
|
242
|
+
nextLevelDeps.push({
|
|
243
|
+
...childDep,
|
|
244
|
+
depth: currentDepth + 1,
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
}
|
|
156
248
|
}
|
|
157
|
-
|
|
158
|
-
|
|
249
|
+
// Move to the next level
|
|
250
|
+
currentLevelDeps = nextLevelDeps;
|
|
251
|
+
}
|
|
159
252
|
};
|
|
160
253
|
//# sourceMappingURL=append-nodes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"append-nodes.js","source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AS,EACT,SAAS,EAAE,eAAe,CAAC,IAAI,EAAE,QAAQ,CAAC,CAC3C,CACF,CAAA;QACH,CAAC;QACD,MAAM,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAA;IAClC,CAAC,CAAC,CACH,CAAA;AACH,CAAC,CAAA","sourcesContent":["import { joinDepIDTuple } from '@vltpkg/dep-id'\nimport type { DepID } from '@vltpkg/dep-id'\nimport { error } from '@vltpkg/error-cause'\nimport type { PackageInfoClient } from '@vltpkg/package-info'\nimport { Spec } from '@vltpkg/spec'\nimport type { SpecOptions } from '@vltpkg/spec'\nimport { longDependencyTypes, normalizeManifest } from '@vltpkg/types'\nimport type { DependencyTypeLong, Manifest } from '@vltpkg/types'\nimport type { PathScurry } from 'path-scurry'\nimport { asDependency, shorten } from '../dependencies.ts'\nimport type { Dependency } from '../dependencies.ts'\nimport type { Graph } from '../graph.ts'\nimport type { Node } from '../node.ts'\nimport { removeOptionalSubgraph } from '../remove-optional-subgraph.ts'\nimport type {\n GraphModifier,\n ModifierActiveEntry,\n} from '../modifiers.ts'\n\ntype FileTypeInfo = {\n id: DepID\n path: string\n isDirectory: boolean\n}\n\n/**\n * Only install devDeps for git dependencies and importers\n * Everything else always gets installed\n */\nconst shouldInstallDepType = (\n node: Node,\n depType: DependencyTypeLong,\n) =>\n depType !== 'devDependencies' ||\n node.importer ||\n node.id.startsWith('git')\n\n/**\n * Retrieve the {@link DepID} and location for a `file:` type {@link Node}.\n */\nconst getFileTypeInfo = (\n spec: Spec,\n fromNode: Node,\n scurry: PathScurry,\n): FileTypeInfo | undefined => {\n const f = spec.final\n if (f.type !== 'file') return\n\n /* c8 ignore start - should be impossible */\n if (!f.file) {\n throw error('no path on file specifier', { spec })\n }\n /* c8 ignore stop */\n\n // Given that both linked folders and local tarballs (both defined with\n // usage of the `file:` spec prefix) location needs to be relative to their\n // parents, build the expected path and use it for both location and id\n const target = scurry.cwd.resolve(fromNode.location).resolve(f.file)\n const path = target.relativePosix()\n const id = joinDepIDTuple(['file', path])\n\n return {\n path,\n id,\n isDirectory: !!target.lstatSync()?.isDirectory(),\n }\n}\n\nconst isStringArray = (a: unknown): a is string[] =>\n Array.isArray(a) && !a.some(b => typeof b !== 'string')\n\nexport const appendNodes = async (\n add: Map<string, Dependency>,\n packageInfo: PackageInfoClient,\n graph: Graph,\n fromNode: Node,\n deps: Dependency[],\n scurry: PathScurry,\n options: SpecOptions,\n seen: Set<DepID>,\n modifiers?: GraphModifier,\n modifierRefs?: Map<string, ModifierActiveEntry>,\n) => {\n /* c8 ignore next */\n if (seen.has(fromNode.id)) return\n seen.add(fromNode.id)\n\n await Promise.all(\n deps.map(async ({ spec, type }) => {\n // see if there's a satisfying node in the graph currently\n const fileTypeInfo = getFileTypeInfo(spec, fromNode, scurry)\n const activeModifier = modifierRefs?.get(spec.name)\n\n // here is the place we swap specs if a edge modifier was defined\n const queryModifier = activeModifier?.modifier.query\n const completeModifier =\n activeModifier &&\n activeModifier.interactiveBreadcrumb.current ===\n activeModifier.modifier.breadcrumb.last\n if (\n queryModifier &&\n completeModifier &&\n 'spec' in activeModifier.modifier\n ) {\n spec = activeModifier.modifier.spec\n if (spec.bareSpec === '-') {\n return\n }\n }\n\n const existingNode = graph.findResolution(\n spec,\n fromNode,\n queryModifier,\n )\n if (existingNode) {\n graph.addEdge(type, spec, fromNode, existingNode)\n return\n }\n\n const edgeOptional =\n type === 'optional' || type === 'peerOptional'\n const mani = await packageInfo\n .manifest(spec, { from: scurry.resolve(fromNode.location) })\n .catch((er: unknown) => {\n // optional deps ignored if inaccessible\n if (edgeOptional || fromNode.optional) {\n return undefined\n }\n throw er\n })\n\n // when an user is adding a nameless dependency, e.g: `github:foo/bar`,\n // `file:./foo/bar`, we need to update the `add` option value to set the\n // correct name once we have it, so that it can properly be stored in\n // the `package.json` file at the end of reify.\n if (mani?.name && spec.name === '(unknown)') {\n const s = add.get(String(spec))\n if (s) {\n // removes the previous, placeholder entry key\n add.delete(String(spec))\n // replaces spec with a version with the correct name\n spec = Spec.parse(mani.name, spec.bareSpec, options)\n // updates the add map with the fixed up spec\n const n = asDependency({\n ...s,\n spec,\n })\n add.set(mani.name, n)\n }\n }\n\n if (!mani) {\n if (!edgeOptional && fromNode.isOptional()) {\n // failed resolution of a non-optional dep of an optional node\n // have to clean up the dependents\n removeOptionalSubgraph(graph, fromNode)\n return\n } else if (edgeOptional) {\n // failed resolution of an optional dep, just ignore it,\n // nothing to prune because we never added it in the first place.\n return\n } else {\n throw error('failed to resolve dependency', {\n spec,\n from: fromNode.location,\n })\n }\n }\n\n const node = graph.placePackage(\n fromNode,\n type,\n spec,\n normalizeManifest(mani as Manifest),\n fileTypeInfo?.id,\n queryModifier,\n )\n\n /* c8 ignore start - not possible, already ensured manifest */\n if (!node) {\n throw error('failed to place package', {\n from: fromNode.location,\n spec,\n })\n }\n /* c8 ignore stop */\n\n if (activeModifier) {\n modifiers?.updateActiveEntry(node, activeModifier)\n }\n\n if (fileTypeInfo?.path && fileTypeInfo.isDirectory) {\n node.location = fileTypeInfo.path\n }\n node.setResolved()\n const nestedAppends: Promise<unknown>[] = []\n\n const bundleDeps = node.manifest?.bundleDependencies\n const bundled = new Set<string>(\n (\n node.id.startsWith('git') ||\n node.importer ||\n !isStringArray(bundleDeps)\n ) ?\n []\n : bundleDeps,\n )\n\n const nextDeps: Dependency[] = []\n\n for (const depTypeName of longDependencyTypes) {\n const depRecord: Record<string, string> | undefined =\n mani[depTypeName]\n\n if (depRecord && shouldInstallDepType(node, depTypeName)) {\n for (const [name, bareSpec] of Object.entries(depRecord)) {\n if (bundled.has(name)) continue\n nextDeps.push({\n type: shorten(depTypeName, name, mani),\n spec: Spec.parse(name, bareSpec, {\n ...options,\n registry: spec.registry,\n }),\n })\n }\n }\n }\n\n if (nextDeps.length) {\n nestedAppends.push(\n appendNodes(\n add,\n packageInfo,\n graph,\n node,\n nextDeps,\n scurry,\n options,\n seen,\n modifiers,\n modifiers?.tryDependencies(node, nextDeps),\n ),\n )\n }\n await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AChC,GAAG,EACH,KAAK,EACL,OAAO,EACP,cAAc,EACd,SAAS,CACV,CAAA;QACH,CAAC,CACF,CACF,CAAA;QAED,oDAAoD;QACpD,KAAK,MAAM,EAAE,kBAAkB,EAAE,IAAI,YAAY,EAAE,CAAC;YAClD,KAAK,MAAM,QAAQ,IAAI,kBAAkB,EAAE,CAAC;gBAC1C,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;oBAChC,oBAAoB;oBACpB,MAAM,YAAY,GAAG,gBAAgB,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,CAAC,CAAA;oBACpD,aAAa,CAAC,IAAI,CAAC;wBACjB,GAAG,QAAQ;wBACX,KAAK,EAAE,YAAY,GAAG,CAAC;qBACxB,CAAC,CAAA;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;QAED,yBAAyB;QACzB,gBAAgB,GAAG,aAAa,CAAA;IAClC,CAAC;AACH,CAAC,CAAA","sourcesContent":["import { joinDepIDTuple } from '@vltpkg/dep-id'\nimport type { DepID } from '@vltpkg/dep-id'\nimport { error } from '@vltpkg/error-cause'\nimport type { PackageInfoClient } from '@vltpkg/package-info'\nimport { Spec } from '@vltpkg/spec'\nimport type { SpecOptions } from '@vltpkg/spec'\nimport { longDependencyTypes, normalizeManifest } from '@vltpkg/types'\nimport type {\n DependencyTypeLong,\n DependencySaveType,\n Manifest,\n} from '@vltpkg/types'\nimport type { PathScurry } from 'path-scurry'\nimport { asDependency, shorten } from '../dependencies.ts'\nimport type { Dependency } from '../dependencies.ts'\nimport type { Graph } from '../graph.ts'\nimport type { Node } from '../node.ts'\nimport { removeOptionalSubgraph } from '../remove-optional-subgraph.ts'\nimport type {\n GraphModifier,\n ModifierActiveEntry,\n} from '../modifiers.ts'\n\ntype FileTypeInfo = {\n id: DepID\n path: string\n isDirectory: boolean\n}\n\n/**\n * Only install devDeps for git dependencies and importers\n * Everything else always gets installed\n */\nconst shouldInstallDepType = (\n node: Node,\n depType: DependencyTypeLong,\n) =>\n depType !== 'devDependencies' ||\n node.importer ||\n node.id.startsWith('git')\n\n/**\n * Retrieve the {@link DepID} and location for a `file:` type {@link Node}.\n */\nconst getFileTypeInfo = (\n spec: Spec,\n fromNode: Node,\n scurry: PathScurry,\n): FileTypeInfo | undefined => {\n const f = spec.final\n if (f.type !== 'file') return\n\n /* c8 ignore start - should be impossible */\n if (!f.file) {\n throw error('no path on file specifier', { spec })\n }\n /* c8 ignore stop */\n\n // Given that both linked folders and local tarballs (both defined with\n // usage of the `file:` spec prefix) location needs to be relative to their\n // parents, build the expected path and use it for both location and id\n const target = scurry.cwd.resolve(fromNode.location).resolve(f.file)\n const path = target.relativePosix()\n const id = joinDepIDTuple(['file', path])\n\n return {\n path,\n id,\n isDirectory: !!target.lstatSync()?.isDirectory(),\n }\n}\n\nconst isStringArray = (a: unknown): a is string[] =>\n Array.isArray(a) && !a.some(b => typeof b !== 'string')\n\n/**\n * Represents a manifest fetch operation with all the context needed.\n */\ntype ManifestFetchTask = {\n spec: Spec\n type: DependencySaveType\n fromNode: Node\n fileTypeInfo?: FileTypeInfo\n activeModifier?: ModifierActiveEntry\n queryModifier?: string\n edgeOptional: boolean\n manifestPromise: Promise<Manifest | undefined>\n depth: number\n}\n\n/**\n * Represents a node placement operation that depends on a resolved manifest.\n */\ntype NodePlacementTask = {\n fetchTask: ManifestFetchTask\n manifest: Manifest | undefined\n node?: Node\n childDeps?: Dependency[]\n childModifierRefs?: Map<string, ModifierActiveEntry>\n}\n\n/**\n * Represents an ongoing append operation for a node and its dependencies.\n */\ntype AppendNodeEntry = {\n node: Node\n deps: Dependency[]\n modifierRefs?: Map<string, ModifierActiveEntry>\n depth: number\n}\n\n/**\n * Fetch manifests for dependencies and create placement tasks.\n */\nconst fetchManifestsForDeps = async (\n packageInfo: PackageInfoClient,\n graph: Graph,\n fromNode: Node,\n deps: Dependency[],\n scurry: PathScurry,\n modifierRefs?: Map<string, ModifierActiveEntry>,\n depth = 0,\n): Promise<NodePlacementTask[]> => {\n // Create fetch tasks for all dependencies at this level\n const fetchTasks: ManifestFetchTask[] = []\n\n for (const { spec: originalSpec, type } of deps) {\n let spec = originalSpec\n const fileTypeInfo = getFileTypeInfo(spec, fromNode, scurry)\n const activeModifier = modifierRefs?.get(spec.name)\n\n // here is the place we swap specs if a edge modifier was defined\n const queryModifier = activeModifier?.modifier.query\n const completeModifier =\n activeModifier &&\n activeModifier.interactiveBreadcrumb.current ===\n activeModifier.modifier.breadcrumb.last\n if (\n queryModifier &&\n completeModifier &&\n 'spec' in activeModifier.modifier\n ) {\n spec = activeModifier.modifier.spec\n if (spec.bareSpec === '-') {\n continue\n }\n }\n\n const existingNode = graph.findResolution(\n spec,\n fromNode,\n queryModifier,\n )\n if (existingNode) {\n graph.addEdge(type, spec, fromNode, existingNode)\n continue\n }\n\n const edgeOptional =\n type === 'optional' || type === 'peerOptional'\n\n // Start manifest fetch immediately for parallel processing\n const manifestPromise = packageInfo\n .manifest(spec, { from: scurry.resolve(fromNode.location) })\n .then(manifest => manifest as Manifest | undefined)\n .catch((er: unknown) => {\n // optional deps ignored if inaccessible\n if (edgeOptional || fromNode.optional) {\n return undefined\n }\n throw er\n })\n\n const fetchTask: ManifestFetchTask = {\n spec,\n type,\n fromNode,\n fileTypeInfo,\n activeModifier,\n queryModifier,\n edgeOptional,\n manifestPromise,\n depth,\n }\n\n fetchTasks.push(fetchTask)\n }\n\n // Create placement tasks\n const placementTasks: NodePlacementTask[] = []\n for (const fetchTask of fetchTasks) {\n const manifest = await fetchTask.manifestPromise\n\n placementTasks.push({\n fetchTask,\n manifest,\n })\n }\n\n return placementTasks\n}\n\n/**\n * Process placement tasks and collect child dependencies\n */\nconst processPlacementTasks = async (\n add: Map<string, Dependency>,\n graph: Graph,\n options: SpecOptions,\n placementTasks: NodePlacementTask[],\n modifiers?: GraphModifier,\n): Promise<{\n childDepsToProcess: Omit<AppendNodeEntry, 'depth'>[]\n}> => {\n const childDepsToProcess: Omit<AppendNodeEntry, 'depth'>[] = []\n\n for (const placementTask of placementTasks) {\n const { fetchTask, manifest } = placementTask\n let { spec } = fetchTask\n const type = fetchTask.type\n const fromNode = fetchTask.fromNode\n const fileTypeInfo = fetchTask.fileTypeInfo\n const activeModifier = fetchTask.activeModifier\n const queryModifier = fetchTask.queryModifier\n const edgeOptional = fetchTask.edgeOptional\n\n // Handle nameless dependencies\n if (manifest?.name && spec.name === '(unknown)') {\n const s = add.get(String(spec))\n if (s) {\n // removes the previous, placeholder entry key\n add.delete(String(spec))\n // replaces spec with a version with the correct name\n spec = Spec.parse(manifest.name, spec.bareSpec, options)\n // updates the add map with the fixed up spec\n const n = asDependency({\n ...s,\n spec,\n })\n add.set(manifest.name, n)\n }\n }\n\n // handles missing manifest resolution\n if (!manifest) {\n if (!edgeOptional && fromNode.isOptional()) {\n // failed resolution of a non-optional dep of an optional node\n // have to clean up the dependents\n removeOptionalSubgraph(graph, fromNode)\n continue\n } else if (edgeOptional) {\n // failed resolution of an optional dep, just ignore it,\n // nothing to prune because we never added it in the first place.\n continue\n } else {\n throw error('failed to resolve dependency', {\n spec,\n from: fromNode.location,\n })\n }\n }\n\n // places a new node in the graph representing a newly seen dependency\n const node = graph.placePackage(\n fromNode,\n type,\n spec,\n normalizeManifest(manifest),\n fileTypeInfo?.id,\n queryModifier,\n )\n\n /* c8 ignore start - not possible, already ensured manifest */\n if (!node) {\n throw error('failed to place package', {\n from: fromNode.location,\n spec,\n })\n }\n /* c8 ignore stop */\n\n // update the node modifier tracker\n if (activeModifier) {\n modifiers?.updateActiveEntry(node, activeModifier)\n }\n\n // updates graph node information\n if (fileTypeInfo?.path && fileTypeInfo.isDirectory) {\n node.location = fileTypeInfo.path\n }\n node.setResolved()\n\n // Collect child dependencies for processing in the next level\n const bundleDeps = manifest.bundleDependencies\n const bundled = new Set<string>(\n (\n node.id.startsWith('git') ||\n node.importer ||\n !isStringArray(bundleDeps)\n ) ?\n []\n : bundleDeps,\n )\n\n // recursively process all child dependencies in the manifest\n const nextDeps: Dependency[] = []\n\n for (const depTypeName of longDependencyTypes) {\n const depRecord: Record<string, string> | undefined =\n manifest[depTypeName]\n\n if (depRecord && shouldInstallDepType(node, depTypeName)) {\n for (const [name, bareSpec] of Object.entries(depRecord)) {\n if (bundled.has(name)) continue\n nextDeps.push({\n type: shorten(depTypeName, name, manifest),\n spec: Spec.parse(name, bareSpec, {\n ...options,\n registry: spec.registry,\n }),\n })\n }\n }\n }\n\n if (nextDeps.length > 0) {\n childDepsToProcess.push({\n node,\n deps: nextDeps,\n modifierRefs: modifiers?.tryDependencies(node, nextDeps),\n })\n }\n }\n\n return { childDepsToProcess }\n}\n\n/**\n * Append new nodes in the given `graph` for dependencies specified at `add`\n * and missing dependencies from the `deps` parameter.\n *\n * It also applies any modifiers that applies to a given node as it processes\n * and builds the graph.\n */\nexport const appendNodes = async (\n add: Map<string, Dependency>,\n packageInfo: PackageInfoClient,\n graph: Graph,\n fromNode: Node,\n deps: Dependency[],\n scurry: PathScurry,\n options: SpecOptions,\n seen: Set<DepID>,\n modifiers?: GraphModifier,\n modifierRefs?: Map<string, ModifierActiveEntry>,\n) => {\n /* c8 ignore next */\n if (seen.has(fromNode.id)) return\n seen.add(fromNode.id)\n\n // Use a queue for breadth-first processing\n let currentLevelDeps: AppendNodeEntry[] = [\n { node: fromNode, deps, modifierRefs, depth: 0 },\n ]\n\n while (currentLevelDeps.length > 0) {\n const nextLevelDeps: AppendNodeEntry[] = []\n\n // Process all nodes at the current level in parallel\n const levelResults = await Promise.all(\n currentLevelDeps.map(\n async ({\n node,\n deps: nodeDeps,\n modifierRefs: nodeModifierRefs,\n depth,\n }: AppendNodeEntry) => {\n // Mark node as seen when we start processing its dependencies\n seen.add(node.id)\n\n // Fetch manifests for this node's dependencies\n const placementTasks = await fetchManifestsForDeps(\n packageInfo,\n graph,\n node,\n // Sort dependencies by spec.name for deterministic ordering\n nodeDeps.sort((a, b) =>\n a.spec.name.localeCompare(b.spec.name, 'en'),\n ),\n scurry,\n nodeModifierRefs,\n depth,\n )\n\n // Process the placement tasks and get child dependencies\n return await processPlacementTasks(\n add,\n graph,\n options,\n placementTasks,\n modifiers,\n )\n },\n ),\n )\n\n // Collect all child dependencies for the next level\n for (const { childDepsToProcess } of levelResults) {\n for (const childDep of childDepsToProcess) {\n if (!seen.has(childDep.node.id)) {\n /* c8 ignore next */\n const currentDepth = currentLevelDeps[0]?.depth ?? 0\n nextLevelDeps.push({\n ...childDep,\n depth: currentDepth + 1,\n })\n }\n }\n }\n\n // Move to the next level\n currentLevelDeps = nextLevelDeps\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"human-readable-output.d.ts","sourceRoot":"","sources":["../../../src/visualization/human-readable-output.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAkBrD,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,IAAI,EAAE,QAAQ,GAAG,SAAS,CAAA;IAC1B,IAAI,EAAE,QAAQ,GAAG,SAAS,CAAA;IAC1B,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;IACf,UAAU,EAAE,OAAO,CAAA;IACnB,IAAI,EAAE,OAAO,CAAA;IACb,OAAO,EAAE,OAAO,CAAA;IAChB,MAAM,EAAE,QAAQ,GAAG,SAAS,CAAA;CAC7B,CAAA;AAED,MAAM,MAAM,wBAAwB,GAAG;IACrC,KAAK,EAAE,QAAQ,EAAE,CAAA;IACjB,SAAS,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAA;IACxB,KAAK,EAAE,QAAQ,EAAE,CAAA;IACjB,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAC7B,CAAA;AAED,MAAM,MAAM,OAAO,GAAG,GAAG,CAAC,QAAQ,GAAG,SAAS,EAAE,QAAQ,CAAC,CAAA;AAEzD,MAAM,MAAM,OAAO,GAAG,GAAG,CAAC,QAAQ,GAAG,SAAS,EAAE,OAAO,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"human-readable-output.d.ts","sourceRoot":"","sources":["../../../src/visualization/human-readable-output.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAkBrD,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,IAAI,EAAE,QAAQ,GAAG,SAAS,CAAA;IAC1B,IAAI,EAAE,QAAQ,GAAG,SAAS,CAAA;IAC1B,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;IACf,UAAU,EAAE,OAAO,CAAA;IACnB,IAAI,EAAE,OAAO,CAAA;IACb,OAAO,EAAE,OAAO,CAAA;IAChB,MAAM,EAAE,QAAQ,GAAG,SAAS,CAAA;CAC7B,CAAA;AAED,MAAM,MAAM,wBAAwB,GAAG;IACrC,KAAK,EAAE,QAAQ,EAAE,CAAA;IACjB,SAAS,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAA;IACxB,KAAK,EAAE,QAAQ,EAAE,CAAA;IACjB,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAC7B,CAAA;AAED,MAAM,MAAM,OAAO,GAAG,GAAG,CAAC,QAAQ,GAAG,SAAS,EAAE,QAAQ,CAAC,CAAA;AAEzD,MAAM,MAAM,OAAO,GAAG,GAAG,CAAC,QAAQ,GAAG,SAAS,EAAE,OAAO,CAAC,CAAA;AAyDxD;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,wBAAwB,EACjC,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,UAiHjC"}
|
|
@@ -8,8 +8,8 @@ const chars = new Map(Object.entries({
|
|
|
8
8
|
'middle-child': '├',
|
|
9
9
|
t: '┬',
|
|
10
10
|
}));
|
|
11
|
-
const isSelected = (options, edge, node) =>
|
|
12
|
-
(!edge || options.edges.includes(edge))
|
|
11
|
+
const isSelected = (options, edge, node) => (!node || options.nodes.includes(node)) &&
|
|
12
|
+
(!edge || options.edges.includes(edge));
|
|
13
13
|
/**
|
|
14
14
|
* Returns a map of tree items to be printed.
|
|
15
15
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"human-readable-output.js","sourceRoot":"","sources":["../../../src/visualization/human-readable-output.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAE3C,OAAO,EAAE,SAAS,IAAI,aAAa,EAAE,MAAM,WAAW,CAAA;AAEtD,MAAM,SAAS,GAAG,CAChB,MAA2C,EAC3C,CAAS,EACT,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,cAAc,EAAE,KAAK,EAAE,CAAC,CAAA;AAExD,MAAM,KAAK,GAAG,IAAI,GAAG,CACnB,MAAM,CAAC,OAAO,CAAC;IACb,UAAU,EAAE,GAAG;IACf,IAAI,EAAE,GAAG;IACT,YAAY,EAAE,GAAG;IACjB,cAAc,EAAE,GAAG;IACnB,CAAC,EAAE,GAAG;CACP,CAAC,CACH,CAAA;AAyBD,MAAM,UAAU,GAAG,CACjB,OAAiC,EACjC,IAAe,EACf,IAAe,EACf,EAAE,CACF,CAAC,CAAC,CACA,CAAC,CAAC,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC,CAAC,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CACxC,CAAA;AAEH;;GAEG;AACH,MAAM,YAAY,GAAG,CACnB,YAA2B,EAC3B,OAAiC,EACjC,EAAE;IACF,MAAM,SAAS,GAAG,IAAI,GAAG,EAAY,CAAA;IACrC,MAAM,SAAS,GAAY,IAAI,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Q,CAAC,CAAA;YAC/B,CAAC;QACH,CAAC;QAED,MAAM,iBAAiB,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAA;QACvD,MAAM,gBAAgB,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAA;QAC7C,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;YACjB,GAAG,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,iBAAiB,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,OAAO,EAAE;YACvF,CAAC,CAAC,EAAE,CAAA;IACR,CAAC,CAAA;IAED,KAAK,MAAM,IAAI,IAAI,YAAY,EAAE,CAAC;QAChC,GAAG,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAA;IACvB,CAAC;IACD,OAAO,KAAK,CAAC,GAAG,CAAC,CAAA;AACnB,CAAC","sourcesContent":["import { splitDepID } from '@vltpkg/dep-id'\nimport type { EdgeLike, NodeLike } from '../types.ts'\nimport { styleText as utilStyleText } from 'node:util'\n\nconst styleText = (\n format: Parameters<typeof utilStyleText>[0],\n s: string,\n) => utilStyleText(format, s, { validateStream: false })\n\nconst chars = new Map(\n Object.entries({\n connection: '─',\n down: '│',\n 'last-child': '└',\n 'middle-child': '├',\n t: '┬',\n }),\n)\n\nexport type TreeItem = {\n name?: string | null\n edge: EdgeLike | undefined\n node: NodeLike | undefined\n prefix: string\n padding: string\n hasSibling: boolean\n seen: boolean\n include: boolean\n parent: TreeItem | undefined\n}\n\nexport type HumanReadableOutputGraph = {\n edges: EdgeLike[]\n importers: Set<NodeLike>\n nodes: NodeLike[]\n highlightSelection?: boolean\n}\n\nexport type EdgeMap = Map<NodeLike | undefined, TreeItem>\n\nexport type TreeMap = Map<EdgeLike | undefined, EdgeMap>\n\nconst isSelected = (\n options: HumanReadableOutputGraph,\n edge?: EdgeLike,\n node?: NodeLike,\n) =>\n !!(\n (!node || options.nodes.includes(node)) &&\n (!edge || options.edges.includes(edge))\n )\n\n/**\n * Returns a map of tree items to be printed.\n */\nconst getTreeItems = (\n initialItems: Set<TreeItem>,\n options: HumanReadableOutputGraph,\n) => {\n const seenNodes = new Set<NodeLike>()\n const treeItems: TreeMap = new Map()\n const traverse = new Set<TreeItem>(initialItems)\n for (const item of traverse) {\n if (item.node) {\n if (seenNodes.has(item.node)) {\n item.seen = true\n continue\n }\n seenNodes.add(item.node)\n const edges = [...item.node.edgesOut.values()].sort(i =>\n Number(i.to?.importer),\n )\n for (const edge of edges) {\n const toItems: EdgeMap =\n treeItems.get(edge) ?? (new Map() as EdgeMap)\n const nextItem: TreeItem = {\n edge,\n node: edge.to,\n hasSibling: false,\n padding: '',\n prefix: '',\n seen: false,\n include: isSelected(options, edge, edge.to),\n parent: item,\n }\n toItems.set(edge.to, nextItem)\n treeItems.set(edge, toItems)\n traverse.add(nextItem)\n }\n }\n }\n for (const item of [...traverse].reverse()) {\n if (item.include && item.parent) {\n item.parent.include = true\n }\n }\n return treeItems\n}\n\n/**\n * Returns a human-readable output of the graph.\n */\nexport function humanReadableOutput(\n options: HumanReadableOutputGraph,\n { colors }: { colors?: boolean },\n) {\n const { importers } = options\n const createStyleText =\n (style: Parameters<typeof styleText>[0]) => (s: string) =>\n colors ? styleText(style, s) : s\n const dim = createStyleText('dim')\n const red = createStyleText('red')\n const reset = createStyleText('reset')\n const yellow = createStyleText('yellow')\n const initialItems = new Set<TreeItem>()\n for (const importer of importers) {\n initialItems.add({\n name: importer.name,\n edge: undefined,\n node: importer,\n prefix: '',\n padding: '',\n hasSibling: false,\n seen: false,\n include: isSelected(options, undefined, importer),\n parent: undefined,\n })\n }\n const treeItems = getTreeItems(initialItems, options)\n\n let res = ''\n const traverse = (item: TreeItem) => {\n let header = ''\n let content = ''\n\n const name = item.name\n const decoratedName =\n (\n options.highlightSelection &&\n isSelected(options, item.edge, item.node) &&\n name\n ) ?\n yellow(name)\n : name\n if (!item.node && item.include) {\n const missing =\n item.edge?.type.endsWith('ptional') ?\n dim('(missing optional)')\n : red('(missing)')\n return `${item.padding}${item.prefix}${decoratedName} ${missing}\\n`\n }\n\n header += `${item.padding}${item.prefix}${decoratedName}\\n`\n\n // seen items need not to be printed or traversed\n if (!item.seen) {\n const edges = item.node ? [...item.node.edgesOut.values()] : []\n const nextItems = edges.map(i => treeItems.get(i)?.get(i.to))\n const includedItems = nextItems.filter(i => i?.include)\n\n for (const nextItem of nextItems) {\n /* c8 ignore next -- impossible but TS doesn't know that */\n if (!nextItem) continue\n\n const parent = item\n const isLast =\n includedItems.indexOf(nextItem) === includedItems.length - 1\n\n // prefixes the node name with the registry name\n // if a custom registry name is found\n const depIdTuple =\n nextItem.node?.id && splitDepID(nextItem.node.id)\n const hasCustomReg =\n depIdTuple?.[0] === 'registry' && depIdTuple[1]\n const nodeName =\n hasCustomReg ?\n `${depIdTuple[1]}:${nextItem.node?.name}`\n : nextItem.node?.name\n\n const toName =\n nextItem.node?.version ?\n `${nodeName}@${nextItem.node.version}`\n : nodeName\n const nextChar = isLast ? 'last-child' : 'middle-child'\n\n const aliasedPackage =\n nextItem.node?.name && nextItem.edge?.name !== nodeName\n nextItem.name =\n nextItem.node?.confused ?\n `${nextItem.edge?.name} ${red('(confused)')}`\n : nextItem.edge?.spec.overridden ?\n /* c8 ignore next */\n `${nextItem.edge.name}@${nextItem.node?.version || nextItem.edge.spec.bareSpec}${aliasedPackage ? ` (${toName})` : ''} ${yellow('(overridden)')}`\n : aliasedPackage ? `${nextItem.edge?.name} (${toName})`\n : `${nextItem.edge?.name}@${nextItem.node?.version || nextItem.edge?.spec.bareSpec}`\n nextItem.padding =\n parent.prefix.length ?\n `${parent.padding}${parent.hasSibling ? chars.get('down') : ' '} `\n : ''\n nextItem.prefix = `${chars.get(nextChar)}${chars.get('connection')}${chars.get('connection')} `\n nextItem.hasSibling = !isLast\n\n content += traverse(nextItem)\n }\n }\n\n const regularConnection = `${chars.get('connection')} `\n const parentConnection = `${chars.get('t')} `\n return item.include ?\n `${content ? header.replace(regularConnection, parentConnection) : header}${content}`\n : ''\n }\n\n for (const item of initialItems) {\n res += traverse(item)\n }\n return reset(res)\n}\n"]}
|
|
1
|
+
{"version":3,"file":"human-readable-output.js","sourceRoot":"","sources":["../../../src/visualization/human-readable-output.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAE3C,OAAO,EAAE,SAAS,IAAI,aAAa,EAAE,MAAM,WAAW,CAAA;AAEtD,MAAM,SAAS,GAAG,CAChB,MAA2C,EAC3C,CAAS,EACT,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,cAAc,EAAE,KAAK,EAAE,CAAC,CAAA;AAExD,MAAM,KAAK,GAAG,IAAI,GAAG,CACnB,MAAM,CAAC,OAAO,CAAC;IACb,UAAU,EAAE,GAAG;IACf,IAAI,EAAE,GAAG;IACT,YAAY,EAAE,GAAG;IACjB,cAAc,EAAE,GAAG;IACnB,CAAC,EAAE,GAAG;CACP,CAAC,CACH,CAAA;AAyBD,MAAM,UAAU,GAAG,CACjB,OAAiC,EACjC,IAAe,EACf,IAAe,EACf,EAAE,CACF,CAAC,CAAC,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC,CAAC,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAA;AAEzC;;GAEG;AACH,MAAM,YAAY,GAAG,CACnB,YAA2B,EAC3B,OAAiC,EACjC,EAAE;IACF,MAAM,SAAS,GAAG,IAAI,GAAG,EAAY,CAAA;IACrC,MAAM,SAAS,GAAY,IAAI,GAAG,EAAE,CAAA;IACpC,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAW,YAAY,CAAC,CAAA;IAChD,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE,CAAC;QAC5B,IAAI,IAAI,CAAC,IAAI,EA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,GAAG,CAAC,GAAG,CAAC,GAAG,CAAA;QAC7C,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;YACjB,GAAG,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,iBAAiB,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,OAAO,EAAE;YACvF,CAAC,CAAC,EAAE,CAAA;IACR,CAAC,CAAA;IAED,KAAK,MAAM,IAAI,IAAI,YAAY,EAAE,CAAC;QAChC,GAAG,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAA;IACvB,CAAC;IACD,OAAO,KAAK,CAAC,GAAG,CAAC,CAAA;AACnB,CAAC","sourcesContent":["import { splitDepID } from '@vltpkg/dep-id'\nimport type { EdgeLike, NodeLike } from '../types.ts'\nimport { styleText as utilStyleText } from 'node:util'\n\nconst styleText = (\n format: Parameters<typeof utilStyleText>[0],\n s: string,\n) => utilStyleText(format, s, { validateStream: false })\n\nconst chars = new Map(\n Object.entries({\n connection: '─',\n down: '│',\n 'last-child': '└',\n 'middle-child': '├',\n t: '┬',\n }),\n)\n\nexport type TreeItem = {\n name?: string | null\n edge: EdgeLike | undefined\n node: NodeLike | undefined\n prefix: string\n padding: string\n hasSibling: boolean\n seen: boolean\n include: boolean\n parent: TreeItem | undefined\n}\n\nexport type HumanReadableOutputGraph = {\n edges: EdgeLike[]\n importers: Set<NodeLike>\n nodes: NodeLike[]\n highlightSelection?: boolean\n}\n\nexport type EdgeMap = Map<NodeLike | undefined, TreeItem>\n\nexport type TreeMap = Map<EdgeLike | undefined, EdgeMap>\n\nconst isSelected = (\n options: HumanReadableOutputGraph,\n edge?: EdgeLike,\n node?: NodeLike,\n) =>\n (!node || options.nodes.includes(node)) &&\n (!edge || options.edges.includes(edge))\n\n/**\n * Returns a map of tree items to be printed.\n */\nconst getTreeItems = (\n initialItems: Set<TreeItem>,\n options: HumanReadableOutputGraph,\n) => {\n const seenNodes = new Set<NodeLike>()\n const treeItems: TreeMap = new Map()\n const traverse = new Set<TreeItem>(initialItems)\n for (const item of traverse) {\n if (item.node) {\n if (seenNodes.has(item.node)) {\n item.seen = true\n continue\n }\n seenNodes.add(item.node)\n const edges = [...item.node.edgesOut.values()].sort(i =>\n Number(i.to?.importer),\n )\n for (const edge of edges) {\n const toItems: EdgeMap =\n treeItems.get(edge) ?? (new Map() as EdgeMap)\n const nextItem: TreeItem = {\n edge,\n node: edge.to,\n hasSibling: false,\n padding: '',\n prefix: '',\n seen: false,\n include: isSelected(options, edge, edge.to),\n parent: item,\n }\n toItems.set(edge.to, nextItem)\n treeItems.set(edge, toItems)\n traverse.add(nextItem)\n }\n }\n }\n for (const item of [...traverse].reverse()) {\n if (item.include && item.parent) {\n item.parent.include = true\n }\n }\n return treeItems\n}\n\n/**\n * Returns a human-readable output of the graph.\n */\nexport function humanReadableOutput(\n options: HumanReadableOutputGraph,\n { colors }: { colors?: boolean },\n) {\n const { importers } = options\n const createStyleText =\n (style: Parameters<typeof styleText>[0]) => (s: string) =>\n colors ? styleText(style, s) : s\n const dim = createStyleText('dim')\n const red = createStyleText('red')\n const reset = createStyleText('reset')\n const yellow = createStyleText('yellow')\n const initialItems = new Set<TreeItem>()\n for (const importer of importers) {\n initialItems.add({\n name: importer.name,\n edge: undefined,\n node: importer,\n prefix: '',\n padding: '',\n hasSibling: false,\n seen: false,\n include: isSelected(options, undefined, importer),\n parent: undefined,\n })\n }\n const treeItems = getTreeItems(initialItems, options)\n\n let res = ''\n const traverse = (item: TreeItem) => {\n let header = ''\n let content = ''\n\n const name = item.name\n const decoratedName =\n (\n options.highlightSelection &&\n isSelected(options, item.edge, item.node) &&\n name\n ) ?\n yellow(name)\n : name\n if (!item.node && item.include) {\n const missing =\n item.edge?.type.endsWith('ptional') ?\n dim('(missing optional)')\n : red('(missing)')\n return `${item.padding}${item.prefix}${decoratedName} ${missing}\\n`\n }\n\n header += `${item.padding}${item.prefix}${decoratedName}\\n`\n\n // seen items need not to be printed or traversed\n if (!item.seen) {\n const edges = item.node ? [...item.node.edgesOut.values()] : []\n const nextItems = edges.map(i => treeItems.get(i)?.get(i.to))\n const includedItems = nextItems.filter(i => i?.include)\n\n for (const nextItem of nextItems) {\n /* c8 ignore next -- impossible but TS doesn't know that */\n if (!nextItem) continue\n\n const parent = item\n const isLast =\n includedItems.indexOf(nextItem) === includedItems.length - 1\n\n // prefixes the node name with the registry name\n // if a custom registry name is found\n const depIdTuple =\n nextItem.node?.id && splitDepID(nextItem.node.id)\n const hasCustomReg =\n depIdTuple?.[0] === 'registry' && depIdTuple[1]\n const nodeName =\n hasCustomReg ?\n `${depIdTuple[1]}:${nextItem.node?.name}`\n : nextItem.node?.name\n\n const toName =\n nextItem.node?.version ?\n `${nodeName}@${nextItem.node.version}`\n : nodeName\n const nextChar = isLast ? 'last-child' : 'middle-child'\n\n const aliasedPackage =\n nextItem.node?.name && nextItem.edge?.name !== nodeName\n nextItem.name =\n nextItem.node?.confused ?\n `${nextItem.edge?.name} ${red('(confused)')}`\n : nextItem.edge?.spec.overridden ?\n /* c8 ignore next */\n `${nextItem.edge.name}@${nextItem.node?.version || nextItem.edge.spec.bareSpec}${aliasedPackage ? ` (${toName})` : ''} ${yellow('(overridden)')}`\n : aliasedPackage ? `${nextItem.edge?.name} (${toName})`\n : `${nextItem.edge?.name}@${nextItem.node?.version || nextItem.edge?.spec.bareSpec}`\n nextItem.padding =\n parent.prefix.length ?\n `${parent.padding}${parent.hasSibling ? chars.get('down') : ' '} `\n : ''\n nextItem.prefix = `${chars.get(nextChar)}${chars.get('connection')}${chars.get('connection')} `\n nextItem.hasSibling = !isLast\n\n content += traverse(nextItem)\n }\n }\n\n const regularConnection = `${chars.get('connection')} `\n const parentConnection = `${chars.get('t')} `\n return item.include ?\n `${content ? header.replace(regularConnection, parentConnection) : header}${content}`\n : ''\n }\n\n for (const item of initialItems) {\n res += traverse(item)\n }\n return reset(res)\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vltpkg/graph",
|
|
3
3
|
"description": "A library that helps understanding & expressing what happens on an install",
|
|
4
|
-
"version": "0.0.0-
|
|
4
|
+
"version": "0.0.0-23",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/vltpkg/vltpkg.git",
|
|
@@ -23,36 +23,36 @@
|
|
|
23
23
|
"graph-run": "^1.1.0",
|
|
24
24
|
"path-scurry": "^2.0.0",
|
|
25
25
|
"promise-call-limit": "^3.0.2",
|
|
26
|
-
"@vltpkg/
|
|
27
|
-
"@vltpkg/dss-breadcrumb": "0.0.0-
|
|
28
|
-
"@vltpkg/
|
|
29
|
-
"@vltpkg/
|
|
30
|
-
"@vltpkg/
|
|
31
|
-
"@vltpkg/fast-split": "0.0.0-
|
|
32
|
-
"@vltpkg/
|
|
33
|
-
"@vltpkg/package-
|
|
34
|
-
"@vltpkg/package-
|
|
35
|
-
"@vltpkg/
|
|
36
|
-
"@vltpkg/
|
|
37
|
-
"@vltpkg/
|
|
38
|
-
"@vltpkg/
|
|
39
|
-
"@vltpkg/
|
|
40
|
-
"@vltpkg/
|
|
41
|
-
"@vltpkg/
|
|
42
|
-
"@vltpkg/
|
|
26
|
+
"@vltpkg/dep-id": "0.0.0-23",
|
|
27
|
+
"@vltpkg/dss-breadcrumb": "0.0.0-23",
|
|
28
|
+
"@vltpkg/cmd-shim": "0.0.0-23",
|
|
29
|
+
"@vltpkg/error-cause": "0.0.0-23",
|
|
30
|
+
"@vltpkg/output": "0.0.0-23",
|
|
31
|
+
"@vltpkg/fast-split": "0.0.0-23",
|
|
32
|
+
"@vltpkg/init": "0.0.0-23",
|
|
33
|
+
"@vltpkg/package-info": "0.0.0-23",
|
|
34
|
+
"@vltpkg/package-json": "0.0.0-23",
|
|
35
|
+
"@vltpkg/pick-manifest": "0.0.0-23",
|
|
36
|
+
"@vltpkg/run": "0.0.0-23",
|
|
37
|
+
"@vltpkg/satisfies": "0.0.0-23",
|
|
38
|
+
"@vltpkg/spec": "0.0.0-23",
|
|
39
|
+
"@vltpkg/types": "0.0.0-23",
|
|
40
|
+
"@vltpkg/rollback-remove": "0.0.0-23",
|
|
41
|
+
"@vltpkg/workspaces": "0.0.0-23",
|
|
42
|
+
"@vltpkg/vlt-json": "0.0.0-23"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@eslint/js": "^9.
|
|
46
|
-
"@types/node": "^22.
|
|
47
|
-
"eslint": "^9.
|
|
48
|
-
"prettier": "^3.6.
|
|
45
|
+
"@eslint/js": "^9.34.0",
|
|
46
|
+
"@types/node": "^22.17.2",
|
|
47
|
+
"eslint": "^9.34.0",
|
|
48
|
+
"prettier": "^3.6.2",
|
|
49
49
|
"tap": "^21.1.0",
|
|
50
50
|
"tar": "^7.4.3",
|
|
51
51
|
"tshy": "^3.0.2",
|
|
52
52
|
"typedoc": "~0.27.9",
|
|
53
53
|
"typescript": "5.7.3",
|
|
54
|
-
"typescript-eslint": "^8.
|
|
55
|
-
"@vltpkg/vlt-json": "0.0.0-
|
|
54
|
+
"typescript-eslint": "^8.40.0",
|
|
55
|
+
"@vltpkg/vlt-json": "0.0.0-23"
|
|
56
56
|
},
|
|
57
57
|
"license": "BSD-2-Clause-Patent",
|
|
58
58
|
"engines": {
|