Refactor zstd decompression in expand-macos-bundle script
Some checks failed
farmcontrol/farmcontrol-server/pipeline/head There was a failure building this commit

- Replaced the findZstd function with a new decompressTarZst function to streamline the zstd decompression process.
- Improved error handling by logging an error message and exiting the process if zstd is not found.
- Updated the script to directly call the new decompression function, enhancing clarity and maintainability.
This commit is contained in:
Tom Butcher 2026-08-01 21:39:47 +01:00
parent cda0286db7
commit 3107a517c3

View File

@ -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");