Skip to content

Commit

Permalink
deps: catch more npa parse failures (#17816)
Browse files Browse the repository at this point in the history
Fixes: #17283

PR-URL: npm/npm#17816
Credit: @SamuelMarks
Reviewed-By: @zkat
  • Loading branch information
SamuelMarks authored and zkat committed Jul 28, 2017
1 parent 44b98b9 commit c3d1d3b
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions lib/install/deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,18 +197,31 @@ function matchingDep (tree, name) {

exports.getAllMetadata = function (args, tree, where, next) {
asyncMap(args, function (arg, done) {
var spec = npa(arg)
let spec
try {
spec = npa(arg)
} catch (e) {
return done(e)
}
if (spec.type !== 'file' && spec.type !== 'directory' && (spec.name == null || spec.rawSpec === '')) {
return fs.stat(path.join(arg, 'package.json'), (err) => {
if (err) {
var version = matchingDep(tree, spec.name)
if (version) {
return fetchPackageMetadata(npa.resolve(spec.name, version), where, done)
try {
return fetchPackageMetadata(npa.resolve(spec.name, version), where, done)
} catch (e) {
return done(e)
}
} else {
return fetchPackageMetadata(spec, where, done)
}
} else {
return fetchPackageMetadata(npa('file:' + arg), where, done)
try {
return fetchPackageMetadata(npa('file:' + arg), where, done)
} catch (e) {
return done(e)
}
}
})
} else {
Expand Down

0 comments on commit c3d1d3b

Please sign in to comment.