|
|
@@ -6,6 +6,7 @@ import z from "zod"
|
|
|
import { NamedError } from "@opencode-ai/util/error"
|
|
|
import { lazy } from "../util/lazy"
|
|
|
import { $ } from "bun"
|
|
|
+import { Filesystem } from "../util/filesystem"
|
|
|
|
|
|
import { ZipReader, BlobReader, BlobWriter } from "@zip.js/zip.js"
|
|
|
import { Log } from "@/util/log"
|
|
|
@@ -131,8 +132,7 @@ export namespace Ripgrep {
|
|
|
}
|
|
|
const filepath = path.join(Global.Path.bin, "rg" + (process.platform === "win32" ? ".exe" : ""))
|
|
|
|
|
|
- const file = Bun.file(filepath)
|
|
|
- if (!(await file.exists())) {
|
|
|
+ if (!(await Filesystem.exists(filepath))) {
|
|
|
const platformKey = `${process.arch}-${process.platform}` as keyof typeof PLATFORM
|
|
|
const config = PLATFORM[platformKey]
|
|
|
if (!config) throw new UnsupportedPlatformError({ platform: platformKey })
|
|
|
@@ -144,9 +144,9 @@ export namespace Ripgrep {
|
|
|
const response = await fetch(url)
|
|
|
if (!response.ok) throw new DownloadFailedError({ url, status: response.status })
|
|
|
|
|
|
- const buffer = await response.arrayBuffer()
|
|
|
+ const arrayBuffer = await response.arrayBuffer()
|
|
|
const archivePath = path.join(Global.Path.bin, filename)
|
|
|
- await Bun.write(archivePath, buffer)
|
|
|
+ await Filesystem.write(archivePath, Buffer.from(arrayBuffer))
|
|
|
if (config.extension === "tar.gz") {
|
|
|
const args = ["tar", "-xzf", archivePath, "--strip-components=1"]
|
|
|
|
|
|
@@ -166,7 +166,7 @@ export namespace Ripgrep {
|
|
|
})
|
|
|
}
|
|
|
if (config.extension === "zip") {
|
|
|
- const zipFileReader = new ZipReader(new BlobReader(new Blob([await Bun.file(archivePath).arrayBuffer()])))
|
|
|
+ const zipFileReader = new ZipReader(new BlobReader(new Blob([arrayBuffer])))
|
|
|
const entries = await zipFileReader.getEntries()
|
|
|
let rgEntry: any
|
|
|
for (const entry of entries) {
|
|
|
@@ -190,7 +190,7 @@ export namespace Ripgrep {
|
|
|
stderr: "Failed to extract rg.exe from zip archive",
|
|
|
})
|
|
|
}
|
|
|
- await Bun.write(filepath, await rgBlob.arrayBuffer())
|
|
|
+ await Filesystem.write(filepath, Buffer.from(await rgBlob.arrayBuffer()))
|
|
|
await zipFileReader.close()
|
|
|
}
|
|
|
await fs.unlink(archivePath)
|