The High-Performance Native TypeScript Compiler for the JVM.
Compile TypeScript directly to native JVM bytecode and executable JARs β without Node.js, V8, Kotlin, or Gradle.
tsbytes is a cutting-edge compiler written in Rust that takes standard TypeScript source files and compiles them directly into Java .class files and standalone, executable .jar archives.
Traditional TypeScript execution requires a heavy runtime environment like Node.js, Bun, or Deno. tsbytes bypasses interpreter runtimes entirely, translating your TypeScript syntax directly into native, optimized JVM bytecode. You keep the standard TypeScript developer experience β node_modules, type checking, and modern ES features β while gaining the legendary performance, reliability, and security of the JVM ecosystem.
| Metric | Node.js (V8) | JVM + Kotlin / Java | tsbytes (Compiled TS) |
|---|---|---|---|
| Startup / Cold Start | Slow (50ms+) | Slow (150ms+) | Ultra-Fast (3ms - 5ms) |
| Memory Footprint | Large (30MB+) | Large (80MB+) | Extremely Low (8MB) |
| Deployment Package | node_modules (100MB+) |
Heavy Fat JAR (50MB+) | Standalone JAR (< 100KB) |
| Runtime Interpreter | Required (Node/V8) | Required (JRE) | Native JVM Bytecode |
tsbytes is exceptionally well-suited for high-throughput, modern infrastructure where speed, portability, and security are paramount:
- β‘ High-Performance Serverless & Microservices: Achieve near-instant millisecond cold starts on AWS Lambda, Google Cloud Functions, or Kubernetes.
- π οΈ Zero-Dependency CLI Tools: Compile your TypeScript command-line utilities into a single, highly portable
.jarfile that runs anywhere Java is installed. - π Secure Enterprise Environments: Run secure TypeScript programs natively inside highly locked-down corporate JVM networks without installing JavaScript runtime engines.
- π Distributed Data Processing: Write type-safe map/reduce, stream filters, or ETL pipelines in TypeScript and run them natively on high-performance JVM data engines (like Apache Spark, Flink, or Hadoop).
- π¦ Embedded Scripting: Embed compiled TypeScript routines inside Java desktop, backend, or Android systems as precompiled library classes.
Get up and running in seconds with cargo:
# Install the tsbytes compiler globally
cargo install tsbytes
# Create a new tsbytes project template
tsb init my-app
cd my-app
# Compile TypeScript directly to an executable JAR and execute it!
tsb jar src/main.ts --output app.jar
java -jar app.jarTypeScript Source β tsbytes Compiler β JVM Bytecode β Executable JAR
(your code) (Rust) (.class) (java -jar)
- Write standard TypeScript: Fully compatible with standard ES2020 types and syntax.
- AST Parsing: tsbytes parses your source code and builds an optimized Middle Intermediate Representation (MIR) and High Intermediate Representation (HIR) using SWC.
- Native Bytecode Generation: Generates standard Java 8+
.classfiles directly, executing native closures, arrow functions, and class declarations without any middle-step Kotlin or Java transpilation. - Embedded Zero-Dependency Runtime: Packages everything β including a specialized JVM-backed, precompiled runtime helper package embedded directly in the compiler's binary β into a standard, lightweight, standalone executable JAR.
Scaffold a standard TypeScript workspace preconfigured for JVM target compilations.
tsb init my-app- Generates a clean workspace:
package.json,tsconfig.json,src/main.ts, and gitignore files. - Installs dependencies and sets up scripts.
Emit only JVM .class files to a target build directory.
tsb compile src/main.ts --output ./build --package com.example.appOptions:
-o, --output <dir>β Output directory (default:./build)-p, --package <pkg>β Target JVM package path (default:com.tsbytes.app)
Compile TypeScript to a standalone, executable JAR archive.
tsb jar src/main.ts --output ./app.jar --package com.example.appOptions:
-o, --output <path>β Output.jarpath (default:./output.jar)-p, --package <pkg>β Target JVM package path (default:com.tsbytes.app)
tsbytes features a robust, zero-dependency, JVM-native implementation of standard ES built-ins, offering fully compliant reference equality and performance benefits:
| Built-in | Description | Status |
|---|---|---|
Map |
Insertion-ordered, custom key/value hash map mapping JS semantics. | β |
Set |
Insertion-ordered unique item collection. | β |
WeakMap |
Weak-referencing dynamic key-value map backing JVM WeakHashMap. |
β |
WeakSet |
Weak-referencing membership collection. | β |
Date |
Epoch-backed UTC millisecond timestamps, parse wrappers, and getters/setters. | β |
RegExp |
Dynamic RegExp engine matching captures, matches, indices, and .exec() / .test(). |
β |
JSON |
Native high-performance stringifier and parser. | β |
fetch |
Native HTTP Client wrapping JDK's high-performance HttpClient with full Response support! |
β |
Unlike JVM structural collections, standard TsObject instances feature Reference Equality identity semantics (equals and hashCode delegate to standard reference addresses), perfectly adhering to ECMAScript standard behaviors when tracking object instances in collections.
src/
βββ swc_frontend/ # SWC AST parsing β TS source β AST
βββ codegen/
β βββ compiler/
β β βββ bytecode_emitter/ # JVM bytecode generation
β β βββ ir_builder/ # AST to HIR/MIR converter
β β βββ type_checker/ # Static type validation
β β βββ module_graph.rs # Relative imports/exports path resolver
β β βββ runtime_gen.rs # Embedded Java runtime class bundler
β β βββ runtime_bytes.rs # Embedded runtime .class bytes
β βββ jar.rs # Executable JAR packager
β βββ mod.rs # CodeGenerator driver
βββ cli/
β βββ init.rs # Project scaffolding template
βββ error.rs # Pretty-printed diagnostics
βββ lib.rs # Public programmatic compiler library API
βββ main.rs # CLI entrypoint
We welcome contributions of all kinds! Please read our contributing guide to get started.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Distributed under the MIT License. See LICENSE for more information.