Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions install.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import { mkdir, unlink, chmod } from 'node:fs/promises';
import { createWriteStream } from 'node:fs';
import { pipeline } from 'node:stream/promises';
import { Readable } from 'node:stream';
import { execFile } from 'node:child_process';
import { promisify } from 'node:util';
import { fileURLToPath } from 'node:url';
import { createRequire } from 'node:module';
import StreamZip from 'node-stream-zip';
import tar from 'tar';
import { x as extractTar } from 'tar';

const execFileAsync = promisify(execFile);
const require = createRequire(import.meta.url);
const pkg = require('./package.json');
const __dirname = path.dirname(fileURLToPath(import.meta.url));
Expand Down Expand Up @@ -87,13 +89,10 @@ async function downloadFile(url, destination) {
await pipeline(body, createWriteStream(destination));
}

async function extractZip(zipPath, destDir) {
const zip = new StreamZip.async({ file: zipPath });
try {
await zip.extract(undefined, destDir);
} finally {
await zip.close();
}
// Windows 10 build 17063+ (April 2018) ships bsdtar as tar.exe and can extract
// a .zip in place. We use that instead of pulling in a JS zip dependency.
async function extractZipWindows(zipPath, destDir) {
await execFileAsync('tar', ['-xf', zipPath, '-C', destDir]);
}

async function tryUnlink(p) {
Expand Down Expand Up @@ -137,8 +136,8 @@ async function install() {
await downloadFile(url, archivePath);

await (isWindows
? extractZip(archivePath, vendorDir)
: tar.x({ file: archivePath, cwd: vendorDir }));
? extractZipWindows(archivePath, vendorDir)
: extractTar({ file: archivePath, cwd: vendorDir }));

await unlink(archivePath);
await chmod(binPath, 0o755);
Expand Down
Loading
Loading