一个帮助您为项目下载完整、轻量级运行时环境的库。它支持多种现代运行时,包括 Node.js、Bun 和 uv,非常适合在构建 Electron 等应用程序时包含轻量级运行时。
- 🚀 支持多种运行时:Node.js、Bun、uv
- 📦 自动下载和配置最新版本
- 🎯 跨平台支持 (Windows, macOS, Linux)
- 🔧 可配置的清理选项(Node.js)
- 💻 命令行界面和编程 API
- 📝 TypeScript 支持
运行时 | 描述 | 默认版本 |
---|---|---|
Node.js | JavaScript 运行时环境 | v22.9.0 |
Bun | 快速的 JavaScript 运行时和工具包 | v1.2.16 |
uv | Python 包管理器和解释器管理工具 | 0.7.13 |
npm install tiny-runtime-injector
# 安装 Node.js
tiny-runtime-injector --type node --version v22.9.0 --dir ./runtime/node
# 安装 Bun
tiny-runtime-injector --type bun --version v1.2.16 --dir ./runtime/bun
# 安装 uv
tiny-runtime-injector --type uv --version 0.7.13 --dir ./runtime/uv
# 查看所有选项
tiny-runtime-injector --help
import { RuntimeInjector } from "tiny-runtime-injector";
// 安装 Node.js
const nodeInjector = new RuntimeInjector({
type: "node",
version: "v22.9.0",
targetDir: "./runtime/node",
cleanup: true,
});
await nodeInjector.inject();
// 安装 Bun
const bunInjector = new RuntimeInjector({
type: "bun",
version: "v1.2.16",
targetDir: "./runtime/bun",
});
await bunInjector.inject();
// 安装 uv
const uvInjector = new RuntimeInjector({
type: "uv",
version: "0.7.13",
targetDir: "./runtime/uv",
});
await uvInjector.inject();
interface RuntimeOptions {
type?: "node" | "bun" | "uv"; // 运行时类型
version?: string; // 版本号
platform?: string; // 目标平台
arch?: string; // 目标架构
targetDir: string; // 安装目录
cleanup?: boolean | CleanupConfig; // 清理配置(仅 Node.js)
}
interface CleanupConfig {
removeDocs?: boolean; // 移除文档文件
removeDevFiles?: boolean; // 移除开发文件
removeSourceMaps?: boolean; // 移除源码映射
customRules?: CleanupRule[]; // 自定义规则
}
import { RuntimeInjector } from "tiny-runtime-injector";
import path from "path";
async function setupRuntimes() {
const runtimeDir = path.join(__dirname, "resources", "runtimes");
// 设置 Node.js 用于后端处理
const nodeInjector = new RuntimeInjector({
type: "node",
version: "v22.9.0",
targetDir: path.join(runtimeDir, "node"),
cleanup: {
removeDocs: true,
removeDevFiles: true,
removeSourceMaps: true,
},
});
// 设置 Bun 用于快速脚本执行
const bunInjector = new RuntimeInjector({
type: "bun",
version: "v1.2.16",
targetDir: path.join(runtimeDir, "bun"),
});
// 设置 uv 用于 Python 包管理
const uvInjector = new RuntimeInjector({
type: "uv",
version: "0.7.13",
targetDir: path.join(runtimeDir, "uv"),
});
await Promise.all([
nodeInjector.inject(),
bunInjector.inject(),
uvInjector.inject(),
]);
console.log("所有运行时设置完成!");
}
setupRuntimes().catch(console.error);
创建 runtime-config.json
:
{
"type": "node",
"version": "v22.9.0",
"targetDir": "./runtime/node",
"cleanup": {
"removeDocs": true,
"removeDevFiles": true,
"removeSourceMaps": true,
"customRules": [
{
"pattern": "**/*.test.js",
"description": "Remove test files"
}
]
}
}
使用配置文件:
tiny-runtime-injector --config runtime-config.json
- ✅ Windows (x64, x86, ARM64)
- ✅ macOS (x64, ARM64)
- ✅ Linux (x64, ARM64, ARMv7, PPC64LE, s390x)
- ✅ Windows (x64, ARM64)
- ✅ macOS (x64, ARM64)
- ✅ Linux (x64, ARM64)
- ✅ Windows (x64, x86, ARM64)
- ✅ macOS (x64, ARM64)
- ✅ Linux (x64, x86, ARM64, ARMv7, PPC64, PPC64LE, s390x, RISCV64)
- ✅ Linux MUSL (x64, x86, ARM64, ARM, ARMv7)
- 包含完整的 Node.js 运行时和 npm
- 支持清理选项以减少文件大小
- 可执行文件:
node.exe
(Windows) 或bin/node
(Unix)
- 单个可执行文件,包含运行时和包管理器
- 无需额外清理,已经很轻量
- 可执行文件:
bun.exe
(Windows) 或bun
(Unix)
- 包含
uv
和uvx
两个可执行文件 uv
:Python 包管理器uvx
:工具执行器- 可执行文件:
uv.exe
/uvx.exe
(Windows) 或uv
/uvx
(Unix)
constructor(options: RuntimeOptions)
async inject(): Promise<void>
下载并设置指定的运行时环境。
-
下载失败
- 检查网络连接
- 验证版本号是否正确
- 确保目标目录有写入权限
-
可执行文件无法运行
- 在 Unix 系统上,检查文件权限(应该是 755)
- 验证架构兼容性
-
版本不匹配
- 使用正确的版本格式:
- Node.js:
v22.9.0
- Bun:
v1.2.16
- uv:
0.7.13
- Node.js:
- 使用正确的版本格式:
欢迎贡献!请查看我们的贡献指南。
MIT
- ✨ 添加对 Bun 和 uv 的支持
- 🔧 重构为支持多运行时架构
- 📝 更新文档和示例
- 🐛 修复跨平台兼容性问题