Skip to content

Commit

Permalink
fix: correctly sort bazel version string components that begin with d…
Browse files Browse the repository at this point in the history
…igits (#154)
  • Loading branch information
kormide authored Feb 28, 2024
1 parent aaa1cbe commit 781548d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/domain/metadata-file.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ describe("constructor", () => {
"github:bar/rules_foo"
],
"versions": [
"1.0.0-rc1",
"1.0.0-rc0",
"1.0.0-rc1",
"0.0.1",
"2.0.0-rc5"
],
Expand Down
10 changes: 9 additions & 1 deletion src/domain/version.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ describe("compareVersions", () => {
"0.32.1",
"0.32.11",
"2.11.0",
"1.0.0-rc1",
"1.0.0-rc0",
"1.0.0-rc1",
"1.0.0-rc23",
"1.0.1-rc1",
"2.10.1",
Expand Down Expand Up @@ -69,4 +69,12 @@ describe("compareVersions", () => {
"x.7.z",
]);
});

it("should sort string identifiers that begin with a digit after numeric identifiers", () => {
expect(
["1.0.0rc1", "1.0.0rc2", "1.0.0rc3", "0.12.0", "1.0.1", "1.1.0"].sort(
compareVersions
)
).toEqual(["0.12.0", "1.0.1", "1.0.0rc1", "1.0.0rc2", "1.0.0rc3", "1.1.0"]);
});
});
2 changes: 1 addition & 1 deletion src/domain/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,6 @@ class Identifier {

public constructor(value: string) {
const numeric = parseInt(value);
this.value = isNaN(numeric) ? value : numeric;
this.value = /^\d+$/.test(value) ? numeric : value;
}
}

0 comments on commit 781548d

Please sign in to comment.