mirror of
https://github.com/sst/opencode.git
synced 2025-12-23 10:11:41 +00:00
Replaced unzip with PowerShell on Windows
Co-authored-by: thdxr <thdxr@users.noreply.github.com>
This commit is contained in:
parent
31e0326f78
commit
f63baed573
3 changed files with 80 additions and 22 deletions
|
|
@ -80,17 +80,41 @@ export namespace Fzf {
|
|||
})
|
||||
}
|
||||
if (config.extension === "zip") {
|
||||
const proc = Bun.spawn(["unzip", "-j", archivePath, "fzf.exe", "-d", Global.Path.bin], {
|
||||
cwd: Global.Path.bin,
|
||||
stderr: "pipe",
|
||||
stdout: "ignore",
|
||||
})
|
||||
await proc.exited
|
||||
if (proc.exitCode !== 0)
|
||||
throw new ExtractionFailedError({
|
||||
filepath: archivePath,
|
||||
stderr: await Bun.readableStreamToText(proc.stderr),
|
||||
if (process.platform === "win32") {
|
||||
const powershellCommand = `
|
||||
Add-Type -AssemblyName System.IO.Compression.FileSystem;
|
||||
$zip = [System.IO.Compression.ZipFile]::OpenRead('${archivePath.replace(/\\/g, '\\\\')}');
|
||||
$entry = $zip.Entries | Where-Object { $_.Name -eq 'fzf.exe' };
|
||||
if ($entry) {
|
||||
[System.IO.Compression.ZipFileExtensions]::ExtractToFile($entry, '${path.join(Global.Path.bin, 'fzf.exe').replace(/\\/g, '\\\\')}', $true);
|
||||
}
|
||||
$zip.Dispose();
|
||||
`.trim()
|
||||
|
||||
const proc = Bun.spawn(["powershell", "-Command", powershellCommand], {
|
||||
cwd: Global.Path.bin,
|
||||
stderr: "pipe",
|
||||
stdout: "ignore",
|
||||
})
|
||||
await proc.exited
|
||||
if (proc.exitCode !== 0)
|
||||
throw new ExtractionFailedError({
|
||||
filepath: archivePath,
|
||||
stderr: await Bun.readableStreamToText(proc.stderr),
|
||||
})
|
||||
} else {
|
||||
const proc = Bun.spawn(["unzip", "-j", archivePath, "fzf.exe", "-d", Global.Path.bin], {
|
||||
cwd: Global.Path.bin,
|
||||
stderr: "pipe",
|
||||
stdout: "ignore",
|
||||
})
|
||||
await proc.exited
|
||||
if (proc.exitCode !== 0)
|
||||
throw new ExtractionFailedError({
|
||||
filepath: archivePath,
|
||||
stderr: await Bun.readableStreamToText(proc.stderr),
|
||||
})
|
||||
}
|
||||
}
|
||||
await fs.unlink(archivePath)
|
||||
if (process.platform !== "win32") await fs.chmod(filepath, 0o755)
|
||||
|
|
|
|||
|
|
@ -161,17 +161,41 @@ export namespace Ripgrep {
|
|||
})
|
||||
}
|
||||
if (config.extension === "zip") {
|
||||
const proc = Bun.spawn(["unzip", "-j", archivePath, "*/rg.exe", "-d", Global.Path.bin], {
|
||||
cwd: Global.Path.bin,
|
||||
stderr: "pipe",
|
||||
stdout: "ignore",
|
||||
})
|
||||
await proc.exited
|
||||
if (proc.exitCode !== 0)
|
||||
throw new ExtractionFailedError({
|
||||
filepath: archivePath,
|
||||
stderr: await Bun.readableStreamToText(proc.stderr),
|
||||
if (process.platform === "win32") {
|
||||
const powershellCommand = `
|
||||
Add-Type -AssemblyName System.IO.Compression.FileSystem;
|
||||
$zip = [System.IO.Compression.ZipFile]::OpenRead('${archivePath.replace(/\\/g, '\\\\')}');
|
||||
$entry = $zip.Entries | Where-Object { $_.Name -eq 'rg.exe' };
|
||||
if ($entry) {
|
||||
[System.IO.Compression.ZipFileExtensions]::ExtractToFile($entry, '${path.join(Global.Path.bin, 'rg.exe').replace(/\\/g, '\\\\')}', $true);
|
||||
}
|
||||
$zip.Dispose();
|
||||
`.trim()
|
||||
|
||||
const proc = Bun.spawn(["powershell", "-Command", powershellCommand], {
|
||||
cwd: Global.Path.bin,
|
||||
stderr: "pipe",
|
||||
stdout: "ignore",
|
||||
})
|
||||
await proc.exited
|
||||
if (proc.exitCode !== 0)
|
||||
throw new ExtractionFailedError({
|
||||
filepath: archivePath,
|
||||
stderr: await Bun.readableStreamToText(proc.stderr),
|
||||
})
|
||||
} else {
|
||||
const proc = Bun.spawn(["unzip", "-j", archivePath, "*/rg.exe", "-d", Global.Path.bin], {
|
||||
cwd: Global.Path.bin,
|
||||
stderr: "pipe",
|
||||
stdout: "ignore",
|
||||
})
|
||||
await proc.exited
|
||||
if (proc.exitCode !== 0)
|
||||
throw new ExtractionFailedError({
|
||||
filepath: archivePath,
|
||||
stderr: await Bun.readableStreamToText(proc.stderr),
|
||||
})
|
||||
}
|
||||
}
|
||||
await fs.unlink(archivePath)
|
||||
if (!platformKey.endsWith("-win32")) await fs.chmod(filepath, 0o755)
|
||||
|
|
|
|||
|
|
@ -192,7 +192,12 @@ export namespace LSPServer {
|
|||
const zipPath = path.join(Global.Path.bin, "elixir-ls.zip")
|
||||
await Bun.file(zipPath).write(response)
|
||||
|
||||
await $`unzip -o -q ${zipPath}`.cwd(Global.Path.bin).nothrow()
|
||||
if (process.platform === "win32") {
|
||||
const powershellCommand = `Expand-Archive -Path '${zipPath.replace(/\\/g, '\\\\')}' -DestinationPath '${Global.Path.bin.replace(/\\/g, '\\\\')}' -Force`
|
||||
await $`powershell -Command "${powershellCommand}"`.cwd(Global.Path.bin).nothrow()
|
||||
} else {
|
||||
await $`unzip -o -q ${zipPath}`.cwd(Global.Path.bin).nothrow()
|
||||
}
|
||||
|
||||
await fs.rm(zipPath, {
|
||||
force: true,
|
||||
|
|
@ -294,7 +299,12 @@ export namespace LSPServer {
|
|||
await Bun.file(tempPath).write(downloadResponse)
|
||||
|
||||
if (ext === "zip") {
|
||||
await $`unzip -o -q ${tempPath}`.cwd(Global.Path.bin).nothrow()
|
||||
if (process.platform === "win32") {
|
||||
const powershellCommand = `Expand-Archive -Path '${tempPath.replace(/\\/g, '\\\\')}' -DestinationPath '${Global.Path.bin.replace(/\\/g, '\\\\')}' -Force`
|
||||
await $`powershell -Command "${powershellCommand}"`.cwd(Global.Path.bin).nothrow()
|
||||
} else {
|
||||
await $`unzip -o -q ${tempPath}`.cwd(Global.Path.bin).nothrow()
|
||||
}
|
||||
} else {
|
||||
await $`tar -xf ${tempPath}`.cwd(Global.Path.bin).nothrow()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue