@0xobelisk/sui-cli 1.2.0-pre.42 → 1.2.0-pre.43

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xobelisk/sui-cli",
3
- "version": "1.2.0-pre.42",
3
+ "version": "1.2.0-pre.43",
4
4
  "description": "Tookit for interacting with move eps framework",
5
5
  "keywords": [
6
6
  "sui",
@@ -43,6 +43,8 @@
43
43
  "ejs": "^3.1.8",
44
44
  "execa": "^7.0.0",
45
45
  "glob": "^8.0.3",
46
+ "http-proxy-agent": "^7.0.2",
47
+ "https-proxy-agent": "^7.0.6",
46
48
  "inquirer": "^9.2.15",
47
49
  "ora": "^5.4.1",
48
50
  "path": "^0.12.7",
@@ -53,8 +55,8 @@
53
55
  "yargs": "^17.7.1",
54
56
  "zod": "^3.22.3",
55
57
  "zod-validation-error": "^1.3.0",
56
- "@0xobelisk/sui-client": "1.2.0-pre.42",
57
- "@0xobelisk/sui-common": "1.2.0-pre.42"
58
+ "@0xobelisk/sui-client": "1.2.0-pre.43",
59
+ "@0xobelisk/sui-common": "1.2.0-pre.43"
58
60
  },
59
61
  "devDependencies": {
60
62
  "@types/cli-progress": "^3.11.5",
@@ -7,6 +7,8 @@ import * as cliProgress from 'cli-progress';
7
7
  import * as fs from 'fs';
8
8
  import * as path from 'path';
9
9
  import * as os from 'os';
10
+ import { HttpsProxyAgent } from 'https-proxy-agent';
11
+ import { HttpProxyAgent } from 'http-proxy-agent';
10
12
 
11
13
  // Check result type
12
14
  interface CheckResult {
@@ -130,7 +132,7 @@ async function execCommand(
130
132
 
131
133
  // Download file with progress bar
132
134
  async function downloadFileWithProgress(url: string, outputPath: string): Promise<void> {
133
- const response = await fetch(url, {
135
+ const response = await fetchWithProxy(url, {
134
136
  headers: {
135
137
  'User-Agent': 'dubhe-cli'
136
138
  }
@@ -143,7 +145,7 @@ async function downloadFileWithProgress(url: string, outputPath: string): Promis
143
145
  const contentLength = response.headers.get('content-length');
144
146
  const totalSize = contentLength ? parseInt(contentLength) : 0;
145
147
 
146
- // 创建进度条
148
+ // Create progress bar
147
149
  const progressBar = new cliProgress.SingleBar({
148
150
  format:
149
151
  chalk.cyan('Download Progress') +
@@ -181,7 +183,7 @@ async function downloadFileWithProgress(url: string, outputPath: string): Promis
181
183
  chunks.push(value);
182
184
  downloadedBytes += value.length;
183
185
 
184
- // 更新进度条
186
+ // Update progress bar
185
187
  if (totalSize > 0) {
186
188
  const downloadedMB = Math.round((downloadedBytes / 1024 / 1024) * 100) / 100;
187
189
  const elapsedTime = (Date.now() - startTime) / 1000;
@@ -193,7 +195,7 @@ async function downloadFileWithProgress(url: string, outputPath: string): Promis
193
195
  }
194
196
  }
195
197
 
196
- // 合并所有 chunks
198
+ // Merge all chunks
197
199
  const totalLength = chunks.reduce((acc, chunk) => acc + chunk.length, 0);
198
200
  const buffer = new Uint8Array(totalLength);
199
201
  let offset = 0;
@@ -203,7 +205,7 @@ async function downloadFileWithProgress(url: string, outputPath: string): Promis
203
205
  offset += chunk.length;
204
206
  }
205
207
 
206
- // 写入文件
208
+ // Write file
207
209
  fs.writeFileSync(outputPath, buffer);
208
210
 
209
211
  if (totalSize > 0) {
@@ -225,6 +227,70 @@ async function downloadFileWithProgress(url: string, outputPath: string): Promis
225
227
  }
226
228
  }
227
229
 
230
+ // Enhanced fetch function with proxy support
231
+ async function fetchWithProxy(url: string, options: RequestInit = {}): Promise<Response> {
232
+ // Check for proxy environment variables
233
+ const httpProxy = process.env.HTTP_PROXY || process.env.http_proxy;
234
+ const httpsProxy = process.env.HTTPS_PROXY || process.env.https_proxy;
235
+ const noProxy = process.env.NO_PROXY || process.env.no_proxy;
236
+
237
+ // Check if URL should be bypassed (NO_PROXY)
238
+ if (noProxy) {
239
+ const noProxyList = noProxy.split(',').map((item) => item.trim());
240
+ const hostname = new URL(url).hostname;
241
+
242
+ for (const noProxyItem of noProxyList) {
243
+ if (
244
+ noProxyItem === '*' ||
245
+ hostname === noProxyItem ||
246
+ hostname.endsWith('.' + noProxyItem) ||
247
+ (noProxyItem.startsWith('.') && hostname.endsWith(noProxyItem))
248
+ ) {
249
+ return fetch(url, options); // No proxy needed
250
+ }
251
+ }
252
+ }
253
+
254
+ const protocol = new URL(url).protocol;
255
+ let agent;
256
+
257
+ // Create appropriate proxy agent
258
+ if (protocol === 'https:' && httpsProxy) {
259
+ agent = new HttpsProxyAgent(httpsProxy);
260
+ } else if (protocol === 'http:' && httpProxy) {
261
+ agent = new HttpProxyAgent(httpProxy);
262
+ } else if (httpsProxy && protocol === 'https:') {
263
+ agent = new HttpsProxyAgent(httpsProxy);
264
+ }
265
+
266
+ if (agent) {
267
+ // Try to use the agent - this method works with undici (Node.js 18+)
268
+ try {
269
+ const fetchOptions: any = {
270
+ ...options,
271
+ dispatcher: agent
272
+ };
273
+ return await fetch(url, fetchOptions);
274
+ } catch (error) {
275
+ // If dispatcher doesn't work, try with agent property
276
+ try {
277
+ const fetchOptions: any = {
278
+ ...options,
279
+ agent
280
+ };
281
+ return await fetch(url, fetchOptions);
282
+ } catch (agentError) {
283
+ console.log(
284
+ chalk.yellow(` ⚠️ Warning: Could not use proxy, falling back to direct connection`)
285
+ );
286
+ return fetch(url, options);
287
+ }
288
+ }
289
+ }
290
+
291
+ return fetch(url, options);
292
+ }
293
+
228
294
  // Fetch GitHub releases with retry
229
295
  async function fetchGitHubReleases(
230
296
  repo: string,
@@ -239,7 +305,7 @@ async function fetchGitHubReleases(
239
305
  console.log(chalk.gray(` Retry ${attempt}/${retries}...`));
240
306
  }
241
307
 
242
- const response = await fetch(url, {
308
+ const response = await fetchWithProxy(url, {
243
309
  headers: {
244
310
  'User-Agent': 'dubhe-cli',
245
311
  Accept: 'application/vnd.github.v3+json'
@@ -505,7 +571,7 @@ async function downloadAndInstallTool(toolName: string, version?: string): Promi
505
571
 
506
572
  // Verify download link
507
573
  try {
508
- const headResponse = await fetch(asset.browser_download_url, {
574
+ const headResponse = await fetchWithProxy(asset.browser_download_url, {
509
575
  method: 'HEAD',
510
576
  headers: { 'User-Agent': 'dubhe-cli' }
511
577
  });