diff --git a/npm-install/postinstall.js b/npm-install/postinstall.js index d3d82d2..dd9ddfd 100644 --- a/npm-install/postinstall.js +++ b/npm-install/postinstall.js @@ -1,9 +1,9 @@ -import { createWriteStream } from "fs"; -import * as fs from "fs/promises"; -import fetch from "node-fetch"; -import { pipeline } from "stream/promises"; -import tar from "tar"; -import { execSync } from "child_process"; +import { createReadStream, createWriteStream } from "node:fs"; +import * as fs from "node:fs/promises"; +import { pipeline } from "node:stream/promises"; +import { execSync } from "node:child_process"; +import { createGunzip } from "node:zlib"; +import { unpackTar } from "modern-tar/fs"; import { ARCH_MAPPING, CONFIG, PLATFORM_MAPPING } from "./config.js"; @@ -35,7 +35,7 @@ async function install() { console.log('fetching from URL', url) const response = await fetch(url); - if (!response.ok) { + if (!response.ok || !response.body) { throw new Error("Failed fetching the binary: " + response.statusText); } @@ -43,7 +43,10 @@ async function install() { await fs.mkdir(binPath, { recursive: true }); await pipeline(response.body, createWriteStream(tarFile)); - await tar.x({ file: tarFile, cwd: binPath }); + + const readStream = createReadStream(tarFile); + await pipeline(readStream, createGunzip(), unpackTar(binPath)); + await fs.rm(tarFile); } @@ -54,4 +57,4 @@ install() .catch(async (err) => { console.error(err); process.exit(1); - }); \ No newline at end of file + }); diff --git a/package.json b/package.json index 8b26057..5e655e0 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "url": "git+https://github.com/pb33f/openapi-changes.git" }, "engines": { - "node": ">=16.0.0" + "node": ">=18.0.0" }, "scripts": { "postinstall": "node ./npm-install/postinstall.js" @@ -24,8 +24,7 @@ ], "dependencies": { "adm-zip": "^0.5.10", - "node-fetch": "^3.2.10", - "tar": "^6.1.11" + "modern-tar": "^0.3.4" }, "bugs": { "url": "https://github.com/pb33f/openapi-changes/issues"