From 6e06694fd6acab185432bccf57bd5c9c3b68f218 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 19 Jan 2023 13:53:24 +0100 Subject: Fix semver comparison --- shared/core-utils/common/version.ts | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) (limited to 'shared') diff --git a/shared/core-utils/common/version.ts b/shared/core-utils/common/version.ts index 8a64f8c4d..305287233 100644 --- a/shared/core-utils/common/version.ts +++ b/shared/core-utils/common/version.ts @@ -1,18 +1,9 @@ -// Thanks https://stackoverflow.com/a/16187766 +// Thanks https://gist.github.com/iwill/a83038623ba4fef6abb9efca87ae9ccb function compareSemVer (a: string, b: string) { - const regExStrip0 = /(\.0+)+$/ - const segmentsA = a.replace(regExStrip0, '').split('.') - const segmentsB = b.replace(regExStrip0, '').split('.') + if (a.startsWith(b + '-')) return -1 + if (b.startsWith(a + '-')) return 1 - const l = Math.min(segmentsA.length, segmentsB.length) - - for (let i = 0; i < l; i++) { - const diff = parseInt(segmentsA[i], 10) - parseInt(segmentsB[i], 10) - - if (diff) return diff - } - - return segmentsA.length - segmentsB.length + return a.localeCompare(b, undefined, { numeric: true, sensitivity: 'case', caseFirst: 'upper' }) } export { -- cgit v1.2.3