Skip to content

Commit 13d8df6

Browse files
fix: optional set calculation (#8537)
1 parent 7fbe07a commit 13d8df6

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
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: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,18 @@ 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 ()
1717
1818
Gathering the optional set from:
19-
j: [i],
19+
j: [j, i],
2020
a: [],
21-
o: [m, n],
22-
b: []
21+
o: [o, m, n],
22+
m: [o, m, n],
23+
b: [b],
2324
*/
2425

2526
const tree = new Node({
@@ -38,8 +39,8 @@ const tree = new Node({
3839
['a', [], ['o']],
3940
['b', ['c'], []],
4041
['c', [], ['b']],
41-
['o', ['m'], []],
42-
['m', ['n'], []],
42+
['o', ['m'], ['i']],
43+
['m', [], ['n']],
4344
['n', [], []],
4445
['i', ['j'], []],
4546
['j', [], []],
@@ -83,11 +84,11 @@ t.equal(setO.has(nodeO), true, 'set o includes o')
8384
t.equal(setO.has(nodeM), true, 'set o includes m')
8485
t.equal(setO.has(nodeN), true, 'set o includes n')
8586

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')
87+
const setM = optionalSet(nodeM)
88+
t.equal(setM.size, 3, 'three nodes in m set')
89+
t.equal(setM.has(nodeO), true, 'set m includes o')
90+
t.equal(setM.has(nodeM), true, 'set m includes m')
91+
t.equal(setM.has(nodeN), true, 'set m includes n')
9192

9293
const setB = optionalSet(nodeB)
9394
t.equal(setB.size, 1, 'gathering from b is only b')

0 commit comments

Comments
 (0)