Skip to content
Open
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
4 changes: 4 additions & 0 deletions workspaces/arborist/lib/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -1505,6 +1505,10 @@ class Node {
}

[_reloadNamedEdges] (name, rootLoc = this.location) {
if (!this.edgesOut.size && !this.children.size && !this.fsChildren.size) {
return
}

const edge = this.edgesOut.get(name)
// if we don't have an edge, do nothing, but keep descending
const rootLocResolved = edge && edge.to &&
Expand Down
40 changes: 40 additions & 0 deletions workspaces/arborist/test/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -1332,6 +1332,46 @@ t.test('reparenting keeps children in root inventory', async t => {
t.equal(root.inventory.has(fsNested), true)
})

t.test('reloading named edges skips empty leaves without caching their state', t => {
const root = new Node({ path: '/some/path' })
const leaf = new Node({ parent: root, pkg: { name: 'leaf' } })
const lookups = []
const get = leaf.edgesOut.get
leaf.edgesOut.get = function (name) {
lookups.push(name)
return get.call(this, name)
}

const foo = new Node({ parent: root, pkg: { name: 'foo', version: '1.0.0' } })
t.same(lookups, [], 'no lookup in an empty leaf during the refresh')
delete leaf.edgesOut.get

leaf.package = { name: 'leaf', dependencies: { foo: '1' } }
t.equal(leaf.edgesOut.get('foo').to, foo)
foo.parent = null
t.equal(leaf.edgesOut.get('foo').to, null, 'the newly added edge still refreshes')
t.end()
})

t.test('reloading traverses dependency-free parents with children', t => {
for (const kind of ['parent', 'fsParent']) {
const root = new Node({ path: '/some/path' })
const parent = new Node({ parent: root, pkg: { name: 'parent' } })
const child = new Node({
[kind]: parent,
path: kind === 'fsParent' ? `${parent.path}/child` : undefined,
pkg: { name: 'child', dependencies: { foo: '1' } },
})
t.equal(parent.edgesOut.size, 0)
t.equal(child.edgesOut.get('foo').to, null)
const foo = new Node({ parent: root, pkg: { name: 'foo', version: '1.0.0' } })
t.equal(child.edgesOut.get('foo').to, foo, `${kind} descendants are refreshed`)
foo.parent = null
t.equal(child.edgesOut.get('foo').to, null, `${kind} descendants track removals`)
}
t.end()
})

t.test('reloading named edges should refresh edgesIn', t => {
// pathological dep nesting scenario:
//
Expand Down
Loading