Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(arborist): identify and repair invalid nodes in the virtual tree #4599

Merged
merged 2 commits into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 15 additions & 0 deletions workspaces/arborist/lib/arborist/build-ideal-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,21 @@ Try using the package name instead, e.g:
})

.then(tree => {
// search the virtual tree for invalid edges, if any are found add their source to
// the depsQueue so that we'll fix it later
depth({
tree,
getChildren: (node) => [...node.edgesOut.values()].map(edge => edge.to),
filter: node => node,
visit: node => {
for (const edge of node.edgesOut.values()) {
if (!edge.valid) {
this[_depsQueue].push(node)
break // no need to continue the loop after the first hit
}
}
},
})
// null the virtual tree, because we're about to hack away at it
// if you want another one, load another copy.
this.idealTree = tree
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121519,7 +121519,7 @@ ArboristNode {
}
`

exports[`test/arborist/build-ideal-tree.js TAP update global > update a single dep 1`] = `
exports[`test/arborist/build-ideal-tree.js TAP update global > update a single dep, also fixes the invalid node 1`] = `
ArboristNode {
"children": Map {
"@isaacs/testing-dev-optional-flags" => ArboristNode {
Expand All @@ -121541,7 +121541,6 @@ ArboristNode {
"wrappy" => ArboristNode {
"edgesIn": Set {
EdgeIn {
"error": "INVALID",
"from": "node_modules/@isaacs/testing-dev-optional-flags",
"name": "wrappy",
"spec": "^1.0.2",
Expand All @@ -121551,7 +121550,8 @@ ArboristNode {
"location": "node_modules/@isaacs/testing-dev-optional-flags/node_modules/wrappy",
"name": "wrappy",
"path": "{CWD}/test/arborist/tap-testdir-build-ideal-tree-update-global/node_modules/@isaacs/testing-dev-optional-flags/node_modules/wrappy",
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"version": "1.0.2",
},
},
"edgesIn": Set {
Expand All @@ -121570,7 +121570,6 @@ ArboristNode {
"type": "prod",
},
"wrappy" => EdgeOut {
"error": "INVALID",
"name": "wrappy",
"spec": "^1.0.2",
"to": "node_modules/@isaacs/testing-dev-optional-flags/node_modules/wrappy",
Expand Down Expand Up @@ -121771,7 +121770,7 @@ ArboristNode {
}
`

exports[`test/arborist/build-ideal-tree.js TAP update global > updating missing dep should have no effect 1`] = `
exports[`test/arborist/build-ideal-tree.js TAP update global > updating missing dep should have no effect, but fix the invalid node 1`] = `
ArboristNode {
"children": Map {
"@isaacs/testing-dev-optional-flags" => ArboristNode {
Expand All @@ -121793,7 +121792,6 @@ ArboristNode {
"wrappy" => ArboristNode {
"edgesIn": Set {
EdgeIn {
"error": "INVALID",
"from": "node_modules/@isaacs/testing-dev-optional-flags",
"name": "wrappy",
"spec": "^1.0.2",
Expand All @@ -121803,7 +121801,8 @@ ArboristNode {
"location": "node_modules/@isaacs/testing-dev-optional-flags/node_modules/wrappy",
"name": "wrappy",
"path": "{CWD}/test/arborist/tap-testdir-build-ideal-tree-update-global/node_modules/@isaacs/testing-dev-optional-flags/node_modules/wrappy",
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"version": "1.0.2",
},
},
"edgesIn": Set {
Expand All @@ -121822,7 +121821,6 @@ ArboristNode {
"type": "prod",
},
"wrappy" => EdgeOut {
"error": "INVALID",
"name": "wrappy",
"spec": "^1.0.2",
"to": "node_modules/@isaacs/testing-dev-optional-flags/node_modules/wrappy",
Expand Down Expand Up @@ -121894,7 +121892,7 @@ ArboristNode {
}
`

exports[`test/arborist/build-ideal-tree.js TAP update global > updating sub-dep has no effect 1`] = `
exports[`test/arborist/build-ideal-tree.js TAP update global > updating sub-dep has no effect, but fixes the invalid node 1`] = `
ArboristNode {
"children": Map {
"@isaacs/testing-dev-optional-flags" => ArboristNode {
Expand All @@ -121916,7 +121914,6 @@ ArboristNode {
"wrappy" => ArboristNode {
"edgesIn": Set {
EdgeIn {
"error": "INVALID",
"from": "node_modules/@isaacs/testing-dev-optional-flags",
"name": "wrappy",
"spec": "^1.0.2",
Expand All @@ -121926,7 +121923,8 @@ ArboristNode {
"location": "node_modules/@isaacs/testing-dev-optional-flags/node_modules/wrappy",
"name": "wrappy",
"path": "{CWD}/test/arborist/tap-testdir-build-ideal-tree-update-global/node_modules/@isaacs/testing-dev-optional-flags/node_modules/wrappy",
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"version": "1.0.2",
},
},
"edgesIn": Set {
Expand All @@ -121945,7 +121943,6 @@ ArboristNode {
"type": "prod",
},
"wrappy" => EdgeOut {
"error": "INVALID",
"name": "wrappy",
"spec": "^1.0.2",
"to": "node_modules/@isaacs/testing-dev-optional-flags/node_modules/wrappy",
Expand Down
6 changes: 3 additions & 3 deletions workspaces/arborist/test/arborist/build-ideal-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -2193,10 +2193,10 @@ t.test('update global', async t => {
})

t.matchSnapshot(await printIdeal(path, { global: true, update: ['abbrev'] }),
'updating missing dep should have no effect')
'updating missing dep should have no effect, but fix the invalid node')

t.matchSnapshot(await printIdeal(path, { global: true, update: ['wrappy'] }),
'updating sub-dep has no effect')
'updating sub-dep has no effect, but fixes the invalid node')

const invalidArgs = [
'once@1.4.0',
Expand All @@ -2214,7 +2214,7 @@ t.test('update global', async t => {
}

t.matchSnapshot(await printIdeal(path, { global: true, update: ['once'] }),
'update a single dep')
'update a single dep, also fixes the invalid node')
t.matchSnapshot(await printIdeal(path, { global: true, update: true }),
'update all the deps')
})
Expand Down