An open API service indexing awesome lists of open source software.

https://github.com/cs01/chadscript

Compile TypeScript to Native Binaries
https://github.com/cs01/chadscript

Last synced: 3 months ago
JSON representation

Compile TypeScript to Native Binaries

Awesome Lists containing this project

README

          

# ChadScript

TypeScript, compiled to native code.

ChadScript compiles a statically analyzable subset of TypeScript to native machine code via LLVM — the same backend behind C, Rust, and Swift. No VM, no interpreter, no runtime. The output is a standalone binary: sub-millisecond startup, ~250KB, zero dependencies.

The compiler is self-hosting and the only dependency is itself. Install with curl, not npm.

**Status: Beta** — self-hosting, 621+ tests, used in [production](https://chadsmith.dev/weather).

**[Docs](https://cs01.github.io/ChadScript/getting-started/installation)** · **[Standard Library](https://cs01.github.io/ChadScript/stdlib/)** · **[Language Features](https://cs01.github.io/ChadScript/language/features)** · **[Benchmarks](https://cs01.github.io/ChadScript/benchmarks)**

---

## Install

```bash
curl -fsSL https://raw.githubusercontent.com/cs01/ChadScript/main/install.sh | sh
```

No dependencies — everything is bundled in the compiler.

---

## Example: API server

```typescript
import { httpServe, Router, Context } from "chadscript/http";

const app: Router = new Router();

app.get("/", (c: Context) => {
return c.html(`

ChadScript API


A native binary serving this page. Try the endpoints:



curl -X POST -d 'hello' localhost:3000/echo


`);
});

app.get("/json", (c: Context) => {
return c.json({ name: "ChadScript", compiled: true });
});

app.get("/users/:id", (c: Context) => {
return c.json({ id: c.req.param("id") });
});

app.get("/users/:name/posts/:pid", (c: Context) => {
return c.json({ user: c.req.param("name"), post: c.req.param("pid") });
});

app.post("/echo", (c: Context) => {
return c.text(c.req.body);
});

httpServe(3000, (req: HttpRequest) => app.handle(req));
```

```bash
chad build app.ts && ./app # compiles in ~0.3s, starts in <2ms
```

Hono-style API, C-level performance. One binary, no node_modules. See [`examples/`](examples/) for more: [weather app](examples/apps/weather/) (in production at [chadsmith.dev/weather](https://chadsmith.dev/weather)), [Hacker News clone](examples/apps/hackernews/), [WebSocket chat](examples/apps/websocket/), SQLite, and more.

---

## Benchmarks

ChadScript compiles through LLVM, the same backend behind C and Rust — so it gets the same optimization passes. Compared against C, Go, Node.js, and Bun on Ubuntu (CI):

| Benchmark | ChadScript | Node.js | vs Node | C |
| -------------- | ---------- | ------- | -------- | ------ |
| Cold Start | **0.6ms** | 21.8ms | **36x** | 0.6ms |
| Monte Carlo Pi | **0.398s** | 1.474s | **3.7x** | 0.400s |
| File I/O | **0.089s** | 0.315s | **3.5x** | 0.088s |
| JSON Parse | **0.005s** | 0.015s | **3.0x** | 0.004s |
| Fibonacci | **1.424s** | 2.842s | **2.0x** | 0.725s |
| Sieve | **0.038s** | 0.054s | **1.4x** | 0.027s |
| N-Body Sim | **1.852s** | 2.296s | **1.2x** | 1.453s |
| Quicksort | **0.202s** | 0.249s | **1.2x** | 0.170s |
| SQLite | **0.374s** | 0.437s | **1.2x** | 0.314s |

[Full benchmarks with Go and Bun](https://cs01.github.io/ChadScript/benchmarks) (updated on every PR)

---

## It's Fast

Your code goes through the same LLVM optimization passes as C and Rust — not a JIT, not an interpreter. 0.8ms cold start, native execution speed.

## It's Familiar

Classes, interfaces, generics, async/await, closures, destructuring, template literals, JSX, `for...of`, `Map`, `Set`, `Promise.all` — it's the TypeScript you already write. No new syntax, no new mental model.

## It's Friendly

No `npm install`. Everything ships with the compiler: HTTP server, SQLite, fetch, crypto, WebSocket, JSON, filesystem, regex, child processes, argument parsing. Write your code, compile it, ship a single binary.

---

## Examples

```bash
git clone https://github.com/cs01/ChadScript && cd ChadScript

chad run examples/snippets/hello.ts
chad run examples/snippets/parallel.ts # async/await + Promise.all
chad run examples/snippets/sqlite-demo.ts # SQLite
chad run examples/apps/http-server/app.ts # http://localhost:3000
chad run examples/apps/weather/app.ts # weather app — live at https://chadsmith.dev/weather
chad run examples/apps/hackernews/app.ts # Hacker News clone
```

See [`examples/cli-tools/`](examples/cli-tools/) for a suite of Unix tool replacements: `cgrep`, `cwc`, `ccat`, `ctree`, `chex`, `cjq`, `cql`, `chttp`, and `cserve`.

---

## Docs

- [Installation](https://cs01.github.io/ChadScript/getting-started/installation)
- [Quickstart](https://cs01.github.io/ChadScript/getting-started/quickstart)
- [Supported Features](https://cs01.github.io/ChadScript/language/features)
- [Standard Library](https://cs01.github.io/ChadScript/stdlib/)