diff --git a/workspaces/arborist/lib/arborist/build-ideal-tree.js b/workspaces/arborist/lib/arborist/build-ideal-tree.js index 535a6ab7d6ad9..f3166c37e1475 100644 --- a/workspaces/arborist/lib/arborist/build-ideal-tree.js +++ b/workspaces/arborist/lib/arborist/build-ideal-tree.js @@ -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 diff --git a/workspaces/arborist/tap-snapshots/test/arborist/build-ideal-tree.js.test.cjs b/workspaces/arborist/tap-snapshots/test/arborist/build-ideal-tree.js.test.cjs index 17aee505ce4bb..1b1e2d55da5de 100644 --- a/workspaces/arborist/tap-snapshots/test/arborist/build-ideal-tree.js.test.cjs +++ b/workspaces/arborist/tap-snapshots/test/arborist/build-ideal-tree.js.test.cjs @@ -121566,7 +121566,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 { @@ -121588,7 +121588,6 @@ ArboristNode { "wrappy" => ArboristNode { "edgesIn": Set { EdgeIn { - "error": "INVALID", "from": "node_modules/@isaacs/testing-dev-optional-flags", "name": "wrappy", "spec": "^1.0.2", @@ -121598,7 +121597,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 { @@ -121617,7 +121617,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", @@ -121818,7 +121817,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 { @@ -121840,7 +121839,6 @@ ArboristNode { "wrappy" => ArboristNode { "edgesIn": Set { EdgeIn { - "error": "INVALID", "from": "node_modules/@isaacs/testing-dev-optional-flags", "name": "wrappy", "spec": "^1.0.2", @@ -121850,7 +121848,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 { @@ -121869,7 +121868,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", @@ -121941,7 +121939,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 { @@ -121963,7 +121961,6 @@ ArboristNode { "wrappy" => ArboristNode { "edgesIn": Set { EdgeIn { - "error": "INVALID", "from": "node_modules/@isaacs/testing-dev-optional-flags", "name": "wrappy", "spec": "^1.0.2", @@ -121973,7 +121970,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 { @@ -121992,7 +121990,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", diff --git a/workspaces/arborist/test/arborist/build-ideal-tree.js b/workspaces/arborist/test/arborist/build-ideal-tree.js index d869c686ef50f..0aadd7adf815f 100644 --- a/workspaces/arborist/test/arborist/build-ideal-tree.js +++ b/workspaces/arborist/test/arborist/build-ideal-tree.js @@ -2213,10 +2213,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', @@ -2234,7 +2234,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') })