Skip to content

Commit bbf77c6

Browse files
committed
improve ripgrep download
1 parent 53b7e04 commit bbf77c6

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

packages/opencode/src/file/ripgrep.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,14 @@ export namespace Ripgrep {
8686
export type End = z.infer<typeof End>
8787
export type Summary = z.infer<typeof Summary>
8888
const PLATFORM = {
89-
darwin: { platform: "apple-darwin", extension: "tar.gz" },
90-
linux: { platform: "unknown-linux-musl", extension: "tar.gz" },
91-
win32: { platform: "pc-windows-msvc", extension: "zip" },
89+
"arm64-darwin": { platform: "aarch64-apple-darwin", extension: "tar.gz" },
90+
"arm64-linux": {
91+
platform: "aarch64-unknown-linux-gnu",
92+
extension: "tar.gz",
93+
},
94+
"x64-darwin": { platform: "x86_64-apple-darwin", extension: "tar.gz" },
95+
"x64-linux": { platform: "x86_64-unknown-linux-musl", extension: "tar.gz" },
96+
"x64-win32": { platform: "x86_64-pc-windows-msvc", extension: "zip" },
9297
} as const
9398

9499
export const ExtractionFailedError = NamedError.create(
@@ -124,15 +129,13 @@ export namespace Ripgrep {
124129

125130
const file = Bun.file(filepath)
126131
if (!(await file.exists())) {
127-
const archMap = { x64: "x86_64", arm64: "aarch64" } as const
128-
const arch = archMap[process.arch as keyof typeof archMap] ?? process.arch
129-
130-
const config = PLATFORM[process.platform as keyof typeof PLATFORM]
131-
if (!config)
132-
throw new UnsupportedPlatformError({ platform: process.platform })
132+
const platformKey =
133+
`${process.arch}-${process.platform}` as keyof typeof PLATFORM
134+
const config = PLATFORM[platformKey]
135+
if (!config) throw new UnsupportedPlatformError({ platform: platformKey })
133136

134137
const version = "14.1.1"
135-
const filename = `ripgrep-${version}-${arch}-${config.platform}.${config.extension}`
138+
const filename = `ripgrep-${version}-${config.platform}.${config.extension}`
136139
const url = `https://github.com/BurntSushi/ripgrep/releases/download/${version}/${filename}`
137140

138141
const response = await fetch(url)
@@ -145,8 +148,8 @@ export namespace Ripgrep {
145148
if (config.extension === "tar.gz") {
146149
const args = ["tar", "-xzf", archivePath, "--strip-components=1"]
147150

148-
if (process.platform === "darwin") args.push("--include=*/rg")
149-
if (process.platform === "linux") args.push("--wildcards", "*/rg")
151+
if (platformKey.endsWith("-darwin")) args.push("--include=*/rg")
152+
if (platformKey.endsWith("-linux")) args.push("--wildcards", "*/rg")
150153

151154
const proc = Bun.spawn(args, {
152155
cwd: Global.Path.bin,
@@ -177,7 +180,7 @@ export namespace Ripgrep {
177180
})
178181
}
179182
await fs.unlink(archivePath)
180-
if (process.platform !== "win32") await fs.chmod(filepath, 0o755)
183+
if (!platformKey.endsWith("-win32")) await fs.chmod(filepath, 0o755)
181184
}
182185

183186
return {

0 commit comments

Comments
 (0)