Skip to content

Commit

Permalink
fix: Favour v1.0 to 1.0 in last tag resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
Alorel committed Sep 21, 2023
1 parent 3e49811 commit a74f516
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/lib/semver.mts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ class SemVer {
this.#patch = fmtNum(patch);
}

public static cmp(a: SemVer | undefined, b: SemVer | undefined): 1 | 0 | -1 {
if (a == null) {
return b == null ? 0 : -1;
} else if (b == null) {
return -1;
}

return cmpNum(a.major, b.major) ?? cmpNum(a.#minor, b.#minor) ?? cmpNum(a.#patch, b.#patch) ?? 0;
/** Sorts in descending order, i.e. a higher version will come before a lower version */
public static cmp(a: SemVer, b: SemVer): 1 | 0 | -1 {
return cmpNum(a.major, b.major)
?? cmpNum(a.#minor, b.#minor)
?? cmpNum(a.#patch, b.#patch)
?? cmpPrefixed(a.prefixed, b.prefixed)
?? 0;
}

public static parse(from: string, allowStrippingVPrefix = false): SemVer | undefined {
Expand Down Expand Up @@ -175,6 +174,14 @@ function fmtNum(num: number | string | undefined): number | undefined {
}
}

function cmpPrefixed(a: boolean, b: boolean): 1 | -1 | undefined {
if (a && !b) {
return -1;
} else if (!a && b) {
return 1;
}
}

function cmpNum(a: number | undefined, b: number | undefined): 1 | -1 | undefined {
if (a == null) {
return b == null ? undefined : 1;
Expand Down

0 comments on commit a74f516

Please sign in to comment.