mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Place current release at the top of version dropdown in Manage Packages dialog. (#12884)
* Also improved sorting for version numbers with non-numeric components.
This commit is contained in:
@@ -144,22 +144,31 @@ export function getOSPlatformId(): string {
|
||||
* @returns 1 if the first version is greater, -1 if it's less, and 0 otherwise.
|
||||
*/
|
||||
export function comparePackageVersions(first: string, second: string): number {
|
||||
let firstVersion = first.split('.').map(numStr => Number.parseInt(numStr));
|
||||
let secondVersion = second.split('.').map(numStr => Number.parseInt(numStr));
|
||||
let firstVersion = first.split('.');
|
||||
let secondVersion = second.split('.');
|
||||
|
||||
// If versions have different lengths, then append zeroes to the shorter one
|
||||
if (firstVersion.length > secondVersion.length) {
|
||||
let diff = firstVersion.length - secondVersion.length;
|
||||
secondVersion = secondVersion.concat(new Array(diff).fill(0));
|
||||
secondVersion = secondVersion.concat(new Array(diff).fill('0'));
|
||||
} else if (secondVersion.length > firstVersion.length) {
|
||||
let diff = secondVersion.length - firstVersion.length;
|
||||
firstVersion = firstVersion.concat(new Array(diff).fill(0));
|
||||
firstVersion = firstVersion.concat(new Array(diff).fill('0'));
|
||||
}
|
||||
|
||||
for (let i = 0; i < firstVersion.length; ++i) {
|
||||
if (firstVersion[i] > secondVersion[i]) {
|
||||
let firstVersionNum: string | number = Number(firstVersion[i]);
|
||||
let secondVersionNum: string | number = Number(secondVersion[i]);
|
||||
|
||||
// Fallback to string comparison if either value isn't a number
|
||||
if (isNaN(firstVersionNum) || isNaN(secondVersionNum)) {
|
||||
firstVersionNum = firstVersion[i];
|
||||
secondVersionNum = secondVersion[i];
|
||||
}
|
||||
|
||||
if (firstVersionNum > secondVersionNum) {
|
||||
return 1;
|
||||
} else if (firstVersion[i] < secondVersion[i]) {
|
||||
} else if (firstVersionNum < secondVersionNum) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user