@npmcli/arborist 2.7.1 → 2.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/node.js CHANGED
@@ -481,6 +481,11 @@ class Node {
481
481
  return this === this.root || this === this.root.target
482
482
  }
483
483
 
484
+ * ancestry () {
485
+ for (let anc = this; anc; anc = anc.resolveParent)
486
+ yield anc
487
+ }
488
+
484
489
  set root (root) {
485
490
  // setting to null means this is the new root
486
491
  // should only ever be one step
@@ -878,16 +883,31 @@ class Node {
878
883
  // root dependency brings peer deps along with it. In that case, we
879
884
  // will go ahead and create the invalid state, and then try to resolve
880
885
  // it with more tree construction, because it's a user request.
881
- canReplaceWith (node) {
886
+ canReplaceWith (node, ignorePeers = []) {
882
887
  if (node.name !== this.name)
883
888
  return false
884
889
 
890
+ if (node.packageName !== this.packageName)
891
+ return false
892
+
893
+ ignorePeers = new Set(ignorePeers)
894
+
885
895
  // gather up all the deps of this node and that are only depended
886
896
  // upon by deps of this node. those ones don't count, since
887
897
  // they'll be replaced if this node is replaced anyway.
888
898
  const depSet = gatherDepSet([this], e => e.to !== this && e.valid)
889
899
 
890
900
  for (const edge of this.edgesIn) {
901
+ // when replacing peer sets, we need to be able to replace the entire
902
+ // peer group, which means we ignore incoming edges from other peers
903
+ // within the replacement set.
904
+ const ignored = !this.isTop &&
905
+ edge.from.parent === this.parent &&
906
+ edge.peer &&
907
+ ignorePeers.has(edge.from.name)
908
+ if (ignored)
909
+ continue
910
+
891
911
  // only care about edges that don't originate from this node
892
912
  if (!depSet.has(edge.from) && !edge.satisfiedBy(node))
893
913
  return false
@@ -896,8 +916,8 @@ class Node {
896
916
  return true
897
917
  }
898
918
 
899
- canReplace (node) {
900
- return node.canReplaceWith(this)
919
+ canReplace (node, ignorePeers) {
920
+ return node.canReplaceWith(this, ignorePeers)
901
921
  }
902
922
 
903
923
  // return true if it's safe to remove this node, because anything that
@@ -1210,6 +1230,12 @@ class Node {
1210
1230
  }
1211
1231
 
1212
1232
  resolve (name) {
1233
+ /* istanbul ignore next - should be impossible,
1234
+ * but I keep doing this mistake in tests */
1235
+ debug(() => {
1236
+ if (typeof name !== 'string' || !name)
1237
+ throw new Error('non-string passed to Node.resolve')
1238
+ })
1213
1239
  const mine = this.children.get(name)
1214
1240
  if (mine)
1215
1241
  return mine
@@ -0,0 +1,72 @@
1
+ // Given a node in a tree, return all of the peer dependency sets that
2
+ // it is a part of, with the entry (top or non-peer) edges into the sets
3
+ // identified.
4
+ //
5
+ // With this information, we can determine whether it is appropriate to
6
+ // replace the entire peer set with another (and remove the old one),
7
+ // push the set deeper into the tree, and so on.
8
+ //
9
+ // Returns a Map of { edge => Set(peerNodes) },
10
+
11
+ const peerEntrySets = node => {
12
+ // this is the union of all peer groups that the node is a part of
13
+ // later, we identify all of the entry edges, and create a set of
14
+ // 1 or more overlapping sets that this node is a part of.
15
+ const unionSet = new Set([node])
16
+ for (const node of unionSet) {
17
+ for (const edge of node.edgesOut.values()) {
18
+ if (edge.valid && edge.peer && edge.to)
19
+ unionSet.add(edge.to)
20
+ }
21
+ for (const edge of node.edgesIn) {
22
+ if (edge.valid && edge.peer)
23
+ unionSet.add(edge.from)
24
+ }
25
+ }
26
+ const entrySets = new Map()
27
+ for (const peer of unionSet) {
28
+ for (const edge of peer.edgesIn) {
29
+ // if not valid, it doesn't matter anyway. either it's been previously
30
+ // overridden, or it's the thing we're interested in replacing.
31
+ if (!edge.valid)
32
+ continue
33
+ // this is the entry point into the peer set
34
+ if (!edge.peer || edge.from.isTop) {
35
+ // get the subset of peer brought in by this peer entry edge
36
+ const sub = new Set([peer])
37
+ for (const peer of sub) {
38
+ for (const edge of peer.edgesOut.values()) {
39
+ if (edge.valid && edge.peer && edge.to)
40
+ sub.add(edge.to)
41
+ }
42
+ }
43
+ // if this subset does not include the node we are focused on,
44
+ // then it is not relevant for our purposes. Example:
45
+ //
46
+ // a -> (b, c, d)
47
+ // b -> PEER(d) b -> d -> e -> f <-> g
48
+ // c -> PEER(f, h) c -> (f <-> g, h -> g)
49
+ // d -> PEER(e) d -> e -> f <-> g
50
+ // e -> PEER(f)
51
+ // f -> PEER(g)
52
+ // g -> PEER(f)
53
+ // h -> PEER(g)
54
+ //
55
+ // The unionSet(e) will include c, but we don't actually care about
56
+ // it. We only expanded to the edge of the peer nodes in order to
57
+ // find the entry edges that caused the inclusion of peer sets
58
+ // including (e), so we want:
59
+ // Map{
60
+ // Edge(a->b) => Set(b, d, e, f, g)
61
+ // Edge(a->d) => Set(d, e, f, g)
62
+ // }
63
+ if (sub.has(node))
64
+ entrySets.set(edge, sub)
65
+ }
66
+ }
67
+ }
68
+
69
+ return entrySets
70
+ }
71
+
72
+ module.exports = peerEntrySets
@@ -0,0 +1,536 @@
1
+ // Given a dep, a node that depends on it, and the edge representing that
2
+ // dependency, place the dep somewhere in the node's tree, and all of its
3
+ // peer dependencies.
4
+ //
5
+ // Handles all of the tree updating needed to place the dep, including
6
+ // removing replaced nodes, pruning now-extraneous or invalidated nodes,
7
+ // and saves a set of what was placed and what needs re-evaluation as
8
+ // a result.
9
+
10
+ const log = require('proc-log')
11
+ const deepestNestingTarget = require('./deepest-nesting-target.js')
12
+ const CanPlaceDep = require('./can-place-dep.js')
13
+ const {
14
+ KEEP,
15
+ CONFLICT,
16
+ } = CanPlaceDep
17
+ const debug = require('./debug.js')
18
+
19
+ const gatherDepSet = require('./gather-dep-set.js')
20
+ const peerEntrySets = require('./peer-entry-sets.js')
21
+
22
+ class PlaceDep {
23
+ constructor (options) {
24
+ const {
25
+ dep,
26
+ edge,
27
+ parent = null,
28
+ } = options
29
+ this.name = edge.name
30
+ this.dep = dep
31
+ this.edge = edge
32
+ this.canPlace = null
33
+
34
+ this.target = null
35
+ this.placed = null
36
+
37
+ // inherit all these fields from the parent to ensure consistency.
38
+ const {
39
+ preferDedupe,
40
+ force,
41
+ explicitRequest,
42
+ updateNames,
43
+ auditReport,
44
+ legacyBundling,
45
+ strictPeerDeps,
46
+ legacyPeerDeps,
47
+ globalStyle,
48
+ } = parent || options
49
+ Object.assign(this, {
50
+ preferDedupe,
51
+ force,
52
+ explicitRequest,
53
+ updateNames,
54
+ auditReport,
55
+ legacyBundling,
56
+ strictPeerDeps,
57
+ legacyPeerDeps,
58
+ globalStyle,
59
+ })
60
+
61
+ this.children = []
62
+ this.parent = parent
63
+ this.peerConflict = null
64
+
65
+ this.checks = new Map()
66
+
67
+ this.place()
68
+ }
69
+
70
+ place () {
71
+ const {
72
+ edge,
73
+ dep,
74
+ preferDedupe,
75
+ globalStyle,
76
+ legacyBundling,
77
+ explicitRequest,
78
+ updateNames,
79
+ checks,
80
+ } = this
81
+
82
+ // nothing to do if the edge is fine as it is
83
+ if (edge.to &&
84
+ !edge.error &&
85
+ !explicitRequest &&
86
+ !updateNames.includes(edge.name) &&
87
+ !this.isVulnerable(edge.to))
88
+ return
89
+
90
+ // walk up the tree until we hit either a top/root node, or a place
91
+ // where the dep is not a peer dep.
92
+ const start = this.getStartNode()
93
+
94
+ let canPlace = null
95
+ let canPlaceSelf = null
96
+ for (const target of start.ancestry()) {
97
+ // if the current location has a peerDep on it, then we can't place here
98
+ // this is pretty rare to hit, since we always prefer deduping peers,
99
+ // and the getStartNode will start us out above any peers from the
100
+ // thing that depends on it. but we could hit it with something like:
101
+ //
102
+ // a -> (b@1, c@1)
103
+ // +-- c@1
104
+ // +-- b -> PEEROPTIONAL(v) (c@2)
105
+ // +-- c@2 -> (v)
106
+ //
107
+ // So we check if we can place v under c@2, that's fine.
108
+ // Then we check under b, and can't, because of the optional peer dep.
109
+ // but we CAN place it under a, so the correct thing to do is keep
110
+ // walking up the tree.
111
+ const targetEdge = target.edgesOut.get(edge.name)
112
+ if (!target.isTop && targetEdge && targetEdge.peer)
113
+ continue
114
+
115
+ const cpd = new CanPlaceDep({
116
+ dep,
117
+ edge,
118
+ // note: this sets the parent's canPlace as the parent of this
119
+ // canPlace, but it does NOT add this canPlace to the parent's
120
+ // children. This way, we can know that it's a peer dep, and
121
+ // get the top edge easily, while still maintaining the
122
+ // tree of checks that factored into the original decision.
123
+ parent: this.parent && this.parent.canPlace,
124
+ target,
125
+ preferDedupe,
126
+ explicitRequest: this.explicitRequest,
127
+ })
128
+ checks.set(target, cpd)
129
+
130
+ // It's possible that a "conflict" is a conflict among the *peers* of
131
+ // a given node we're trying to place, but there actually is no current
132
+ // node. Eg,
133
+ // root -> (a, b)
134
+ // a -> PEER(c)
135
+ // b -> PEER(d)
136
+ // d -> PEER(c@2)
137
+ // We place (a), and get a peer of (c) along with it.
138
+ // then we try to place (b), and get CONFLICT in the check, because
139
+ // of the conflicting peer from (b)->(d)->(c@2). In that case, we
140
+ // should treat (b) and (d) as OK, and place them in the last place
141
+ // where they did not themselves conflict, and skip c@2 if conflict
142
+ // is ok by virtue of being forced or not ours and not strict.
143
+ if (cpd.canPlaceSelf !== CONFLICT)
144
+ canPlaceSelf = cpd
145
+
146
+ // we found a place this can go, along with all its peer friends.
147
+ // we break when we get the first conflict
148
+ if (cpd.canPlace !== CONFLICT)
149
+ canPlace = cpd
150
+ else
151
+ break
152
+
153
+ // if it's a load failure, just plop it in the first place attempted,
154
+ // since we're going to crash the build or prune it out anyway.
155
+ // but, this will frequently NOT be a successful canPlace, because
156
+ // it'll have no version or other information.
157
+ if (dep.errors.length)
158
+ break
159
+
160
+ // nest packages like npm v1 and v2
161
+ // very disk-inefficient
162
+ if (legacyBundling)
163
+ break
164
+
165
+ // when installing globally, or just in global style, we never place
166
+ // deps above the first level.
167
+ if (globalStyle) {
168
+ const rp = target.resolveParent
169
+ if (rp && rp.isProjectRoot)
170
+ break
171
+ }
172
+ }
173
+
174
+ Object.assign(this, {
175
+ canPlace,
176
+ canPlaceSelf,
177
+ })
178
+ this.current = edge.to
179
+
180
+ // if we can't find a target, that means that the last place checked,
181
+ // and all the places before it, had a conflict.
182
+ if (!canPlace) {
183
+ // if not forced, or it's our dep, or strictPeerDeps is set, then
184
+ // this is an ERESOLVE error.
185
+ if (!this.conflictOk)
186
+ return this.failPeerConflict()
187
+
188
+ // ok! we're gonna allow the conflict, but we should still warn
189
+ // if we have a current, then we treat CONFLICT as a KEEP.
190
+ // otherwise, we just skip it. Only warn on the one that actually
191
+ // could not be placed somewhere.
192
+ if (!canPlaceSelf) {
193
+ this.warnPeerConflict()
194
+ return
195
+ }
196
+
197
+ this.canPlace = canPlaceSelf
198
+ }
199
+
200
+ // now we have a target, a tree of CanPlaceDep results for the peer group,
201
+ // and we are ready to go
202
+ this.placeInTree()
203
+ }
204
+
205
+ placeInTree () {
206
+ const {
207
+ dep,
208
+ canPlace,
209
+ edge,
210
+ } = this
211
+
212
+ /* istanbul ignore next */
213
+ if (!canPlace) {
214
+ debug(() => {
215
+ throw new Error('canPlace not set, but trying to place in tree')
216
+ })
217
+ return
218
+ }
219
+
220
+ const { target } = canPlace
221
+
222
+ log.silly(
223
+ 'placeDep',
224
+ target.location || 'ROOT',
225
+ `${dep.name}@${dep.version}`,
226
+ canPlace.description,
227
+ `for: ${this.edge.from.package._id || this.edge.from.location}`,
228
+ `want: ${edge.spec || '*'}`
229
+ )
230
+
231
+ const placementType = canPlace.canPlace === CONFLICT
232
+ ? canPlace.canPlaceSelf
233
+ : canPlace.canPlace
234
+
235
+ // if we're placing in the tree with --force, we can get here even though
236
+ // it's a conflict. Treat it as a KEEP, but warn and move on.
237
+ if (placementType === KEEP) {
238
+ // this was an overridden peer dep
239
+ if (edge.peer && !edge.valid)
240
+ this.warnPeerConflict()
241
+
242
+ // if we get a KEEP in a update scenario, then we MAY have something
243
+ // already duplicating this unnecessarily! For example:
244
+ // ```
245
+ // root (dep: y@1)
246
+ // +-- x (dep: y@1.1)
247
+ // | +-- y@1.1.0 (replacing with 1.1.2, got KEEP at the root)
248
+ // +-- y@1.1.2 (updated already from 1.0.0)
249
+ // ```
250
+ // Now say we do `reify({update:['y']})`, and the latest version is
251
+ // 1.1.2, which we now have in the root. We'll try to place y@1.1.2
252
+ // first in x, then in the root, ending with KEEP, because we already
253
+ // have it. In that case, we ought to REMOVE the nm/x/nm/y node, because
254
+ // it is an unnecessary duplicate.
255
+ this.pruneDedupable(target)
256
+ return
257
+ }
258
+
259
+ // XXX if we are replacing SOME of a peer entry group, we will need to
260
+ // remove any that are not being replaced and will now be invalid, and
261
+ // re-evaluate them deeper into the tree.
262
+
263
+ const virtualRoot = dep.parent
264
+ this.placed = new dep.constructor({
265
+ name: dep.name,
266
+ pkg: dep.package,
267
+ resolved: dep.resolved,
268
+ integrity: dep.integrity,
269
+ legacyPeerDeps: this.legacyPeerDeps,
270
+ error: dep.errors[0],
271
+ ...(dep.isLink ? { target: dep.target, realpath: dep.target.path } : {}),
272
+ })
273
+
274
+ this.oldDep = target.children.get(this.name)
275
+ if (this.oldDep)
276
+ this.replaceOldDep()
277
+ else
278
+ this.placed.parent = target
279
+
280
+ // if it's an overridden peer dep, warn about it
281
+ if (edge.peer && !this.placed.satisfies(edge))
282
+ this.warnPeerConflict()
283
+
284
+ // If the edge is not an error, then we're updating something, and
285
+ // MAY end up putting a better/identical node further up the tree in
286
+ // a way that causes an unnecessary duplication. If so, remove the
287
+ // now-unnecessary node.
288
+ if (edge.valid && edge.to && edge.to !== this.placed)
289
+ this.pruneDedupable(edge.to, false)
290
+
291
+ // in case we just made some duplicates that can be removed,
292
+ // prune anything deeper in the tree that can be replaced by this
293
+ for (const node of target.root.inventory.query('name', this.name)) {
294
+ if (node.isDescendantOf(target) && !node.isTop) {
295
+ this.pruneDedupable(node, false)
296
+ // only walk the direct children of the ones we kept
297
+ if (node.root === target.root) {
298
+ for (const kid of node.children.values())
299
+ this.pruneDedupable(kid, false)
300
+ }
301
+ }
302
+ }
303
+
304
+ // also place its unmet or invalid peer deps at this location
305
+ // loop through any peer deps from the thing we just placed, and place
306
+ // those ones as well. it's safe to do this with the virtual nodes,
307
+ // because we're copying rather than moving them out of the virtual root,
308
+ // otherwise they'd be gone and the peer set would change throughout
309
+ // this loop.
310
+ for (const peerEdge of this.placed.edgesOut.values()) {
311
+ if (peerEdge.valid || !peerEdge.peer || peerEdge.overridden)
312
+ continue
313
+
314
+ const peer = virtualRoot.children.get(peerEdge.name)
315
+
316
+ // Note: if the virtualRoot *doesn't* have the peer, then that means
317
+ // it's an optional peer dep. If it's not being properly met (ie,
318
+ // peerEdge.valid is false), then this is likely heading for an
319
+ // ERESOLVE error, unless it can walk further up the tree.
320
+ if (!peer)
321
+ continue
322
+
323
+ // overridden peerEdge, just accept what's there already
324
+ if (!peer.satisfies(peerEdge))
325
+ continue
326
+
327
+ this.children.push(new PlaceDep({
328
+ parent: this,
329
+ dep: peer,
330
+ node: this.placed,
331
+ edge: peerEdge,
332
+ }))
333
+ }
334
+ }
335
+
336
+ replaceOldDep () {
337
+ // XXX handle replacing an entire peer group?
338
+ // what about cases where we need to push some other peer groups deeper
339
+ // into the tree? all the tree updating should be done here, and track
340
+ // all the things that we add and remove, so that we can know what
341
+ // to re-evaluate.
342
+
343
+ // if we're replacing, we should also remove any nodes for edges that
344
+ // are now invalid, and where this (or its deps) is the only dependent,
345
+ // and also recurse on that pruning. Otherwise leaving that dep node
346
+ // around can result in spurious conflicts pushing nodes deeper into
347
+ // the tree than needed in the case of cycles that will be removed
348
+ // later anyway.
349
+ const oldDeps = []
350
+ for (const [name, edge] of this.oldDep.edgesOut.entries()) {
351
+ if (!this.placed.edgesOut.has(name) && edge.to)
352
+ oldDeps.push(...gatherDepSet([edge.to], e => e.to !== edge.to))
353
+ }
354
+ this.placed.replace(this.oldDep)
355
+ this.pruneForReplacement(this.placed, oldDeps)
356
+ }
357
+
358
+ pruneForReplacement (node, oldDeps) {
359
+ // gather up all the now-invalid/extraneous edgesOut, as long as they are
360
+ // only depended upon by the old node/deps
361
+ const invalidDeps = new Set([...node.edgesOut.values()]
362
+ .filter(e => e.to && !e.valid).map(e => e.to))
363
+ for (const dep of oldDeps) {
364
+ const set = gatherDepSet([dep], e => e.to !== dep && e.valid)
365
+ for (const dep of set)
366
+ invalidDeps.add(dep)
367
+ }
368
+
369
+ // ignore dependency edges from the node being replaced, but
370
+ // otherwise filter the set down to just the set with no
371
+ // dependencies from outside the set, except the node in question.
372
+ const deps = gatherDepSet(invalidDeps, edge =>
373
+ edge.from !== node && edge.to !== node && edge.valid)
374
+
375
+ // now just delete whatever's left, because it's junk
376
+ for (const dep of deps)
377
+ dep.root = null
378
+ }
379
+
380
+ // prune all the nodes in a branch of the tree that can be safely removed
381
+ // This is only the most basic duplication detection; it finds if there
382
+ // is another satisfying node further up the tree, and if so, dedupes.
383
+ // Even in legacyBundling mode, we do this amount of deduplication.
384
+ pruneDedupable (node, descend = true) {
385
+ if (node.canDedupe(this.preferDedupe)) {
386
+ // gather up all deps that have no valid edges in from outside
387
+ // the dep set, except for this node we're deduping, so that we
388
+ // also prune deps that would be made extraneous.
389
+ const deps = gatherDepSet([node], e => e.to !== node && e.valid)
390
+ for (const node of deps)
391
+ node.root = null
392
+ return
393
+ }
394
+ if (descend) {
395
+ // sort these so that they're deterministically ordered
396
+ // otherwise, resulting tree shape is dependent on the order
397
+ // in which they happened to be resolved.
398
+ const nodeSort = (a, b) => a.location.localeCompare(b.location, 'en')
399
+
400
+ const children = [...node.children.values()].sort(nodeSort)
401
+ for (const child of children)
402
+ this.pruneDedupable(child)
403
+ const fsChildren = [...node.fsChildren].sort(nodeSort)
404
+ for (const topNode of fsChildren) {
405
+ const children = [...topNode.children.values()].sort(nodeSort)
406
+ for (const child of children)
407
+ this.pruneDedupable(child)
408
+ }
409
+ }
410
+ }
411
+
412
+ get conflictOk () {
413
+ return this.force || (!this.isMine && !this.strictPeerDeps)
414
+ }
415
+
416
+ get isMine () {
417
+ const { edge } = this.top
418
+ const { from: node } = edge
419
+
420
+ if (node.isWorkspace || node.isProjectRoot)
421
+ return true
422
+
423
+ if (!edge.peer)
424
+ return false
425
+
426
+ // re-entry case. check if any non-peer edges come from the project,
427
+ // or any entryEdges on peer groups are from the root.
428
+ let hasPeerEdges = false
429
+ for (const edge of node.edgesIn) {
430
+ if (edge.peer) {
431
+ hasPeerEdges = true
432
+ continue
433
+ }
434
+ if (edge.from.isWorkspace || edge.from.isProjectRoot)
435
+ return true
436
+ }
437
+ if (hasPeerEdges) {
438
+ for (const edge of peerEntrySets(node).keys()) {
439
+ if (edge.from.isWorkspace || edge.from.isProjectRoot)
440
+ return true
441
+ }
442
+ }
443
+
444
+ return false
445
+ }
446
+
447
+ warnPeerConflict () {
448
+ this.edge.overridden = true
449
+ const expl = this.explainPeerConflict()
450
+ log.warn('ERESOLVE', 'overriding peer dependency', expl)
451
+ }
452
+
453
+ failPeerConflict () {
454
+ const expl = this.explainPeerConflict()
455
+ throw Object.assign(new Error('could not resolve'), expl)
456
+ }
457
+
458
+ explainPeerConflict () {
459
+ const { edge, dep } = this.top
460
+ const { from: node } = edge
461
+ const curNode = node.resolve(edge.name)
462
+
463
+ const expl = {
464
+ code: 'ERESOLVE',
465
+ edge: edge.explain(),
466
+ dep: dep.explain(edge),
467
+ }
468
+
469
+ if (this.parent) {
470
+ // this is the conflicted peer
471
+ expl.current = curNode && curNode.explain(edge)
472
+ expl.peerConflict = this.current && this.current.explain(this.edge)
473
+ } else {
474
+ expl.current = curNode && curNode.explain()
475
+ if (this.canPlaceSelf && this.canPlaceSelf.canPlaceSelf !== CONFLICT) {
476
+ // failed while checking for a child dep
477
+ const cps = this.canPlaceSelf
478
+ for (const peer of cps.conflictChildren) {
479
+ if (peer.current) {
480
+ expl.peerConflict = {
481
+ current: peer.current.explain(),
482
+ peer: peer.dep.explain(peer.edge),
483
+ }
484
+ break
485
+ }
486
+ }
487
+ } else {
488
+ expl.peerConflict = {
489
+ current: this.current && this.current.explain(),
490
+ peer: this.dep.explain(this.edge),
491
+ }
492
+ }
493
+ }
494
+
495
+ const {
496
+ strictPeerDeps,
497
+ force,
498
+ isMine,
499
+ } = this
500
+ Object.assign(expl, {
501
+ strictPeerDeps,
502
+ force,
503
+ isMine,
504
+ })
505
+
506
+ // XXX decorate more with this.canPlace and this.canPlaceSelf,
507
+ // this.checks, this.children, walk over conflicted peers, etc.
508
+ return expl
509
+ }
510
+
511
+ getStartNode () {
512
+ // if we are a peer, then we MUST be at least as shallow as the
513
+ // peer dependent
514
+ const from = this.parent ? this.parent.getStartNode() : this.edge.from
515
+ return deepestNestingTarget(from, this.name)
516
+ }
517
+
518
+ get top () {
519
+ return this.parent ? this.parent.top : this
520
+ }
521
+
522
+ isVulnerable (node) {
523
+ return this.auditReport && this.auditReport.isVulnerable(node)
524
+ }
525
+
526
+ get allChildren () {
527
+ const set = new Set(this.children)
528
+ for (const child of set) {
529
+ for (const grandchild of child.children)
530
+ set.add(grandchild)
531
+ }
532
+ return [...set]
533
+ }
534
+ }
535
+
536
+ module.exports = PlaceDep