Skip to content

Commit bd96ae4

Browse files
nlflukekarrys
authored andcommitted
fix(arborist): identify and repair invalid nodes in the virtual tree
1 parent 18b8b94 commit bd96ae4

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

workspaces/arborist/lib/arborist/build-ideal-tree.js

+15
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,21 @@ Try using the package name instead, e.g:
355355
})
356356

357357
.then(tree => {
358+
// search the virtual tree for invalid edges, if any are found add their source to
359+
// the depsQueue so that we'll fix it later
360+
depth({
361+
tree,
362+
getChildren: (node) => [...node.edgesOut.values()].map(edge => edge.to),
363+
filter: node => node,
364+
visit: node => {
365+
for (const edge of node.edgesOut.values()) {
366+
if (!edge.valid) {
367+
this[_depsQueue].push(node)
368+
break // no need to continue the loop after the first hit
369+
}
370+
}
371+
},
372+
})
358373
// null the virtual tree, because we're about to hack away at it
359374
// if you want another one, load another copy.
360375
this.idealTree = tree

workspaces/arborist/tap-snapshots/test/arborist/build-ideal-tree.js.test.cjs

+9-12
Original file line numberDiff line numberDiff line change
@@ -121566,7 +121566,7 @@ ArboristNode {
121566121566
}
121567121567
`
121568121568

121569-
exports[`test/arborist/build-ideal-tree.js TAP update global > update a single dep 1`] = `
121569+
exports[`test/arborist/build-ideal-tree.js TAP update global > update a single dep, also fixes the invalid node 1`] = `
121570121570
ArboristNode {
121571121571
"children": Map {
121572121572
"@isaacs/testing-dev-optional-flags" => ArboristNode {
@@ -121588,7 +121588,6 @@ ArboristNode {
121588121588
"wrappy" => ArboristNode {
121589121589
"edgesIn": Set {
121590121590
EdgeIn {
121591-
"error": "INVALID",
121592121591
"from": "node_modules/@isaacs/testing-dev-optional-flags",
121593121592
"name": "wrappy",
121594121593
"spec": "^1.0.2",
@@ -121598,7 +121597,8 @@ ArboristNode {
121598121597
"location": "node_modules/@isaacs/testing-dev-optional-flags/node_modules/wrappy",
121599121598
"name": "wrappy",
121600121599
"path": "{CWD}/test/arborist/tap-testdir-build-ideal-tree-update-global/node_modules/@isaacs/testing-dev-optional-flags/node_modules/wrappy",
121601-
"version": "1.0.0",
121600+
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
121601+
"version": "1.0.2",
121602121602
},
121603121603
},
121604121604
"edgesIn": Set {
@@ -121617,7 +121617,6 @@ ArboristNode {
121617121617
"type": "prod",
121618121618
},
121619121619
"wrappy" => EdgeOut {
121620-
"error": "INVALID",
121621121620
"name": "wrappy",
121622121621
"spec": "^1.0.2",
121623121622
"to": "node_modules/@isaacs/testing-dev-optional-flags/node_modules/wrappy",
@@ -121818,7 +121817,7 @@ ArboristNode {
121818121817
}
121819121818
`
121820121819

121821-
exports[`test/arborist/build-ideal-tree.js TAP update global > updating missing dep should have no effect 1`] = `
121820+
exports[`test/arborist/build-ideal-tree.js TAP update global > updating missing dep should have no effect, but fix the invalid node 1`] = `
121822121821
ArboristNode {
121823121822
"children": Map {
121824121823
"@isaacs/testing-dev-optional-flags" => ArboristNode {
@@ -121840,7 +121839,6 @@ ArboristNode {
121840121839
"wrappy" => ArboristNode {
121841121840
"edgesIn": Set {
121842121841
EdgeIn {
121843-
"error": "INVALID",
121844121842
"from": "node_modules/@isaacs/testing-dev-optional-flags",
121845121843
"name": "wrappy",
121846121844
"spec": "^1.0.2",
@@ -121850,7 +121848,8 @@ ArboristNode {
121850121848
"location": "node_modules/@isaacs/testing-dev-optional-flags/node_modules/wrappy",
121851121849
"name": "wrappy",
121852121850
"path": "{CWD}/test/arborist/tap-testdir-build-ideal-tree-update-global/node_modules/@isaacs/testing-dev-optional-flags/node_modules/wrappy",
121853-
"version": "1.0.0",
121851+
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
121852+
"version": "1.0.2",
121854121853
},
121855121854
},
121856121855
"edgesIn": Set {
@@ -121869,7 +121868,6 @@ ArboristNode {
121869121868
"type": "prod",
121870121869
},
121871121870
"wrappy" => EdgeOut {
121872-
"error": "INVALID",
121873121871
"name": "wrappy",
121874121872
"spec": "^1.0.2",
121875121873
"to": "node_modules/@isaacs/testing-dev-optional-flags/node_modules/wrappy",
@@ -121941,7 +121939,7 @@ ArboristNode {
121941121939
}
121942121940
`
121943121941

121944-
exports[`test/arborist/build-ideal-tree.js TAP update global > updating sub-dep has no effect 1`] = `
121942+
exports[`test/arborist/build-ideal-tree.js TAP update global > updating sub-dep has no effect, but fixes the invalid node 1`] = `
121945121943
ArboristNode {
121946121944
"children": Map {
121947121945
"@isaacs/testing-dev-optional-flags" => ArboristNode {
@@ -121963,7 +121961,6 @@ ArboristNode {
121963121961
"wrappy" => ArboristNode {
121964121962
"edgesIn": Set {
121965121963
EdgeIn {
121966-
"error": "INVALID",
121967121964
"from": "node_modules/@isaacs/testing-dev-optional-flags",
121968121965
"name": "wrappy",
121969121966
"spec": "^1.0.2",
@@ -121973,7 +121970,8 @@ ArboristNode {
121973121970
"location": "node_modules/@isaacs/testing-dev-optional-flags/node_modules/wrappy",
121974121971
"name": "wrappy",
121975121972
"path": "{CWD}/test/arborist/tap-testdir-build-ideal-tree-update-global/node_modules/@isaacs/testing-dev-optional-flags/node_modules/wrappy",
121976-
"version": "1.0.0",
121973+
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
121974+
"version": "1.0.2",
121977121975
},
121978121976
},
121979121977
"edgesIn": Set {
@@ -121992,7 +121990,6 @@ ArboristNode {
121992121990
"type": "prod",
121993121991
},
121994121992
"wrappy" => EdgeOut {
121995-
"error": "INVALID",
121996121993
"name": "wrappy",
121997121994
"spec": "^1.0.2",
121998121995
"to": "node_modules/@isaacs/testing-dev-optional-flags/node_modules/wrappy",

workspaces/arborist/test/arborist/build-ideal-tree.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -2213,10 +2213,10 @@ t.test('update global', async t => {
22132213
})
22142214

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

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

22212221
const invalidArgs = [
22222222
@@ -2234,7 +2234,7 @@ t.test('update global', async t => {
22342234
}
22352235

22362236
t.matchSnapshot(await printIdeal(path, { global: true, update: ['once'] }),
2237-
'update a single dep')
2237+
'update a single dep, also fixes the invalid node')
22382238
t.matchSnapshot(await printIdeal(path, { global: true, update: true }),
22392239
'update all the deps')
22402240
})

0 commit comments

Comments
 (0)