From e96d35cc7fe044803e75aa3444b14046001909da Mon Sep 17 00:00:00 2001 From: timzhong2000 Date: Sat, 22 Aug 2026 21:33:42 +0800 Subject: [PATCH] Add JavaScript and TypeScript aliases --- README.md | 2 +- README_zh.md | 2 +- skills/run-code-snippet/SKILL.md | 2 +- src/cli.rs | 12 ++++++++++-- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 9b6db6e..98b3aff 100644 --- a/README.md +++ b/README.md @@ -144,7 +144,7 @@ run-code [OPTIONS] TOOLCHAIN[@VERSION] run-code skill ``` -- `TOOLCHAIN[@VERSION]`: Select a language and optional version. Supported toolchains are `python`, `node`, `rust`, `go`, and `dotnet`; `csharp` and `cs` are aliases for `dotnet`. +- `TOOLCHAIN[@VERSION]`: Select a language and optional version. Supported toolchains are `python`, `node`, `rust`, `go`, and `dotnet`; `javascript` and `typescript` are aliases for `node`, while `csharp` and `cs` are aliases for `dotnet`. - `-p, --package SPEC`: Add a temporary dependency. Repeat the option to install multiple packages. Specs follow each ecosystem: Python uses `NAME==VERSION`; Node, Rust, Go, and .NET use `NAME@VERSION`. Rust also supports `NAME[@VERSION][FEATURE,...]`, such as `'tokio@1[full]'`. - `--commonjs`: Run Node code as CommonJS. The default is ESM with top-level `await` support. - `--clean`: Delete the generated project after execution. Without this option, the project is retained and its path appears in the displayed command. diff --git a/README_zh.md b/README_zh.md index f478574..d07a03a 100644 --- a/README_zh.md +++ b/README_zh.md @@ -144,7 +144,7 @@ run-code [OPTIONS] TOOLCHAIN[@VERSION] run-code skill ``` -- `TOOLCHAIN[@VERSION]`:选择语言及版本。支持 `python`、`node`、`rust`、`go` 和 `dotnet`;`csharp`、`cs` 是 `dotnet` 的别名,版本可以省略。 +- `TOOLCHAIN[@VERSION]`:选择语言及版本。支持 `python`、`node`、`rust`、`go` 和 `dotnet`;`javascript`、`typescript` 是 `node` 的别名,`csharp`、`cs` 是 `dotnet` 的别名,版本可以省略。 - `-p, --package SPEC`:添加临时依赖,可重复使用以安装多个包。依赖格式遵循对应生态;Python 版本使用 `NAME==VERSION`,Node、Rust、Go 和 .NET 使用 `NAME@VERSION`。Rust 还支持 `NAME[@VERSION][FEATURE,...]`,例如 `'tokio@1[full]'`。 - `--commonjs`:让 Node 以 CommonJS 方式运行;默认使用支持顶层 `await` 的 ESM。 - `--clean`:运行结束后删除临时项目;不指定时保留项目,默认输出的执行命令中会包含项目路径。 diff --git a/skills/run-code-snippet/SKILL.md b/skills/run-code-snippet/SKILL.md index 43805bf..f7312c1 100644 --- a/skills/run-code-snippet/SKILL.md +++ b/skills/run-code-snippet/SKILL.md @@ -30,7 +30,7 @@ CODE '@ | run-code TOOLCHAIN[@VERSION] [--package SPEC ...] [--commonjs] [--clean] [--quiet] ``` -使用 `python`、`node`、`rust`、`go` 或 `dotnet`;`csharp` 和 `cs` 是 `dotnet` 的别名。省略版本时使用内置的最新稳定版本。Python 依赖版本使用 `NAME==VERSION`;Rust 依赖可用 `NAME[@VERSION][FEATURE,...]` 指定 Cargo features;.NET 依赖使用 NuGet 的 `NAME[@VERSION]`。Node 默认以 ESM 统一运行 JavaScript/TypeScript,仅在代码明确依赖 CommonJS 时添加 `--commonjs`。C# 使用 .NET 10+ file-based app。Python 和 Node 未指定 `--package` 时直接执行且不创建项目;指定依赖时才创建隔离项目。需要项目时默认保留;仅在明确只需一次结果时添加 `--clean`,仅需代码本身的输出时添加 `--quiet`。直接调用工具,不自行创建项目或检查运行环境。 +使用 `python`、`node`、`rust`、`go` 或 `dotnet`;`javascript` 和 `typescript` 是 `node` 的别名,`csharp` 和 `cs` 是 `dotnet` 的别名。省略版本时使用内置的最新稳定版本。Python 依赖版本使用 `NAME==VERSION`;Rust 依赖可用 `NAME[@VERSION][FEATURE,...]` 指定 Cargo features;.NET 依赖使用 NuGet 的 `NAME[@VERSION]`。Node 默认以 ESM 统一运行 JavaScript/TypeScript,仅在代码明确依赖 CommonJS 时添加 `--commonjs`。C# 使用 .NET 10+ file-based app。Python 和 Node 未指定 `--package` 时直接执行且不创建项目;指定依赖时才创建隔离项目。需要项目时默认保留;仅在明确只需一次结果时添加 `--clean`,仅需代码本身的输出时添加 `--quiet`。直接调用工具,不自行创建项目或检查运行环境。 ## Examples diff --git a/src/cli.rs b/src/cli.rs index 05be355..c7cdb84 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -54,13 +54,13 @@ impl FromStr for ToolchainSpec { }; let kind = match name { "python" | "py" => ToolchainKind::Python, - "node" => ToolchainKind::Node, + "node" | "javascript" | "typescript" => ToolchainKind::Node, "rust" => ToolchainKind::Rust, "go" => ToolchainKind::Go, "dotnet" | "csharp" | "cs" => ToolchainKind::Dotnet, _ => { return Err(format!( - "unsupported toolchain {name:?}; expected python, node, rust, go, or dotnet" + "unsupported toolchain {name:?}; expected python, node, javascript, typescript, rust, go, or dotnet" )); } }; @@ -215,4 +215,12 @@ mod tests { "dotnet@10" ); } + + #[test] + fn language_names_alias_to_node() { + for alias in ["javascript", "typescript"] { + let spec = format!("{alias}@20").parse::().unwrap(); + assert_eq!(spec.display(), "node@20"); + } + } }