From 0e5c3728ec3a06b19251e166a1f0ab9ce568aace Mon Sep 17 00:00:00 2001 From: Pavel Ivanov Date: Wed, 4 Sep 2024 11:25:21 +0300 Subject: [PATCH] fix: Ensure installation directory exists before downloading binary (#97) - Updated the `download` method in `Binary` class to be asynchronous. - Added a check to ensure the `installDir` directory exists before starting the download. - If the directory does not exist, it is created with `fs.mkdir` using the `recursive` option. - Add the `bin` folder in the npm package distribution, allowing necessary binaries to be available post-installation. --- npm/.changeset/olive-years-suffer.md | 5 +++++ npm/dist/getBinary.js | 5 +++-- npm/dist/index.js | 6 +++++- npm/package.json | 1 + npm/src/index.ts | 7 ++++++- 5 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 npm/.changeset/olive-years-suffer.md diff --git a/npm/.changeset/olive-years-suffer.md b/npm/.changeset/olive-years-suffer.md new file mode 100644 index 0000000..fa50922 --- /dev/null +++ b/npm/.changeset/olive-years-suffer.md @@ -0,0 +1,5 @@ +--- +"near-sandbox": minor +--- + +Ensure installation directory exists before downloading binary diff --git a/npm/dist/getBinary.js b/npm/dist/getBinary.js index f9c926e..a52827b 100644 --- a/npm/dist/getBinary.js +++ b/npm/dist/getBinary.js @@ -7,7 +7,8 @@ const os = require("os"); function getPlatform() { const type = os.type(); const arch = os.arch(); - if ((type === "Linux" || type === "Darwin") && arch === "x64") { + // Darwind x86_64 is not supported for quite some time :( + if (type === "Linux" && arch === "x64") { return [type, "x86_64"]; } else if (type === "Darwin" && arch === "arm64") { @@ -17,7 +18,7 @@ function getPlatform() { } function AWSUrl() { const [platform, arch] = getPlatform(); - return `https://s3-us-west-1.amazonaws.com/build.nearprotocol.com/nearcore/${platform}-${arch}/1.40.0/7dd0b5993577f592be15eb102e5a3da37be66271/near-sandbox.tar.gz`; + return `https://s3-us-west-1.amazonaws.com/build.nearprotocol.com/nearcore/${platform}-${arch}/2.1.1/near-sandbox.tar.gz`; } exports.AWSUrl = AWSUrl; function getBinary(name = "near-sandbox") { diff --git a/npm/dist/index.js b/npm/dist/index.js index 2ac735e..898165d 100644 --- a/npm/dist/index.js +++ b/npm/dist/index.js @@ -74,7 +74,11 @@ class Binary { get binPath() { return (0, path_1.join)(this.installDir, this.name); } - download(url) { + async download(url) { + // Ensure the install directory exists + if (!await (0, utils_1.fileExists)(this.installDir)) { + await fs.mkdir(this.installDir, { recursive: true }); + } return pipeline(got_1.default.stream(url), new stream.PassThrough(), tar.x({ strip: 1, C: this.installDir })); } async install() { diff --git a/npm/package.json b/npm/package.json index f95e6b7..3d78057 100644 --- a/npm/package.json +++ b/npm/package.json @@ -38,6 +38,7 @@ }, "files": [ "*.js", + "bin", "dist/*.ts", "dist/*.js" ] diff --git a/npm/src/index.ts b/npm/src/index.ts index 455bed3..bd41160 100644 --- a/npm/src/index.ts +++ b/npm/src/index.ts @@ -72,7 +72,12 @@ export class Binary { return join(this.installDir, this.name); } - download(url: URL): Promise { + async download(url: URL): Promise { + // Ensure the install directory exists + if (!await fileExists(this.installDir)) { + await fs.mkdir(this.installDir, { recursive: true }); + } + return pipeline( got.stream(url), new stream.PassThrough(),