Skip to content
Merged
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
15 changes: 11 additions & 4 deletions workspaces/arborist/lib/calc-dep-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ const calcDepFlagsStep = (node) => {

// for links, map their hierarchy appropriately
if (node.isLink) {
// node.target can be null, we check to ensure it's not null before proceeding
if (node.target == null) {
return node
}
node.target.dev = node.dev
node.target.optional = node.optional
node.target.devOptional = node.devOptional
Expand Down Expand Up @@ -97,15 +101,18 @@ const unsetFlag = (node, flag) => {
tree: node,
visit: node => {
node.extraneous = node[flag] = false
if (node.isLink) {
if (node.isLink && node.target) {
node.target.extraneous = node.target[flag] = false
}
},
getChildren: node => {
const children = []
for (const edge of node.target.edgesOut.values()) {
if (edge.to && edge.to[flag] &&
(flag !== 'peer' && edge.type === 'peer' || edge.type === 'prod')
const targetNode = node.isLink && node.target ? node.target : node
for (const edge of targetNode.edgesOut.values()) {
if (
edge.to &&
edge.to[flag] &&
((flag !== 'peer' && edge.type === 'peer') || edge.type === 'prod')
) {
children.push(edge.to)
}
Expand Down
13 changes: 13 additions & 0 deletions workspaces/arborist/test/calc-dep-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,16 @@ t.test('set parents to not extraneous when visiting', t => {
t.equal(bazLink.devOptional, false, 'bazlink not devOptional')
t.end()
})

t.test('check null target in link', async t => {
const root = new Link({
path: '/some/path',
realpath: '/some/path',
pkg: {
dependencies: { foo: '' },
},
})
t.doesNotThrow(() => calcDepFlags(root))
t.doesNotThrow(() => calcDepFlags(root, false))
t.end()
})