scriptc compiles ordinary TypeScript into small, fast native executables without needing Node.js, V8, or any JavaScript runtime in the binary.

Stars

1,985

7-day growth

No data

Forks

35

Open issues

9

License

Apache-2.0

Last updated

2026-07-28

AI repository intelligence
FR-AI / ANALYSIS

Why it is worth attention

It achieves near-instant startup (~2ms), tiny binary sizes (170-200KB static), and byte-for-byte correctness against Node through differential testing and memory-safety checks, while preserving standard TypeScript syntax and type-checking via tsc.

Who it is for

  • TypeScript developers wanting to distribute self-contained CLI tools or servers with minimal footprint
  • Systems programmers seeking a higher-level language for small, fast binaries without sacrificing JavaScript semantics
  • Node.js users frustrated by startup latency and large bundle sizes for production deployments
  • Toolchain enthusiasts interested in novel compilation techniques for dynamic languages

Use cases

  • Packaging a TypeScript CLI tool as a single native binary for distribution (e.g., a 'fib' or proxy server)
  • Running TypeScript scripts with near-zero startup cost for serverless or edge environments
  • Replacing Node.js containers with smaller, faster native binaries for microservices
  • Integrating TypeScript logic into embedded systems via native FFI

Strengths

  • Full static compilation of the TypeScript language standard library and Node.js API surface with JS-exact semantics
  • Differential testing against Node ensures byte-identical output for 800+ corpus programs, plus memory-safety via AddressSanitizer
  • Performance edge: startup ~2ms vs Node's ~47ms, binary size 170KB vs Node SEA 60-100MB, RSS 1-4MB vs 67-116MB
  • Flexible escape hatches (comptime, --dynamic, --ffi) that never silently miscompile

Considerations

  • Requires clang and is primarily tested on macOS arm64; Linux/Windows cross-compilation is secondary
  • Dynamic code (npm deps, 'any' types) triggers use of an embedded QuickJS engine (~620KB), increasing binary size and runtime overhead
  • Some deliberate documented divergences from Node (a few dozen around timing and error properties) and integer inference/ownership analysis are still on the roadmap

README quick start

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.

Description

TypeScript-to-Native Compiler

Related repositories

Similar projects matched by category, topics, and programming language.

YutongChenVictor
Featured
YutongChenVictor GitHub avatar

NPU-E2E

An educational full-stack NPU accelerator demo featuring a 16×16 systolic array RTL design, AXI4 SoC integration, C/Python runtime, UART driver, and TVM BYOC compiler backend, verified on FPGA with LeNet-5 inference.

AI & Machine LearningDeveloper Tools
17
mereyabdenbekuly-ctrl
Featured
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 & Machine LearningAI Agents
859
0xwilliamortiz
Featured
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 & Machine LearningLarge Language Models
577