Skip to content

Commit

Permalink
install/deps: Compute required package in legacy npm compatible way (…
Browse files Browse the repository at this point in the history
…#17590)

Not having this meant that uninstalls of globals installed by npm@4 or
earlier would fail, due to _requested not having the fields we expected.

PR-URL: npm/npm#17590
Credit: @iarna
Reviewed-By: @zkat
  • Loading branch information
iarna authored and zkat committed Jul 5, 2017
1 parent 06ba0a1 commit 9e5a943
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/install/deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,16 @@ exports.loadRequestedDeps = function (args, tree, saveToDependencies, log, next)
}, andForEachChild(loadDeps, andFinishTracker(log, next)))
}

function isNotEmpty (value) {
return value != null && value !== ''
}

module.exports.computeVersionSpec = computeVersionSpec
function computeVersionSpec (tree, child) {
validate('OO', arguments)
var requested
if (child.package._requested) {
var childReq = child.package._requested
if (childReq && (isNotEmpty(childReq.saveSpec) || (isNotEmpty(childReq.rawSpec) && isNotEmpty(childReq.fetchSpec)))) {
requested = child.package._requested
} else if (child.package._from) {
requested = npa(child.package._from)
Expand All @@ -277,7 +282,7 @@ function computeVersionSpec (tree, child) {
} else if (requested.type === 'directory' || requested.type === 'file') {
return 'file:' + path.relative(tree.path, requested.fetchSpec)
} else {
return requested.saveSpec
return requested.saveSpec || requested.rawSpec
}
}

Expand Down

0 comments on commit 9e5a943

Please sign in to comment.