mihomo-cli 2.4.0 → 2.4.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/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.4.2] - 2026-05-02
4
+
5
+ ### 改进
6
+
7
+ - 自动清理阈值统一为 50 个节点(不再区分订阅类型)
8
+ - 订阅默认更新间隔从 12 小时缩短为 4 小时
9
+
10
+ ---
11
+
12
+ ## [2.4.1] - 2026-05-02
13
+
14
+ ### 修复
15
+
16
+ - 启动时清除代理环境变量(`http_proxy` / `https_proxy` / `all_proxy`),避免系统已有代理导致请求异常
17
+
18
+ ---
19
+
3
20
  ## [2.4.0] - 2026-05-02
4
21
 
5
22
  ### 新功能
package/README.md CHANGED
@@ -198,7 +198,7 @@ mihomo kernel --mirror-all hk.gh-proxy.org
198
198
 
199
199
  ## 订阅自动更新
200
200
 
201
- - 默认更新间隔:12 小时(或订阅服务端指定的 `profile-update-interval`)
201
+ - 默认更新间隔:4 小时(或订阅服务端指定的 `profile-update-interval`)
202
202
  - 触发时机:`start` 命令、`sub list` 命令
203
203
  - 更新失败时继续使用本地缓存,不影响使用
204
204
 
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;
@@ -4222,7 +4211,7 @@ function viewLogWithTail(logPath, options) {
4222
4211
  }
4223
4212
 
4224
4213
  // src/subscription.ts
4225
- var DEFAULT_UPDATE_INTERVAL_HOURS = 12;
4214
+ var DEFAULT_UPDATE_INTERVAL_HOURS = 4;
4226
4215
  var YAML_DUMP_OPTS = { indent: 2, lineWidth: -1, noCompatMode: true };
4227
4216
  var HTTP_CLIENT = createHttpClient({ timeout: 6e4 });
4228
4217
  function isMultiUrl(url) {
@@ -4667,8 +4656,7 @@ function printStatus() {
4667
4656
  }
4668
4657
 
4669
4658
  // src/commands/start.ts
4670
- var AUTO_CLEAN_THRESHOLD = 100;
4671
- var AUTO_CLEAN_THRESHOLD_FREE = 50;
4659
+ var AUTO_CLEAN_THRESHOLD = 50;
4672
4660
  function handleStopResult(result) {
4673
4661
  if (result.remaining && result.remaining.length > 0) {
4674
4662
  console.error(`${colors.red("\u90E8\u5206\u8FDB\u7A0B\u672A\u7EC8\u6B62:")} ${result.remaining.join(", ")}`);
@@ -4720,10 +4708,9 @@ async function cmdStart(args) {
4720
4708
  }
4721
4709
  process.exit(1);
4722
4710
  }
4723
- const cleanThreshold = sub.name.startsWith("free") ? AUTO_CLEAN_THRESHOLD_FREE : AUTO_CLEAN_THRESHOLD;
4724
- if (configInfo.proxies > cleanThreshold) {
4711
+ if (configInfo.proxies > AUTO_CLEAN_THRESHOLD) {
4725
4712
  console.log("");
4726
- console.log(`\u8282\u70B9\u6570 ${configInfo.proxies} \u8D85\u8FC7 ${cleanThreshold}\uFF0C\u81EA\u52A8\u6E05\u7406...`);
4713
+ console.log(`\u8282\u70B9\u6570 ${configInfo.proxies} \u8D85\u8FC7 ${AUTO_CLEAN_THRESHOLD}\uFF0C\u81EA\u52A8\u6E05\u7406...`);
4727
4714
  console.log("");
4728
4715
  await sleep(1e3);
4729
4716
  const cleanResult = await autoCleanSubscription(sub.name, { onResult: printTestResult });
@@ -6174,7 +6161,16 @@ process.on("unhandledRejection", (reason) => {
6174
6161
  \u672A\u5904\u7406\u7684 Promise \u62D2\u7EDD: ${msg}`);
6175
6162
  process.exit(1);
6176
6163
  });
6164
+ function clearProxyEnv() {
6165
+ delete process.env.http_proxy;
6166
+ delete process.env.https_proxy;
6167
+ delete process.env.HTTP_PROXY;
6168
+ delete process.env.HTTPS_PROXY;
6169
+ delete process.env.all_proxy;
6170
+ delete process.env.ALL_PROXY;
6171
+ }
6177
6172
  async function main() {
6173
+ clearProxyEnv();
6178
6174
  ensureDirs();
6179
6175
  const args = process.argv.slice(2);
6180
6176
  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.2",
4
4
  "type": "module",
5
5
  "description": "A terminal-based mihomo (Clash.Meta) client for macOS",
6
6
  "bin": {