( channelOrVersion: string, )
| 110 | } |
| 111 | |
| 112 | export async function getLatestVersion( |
| 113 | channelOrVersion: string, |
| 114 | ): Promise<string> { |
| 115 | // Direct version - match internal format too (e.g. 1.0.30-dev.shaf4937ce) |
| 116 | if (/^v?\d+\.\d+\.\d+(-\S+)?$/.test(channelOrVersion)) { |
| 117 | const normalized = channelOrVersion.startsWith('v') |
| 118 | ? channelOrVersion.slice(1) |
| 119 | : channelOrVersion |
| 120 | // 99.99.x is reserved for CI smoke-test fixtures on real GCS. |
| 121 | // feature() is false in all shipped builds — DCE collapses this to an |
| 122 | // unconditional throw. Only `bun --feature=ALLOW_TEST_VERSIONS` (the |
| 123 | // smoke test's source-level invocation) bypasses. |
| 124 | if (/^99\.99\./.test(normalized) && !feature('ALLOW_TEST_VERSIONS')) { |
| 125 | throw new Error( |
| 126 | `Version ${normalized} is not available for installation. Use 'stable' or 'latest'.`, |
| 127 | ) |
| 128 | } |
| 129 | return normalized |
| 130 | } |
| 131 | |
| 132 | // ReleaseChannel validation |
| 133 | const channel = channelOrVersion as ReleaseChannel |
| 134 | if (channel !== 'stable' && channel !== 'latest') { |
| 135 | throw new Error( |
| 136 | `Invalid channel: ${channelOrVersion}. Use 'stable' or 'latest'`, |
| 137 | ) |
| 138 | } |
| 139 | |
| 140 | // Route to appropriate source |
| 141 | if (process.env.USER_TYPE === 'ant') { |
| 142 | // Use Artifactory for ant users |
| 143 | const npmTag = channel === 'stable' ? 'stable' : 'latest' |
| 144 | return getLatestVersionFromArtifactory(npmTag) |
| 145 | } |
| 146 | |
| 147 | // Use GCS for external users |
| 148 | return getLatestVersionFromBinaryRepo(channel, GCS_BUCKET_URL) |
| 149 | } |
| 150 | |
| 151 | export async function downloadVersionFromArtifactory( |
| 152 | version: string, |
no test coverage detected