@vltpkg/graph 1.0.0-rc.4 → 1.0.0-rc.6
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/actual/load.d.ts.map +1 -1
- package/dist/esm/actual/load.js +25 -8
- package/dist/esm/actual/load.js.map +1 -1
- package/dist/esm/diff.d.ts +2 -0
- package/dist/esm/diff.d.ts.map +1 -1
- package/dist/esm/edge.d.ts +1 -0
- package/dist/esm/edge.d.ts.map +1 -1
- package/dist/esm/edge.js +4 -0
- package/dist/esm/edge.js.map +1 -1
- package/dist/esm/graph.d.ts +18 -4
- package/dist/esm/graph.d.ts.map +1 -1
- package/dist/esm/graph.js +50 -39
- package/dist/esm/graph.js.map +1 -1
- package/dist/esm/ideal/append-nodes.d.ts +1 -1
- package/dist/esm/ideal/append-nodes.d.ts.map +1 -1
- package/dist/esm/ideal/append-nodes.js +146 -64
- package/dist/esm/ideal/append-nodes.js.map +1 -1
- package/dist/esm/ideal/build-ideal-from-starting-graph.d.ts +2 -5
- package/dist/esm/ideal/build-ideal-from-starting-graph.d.ts.map +1 -1
- package/dist/esm/ideal/build-ideal-from-starting-graph.js +23 -12
- package/dist/esm/ideal/build-ideal-from-starting-graph.js.map +1 -1
- package/dist/esm/ideal/build.d.ts.map +1 -1
- package/dist/esm/ideal/build.js +0 -2
- package/dist/esm/ideal/build.js.map +1 -1
- package/dist/esm/ideal/get-ordered-dependencies.d.ts +10 -0
- package/dist/esm/ideal/get-ordered-dependencies.d.ts.map +1 -0
- package/dist/esm/ideal/get-ordered-dependencies.js +42 -0
- package/dist/esm/ideal/get-ordered-dependencies.js.map +1 -0
- package/dist/esm/ideal/peers.d.ts +71 -0
- package/dist/esm/ideal/peers.d.ts.map +1 -0
- package/dist/esm/ideal/peers.js +318 -0
- package/dist/esm/ideal/peers.js.map +1 -0
- package/dist/esm/ideal/{add-nodes.d.ts → refresh-ideal-graph.d.ts} +9 -5
- package/dist/esm/ideal/refresh-ideal-graph.d.ts.map +1 -0
- package/dist/esm/ideal/refresh-ideal-graph.js +79 -0
- package/dist/esm/ideal/refresh-ideal-graph.js.map +1 -0
- package/dist/esm/ideal/types.d.ts +65 -1
- package/dist/esm/ideal/types.d.ts.map +1 -1
- package/dist/esm/ideal/types.js.map +1 -1
- package/dist/esm/install.d.ts +3 -2
- package/dist/esm/install.d.ts.map +1 -1
- package/dist/esm/install.js +21 -5
- package/dist/esm/install.js.map +1 -1
- package/dist/esm/lockfile/load-nodes.d.ts.map +1 -1
- package/dist/esm/lockfile/load-nodes.js +8 -2
- package/dist/esm/lockfile/load-nodes.js.map +1 -1
- package/dist/esm/lockfile/load.d.ts +0 -4
- package/dist/esm/lockfile/load.d.ts.map +1 -1
- package/dist/esm/lockfile/load.js +4 -29
- package/dist/esm/lockfile/load.js.map +1 -1
- package/dist/esm/node.d.ts +14 -0
- package/dist/esm/node.d.ts.map +1 -1
- package/dist/esm/node.js +16 -0
- package/dist/esm/node.js.map +1 -1
- package/dist/esm/visualization/json-output.d.ts +2 -1
- package/dist/esm/visualization/json-output.d.ts.map +1 -1
- package/dist/esm/visualization/json-output.js +2 -2
- package/dist/esm/visualization/json-output.js.map +1 -1
- package/package.json +21 -21
- package/dist/esm/ideal/add-nodes.d.ts.map +0 -1
- package/dist/esm/ideal/add-nodes.js +0 -39
- package/dist/esm/ideal/add-nodes.js.map +0 -1
- package/dist/esm/ideal/remove-nodes.d.ts +0 -7
- package/dist/esm/ideal/remove-nodes.d.ts.map +0 -1
- package/dist/esm/ideal/remove-nodes.js +0 -19
- package/dist/esm/ideal/remove-nodes.js.map +0 -1
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
// helpers for managing peer dependency resolution
|
|
2
|
+
// during the ideal graph building process.
|
|
3
|
+
import { intersects } from '@vltpkg/semver';
|
|
4
|
+
import { satisfies } from '@vltpkg/satisfies';
|
|
5
|
+
import { getDependencies } from "../dependencies.js";
|
|
6
|
+
import { getOrderedDependencies } from "./get-ordered-dependencies.js";
|
|
7
|
+
/**
|
|
8
|
+
* Retrieve a unique hash value for a given peer context set.
|
|
9
|
+
*/
|
|
10
|
+
export const retrievePeerContextHash = (peerContext) => {
|
|
11
|
+
// skips creating the initial peer context ref
|
|
12
|
+
if (!peerContext?.index)
|
|
13
|
+
return undefined;
|
|
14
|
+
return `ṗ:${peerContext.index}`;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Checks if a given spec is compatible with the specs already
|
|
18
|
+
* assigned to a peer context entry.
|
|
19
|
+
*
|
|
20
|
+
* Returns true if compatible, false otherwise.
|
|
21
|
+
*/
|
|
22
|
+
export const incompatibleSpecs = (spec, entry) => {
|
|
23
|
+
if (entry.specs.size > 0) {
|
|
24
|
+
for (const s of entry.specs) {
|
|
25
|
+
if (
|
|
26
|
+
// only able to check range intersections for registry types
|
|
27
|
+
(spec.type === 'registry' &&
|
|
28
|
+
(!spec.range ||
|
|
29
|
+
!s.range ||
|
|
30
|
+
!intersects(spec.range, s.range))) ||
|
|
31
|
+
// also support types other than registry in case
|
|
32
|
+
// they use the very same bareSpec value
|
|
33
|
+
(spec.type !== 'registry' && spec.bareSpec !== s.bareSpec)) {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
};
|
|
40
|
+
/*
|
|
41
|
+
* Checks if there are any conflicting versions for a given dependency
|
|
42
|
+
* to be added to a peer context set which will require forking.
|
|
43
|
+
*
|
|
44
|
+
* Returns true if forking is needed, false otherwise.
|
|
45
|
+
*/
|
|
46
|
+
export const checkEntriesToPeerContext = (peerContext, entries) => {
|
|
47
|
+
// check on compatibility of new entries
|
|
48
|
+
for (const { spec, target } of entries) {
|
|
49
|
+
const name = target?.name ?? spec.final.name;
|
|
50
|
+
// skip any inactive entry
|
|
51
|
+
const entry = peerContext.get(name);
|
|
52
|
+
if (!entry?.active)
|
|
53
|
+
continue;
|
|
54
|
+
// validate if the provided spec is compatible with existing specs
|
|
55
|
+
if (incompatibleSpecs(spec, entry)) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return false;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Add or update dependencies in a given peer context making sure to check
|
|
63
|
+
* for compatibility with existing dependencies already resolved by a given
|
|
64
|
+
* peer context set. Extra info such as a target or dependent nodes is
|
|
65
|
+
* optional.
|
|
66
|
+
*
|
|
67
|
+
* Returns true if forking is needed, false otherwise.
|
|
68
|
+
*/
|
|
69
|
+
export const addEntriesToPeerContext = (peerContext, entries, fromNode, monorepo) => {
|
|
70
|
+
// pre check to see if any of the new entries to be added to the
|
|
71
|
+
// provided peer context set conflicts with existing ones
|
|
72
|
+
// if that's already the case we can skip processing them and
|
|
73
|
+
// will return that a fork is needed right away
|
|
74
|
+
if (checkEntriesToPeerContext(peerContext, entries))
|
|
75
|
+
return true;
|
|
76
|
+
// iterate on every entry to be added to the peer context set
|
|
77
|
+
for (const { dependent, spec, target, type } of entries) {
|
|
78
|
+
const name = target?.name ?? spec.final.name;
|
|
79
|
+
// if there's no existing entry, create one
|
|
80
|
+
let entry = peerContext.get(name);
|
|
81
|
+
if (!entry) {
|
|
82
|
+
entry = {
|
|
83
|
+
active: true,
|
|
84
|
+
specs: new Set([spec]),
|
|
85
|
+
target,
|
|
86
|
+
type,
|
|
87
|
+
contextDependents: new Set(),
|
|
88
|
+
};
|
|
89
|
+
peerContext.set(name, entry);
|
|
90
|
+
if (dependent)
|
|
91
|
+
entry.contextDependents.add(dependent);
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
// perform an extra check that confirms the new spec does not
|
|
95
|
+
// conflicts with existing specs in this entry, this handles the
|
|
96
|
+
// case of adding sibling deps that conflicts with one another
|
|
97
|
+
if (incompatibleSpecs(spec, entry))
|
|
98
|
+
return true;
|
|
99
|
+
if (target &&
|
|
100
|
+
[...entry.specs].every(s => satisfies(target.id, s, fromNode.location, fromNode.projectRoot, monorepo))) {
|
|
101
|
+
if (target.id !== entry.target?.id &&
|
|
102
|
+
target.version !== entry.target?.version) {
|
|
103
|
+
// we have a compatible entry that has a new, compatible target
|
|
104
|
+
// so we need to update all dependents to point to the new target
|
|
105
|
+
for (const dependents of entry.contextDependents) {
|
|
106
|
+
const edge = dependents.edgesOut.get(name);
|
|
107
|
+
if (edge?.to && edge.to !== target) {
|
|
108
|
+
edge.to.edgesIn.delete(edge);
|
|
109
|
+
edge.to = target;
|
|
110
|
+
target.edgesIn.add(edge);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
entry.target = target;
|
|
114
|
+
}
|
|
115
|
+
// otherwise sets the value in case it was nullish
|
|
116
|
+
entry.target ??= target;
|
|
117
|
+
}
|
|
118
|
+
// update specs and dependents values
|
|
119
|
+
entry.specs.add(spec);
|
|
120
|
+
if (dependent)
|
|
121
|
+
entry.contextDependents.add(dependent);
|
|
122
|
+
}
|
|
123
|
+
return false;
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* Create and returns a forked copy of a given peer context set.
|
|
127
|
+
*/
|
|
128
|
+
export const forkPeerContext = (graph, peerContext, entries) => {
|
|
129
|
+
// create a new peer context set
|
|
130
|
+
const nextPeerContext = new Map();
|
|
131
|
+
nextPeerContext.index = graph.nextPeerContextIndex();
|
|
132
|
+
// register it in the graph
|
|
133
|
+
graph.peerContexts[nextPeerContext.index] = nextPeerContext;
|
|
134
|
+
// copy existing entries marking them as inactive, it's also important
|
|
135
|
+
// to note that specs and contextDependents are new objects so that changes
|
|
136
|
+
// to those in the new context do not affect the previous one
|
|
137
|
+
for (const [name, entry] of peerContext.entries()) {
|
|
138
|
+
nextPeerContext.set(name, {
|
|
139
|
+
active: false,
|
|
140
|
+
specs: new Set(entry.specs),
|
|
141
|
+
target: undefined,
|
|
142
|
+
type: entry.type,
|
|
143
|
+
contextDependents: new Set(entry.contextDependents),
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
// add the new entries to this peer context set, marking them as active
|
|
147
|
+
// these are the entries that were incompatible with the previous context set
|
|
148
|
+
for (const entry of entries) {
|
|
149
|
+
const { dependent, spec, target, type } = entry;
|
|
150
|
+
const name = target?.name /* c8 ignore next */ ?? spec.final.name;
|
|
151
|
+
const newEntry = {
|
|
152
|
+
active: true,
|
|
153
|
+
specs: new Set([spec]),
|
|
154
|
+
target,
|
|
155
|
+
type,
|
|
156
|
+
contextDependents: dependent ? new Set([dependent]) : new Set(),
|
|
157
|
+
};
|
|
158
|
+
nextPeerContext.set(name, newEntry);
|
|
159
|
+
}
|
|
160
|
+
return nextPeerContext;
|
|
161
|
+
};
|
|
162
|
+
/**
|
|
163
|
+
* Starts the peer dependency placement process
|
|
164
|
+
* for a given node being processed and placed.
|
|
165
|
+
*/
|
|
166
|
+
export const startPeerPlacement = (peerContext, manifest, fromNode, options) => {
|
|
167
|
+
// queue entries so that they can be added at the end of the placement
|
|
168
|
+
// process, use a map to ensure deduplication between read json dep
|
|
169
|
+
// values and the resolved edges in the graph
|
|
170
|
+
const queueMap = new Map();
|
|
171
|
+
let peerSetHash;
|
|
172
|
+
if (manifest.peerDependencies &&
|
|
173
|
+
Object.keys(manifest.peerDependencies).length > 0) {
|
|
174
|
+
// generates a peer context set hash for nodes that
|
|
175
|
+
// have peer dependencies to be resolved
|
|
176
|
+
peerSetHash = retrievePeerContextHash(peerContext);
|
|
177
|
+
// get any potential sibling dependency from the
|
|
178
|
+
// parent node that might have not been parsed yet
|
|
179
|
+
const siblingDeps = getDependencies(fromNode, {
|
|
180
|
+
...options,
|
|
181
|
+
registry: fromNode.registry,
|
|
182
|
+
});
|
|
183
|
+
for (const [depName, dep] of siblingDeps) {
|
|
184
|
+
queueMap.set(depName, dep);
|
|
185
|
+
}
|
|
186
|
+
// collect the already parsed nodes and add those to the
|
|
187
|
+
// list of entries to be added to the peer context set
|
|
188
|
+
for (const edge of fromNode.edgesOut.values()) {
|
|
189
|
+
queueMap.set(edge.name, {
|
|
190
|
+
spec: edge.spec,
|
|
191
|
+
target: edge.to,
|
|
192
|
+
type: edge.type,
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return {
|
|
197
|
+
peerSetHash,
|
|
198
|
+
queuedEntries: [...queueMap.values()],
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
/**
|
|
202
|
+
* Ends the peer dependency placement process, returning the functions that
|
|
203
|
+
* are going to be used to update the peer context set, forking when needed
|
|
204
|
+
* and resolving peer dependencies if possible.
|
|
205
|
+
*/
|
|
206
|
+
export const endPeerPlacement = (peerContext, nextDeps, nextPeerDeps, graph, spec, fromNode, node, type, queuedEntries) => ({
|
|
207
|
+
/**
|
|
208
|
+
* Add the new entries to the current peer context set.
|
|
209
|
+
*/
|
|
210
|
+
putEntries: () => {
|
|
211
|
+
// keep track of whether we need to fork the current peer context set
|
|
212
|
+
let needsToForkPeerContext = false;
|
|
213
|
+
// add queued entries from this node parents along
|
|
214
|
+
// with a self-ref to the current peer context set
|
|
215
|
+
const prevEntries = [
|
|
216
|
+
...queuedEntries,
|
|
217
|
+
/* ref itself */ {
|
|
218
|
+
spec,
|
|
219
|
+
target: node,
|
|
220
|
+
type,
|
|
221
|
+
},
|
|
222
|
+
];
|
|
223
|
+
addEntriesToPeerContext(peerContext, prevEntries, fromNode, graph.monorepo);
|
|
224
|
+
// add this node's direct dependencies next
|
|
225
|
+
const nextEntries = [
|
|
226
|
+
...nextDeps.map(dep => ({ ...dep, dependent: node })),
|
|
227
|
+
...[...nextPeerDeps.values()].map(dep => ({
|
|
228
|
+
...dep,
|
|
229
|
+
dependent: node,
|
|
230
|
+
})),
|
|
231
|
+
];
|
|
232
|
+
if (nextEntries.length > 0) {
|
|
233
|
+
needsToForkPeerContext = addEntriesToPeerContext(peerContext, nextEntries, node, graph.monorepo);
|
|
234
|
+
}
|
|
235
|
+
// returns all entries that need to be added to a forked
|
|
236
|
+
// context or undefined if the current context was updated directly
|
|
237
|
+
return needsToForkPeerContext ? nextEntries : undefined;
|
|
238
|
+
},
|
|
239
|
+
/**
|
|
240
|
+
* Try to resolve peer dependencies using already seen target
|
|
241
|
+
* values from the current peer context set.
|
|
242
|
+
*/
|
|
243
|
+
resolvePeerDeps: () => {
|
|
244
|
+
// iterate on the set of peer dependencies of the current node
|
|
245
|
+
// and try to resolve them from the existing peer context set,
|
|
246
|
+
// when possible, add them as edges in the graph right away, if not,
|
|
247
|
+
// then we move them back to the `nextDeps` list for processing
|
|
248
|
+
// along with the rest of the regular dependencies
|
|
249
|
+
for (const nextDep of nextPeerDeps.values()) {
|
|
250
|
+
const { spec, type } = nextDep;
|
|
251
|
+
if (type === 'peer' || type === 'peerOptional') {
|
|
252
|
+
// try to retrieve an entry for that peer dep from
|
|
253
|
+
// the current peer context set
|
|
254
|
+
const entry = peerContext.get(spec.final.name);
|
|
255
|
+
if (!node.edgesOut.has(spec.final.name) &&
|
|
256
|
+
entry?.target &&
|
|
257
|
+
satisfies(entry.target.id, spec, fromNode.location, fromNode.projectRoot, graph.monorepo)) {
|
|
258
|
+
// entry satisfied, create edge in the graph
|
|
259
|
+
graph.addEdge(type, spec, node, entry.target);
|
|
260
|
+
entry.specs.add(spec.final);
|
|
261
|
+
}
|
|
262
|
+
else if (type === 'peerOptional') {
|
|
263
|
+
// skip unsatisfied peerOptional dependencies,
|
|
264
|
+
// just create a dangling edge
|
|
265
|
+
graph.addEdge(type, spec, node);
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
// could not satisfy from peer context, add to next deps
|
|
269
|
+
nextDeps.push(nextDep);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
},
|
|
274
|
+
});
|
|
275
|
+
/**
|
|
276
|
+
* Given an array of processed results for the current level dependencies
|
|
277
|
+
* being placed in the currently building ideal graph, traverse its direct
|
|
278
|
+
* dependencies and track peer dependencies in their appropriate peer context
|
|
279
|
+
* sets, forking as needed and resolving peer dependencies using suitable
|
|
280
|
+
* nodes already present in the graph if possible.
|
|
281
|
+
*/
|
|
282
|
+
export const postPlacementPeerCheck = (graph, sortedLevelResults) => {
|
|
283
|
+
// Update peer contexts in a sorted manner after processing all nodes
|
|
284
|
+
// at a given level to ensure deterministic behavior when it comes to
|
|
285
|
+
// forking new peer contexts
|
|
286
|
+
for (const childDepsToProcess of sortedLevelResults) {
|
|
287
|
+
const needsForking = new Map();
|
|
288
|
+
// first iterate on all child deps, adding entries to the current
|
|
289
|
+
// context and collect the information on which ones need forking
|
|
290
|
+
for (const childDep of childDepsToProcess) {
|
|
291
|
+
const needsFork = childDep.updateContext.putEntries();
|
|
292
|
+
if (needsFork) {
|
|
293
|
+
needsForking.set(childDep, needsFork);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
// then iterate again, forking contexts as needed but also try to
|
|
297
|
+
// reuse the context of the previous sibling if possible
|
|
298
|
+
let prevContext;
|
|
299
|
+
for (const [childDep, nextEntries] of needsForking.entries()) {
|
|
300
|
+
if (prevContext &&
|
|
301
|
+
!checkEntriesToPeerContext(prevContext, nextEntries)) {
|
|
302
|
+
// the context of the previous sibling can be reused
|
|
303
|
+
addEntriesToPeerContext(prevContext, nextEntries, childDep.node, graph.monorepo);
|
|
304
|
+
childDep.peerContext = prevContext;
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
childDep.peerContext = forkPeerContext(graph, childDep.peerContext, nextEntries);
|
|
308
|
+
prevContext = childDep.peerContext;
|
|
309
|
+
}
|
|
310
|
+
// try to resolve peer dependencies now that
|
|
311
|
+
// the context is fully set up
|
|
312
|
+
for (const childDep of childDepsToProcess) {
|
|
313
|
+
childDep.updateContext.resolvePeerDeps();
|
|
314
|
+
childDep.deps = getOrderedDependencies(childDep.deps);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
//# sourceMappingURL=peers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"peers.js","sourceRoot":"","sources":["../../../src/ideal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C5C,8BAA8B;QAC9B,KAAK,MAAM,QAAQ,IAAI,kBAAkB,EAAE,CAAC;YAC1C,QAAQ,CAAC,aAAa,CAAC,eAAe,EAAE,CAAA;YACxC,QAAQ,CAAC,IAAI,GAAG,sBAAsB,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;QACvD,CAAC;IACH,CAAC;AACH,CAAC,CAAA","sourcesContent":["// helpers for managing peer dependency resolution\n// during the ideal graph building process.\n\nimport { intersects } from '@vltpkg/semver'\nimport { satisfies } from '@vltpkg/satisfies'\nimport { getDependencies } from '../dependencies.ts'\nimport { getOrderedDependencies } from './get-ordered-dependencies.ts'\nimport type { Spec, SpecOptions } from '@vltpkg/spec'\nimport type { DependencySaveType, Manifest } from '@vltpkg/types'\nimport type { Monorepo } from '@vltpkg/workspaces'\nimport type { Dependency } from '../dependencies.ts'\nimport type { Graph } from '../graph.ts'\nimport type { Node } from '../node.ts'\nimport type {\n PeerContext,\n PeerContextEntry,\n PeerContextEntryInput,\n ProcessPlacementResult,\n ProcessPlacementResultEntry,\n} from './types.ts'\n\n/**\n * Retrieve a unique hash value for a given peer context set.\n */\nexport const retrievePeerContextHash = (\n peerContext: PeerContext | undefined,\n): string | undefined => {\n // skips creating the initial peer context ref\n if (!peerContext?.index) return undefined\n\n return `ṗ:${peerContext.index}`\n}\n\n/**\n * Checks if a given spec is compatible with the specs already\n * assigned to a peer context entry.\n *\n * Returns true if compatible, false otherwise.\n */\nexport const incompatibleSpecs = (\n spec: Spec,\n entry: PeerContextEntry,\n): boolean => {\n if (entry.specs.size > 0) {\n for (const s of entry.specs) {\n if (\n // only able to check range intersections for registry types\n (spec.type === 'registry' &&\n (!spec.range ||\n !s.range ||\n !intersects(spec.range, s.range))) ||\n // also support types other than registry in case\n // they use the very same bareSpec value\n (spec.type !== 'registry' && spec.bareSpec !== s.bareSpec)\n ) {\n return true\n }\n }\n }\n return false\n}\n\n/*\n * Checks if there are any conflicting versions for a given dependency\n * to be added to a peer context set which will require forking.\n *\n * Returns true if forking is needed, false otherwise.\n */\nexport const checkEntriesToPeerContext = (\n peerContext: PeerContext,\n entries: PeerContextEntryInput[],\n): boolean => {\n // check on compatibility of new entries\n for (const { spec, target } of entries) {\n const name = target?.name ?? spec.final.name\n\n // skip any inactive entry\n const entry = peerContext.get(name)\n if (!entry?.active) continue\n\n // validate if the provided spec is compatible with existing specs\n if (incompatibleSpecs(spec, entry)) {\n return true\n }\n }\n\n return false\n}\n\n/**\n * Add or update dependencies in a given peer context making sure to check\n * for compatibility with existing dependencies already resolved by a given\n * peer context set. Extra info such as a target or dependent nodes is\n * optional.\n *\n * Returns true if forking is needed, false otherwise.\n */\nexport const addEntriesToPeerContext = (\n peerContext: PeerContext,\n entries: PeerContextEntryInput[],\n fromNode: Node,\n monorepo?: Monorepo,\n): boolean => {\n // pre check to see if any of the new entries to be added to the\n // provided peer context set conflicts with existing ones\n // if that's already the case we can skip processing them and\n // will return that a fork is needed right away\n if (checkEntriesToPeerContext(peerContext, entries)) return true\n\n // iterate on every entry to be added to the peer context set\n for (const { dependent, spec, target, type } of entries) {\n const name = target?.name ?? spec.final.name\n\n // if there's no existing entry, create one\n let entry = peerContext.get(name)\n if (!entry) {\n entry = {\n active: true,\n specs: new Set([spec]),\n target,\n type,\n contextDependents: new Set(),\n }\n peerContext.set(name, entry)\n if (dependent) entry.contextDependents.add(dependent)\n continue\n }\n\n // perform an extra check that confirms the new spec does not\n // conflicts with existing specs in this entry, this handles the\n // case of adding sibling deps that conflicts with one another\n if (incompatibleSpecs(spec, entry)) return true\n\n if (\n target &&\n [...entry.specs].every(s =>\n satisfies(\n target.id,\n s,\n fromNode.location,\n fromNode.projectRoot,\n monorepo,\n ),\n )\n ) {\n if (\n target.id !== entry.target?.id &&\n target.version !== entry.target?.version\n ) {\n // we have a compatible entry that has a new, compatible target\n // so we need to update all dependents to point to the new target\n for (const dependents of entry.contextDependents) {\n const edge = dependents.edgesOut.get(name)\n if (edge?.to && edge.to !== target) {\n edge.to.edgesIn.delete(edge)\n edge.to = target\n target.edgesIn.add(edge)\n }\n }\n entry.target = target\n }\n\n // otherwise sets the value in case it was nullish\n entry.target ??= target\n }\n\n // update specs and dependents values\n entry.specs.add(spec)\n if (dependent) entry.contextDependents.add(dependent)\n }\n\n return false\n}\n\n/**\n * Create and returns a forked copy of a given peer context set.\n */\nexport const forkPeerContext = (\n graph: Graph,\n peerContext: PeerContext,\n entries: PeerContextEntryInput[],\n): PeerContext => {\n // create a new peer context set\n const nextPeerContext: PeerContext = new Map()\n nextPeerContext.index = graph.nextPeerContextIndex()\n // register it in the graph\n graph.peerContexts[nextPeerContext.index] = nextPeerContext\n\n // copy existing entries marking them as inactive, it's also important\n // to note that specs and contextDependents are new objects so that changes\n // to those in the new context do not affect the previous one\n for (const [name, entry] of peerContext.entries()) {\n nextPeerContext.set(name, {\n active: false,\n specs: new Set(entry.specs),\n target: undefined,\n type: entry.type,\n contextDependents: new Set(entry.contextDependents),\n })\n }\n\n // add the new entries to this peer context set, marking them as active\n // these are the entries that were incompatible with the previous context set\n for (const entry of entries) {\n const { dependent, spec, target, type } = entry\n const name = target?.name /* c8 ignore next */ ?? spec.final.name\n const newEntry = {\n active: true,\n specs: new Set([spec]),\n target,\n type,\n contextDependents:\n dependent ? new Set([dependent]) : new Set<Node>(),\n }\n nextPeerContext.set(name, newEntry)\n }\n\n return nextPeerContext\n}\n\n/**\n * Starts the peer dependency placement process\n * for a given node being processed and placed.\n */\nexport const startPeerPlacement = (\n peerContext: PeerContext,\n manifest: Manifest,\n fromNode: Node,\n options: SpecOptions,\n) => {\n // queue entries so that they can be added at the end of the placement\n // process, use a map to ensure deduplication between read json dep\n // values and the resolved edges in the graph\n const queueMap = new Map<string, PeerContextEntryInput>()\n let peerSetHash: string | undefined\n\n if (\n manifest.peerDependencies &&\n Object.keys(manifest.peerDependencies).length > 0\n ) {\n // generates a peer context set hash for nodes that\n // have peer dependencies to be resolved\n peerSetHash = retrievePeerContextHash(peerContext)\n\n // get any potential sibling dependency from the\n // parent node that might have not been parsed yet\n const siblingDeps = getDependencies(fromNode, {\n ...options,\n registry: fromNode.registry,\n })\n for (const [depName, dep] of siblingDeps) {\n queueMap.set(depName, dep)\n }\n\n // collect the already parsed nodes and add those to the\n // list of entries to be added to the peer context set\n for (const edge of fromNode.edgesOut.values()) {\n queueMap.set(edge.name, {\n spec: edge.spec,\n target: edge.to,\n type: edge.type,\n })\n }\n }\n\n return {\n peerSetHash,\n queuedEntries: [...queueMap.values()],\n }\n}\n\n/**\n * Ends the peer dependency placement process, returning the functions that\n * are going to be used to update the peer context set, forking when needed\n * and resolving peer dependencies if possible.\n */\nexport const endPeerPlacement = (\n peerContext: PeerContext,\n nextDeps: Dependency[],\n nextPeerDeps: Map<string, Dependency> & { id?: number },\n graph: Graph,\n spec: Spec,\n fromNode: Node,\n node: Node,\n type: DependencySaveType,\n queuedEntries: PeerContextEntryInput[],\n) => ({\n /**\n * Add the new entries to the current peer context set.\n */\n putEntries: () => {\n // keep track of whether we need to fork the current peer context set\n let needsToForkPeerContext = false\n // add queued entries from this node parents along\n // with a self-ref to the current peer context set\n const prevEntries = [\n ...queuedEntries,\n /* ref itself */ {\n spec,\n target: node,\n type,\n },\n ]\n addEntriesToPeerContext(\n peerContext,\n prevEntries,\n fromNode,\n graph.monorepo,\n )\n\n // add this node's direct dependencies next\n const nextEntries = [\n ...nextDeps.map(dep => ({ ...dep, dependent: node })),\n ...[...nextPeerDeps.values()].map(dep => ({\n ...dep,\n dependent: node,\n })),\n ]\n if (nextEntries.length > 0) {\n needsToForkPeerContext = addEntriesToPeerContext(\n peerContext,\n nextEntries,\n node,\n graph.monorepo,\n )\n }\n\n // returns all entries that need to be added to a forked\n // context or undefined if the current context was updated directly\n return needsToForkPeerContext ? nextEntries : undefined\n },\n\n /**\n * Try to resolve peer dependencies using already seen target\n * values from the current peer context set.\n */\n resolvePeerDeps: () => {\n // iterate on the set of peer dependencies of the current node\n // and try to resolve them from the existing peer context set,\n // when possible, add them as edges in the graph right away, if not,\n // then we move them back to the `nextDeps` list for processing\n // along with the rest of the regular dependencies\n for (const nextDep of nextPeerDeps.values()) {\n const { spec, type } = nextDep\n if (type === 'peer' || type === 'peerOptional') {\n // try to retrieve an entry for that peer dep from\n // the current peer context set\n const entry = peerContext.get(spec.final.name)\n if (\n !node.edgesOut.has(spec.final.name) &&\n entry?.target &&\n satisfies(\n entry.target.id,\n spec,\n fromNode.location,\n fromNode.projectRoot,\n graph.monorepo,\n )\n ) {\n // entry satisfied, create edge in the graph\n graph.addEdge(type, spec, node, entry.target)\n entry.specs.add(spec.final)\n } else if (type === 'peerOptional') {\n // skip unsatisfied peerOptional dependencies,\n // just create a dangling edge\n graph.addEdge(type, spec, node)\n } else {\n // could not satisfy from peer context, add to next deps\n nextDeps.push(nextDep)\n }\n }\n }\n },\n})\n\n/**\n * Given an array of processed results for the current level dependencies\n * being placed in the currently building ideal graph, traverse its direct\n * dependencies and track peer dependencies in their appropriate peer context\n * sets, forking as needed and resolving peer dependencies using suitable\n * nodes already present in the graph if possible.\n */\nexport const postPlacementPeerCheck = (\n graph: Graph,\n sortedLevelResults: ProcessPlacementResult[],\n) => {\n // Update peer contexts in a sorted manner after processing all nodes\n // at a given level to ensure deterministic behavior when it comes to\n // forking new peer contexts\n for (const childDepsToProcess of sortedLevelResults) {\n const needsForking = new Map<\n ProcessPlacementResultEntry,\n {\n dependent: Node\n spec: Spec\n type: DependencySaveType\n }[]\n >()\n // first iterate on all child deps, adding entries to the current\n // context and collect the information on which ones need forking\n for (const childDep of childDepsToProcess) {\n const needsFork = childDep.updateContext.putEntries()\n if (needsFork) {\n needsForking.set(childDep, needsFork)\n }\n }\n // then iterate again, forking contexts as needed but also try to\n // reuse the context of the previous sibling if possible\n let prevContext\n for (const [childDep, nextEntries] of needsForking.entries()) {\n if (\n prevContext &&\n !checkEntriesToPeerContext(prevContext, nextEntries)\n ) {\n // the context of the previous sibling can be reused\n addEntriesToPeerContext(\n prevContext,\n nextEntries,\n childDep.node,\n graph.monorepo,\n )\n childDep.peerContext = prevContext\n continue\n }\n childDep.peerContext = forkPeerContext(\n graph,\n childDep.peerContext,\n nextEntries,\n )\n prevContext = childDep.peerContext\n }\n // try to resolve peer dependencies now that\n // the context is fully set up\n for (const childDep of childDepsToProcess) {\n childDep.updateContext.resolvePeerDeps()\n childDep.deps = getOrderedDependencies(childDep.deps)\n }\n }\n}\n"]}
|
|
@@ -2,10 +2,10 @@ import type { PathScurry } from 'path-scurry';
|
|
|
2
2
|
import type { PackageInfoClient } from '@vltpkg/package-info';
|
|
3
3
|
import type { SpecOptions } from '@vltpkg/spec';
|
|
4
4
|
import type { RollbackRemove } from '@vltpkg/rollback-remove';
|
|
5
|
-
import type { BuildIdealAddOptions, BuildIdealFromGraphOptions } from './types.ts';
|
|
5
|
+
import type { BuildIdealAddOptions, BuildIdealFromGraphOptions, BuildIdealRemoveOptions } from './types.ts';
|
|
6
6
|
import type { GraphModifier } from '../modifiers.ts';
|
|
7
7
|
import type { Graph } from '../graph.ts';
|
|
8
|
-
export type
|
|
8
|
+
export type RefreshIdealGraphOptions = BuildIdealAddOptions & BuildIdealRemoveOptions & BuildIdealFromGraphOptions & SpecOptions & {
|
|
9
9
|
/**
|
|
10
10
|
* The graph modifiers helper object.
|
|
11
11
|
*/
|
|
@@ -28,7 +28,11 @@ export type AddNodesOptions = BuildIdealAddOptions & BuildIdealFromGraphOptions
|
|
|
28
28
|
remover: RollbackRemove;
|
|
29
29
|
};
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
31
|
+
* Rebuilds the provided ideal graph.
|
|
32
32
|
*/
|
|
33
|
-
export declare const
|
|
34
|
-
|
|
33
|
+
export declare const refreshIdealGraph: ({ add, graph, modifiers, packageInfo, scurry, actual, remove, remover, ...specOptions }: RefreshIdealGraphOptions) => Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Retrieve the next unique index for a peer context set.
|
|
36
|
+
*/
|
|
37
|
+
export declare const nextPeerContextIndex: () => number;
|
|
38
|
+
//# sourceMappingURL=refresh-ideal-graph.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refresh-ideal-graph.d.ts","sourceRoot":"","sources":["../../../src/ideal/refresh-ideal-graph.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAE7C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAC7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAC7D,OAAO,KAAK,EACV,oBAAoB,EACpB,0BAA0B,EAC1B,uBAAuB,EACxB,MAAM,YAAY,CAAA;AAEnB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAEpD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAGxC,MAAM,MAAM,wBAAwB,GAAG,oBAAoB,GACzD,uBAAuB,GACvB,0BAA0B,GAC1B,WAAW,GAAG;IACZ;;OAEG;IACH,SAAS,CAAC,EAAE,aAAa,CAAA;IACzB;;OAEG;IACH,MAAM,EAAE,UAAU,CAAA;IAElB;;OAEG;IACH,WAAW,EAAE,iBAAiB,CAAA;IAE9B;;OAEG;IACH,MAAM,CAAC,EAAE,KAAK,CAAA;IAEd;;OAEG;IACH,OAAO,EAAE,cAAc,CAAA;CACxB,CAAA;AAkCH;;GAEG;AACH,eAAO,MAAM,iBAAiB,4FAU3B,wBAAwB,kBAgE1B,CAAA;AAMD;;GAEG;AACH,eAAO,MAAM,oBAAoB,cAA2B,CAAA"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { appendNodes } from "./append-nodes.js";
|
|
2
|
+
import { getNodeOrderedDependencies } from "./get-ordered-dependencies.js";
|
|
3
|
+
/**
|
|
4
|
+
* Returns an ordered list of importer nodes.
|
|
5
|
+
*/
|
|
6
|
+
const getOrderedImporters = (graph) => {
|
|
7
|
+
const orderedImporters = [...graph.importers].sort((a, b) => {
|
|
8
|
+
// sorts importers first by usage of peer deps
|
|
9
|
+
const aIsPeer = (a.manifest?.peerDependencies &&
|
|
10
|
+
Object.keys(a.manifest.peerDependencies).length > 0) ?
|
|
11
|
+
1
|
|
12
|
+
: 0;
|
|
13
|
+
const bIsPeer = (b.manifest?.peerDependencies &&
|
|
14
|
+
Object.keys(b.manifest.peerDependencies).length > 0) ?
|
|
15
|
+
1
|
|
16
|
+
: 0;
|
|
17
|
+
// importers with regular deps only first, with peer deps last
|
|
18
|
+
if (aIsPeer !== bIsPeer) {
|
|
19
|
+
return aIsPeer - bIsPeer;
|
|
20
|
+
}
|
|
21
|
+
// if both are in the same group, sort alphabetically by manifest name
|
|
22
|
+
return a.name.localeCompare(b.name, 'en');
|
|
23
|
+
});
|
|
24
|
+
return orderedImporters;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Rebuilds the provided ideal graph.
|
|
28
|
+
*/
|
|
29
|
+
export const refreshIdealGraph = async ({ add, graph, modifiers, packageInfo, scurry, actual, remove, remover, ...specOptions }) => {
|
|
30
|
+
const seen = new Set();
|
|
31
|
+
const extractPromises = [];
|
|
32
|
+
const seenExtracted = new Set();
|
|
33
|
+
// gets an ordered list of importers to ensure deterministic processing
|
|
34
|
+
const orderedImporters = getOrderedImporters(graph);
|
|
35
|
+
const depsPerImporter = new Map();
|
|
36
|
+
for (const importer of orderedImporters) {
|
|
37
|
+
// gets an ordered list of dependencies for this importer
|
|
38
|
+
// while also taking into account additions and removals
|
|
39
|
+
const deps = getNodeOrderedDependencies(importer, { add, remove });
|
|
40
|
+
depsPerImporter.set(importer, deps);
|
|
41
|
+
}
|
|
42
|
+
// removes all edges to start recalculating the graph
|
|
43
|
+
if (add.modifiedDependencies || remove.modifiedDependencies) {
|
|
44
|
+
graph.resetEdges();
|
|
45
|
+
}
|
|
46
|
+
// iterates on the list of dependencies per importer updating
|
|
47
|
+
// the graph using metadata fetch from the registry manifest files
|
|
48
|
+
for (const importer of orderedImporters) {
|
|
49
|
+
modifiers?.tryImporter(importer);
|
|
50
|
+
// gets a ref to the map of dependencies being added to this importer
|
|
51
|
+
const addedDeps = add.get(importer.id);
|
|
52
|
+
const deps = depsPerImporter.get(importer);
|
|
53
|
+
/* c8 ignore next */
|
|
54
|
+
if (!deps)
|
|
55
|
+
continue;
|
|
56
|
+
// gets a ref to the list of modifier functions for this set of deps
|
|
57
|
+
const modifierRefs = modifiers?.tryDependencies(importer, deps);
|
|
58
|
+
// Add new nodes for packages defined in the dependencies list fetching
|
|
59
|
+
// metadata from the registry manifests and updating the graph
|
|
60
|
+
await appendNodes(packageInfo, graph, importer, deps, scurry, specOptions, seen, addedDeps, modifiers, modifierRefs, extractPromises, actual, seenExtracted, remover);
|
|
61
|
+
}
|
|
62
|
+
// set default node locations, if possible
|
|
63
|
+
for (const node of graph.nodes.values()) {
|
|
64
|
+
node.setDefaultLocation();
|
|
65
|
+
}
|
|
66
|
+
// Wait for all extraction promises to complete
|
|
67
|
+
if (extractPromises.length > 0) {
|
|
68
|
+
await Promise.all(extractPromises);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Global index to assign unique ids used to track peer context sets.
|
|
73
|
+
*/
|
|
74
|
+
let peerContextIndex = 0;
|
|
75
|
+
/**
|
|
76
|
+
* Retrieve the next unique index for a peer context set.
|
|
77
|
+
*/
|
|
78
|
+
export const nextPeerContextIndex = () => peerContextIndex++;
|
|
79
|
+
//# sourceMappingURL=refresh-ideal-graph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refresh-ideal-graph.js","sourceRoot":"","sources":["../../../src/ideal/refresh-ideal-graph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAA;AA8C1E;;GAE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,EAAE,CAAC;QACxC,IAAI,CAAC,kBAAkB,EAAE,CAAA;IAC3B,CAAC;IAED,+CAA+C;IAC/C,IAAI,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC/B,MAAM,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAA;IACpC,CAAC;AACH,CAAC,CAAA;AAED;;GAEG;AACH,IAAI,gBAAgB,GAAG,CAAC,CAAA;AACxB;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,EAAE,CAAC,gBAAgB,EAAE,CAAA","sourcesContent":["import { appendNodes } from './append-nodes.ts'\nimport { getNodeOrderedDependencies } from './get-ordered-dependencies.ts'\nimport type { PathScurry } from 'path-scurry'\nimport type { DepID } from '@vltpkg/dep-id'\nimport type { PackageInfoClient } from '@vltpkg/package-info'\nimport type { SpecOptions } from '@vltpkg/spec'\nimport type { RollbackRemove } from '@vltpkg/rollback-remove'\nimport type {\n BuildIdealAddOptions,\n BuildIdealFromGraphOptions,\n BuildIdealRemoveOptions,\n} from './types.ts'\nimport type { Dependency } from '../dependencies.ts'\nimport type { GraphModifier } from '../modifiers.ts'\nimport type { ExtractResult } from '../reify/extract-node.ts'\nimport type { Graph } from '../graph.ts'\nimport type { Node } from '../node.ts'\n\nexport type RefreshIdealGraphOptions = BuildIdealAddOptions &\n BuildIdealRemoveOptions &\n BuildIdealFromGraphOptions &\n SpecOptions & {\n /**\n * The graph modifiers helper object.\n */\n modifiers?: GraphModifier\n /**\n * A {@link PathScurry} instance based on the `projectRoot` path\n */\n scurry: PathScurry\n\n /**\n * A {@link PackageInfoClient} instance to read manifest info from.\n */\n packageInfo: PackageInfoClient\n\n /**\n * The actual graph to compare against for early extraction\n */\n actual?: Graph\n\n /**\n * A {@link RollbackRemove} instance to handle extraction rollbacks\n */\n remover: RollbackRemove\n }\n\n/**\n * Returns an ordered list of importer nodes.\n */\nconst getOrderedImporters = (graph: Graph): Node[] => {\n const orderedImporters = [...graph.importers].sort((a, b) => {\n // sorts importers first by usage of peer deps\n const aIsPeer =\n (\n a.manifest?.peerDependencies &&\n Object.keys(a.manifest.peerDependencies).length > 0\n ) ?\n 1\n : 0\n const bIsPeer =\n (\n b.manifest?.peerDependencies &&\n Object.keys(b.manifest.peerDependencies).length > 0\n ) ?\n 1\n : 0\n\n // importers with regular deps only first, with peer deps last\n if (aIsPeer !== bIsPeer) {\n return aIsPeer - bIsPeer\n }\n\n // if both are in the same group, sort alphabetically by manifest name\n return a.name.localeCompare(b.name, 'en')\n })\n return orderedImporters\n}\n\n/**\n * Rebuilds the provided ideal graph.\n */\nexport const refreshIdealGraph = async ({\n add,\n graph,\n modifiers,\n packageInfo,\n scurry,\n actual,\n remove,\n remover,\n ...specOptions\n}: RefreshIdealGraphOptions) => {\n const seen = new Set<DepID>()\n const extractPromises: Promise<ExtractResult>[] = []\n const seenExtracted = new Set<DepID>()\n\n // gets an ordered list of importers to ensure deterministic processing\n const orderedImporters = getOrderedImporters(graph)\n const depsPerImporter = new Map<Node, Dependency[]>()\n for (const importer of orderedImporters) {\n // gets an ordered list of dependencies for this importer\n // while also taking into account additions and removals\n const deps = getNodeOrderedDependencies(importer, { add, remove })\n depsPerImporter.set(importer, deps)\n }\n\n // removes all edges to start recalculating the graph\n if (add.modifiedDependencies || remove.modifiedDependencies) {\n graph.resetEdges()\n }\n\n // iterates on the list of dependencies per importer updating\n // the graph using metadata fetch from the registry manifest files\n for (const importer of orderedImporters) {\n modifiers?.tryImporter(importer)\n\n // gets a ref to the map of dependencies being added to this importer\n const addedDeps = add.get(importer.id)\n\n const deps = depsPerImporter.get(importer)\n /* c8 ignore next */\n if (!deps) continue\n\n // gets a ref to the list of modifier functions for this set of deps\n const modifierRefs = modifiers?.tryDependencies(importer, deps)\n\n // Add new nodes for packages defined in the dependencies list fetching\n // metadata from the registry manifests and updating the graph\n await appendNodes(\n packageInfo,\n graph,\n importer,\n deps,\n scurry,\n specOptions,\n seen,\n addedDeps,\n modifiers,\n modifierRefs,\n extractPromises,\n actual,\n seenExtracted,\n remover,\n )\n }\n\n // set default node locations, if possible\n for (const node of graph.nodes.values()) {\n node.setDefaultLocation()\n }\n\n // Wait for all extraction promises to complete\n if (extractPromises.length > 0) {\n await Promise.all(extractPromises)\n }\n}\n\n/**\n * Global index to assign unique ids used to track peer context sets.\n */\nlet peerContextIndex = 0\n/**\n * Retrieve the next unique index for a peer context set.\n */\nexport const nextPeerContextIndex = () => peerContextIndex++\n"]}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { PackageInfoClient } from '@vltpkg/package-info';
|
|
2
|
-
import type {
|
|
2
|
+
import type { Spec } from '@vltpkg/spec';
|
|
3
|
+
import type { DependencySaveType } from '@vltpkg/types';
|
|
4
|
+
import type { AddImportersDependenciesMap, Dependency, RemoveImportersDependenciesMap } from '../dependencies.ts';
|
|
5
|
+
import type { ModifierActiveEntry } from '../modifiers.ts';
|
|
3
6
|
import type { Graph } from '../graph.ts';
|
|
7
|
+
import type { Node } from '../node.ts';
|
|
4
8
|
export type BuildIdealAddOptions = {
|
|
5
9
|
/**
|
|
6
10
|
* A {@link AddImportersDependenciesMap} in which keys are {@link DepID}
|
|
@@ -32,4 +36,64 @@ export type BuildIdealPackageInfoOptions = {
|
|
|
32
36
|
*/
|
|
33
37
|
packageInfo: PackageInfoClient;
|
|
34
38
|
};
|
|
39
|
+
/**
|
|
40
|
+
* Represents an ongoing append operation for a node and its dependencies.
|
|
41
|
+
*/
|
|
42
|
+
export type AppendNodeEntry = {
|
|
43
|
+
node: Node;
|
|
44
|
+
deps: Dependency[];
|
|
45
|
+
modifierRefs?: Map<string, ModifierActiveEntry>;
|
|
46
|
+
depth: number;
|
|
47
|
+
peerContext: PeerContext;
|
|
48
|
+
updateContext: {
|
|
49
|
+
putEntries: () => {
|
|
50
|
+
dependent: Node;
|
|
51
|
+
spec: Spec;
|
|
52
|
+
type: DependencySaveType;
|
|
53
|
+
}[] | undefined;
|
|
54
|
+
resolvePeerDeps: () => void;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* The result of processing a given placed node in the graph.
|
|
59
|
+
*/
|
|
60
|
+
export type ProcessPlacementResultEntry = Omit<AppendNodeEntry, 'depth'>;
|
|
61
|
+
/**
|
|
62
|
+
* The result of processing placement for nodes to be added to the graph.
|
|
63
|
+
*/
|
|
64
|
+
export type ProcessPlacementResult = ProcessPlacementResultEntry[];
|
|
65
|
+
/**
|
|
66
|
+
* Entry in a peer context representing a resolved peer dependency.
|
|
67
|
+
*/
|
|
68
|
+
export type PeerContextEntry = {
|
|
69
|
+
/**
|
|
70
|
+
* True if this entry is currently being resolved and track by this
|
|
71
|
+
* peer context set, false in case this entry was inherit from a previous
|
|
72
|
+
* peer context set and should not be considered for resolution.
|
|
73
|
+
*/
|
|
74
|
+
active: boolean;
|
|
75
|
+
/** List of full Spec objects that are part of this peer context entry */
|
|
76
|
+
specs: Set<Spec>;
|
|
77
|
+
/** The target Node that satisfies all specs for this peer context entry */
|
|
78
|
+
target: Node | undefined;
|
|
79
|
+
/** The type of dependency this entry represents */
|
|
80
|
+
type: DependencySaveType;
|
|
81
|
+
/** Context dependent nodes that had dependencies resolved to this entry */
|
|
82
|
+
contextDependents: Set<Node>;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Input for adding an entry to peer contexts.
|
|
86
|
+
*/
|
|
87
|
+
export type PeerContextEntryInput = {
|
|
88
|
+
/** Node that depends on this resolved peer context set entry */
|
|
89
|
+
dependent?: Node;
|
|
90
|
+
/** Node this peer context entry resolves to */
|
|
91
|
+
target?: Node;
|
|
92
|
+
} & Dependency;
|
|
93
|
+
/**
|
|
94
|
+
* Represents resolved peer dependencies in a given append-nodes context.
|
|
95
|
+
*/
|
|
96
|
+
export type PeerContext = Map<string, PeerContextEntry> & {
|
|
97
|
+
index?: number;
|
|
98
|
+
};
|
|
35
99
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/ideal/types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAC7D,OAAO,KAAK,EACV,2BAA2B,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/ideal/types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAC7D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AACvD,OAAO,KAAK,EACV,2BAA2B,EAC3B,UAAU,EACV,8BAA8B,EAC/B,MAAM,oBAAoB,CAAA;AAC3B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAC1D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAEtC,MAAM,MAAM,oBAAoB,GAAG;IACjC;;;;;OAKG;IACH,GAAG,EAAE,2BAA2B,CAAA;CACjC,CAAA;AAED,MAAM,MAAM,uBAAuB,GAAG;IACpC;;;;;OAKG;IACH,MAAM,EAAE,8BAA8B,CAAA;CACvC,CAAA;AAED,MAAM,MAAM,0BAA0B,GAAG;IACvC;;;OAGG;IACH,KAAK,EAAE,KAAK,CAAA;CACb,CAAA;AAED,MAAM,MAAM,4BAA4B,GAAG;IACzC;;OAEG;IACH,WAAW,EAAE,iBAAiB,CAAA;CAC/B,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,IAAI,CAAA;IACV,IAAI,EAAE,UAAU,EAAE,CAAA;IAClB,YAAY,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAA;IAC/C,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,WAAW,CAAA;IACxB,aAAa,EAAE;QACb,UAAU,EAAE,MACR;YACE,SAAS,EAAE,IAAI,CAAA;YACf,IAAI,EAAE,IAAI,CAAA;YACV,IAAI,EAAE,kBAAkB,CAAA;SACzB,EAAE,GACH,SAAS,CAAA;QACb,eAAe,EAAE,MAAM,IAAI,CAAA;KAC5B,CAAA;CACF,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,2BAA2B,GAAG,IAAI,CAC5C,eAAe,EACf,OAAO,CACR,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG,2BAA2B,EAAE,CAAA;AAElE;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B;;;;OAIG;IACH,MAAM,EAAE,OAAO,CAAA;IACf,yEAAyE;IACzE,KAAK,EAAE,GAAG,CAAC,IAAI,CAAC,CAAA;IAChB,2EAA2E;IAC3E,MAAM,EAAE,IAAI,GAAG,SAAS,CAAA;IACxB,mDAAmD;IACnD,IAAI,EAAE,kBAAkB,CAAA;IACxB,2EAA2E;IAC3E,iBAAiB,EAAE,GAAG,CAAC,IAAI,CAAC,CAAA;CAC7B,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC,gEAAgE;IAChE,SAAS,CAAC,EAAE,IAAI,CAAA;IAChB,+CAA+C;IAC/C,MAAM,CAAC,EAAE,IAAI,CAAA;CACd,GAAG,UAAU,CAAA;AAEd;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC,GAAG;IACxD,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/ideal/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { DepID } from '@vltpkg/dep-id'\nimport type { PackageInfoClient } from '@vltpkg/package-info'\nimport type {\n AddImportersDependenciesMap,\n Dependency,\n RemoveImportersDependenciesMap,\n} from '../dependencies.ts'\nimport type { Graph } from '../graph.ts'\n\nexport type BuildIdealAddOptions = {\n /**\n * A {@link AddImportersDependenciesMap} in which keys are {@link DepID}\n * linking to another `Map` in which keys are the dependency names and values\n * are {@link Dependency}. This structure represents dependencies that need\n * to be added to the importer represented by {@link DepID}.\n */\n add: AddImportersDependenciesMap\n}\n\nexport type BuildIdealRemoveOptions = {\n /**\n * A {@link RemoveImportersDependenciesMap} object representing nodes to be\n * removed from the ideal graph. Each {@link DepID} key represents an\n * importer node and the `Set` of dependency names to be removed from its\n * dependency list.\n */\n remove: RemoveImportersDependenciesMap\n}\n\nexport type BuildIdealFromGraphOptions = {\n /**\n * An initial {@link Graph} to start building from, adding nodes to any\n * missing edges and appending any new specs defined in `addSpecs`.\n */\n graph: Graph\n}\n\nexport type BuildIdealPackageInfoOptions = {\n /**\n * A {@link PackageInfoClient} instance to read manifest info from.\n */\n packageInfo: PackageInfoClient\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/ideal/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { DepID } from '@vltpkg/dep-id'\nimport type { PackageInfoClient } from '@vltpkg/package-info'\nimport type { Spec } from '@vltpkg/spec'\nimport type { DependencySaveType } from '@vltpkg/types'\nimport type {\n AddImportersDependenciesMap,\n Dependency,\n RemoveImportersDependenciesMap,\n} from '../dependencies.ts'\nimport type { ModifierActiveEntry } from '../modifiers.ts'\nimport type { Graph } from '../graph.ts'\nimport type { Node } from '../node.ts'\n\nexport type BuildIdealAddOptions = {\n /**\n * A {@link AddImportersDependenciesMap} in which keys are {@link DepID}\n * linking to another `Map` in which keys are the dependency names and values\n * are {@link Dependency}. This structure represents dependencies that need\n * to be added to the importer represented by {@link DepID}.\n */\n add: AddImportersDependenciesMap\n}\n\nexport type BuildIdealRemoveOptions = {\n /**\n * A {@link RemoveImportersDependenciesMap} object representing nodes to be\n * removed from the ideal graph. Each {@link DepID} key represents an\n * importer node and the `Set` of dependency names to be removed from its\n * dependency list.\n */\n remove: RemoveImportersDependenciesMap\n}\n\nexport type BuildIdealFromGraphOptions = {\n /**\n * An initial {@link Graph} to start building from, adding nodes to any\n * missing edges and appending any new specs defined in `addSpecs`.\n */\n graph: Graph\n}\n\nexport type BuildIdealPackageInfoOptions = {\n /**\n * A {@link PackageInfoClient} instance to read manifest info from.\n */\n packageInfo: PackageInfoClient\n}\n\n/**\n * Represents an ongoing append operation for a node and its dependencies.\n */\nexport type AppendNodeEntry = {\n node: Node\n deps: Dependency[]\n modifierRefs?: Map<string, ModifierActiveEntry>\n depth: number\n peerContext: PeerContext\n updateContext: {\n putEntries: () =>\n | {\n dependent: Node\n spec: Spec\n type: DependencySaveType\n }[]\n | undefined\n resolvePeerDeps: () => void\n }\n}\n\n/**\n * The result of processing a given placed node in the graph.\n */\nexport type ProcessPlacementResultEntry = Omit<\n AppendNodeEntry,\n 'depth'\n>\n\n/**\n * The result of processing placement for nodes to be added to the graph.\n */\nexport type ProcessPlacementResult = ProcessPlacementResultEntry[]\n\n/**\n * Entry in a peer context representing a resolved peer dependency.\n */\nexport type PeerContextEntry = {\n /**\n * True if this entry is currently being resolved and track by this\n * peer context set, false in case this entry was inherit from a previous\n * peer context set and should not be considered for resolution.\n */\n active: boolean\n /** List of full Spec objects that are part of this peer context entry */\n specs: Set<Spec>\n /** The target Node that satisfies all specs for this peer context entry */\n target: Node | undefined\n /** The type of dependency this entry represents */\n type: DependencySaveType\n /** Context dependent nodes that had dependencies resolved to this entry */\n contextDependents: Set<Node>\n}\n\n/**\n * Input for adding an entry to peer contexts.\n */\nexport type PeerContextEntryInput = {\n /** Node that depends on this resolved peer context set entry */\n dependent?: Node\n /** Node this peer context entry resolves to */\n target?: Node\n} & Dependency\n\n/**\n * Represents resolved peer dependencies in a given append-nodes context.\n */\nexport type PeerContext = Map<string, PeerContextEntry> & {\n index?: number\n}\n"]}
|
package/dist/esm/install.d.ts
CHANGED
|
@@ -2,18 +2,19 @@ import type { PackageInfoClient } from '@vltpkg/package-info';
|
|
|
2
2
|
import type { LoadOptions } from './actual/load.ts';
|
|
3
3
|
import type { AddImportersDependenciesMap } from './dependencies.ts';
|
|
4
4
|
import type { DepID } from '@vltpkg/dep-id';
|
|
5
|
+
import type { Graph } from './index.ts';
|
|
5
6
|
export type InstallOptions = LoadOptions & {
|
|
6
7
|
packageInfo: PackageInfoClient;
|
|
7
8
|
cleanInstall?: boolean;
|
|
8
9
|
allowScripts: string;
|
|
9
10
|
};
|
|
10
11
|
export declare const install: (options: InstallOptions, add?: AddImportersDependenciesMap) => Promise<{
|
|
11
|
-
graph:
|
|
12
|
+
graph: Graph;
|
|
12
13
|
diff: undefined;
|
|
13
14
|
buildQueue?: undefined;
|
|
14
15
|
} | {
|
|
15
16
|
buildQueue: DepID[] | undefined;
|
|
16
|
-
graph:
|
|
17
|
+
graph: Graph;
|
|
17
18
|
diff: import("./diff.ts").Diff;
|
|
18
19
|
}>;
|
|
19
20
|
//# sourceMappingURL=install.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../src/install.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAC7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAEnD,OAAO,KAAK,EACV,2BAA2B,
|
|
1
|
+
{"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../src/install.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAC7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAEnD,OAAO,KAAK,EACV,2BAA2B,EAG5B,MAAM,mBAAmB,CAAA;AAE1B,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAM3C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAGvC,MAAM,MAAM,cAAc,GAAG,WAAW,GAAG;IACzC,WAAW,EAAE,iBAAiB,CAAA;IAC9B,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,YAAY,EAAE,MAAM,CAAA;CACrB,CAAA;AAED,eAAO,MAAM,OAAO,YACT,cAAc,QACjB,2BAA2B;;;;;;;;EAyNlC,CAAA"}
|