scriptc 将普通 TypeScript 编译成小巧、快速的原生可执行文件,无需 Node.js、V8 或任何 JavaScript 运行时嵌入到二进制文件中。

Stars

1,985

7 天增长

暂无数据

Fork 数

35

开放 Issue

9

开源协议

Apache-2.0

最近更新

2026-07-28

AI 仓库情报摘要
FR-AI / ANALYSIS

为什么值得关注

它实现了接近瞬时的启动(约 2ms)、极小的二进制体积(静态 170-200KB),并通过差分测试和内存安全检查确保与 Node 逐字节一致,同时保留标准 TypeScript 语法和 tsc 类型检查。

适合谁使用

  • 希望分发自包含 CLI 工具或服务器且占用极小的 TypeScript 开发者
  • 寻求高级语言以生成小而快二进制文件且不牺牲 JavaScript 语义的系统程序员
  • 受困于 Node.js 启动延迟和体积较大的生产部署的 Node 用户
  • 对动态语言新型编译技术感兴趣的工具链爱好者

典型使用场景

  • 将 TypeScript CLI 工具打包成单个原生二进制文件分发给用户(例如 fib 计算或代理服务器)
  • 在无服务器或边缘环境中以接近零启动成本运行 TypeScript 脚本
  • 用更小、更快的原生二进制替代 Node.js 容器用于微服务
  • 通过原生 FFI 将 TypeScript 逻辑集成到嵌入式系统中

项目优势

  • 完整静态编译 TypeScript 语言、标准库和 Node.js API 表面,保持 JS 精确语义
  • 对 800+ 语料库程序进行差分测试确保与 Node 输出字节一致,并通过 AddressSanitizer 保证内存安全
  • 性能优势:启动约 2ms(Node 约 47ms),二进制体积 170KB(Node SEA 为 60-100MB),常驻内存 1-4MB(Node 为 67-116MB)
  • 灵活的逃生舱(comptime、--dynamic、--ffi)且永远不会静默编译错误

使用前须知

  • 需要 clang,主要测试平台为 macOS arm64;Linux/Windows 交叉编译为次要支持
  • 动态代码(npm 依赖、any 类型)会嵌入 QuickJS 引擎(约 620KB),增加二进制体积和运行时开销
  • 存在少量与 Node 的故意差异(约几十处,涉及时序和错误对象属性),且整数推断和所有权分析仍在路线图上

README 快速开始

scriptc

Zero-runtime TypeScript. scriptc compiles ordinary TypeScript into small, fast native executables — no Node, no V8, no JavaScript engine in the binary.

$ cat fib.ts
function fib(n: number): number {
  return n  ...)`** runs TypeScript at build time (in an isolated VM inside the compiler) and bakes the result into the binary as a literal.
- **Native FFI (`--ffi`)** binds signature-only TypeScript declarations to direct C ABI calls and links manifest-declared archives, objects, and system libraries. The boundary is explicit and length-delimited; see the [Native FFI guide](https://scriptc.dev/ffi).
- **`--dynamic`** embeds the engine for npm deps and `any` code. `scriptc coverage --dynamic` reports exactly which statements run where and what the remaining blockers are. Static stays the default: a binary never silently grows an engine.
- **Checked casts** — `JSON.parse(...) as Config` inserts a runtime validation that throws a catchable error naming the offending path (`expected number at $.port, got string`). TypeScript's `as` is a promise; scriptc verifies it.

## Architecture

```mermaid
flowchart LR
    TS[TypeScript] -->|tsc: parse + typecheck| L[lowering]
    L --> IR[typed IR]
    IR --> C[C]
    C -->|clang| BIN[native executable]
  • packages/compiler — frontend (tsc API → IR), the IR with validator/serializer, the LLVM and C backends. The IR is the only interface between the ends; LLVM is the default code generator (with a transparent fallback for programs outside its tier), and C is the reference backend forever (readable, source-line-annotated output via --backend c).
  • packages/runtime — the C runtime: refcounted values with a cycle collector, stackful fibers and the event loop (kqueue), the server stack, JS-exact number formatting. Feature units are link-gated: binaries pay only for what they use.
  • packages/cliscriptc build | run | coverage.

Development

$ pnpm install && pnpm build
$ pnpm test                      # differential corpus + diagnostics snapshots
$ SCRIPTC_SAN=1 pnpm test        # the same corpus under ASan + RC audit
$ pnpm scriptc build x.ts --emit-ir   # keep .scriptc/x.c and x.ir.json

Every feature lands with differential tests; both lanes green is the merge bar.

项目描述

TypeScript-to-Native Compiler

相关仓库与替代方案

根据分类、Topic 和编程语言匹配的相似项目。

AgriciDaniel
精选
AgriciDaniel GitHub avatar

anti-slop

Anti-slop is a tool for detecting and repairing substance defects in AI-assisted prose, code, documentation, and agent output using deterministic scanners and structural procedures that produce verifiable artifacts rather than authorship judgments.

AI 与机器学习大语言模型
9
mereyabdenbekuly-ctrl
精选
mereyabdenbekuly-ctrl GitHub avatar

clodex-ide

Clodex is an open-source, local-first agentic IDE that combines persistent AI tasks, code, terminal, browser, Git, models, memory, and governed execution in one Electron workspace, currently in technical preview.

AI 与机器学习AI 智能体
859
0xwilliamortiz
精选
0xwilliamortiz GitHub avatar

openclaude-improved

OpenClaude is an open-source CLI coding agent that runs on any platform and supports a wide range of LLM providers, offering the same tools and workflows as Claude Code.

AI 与机器学习大语言模型
577