(a: string, b: string)
| 45 | * - -1 when `a < b` |
| 46 | */ |
| 47 | export function compareVersions(a: string, b: string): number { |
| 48 | const aParts = parseVersion(a) |
| 49 | const bParts = parseVersion(b) |
| 50 | const maxLength = Math.max(aParts.length, bParts.length) |
| 51 | |
| 52 | for (let i = 0; i < maxLength; i++) { |
| 53 | const aPart = aParts[i] ?? 0 |
| 54 | const bPart = bParts[i] ?? 0 |
| 55 | |
| 56 | if (aPart > bPart) { |
| 57 | return 1 |
| 58 | } |
| 59 | |
| 60 | if (aPart < bPart) { |
| 61 | return -1 |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | return 0 |
| 66 | } |
| 67 | |
| 68 | export async function getLatestCliVersion(fetchImpl: typeof fetch = fetch): Promise<string> { |
| 69 | const response = await fetchImpl(RELEASES_URL, { |
no test coverage detected