Skip to content

Commit

Permalink
Merge 8a06776 into 6a15172
Browse files Browse the repository at this point in the history
  • Loading branch information
mxcl committed Oct 1, 2023
2 parents 6a15172 + 8a06776 commit 1fec42f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/utils/semver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,20 @@ Deno.test("semver", async test => {
assertFalse(a.satisfies(new SemVer("1.0.0")))
})

await test.step("^0 string is not @0.0.0", () => {
const a = new semver.Range("^0")
assertEquals(a.toString(), "^0")

const b = new semver.Range("^0.0")
assertEquals(b.toString(), "~0") //NOTE strictly should be ~0.0 but this is fine

const c = new semver.Range("^1")
assertEquals(c.toString(), "^1")

const d = new semver.Range("^1.0")
assertEquals(d.toString(), "^1")
})

//FIXME this *should* work
// await test.step("^11,^12…^11.3,^12.2", () => {
// const a = new semver.Range("^11,^12")
Expand Down
12 changes: 10 additions & 2 deletions src/utils/semver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,17 @@ export class Range {
return this.set.map(v => {
if (!isArray(v)) return `=${v.toString()}`
const [v1, v2] = v
if (v1.major > 0 && v2.major == v1.major + 1 && v2.minor == 0 && v2.patch == 0) {
if (v2.major == v1.major + 1 && v2.minor == 0 && v2.patch == 0) {
const v = chomp(v1)
return `^${v}`
if (v1.major == 0) {
if (v1.components.length == 1) {
return `^0`
} else {
return `>=${v}<1`
}
} else {
return `^${v}`
}
} else if (v2.major == v1.major && v2.minor == v1.minor + 1 && v2.patch == 0) {
const v = chomp(v1)
return `~${v}`
Expand Down

0 comments on commit 1fec42f

Please sign in to comment.