Skip to content
This repository has been archived by the owner on Jan 20, 2022. It is now read-only.

Commit

Permalink
fix(install): make sure to reload explicitRequests
Browse files Browse the repository at this point in the history
when we are placing our deps, if our edge dep was explicitly requested,
we want to re-place it instead of leaving whatever was there before.

This will mean doing something like `npm install foo` will install the
latest version of `foo` that your tree currently allows, instead of
doing nothing if any version already existed
  • Loading branch information
wraithgar committed Jan 29, 2021
1 parent 3bf786c commit 66c01f3
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/arborist/build-ideal-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 []
Expand Down
34 changes: 34 additions & 0 deletions tap-snapshots/test-arborist-build-ideal-tree.js-TAP.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
19 changes: 19 additions & 0 deletions test/arborist/build-ideal-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'] }))
})

0 comments on commit 66c01f3

Please sign in to comment.