From 245300ad92c3debbf4c79c702c52809ffff1f943 Mon Sep 17 00:00:00 2001 From: Liam Mitchell Date: Thu, 28 Aug 2025 13:58:50 +0200 Subject: [PATCH] fix: optional set calc --- workspaces/arborist/lib/optional-set.js | 6 ++---- workspaces/arborist/test/optional-set.js | 25 ++++++++++++------------ 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/workspaces/arborist/lib/optional-set.js b/workspaces/arborist/lib/optional-set.js index 9f5184ea02442..76d557c0e52c5 100644 --- a/workspaces/arborist/lib/optional-set.js +++ b/workspaces/arborist/lib/optional-set.js @@ -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 diff --git a/workspaces/arborist/test/optional-set.js b/workspaces/arborist/test/optional-set.js index e639ea1450ef6..f28564554a71b 100644 --- a/workspaces/arborist/test/optional-set.js +++ b/workspaces/arborist/test/optional-set.js @@ -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({ @@ -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', [], []], @@ -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')