* Downloads and installs ripgrep for the specified target * * @param {string} target - Target platform-arch (e.g., 'darwin-x64') * @param {string} targetDir - Directory to install ripgrep to * @returns {Promise } - Path to the installed ripgrep binary
(target, targetDir)
| 76 | * @returns {Promise<string>} - Path to the installed ripgrep binary |
| 77 | */ |
| 78 | async function downloadRipgrep(target, targetDir) { |
| 79 | // Get the ripgrep release file name for the target |
| 80 | const releaseFile = TARGET_TO_RIPGREP_RELEASE[target]; |
| 81 | if (!releaseFile) { |
| 82 | throw new Error(`Unsupported target: ${target}`); |
| 83 | } |
| 84 | |
| 85 | const platform = target.split("-")[0]; |
| 86 | const downloadUrl = `${RIPGREP_BASE_URL}/${releaseFile}`; |
| 87 | const tempDir = path.join(targetDir, "temp"); |
| 88 | |
| 89 | // Create temp directory |
| 90 | fs.mkdirSync(tempDir, { recursive: true }); |
| 91 | |
| 92 | const archivePath = path.join(tempDir, releaseFile); |
| 93 | |
| 94 | try { |
| 95 | // Download the ripgrep release |
| 96 | console.log(`[info] Downloading ripgrep from ${downloadUrl}`); |
| 97 | await downloadFile(downloadUrl, archivePath); |
| 98 | |
| 99 | // Extract the archive |
| 100 | console.log(`[info] Extracting ripgrep to ${targetDir}`); |
| 101 | await extractArchive(archivePath, targetDir, platform); |
| 102 | |
| 103 | // Make the binary executable on Unix-like systems |
| 104 | if (platform !== "win32") { |
| 105 | const rgPath = path.join(targetDir, "rg"); |
| 106 | fs.chmodSync(rgPath, 0o755); |
| 107 | } |
| 108 | |
| 109 | // Clean up |
| 110 | rimrafSync(tempDir); |
| 111 | |
| 112 | // Return the path to the ripgrep binary |
| 113 | const binName = platform === "win32" ? "rg.exe" : "rg"; |
| 114 | return path.join(targetDir, binName); |
| 115 | } catch (error) { |
| 116 | console.error(`[error] Failed to download ripgrep for ${target}:`, error); |
| 117 | // Clean up temp directory on error |
| 118 | rimrafSync(tempDir); |
| 119 | throw error; |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | module.exports = { |
| 124 | downloadRipgrep, |
no test coverage detected