near-cli-rs 0.14.0 → 0.14.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitignore +1 -0
- package/CHANGELOG.md +14 -0
- package/README.md +1 -1
- package/binary-install.js +141 -0
- package/binary.js +56 -69
- package/npm-shrinkwrap.json +647 -211
- package/package.json +84 -22
- package/run-near.js +4 -0
- package/run.js +0 -4
package/.gitignore
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.14.2](https://github.com/near/near-cli-rs/compare/v0.14.1...v0.14.2) - 2024-08-21
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- Upgraded cargo-dist to 0.21.1 and enabled Linux ARM64 build ([#397](https://github.com/near/near-cli-rs/pull/397))
|
|
14
|
+
- Prioritize searching an access key in the signer account subfolder (<credentials-dir>/<network>/<account-id>/*.json) in legacy keychain and then fallback to <credentials-dir>/<network>/<account-id>.json instead of the other way around ([#396](https://github.com/near/near-cli-rs/pull/396))
|
|
15
|
+
|
|
16
|
+
### Other
|
|
17
|
+
- Fixed the one-liner curl installation command
|
|
18
|
+
|
|
19
|
+
## [0.14.1](https://github.com/near/near-cli-rs/compare/v0.14.0...v0.14.1) - 2024-08-15
|
|
20
|
+
|
|
21
|
+
### Fixed
|
|
22
|
+
- Fixed native operating system keychain support that got broken with 0.14.0 release ([#392](https://github.com/near/near-cli-rs/pull/392))
|
|
23
|
+
|
|
10
24
|
## [0.14.0](https://github.com/near/near-cli-rs/compare/v0.13.0...v0.14.0) - 2024-08-13
|
|
11
25
|
|
|
12
26
|
### Fixed
|
package/README.md
CHANGED
|
@@ -35,7 +35,7 @@ https://github.com/user-attachments/assets/7d5d090e-4885-4c27-9d0f-045905952071
|
|
|
35
35
|
<summary>Install via shell script (macOS, Linux, Windows/WSL)</summary>
|
|
36
36
|
|
|
37
37
|
```sh
|
|
38
|
-
|
|
38
|
+
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/near/near-cli-rs/releases/latest/download/near-cli-rs-installer.sh | sh
|
|
39
39
|
```
|
|
40
40
|
</details>
|
|
41
41
|
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
const { existsSync, mkdirSync } = require("fs");
|
|
2
|
+
const { join } = require("path");
|
|
3
|
+
const { spawnSync } = require("child_process");
|
|
4
|
+
|
|
5
|
+
const axios = require("axios");
|
|
6
|
+
const tar = require("tar");
|
|
7
|
+
const rimraf = require("rimraf");
|
|
8
|
+
|
|
9
|
+
const error = (msg) => {
|
|
10
|
+
console.error(msg);
|
|
11
|
+
process.exit(1);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
class Package {
|
|
15
|
+
constructor(name, url, binaries) {
|
|
16
|
+
let errors = [];
|
|
17
|
+
if (typeof url !== "string") {
|
|
18
|
+
errors.push("url must be a string");
|
|
19
|
+
} else {
|
|
20
|
+
try {
|
|
21
|
+
new URL(url);
|
|
22
|
+
} catch (e) {
|
|
23
|
+
errors.push(e);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (name && typeof name !== "string") {
|
|
27
|
+
errors.push("package name must be a string");
|
|
28
|
+
}
|
|
29
|
+
if (!name) {
|
|
30
|
+
errors.push("You must specify the name of your package");
|
|
31
|
+
}
|
|
32
|
+
if (binaries && typeof binaries !== "object") {
|
|
33
|
+
errors.push("binaries must be a string => string map");
|
|
34
|
+
}
|
|
35
|
+
if (!binaries) {
|
|
36
|
+
errors.push("You must specify the binaries in the package");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (errors.length > 0) {
|
|
40
|
+
let errorMsg =
|
|
41
|
+
"One or more of the parameters you passed to the Binary constructor are invalid:\n";
|
|
42
|
+
errors.forEach((error) => {
|
|
43
|
+
errorMsg += error;
|
|
44
|
+
});
|
|
45
|
+
errorMsg +=
|
|
46
|
+
'\n\nCorrect usage: new Package("my-binary", "https://example.com/binary/download.tar.gz", {"my-binary": "my-binary"})';
|
|
47
|
+
error(errorMsg);
|
|
48
|
+
}
|
|
49
|
+
this.url = url;
|
|
50
|
+
this.name = name;
|
|
51
|
+
this.installDirectory = join(__dirname, "node_modules", ".bin_real");
|
|
52
|
+
this.binaries = binaries;
|
|
53
|
+
|
|
54
|
+
if (!existsSync(this.installDirectory)) {
|
|
55
|
+
mkdirSync(this.installDirectory, { recursive: true });
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
exists() {
|
|
60
|
+
for (const binaryName in this.binaries) {
|
|
61
|
+
const binRelPath = this.binaries[binaryName];
|
|
62
|
+
const binPath = join(this.installDirectory, binRelPath);
|
|
63
|
+
if (!existsSync(binPath)) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
install(fetchOptions, suppressLogs = false) {
|
|
71
|
+
if (this.exists()) {
|
|
72
|
+
if (!suppressLogs) {
|
|
73
|
+
console.error(
|
|
74
|
+
`${this.name} is already installed, skipping installation.`,
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
return Promise.resolve();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (existsSync(this.installDirectory)) {
|
|
81
|
+
rimraf.sync(this.installDirectory);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
mkdirSync(this.installDirectory, { recursive: true });
|
|
85
|
+
|
|
86
|
+
if (!suppressLogs) {
|
|
87
|
+
console.error(`Downloading release from ${this.url}`);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return axios({ ...fetchOptions, url: this.url, responseType: "stream" })
|
|
91
|
+
.then((res) => {
|
|
92
|
+
return new Promise((resolve, reject) => {
|
|
93
|
+
const sink = res.data.pipe(
|
|
94
|
+
tar.x({ strip: 1, C: this.installDirectory }),
|
|
95
|
+
);
|
|
96
|
+
sink.on("finish", () => resolve());
|
|
97
|
+
sink.on("error", (err) => reject(err));
|
|
98
|
+
});
|
|
99
|
+
})
|
|
100
|
+
.then(() => {
|
|
101
|
+
if (!suppressLogs) {
|
|
102
|
+
console.error(`${this.name} has been installed!`);
|
|
103
|
+
}
|
|
104
|
+
})
|
|
105
|
+
.catch((e) => {
|
|
106
|
+
error(`Error fetching release: ${e.message}`);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
run(binaryName, fetchOptions) {
|
|
111
|
+
const promise = !this.exists()
|
|
112
|
+
? this.install(fetchOptions, true)
|
|
113
|
+
: Promise.resolve();
|
|
114
|
+
|
|
115
|
+
promise
|
|
116
|
+
.then(() => {
|
|
117
|
+
const [, , ...args] = process.argv;
|
|
118
|
+
|
|
119
|
+
const options = { cwd: process.cwd(), stdio: "inherit" };
|
|
120
|
+
|
|
121
|
+
const binRelPath = this.binaries[binaryName];
|
|
122
|
+
if (!binRelPath) {
|
|
123
|
+
error(`${binaryName} is not a known binary in ${this.name}`);
|
|
124
|
+
}
|
|
125
|
+
const binPath = join(this.installDirectory, binRelPath);
|
|
126
|
+
const result = spawnSync(binPath, args, options);
|
|
127
|
+
|
|
128
|
+
if (result.error) {
|
|
129
|
+
error(result.error);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
process.exit(result.status);
|
|
133
|
+
})
|
|
134
|
+
.catch((e) => {
|
|
135
|
+
error(e.message);
|
|
136
|
+
process.exit(1);
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
module.exports.Package = Package;
|
package/binary.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const { Package } = require("./binary-install");
|
|
2
2
|
const os = require("os");
|
|
3
3
|
const cTable = require("console.table");
|
|
4
4
|
const libc = require("detect-libc");
|
|
@@ -9,57 +9,37 @@ const error = (msg) => {
|
|
|
9
9
|
process.exit(1);
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
const {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
"artifact_name": "near-cli-rs-aarch64-apple-darwin.tar.gz",
|
|
22
|
-
"bins": ["near"],
|
|
23
|
-
"zip_ext": ".tar.gz"
|
|
24
|
-
},
|
|
25
|
-
"x86_64-apple-darwin": {
|
|
26
|
-
"artifact_name": "near-cli-rs-x86_64-apple-darwin.tar.gz",
|
|
27
|
-
"bins": ["near"],
|
|
28
|
-
"zip_ext": ".tar.gz"
|
|
29
|
-
},
|
|
30
|
-
"x86_64-pc-windows-msvc": {
|
|
31
|
-
"artifact_name": "near-cli-rs-x86_64-pc-windows-msvc.tar.gz",
|
|
32
|
-
"bins": ["near.exe"],
|
|
33
|
-
"zip_ext": ".tar.gz"
|
|
34
|
-
},
|
|
35
|
-
"x86_64-unknown-linux-gnu": {
|
|
36
|
-
"artifact_name": "near-cli-rs-x86_64-unknown-linux-gnu.tar.gz",
|
|
37
|
-
"bins": ["near"],
|
|
38
|
-
"zip_ext": ".tar.gz"
|
|
39
|
-
}
|
|
40
|
-
};
|
|
12
|
+
const {
|
|
13
|
+
name,
|
|
14
|
+
artifactDownloadUrl,
|
|
15
|
+
supportedPlatforms,
|
|
16
|
+
glibcMinimum,
|
|
17
|
+
} = require("./package.json");
|
|
18
|
+
|
|
19
|
+
const builderGlibcMajorVersion = glibcMinimum.major;
|
|
20
|
+
const builderGlibcMInorVersion = glibcMinimum.series;
|
|
41
21
|
|
|
42
22
|
const getPlatform = () => {
|
|
43
|
-
const
|
|
44
|
-
const
|
|
23
|
+
const rawOsType = os.type();
|
|
24
|
+
const rawArchitecture = os.arch();
|
|
45
25
|
|
|
46
26
|
// We want to use rust-style target triples as the canonical key
|
|
47
27
|
// for a platform, so translate the "os" library's concepts into rust ones
|
|
48
|
-
let
|
|
49
|
-
switch (
|
|
28
|
+
let osType = "";
|
|
29
|
+
switch (rawOsType) {
|
|
50
30
|
case "Windows_NT":
|
|
51
|
-
|
|
31
|
+
osType = "pc-windows-msvc";
|
|
52
32
|
break;
|
|
53
33
|
case "Darwin":
|
|
54
|
-
|
|
34
|
+
osType = "apple-darwin";
|
|
55
35
|
break;
|
|
56
36
|
case "Linux":
|
|
57
|
-
|
|
37
|
+
osType = "unknown-linux-gnu";
|
|
58
38
|
break;
|
|
59
39
|
}
|
|
60
40
|
|
|
61
41
|
let arch = "";
|
|
62
|
-
switch (
|
|
42
|
+
switch (rawArchitecture) {
|
|
63
43
|
case "x64":
|
|
64
44
|
arch = "x86_64";
|
|
65
45
|
break;
|
|
@@ -68,70 +48,77 @@ const getPlatform = () => {
|
|
|
68
48
|
break;
|
|
69
49
|
}
|
|
70
50
|
|
|
71
|
-
if (
|
|
72
|
-
if (libc.familySync() ==
|
|
73
|
-
|
|
51
|
+
if (rawOsType === "Linux") {
|
|
52
|
+
if (libc.familySync() == "musl") {
|
|
53
|
+
osType = "unknown-linux-musl-dynamic";
|
|
74
54
|
} else if (libc.isNonGlibcLinuxSync()) {
|
|
75
|
-
|
|
76
|
-
|
|
55
|
+
console.warn(
|
|
56
|
+
"Your libc is neither glibc nor musl; trying static musl binary instead",
|
|
57
|
+
);
|
|
58
|
+
osType = "unknown-linux-musl-static";
|
|
77
59
|
} else {
|
|
78
|
-
let
|
|
79
|
-
let
|
|
80
|
-
let
|
|
81
|
-
let
|
|
60
|
+
let libcVersion = libc.versionSync();
|
|
61
|
+
let splitLibcVersion = libcVersion.split(".");
|
|
62
|
+
let libcMajorVersion = splitLibcVersion[0];
|
|
63
|
+
let libcMinorVersion = splitLibcVersion[1];
|
|
82
64
|
if (
|
|
83
|
-
|
|
84
|
-
|
|
65
|
+
libcMajorVersion != builderGlibcMajorVersion ||
|
|
66
|
+
libcMinorVersion < builderGlibcMInorVersion
|
|
85
67
|
) {
|
|
86
68
|
// We can't run the glibc binaries, but we can run the static musl ones
|
|
87
69
|
// if they exist
|
|
88
|
-
console.warn(
|
|
89
|
-
|
|
70
|
+
console.warn(
|
|
71
|
+
"Your glibc isn't compatible; trying static musl binary instead",
|
|
72
|
+
);
|
|
73
|
+
osType = "unknown-linux-musl-static";
|
|
90
74
|
}
|
|
91
75
|
}
|
|
92
76
|
}
|
|
93
77
|
|
|
94
78
|
// Assume the above succeeded and build a target triple to look things up with.
|
|
95
79
|
// If any of it failed, this lookup will fail and we'll handle it like normal.
|
|
96
|
-
let
|
|
97
|
-
let platform = supportedPlatforms[
|
|
80
|
+
let targetTriple = `${arch}-${osType}`;
|
|
81
|
+
let platform = supportedPlatforms[targetTriple];
|
|
98
82
|
|
|
99
83
|
if (!platform) {
|
|
100
84
|
error(
|
|
101
|
-
`Platform with type "${
|
|
85
|
+
`Platform with type "${rawOsType}" and architecture "${rawArchitecture}" is not supported by ${name}.\nYour system must be one of the following:\n\n${Object.keys(
|
|
86
|
+
supportedPlatforms,
|
|
87
|
+
).join(",")}`,
|
|
102
88
|
);
|
|
103
89
|
}
|
|
104
90
|
|
|
105
91
|
return platform;
|
|
106
92
|
};
|
|
107
93
|
|
|
108
|
-
const
|
|
94
|
+
const getPackage = () => {
|
|
109
95
|
const platform = getPlatform();
|
|
110
|
-
const url = `${
|
|
111
|
-
|
|
112
|
-
if (platform.bins.length > 1) {
|
|
113
|
-
// Not yet supported
|
|
114
|
-
error("this app has multiple binaries, which isn't yet implemented");
|
|
115
|
-
}
|
|
116
|
-
let binary = new Binary(platform.bins[0], url);
|
|
96
|
+
const url = `${artifactDownloadUrl}/${platform.artifactName}`;
|
|
97
|
+
let binary = new Package(name, url, platform.bins);
|
|
117
98
|
|
|
118
99
|
return binary;
|
|
119
100
|
};
|
|
120
101
|
|
|
121
102
|
const install = (suppressLogs) => {
|
|
122
|
-
|
|
123
|
-
|
|
103
|
+
if (!artifactDownloadUrl || artifactDownloadUrl.length === 0) {
|
|
104
|
+
console.warn("in demo mode, not installing binaries");
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const package = getPackage();
|
|
108
|
+
const proxy = configureProxy(package.url);
|
|
124
109
|
|
|
125
|
-
return
|
|
110
|
+
return package.install(proxy, suppressLogs);
|
|
126
111
|
};
|
|
127
112
|
|
|
128
|
-
const run = () => {
|
|
129
|
-
const
|
|
130
|
-
|
|
113
|
+
const run = (binaryName) => {
|
|
114
|
+
const package = getPackage();
|
|
115
|
+
const proxy = configureProxy(package.url);
|
|
116
|
+
|
|
117
|
+
package.run(binaryName, proxy);
|
|
131
118
|
};
|
|
132
119
|
|
|
133
120
|
module.exports = {
|
|
134
121
|
install,
|
|
135
122
|
run,
|
|
136
|
-
|
|
123
|
+
getPackage,
|
|
137
124
|
};
|