From 46090d6e37a4b2fb35bbaf2224a67d17ad7af23b Mon Sep 17 00:00:00 2001 From: CreatorGhost Date: Sun, 12 Jul 2026 00:57:53 +0530 Subject: [PATCH] fix(core): extract zips with tar on Windows instead of Expand-Archive Ported from upstream anomalyco/opencode#36035. --- packages/core/src/ripgrep/binary.ts | 30 ++++++++------------------- packages/opencode/src/util/archive.ts | 10 +++++---- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/packages/core/src/ripgrep/binary.ts b/packages/core/src/ripgrep/binary.ts index 762a8e613ef0..9d5525376101 100644 --- a/packages/core/src/ripgrep/binary.ts +++ b/packages/core/src/ripgrep/binary.ts @@ -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, diff --git a/packages/opencode/src/util/archive.ts b/packages/opencode/src/util/archive.ts index 8fc549779393..af4c788918b8 100644 --- a/packages/opencode/src/util/archive.ts +++ b/packages/opencode/src/util/archive.ts @@ -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 }