Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions workspaces/arborist/lib/optional-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ const optionalSet = node => {
}

// now that we've hit the boundary, gather the rest of the nodes in
// the optional section. that's the set of dependencies that are only
// depended upon by other nodes within the set, or optional dependencies
// from outside the set.
return gatherDepSet(set, edge => !edge.optional)
// the optional section that don't have dependents outside the set.
return gatherDepSet(set, edge => !set.has(edge.to))
}

module.exports = optionalSet
25 changes: 13 additions & 12 deletions workspaces/arborist/test/optional-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@ tree (PROD a, PROD c, OPT i)
+-- a (OPT o)
+-- b (PROD c)
+-- c (OPT b)
+-- o (PROD m)
+-- m (PROD n)
+-- o (PROD m, OPT i)
+-- m (OPT n)
+-- n ()
+-- OPT i (PROD j)
+-- j ()

Gathering the optional set from:
j: [i],
j: [j, i],
a: [],
o: [m, n],
b: []
o: [o, m, n],
m: [o, m, n],
b: [b],
*/

const tree = new Node({
Expand All @@ -38,8 +39,8 @@ const tree = new Node({
['a', [], ['o']],
['b', ['c'], []],
['c', [], ['b']],
['o', ['m'], []],
['m', ['n'], []],
['o', ['m'], ['i']],
['m', [], ['n']],
['n', [], []],
['i', ['j'], []],
['j', [], []],
Expand Down Expand Up @@ -83,11 +84,11 @@ t.equal(setO.has(nodeO), true, 'set o includes o')
t.equal(setO.has(nodeM), true, 'set o includes m')
t.equal(setO.has(nodeN), true, 'set o includes n')

const setN = optionalSet(nodeO)
t.equal(setN.size, 3, 'three nodes in n set')
t.equal(setN.has(nodeO), true, 'set n includes o')
t.equal(setN.has(nodeM), true, 'set n includes m')
t.equal(setN.has(nodeN), true, 'set n includes n')
const setM = optionalSet(nodeM)
t.equal(setM.size, 3, 'three nodes in m set')
t.equal(setM.has(nodeO), true, 'set m includes o')
t.equal(setM.has(nodeM), true, 'set m includes m')
t.equal(setM.has(nodeN), true, 'set m includes n')

const setB = optionalSet(nodeB)
t.equal(setB.size, 1, 'gathering from b is only b')
Expand Down
Loading