@42ailab/42plugin 0.2.24 → 0.2.25

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 +13 -0
  2. package/package.json +6 -6
package/bin/42plugin CHANGED
@@ -7,6 +7,8 @@
7
7
 
8
8
  const { platform, arch, env, version } = process;
9
9
  const { spawnSync } = require("child_process");
10
+ const { existsSync } = require("fs");
11
+ const { join } = require("path");
10
12
 
11
13
  const PLATFORMS = {
12
14
  win32: {
@@ -26,9 +28,20 @@ const binPath = env.PLUGIN_BINARY || PLATFORMS?.[platform]?.[arch];
26
28
 
27
29
  if (binPath) {
28
30
  let resolvedPath;
31
+
32
+ // 1. 优先使用 require.resolve(本地安装时有效)
29
33
  try {
30
34
  resolvedPath = require.resolve(binPath);
31
35
  } catch {
36
+ // 2. Fallback: 查找嵌套的 node_modules(全局安装时有效)
37
+ // npm/bun 全局安装时,optionalDependencies 会被安装到主包内部的 node_modules
38
+ const nestedPath = join(__dirname, "..", "node_modules", binPath);
39
+ if (existsSync(nestedPath)) {
40
+ resolvedPath = nestedPath;
41
+ }
42
+ }
43
+
44
+ if (!resolvedPath) {
32
45
  console.error(`错误: 找不到平台二进制包 ${binPath.split("/")[0]}`);
33
46
  console.error("");
34
47
  console.error("可能原因:");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@42ailab/42plugin",
3
- "version": "0.2.24",
3
+ "version": "0.2.25",
4
4
  "description": "42plugin CLI - AI 插件管理工具",
5
5
  "bin": {
6
6
  "42plugin": "bin/42plugin"
@@ -26,10 +26,10 @@
26
26
  "node": ">=18.0.0"
27
27
  },
28
28
  "optionalDependencies": {
29
- "@42ailab/42plugin-darwin-arm64": "0.2.24",
30
- "@42ailab/42plugin-darwin-x64": "0.2.24",
31
- "@42ailab/42plugin-linux-arm64": "0.2.24",
32
- "@42ailab/42plugin-linux-x64": "0.2.24",
33
- "@42ailab/42plugin-win32-x64": "0.2.24"
29
+ "@42ailab/42plugin-darwin-arm64": "0.2.25",
30
+ "@42ailab/42plugin-darwin-x64": "0.2.25",
31
+ "@42ailab/42plugin-linux-arm64": "0.2.25",
32
+ "@42ailab/42plugin-linux-x64": "0.2.25",
33
+ "@42ailab/42plugin-win32-x64": "0.2.25"
34
34
  }
35
35
  }