( channelOrVersion: string, )
| 166 | } |
| 167 | |
| 168 | export async function getLatestVersion( |
| 169 | channelOrVersion: string, |
| 170 | ): Promise<string> { |
| 171 | // Direct version - match internal format too (e.g. 1.0.30-dev.shaf4937ce) |
| 172 | if (/^v?\d+\.\d+\.\d+(-\S+)?$/.test(channelOrVersion)) { |
| 173 | const normalized = channelOrVersion.startsWith('v') |
| 174 | ? channelOrVersion.slice(1) |
| 175 | : channelOrVersion |
| 176 | // 99.99.x is reserved for CI smoke-test fixtures on real GCS. |
| 177 | // feature() is false in all shipped builds — DCE collapses this to an |
| 178 | // unconditional throw. Only `bun --feature=ALLOW_TEST_VERSIONS` (the |
| 179 | // smoke test's source-level invocation) bypasses. |
| 180 | if (/^99\.99\./.test(normalized) && !feature('ALLOW_TEST_VERSIONS')) { |
| 181 | throw new Error( |
| 182 | `Version ${normalized} is not available for installation. Use 'stable' or 'latest'.`, |
| 183 | ) |
| 184 | } |
| 185 | return normalized |
| 186 | } |
| 187 | |
| 188 | // ReleaseChannel validation |
| 189 | const channel = channelOrVersion as ReleaseChannel |
| 190 | if (channel !== 'stable' && channel !== 'latest') { |
| 191 | throw new Error( |
| 192 | `Invalid channel: ${channelOrVersion}. Use 'stable' or 'latest'`, |
| 193 | ) |
| 194 | } |
| 195 | |
| 196 | const binaryRepoUrl = getPublicBinaryUrl() |
| 197 | if (binaryRepoUrl) { |
| 198 | return getLatestVersionFromBinaryRepo(channel, binaryRepoUrl) |
| 199 | } |
| 200 | |
| 201 | return getLatestVersionFromGithubReleases(channel) |
| 202 | } |
| 203 | |
| 204 | // Stall timeout: abort if no bytes received for this duration |
| 205 | const DEFAULT_STALL_TIMEOUT_MS = 60000 // 60 seconds |
no test coverage detected