@42ailab/42plugin 0.3.2 → 0.3.5

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/bin/42plugin-repair +83 -27
  2. package/package.json +6 -6
@@ -5,11 +5,15 @@
5
5
  * 用于修复常见的安装问题,特别是 Windows 平台
6
6
  */
7
7
 
8
- const { platform, arch, env } = process;
8
+ const { platform, arch, env, argv } = process;
9
9
  const { execSync } = require("child_process");
10
10
  const { existsSync, rmSync, writeFileSync } = require("fs");
11
11
  const { join, isAbsolute } = require("path");
12
12
 
13
+ // 解析命令行参数
14
+ const uninstallOnly = argv.includes("--uninstall-only") || argv.includes("--remove");
15
+ const packages = ["@42ailab/42plugin", `@42ailab/42plugin-${platform}-${arch}`];
16
+
13
17
  // 颜色输出
14
18
  const colors = {
15
19
  reset: "\x1b[0m",
@@ -65,7 +69,11 @@ function detectPackageManager() {
65
69
  }
66
70
 
67
71
  async function repair() {
68
- log("\n🔧 42plugin 自动修复工具", "cyan");
72
+ if (uninstallOnly) {
73
+ log("\n🗑️ 42plugin 卸载工具", "cyan");
74
+ } else {
75
+ log("\n🔧 42plugin 自动修复工具", "cyan");
76
+ }
69
77
  log("=" .repeat(40), "cyan");
70
78
 
71
79
  const packageManager = detectPackageManager();
@@ -99,26 +107,31 @@ async function repair() {
99
107
  log(` ⚠️ 缓存清理失败: ${error.message}`, "yellow");
100
108
  }
101
109
 
102
- // Step 2: 卸载旧版本
103
- log("\n步骤 2: 卸载旧版本...", "yellow");
104
- try {
105
- switch (packageManager) {
106
- case "npm":
107
- execSync("npm uninstall -g @42ailab/42plugin", { stdio: "inherit" });
108
- break;
109
- case "bun":
110
- execSync("bun remove -g @42ailab/42plugin", { stdio: "inherit" });
111
- break;
112
- case "yarn":
113
- execSync("yarn global remove @42ailab/42plugin", { stdio: "inherit" });
114
- break;
115
- case "pnpm":
116
- execSync("pnpm remove -g @42ailab/42plugin", { stdio: "inherit" });
117
- break;
110
+ // Step 2: 从所有包管理器卸载旧版本(确保彻底清理)
111
+ log("\n步骤 2: 从所有包管理器卸载旧版本...", "yellow");
112
+
113
+ const uninstallCommands = {
114
+ npm: (pkg) => `npm uninstall -g ${pkg}`,
115
+ bun: (pkg) => `bun remove -g ${pkg}`,
116
+ yarn: (pkg) => `yarn global remove ${pkg}`,
117
+ pnpm: (pkg) => `pnpm remove -g ${pkg}`,
118
+ };
119
+
120
+ let anyUninstalled = false;
121
+ for (const [pm, getCmd] of Object.entries(uninstallCommands)) {
122
+ for (const pkg of packages) {
123
+ try {
124
+ execSync(getCmd(pkg), { stdio: "pipe" });
125
+ log(` ✅ [${pm}] ${pkg} 卸载完成`, "green");
126
+ anyUninstalled = true;
127
+ } catch {
128
+ // 未安装或 PM 不可用,静默跳过
129
+ }
118
130
  }
119
- log(" ✅ 旧版本卸载完成", "green");
120
- } catch (error) {
121
- log(" ⚠️ 未找到已安装的版本", "yellow");
131
+ }
132
+
133
+ if (!anyUninstalled) {
134
+ log(" ℹ️ 未找到通过包管理器安装的版本", "yellow");
122
135
  }
123
136
 
124
137
  // Step 3: Windows 特殊处理
@@ -128,8 +141,17 @@ async function repair() {
128
141
  // 清理可能损坏的全局 node_modules(仅清理 42plugin 相关目录)
129
142
  const globalPaths = [];
130
143
 
144
+ // 获取 npm 实际全局 prefix(用户可能修改了默认路径)
145
+ let npmPrefix = null;
146
+ try {
147
+ npmPrefix = execSync("npm config get prefix", { encoding: "utf-8", stdio: "pipe" }).trim();
148
+ } catch {}
149
+
131
150
  // 安全地构建路径,确保环境变量存在且路径为绝对路径
132
- if (env.APPDATA && isAbsolute(env.APPDATA)) {
151
+ if (npmPrefix && isAbsolute(npmPrefix)) {
152
+ globalPaths.push(join(npmPrefix, "node_modules", "@42ailab", "42plugin"));
153
+ globalPaths.push(join(npmPrefix, "node_modules", "@42ailab", "42plugin-win32-x64"));
154
+ } else if (env.APPDATA && isAbsolute(env.APPDATA)) {
133
155
  globalPaths.push(join(env.APPDATA, "npm", "node_modules", "@42ailab", "42plugin"));
134
156
  globalPaths.push(join(env.APPDATA, "npm", "node_modules", "@42ailab", "42plugin-win32-x64"));
135
157
  }
@@ -156,11 +178,45 @@ async function repair() {
156
178
  }
157
179
  }
158
180
 
159
- // 检查并关闭可能占用文件的防病毒软件提示
160
- log("\n 💡 提示: 如果安装仍然失败,请尝试:", "yellow");
161
- log(" 1. 暂时禁用 Windows Defender 或其他防病毒软件", "yellow");
162
- log(" 2. 以管理员身份运行命令提示符", "yellow");
163
- log(" 3. 检查代理设置: npm config get proxy", "yellow");
181
+ // 清理 bun bin 目录中的 42plugin 相关文件
182
+ // bun remove 不会自动删除 ~/.bun/bin/ 下的 .exe 和 .bunx 文件
183
+ if (env.USERPROFILE && isAbsolute(env.USERPROFILE)) {
184
+ const bunBinDir = join(env.USERPROFILE, ".bun", "bin");
185
+ const bunBinFiles = [
186
+ join(bunBinDir, "42plugin.exe"),
187
+ join(bunBinDir, "42plugin.bunx"),
188
+ join(bunBinDir, "42plugin-repair.exe"),
189
+ join(bunBinDir, "42plugin-repair.bunx"),
190
+ ];
191
+ for (const filePath of bunBinFiles) {
192
+ if (existsSync(filePath)) {
193
+ log(` 清理 ${filePath}...`, "blue");
194
+ try {
195
+ rmSync(filePath, { force: true });
196
+ log(` ✅ 清理完成`, "green");
197
+ } catch (error) {
198
+ log(` ⚠️ 清理失败: ${error.message}`, "yellow");
199
+ }
200
+ }
201
+ }
202
+ }
203
+
204
+ if (!uninstallOnly) {
205
+ // 检查并关闭可能占用文件的防病毒软件提示
206
+ log("\n 💡 提示: 如果安装仍然失败,请尝试:", "yellow");
207
+ log(" 1. 暂时禁用 Windows Defender 或其他防病毒软件", "yellow");
208
+ log(" 2. 以管理员身份运行命令提示符", "yellow");
209
+ log(" 3. 检查代理设置: npm config get proxy", "yellow");
210
+ }
211
+ }
212
+
213
+ // 仅卸载模式:跳过重新安装和验证
214
+ if (uninstallOnly) {
215
+ log("\n✅ 42plugin 已彻底卸载。", "green");
216
+ log(" 如需重新安装,请运行:", "blue");
217
+ log(" npm install -g @42ailab/42plugin", "blue");
218
+ log(" 或: bun add -g @42ailab/42plugin", "blue");
219
+ return;
164
220
  }
165
221
 
166
222
  // Step 4: 重新安装
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@42ailab/42plugin",
3
- "version": "0.3.2",
3
+ "version": "0.3.5",
4
4
  "description": "42plugin CLI - AI 插件管理工具",
5
5
  "bin": {
6
6
  "42plugin": "bin/42plugin",
@@ -36,10 +36,10 @@
36
36
  "node": ">=18.0.0"
37
37
  },
38
38
  "optionalDependencies": {
39
- "@42ailab/42plugin-darwin-arm64": "0.3.2",
40
- "@42ailab/42plugin-darwin-x64": "0.3.2",
41
- "@42ailab/42plugin-linux-arm64": "0.3.2",
42
- "@42ailab/42plugin-linux-x64": "0.3.2",
43
- "@42ailab/42plugin-win32-x64": "0.3.2"
39
+ "@42ailab/42plugin-darwin-arm64": "0.3.5",
40
+ "@42ailab/42plugin-darwin-x64": "0.3.5",
41
+ "@42ailab/42plugin-linux-arm64": "0.3.5",
42
+ "@42ailab/42plugin-linux-x64": "0.3.5",
43
+ "@42ailab/42plugin-win32-x64": "0.3.5"
44
44
  }
45
45
  }