From c99021d5a3d2dba3e3a2fb30a441d1c6537c8d70 Mon Sep 17 00:00:00 2001 From: claude-code-best Date: Sat, 4 Apr 2026 17:02:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=B0=9D=E8=AF=95=E4=BF=AE=E5=A4=8D=20w?= =?UTF-8?q?indows=20=E4=B8=8B=E9=9D=A2=E6=B2=A1=E6=9C=89=20unzip=20?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/download-ripgrep.ts | 45 +++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/scripts/download-ripgrep.ts b/scripts/download-ripgrep.ts index 4582f38a4..edf12c3d7 100644 --- a/scripts/download-ripgrep.ts +++ b/scripts/download-ripgrep.ts @@ -248,6 +248,7 @@ async function downloadAndExtract(): Promise { rmSync(tmpDir, { recursive: true, force: true }) } } else { + let fflateError: unknown try { const { unzipSync } = await import('fflate') const unzipped = unzipSync(new Uint8Array(buffer)) @@ -256,20 +257,50 @@ async function downloadAndExtract(): Promise { throw new Error(`Binary ${extractedBinary} not found in zip`) } writeFileSync(binaryPath, Buffer.from(unzipped[key])) - } catch { - // No fflate or bad archive — try `unzip` CLI (common on Unix / Git for Windows) + fflateError = undefined + } catch (e) { + fflateError = e + } + + if (fflateError) { + // fflate failed — try PowerShell Expand-Archive on Windows, then unzip CLI const tmpDir = path.join(binaryDir, '.tmp-download') rmSync(tmpDir, { recursive: true, force: true }) mkdirSync(tmpDir, { recursive: true }) try { const archivePath = path.join(tmpDir, assetName) writeFileSync(archivePath, buffer) - const result = spawnSync('unzip', ['-o', archivePath, '-d', tmpDir], { - stdio: 'pipe', - }) - if (result.status !== 0) { - throw new Error(`unzip failed: ${result.stderr?.toString()}`) + + let extracted = false + + // On Windows, prefer PowerShell Expand-Archive + if (process.platform === 'win32') { + const psCmd = `Expand-Archive -Path '${archivePath.replace(/'/g, "''")}' -DestinationPath '${tmpDir.replace(/'/g, "''")}' -Force` + const psResult = spawnSync( + 'powershell.exe', + ['-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass', '-Command', psCmd], + { stdio: 'pipe', windowsHide: true }, + ) + if (psResult.status === 0) { + extracted = true + } else { + const psErr = psResult.stderr?.toString().trim() || 'unknown error' + console.log(`[ripgrep] PowerShell Expand-Archive failed: ${psErr}`) + } } + + // Fallback: unzip CLI (Git for Windows, MSYS2, or Unix) + if (!extracted) { + const result = spawnSync('unzip', ['-o', archivePath, '-d', tmpDir], { + stdio: 'pipe', + }) + if (result.status !== 0) { + const unzipErr = result.stderr?.toString().trim() || 'command not found' + const fflateMsg = fflateError instanceof Error ? fflateError.message : String(fflateError) + throw new Error(`zip extraction failed (fflate: ${fflateMsg}; unzip: ${unzipErr})`) + } + } + const srcBinary = path.join(tmpDir, extractedBinary) if (!existsSync(srcBinary)) { throw new Error(`Binary not found at expected path: ${srcBinary}`)