From a9007b4df40a8730962596cc414e8eaeb0315825 Mon Sep 17 00:00:00 2001 From: Jeff Widman Date: Tue, 10 Nov 2026 15:24:24 -0800 Subject: [PATCH] refactor(arborist): make getBundler traversal Set-only Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- workspaces/arborist/lib/node.js | 9 ++------- workspaces/arborist/test/node.js | 26 -------------------------- 2 files changed, 2 insertions(+), 33 deletions(-) diff --git a/workspaces/arborist/lib/node.js b/workspaces/arborist/lib/node.js index f913376a1b7d2..2f289fb601333 100644 --- a/workspaces/arborist/lib/node.js +++ b/workspaces/arborist/lib/node.js @@ -524,17 +524,12 @@ class Node { } getBundler (seen = new Set()) { - const isArray = Array.isArray(seen) // made a cycle, definitely not bundled! - if (isArray ? seen.includes(this) : seen.has(this)) { + if (seen.has(this)) { return null } - if (isArray) { - seen.push(this) - } else { - seen.add(this) - } + seen.add(this) const parent = this[_parent] if (!parent) { diff --git a/workspaces/arborist/test/node.js b/workspaces/arborist/test/node.js index 004543b731aa3..919dc2905373e 100644 --- a/workspaces/arborist/test/node.js +++ b/workspaces/arborist/test/node.js @@ -838,32 +838,6 @@ t.test('bundled dependencies logic', t => { t.end() }) -t.test('getBundler preserves explicit array traversal state', t => { - const root = new Node({ - path: '/path/to/root', - pkg: { - name: 'root', - dependencies: { a: '*' }, - bundleDependencies: ['a'], - }, - }) - const a = new Node({ - parent: root, - pkg: { name: 'a', version: '1.0.0' }, - }) - const visited = [] - t.equal(a.getBundler(visited), root) - t.same(visited, [a, root], 'populates the caller-provided array') - t.equal(a.getBundler(visited), null, 'honors nodes already visited') - t.same(visited, [a, root], 'does not append already visited nodes') - t.equal(a.getBundler(), root, 'default calls have independent traversal state') - - const duplicates = [root, root] - t.equal(a.getBundler(duplicates), root) - t.same(duplicates, [root, root, a], 'preserves existing array contents and order') - t.end() -}) - t.test('move fsChildren when moving to a new fsParent in same root', t => { const root = new Node({ path: '/path/to/root',