Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 9 additions & 21 deletions packages/core/src/ripgrep/binary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,15 @@ export namespace RipgrepBinary {
) {
const dir = yield* fs.makeTempDirectoryScoped({ directory: Global.Path.bin, prefix: "ripgrep-" })

if (config.extension === "zip") {
const shell = (yield* Effect.sync(() => which("powershell.exe") ?? which("pwsh.exe"))) ?? "powershell.exe"
const result = yield* run(shell, [
"-NoProfile",
"-NonInteractive",
"-Command",
`$global:ProgressPreference = 'SilentlyContinue'; Expand-Archive -LiteralPath '${archive.replaceAll("'", "''")}' -DestinationPath '${dir.replaceAll("'", "''")}' -Force`,
])
if (result.code !== 0)
throw new Error(
result.stderr.trim() || result.stdout.trim() || `ripgrep extraction failed with code ${result.code}`,
)
}

if (config.extension === "tar.gz") {
const result = yield* run("tar", ["-xzf", archive, "-C", dir])
if (result.code !== 0)
throw new Error(
result.stderr.trim() || result.stdout.trim() || `ripgrep extraction failed with code ${result.code}`,
)
}
// zip is extracted with tar too: Windows ships bsdtar as tar.exe since
// Windows 10 1803 (Bun needs 1809+) and it reads zip natively. PowerShell's
// Expand-Archive can't be used: module autoload fails when powershell.exe
// is spawned from the Bun-compiled binary (#24291).
const result = yield* run("tar", [config.extension === "zip" ? "-xf" : "-xzf", archive, "-C", dir])
if (result.code !== 0)
throw new Error(
result.stderr.trim() || result.stdout.trim() || `ripgrep extraction failed with code ${result.code}`,
)

const extracted = path.join(
dir,
Expand Down
10 changes: 6 additions & 4 deletions packages/opencode/src/util/archive.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import fs from "fs/promises"
import path from "path"
import * as Process from "./process"

export async function extractZip(zipPath: string, destDir: string) {
if (process.platform === "win32") {
const winZipPath = path.resolve(zipPath)
// tar.exe (bsdtar) ships with Windows 10 1803+ (Bun needs 1809+) and extracts
// zip natively. PowerShell's Expand-Archive can't be used: module autoload
// fails when powershell.exe is spawned from the Bun-compiled binary (#24291).
const winDestDir = path.resolve(destDir)
// $global:ProgressPreference suppresses PowerShell's blue progress bar popup
const cmd = `$global:ProgressPreference = 'SilentlyContinue'; Expand-Archive -Path '${winZipPath}' -DestinationPath '${winDestDir}' -Force`
await Process.run(["powershell", "-NoProfile", "-NonInteractive", "-Command", cmd])
await fs.mkdir(winDestDir, { recursive: true })
await Process.run(["tar", "-xf", path.resolve(zipPath), "-C", winDestDir])
return
}

Expand Down
Loading