Skip to content

Commit fc56c2e

Browse files
committed
handle equal majors more gracefully
1 parent 4dd57fe commit fc56c2e

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

src/components/versionSelector/index.tsx

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,26 @@ import styles from './style.module.scss';
1212
import {VersionBanner} from '../versionBanner';
1313

1414
function sortVersions(versions: string[]) {
15-
return versions
16-
.sort((a, b) => {
17-
const aSegments = parseInt(a.split('.')[0], 10);
18-
const bSegments = parseInt(b.split('.')[0], 10);
15+
return versions.sort((a, b) => {
16+
const aMajor = parseInt(a.split('.')[0], 10);
17+
const bMajor = parseInt(b.split('.')[0], 10);
1918

20-
if (isNaN(aSegments) || isNaN(bSegments)) {
21-
return a.localeCompare(b);
22-
}
19+
if (isNaN(aMajor) || isNaN(bMajor)) {
20+
return a.localeCompare(b);
21+
}
2322

24-
if (aSegments < bSegments) {
25-
return -1;
26-
}
23+
if (aMajor < bMajor) {
2724
return 1;
28-
})
29-
.reverse();
25+
}
26+
27+
if (aMajor === bMajor) {
28+
// yes, this is flawed. But for now there's no case where we need to order
29+
// by minor or patch so I wanna avoid pulling in semver as a dependency
30+
return a.localeCompare(b);
31+
}
32+
33+
return -1;
34+
});
3035
}
3136

3237
export function VersionSelector({versions, sdk}: {sdk: string; versions: string[]}) {

0 commit comments

Comments
 (0)