Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure installation directory exists before downloading binary #97

Merged
merged 2 commits into from
Sep 4, 2024
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
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