@42ailab/42plugin 0.2.18 → 0.2.19

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 +32 -13
  2. package/package.json +6 -6
package/bin/42plugin CHANGED
@@ -8,7 +8,7 @@
8
8
  */
9
9
 
10
10
  import { spawnSync } from 'node:child_process';
11
- import { existsSync } from 'node:fs';
11
+ import { existsSync, readFileSync } from 'node:fs';
12
12
  import { join, dirname } from 'node:path';
13
13
  import { fileURLToPath } from 'node:url';
14
14
 
@@ -23,6 +23,17 @@ const PLATFORMS = {
23
23
  'win32-x64': '@42ailab/42plugin-win32-x64',
24
24
  };
25
25
 
26
+ // 获取主包版本号
27
+ function getMainPackageVersion() {
28
+ try {
29
+ const pkgPath = join(__dirname, '..', 'package.json');
30
+ const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));
31
+ return pkg.version;
32
+ } catch {
33
+ return null;
34
+ }
35
+ }
36
+
26
37
  // 获取当前平台标识
27
38
  function getPlatformKey() {
28
39
  const platform = process.platform;
@@ -49,18 +60,20 @@ function detectPackageManager() {
49
60
  }
50
61
 
51
62
  // 尝试自动安装平台包
52
- function tryAutoInstall(packageName) {
63
+ function tryAutoInstall(packageName, version) {
53
64
  const pm = detectPackageManager();
54
- console.error(`正在自动安装平台包: ${packageName}...`);
65
+ // 使用具体版本号,避免 latest tag 同步问题
66
+ const packageSpec = version ? `${packageName}@${version}` : packageName;
67
+ console.error(`正在自动安装平台包: ${packageSpec}...`);
55
68
 
56
69
  let result;
57
70
  if (pm === 'bun') {
58
- result = spawnSync('bun', ['add', '-g', packageName], {
71
+ result = spawnSync('bun', ['add', '-g', packageSpec], {
59
72
  stdio: 'inherit',
60
73
  shell: process.platform === 'win32',
61
74
  });
62
75
  } else {
63
- result = spawnSync('npm', ['install', '-g', packageName], {
76
+ result = spawnSync('npm', ['install', '-g', packageSpec], {
64
77
  stdio: 'inherit',
65
78
  shell: process.platform === 'win32',
66
79
  });
@@ -73,6 +86,7 @@ function tryAutoInstall(packageName) {
73
86
  function findBinary(autoInstall = false) {
74
87
  const platformKey = getPlatformKey();
75
88
  const packageName = PLATFORMS[platformKey];
89
+ const version = getMainPackageVersion();
76
90
 
77
91
  if (!packageName) {
78
92
  console.error(`错误: 不支持的平台 ${platformKey}`);
@@ -103,27 +117,32 @@ function findBinary(autoInstall = false) {
103
117
 
104
118
  // 找不到二进制文件,尝试自动安装
105
119
  if (!autoInstall) {
106
- if (tryAutoInstall(packageName)) {
120
+ if (tryAutoInstall(packageName, version)) {
107
121
  // 安装成功,重新查找
108
122
  return findBinary(true);
109
123
  }
110
124
  }
111
125
 
112
126
  // 自动安装失败,显示手动安装提示
127
+ const versionSpec = version ? `@${version}` : '';
113
128
  console.error('');
114
129
  console.error(`错误: 找不到 ${platformKey} 平台的二进制文件`);
115
- console.error(`请手动安装: ${packageName}`);
130
+ console.error(`请手动安装: ${packageName}${versionSpec}`);
116
131
  console.error('');
117
132
  console.error('尝试以下方法:');
118
133
  console.error('');
119
- console.error(' # Bun 用户');
120
- console.error(` bun add -g ${packageName}`);
134
+ console.error(' # 推荐: Homebrew (macOS/Linux)');
135
+ console.error(' brew install 42ailab/42plugin/42plugin');
121
136
  console.error('');
122
- console.error(' # npm 用户');
123
- console.error(' npm install -g @42ailab/42plugin');
137
+ console.error(' # npm 用户 (指定版本)');
138
+ console.error(` npm install -g ${packageName}${versionSpec}`);
124
139
  console.error('');
125
- console.error(' # Homebrew (macOS/Linux)');
126
- console.error(' brew install 42ailab/42plugin/42plugin');
140
+ console.error(' # Bun 用户 (指定版本)');
141
+ console.error(` bun add -g ${packageName}${versionSpec}`);
142
+ console.error('');
143
+ console.error('如果问题持续,请尝试清除缓存后重新安装:');
144
+ console.error(' npm cache clean --force');
145
+ console.error(' bun pm cache rm');
127
146
  process.exit(1);
128
147
  }
129
148
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@42ailab/42plugin",
3
- "version": "0.2.18",
3
+ "version": "0.2.19",
4
4
  "description": "42plugin CLI - AI 插件管理工具",
5
5
  "type": "module",
6
6
  "bin": {
@@ -32,10 +32,10 @@
32
32
  "node": ">=18.0.0"
33
33
  },
34
34
  "optionalDependencies": {
35
- "@42ailab/42plugin-darwin-arm64": "0.2.18",
36
- "@42ailab/42plugin-darwin-x64": "0.2.18",
37
- "@42ailab/42plugin-linux-arm64": "0.2.18",
38
- "@42ailab/42plugin-linux-x64": "0.2.18",
39
- "@42ailab/42plugin-win32-x64": "0.2.18"
35
+ "@42ailab/42plugin-darwin-arm64": "0.2.19",
36
+ "@42ailab/42plugin-darwin-x64": "0.2.19",
37
+ "@42ailab/42plugin-linux-arm64": "0.2.19",
38
+ "@42ailab/42plugin-linux-x64": "0.2.19",
39
+ "@42ailab/42plugin-win32-x64": "0.2.19"
40
40
  }
41
41
  }