Vercel推出了Scriptc,一款将TypeScript代码编译为原生可执行文件的编译器[1]。该工具能够生成小型、快速的二进制文件,无需依赖Node、V8或任何JavaScript引擎[1]。编译后的原生二进制文件大小约为178KB,启动时间仅需约2ms[1]。
Scriptc采用三层编译策略以处理不同场景[1]。其中99%的TypeScript代码可编译为静态原生代码,直接作为原生二进制执行[1];对于无法完全静态编译的代码,Scriptc提供动态运行模式,通过嵌入quickjs-ng引擎(约620KB)来执行[1];某些代码则被标记为拒绝编译[1]。该编译器支持macOS arm64作为主要平台,Linux和Windows通过交叉编译得到验证[1]。
为确保编译输出的正确性,Vercel运用了差异化测试和内存安全检查手段[1]。包括800多个测试程序在Node.js和原生二进制环境下必须产生完全一致的字节级输出,以及通过AddressSanitizer进行内存安全检查[1]。Scriptc支持Node.js API表面的多个模块,包括fs、path、process、child_process、net、http、https、tls、dgram和dns等[1]。此外,编译器还提供了编译时执行、原生FFI绑定和运行时checked casts等高级特性[1]。
Vercel has introduced Scriptc, a TypeScript-to-native code compiler that transforms TypeScript into small, fast native executables without requiring Node, V8, or any JavaScript engine in the binary [1]. The compiler supports 99% static compilation and delivers native binaries of approximately 178 kilobytes with startup times around 2 milliseconds [1].
Scriptc employs a three-tier compilation strategy to handle different code scenarios [1]. Code that can be statically compiled produces pure native executables with no embedded runtime; code requiring dynamic execution includes the quickjs-ng engine at roughly 620 kilobytes; and incompatible code is rejected during compilation [1]. The compiler supports a substantial portion of the Node.js API surface, including fs, path, process, child_process, net, http, https, tls, dgram, and dns modules [1].
To ensure reliability, Scriptc validates its output through differential testing across over 800 test programs, requiring byte-identical results between Node and native binary execution, alongside AddressSanitizer memory safety checks [1]. The compiler currently targets macOS arm64 as its primary platform, with Linux and Windows support verified through cross-compilation [1]. Advanced features include compile-time execution via comptime(), native FFI bindings, and runtime-verified checked casts [1].