Skip to content

Commit 781548d

Browse files
authored
fix: correctly sort bazel version string components that begin with digits (#154)
1 parent aaa1cbe commit 781548d

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

src/domain/metadata-file.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,8 @@ describe("constructor", () => {
315315
"github:bar/rules_foo"
316316
],
317317
"versions": [
318-
"1.0.0-rc1",
319318
"1.0.0-rc0",
319+
"1.0.0-rc1",
320320
"0.0.1",
321321
"2.0.0-rc5"
322322
],

src/domain/version.spec.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ describe("compareVersions", () => {
99
"0.32.1",
1010
"0.32.11",
1111
"2.11.0",
12-
"1.0.0-rc1",
1312
"1.0.0-rc0",
13+
"1.0.0-rc1",
1414
"1.0.0-rc23",
1515
"1.0.1-rc1",
1616
"2.10.1",
@@ -69,4 +69,12 @@ describe("compareVersions", () => {
6969
"x.7.z",
7070
]);
7171
});
72+
73+
it("should sort string identifiers that begin with a digit after numeric identifiers", () => {
74+
expect(
75+
["1.0.0rc1", "1.0.0rc2", "1.0.0rc3", "0.12.0", "1.0.1", "1.1.0"].sort(
76+
compareVersions
77+
)
78+
).toEqual(["0.12.0", "1.0.1", "1.0.0rc1", "1.0.0rc2", "1.0.0rc3", "1.1.0"]);
79+
});
7280
});

src/domain/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,6 @@ class Identifier {
8888

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

0 commit comments

Comments
 (0)