Skip to content

Commit

Permalink
Fix crash for any version (#14)
Browse files Browse the repository at this point in the history
* Fix crash for any version

* remove test
  • Loading branch information
ota-meshi authored Oct 22, 2021
1 parent 3a4be03 commit b9d9e2c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/utils/semver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ export function maxNextVersion(range: Range): SemVer | null {
let max = null
let hasMin = false
for (const comparator of comparators) {
if (!comparator.semver.version) {
// ANY
return null
}
// Clone to avoid manipulating the comparators semver object.
const compVer = new SemVer(comparator.semver.version)
if (
Expand Down
25 changes: 24 additions & 1 deletion tests/lib/utils/semver.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import assert from "assert"

import { normalizeSemverRange } from "../../../lib/utils/semver"
import { normalizeSemverRange, maxNextVersion } from "../../../lib/utils/semver"
import { Range, subset } from "semver"

describe("normalizeSemverRange", () => {
Expand Down Expand Up @@ -83,3 +83,26 @@ describe("normalizeSemverRange", () => {
})
}
})
describe("maxNextVersion", () => {
const testcases = [
{
input: ">=10",
output: null,
},
{
input: "^10",
output: "11.0.0-0",
},
{
input: "*",
output: null,
},
]
for (const { input, output } of testcases) {
it(`Get max next version "${input}" should result in "${output}".`, () => {
const inRange = new Range(input)
const outRange = maxNextVersion(inRange)
assert.strictEqual(outRange?.raw ?? null, output)
})
}
})

0 comments on commit b9d9e2c

Please sign in to comment.