Skip to content

Commit 105a86c

Browse files
committed
fix: optional set calc
1 parent 5f18557 commit 105a86c

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

workspaces/arborist/lib/optional-set.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,8 @@ const optionalSet = node => {
2929
}
3030

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

3836
module.exports = optionalSet

workspaces/arborist/test/optional-set.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ tree (PROD a, PROD c, OPT i)
99
+-- a (OPT o)
1010
+-- b (PROD c)
1111
+-- c (OPT b)
12-
+-- o (PROD m)
13-
+-- m (PROD n)
12+
+-- o (PROD m, OPT i)
13+
+-- m (OPT n)
1414
+-- n ()
1515
+-- OPT i (PROD j)
1616
+-- j ()
@@ -38,8 +38,8 @@ const tree = new Node({
3838
['a', [], ['o']],
3939
['b', ['c'], []],
4040
['c', [], ['b']],
41-
['o', ['m'], []],
42-
['m', ['n'], []],
41+
['o', ['m'], ['i']],
42+
['m', [], ['n']],
4343
['n', [], []],
4444
['i', ['j'], []],
4545
['j', [], []],
@@ -83,12 +83,6 @@ t.equal(setO.has(nodeO), true, 'set o includes o')
8383
t.equal(setO.has(nodeM), true, 'set o includes m')
8484
t.equal(setO.has(nodeN), true, 'set o includes n')
8585

86-
const setN = optionalSet(nodeO)
87-
t.equal(setN.size, 3, 'three nodes in n set')
88-
t.equal(setN.has(nodeO), true, 'set n includes o')
89-
t.equal(setN.has(nodeM), true, 'set n includes m')
90-
t.equal(setN.has(nodeN), true, 'set n includes n')
91-
9286
const setB = optionalSet(nodeB)
9387
t.equal(setB.size, 1, 'gathering from b is only b')
9488
t.equal(setB.has(nodeB), true, 'set b includes b')

0 commit comments

Comments
 (0)