ali-skills 0.2.0 → 0.2.1-beta.1

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/cli.mjs +54 -37
  2. package/package.json +1 -4
package/bin/cli.mjs CHANGED
@@ -1,48 +1,65 @@
1
1
  #!/usr/bin/env node
2
2
  import { execSync } from 'child_process';
3
+ import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'fs';
4
+ import { join } from 'path';
5
+ import { homedir } from 'os';
6
+ import { pathToFileURL } from 'url';
3
7
 
4
- const INTERNAL_REGISTRY = 'https://registry.anpm.alibaba-inc.com';
8
+ const REGISTRY = 'https://registry.anpm.alibaba-inc.com';
9
+ const PKG = '@ali/cli-skills';
10
+ const CACHE_DIR = join(homedir(), '.ali-skills');
11
+ const PKG_DIR = join(CACHE_DIR, 'node_modules', PKG);
5
12
 
6
- function getRegistry() {
13
+ /** 读取缓存中已安装的版本号 */
14
+ function getInstalledVersion() {
7
15
  try {
8
- return execSync('npm config get registry', { encoding: 'utf8' }).trim().replace(/\/$/, '');
16
+ return JSON.parse(readFileSync(join(PKG_DIR, 'package.json'), 'utf8')).version || null;
9
17
  } catch {
10
- return '';
18
+ return null;
11
19
  }
12
20
  }
13
21
 
14
- try {
15
- await import('@ali/cli-skills/bin/cli.mjs');
16
- } catch (err) {
17
- if (err.code === 'ERR_MODULE_NOT_FOUND' || err.code === 'MODULE_NOT_FOUND') {
18
- const registry = getRegistry();
19
- const isInternal = registry.includes('alibaba-inc.com') || registry.includes('anpm.alibaba');
20
-
21
- if (!isInternal) {
22
- console.error(`
23
- 错误:当前 npm registry 不是阿里内网源,无法安装内部依赖包 @ali/cli-skills
24
-
25
- 当前 registry: ${registry || '(未知)'}
26
-
27
- 请选择以下方式之一重新执行:
28
-
29
- 1. 配置内网源后重新执行:
30
- npm config set registry ${INTERNAL_REGISTRY}
31
- npx ali-skills
32
-
33
- 2. 使用 tnpx 执行:
34
- tnpx ali-skills
35
-
36
- 3. 临时指定 registry 执行:
37
- npx --registry ${INTERNAL_REGISTRY} ali-skills
38
- `);
39
- } else {
40
- console.error(`
41
- 错误:@ali/cli-skills 未找到,请尝试重新安装:
42
- npx --registry ${INTERNAL_REGISTRY} ali-skills@latest
43
- `);
44
- }
45
- process.exit(1);
22
+ /** 从内网 registry 查最新版本,超时 5s 返回 null */
23
+ function getLatestVersion() {
24
+ try {
25
+ return execSync(`npm view ${PKG} version --registry ${REGISTRY}`, {
26
+ encoding: 'utf8',
27
+ timeout: 5000,
28
+ stdio: ['pipe', 'pipe', 'pipe'],
29
+ }).trim();
30
+ } catch {
31
+ return null;
32
+ }
33
+ }
34
+
35
+ /** 安装指定版本到缓存目录 */
36
+ function install(version) {
37
+ mkdirSync(CACHE_DIR, { recursive: true });
38
+ const pkgJson = join(CACHE_DIR, 'package.json');
39
+ if (!existsSync(pkgJson)) {
40
+ writeFileSync(pkgJson, '{"private":true}');
46
41
  }
47
- throw err;
42
+ execSync(
43
+ `npm install ${PKG}@${version} --registry ${REGISTRY} --prefix "${CACHE_DIR}" --no-audit --no-fund --loglevel=error`,
44
+ { stdio: 'inherit' },
45
+ );
48
46
  }
47
+
48
+ const installedVersion = getInstalledVersion();
49
+ const latestVersion = getLatestVersion();
50
+
51
+ // 无法联通内网 registry,且本地无缓存 → 报错
52
+ if (!latestVersion && !installedVersion) {
53
+ console.error(`错误:无法连接内网 registry(${REGISTRY})且本地无缓存。\n请确保处于阿里内网或 VPN 环境后重试。`);
54
+ process.exit(1);
55
+ }
56
+
57
+ // 有新版本 → 自动安装/更新
58
+ if (latestVersion && latestVersion !== installedVersion) {
59
+ const action = installedVersion ? `更新 ${installedVersion} → ${latestVersion}` : `安装 ${latestVersion}`;
60
+ process.stderr.write(`[ali-skills] ${PKG} ${action}...\n`);
61
+ install(latestVersion);
62
+ }
63
+
64
+ // 执行
65
+ await import(pathToFileURL(join(PKG_DIR, 'bin', 'cli.mjs')).href);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ali-skills",
3
- "version": "0.2.0",
3
+ "version": "0.2.1-beta.1",
4
4
  "description": "The open agent skills ecosystem",
5
5
  "type": "module",
6
6
  "bin": {
@@ -31,9 +31,6 @@
31
31
  },
32
32
  "author": "",
33
33
  "license": "MIT",
34
- "optionalDependencies": {
35
- "@ali/cli-skills": "^2.1.8"
36
- },
37
34
  "engines": {
38
35
  "node": ">=18"
39
36
  },