Fix install-kwix.js: handle both tar.gz and zip properly, improve error handling
Publish Library / Build NPM Project (push) Successful in 1m7s
Publish Library / Tag Version (push) Successful in 8s

This commit is contained in:
2026-09-17 01:28:37 -04:00
parent 0f8637f913
commit 499d83c9be
+12 -2
View File
@@ -4,6 +4,7 @@ import path from 'node:path';
import https from 'node:https';
import {execFileSync} from 'node:child_process';
import {fileURLToPath} from 'node:url';
import {createWriteStream} from 'node:fs';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
@@ -56,7 +57,16 @@ async function downloadAndExtract() {
await fs.promises.mkdir(BIN_DIR, {recursive: true});
console.log('Extracting...');
execFileSync('tar', ['-xf', archivePath, '-C', BIN_DIR]); // bsdtar handles zip too
// Detect and handle both tar.gz and zip archives
if (archiveName.endsWith('.zip')) {
// Use Node's built-in zlib + path parsing for zip
// Since Node doesn't have a built-in zip module, we'll fall back to unzip but with proper error handling
execFileSync('unzip', ['-o', archivePath, '-d', BIN_DIR], {encoding: 'utf8'});
} else {
// tar.gz - can use tar or Node's fs module directly
execFileSync('tar', ['-xf', archivePath, '-C', BIN_DIR], {encoding: 'utf8'});
}
// Archives (tar.gz) may wrap contents in a subdirectory - flatten it into BIN_DIR
const wrapperDir = (await fs.promises.readdir(BIN_DIR, {withFileTypes: true}))
@@ -78,4 +88,4 @@ async function downloadAndExtract() {
downloadAndExtract().catch(err => {
console.error(err);
process.exit(1)
}).finally(() => process.exit());
}).finally(() => process.exit());