mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-14 12:16:38 +00:00
fix: compare cliproxy fork release suffixes (#1419)
This commit is contained in:
1 parent
6506f00d8b
commit
aee322ea88
4 files changed
+96
-33
No files matched your search
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user