Skip to content

Commit

Permalink
fix: Ensure installation directory exists before downloading binary (#97
Browse files Browse the repository at this point in the history
)

  - 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.
  • Loading branch information
pivanov authored Sep 4, 2024
1 parent 221dddf commit 0e5c372
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
5 changes: 5 additions & 0 deletions npm/.changeset/olive-years-suffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"near-sandbox": minor
---

Ensure installation directory exists before downloading binary
5 changes: 3 additions & 2 deletions npm/dist/getBinary.js
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand All @@ -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") {
Expand Down
6 changes: 5 additions & 1 deletion npm/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions npm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
},
"files": [
"*.js",
"bin",
"dist/*.ts",
"dist/*.js"
]
Expand Down
7 changes: 6 additions & 1 deletion npm/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ export class Binary {
return join(this.installDir, this.name);
}

download(url: URL): Promise<void> {
async download(url: URL): Promise<void> {
// 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(),
Expand Down

0 comments on commit 0e5c372

Please sign in to comment.