mihomo-cli 26.9.92 → 26.9.94
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 +27 -0
- package/README.md +92 -42
- package/dist/index.js +4251 -4247
- package/package.json +1 -3
- package/scripts/preuninstall.mjs +0 -65
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mihomo-cli",
|
|
3
|
-
"version": "26.9.
|
|
3
|
+
"version": "26.9.94",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A terminal-based mihomo (Clash.Meta) client for macOS",
|
|
6
6
|
"bin": {
|
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
},
|
|
12
12
|
"files": [
|
|
13
13
|
"dist",
|
|
14
|
-
"scripts",
|
|
15
14
|
"CHANGELOG.md"
|
|
16
15
|
],
|
|
17
16
|
"scripts": {
|
|
@@ -23,7 +22,6 @@
|
|
|
23
22
|
"typecheck": "tsc --noEmit",
|
|
24
23
|
"test": "node --import tsx --test \"src/**/*.spec.ts\"",
|
|
25
24
|
"prepublishOnly": "npm run build",
|
|
26
|
-
"preuninstall": "node scripts/preuninstall.mjs",
|
|
27
25
|
"prepare": "husky"
|
|
28
26
|
},
|
|
29
27
|
"keywords": [
|
package/scripts/preuninstall.mjs
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// npm 卸载前提示。**只警告、不自动卸载服务**:
|
|
3
|
-
// `mihomo update`(npm 升级)也会触发旧版本的 preuninstall,若在这里自动 uninstall,
|
|
4
|
-
// 每次升级都会把用户的 LaunchAgent 删掉。升级场景让用户忽略提示即可;真正卸载时
|
|
5
|
-
// CLI 在 preuninstall 阶段仍在 PATH,用户来得及中止后先跑 `mihomo uninstall`。
|
|
6
|
-
import { spawnSync } from 'node:child_process';
|
|
7
|
-
import fs from 'node:fs';
|
|
8
|
-
import os from 'node:os';
|
|
9
|
-
import path from 'node:path';
|
|
10
|
-
import { fileURLToPath } from 'node:url';
|
|
11
|
-
|
|
12
|
-
const DEFAULT_LABEL = 'com.mihomo-cli.daemon';
|
|
13
|
-
|
|
14
|
-
/** 只读探测:服务是否装载、plist 与数据目录是否存在。纯函数化以便 spec 隔离 HOME/label 验证 */
|
|
15
|
-
export function inspectInstallation(env = process.env) {
|
|
16
|
-
const label = env.MIHOMO_CLI_DAEMON_LABEL || DEFAULT_LABEL;
|
|
17
|
-
const uid = typeof process.getuid === 'function' ? process.getuid() : -1;
|
|
18
|
-
const home = env.HOME || os.homedir();
|
|
19
|
-
const plist = path.join(home, 'Library', 'LaunchAgents', `${label}.plist`);
|
|
20
|
-
const dataDir = env.MIHOMO_CLI_DIR || path.join(home, '.mihomo-cli');
|
|
21
|
-
|
|
22
|
-
let loaded = false;
|
|
23
|
-
if (uid >= 0) {
|
|
24
|
-
const r = spawnSync('launchctl', ['print', `gui/${uid}/${label}`], { stdio: 'ignore' });
|
|
25
|
-
loaded = r.status === 0;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return {
|
|
29
|
-
label,
|
|
30
|
-
uid,
|
|
31
|
-
plist,
|
|
32
|
-
plistExists: fs.existsSync(plist),
|
|
33
|
-
loaded,
|
|
34
|
-
dataDir,
|
|
35
|
-
dataExists: fs.existsSync(dataDir),
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/** 组装提示正文(纯函数) */
|
|
40
|
-
export function buildNotice(i) {
|
|
41
|
-
return [
|
|
42
|
-
'⚠️ mihomo-cli:npm 卸载只移除 npm 包,不会停止 launchd 服务、也不会删除数据目录',
|
|
43
|
-
` 服务 label : ${i.label}(${i.loaded ? '当前已装载' : '未装载'})`,
|
|
44
|
-
` LaunchAgent: ${i.plist}${i.plistExists ? '' : '(不存在)'}`,
|
|
45
|
-
` 数据目录 : ${i.dataDir}${i.dataExists ? '' : '(不存在)'}`,
|
|
46
|
-
'',
|
|
47
|
-
' · 若正在升级(mihomo update),忽略本提示即可,升级后服务与数据不变',
|
|
48
|
-
' · 若确实要卸载,请中止后先运行: mihomo uninstall',
|
|
49
|
-
' · CLI 已被移除后只能手动清理:',
|
|
50
|
-
` launchctl bootout gui/${i.uid}/${i.label} 2>/dev/null; rm -f ${i.plist}`,
|
|
51
|
-
` rm -rf ${i.dataDir} # 订阅、内核、日志等全部数据`,
|
|
52
|
-
'',
|
|
53
|
-
].join('\n');
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function main() {
|
|
57
|
-
const i = inspectInstallation();
|
|
58
|
-
// 全都不存在:纯包卸载,无需打扰(常见于 CI、临时环境)
|
|
59
|
-
if (!i.loaded && !i.plistExists && !i.dataExists) return;
|
|
60
|
-
console.error(`\n${buildNotice(i)}`);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
64
|
-
main();
|
|
65
|
-
}
|