← 返回 Skills 市场
piaolingwuyu

用于自动切换项目中适合的node 版本

作者 piaolingwuyu · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ✓ 安全检测通过
101
总下载
0
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install nvm-auto-switch
功能描述
根据 package.json 中的 engines 字段自动检测 Node.js 版本要求,如未安装 nvm 则自动安装,并切换到正确的 Node 版本。支持 Windows、macOS 和 Linux。在开发 Node.js 项目、切换 Node 版本或设置开发环境时使用。
使用说明 (SKILL.md)

\r \r

NVM 自动切换\r

\r 根据 package.json 的 engines 字段自动切换到正确的 Node.js 版本。\r \r

使用场景\r

\r

  • 进入 Node.js 项目目录\r
  • 设置新的开发环境\r
  • Node 版本不匹配错误\r
  • CI/CD 流水线设置\r \r

快速开始\r

\r

Windows\r

# 自动获取当前目录\r
.\scripts\
vm-auto-switch.ps1\r
\r
# 或指定项目路径\r
.\scripts\
vm-auto-switch.ps1 [项目路径]\r
```\r
\r
### macOS / Linux\r
```bash\r
# 自动获取当前目录\r
./scripts/nvm-auto-switch.sh\r
\r
# 或指定项目路径\r
./scripts/nvm-auto-switch.sh [项目路径]\r
```\r
\r
## 工作原理\r
\r
1. **检测操作系统** - 识别 Windows、macOS 或 Linux\r
2. **自动获取项目路径** - 如未提供路径,自动使用当前工作目录\r
3. **检查当前 Node 版本** - 获取当前激活的 Node.js 版本\r
4. **检查/安装 NVM** - 如未安装则自动安装\r
5. **读取 package.json** - 解析 engines.node 字段\r
6. **对比版本** - 如果当前版本已满足要求,跳过切换\r
7. **查找/安装 Node** - 使用现有版本或下载匹配版本\r
8. **切换版本** - 激活正确的 Node 版本\r
\r
## 工作流程\r
\r
```\r
获取项目路径(参数或当前目录)\r
↓\r
检查当前 Node 版本\r
↓\r
读取 package.json engines.node\r
解析版本要求 (例如 >=14.0.0)\r
↓\r
当前版本已满足要求?\r
├── 是 → 跳过切换,提示当前版本兼容\r
│\r
└── 否 → 继续\r
    ↓\r
    检查 NVM 是否已安装?\r
    ├── 否 → 自动安装 NVM\r
    │   ├── Windows: 下载 nvm-setup.exe\r
    │   └── macOS/Linux: 运行安装脚本\r
    │\r
    └── 是 → 继续\r
        ↓\r
        查找匹配的已安装版本?\r
        ├── 是 → nvm use \x3C版本号>\r
        │\r
        └── 否 → nvm install \x3C最新匹配版本>\r
            nvm use \x3C版本号>\r
```\r
\r
## 脚本\r
\r
`scripts/` 目录下的工具脚本:\r
\r
| 脚本 | 平台 | 用途 |\r
|------|------|------|\r
| `nvm-auto-switch.ps1` | Windows | PowerShell 实现 |\r
| `nvm-auto-switch.sh` | macOS/Linux | Bash 实现 |\r
\r
## 示例\r
\r
**当前目录(自动获取):**\r
```bash\r
./scripts/nvm-auto-switch.sh\r
```\r
\r
```powershell\r
.\scripts\
vm-auto-switch.ps1\r
```\r
\r
**指定项目:**\r
```bash\r
./scripts/nvm-auto-switch.sh /path/to/project\r
```\r
\r
```powershell\r
.\scripts\
vm-auto-switch.ps1 "C:\projects\my-app"\r
```\r
\r
## 注意事项\r
\r
- Windows 需要管理员权限来安装 nvm\r
- macOS/Linux 需要 curl 来安装 nvm\r
- 支持版本前缀:`^`, `~`, `>=`, `\x3C=` 等\r
- 安装 nvm 后可能需要重启终端\r
- 不提供路径参数时,自动使用当前工作目录\r
安全使用建议
This skill is internally consistent with its purpose, but review these points before using it: 1) The Bash script will download and immediately execute the nvm install script from GitHub (curl | bash). Although it uses the official nvm raw URL and a pinned tag, executing remote installers has supply-chain risk — if you are cautious, install nvm manually or inspect the install script before running. 2) The SKILL.md mentions a Windows PowerShell script but that file is not included; Windows behavior is therefore unclear. 3) The package.json parsing is simple and may fail on unusual formatting; test in a safe project first. 4) Run this as a non-root user, and be prepared to restart your shell after nvm installation. If you need higher assurance, fetch the install script, verify its contents (or checksum), and run it interactively rather than piping it directly to bash.
能力评估
Purpose & Capability
The name/description describe auto-switching Node versions based on package.json and the provided Bash script implements exactly that: reading package.json, detecting required Node version, installing/loading nvm if missing, and installing/using a matching Node. No unrelated credentials, binaries, or config paths are requested.
Instruction Scope
The SKILL.md and the shell script stay within scope (detect project path, read package.json, install/use nvm, install Node versions). Notes: (1) SKILL.md references a PowerShell script (nvm-auto-switch.ps1) for Windows but that file is not included — missing file means Windows behavior is unspecified; (2) package.json is parsed with a simple grep which is brittle for non-standard formatting; (3) the script performs a network install of nvm by piping the remote install script to bash—this is expected for auto-install but is an important execution-time risk to be aware of.
Install Mechanism
There is no separate install spec (instruction-only with an included script). The script runs curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash to install nvm. Using the official nvm raw URL and a pinned version is reasonable, but curl|bash executes remote code at run-time and carries the usual remote-execution risk (supply-chain/tampering).
Credentials
The skill declares no environment variables or credentials and does not request unrelated access. The script uses standard environment values (HOME, PATH) and external tools (curl, node, npm, nvm) appropriate to its function. SKILL.md correctly notes that Windows may require admin rights and macOS/Linux require curl.
Persistence & Privilege
The skill is not force-included (always: false) and doesn't attempt to modify other skills or system-wide settings. It simply installs/loads nvm in the user's home environment when run.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install nvm-auto-switch
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /nvm-auto-switch 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
nvm-auto-switch 1.0.0 - Initial release. - Automatically detects Node.js version requirements from package.json and switches Node versions accordingly. - Installs nvm automatically if not present. - Supports Windows (PowerShell) and macOS/Linux (Bash). - Can be run with or without specifying a project path; defaults to current directory. - Handles Node version matching based on engines.node, including common version prefixes.
元数据
Slug nvm-auto-switch
版本 1.0.0
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 1
常见问题

用于自动切换项目中适合的node 版本 是什么?

根据 package.json 中的 engines 字段自动检测 Node.js 版本要求,如未安装 nvm 则自动安装,并切换到正确的 Node 版本。支持 Windows、macOS 和 Linux。在开发 Node.js 项目、切换 Node 版本或设置开发环境时使用。 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 101 次。

如何安装 用于自动切换项目中适合的node 版本?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install nvm-auto-switch」即可一键安装,无需额外配置。

用于自动切换项目中适合的node 版本 是免费的吗?

是的,用于自动切换项目中适合的node 版本 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

用于自动切换项目中适合的node 版本 支持哪些平台?

用于自动切换项目中适合的node 版本 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 用于自动切换项目中适合的node 版本?

由 piaolingwuyu(@piaolingwuyu)开发并维护,当前版本 v1.0.0。

💬 留言讨论