diff --git a/lib/arborist/build-ideal-tree.js b/lib/arborist/build-ideal-tree.js index 9328b8043..decdf1cec 100644 --- a/lib/arborist/build-ideal-tree.js +++ b/lib/arborist/build-ideal-tree.js @@ -1148,6 +1148,7 @@ This is a one-time fix-up, please be patient... [_placeDep] (dep, node, edge, peerEntryEdge = null, peerPath = []) { if (edge.to && !edge.error && + !this[_explicitRequests].has(edge.name) && !this[_updateNames].includes(edge.name) && !this[_isVulnerable](edge.to)) return [] diff --git a/tap-snapshots/test-arborist-build-ideal-tree.js-TAP.test.js b/tap-snapshots/test-arborist-build-ideal-tree.js-TAP.test.js index d419032bc..8b7f78835 100644 --- a/tap-snapshots/test-arborist-build-ideal-tree.js-TAP.test.js +++ b/tap-snapshots/test-arborist-build-ideal-tree.js-TAP.test.js @@ -12875,6 +12875,40 @@ ArboristNode { } ` +exports[`test/arborist/build-ideal-tree.js TAP existing dep that needs to be reinstalled > must match snapshot 1`] = ` +ArboristNode { + "children": Map { + "lodash" => ArboristNode { + "dev": true, + "edgesIn": Set { + EdgeIn { + "from": "", + "name": "lodash", + "spec": "^3.9.1", + "type": "dev", + }, + }, + "location": "node_modules/lodash", + "name": "lodash", + "path": "{CWD}/test/arborist/build-ideal-tree-existing-dep-that-needs-to-be-reinstalled/node_modules/lodash", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-3.10.1.tgz", + "version": "3.10.1", + }, + }, + "edgesOut": Map { + "lodash" => EdgeOut { + "name": "lodash", + "spec": "^3.9.1", + "to": "node_modules/lodash", + "type": "dev", + }, + }, + "location": "", + "name": "build-ideal-tree-existing-dep-that-needs-to-be-reinstalled", + "path": "{CWD}/test/arborist/build-ideal-tree-existing-dep-that-needs-to-be-reinstalled", +} +` + exports[`test/arborist/build-ideal-tree.js TAP force a new mkdirp (but not semver major) > must match snapshot 1`] = ` ArboristNode { "children": Map { diff --git a/test/arborist/build-ideal-tree.js b/test/arborist/build-ideal-tree.js index b2c716d9c..951ec274c 100644 --- a/test/arborist/build-ideal-tree.js +++ b/test/arborist/build-ideal-tree.js @@ -2324,3 +2324,22 @@ t.test('do not fail if root peerDep looser than meta peerDep', async t => { const path = resolve(fixtures, 'test-peer-looser-than-dev') t.matchSnapshot(await printIdeal(path)) }) + +t.test('adding existing dep with updateable version in package.json', async t => { + const path = t.testdir({ + node_modules: { + lodash: { + 'package.json': JSON.stringify({ + version: '3.9.1' + }) + } + }, + 'package.json': JSON.stringify({ + devDependencies: { + lodash: '^3.9.1' + }, + }) + }) + + t.matchSnapshot(await printIdeal(path, { add: ['lodash'] })) +})