Skip to content

Commit

Permalink
Fixes pkgxdev#242
Browse files Browse the repository at this point in the history
  • Loading branch information
mxcl committed Dec 11, 2022
1 parent a14735b commit 07ac92f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/utils/semver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,17 @@ export class Range {
}

match = input.match(/^>=((\d+\.)*\d+)\s*(<((\d+\.)*\d+))?$/)
if (match) {
const v1 = parse(match[1])!
const v2 = match[3] ? parse(match[4])! : new SemVer([Infinity, Infinity, Infinity])
return [v1, v2]
}

match = input.match(/^<\d+(\.\d+)*$/)
if (!match) throw new Error(`invalid semver range: \`${input}\``)
const v1 = parse(match[1])!
const v2 = match[3] ? parse(match[4])! : new SemVer([Infinity, Infinity, Infinity])

const v1 = new SemVer([0,0,0])
const v2 = parse(match[0].slice(1)) ?? (() => {throw new Error()})()
return [v1, v2]
})

Expand Down
5 changes: 5 additions & 0 deletions tests/unit/semver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ Deno.test("semver", async test => {
assert(f.satisfies(new SemVer("16.0.0")))
assertFalse(f.satisfies(new SemVer("17.0.0")))
assert(f.satisfies(new SemVer("18.0.0")))

const g = new semver.Range("<15")
assert(g.satisfies(new SemVer("14.0.0")))
assert(g.satisfies(new SemVer("0.0.1")))
assertFalse(g.satisfies(new SemVer("15.0.0")))
})

await test.step("intersection", async test => {
Expand Down

0 comments on commit 07ac92f

Please sign in to comment.