diff --git a/scripts/expand-macos-bundle.mjs b/scripts/expand-macos-bundle.mjs index 3246b78..13b494f 100644 --- a/scripts/expand-macos-bundle.mjs +++ b/scripts/expand-macos-bundle.mjs @@ -46,25 +46,32 @@ if (!existsSync(tarZstPath)) { process.exit(0); } -function findZstd() { - const fromPath = spawnSync("zstd", ["--version"], { encoding: "utf8" }); - if (fromPath.status === 0) { - return "zstd"; +function decompressTarZst(inputPath, outputPath) { + const systemZstd = spawnSync("zstd", ["--version"], { encoding: "utf8" }); + if (systemZstd.status === 0) { + return spawnSync("zstd", ["-d", "-f", "-o", outputPath, inputPath], { + stdio: "inherit", + }); } const hostArch = process.arch === "arm64" ? "arm64" : "x64"; - const electrobunZstd = path.join( + const zigZstd = path.join( rootDir, "node_modules/electrobun/dist-macos-" + hostArch, "zig-zstd", ); - if (existsSync(electrobunZstd)) { - return electrobunZstd; + if (existsSync(zigZstd)) { + return spawnSync( + zigZstd, + ["decompress", "-i", inputPath, "-o", outputPath, "--no-timing"], + { stdio: "inherit" }, + ); } - throw new Error( + console.error( "expand-macos-bundle: zstd not found (install zstd or use electrobun dist binaries)", ); + process.exit(1); } const workDir = path.join(tmpdir(), `farmcontrol-server-expand-${hash}`); @@ -72,10 +79,7 @@ const tarPath = path.join(workDir, `${hash}.tar`); rmSync(workDir, { recursive: true, force: true }); mkdirSync(workDir, { recursive: true }); -const zstd = findZstd(); -const decompress = spawnSync(zstd, ["-d", "-f", "-o", tarPath, tarZstPath], { - stdio: "inherit", -}); +const decompress = decompressTarZst(tarZstPath, tarPath); if (decompress.status !== 0) { console.error("expand-macos-bundle: zstd decompression failed");