mihomo-cli 2.4.0 → 2.4.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.4.1] - 2026-05-02
4
+
5
+ ### 修复
6
+
7
+ - 启动时清除代理环境变量(`http_proxy` / `https_proxy` / `all_proxy`),避免系统已有代理导致请求异常
8
+
9
+ ---
10
+
3
11
  ## [2.4.0] - 2026-05-02
4
12
 
5
13
  ### 新功能
package/dist/index.js CHANGED
@@ -3509,48 +3509,37 @@ function parseProxyUris(content) {
3509
3509
  return proxies;
3510
3510
  }
3511
3511
  async function downloadAllSources(sources, onProgress) {
3512
- const savedProxy = { http: process.env.http_proxy, https: process.env.https_proxy, HTTP: process.env.HTTP_PROXY, HTTPS: process.env.HTTPS_PROXY };
3513
- delete process.env.http_proxy;
3514
- delete process.env.https_proxy;
3515
- delete process.env.HTTP_PROXY;
3516
- delete process.env.HTTPS_PROXY;
3517
- try {
3518
- const client = createHttpClient({ timeout: 3e4 });
3519
- const tasks = sources.map(async (source) => {
3520
- const entry = { name: source.name, url: source.url, proxies: [], proxyGroups: 0 };
3512
+ const client = createHttpClient({ timeout: 3e4 });
3513
+ const tasks = sources.map(async (source) => {
3514
+ const entry = { name: source.name, url: source.url, proxies: [], proxyGroups: 0 };
3515
+ try {
3516
+ const response = await client.get(source.url, { responseType: "text" });
3517
+ const content = response.data;
3518
+ if (!content?.trim()) throw new Error("\u5185\u5BB9\u4E3A\u7A7A");
3519
+ let proxies;
3521
3520
  try {
3522
- const response = await client.get(source.url, { responseType: "text" });
3523
- const content = response.data;
3524
- if (!content?.trim()) throw new Error("\u5185\u5BB9\u4E3A\u7A7A");
3525
- let proxies;
3526
- try {
3527
- const parsed = parseYamlOrJson(content, "\u8BA2\u9605\u5185\u5BB9");
3528
- proxies = parsed.proxies || [];
3529
- const groups = parsed["proxy-groups"];
3530
- if (groups) entry.proxyGroups = groups.length;
3531
- } catch {
3532
- const decoded = tryDecodeBase64Content(content);
3533
- if (decoded) {
3534
- proxies = parseProxyUris(decoded);
3535
- } else {
3536
- proxies = parseProxyUris(content);
3537
- }
3538
- if (proxies.length === 0) throw new Error("\u65E0\u6CD5\u89E3\u6790\u8BA2\u9605\u5185\u5BB9\uFF08\u975E YAML/JSON/Base64\uFF09");
3521
+ const parsed = parseYamlOrJson(content, "\u8BA2\u9605\u5185\u5BB9");
3522
+ proxies = parsed.proxies || [];
3523
+ const groups = parsed["proxy-groups"];
3524
+ if (groups) entry.proxyGroups = groups.length;
3525
+ } catch {
3526
+ const decoded = tryDecodeBase64Content(content);
3527
+ if (decoded) {
3528
+ proxies = parseProxyUris(decoded);
3529
+ } else {
3530
+ proxies = parseProxyUris(content);
3539
3531
  }
3540
- entry.proxies = proxies.map((p) => ({ ...p, name: `[${source.name}] ${p.name}` }));
3541
- onProgress?.(source.name, true, proxies.length, entry.proxyGroups);
3542
- } catch (e) {
3543
- entry.error = e.message;
3544
- onProgress?.(source.name, false, 0, 0, entry.error);
3532
+ if (proxies.length === 0) throw new Error("\u65E0\u6CD5\u89E3\u6790\u8BA2\u9605\u5185\u5BB9\uFF08\u975E YAML/JSON/Base64\uFF09");
3545
3533
  }
3546
- return entry;
3547
- });
3548
- return await Promise.all(tasks);
3549
- } finally {
3550
- for (const [key, val] of Object.entries(savedProxy)) {
3551
- if (val !== void 0) process.env[key] = val;
3534
+ entry.proxies = proxies.map((p) => ({ ...p, name: `[${source.name}] ${p.name}` }));
3535
+ onProgress?.(source.name, true, proxies.length, entry.proxyGroups);
3536
+ } catch (e) {
3537
+ entry.error = e.message;
3538
+ onProgress?.(source.name, false, 0, 0, entry.error);
3552
3539
  }
3553
- }
3540
+ return entry;
3541
+ });
3542
+ return await Promise.all(tasks);
3554
3543
  }
3555
3544
  function isProxyValid(proxy) {
3556
3545
  if (!proxy.name || !proxy.server || !proxy.port) return false;
@@ -6174,7 +6163,16 @@ process.on("unhandledRejection", (reason) => {
6174
6163
  \u672A\u5904\u7406\u7684 Promise \u62D2\u7EDD: ${msg}`);
6175
6164
  process.exit(1);
6176
6165
  });
6166
+ function clearProxyEnv() {
6167
+ delete process.env.http_proxy;
6168
+ delete process.env.https_proxy;
6169
+ delete process.env.HTTP_PROXY;
6170
+ delete process.env.HTTPS_PROXY;
6171
+ delete process.env.all_proxy;
6172
+ delete process.env.ALL_PROXY;
6173
+ }
6177
6174
  async function main() {
6175
+ clearProxyEnv();
6178
6176
  ensureDirs();
6179
6177
  const args = process.argv.slice(2);
6180
6178
  if (args.length === 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mihomo-cli",
3
- "version": "2.4.0",
3
+ "version": "2.4.1",
4
4
  "type": "module",
5
5
  "description": "A terminal-based mihomo (Clash.Meta) client for macOS",
6
6
  "bin": {