| name | chadscript |
|---|---|
| description | Use when writing ChadScript applications, compiling TypeScript to native binaries, or working with the chad CLI. Triggers on ChadScript projects (chadscript.d.ts present), chad CLI usage, or native compilation tasks. |
ChadScript compiles TypeScript to native binaries via LLVM IR. It produces fast, single-file executables with no runtime dependency on Node.js.
chad build app.ts # compile to .build/app
chad build app.ts -o myapp # compile with custom output
chad run app.ts # compile and run
chad run app.ts -- arg1 # pass args to the binary
chad watch app.ts # recompile+run on file changes
chad init # scaffold a new project
chad ir app.ts # emit LLVM IR onlyRun chad init to generate chadscript.d.ts (type definitions), tsconfig.json, and hello.ts.
The chadscript.d.ts file provides type definitions for ChadScript-specific APIs. Keep it in your project root.
ChadScript supports a practical subset of TypeScript:
- Classes with inheritance, interfaces, generics (type-erased)
- Arrays (
number[],string[],object[]), Maps, Sets - String/array methods:
map,filter,find,reduce,push,pop,split,trim,replace,indexOf,includes,slice,substring,startsWith,endsWith,padStart,padEnd, etc. - Template literals, destructuring, spread operator
for...of,forloops,while,if/else, ternary, switchasync/awaitwithfetch(),setTimeout,setInterval- Closures (capture by value — mutations after capture won't be seen)
- Enums (numeric and string)
- Type assertions (
as), optional chaining (?.), nullish coalescing (??)
import * as fs from "fs"; // readFileSync, writeFileSync, existsSync, etc.
import * as path from "path"; // join, resolve, dirname, basename, extname
import * as os from "os"; // platform, arch, cpus, totalmem, homedir
import * as child_process from "child_process"; // execSyncAlso available globally: console, process, JSON, Math, Date, setTimeout, setInterval.
Embed files at compile time — they're baked into the binary:
ChadScript.embedFile("./config.json");
ChadScript.embedDir("./public");
const config = ChadScript.getEmbeddedFile("config.json");
const binary = ChadScript.getEmbeddedFileAsUint8Array("image.png");function handler(req: HttpRequest): HttpResponse {
return { status: 200, body: "hello", headers: "" };
}
httpServe(3000, handler);Combine with ChadScript.embedDir("./public") and ChadScript.serveEmbedded(req.path) for static file serving from a single binary.
- No
node_modulesimports — only built-in modules and local files - No
anytype — all values must have a concrete type - Closures capture by value — mutating a variable after it's captured in a closure won't update the closure's copy
process.exit()is required at the end of synchronous programs (no implicit exit)- Generics use type erasure —
Tbecomesi8*(opaque pointer), numeric type params not supported - Union types limited to members with the same LLVM representation
chad target add linux-x64
chad build app.ts --target linux-x64