mirror of
https://github.com/sst/opencode.git
synced 2025-08-31 02:07:24 +00:00
improve ripgrep download
This commit is contained in:
parent
53b7e04b86
commit
bbf77c6139
1 changed files with 16 additions and 13 deletions
|
@ -86,9 +86,14 @@ export namespace Ripgrep {
|
||||||
export type End = z.infer<typeof End>
|
export type End = z.infer<typeof End>
|
||||||
export type Summary = z.infer<typeof Summary>
|
export type Summary = z.infer<typeof Summary>
|
||||||
const PLATFORM = {
|
const PLATFORM = {
|
||||||
darwin: { platform: "apple-darwin", extension: "tar.gz" },
|
"arm64-darwin": { platform: "aarch64-apple-darwin", extension: "tar.gz" },
|
||||||
linux: { platform: "unknown-linux-musl", extension: "tar.gz" },
|
"arm64-linux": {
|
||||||
win32: { platform: "pc-windows-msvc", extension: "zip" },
|
platform: "aarch64-unknown-linux-gnu",
|
||||||
|
extension: "tar.gz",
|
||||||
|
},
|
||||||
|
"x64-darwin": { platform: "x86_64-apple-darwin", extension: "tar.gz" },
|
||||||
|
"x64-linux": { platform: "x86_64-unknown-linux-musl", extension: "tar.gz" },
|
||||||
|
"x64-win32": { platform: "x86_64-pc-windows-msvc", extension: "zip" },
|
||||||
} as const
|
} as const
|
||||||
|
|
||||||
export const ExtractionFailedError = NamedError.create(
|
export const ExtractionFailedError = NamedError.create(
|
||||||
|
@ -124,15 +129,13 @@ export namespace Ripgrep {
|
||||||
|
|
||||||
const file = Bun.file(filepath)
|
const file = Bun.file(filepath)
|
||||||
if (!(await file.exists())) {
|
if (!(await file.exists())) {
|
||||||
const archMap = { x64: "x86_64", arm64: "aarch64" } as const
|
const platformKey =
|
||||||
const arch = archMap[process.arch as keyof typeof archMap] ?? process.arch
|
`${process.arch}-${process.platform}` as keyof typeof PLATFORM
|
||||||
|
const config = PLATFORM[platformKey]
|
||||||
const config = PLATFORM[process.platform as keyof typeof PLATFORM]
|
if (!config) throw new UnsupportedPlatformError({ platform: platformKey })
|
||||||
if (!config)
|
|
||||||
throw new UnsupportedPlatformError({ platform: process.platform })
|
|
||||||
|
|
||||||
const version = "14.1.1"
|
const version = "14.1.1"
|
||||||
const filename = `ripgrep-${version}-${arch}-${config.platform}.${config.extension}`
|
const filename = `ripgrep-${version}-${config.platform}.${config.extension}`
|
||||||
const url = `https://github.com/BurntSushi/ripgrep/releases/download/${version}/${filename}`
|
const url = `https://github.com/BurntSushi/ripgrep/releases/download/${version}/${filename}`
|
||||||
|
|
||||||
const response = await fetch(url)
|
const response = await fetch(url)
|
||||||
|
@ -145,8 +148,8 @@ export namespace Ripgrep {
|
||||||
if (config.extension === "tar.gz") {
|
if (config.extension === "tar.gz") {
|
||||||
const args = ["tar", "-xzf", archivePath, "--strip-components=1"]
|
const args = ["tar", "-xzf", archivePath, "--strip-components=1"]
|
||||||
|
|
||||||
if (process.platform === "darwin") args.push("--include=*/rg")
|
if (platformKey.endsWith("-darwin")) args.push("--include=*/rg")
|
||||||
if (process.platform === "linux") args.push("--wildcards", "*/rg")
|
if (platformKey.endsWith("-linux")) args.push("--wildcards", "*/rg")
|
||||||
|
|
||||||
const proc = Bun.spawn(args, {
|
const proc = Bun.spawn(args, {
|
||||||
cwd: Global.Path.bin,
|
cwd: Global.Path.bin,
|
||||||
|
@ -177,7 +180,7 @@ export namespace Ripgrep {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
await fs.unlink(archivePath)
|
await fs.unlink(archivePath)
|
||||||
if (process.platform !== "win32") await fs.chmod(filepath, 0o755)
|
if (!platformKey.endsWith("-win32")) await fs.chmod(filepath, 0o755)
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue