Sorts version numbers

pull/4371/head v0.46.0-dev-20240124
Henning Dieterichs 1 year ago committed by Henning Dieterichs
parent 73b47d4592
commit 21db3aebf0

@ -59,9 +59,38 @@ async function _getNpmVersions(): Promise<string[]> {
]); ]);
const validVersions = versions.filter((v) => !brokenVersions.has(v)); const validVersions = versions.filter((v) => !brokenVersions.has(v));
validVersions.sort((v1, v2) => -compareSemanticVersions(v1, v2));
return validVersions; return validVersions;
} }
function compareSemanticVersions(version1: string, version2: string): number {
const v1 = version1.split(/[.]/);
const v2 = version2.split(/[.]/);
for (let i = 0; i < Math.min(v1.length, v2.length); i++) {
const isNumber = /^\d+$/.test(v1[i]) && /^\d+$/.test(v2[i]);
if (isNumber) {
const n1 = parseInt(v1[i]);
const n2 = parseInt(v2[i]);
if (n1 < n2) {
return -1;
}
if (n1 > n2) {
return 1;
}
} else {
const compare = v1[i].localeCompare(v2[i]);
if (compare !== 0) {
return compare;
}
}
}
return v1.length - v2.length;
}
export async function getVsCodeCommitId( export async function getVsCodeCommitId(
monacoEditorVersion: string monacoEditorVersion: string
): Promise<string | undefined> { ): Promise<string | undefined> {

Loading…
Cancel
Save