← Back to Skills Marketplace
piaolingwuyu

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

by piaolingwuyu · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ✓ Security Clean
101
Downloads
0
Stars
0
Active Installs
1
Versions
Install in OpenClaw
/install nvm-auto-switch
Description
根据 package.json 中的 engines 字段自动检测 Node.js 版本要求,如未安装 nvm 则自动安装,并切换到正确的 Node 版本。支持 Windows、macOS 和 Linux。在开发 Node.js 项目、切换 Node 版本或设置开发环境时使用。
README (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
Usage Guidance
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.
Capability Assessment
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.
How to Use
  1. Make sure OpenClaw is installed (local or Docker)
  2. Run the install command in chat: /install nvm-auto-switch
  3. After installation, invoke the skill by name or use /nvm-auto-switch
  4. Provide required inputs per the skill's parameter spec and get structured output
Version History
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.
Metadata
Slug nvm-auto-switch
Version 1.0.0
License MIT-0
All-time Installs 0
Active Installs 0
Total Versions 1
Frequently Asked Questions

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

根据 package.json 中的 engines 字段自动检测 Node.js 版本要求,如未安装 nvm 则自动安装,并切换到正确的 Node 版本。支持 Windows、macOS 和 Linux。在开发 Node.js 项目、切换 Node 版本或设置开发环境时使用。 It is an AI Agent Skill for Claude Code / OpenClaw, with 101 downloads so far.

How do I install 用于自动切换项目中适合的node 版本?

Run "/install nvm-auto-switch" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.

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

Yes, 用于自动切换项目中适合的node 版本 is completely free, licensed under MIT-0. You can download, install and use it at no cost.

Which platforms does 用于自动切换项目中适合的node 版本 support?

用于自动切换项目中适合的node 版本 is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).

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

It is built and maintained by piaolingwuyu (@piaolingwuyu); the current version is v1.0.0.

💬 Comments