diff --git a/scripts/expand-windows-installer.mjs b/scripts/expand-windows-installer.mjs index 120e37c..1061c9b 100644 --- a/scripts/expand-windows-installer.mjs +++ b/scripts/expand-windows-installer.mjs @@ -1,4 +1,5 @@ import { + cpSync, existsSync, mkdirSync, readdirSync, @@ -13,27 +14,8 @@ const rootDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..") const electrobunDir = path.join(rootDir, "node_modules/electrobun"); function findZstdDecompressCommand() { - const spawnOpts = process.platform === "win32" ? { shell: true } : {}; - - const systemZstd = spawnSync("zstd", ["--version"], { - encoding: "utf8", - ...spawnOpts, - }); - if (systemZstd.status === 0) { - return { - command: "zstd", - args: (inputPath, outputPath) => [ - "-d", - "-f", - "-o", - outputPath, - inputPath, - ], - }; - } - const hostArch = process.arch === "arm64" ? "arm64" : "x64"; - const candidates = [ + const zigCandidates = [ path.join(electrobunDir, `dist-win-${hostArch}`, "zig-zstd.exe"), path.join(electrobunDir, "dist-win-x64", "zig-zstd.exe"), path.join(electrobunDir, `dist-macos-${hostArch}`, "zig-zstd"), @@ -44,12 +26,13 @@ function findZstdDecompressCommand() { path.join(electrobunDir, "vendors", "zig-zstd", "arm64", "zig-zstd.exe"), ]; - for (const candidate of candidates) { + for (const candidate of zigCandidates) { if (!existsSync(candidate)) { continue; } return { + kind: "zig-zstd", command: candidate, args: (inputPath, outputPath) => [ "decompress", @@ -62,6 +45,24 @@ function findZstdDecompressCommand() { }; } + const systemZstd = spawnSync("zstd", ["--version"], { + encoding: "utf8", + shell: process.platform === "win32", + }); + if (systemZstd.status === 0) { + return { + kind: "system-zstd", + command: "zstd", + args: (inputPath, outputPath) => [ + "-d", + "-f", + "-o", + outputPath, + inputPath, + ], + }; + } + return null; } @@ -73,14 +74,23 @@ function decompressTarZst(inputPath, outputPath) { ); } - const result = spawnSync(zstd.command, zstd.args(inputPath, outputPath), { + const resolvedInput = path.resolve(inputPath); + const resolvedOutput = path.resolve(outputPath); + const args = zstd.args(resolvedInput, resolvedOutput); + + console.log( + `expand-windows-installer: decompressing with ${zstd.command} (${zstd.kind})`, + ); + + const result = spawnSync(zstd.command, args, { stdio: "inherit", - shell: process.platform === "win32", + shell: false, + windowsHide: true, }); if (result.status !== 0) { throw new Error( - `expand-windows-installer: decompression failed (exit ${result.status ?? 1})`, + `expand-windows-installer: decompression failed (exit ${result.status ?? 1}) using ${zstd.command} ${args.join(" ")}`, ); } } @@ -97,11 +107,14 @@ export function expandWindowsAppFromArchive(setupArchivePath, parentDir) { rmSync(workDir, { recursive: true, force: true }); mkdirSync(workDir, { recursive: true }); - decompressTarZst(resolvedArchive, tarPath); + const archiveForDecompress = path.join(workDir, "setup.tar.zst"); + cpSync(resolvedArchive, archiveForDecompress); + decompressTarZst(archiveForDecompress, tarPath); const extractTar = spawnSync("tar", ["-xf", tarPath, "-C", workDir], { stdio: "inherit", - shell: process.platform === "win32", + shell: false, + windowsHide: true, }); if (extractTar.status !== 0) {