Skip to content

Commit

Permalink
feat(selection): Avoid matching deprecated packages if possible
Browse files Browse the repository at this point in the history
BREAKING CHANGE: deprecated versions may be skipped now
  • Loading branch information
iarna authored and zkat committed Oct 3, 2017
1 parent ed743a0 commit 3fc6c3a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function pickManifest (packument, wanted, opts) {
}
const distTags = packument['dist-tags'] || {}
const versions = Object.keys(packument.versions || {}).filter(v => semver.valid(v, true))
const undeprecated = versions.filter(v => !packument.versions[v].deprecated)
let err

if (!versions.length) {
Expand Down Expand Up @@ -45,6 +46,9 @@ function pickManifest (packument, wanted, opts) {
target = tagVersion
}

if (!target) {
target = semver.maxSatisfying(undeprecated, wanted, true)
}
if (!target) {
target = semver.maxSatisfying(versions, wanted, true)
}
Expand Down
28 changes: 28 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,31 @@ test('matches even if requested version has garbage', t => {
t.equal(manifest.version, '1.0.0', 'picked the right manifest even though `wanted` had garbage')
t.done()
})

test('matches skip deprecated versions', t => {
const metadata = {
versions: {
'1.0.0': { version: '1.0.0' },
'1.0.1': { version: '1.0.1' },
'1.1.0': { version: '1.1.0', deprecated: 'yes' },
'2.0.0': { version: '2.0.0' }
}
}
const manifest = pickManifest(metadata, '^1.0.0')
t.equal(manifest.version, '1.0.1', 'picked the right manifest')
t.done()
})

test('matches deprecated versions if we have to', t => {
const metadata = {
versions: {
'1.0.0': { version: '1.0.0' },
'1.0.1': { version: '1.0.1' },
'1.1.0': { version: '1.1.0', deprecated: 'yes' },
'2.0.0': { version: '2.0.0' }
}
}
const manifest = pickManifest(metadata, '^1.1.0')
t.equal(manifest.version, '1.1.0', 'picked the right manifest')
t.done()
})

0 comments on commit 3fc6c3a

Please sign in to comment.