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
3 changes: 2 additions & 1 deletion workspaces/arborist/lib/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,8 @@ class Node {

// if they're links, they match if the targets match
if (this.isLink) {
return node.isLink && this.target.matches(node.target)
return node.isLink && !!this.target && !!node.target &&
this.target.matches(node.target)
}

// if they're two project root nodes, they're different if the paths differ
Expand Down
13 changes: 13 additions & 0 deletions workspaces/arborist/test/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -1449,6 +1449,19 @@ t.test('detect that two nodes are the same thing', async t => {
check(a, b, true, 'links match if targets match')
}

{
const root = new Node({ path: '/root', pkg: { name: 'root', version: '1.0.0' } })
const target = new Node({ root, path: '/root/packages/x', pkg: { name: 'x', version: '1.2.3' } })
const a = new Link({ root, parent: root, name: 'x', target })
const b = new Node({ root, parent: root, name: 'b', pkg: { name: 'b', version: '1.0.0' } })
// Nested link to the same target
const bx = new Link({ root, parent: b, name: 'x', target })
target.root = new Node({ path: '/other-root' })
t.equal(a.target, null, 'target was cleared')
t.equal(bx.target, null, 'nested link target was cleared')
check(a, bx, false, 'links with cleared targets do not match')
}

{
const a = new Node({ path: '/foo', pkg: { name: 'x', version: '1.2.3' } })
const b = new Node({ path: '/foo', pkg: { name: 'x', version: '1.2.3' } })
Expand Down