@delta-infra/cli 1.0.34 → 1.0.35

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/scripts/install.js +128 -47
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@delta-infra/cli",
3
- "version": "1.0.34",
3
+ "version": "1.0.35",
4
4
  "description": "Delta Sandbox CLI",
5
5
  "bin": {
6
6
  "delta-cli": "scripts/run.js"
@@ -31,6 +31,13 @@ const REPO = "yzailab/delta-infra-cli";
31
31
  const DEFAULT_ALLOWED_HOSTS = new Set([
32
32
  "github.com",
33
33
  "gh-proxy.com",
34
+ "ghproxy.net",
35
+ "gh.ddlc.top",
36
+ "gh.llkk.cc",
37
+ "gh.dpik.top",
38
+ "gh.con.sh",
39
+ "slink.ltd",
40
+ "xget.xi-xu.me",
34
41
  "objects.githubusercontent.com",
35
42
  "release-assets.githubusercontent.com",
36
43
  "github-releases.githubusercontent.com",
@@ -75,17 +82,89 @@ function _getCurlTimeout() {
75
82
  return _curlTimeoutMs;
76
83
  }
77
84
 
78
- function releaseAssetUrls(version, assetName) {
85
+ // List of well-known GitHub release download mirrors.
86
+ // Format: [hostname, urlPrefix] — urlPrefix is prepended to the GitHub URL.
87
+ var _MIRROR_LIST = [
88
+ ["gh-proxy.com", "https://gh-proxy.com"],
89
+ ["ghproxy.net", "https://ghproxy.net"],
90
+ ["gh.ddlc.top", "https://gh.ddlc.top"],
91
+ ["gh.llkk.cc", "https://gh.llkk.cc"],
92
+ ["gh.dpik.top", "https://gh.dpik.top"],
93
+ ["gh.con.sh", "https://gh.con.sh"],
94
+ ["slink.ltd", "https://slink.ltd"],
95
+ ["xget.xi-xu.me", "https://xget.xi-xu.me"],
96
+ ];
97
+
98
+ // Quick connectivity check: fetch a small file (checksums.txt) from each
99
+ // mirror and return only the ones that respond within the probe timeout.
100
+ function probeMirrors(version, cb) {
101
+ var probeUrl = "/https://github.com/" + REPO + "/releases/download/v" + version + "/checksums.txt";
102
+ var results = [];
103
+ var pending = _MIRROR_LIST.length;
104
+ var done = false;
105
+
106
+ function finish() {
107
+ if (done) return;
108
+ done = true;
109
+ cb(results);
110
+ }
111
+
112
+ if (pending === 0) return finish();
113
+
114
+ for (var i = 0; i < _MIRROR_LIST.length; i++) {
115
+ (function(idx) {
116
+ var entry = _MIRROR_LIST[idx];
117
+ var host = entry[0];
118
+ var prefix = entry[1];
119
+ var testUrl = prefix + probeUrl;
120
+ var args = [
121
+ "--fail", "--location", "--silent", "--show-error",
122
+ "--connect-timeout", "3", "--max-time", "5",
123
+ "--output", "/dev/null", testUrl,
124
+ ];
125
+ var child;
126
+ try {
127
+ child = require("child_process").spawn("curl", args, { stdio: ["ignore", "pipe", "pipe"], timeout: 8000 });
128
+ var stdout = "";
129
+ var stderr = "";
130
+ child.stdout.on("data", function(d) { stdout += d; });
131
+ child.stderr.on("data", function(d) { stderr += d; });
132
+ child.on("close", function(code) {
133
+ if (code === 0) {
134
+ results.push(prefix + "/https://github.com/" + REPO + "/releases/download/v" + version + "/" + archiveName);
135
+ }
136
+ pending--;
137
+ if (pending === 0) finish();
138
+ });
139
+ child.on("error", function() {
140
+ pending--;
141
+ if (pending === 0) finish();
142
+ });
143
+ } catch (e) {
144
+ pending--;
145
+ if (pending === 0) finish();
146
+ }
147
+ })(i);
148
+ }
149
+ // Safety timeout: if probes hang, continue without mirrors after 10s
150
+ setTimeout(finish, 10000);
151
+ }
152
+
153
+ function releaseAssetUrls(version, assetName, cb) {
79
154
  var urls = [];
80
155
  var mirror = process.env.DELTA_CLI_MIRROR || "";
81
156
  if (mirror) {
82
157
  urls.push("" + mirror.replace(/\/$/, "") + "/yzailab/delta-infra-cli/releases/download/v" + version + "/" + assetName);
83
158
  }
84
- // gh-proxy.com China acceleration mirror (tried before GitHub source)
85
- urls.push("https://gh-proxy.com/https://github.com/yzailab/delta-infra-cli/releases/download/v" + version + "/" + assetName);
86
- // GitHub source
87
- urls.push(GITHUB_URL);
88
- return urls;
159
+ // Probe mirrors in parallel first, then fallback
160
+ probeMirrors(version, function(mirrorUrls) {
161
+ for (var i = 0; i < mirrorUrls.length; i++) {
162
+ urls.push(mirrorUrls[i]);
163
+ }
164
+ // GitHub source (last resort)
165
+ urls.push(GITHUB_URL);
166
+ cb(urls);
167
+ });
89
168
  }
90
169
 
91
170
  function assertAllowedHost(url) {
@@ -232,58 +311,60 @@ function verifyChecksum(archivePath, expectedHash) {
232
311
  // ── Main install ───────────────────────────────────────────────────────────
233
312
 
234
313
  function install() {
235
- const downloadUrls = releaseAssetUrls(VERSION, archiveName);
236
-
237
314
  fs.mkdirSync(binDir, { recursive: true });
238
- const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "delta-cli-"));
239
- const archivePath = path.join(tmpDir, archiveName);
315
+ var tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "delta-cli-"));
316
+ var archivePath = path.join(tmpDir, archiveName);
240
317
 
241
- try {
242
- let lastErr;
243
- let downloaded = false;
244
- for (const url of downloadUrls) {
245
- try {
246
- download(url, archivePath);
247
- downloaded = true;
248
- break;
249
- } catch (e) {
250
- lastErr = e;
318
+ releaseAssetUrls(VERSION, archiveName, function(downloadUrls) {
319
+ try {
320
+ var lastErr;
321
+ var downloaded = false;
322
+ for (var i = 0; i < downloadUrls.length; i++) {
323
+ try {
324
+ console.error("Downloading from " + downloadUrls[i]);
325
+ download(downloadUrls[i], archivePath);
326
+ downloaded = true;
327
+ break;
328
+ } catch (e) {
329
+ console.error("Failed: " + e.message);
330
+ lastErr = e;
331
+ }
251
332
  }
252
- }
253
- if (!downloaded) throw lastErr;
333
+ if (!downloaded) throw lastErr;
254
334
 
255
- const expectedHash = getExpectedChecksum(archiveName);
256
- verifyChecksum(archivePath, expectedHash);
335
+ const expectedHash = getExpectedChecksum(archiveName);
336
+ verifyChecksum(archivePath, expectedHash);
257
337
 
258
- if (isWindows) {
259
- extractZipWindows(archivePath, tmpDir);
260
- } else {
261
- execFileSync("tar", ["-xzf", archivePath, "-C", tmpDir], { stdio: "ignore" });
262
- }
338
+ if (isWindows) {
339
+ extractZipWindows(archivePath, tmpDir);
340
+ } else {
341
+ execFileSync("tar", ["-xzf", archivePath, "-C", tmpDir], { stdio: "ignore" });
342
+ }
263
343
 
264
- const binaryName = NAME + (isWindows ? ".exe" : "");
265
- const extractedBinary = path.join(tmpDir, `${NAME}-${platform}-${arch}`);
266
- if (fs.existsSync(extractedBinary)) {
267
- fs.copyFileSync(extractedBinary, dest);
268
- } else {
269
- // Fallback: try the plain name (older release format)
270
- const plainBinary = path.join(tmpDir, binaryName);
271
- if (fs.existsSync(plainBinary)) {
272
- fs.copyFileSync(plainBinary, dest);
344
+ const binaryName = NAME + (isWindows ? ".exe" : "");
345
+ const extractedBinary = path.join(tmpDir, NAME + "-" + platform + "-" + arch);
346
+ if (fs.existsSync(extractedBinary)) {
347
+ fs.copyFileSync(extractedBinary, dest);
273
348
  } else {
274
- // Search in tmpDir
275
- const files = fs.readdirSync(tmpDir).filter(f => f.includes(NAME) || f.includes(binaryName));
276
- if (files.length > 0) {
277
- fs.copyFileSync(path.join(tmpDir, files[0]), dest);
349
+ // Fallback: try the plain name (older release format)
350
+ const plainBinary = path.join(tmpDir, binaryName);
351
+ if (fs.existsSync(plainBinary)) {
352
+ fs.copyFileSync(plainBinary, dest);
278
353
  } else {
279
- throw new Error(`Binary not found in extracted archive. Files: ${fs.readdirSync(tmpDir).join(", ")}`);
354
+ // Search in tmpDir
355
+ const files = fs.readdirSync(tmpDir).filter(function(f) { return f.indexOf(NAME) !== -1 || f.indexOf(binaryName) !== -1; });
356
+ if (files.length > 0) {
357
+ fs.copyFileSync(path.join(tmpDir, files[0]), dest);
358
+ } else {
359
+ throw new Error("Binary not found in extracted archive. Files: " + fs.readdirSync(tmpDir).join(", "));
360
+ }
280
361
  }
281
362
  }
363
+ fs.chmodSync(dest, 0o755);
364
+ } finally {
365
+ fs.rmSync(tmpDir, { recursive: true, force: true });
282
366
  }
283
- fs.chmodSync(dest, 0o755);
284
- } finally {
285
- fs.rmSync(tmpDir, { recursive: true, force: true });
286
- }
367
+ });
287
368
  }
288
369
 
289
370
  // ── Entry ──────────────────────────────────────────────────────────────────