()
| 170 | } |
| 171 | |
| 172 | async function main() { |
| 173 | const { target, ext } = getPlatformMapping() |
| 174 | const assetName = `ripgrep-v${RG_VERSION}-${target}.${ext}` |
| 175 | const binaryPath = getBinaryPath() |
| 176 | const binDir = path.dirname(binaryPath) |
| 177 | |
| 178 | const force = process.argv.includes('--force') |
| 179 | if (!force && existsSync(binaryPath) && statSync(binaryPath).size > 0) { |
| 180 | console.log(`[ripgrep] Binary already exists at ${binaryPath}, skipping.`) |
| 181 | return |
| 182 | } |
| 183 | |
| 184 | console.log(`[ripgrep] Downloading v${RG_VERSION} for ${target}...`) |
| 185 | const extractedBinary = process.platform === 'win32' ? 'rg.exe' : 'rg' |
| 186 | const mirrors = [RELEASE_BASE] |
| 187 | if (RELEASE_BASE === DEFAULT_RELEASE_BASE.replace(/\/$/, '')) mirrors.push(MIRROR_RELEASE_BASE.replace(/\/$/, '')) |
| 188 | |
| 189 | let buffer, lastError |
| 190 | for (const base of mirrors) { |
| 191 | const url = `${base}/${assetName}` |
| 192 | try { |
| 193 | console.log(`[ripgrep] Trying ${url}`) |
| 194 | buffer = await downloadUrlToBufferWithFallback(url) |
| 195 | break |
| 196 | } catch (e) { |
| 197 | console.warn(`[ripgrep] Download from ${base} failed: ${e instanceof Error ? e.message : e}`) |
| 198 | lastError = e |
| 199 | } |
| 200 | } |
| 201 | if (!buffer) throw lastError |
| 202 | |
| 203 | console.log(`[ripgrep] Downloaded ${Math.round(buffer.length / 1024)} KB`) |
| 204 | mkdirSync(binDir, { recursive: true }) |
| 205 | |
| 206 | if (ext === 'tar.gz') { |
| 207 | await extractTarGz(buffer, binaryPath, extractedBinary, assetName) |
| 208 | } else { |
| 209 | await extractZip(buffer, binaryPath, extractedBinary) |
| 210 | } |
| 211 | |
| 212 | if (process.platform !== 'win32') chmodSync(binaryPath, 0o755) |
| 213 | console.log(`[ripgrep] Installed to ${binaryPath}`) |
| 214 | } |
| 215 | |
| 216 | main().catch((error) => { |
| 217 | const msg = error instanceof Error ? error.message : String(error) |
no test coverage detected