Skip to content
Open
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: 12 additions & 9 deletions npm-install/postinstall.js
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -35,15 +35,18 @@ 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);
}

const tarFile = "downloaded.tar.gz";

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);
}

Expand All @@ -54,4 +57,4 @@ install()
.catch(async (err) => {
console.error(err);
process.exit(1);
});
});
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
Loading