Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
optional-set.js33 linesDownload Raw Back to lib
1// when an optional dep fails to install, we need to remove the branch of the
2// graph up to the first optionalDependencies, as well as any nodes that are
3// only required by other nodes in the set.
4//
5// This function finds the set of nodes that will need to be removed in that
6// case.
7//
8// Note that this is *only* going to work with trees where calcDepFlags
9// has been called, because we rely on the node.optional flag.
10
11const gatherDepSet = require('./gather-dep-set.js')
12const optionalSet = node => {
13  // start with the node, then walk up the dependency graph until we
14  // get to the boundaries that define the optional set.  since the
15  // node is optional, we know that all paths INTO this area of the
16  // graph are optional, but there may be non-optional dependencies
17  // WITHIN the area.
18  const set = new Set([node])
19  for (const node of set) {
20    for (const edge of node.edgesIn) {
21      if (!edge.optional) {
22        set.add(edge.from)
23      }
24    }
25  }
26
27  // now that we've hit the boundary, gather the rest of the nodes in
28  // the optional section that don't have dependents outside the set.
29  return gatherDepSet(set, edge => !set.has(edge.to))
30}
31
32module.exports = optionalSet
33 
codekingpro/portable-devtools · Team Ai