Grepedia
SC

scriptc

scriptc compiles TypeScript into small, fast native binaries without requiring Node.js, V8, or any embedded JavaScript runtime engine during execution.

Score1
About

scriptc is a specialized compiler designed to transform ordinary TypeScript code into small, fast, and self-contained native executables. By eliminating the need for Node.js, V8, or any external JavaScript runtime, it allows developers to distribute binaries that start in milliseconds and link only against system libraries. Created to provide static execution performance with the developer experience of TypeScript, scriptc uses a tiered approach to ensure predictable, safe, and performant output. It supports modern TypeScript features, including classes, closures, async/await, and a wide surface of the Node.js API, ensuring that programs behave consistently compared to their Node-based counterparts.

The tool functions by analyzing the TypeScript source code through the real TypeScript compiler. It then performs a lowering process to generate a typed intermediate representation. This IR is subsequently passed through one of two backends: an LLVM-based backend for high-performance machine code generation or a C-based reference backend for maximum transparency. Because the tool is built with a focus on correctness and safety, every construct in a program is assigned to a specific tier: statically compiled native code, dynamic code running in an embedded JavaScript island, or code that is rejected at compile time if it cannot be safely or reliably converted.

Some of the key features are:

  • Native Compilation: Transforms TypeScript directly into platform-specific machine code binaries without bundling a massive runtime engine.
  • Tiered Execution: Manages program components through static compilation, an optional dynamic island, or compile-time rejection to prevent silent failures.
  • Embedded Dynamic Engine: Utilizes quickjs-ng as an optional, opt-in component to execute legacy JavaScript dependencies or dynamic any-typed code.
  • Differential Testing: Validates every change against a corpus of programs to ensure identical standard output, exit codes, and behavior compared to Node.js.
  • Memory Safety: Employs an AddressSanitizer lane and reference-count auditing to prevent memory leaks and use-after-free vulnerabilities.
  • Native FFI: Allows calling C ABI symbols directly from TypeScript code using a strict JSON manifest for cross-language interoperability.
  • Static Coverage Reports: Provides detailed analysis of code compilation, showing exactly which parts are static, which are dynamic, and what blocks remaining static conversion.
  • Platform Support: Offers cross-compilation capabilities for Linux and Windows while maintaining macOS arm64 as a primary development target.

Operationally, scriptc is used primarily through its command-line interface. Developers provide a TypeScript entry file, and the compiler manages the entire toolchain—from type checking and IR generation to final binary linking. By default, it produces efficient binaries, but users can explicitly request optimization or diagnostic information, such as IR output or the kept C translation units. The build process is governed by the user's tsconfig.json, ensuring that the compiler adheres to existing strictness and project-level configurations.

Some common use cases include:

  • High-Performance CLIs: Developing command-line tools that require near-instant startup times and minimal memory footprints compared to traditional Node-based scripts.
  • Server-Side Services: Deploying network-intensive services (HTTP/HTTPS/TLS) as single, portable binaries that require no runtime environment installations on the host server.
  • System Utilities: Creating lightweight, dependency-free utilities that interact with system files and processes using standard Node.js APIs.
  • Edge Computing: Preparing self-contained binaries for restricted environments where standard heavy runtimes are not available or are prohibitively expensive in terms of resource consumption.