Skip to content

Commit

Permalink
fix(semver): use loose semver parsing for *all* ops
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Jun 29, 2017
1 parent e6493e5 commit bbc0daa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ function pickManifest (packument, wanted, opts) {
const spec = npa.resolve(packument.name, wanted)
const type = spec.type
if (type === 'version' || type === 'range') {
wanted = semver.clean(wanted) || wanted
wanted = semver.clean(wanted, true) || wanted
}
const distTags = packument['dist-tags'] || {}
const versions = Object.keys(packument.versions || {}).filter(v => semver.valid(v))
const versions = Object.keys(packument.versions || {}).filter(v => semver.valid(v, true))
let err

if (!versions.length) {
Expand Down
14 changes: 14 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,17 @@ test('matches even if requested version has spaces', t => {
t.equal(manifest.version, '1.0.0', 'picked the right manifest even though `wanted` had spaced')
t.done()
})

test('matches even if requested version has garbage', t => {
const metadata = {
versions: {
'1.0.0': { version: '1.0.0' },
'1.0.1': { version: '1.0.1' },
'1.0.2': { version: '1.0.2' },
'2.0.0': { version: '2.0.0' }
}
}
const manifest = pickManifest(metadata, '== 1.0.0 || foo')
t.equal(manifest.version, '1.0.0', 'picked the right manifest even though `wanted` had garbage')
t.done()
})

0 comments on commit bbc0daa

Please sign in to comment.