@lijuneleven/easy-terminal 0.1.7 → 0.1.8
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/package.json +1 -1
- package/scripts/install.js +47 -2
package/package.json
CHANGED
package/scripts/install.js
CHANGED
|
@@ -4,6 +4,7 @@ const fs = require("fs");
|
|
|
4
4
|
const path = require("path");
|
|
5
5
|
const http = require("http");
|
|
6
6
|
const https = require("https");
|
|
7
|
+
const { spawn } = require("child_process");
|
|
7
8
|
const { pipeline } = require("stream/promises");
|
|
8
9
|
const { createWriteStream } = require("fs");
|
|
9
10
|
|
|
@@ -15,7 +16,7 @@ const giteeRepo = process.env.EASY_TERMINAL_GITEE_REPO || "eleven_lj/easy_termin
|
|
|
15
16
|
const version = packageJson.version;
|
|
16
17
|
const platform = process.platform;
|
|
17
18
|
const arch = process.arch;
|
|
18
|
-
const requestTimeoutMs = Number(process.env.EASY_TERMINAL_DOWNLOAD_TIMEOUT_MS ||
|
|
19
|
+
const requestTimeoutMs = Number(process.env.EASY_TERMINAL_DOWNLOAD_TIMEOUT_MS || 120000);
|
|
19
20
|
|
|
20
21
|
const platformMap = {
|
|
21
22
|
darwin: "darwin",
|
|
@@ -89,6 +90,45 @@ async function download(downloadUrl, redirects = 0) {
|
|
|
89
90
|
}
|
|
90
91
|
}
|
|
91
92
|
|
|
93
|
+
async function downloadWithCurl(downloadUrl) {
|
|
94
|
+
await fs.promises.mkdir(vendorDir, { recursive: true });
|
|
95
|
+
|
|
96
|
+
await new Promise((resolve, reject) => {
|
|
97
|
+
const timeoutSeconds = Math.max(1, Math.ceil(requestTimeoutMs / 1000));
|
|
98
|
+
const child = spawn("curl", [
|
|
99
|
+
"-fL",
|
|
100
|
+
"--connect-timeout",
|
|
101
|
+
"20",
|
|
102
|
+
"--max-time",
|
|
103
|
+
String(timeoutSeconds),
|
|
104
|
+
"-H",
|
|
105
|
+
"User-Agent: easy-terminal-npm",
|
|
106
|
+
"-o",
|
|
107
|
+
outPath,
|
|
108
|
+
downloadUrl
|
|
109
|
+
], {
|
|
110
|
+
stdio: ["ignore", "ignore", "pipe"]
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
let stderr = "";
|
|
114
|
+
child.stderr.on("data", (chunk) => {
|
|
115
|
+
stderr += chunk.toString();
|
|
116
|
+
});
|
|
117
|
+
child.on("error", reject);
|
|
118
|
+
child.on("exit", (code) => {
|
|
119
|
+
if (code === 0) {
|
|
120
|
+
resolve();
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
reject(new Error((stderr.trim() || `curl exited with code ${code}`).split("\n").slice(-1)[0]));
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
if (targetPlatform !== "windows") {
|
|
128
|
+
await fs.promises.chmod(outPath, 0o755);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
92
132
|
async function main() {
|
|
93
133
|
const failures = [];
|
|
94
134
|
|
|
@@ -96,7 +136,12 @@ async function main() {
|
|
|
96
136
|
try {
|
|
97
137
|
console.log(`[easy-terminal] downloading ${assetName}`);
|
|
98
138
|
console.log(`[easy-terminal] source: ${url}`);
|
|
99
|
-
|
|
139
|
+
try {
|
|
140
|
+
await downloadWithCurl(url);
|
|
141
|
+
} catch (curlErr) {
|
|
142
|
+
console.warn(`[easy-terminal] curl download failed, trying node downloader`);
|
|
143
|
+
await download(url);
|
|
144
|
+
}
|
|
100
145
|
console.log(`[easy-terminal] installed binary to ${outPath}`);
|
|
101
146
|
return;
|
|
102
147
|
} catch (err) {
|