Skip to content

Commit 9981211

Browse files
ruyadornonlf
authored andcommitted
fix: npm outdated parsing invalid specs
This commit fixes a problem in which npm outdated was breaking when trying to read an invalid semver range spec defined for a given installed dep by performing the `npm-package-arg` parsing within a try/catch block instead of expecting to read properties from the returned instance. Also, adds the missing test for that specific line of code. Fixes #1703 PR-URL: #1857 Credit: @ruyadorno Close: #1857 Reviewed-by: @nlf
1 parent 52114b7 commit 9981211

File tree

2 files changed

+128
-73
lines changed

2 files changed

+128
-73
lines changed

lib/outdated.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,11 @@ async function outdated_ (tree, deps, opts) {
138138
const packument = await getPackument(spec)
139139
const expected = edge.spec
140140
// if it's not a range, version, or tag, skip it
141-
/* istanbul ignore next */
142-
if (!npa(`${edge.name}@${edge.spec}`).registry) {
141+
try {
142+
if (!npa(`${edge.name}@${edge.spec}`).registry) {
143+
return null
144+
}
145+
} catch (err) {
143146
return null
144147
}
145148
const wanted = pickManifest(packument, expected, npm.flatOptions)
@@ -170,7 +173,7 @@ async function outdated_ (tree, deps, opts) {
170173
err.code === 'E403' ||
171174
err.code === 'E404')
172175
) {
173-
throw (err)
176+
throw err
174177
}
175178
}
176179
}

0 commit comments

Comments
 (0)