mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-22 16:25:51 +00:00
Merge branch 'claude-code-best:main' into main
This commit is contained in:
@@ -248,6 +248,7 @@ async function downloadAndExtract(): Promise<void> {
|
|||||||
rmSync(tmpDir, { recursive: true, force: true })
|
rmSync(tmpDir, { recursive: true, force: true })
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
let fflateError: unknown
|
||||||
try {
|
try {
|
||||||
const { unzipSync } = await import('fflate')
|
const { unzipSync } = await import('fflate')
|
||||||
const unzipped = unzipSync(new Uint8Array(buffer))
|
const unzipped = unzipSync(new Uint8Array(buffer))
|
||||||
@@ -256,20 +257,50 @@ async function downloadAndExtract(): Promise<void> {
|
|||||||
throw new Error(`Binary ${extractedBinary} not found in zip`)
|
throw new Error(`Binary ${extractedBinary} not found in zip`)
|
||||||
}
|
}
|
||||||
writeFileSync(binaryPath, Buffer.from(unzipped[key]))
|
writeFileSync(binaryPath, Buffer.from(unzipped[key]))
|
||||||
} catch {
|
fflateError = undefined
|
||||||
// No fflate or bad archive — try `unzip` CLI (common on Unix / Git for Windows)
|
} catch (e) {
|
||||||
|
fflateError = e
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fflateError) {
|
||||||
|
// fflate failed — try PowerShell Expand-Archive on Windows, then unzip CLI
|
||||||
const tmpDir = path.join(binaryDir, '.tmp-download')
|
const tmpDir = path.join(binaryDir, '.tmp-download')
|
||||||
rmSync(tmpDir, { recursive: true, force: true })
|
rmSync(tmpDir, { recursive: true, force: true })
|
||||||
mkdirSync(tmpDir, { recursive: true })
|
mkdirSync(tmpDir, { recursive: true })
|
||||||
try {
|
try {
|
||||||
const archivePath = path.join(tmpDir, assetName)
|
const archivePath = path.join(tmpDir, assetName)
|
||||||
writeFileSync(archivePath, buffer)
|
writeFileSync(archivePath, buffer)
|
||||||
const result = spawnSync('unzip', ['-o', archivePath, '-d', tmpDir], {
|
|
||||||
stdio: 'pipe',
|
let extracted = false
|
||||||
})
|
|
||||||
if (result.status !== 0) {
|
// On Windows, prefer PowerShell Expand-Archive
|
||||||
throw new Error(`unzip failed: ${result.stderr?.toString()}`)
|
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)
|
const srcBinary = path.join(tmpDir, extractedBinary)
|
||||||
if (!existsSync(srcBinary)) {
|
if (!existsSync(srcBinary)) {
|
||||||
throw new Error(`Binary not found at expected path: ${srcBinary}`)
|
throw new Error(`Binary not found at expected path: ${srcBinary}`)
|
||||||
|
|||||||
Reference in New Issue
Block a user