fix: compare cliproxy fork release suffixes (#1419)

This commit is contained in:
Kai (Tam Nhu) Tran authored and GitHub committed 2026-05-30 13:42:31 -04:00
1 parent 6506f00d8b
commit aee322ea88
4 files changed
+96 -33

No files matched your search

+32 -13
View File
@@ -1,20 +1,39 @@
function normalizeVersionParts(version: string): number[] {
return version.replace(/-\d+$/, '').split('.').map(Number);
interface ParsedCliproxyVersion {
major: number;
minor: number;
patch: number;
forkRelease: number;
}
function parseCliproxyVersion(version: string): ParsedCliproxyVersion {
const normalized = version.trim().replace(/^v/, '');
const [coreVersion, forkReleaseValue = '0'] = normalized.split('-', 2);
const [major = 0, minor = 0, patch = 0] = coreVersion
.split('.')
.map((part) => Number.parseInt(part, 10) || 0);
const forkRelease = /^\d+$/.test(forkReleaseValue)
? Number.parseInt(forkReleaseValue, 10) || 0
: 0;
return { major, minor, patch, forkRelease };
}
function compareVersionPart(a: number, b: number): number {
if (a > b) return 1;
if (a < b) return -1;
return 0;
}
export function compareCliproxyVersions(a: string, b: string): number {
const aParts = normalizeVersionParts(a);
const bParts = normalizeVersionParts(b);
const left = parseCliproxyVersion(a);
const right = parseCliproxyVersion(b);
for (let index = 0; index < 3; index += 1) {
const aPart = aParts[index] || 0;
const bPart = bParts[index] || 0;
if (aPart > bPart) return 1;
if (aPart < bPart) return -1;
}
return 0;
return (
compareVersionPart(left.major, right.major) ||
compareVersionPart(left.minor, right.minor) ||
compareVersionPart(left.patch, right.patch) ||
compareVersionPart(left.forkRelease, right.forkRelease)
);
}
export function isCliproxyVersionExperimental(version: string, maxStableVersion: string): boolean {