Skip to content

Commit

Permalink
MinVersion failing for '^2.16.2 ^2.16' alike range
Browse files Browse the repository at this point in the history
Patch for issue #340

EDIT(@isaacs): updated to make it not break other stuff, and added test.

PR-URL: #341
Credit: @alfredsgenkins
Close: #341
Reviewed-by: @isaacs
  • Loading branch information
alfredsgenkins authored and isaacs committed Dec 1, 2020
1 parent a7acc5d commit 2d01126
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 5 additions & 2 deletions ranges/min-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const minVersion = (range, loose) => {
for (let i = 0; i < range.set.length; ++i) {
const comparators = range.set[i]

let setMin = null
comparators.forEach((comparator) => {
// Clone to avoid manipulating the comparator's semver object.
const compver = new SemVer(comparator.semver.version)
Expand All @@ -33,8 +34,8 @@ const minVersion = (range, loose) => {
/* fallthrough */
case '':
case '>=':
if (!minver || gt(minver, compver)) {
minver = compver
if (!setMin || gt(compver, setMin)) {
setMin = compver
}
break
case '<':
Expand All @@ -46,6 +47,8 @@ const minVersion = (range, loose) => {
throw new Error(`Unexpected operation: ${comparator.operator}`)
}
})
if (setMin && (!minver || gt(minver, setMin)))
minver = setMin
}

if (minver && range.test(minver)) {
Expand Down
6 changes: 5 additions & 1 deletion test/ranges/min-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ test('minimum version in range tests', (t) => {
['^1.1.1', '1.1.1'],
['^1.1.1-beta', '1.1.1-beta'],
['^1.1.1 || >=2', '1.1.1'],
['^2.16.2 ^2.16', '2.16.2'],

// '-' operator
['1.1.1 - 1.8.0', '1.1.1'],
Expand Down Expand Up @@ -69,7 +70,10 @@ test('minimum version in range tests', (t) => {
const loose = tuple[2] || false
const msg = `minVersion(${range}, ${loose}) = ${version}`
const min = minVersion(range, loose)
t.ok(min === version || (min && min.version === version), msg)
t.ok(min === version || (min && min.version === version), msg, {
found: min,
wanted: version,
})
})
t.end()
})

0 comments on commit 2d01126

Please sign in to comment.