mirror of
https://git.openapi.site/https://github.com/desirecore/market.git
synced 2026-12-05 11:39:26 +08:00
fix(nodejs-runtime): 修正过时的 Volta 路径(1.0.4)/ correct stale Volta paths (#240)
nodejs-runtime 与 dev-environment-setup 还在描述客户端 10.0.105 之前的布局:真实数据根里没有 runtime/volta,VOLTA_HOME 也不同。Agent 照做会找不到二进制或另建一个 Volta Home;probe-node.sh 也因此把 volta_path、volta_tools 报成空,继而把 Agent 带到系统包管理器。
- Volta Home 改为 runtime/volta-home(显式 VOLTA_HOME 优先),二进制改为随包的 static/toolchains/<平台>-<架构>/volta/volta;runtime/volta/volta 只有手动下载后才存在
- 先用已在 PATH 上的内置 Node;指定版本用 tools/image/node/<版本>/bin 的绝对路径
- 明确不要使用 volta-home/bin:未导出 VOLTA_HOME 时 shim 看 ~/.volta,拿不到 DesireCore 的 Node,放在 PATH 上还会卡住
- probe-node.sh 按新布局查找普通可执行文件;调用 Volta 时带 VOLTA_HOME,不再新建 ~/.volta
- 安装命令改用 fetch(与客户端相同,不改默认版本);在 DesireCore 里 cd 不会切换版本,改用 volta run
- pnpm@latest 改为 pnpm@11:pnpm 12 的包里没有 pnpm.cjs,Volta 2.0.2 生成的入口和 volta run 都跑不起来
- POST /pkg/{tool}/install 示例改用完整版本号;说明轮询 installed 接口的判据与上限;移除 Volta 2.0.2 不存在的 VOLTA_NODE_MIRROR
- 版本 nodejs-runtime 1.0.3 → 1.0.4、dev-environment-setup 2.0.4 → 2.0.5,sidecar 与 i18n source_hash 同步;不设客户端版本门槛
Correct the Volta paths in nodejs-runtime and dev-environment-setup, which still described the layout from before client 10.0.105, make probe-node.sh find the current one, and avoid pnpm 12, which Volta 2.0.2 cannot run.
验证:catalog metadata 与 i18n 校验 0 error,translate --check 通过;standalone 隔离 HOME + mock 模型下真实 Bash 工具按文档跑通,未调用真实模型;pnpm 9、10、11、12 逐版本实测。Windows 写法只对照源码。私有敏感词扫描未执行,经用户确认后合并。
This commit is contained in:
13 files changed
+217
-111
No files matched your search
@@ -14,7 +14,7 @@ description: >-
|
||||
"yarn", "volta", "nvm", "fnm", "nodejs version", "package-lock", or any
|
||||
Node.js / npm runtime error. 使用场景:用户需要 安装 Node.js、安装 npm、
|
||||
pnpm、yarn、配置全局包、解决 EACCES、PATH 问题、镜像/代理配置。
|
||||
version: 1.0.3
|
||||
version: 1.0.4
|
||||
type: procedural
|
||||
risk_level: low
|
||||
status: enabled
|
||||
@@ -30,7 +30,7 @@ tags:
|
||||
- environment
|
||||
metadata:
|
||||
author: desirecore
|
||||
updated_at: '2026-05-02'
|
||||
updated_at: '2026-11-01'
|
||||
i18n:
|
||||
default_locale: en-US
|
||||
source_locale: zh-CN
|
||||
@@ -43,7 +43,7 @@ metadata:
|
||||
description: >-
|
||||
Use this skill when the user needs to install, upgrade, or troubleshoot Node.js, npm, pnpm, yarn, and JavaScript/TypeScript runtime environments. Covers four-tier fallback strategy: (1) DesireCore HTTP API for in-app installation, (2) DesireCore built-in Volta CLI for Node.js + package manager version management, (3) system package managers (brew/apt/dnf/winget/NodeSource), (4) community nvm/fnm as last resort. Also covers global package management, npm registry/proxy configuration, EACCES permission errors, and PATH troubleshooting. Triggers include: "install node", "node not found", "npm not found", "npm EACCES", "pnpm", "yarn", "volta", "nvm", "fnm", "nodejs version", "package-lock", or any Node.js / npm runtime error. 使用场景:用户需要 安装 Node.js、安装 npm、 pnpm、yarn、配置全局包、解决 EACCES、PATH 问题、镜像/代理配置。
|
||||
body: ./SKILL.zh-CN.md
|
||||
source_hash: sha256:2b8a00816c65d71c
|
||||
source_hash: sha256:33f778ab7c9fd66a
|
||||
translated_by: human
|
||||
en-US:
|
||||
name: Node.js Runtime Management
|
||||
@@ -51,9 +51,9 @@ metadata:
|
||||
description: >-
|
||||
Use this skill when the user needs to install, upgrade, or troubleshoot Node.js, npm, pnpm, yarn, and JavaScript/TypeScript runtime environments. Covers four-tier fallback strategy: (1) DesireCore HTTP API for in-app installation, (2) DesireCore built-in Volta CLI for Node.js + package manager version management, (3) system package managers (brew/apt/dnf/winget/NodeSource), (4) community nvm/fnm as last resort. Also covers global package management, npm registry/proxy configuration, EACCES permission errors, and PATH troubleshooting. Triggers include: "install node", "node not found", "npm not found", "npm EACCES", "pnpm", "yarn", "volta", "nvm", "fnm", "nodejs version", "package-lock", or any Node.js / npm runtime error. Use cases: the user needs to install Node.js, install npm, pnpm, yarn, configure global packages, resolve EACCES, PATH issues, registry mirror / proxy configuration.
|
||||
body: ./SKILL.md
|
||||
source_hash: sha256:cb8150156dd47cbc
|
||||
source_hash: sha256:33f778ab7c9fd66a
|
||||
translated_by: human
|
||||
translated_at: '2026-05-03'
|
||||
translated_at: '2026-11-01'
|
||||
market:
|
||||
icon: >-
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0
|
||||
@@ -83,8 +83,9 @@ npm / pnpm / yarn / troubleshoot `node: command not found`, `npm: command not fo
|
||||
EACCES global install permission errors, node-gyp build failures, registry mirror / proxy issues, or other
|
||||
Node.js runtime problems, or when other skills (pptx using pptxgenjs, etc.) report "Node.js unavailable".
|
||||
|
||||
**How**: prefer the DesireCore built-in Volta and follow a four-tier fallback (HTTP API → Volta CLI →
|
||||
system package manager brew/apt/NodeSource/winget → community options nvm/fnm).
|
||||
**How**: first check whether `node` already works: DesireCore appends a managed Node directory to its service PATH, so nothing
|
||||
usually needs installing. To install or switch versions, prefer the DesireCore built-in Volta and follow a four-tier fallback
|
||||
(HTTP API → Volta CLI → system package manager brew/apt/NodeSource/winget → community options nvm/fnm).
|
||||
|
||||
## L1: Overview and Use Cases
|
||||
|
||||
@@ -106,7 +107,7 @@ Procedural skill. Before each Node.js environment operation, run `scripts/probe-
|
||||
|
||||
- **DesireCore first**: Volta + HTTP API as L1/L2, avoiding pollution of the system Node
|
||||
- **JSON-driven decisions**: the probe script outputs structured data that Claude can parse directly
|
||||
- **package.json#volta compatible**: Volta automatically switches versions per project
|
||||
- **package.json#volta compatible**: `volta run` uses the versions the project pins
|
||||
|
||||
## L2: Detailed Specification
|
||||
|
||||
@@ -123,11 +124,15 @@ See `../dev-environment-setup/references/probe-snapshot.md` for field definition
|
||||
|
||||
| Condition | Path |
|
||||
|------|------|
|
||||
| `system_node.path` non-empty and its version is sufficient (`system_npm.path` also non-empty when npm is needed) | Use `node` / `npm` directly; nothing to install |
|
||||
| A specific version is needed and `volta_tools.node` lists it | Absolute path `<Volta Home>/tools/image/node/<version>/bin/node` (→ `references/volta-desirecore.md`) |
|
||||
| `desirecore_api` non-empty | **L1** HTTP API |
|
||||
| `desirecore_api` empty, `volta_path` non-empty | **L2** Volta CLI |
|
||||
| Neither of the above | **L3** System package manager (brew / apt / NodeSource / winget) |
|
||||
| L1–L3 all fail or user explicitly requests | **L4** Community options (nvm / fnm) |
|
||||
|
||||
`system_node` is whatever PATH resolves, which may be DesireCore's managed Node: one managed version is appended after the system directories, so a system `node` wins when there is one. The Managed runtimes section of the `<env>` block lists the absolute path of every managed version.
|
||||
|
||||
### Step 3: Execute (only the main path is shown; see each reference for details)
|
||||
|
||||
#### L1: HTTP API (→ `references/volta-desirecore.md`)
|
||||
@@ -144,10 +149,10 @@ curl -sk -X POST "${BASE}/node/install" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"version":"22"}'
|
||||
|
||||
# 安装包管理器
|
||||
# 安装包管理器(必须是完整版本号,可选版本见 ${BASE}/pkg/pnpm/available)
|
||||
curl -sk -X POST "${BASE}/pkg/pnpm/install" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"version":"latest"}'
|
||||
-d '{"version":"9.15.9"}'
|
||||
|
||||
# 完成后刷新缓存
|
||||
curl -sk -X POST "${BASE}/environment/refresh"
|
||||
@@ -156,20 +161,23 @@ curl -sk -X POST "${BASE}/environment/refresh"
|
||||
#### L2: Volta CLI Absolute Path (→ `references/volta-desirecore.md`)
|
||||
|
||||
```bash
|
||||
VOLTA=${DESIRECORE_ROOT}/runtime/volta/volta
|
||||
export VOLTA_HOME=${DESIRECORE_ROOT}/runtime/volta
|
||||
VOLTA=$(jq -r .volta_path /tmp/node-probe.json)
|
||||
export VOLTA_HOME="${VOLTA_HOME:-${DESIRECORE_ROOT}/runtime/volta-home}"
|
||||
export VOLTA_FEATURE_PNPM=1
|
||||
|
||||
"$VOLTA" install node@22
|
||||
"$VOLTA" install pnpm@latest
|
||||
"$VOLTA" install yarn@latest
|
||||
"$VOLTA" fetch node@22
|
||||
"$VOLTA" fetch pnpm@11
|
||||
"$VOLTA" fetch yarn@latest
|
||||
"$VOLTA" list all
|
||||
|
||||
# 项目级固定(修改 package.json#volta)
|
||||
# 项目级固定(修改 package.json#volta),按固定版本运行
|
||||
"$VOLTA" pin node@22 pnpm@9
|
||||
"$VOLTA" run node --version
|
||||
```
|
||||
|
||||
Windows: `%USERPROFILE%\.desirecore\runtime\volta\volta.exe`.
|
||||
Set both variables on every Volta call: DesireCore sets them only for its own calls, not for Bash. Use pnpm 11 or earlier, because Volta 2.0.2 cannot run pnpm 12. The binary ships at `static/toolchains/<platform>-<arch>/volta/volta` under the app directory; `runtime/volta/volta` exists only after a manual Volta download.
|
||||
|
||||
Windows: `<install dir>\static\toolchains\win32-<arch>\volta\volta.exe`, with `VOLTA_HOME` at `$env:DESIRECORE_ROOT\runtime\volta-home`.
|
||||
|
||||
#### L3: System Package Manager
|
||||
|
||||
@@ -206,7 +214,8 @@ See `references/troubleshooting.md` for details:
|
||||
1. **Never `sudo npm install -g`**: use a user-level prefix or Volta/nvm.
|
||||
2. **Refresh after modifying the environment**: for L1, call `POST /api/runtime/environment/refresh`; for other paths, re-run the probe.
|
||||
3. **Cross-skill collaboration**: when `pptx` and others need Node.js, install via this skill's main path; for npm package quick reference, see `../dev-environment-setup/references/office-deps.md`.
|
||||
4. **Respect package.json#volta**: when this field is detected, prefer Volta — do not switch to nvm.
|
||||
4. **Respect package.json#volta**: when this field is detected, prefer Volta — do not switch to nvm. Run through `"$VOLTA" run`, because `cd` alone does not switch versions in DesireCore.
|
||||
5. **Do not use `runtime/volta-home/bin`**: these entries are Volta shims. DesireCore does not export `VOLTA_HOME`, and without it they read `~/.volta`, so they never reach DesireCore's Node: they fail with `Node is not available`, or pass through to a system Node if there is one. On PATH they also hang for more than 30 seconds. Repairing a broken link there does not help. Use `tools/image/node/<version>/bin` instead.
|
||||
|
||||
## References
|
||||
|
||||
|
||||
@@ -9,7 +9,8 @@ npm / pnpm / yarn / 排查 `node: command not found`、`npm: command not found`
|
||||
EACCES 全局安装权限错误、node-gyp 编译失败、registry 镜像 / proxy 问题 等
|
||||
Node.js 运行时问题,或其他 skill(pptx 用 pptxgenjs 等)报告 "Node.js 不可用" 时。
|
||||
|
||||
**怎么做**:优先使用 DesireCore 内置 Volta,按四级降级(HTTP API → Volta CLI →
|
||||
**怎么做**:先确认 `node` 是否已可用:DesireCore 把内置 Node 目录追加到了服务 PATH,通常不需要安装。
|
||||
需要安装或切换版本时,优先使用 DesireCore 内置 Volta,按四级降级(HTTP API → Volta CLI →
|
||||
系统包管理器 brew/apt/NodeSource/winget → 社区方案 nvm/fnm)执行。
|
||||
|
||||
## L1:概述与使用场景
|
||||
@@ -32,7 +33,7 @@ procedural skill。每次执行 Node.js 环境操作前,先运行 `scripts/pro
|
||||
|
||||
- **DesireCore 优先**:Volta + HTTP API 作为 L1/L2,避免污染系统 Node
|
||||
- **JSON 决策**:probe 脚本输出结构化数据,Claude 可直接解析
|
||||
- **package.json#volta 兼容**:Volta 自动按项目切换版本
|
||||
- **package.json#volta 兼容**:`volta run` 按项目固定的版本运行
|
||||
|
||||
## L2:详细规范
|
||||
|
||||
@@ -49,11 +50,15 @@ cat /tmp/node-probe.json | jq .
|
||||
|
||||
| 条件 | 路径 |
|
||||
|------|------|
|
||||
| `system_node.path` 非空且版本够用(用 npm 时 `system_npm.path` 也非空) | 直接用 `node` / `npm`,不需要安装 |
|
||||
| 需要指定版本,且 `volta_tools.node` 已列出 | 绝对路径 `<Volta Home>/tools/image/node/<version>/bin/node`(→ `references/volta-desirecore.md`) |
|
||||
| `desirecore_api` 非空 | **L1** HTTP API |
|
||||
| `desirecore_api` 空,`volta_path` 非空 | **L2** Volta CLI |
|
||||
| 上述都不满足 | **L3** 系统包管理器(brew / apt / NodeSource / winget) |
|
||||
| L1–L3 全部失败或用户明示 | **L4** 社区方案(nvm / fnm) |
|
||||
|
||||
`system_node` 是 PATH 解析到的结果,可能就是 DesireCore 的内置 Node:一个内置版本追加在系统目录之后,系统有 `node` 时系统版本优先。`<env>` 块的 Managed runtimes 段列出每个内置版本的绝对路径。
|
||||
|
||||
### 第三步:执行(仅展示主路径,详见各 references)
|
||||
|
||||
#### L1:HTTP API(→ `references/volta-desirecore.md`)
|
||||
@@ -70,10 +75,10 @@ curl -sk -X POST "${BASE}/node/install" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"version":"22"}'
|
||||
|
||||
# 安装包管理器
|
||||
# 安装包管理器(必须是完整版本号,可选版本见 ${BASE}/pkg/pnpm/available)
|
||||
curl -sk -X POST "${BASE}/pkg/pnpm/install" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"version":"latest"}'
|
||||
-d '{"version":"9.15.9"}'
|
||||
|
||||
# 完成后刷新缓存
|
||||
curl -sk -X POST "${BASE}/environment/refresh"
|
||||
@@ -82,20 +87,23 @@ curl -sk -X POST "${BASE}/environment/refresh"
|
||||
#### L2:Volta CLI 绝对路径(→ `references/volta-desirecore.md`)
|
||||
|
||||
```bash
|
||||
VOLTA=${DESIRECORE_ROOT}/runtime/volta/volta
|
||||
export VOLTA_HOME=${DESIRECORE_ROOT}/runtime/volta
|
||||
VOLTA=$(jq -r .volta_path /tmp/node-probe.json)
|
||||
export VOLTA_HOME="${VOLTA_HOME:-${DESIRECORE_ROOT}/runtime/volta-home}"
|
||||
export VOLTA_FEATURE_PNPM=1
|
||||
|
||||
"$VOLTA" install node@22
|
||||
"$VOLTA" install pnpm@latest
|
||||
"$VOLTA" install yarn@latest
|
||||
"$VOLTA" fetch node@22
|
||||
"$VOLTA" fetch pnpm@11
|
||||
"$VOLTA" fetch yarn@latest
|
||||
"$VOLTA" list all
|
||||
|
||||
# 项目级固定(修改 package.json#volta)
|
||||
# 项目级固定(修改 package.json#volta),按固定版本运行
|
||||
"$VOLTA" pin node@22 pnpm@9
|
||||
"$VOLTA" run node --version
|
||||
```
|
||||
|
||||
Windows:`%USERPROFILE%\.desirecore\runtime\volta\volta.exe`。
|
||||
每次调用 Volta 都要设置这两个变量:DesireCore 只在自己调用时设置,不传给 Bash。pnpm 要用 11 或更早的版本,Volta 2.0.2 运行不了 pnpm 12。二进制随包位于应用目录下的 `static/toolchains/<平台>-<架构>/volta/volta`;`runtime/volta/volta` 只有手动下载 Volta 后才存在。
|
||||
|
||||
Windows:`<安装目录>\static\toolchains\win32-<架构>\volta\volta.exe`,`VOLTA_HOME` 为 `$env:DESIRECORE_ROOT\runtime\volta-home`。
|
||||
|
||||
#### L3:系统包管理器
|
||||
|
||||
@@ -132,7 +140,8 @@ Windows:`%USERPROFILE%\.desirecore\runtime\volta\volta.exe`。
|
||||
1. **绝不 `sudo npm install -g`**:用户级 prefix 或 Volta/nvm。
|
||||
2. **修改环境后必须刷新**:L1 调 `POST /api/runtime/environment/refresh`;其它路径重跑 probe。
|
||||
3. **跨 skill 协作**:`pptx` 等需要 Node.js 时,按本 skill 主路径安装;npm 包速查见 `../dev-environment-setup/references/office-deps.md`。
|
||||
4. **package.json#volta 必须尊重**:检测到该字段时优先 Volta,不要切到 nvm。
|
||||
4. **package.json#volta 必须尊重**:检测到该字段时优先 Volta,不要切到 nvm。用 `"$VOLTA" run` 运行,在 DesireCore 里只 `cd` 不会切换版本。
|
||||
5. **不要使用 `runtime/volta-home/bin`**:这里的入口是 Volta shim。DesireCore 不导出 `VOLTA_HOME`,未导出时它们看的是 `~/.volta`,拿不到 DesireCore 的 Node:报 `Node is not available`,系统有 Node 时则透传到系统版本。放在 PATH 上还会卡住超过 30 秒。修好这里的断链也没有用,改用 `tools/image/node/<version>/bin`。
|
||||
|
||||
## 引用关系
|
||||
|
||||
|
||||
@@ -33,14 +33,14 @@
|
||||
},
|
||||
"release": {
|
||||
"state": "known",
|
||||
"version": "1.0.3",
|
||||
"version": "1.0.4",
|
||||
"versionScheme": "semver"
|
||||
},
|
||||
"timestamps": {
|
||||
"catalogUpdatedAt": {
|
||||
"state": "known",
|
||||
"value": "2026-07-07T13:14:31Z",
|
||||
"precision": "second"
|
||||
"value": "2026-11-01",
|
||||
"precision": "day"
|
||||
},
|
||||
"releasePublishedAt": {
|
||||
"state": "unknown"
|
||||
|
||||
@@ -12,19 +12,29 @@
|
||||
## 通过 DesireCore Volta 安装
|
||||
|
||||
```bash
|
||||
VOLTA=${DESIRECORE_ROOT}/runtime/volta/volta
|
||||
VOLTA=$(bash skills/nodejs-runtime/scripts/probe-node.sh | jq -r .volta_path)
|
||||
export VOLTA_HOME="${VOLTA_HOME:-${DESIRECORE_ROOT}/runtime/volta-home}"
|
||||
export VOLTA_FEATURE_PNPM=1
|
||||
|
||||
"$VOLTA" install pnpm@latest
|
||||
"$VOLTA" install yarn@latest
|
||||
"$VOLTA" install npm@10
|
||||
"$VOLTA" fetch pnpm@11 # pnpm 12 在 Volta 2.0.2 下跑不起来
|
||||
"$VOLTA" fetch yarn@latest
|
||||
"$VOLTA" fetch npm@10
|
||||
```
|
||||
|
||||
或 HTTP API:
|
||||
|
||||
```bash
|
||||
BASE="https://127.0.0.1:$(cat ${DESIRECORE_ROOT}/agent-service.port)/api/runtime"
|
||||
curl -sk -X POST "${BASE}/pkg/pnpm/install" -H "Content-Type: application/json" -d '{"version":"latest"}'
|
||||
curl -sk -X POST "${BASE}/pkg/pnpm/install" -H "Content-Type: application/json" -d '{"version":"9.15.9"}' # 必须是完整版本号
|
||||
```
|
||||
|
||||
装好的 pnpm / yarn 不在 PATH 上(PATH 上只有内置 Node 的目录),这样调用:
|
||||
|
||||
```bash
|
||||
"$VOLTA" run --node 22 --pnpm 9 pnpm --version
|
||||
|
||||
# 或直接用 image 目录,PATH 上要能找到 node
|
||||
"$VOLTA_HOME/tools/image/pnpm/<version>/bin/pnpm" --version
|
||||
```
|
||||
|
||||
## 项目级固定版本
|
||||
@@ -40,7 +50,7 @@ curl -sk -X POST "${BASE}/pkg/pnpm/install" -H "Content-Type: application/json"
|
||||
}
|
||||
```
|
||||
|
||||
在装了 Volta 的环境中 `cd` 进项目即自动切换。
|
||||
用 `"$VOLTA" run <命令>` 按这里的版本运行。`cd` 进项目自动切换要求 Volta shim 在 PATH 最前且已导出 `VOLTA_HOME`,DesireCore 里不是这种配置。
|
||||
|
||||
### packageManager 字段(Corepack 标准)
|
||||
|
||||
|
||||
@@ -13,11 +13,13 @@ export NVM_DIR="$HOME/.nvm"
|
||||
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
|
||||
node --version
|
||||
|
||||
# 3. Volta 已装但未在 PATH?
|
||||
ls ${DESIRECORE_ROOT}/runtime/volta/volta 2>/dev/null && \
|
||||
echo "运行 ${DESIRECORE_ROOT}/runtime/volta/volta 直接调用,无需 PATH"
|
||||
# 3. DesireCore 内置 Node 已装但不在 PATH?用绝对路径调用
|
||||
ls "${VOLTA_HOME:-${DESIRECORE_ROOT}/runtime/volta-home}/tools/image/node" 2>/dev/null
|
||||
"${VOLTA_HOME:-${DESIRECORE_ROOT}/runtime/volta-home}/tools/image/node/<version>/bin/node" --version
|
||||
```
|
||||
|
||||
不要改用 `runtime/volta-home/bin` 下的入口,原因见 `references/volta-desirecore.md`。
|
||||
|
||||
**根治**:按主 SKILL.md 决策树重新执行 L1–L3 安装路径。
|
||||
|
||||
## npm EACCES(全局安装权限错误)
|
||||
@@ -147,9 +149,9 @@ probe-node.sh 输出后,按字段快速判断:
|
||||
|
||||
| 字段 | 期望 | 失败原因 |
|
||||
|------|------|----------|
|
||||
| `system_node.version` | 非空且 ≥ 18 | 未装或版本太低 |
|
||||
| `system_node.version` | 非空且 ≥ 18 | 未装或版本太低(这是 PATH 解析到的 Node,可能是内置版本) |
|
||||
| `system_npm.version` | 非空 | 应随 Node 自带 |
|
||||
| `volta_path` | 非空 | DesireCore Volta 未释放,调 `POST /api/runtime/volta/install` |
|
||||
| `volta_path` | 非空 | 应用不在默认安装位置,走 L1 或到应用目录下找(见 `references/volta-desirecore.md`) |
|
||||
| `volta_tools.node` | 非空数组 | 还未装任何 Volta 管理的 Node 版本 |
|
||||
| `package_json_volta` | 项目用 Volta | 优先 Volta,不要切到 nvm |
|
||||
| `registry` | `*.npmmirror.com` | 已加速;空字符串可能是 npm 未装 |
|
||||
|
||||
@@ -1,8 +1,31 @@
|
||||
# DesireCore 内置 Volta(L1 / L2 主路径)
|
||||
|
||||
DesireCore 内置 [Volta](https://volta.sh/) v2.0.2(Rust 实现的 Node.js 工具链管理器)。Volta 二进制随应用打包于 `static/volta/`,运行时位于 `${DESIRECORE_ROOT}/runtime/volta/`,**用户无需单独安装**。
|
||||
DesireCore 内置 [Volta](https://volta.sh/) v2.0.2(Rust 实现的 Node.js 工具链管理器),**用户无需单独安装**。
|
||||
|
||||
> 与系统 Node.js 完全隔离:Volta 安装的工具位于 `${DESIRECORE_ROOT}/runtime/volta/tools/image/`,不修改系统 PATH。
|
||||
| 内容 | 位置 |
|
||||
|------|------|
|
||||
| Volta Home(版本与工具数据) | `${VOLTA_HOME:-${DESIRECORE_ROOT}/runtime/volta-home}`:启动 DesireCore 前显式设置的 `VOLTA_HOME` 优先,否则是实例目录 |
|
||||
| Volta 二进制(随包,默认) | 应用目录下的 `static/toolchains/<平台>-<架构>/volta/volta`(Windows 为 `volta.exe`)。应用目录在 macOS 是 `<App>.app/Contents`,其他平台是安装目录 |
|
||||
| Volta 二进制(手动下载,存在时优先) | `${DESIRECORE_ROOT}/runtime/volta/volta`,只有随包二进制不可用、经 `POST /volta/install` 下载后才存在 |
|
||||
| 内置 Node | `<Volta Home>/tools/image/node/<version>/bin/`(Windows 没有 `bin` 这一层) |
|
||||
|
||||
## 直接使用内置 Node(通常不需要安装)
|
||||
|
||||
DesireCore 把一个内置 Node 版本(推荐版本已安装就用它,否则取最高版本)的目录追加到服务进程 PATH 末尾,Bash 等工具都会继承,不改用户的 shell 配置。
|
||||
|
||||
- 系统没有 Node 时,直接运行 `node`、`npm`、`npx`。
|
||||
- 系统已有 Node 时系统版本优先。要用内置版本,写绝对路径。版本清单见 `<env>` 块的 Managed runtimes 段,或列目录:
|
||||
|
||||
```bash
|
||||
VOLTA_HOME="${VOLTA_HOME:-${DESIRECORE_ROOT}/runtime/volta-home}"
|
||||
ls "$VOLTA_HOME/tools/image/node"
|
||||
|
||||
NODE_BIN="$VOLTA_HOME/tools/image/node/<version>/bin"
|
||||
"$NODE_BIN/node" --version
|
||||
PATH="$NODE_BIN:$PATH" npm --version # npm 要从 PATH 找 node
|
||||
```
|
||||
|
||||
> **不要使用 `<Volta Home>/bin`**。这里的 `node`、`npm` 等入口是 Volta shim,它按 `VOLTA_HOME` 选 Home。DesireCore 不导出这个变量,未导出时 shim 看的是 `~/.volta`(不存在还会新建),拿不到 DesireCore 的 Node:报 `Node is not available`,系统有 Node 时则透传到系统版本。这个目录放在 PATH 上还会卡住超过 30 秒。旧版升级的用户这里可能是断链,修好链接同样拿不到 DesireCore 的 Node,不需要修。
|
||||
|
||||
## L1:通过 HTTP API 操作(推荐,DesireCore 应用内)
|
||||
|
||||
@@ -22,7 +45,7 @@ curl -sk --max-time 0.5 "${BASE}/environment" >/dev/null \
|
||||
|
||||
```bash
|
||||
curl -sk "${BASE}/volta/status"
|
||||
curl -sk -X POST "${BASE}/volta/install" # 自动下载到 runtime/
|
||||
curl -sk -X POST "${BASE}/volta/install" # 随包 Volta 可用时直接返回成功,否则下载到 runtime/volta/
|
||||
```
|
||||
|
||||
### Node.js 版本
|
||||
@@ -54,9 +77,10 @@ TOOL="pnpm" # 或 yarn / npm
|
||||
curl -sk "${BASE}/pkg/${TOOL}/installed"
|
||||
curl -sk "${BASE}/pkg/${TOOL}/available"
|
||||
|
||||
# 必须是完整版本号,latest、9 这类写法返回 400
|
||||
curl -sk -X POST "${BASE}/pkg/${TOOL}/install" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"version":"latest"}'
|
||||
-d '{"version":"9.15.9"}'
|
||||
|
||||
curl -sk -X POST "${BASE}/pkg/${TOOL}/remove" \
|
||||
-H "Content-Type: application/json" \
|
||||
@@ -65,7 +89,7 @@ curl -sk -X POST "${BASE}/pkg/${TOOL}/remove" \
|
||||
|
||||
### 实时输出 / 缓存刷新
|
||||
|
||||
异步任务:监听 Socket.IO 事件 `runtime:terminal` / `runtime:complete`,按 taskId 过滤。
|
||||
异步任务:监听 Socket.IO 事件 `runtime:terminal` / `runtime:complete`,按 taskId 过滤。没有 Socket.IO 客户端时,轮询 `GET ${BASE}/node/installed`(包管理器为 `GET ${BASE}/pkg/${TOOL}/installed`):安装时等目标版本出现,移除时等它消失。任务失败时轮询不会收到信号,所以要设上限;超时后看 `<Volta Home>/log/` 里最新的 `volta-error-*.log`。
|
||||
|
||||
```bash
|
||||
curl -sk -X POST "${BASE}/environment/refresh" # 安装结束后刷新
|
||||
@@ -76,17 +100,19 @@ curl -sk -X POST "${BASE}/environment/refresh" # 安装结束后刷新
|
||||
### macOS / Linux
|
||||
|
||||
```bash
|
||||
VOLTA=${DESIRECORE_ROOT}/runtime/volta/volta
|
||||
export VOLTA_HOME=${DESIRECORE_ROOT}/runtime/volta
|
||||
export VOLTA_FEATURE_PNPM=1
|
||||
# export VOLTA_NODE_MIRROR=https://npmmirror.com/mirrors/node # 中国大陆加速
|
||||
# 二进制路径取自探测结果,为空时见下方「找不到 Volta 二进制」
|
||||
VOLTA=$(bash skills/nodejs-runtime/scripts/probe-node.sh | jq -r .volta_path)
|
||||
|
||||
# 安装
|
||||
"$VOLTA" install node@22 # 最新 22.x
|
||||
"$VOLTA" install node@20.11.0 # 精确版本
|
||||
"$VOLTA" install pnpm@latest
|
||||
"$VOLTA" install yarn@latest
|
||||
"$VOLTA" install npm@10
|
||||
# 每次调用都要设置:DesireCore 只在自己调用 Volta 时设置它们,不传给 Bash
|
||||
export VOLTA_HOME="${VOLTA_HOME:-${DESIRECORE_ROOT}/runtime/volta-home}"
|
||||
export VOLTA_FEATURE_PNPM=1
|
||||
|
||||
# 下载到 Volta Home(与 DesireCore 自身的做法相同,不改默认版本)
|
||||
"$VOLTA" fetch node@22 # 最新 22.x
|
||||
"$VOLTA" fetch node@20.11.0 # 精确版本
|
||||
"$VOLTA" fetch pnpm@11 # pnpm 12 在 Volta 2.0.2 下跑不起来,见下方故障排查
|
||||
"$VOLTA" fetch yarn@latest
|
||||
"$VOLTA" fetch npm@10
|
||||
|
||||
# 列表
|
||||
"$VOLTA" list all
|
||||
@@ -94,6 +120,11 @@ export VOLTA_FEATURE_PNPM=1
|
||||
|
||||
# 项目级固定(写入 package.json#volta)
|
||||
"$VOLTA" pin node@22 pnpm@9
|
||||
|
||||
# 运行:项目固定了版本时直接 run,否则显式传版本
|
||||
"$VOLTA" run node --version
|
||||
"$VOLTA" run --node 22 node --version
|
||||
"$VOLTA" run --node 22 --pnpm 9 pnpm --version
|
||||
```
|
||||
|
||||
`volta pin` 后 `package.json` 中会自动追加:
|
||||
@@ -104,53 +135,60 @@ export VOLTA_FEATURE_PNPM=1
|
||||
}
|
||||
```
|
||||
|
||||
后续 `cd` 进项目目录时 Volta 自动激活对应版本。
|
||||
项目没有固定版本时,`"$VOLTA" run node` 报 `Node is not available`(提示 `first set a default version`),需要显式传 `--node`,或用 `"$VOLTA" install node@22` 把它设为这个 Home 的默认版本。
|
||||
|
||||
### 找不到 Volta 二进制
|
||||
|
||||
`probe-node.sh` 依次查找 `${DESIRECORE_ROOT}/runtime/volta/volta`、`$DESIRECORE_STATIC_DIR` 下的工具链、`<Volta Home>/bin/node` 的链接目标所在目录,以及默认安装位置(`/Applications/*.app/Contents/static`、`/opt/*/static`)。应用装在别处时 `volta_path` 为空(AppImage 每次启动的挂载路径都不同),这时走 L1,或按本文开头的表格到应用目录下找。
|
||||
|
||||
### Windows PowerShell
|
||||
|
||||
```powershell
|
||||
$Volta = "$env:USERPROFILE\.desirecore\runtime\volta\volta.exe"
|
||||
$env:VOLTA_HOME = "$env:USERPROFILE\.desirecore\runtime\volta"
|
||||
# 手动下载过 Volta 时改用 "$env:DESIRECORE_ROOT\runtime\volta\volta.exe"
|
||||
$Volta = "<安装目录>\static\toolchains\win32-x64\volta\volta.exe" # ARM 为 win32-arm64
|
||||
if (-not $env:VOLTA_HOME) { $env:VOLTA_HOME = "$env:DESIRECORE_ROOT\runtime\volta-home" }
|
||||
$env:VOLTA_FEATURE_PNPM = "1"
|
||||
|
||||
& $Volta install node@22
|
||||
& $Volta install pnpm@latest
|
||||
& $Volta fetch node@22
|
||||
& $Volta fetch pnpm@11
|
||||
& $Volta list all
|
||||
```
|
||||
|
||||
### 移除
|
||||
|
||||
Volta 没有 `volta uninstall node`,直接删目录或用 HTTP API:
|
||||
Volta 不支持 `volta uninstall node`,优先用 HTTP API,它会同时清理已下载的归档:
|
||||
|
||||
```bash
|
||||
rm -rf ${DESIRECORE_ROOT}/runtime/volta/tools/image/node/<version>
|
||||
```
|
||||
|
||||
或:
|
||||
```bash
|
||||
curl -sk -X POST "${BASE}/node/remove" -H "Content-Type: application/json" -d '{"version":"22.11.0"}'
|
||||
```
|
||||
|
||||
或直接删目录:
|
||||
```bash
|
||||
rm -rf "${VOLTA_HOME:-${DESIRECORE_ROOT}/runtime/volta-home}/tools/image/node/<version>"
|
||||
```
|
||||
|
||||
## 可视化管理
|
||||
|
||||
DesireCore 应用 → 资源管理器 → 计算资源 → **运行环境** Tab,GUI 安装/删除 Node.js 与包管理器。
|
||||
|
||||
## 版本自动切换(核心优势)
|
||||
## 按项目切换版本
|
||||
|
||||
只要 `package.json` 中有 `volta` 字段,Volta 会在 `cd` 进入目录时**自动激活**对应版本。无需手动 `volta use`,也无需 `.nvmrc`。
|
||||
`package.json` 中有 `volta` 字段时,`"$VOLTA" run <命令>` 按固定的版本运行,无需 `volta use`,也无需 `.nvmrc`。
|
||||
|
||||
`cd` 进目录自动切换要求 Volta shim 在 PATH 最前且已导出 `VOLTA_HOME`。DesireCore 的 PATH 上是固定的内置 Node,不是 shim,所以在这里只 `cd` 不会切换版本。
|
||||
|
||||
## Volta vs nvm
|
||||
|
||||
| 维度 | Volta(DesireCore 内置) | nvm(社区) |
|
||||
|------|--------------------------|-------------|
|
||||
| 安装方式 | 随 DesireCore 内置 | 用户手动 |
|
||||
| 版本切换 | **自动**(基于 package.json) | 手动 `nvm use` 或 `.nvmrc` |
|
||||
| 版本切换 | `volta run` 按 package.json 选择 | 手动 `nvm use` 或 `.nvmrc` |
|
||||
| 包管理器 | 支持(pnpm/yarn/npm 都可固定版本) | 不支持 |
|
||||
| Windows 原生 | ✅ | 需 nvm-windows(功能受限) |
|
||||
| 速度 | 极快(Rust 实现) | 较慢(shell 脚本) |
|
||||
| 系统 PATH | 不污染 | 修改 PATH |
|
||||
| GUI | DesireCore 运行环境 Tab | 无 |
|
||||
| 镜像加速 | `VOLTA_NODE_MIRROR` | 无内建支持 |
|
||||
| 自定义下载源 | Volta Home 下的 `hooks.json` | 无内建支持 |
|
||||
|
||||
**结论**:DesireCore 应用内、有 Volta 时永远首选 Volta;外部脚本可考虑 nvm/fnm。
|
||||
|
||||
@@ -158,8 +196,11 @@ DesireCore 应用 → 资源管理器 → 计算资源 → **运行环境** Tab
|
||||
|
||||
| 现象 | 排查 |
|
||||
|------|------|
|
||||
| `volta: not found` | 二进制未释放,调 `POST /api/runtime/volta/install` |
|
||||
| `Volta error: Could not download node v22.x.x` | 网络或镜像问题,设 `VOLTA_NODE_MIRROR` |
|
||||
| `volta install pnpm` 报错 | 检查 `VOLTA_FEATURE_PNPM=1` 是否设置 |
|
||||
| Windows Defender 隔离 volta.exe | 信任 `~\.desirecore\runtime\volta\` 目录 |
|
||||
| `cd` 进项目后版本未切换 | 确认 `package.json` 中 `volta` 字段且 PATH 中 Volta shim 在最前 |
|
||||
| `volta: not found` | Volta 不在 PATH 上是正常的,用绝对路径调用,见「找不到 Volta 二进制」 |
|
||||
| `Node is not available` | 调到了 `<Volta Home>/bin` 下的 shim,或 Volta 没带 `VOLTA_HOME`:改用 `tools/image/node/<version>/bin`,或同时设置 `VOLTA_HOME` 和 `VOLTA_FEATURE_PNPM`。`volta run` 在项目没有固定版本时也报这个错:传 `--node` |
|
||||
| `node` 卡住超过 30 秒 | `<Volta Home>/bin` 在 PATH 上且未导出 `VOLTA_HOME`。把它从 PATH 去掉,需要时改加 `tools/image/node/<version>/bin` |
|
||||
| `Could not download ...` | 网络或下载源问题,可以重试。Volta 2.0.2 没有镜像环境变量,自定义下载源用 `hooks.json`,否则降级到 L3 |
|
||||
| `Cannot find module .../pnpm.cjs` | pnpm 12 的包里没有 `pnpm.cjs`,Volta 2.0.2 生成的入口跑不起来,`volta run` 同样失败。改用 pnpm 11 或更早的版本 |
|
||||
| 其他 pnpm 相关报错 | 检查 `VOLTA_FEATURE_PNPM=1` 是否设置 |
|
||||
| Windows Defender 隔离 volta.exe | 信任应用安装目录下的 `static\toolchains\` |
|
||||
| `cd` 进项目后版本未切换 | DesireCore 里符合预期,用 `"$VOLTA" run` 按 `package.json#volta` 运行 |
|
||||
@@ -46,16 +46,33 @@ SYS_NODE=$(detect_tool node)
|
||||
SYS_NPM=$(detect_tool npm)
|
||||
|
||||
# ── DesireCore Volta ────────────────────
|
||||
VOLTA_BIN="${DESIRECORE_ROOT}/runtime/volta/volta"
|
||||
# Volta Home:启动 DesireCore 前显式设置的 VOLTA_HOME 优先,否则是实例目录
|
||||
VOLTA_HOME_DIR="${VOLTA_HOME:-${DESIRECORE_ROOT}/runtime/volta-home}"
|
||||
|
||||
# 二进制与服务同序:手动下载的 runtime/volta/volta 优先,其次随包工具链。
|
||||
# 桌面版的应用目录不在环境变量里,随包路径再看 Home 里入口的链接目标(只读链接,不执行入口;
|
||||
# Volta 建入口时指向自身目录的 volta-shim,旧版升级后可能已断)和默认安装位置。
|
||||
VOLTA_TARGET="${PLATFORM}-${ARCH}"
|
||||
VOLTA_SHIM=$(readlink "${VOLTA_HOME_DIR}/bin/node" 2>/dev/null)
|
||||
VOLTA_PATH=""
|
||||
VOLTA_VERSION=""
|
||||
if [ -x "$VOLTA_BIN" ]; then
|
||||
VOLTA_PATH="$VOLTA_BIN"
|
||||
VOLTA_VERSION=$("$VOLTA_BIN" --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+(\.[0-9]+)?' | head -n1)
|
||||
fi
|
||||
for VOLTA_BIN in \
|
||||
"${DESIRECORE_ROOT}/runtime/volta/volta" \
|
||||
"${DESIRECORE_STATIC_DIR}/toolchains/${VOLTA_TARGET}/volta/volta" \
|
||||
"${VOLTA_SHIM%/*}/volta" \
|
||||
/Applications/*.app/Contents/static/toolchains/"${VOLTA_TARGET}"/volta/volta \
|
||||
/opt/*/static/toolchains/"${VOLTA_TARGET}"/volta/volta
|
||||
do
|
||||
if [ -f "$VOLTA_BIN" ] && [ -x "$VOLTA_BIN" ]; then
|
||||
VOLTA_PATH="$VOLTA_BIN"
|
||||
# 必须带 VOLTA_HOME:不带时 Volta 会新建 ~/.volta
|
||||
VOLTA_VERSION=$(VOLTA_HOME="$VOLTA_HOME_DIR" "$VOLTA_BIN" --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+(\.[0-9]+)?' | head -n1)
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# Volta 已装工具(直接读 image 目录最稳)
|
||||
VOLTA_IMG="${DESIRECORE_ROOT}/runtime/volta/tools/image"
|
||||
VOLTA_IMG="${VOLTA_HOME_DIR}/tools/image"
|
||||
list_dir() {
|
||||
local dir="$1"
|
||||
if [ -d "$dir" ]; then
|
||||
|
||||
Reference in new issue
Block a user