v0.4.24 — tvOS 目标平台、从 Linux 交叉编译 iOS/macOS、perry login

一套代码。所有平台。
原生性能。

Perry 将 TypeScript 编译为 macOS、iPadOS、iOS、Android、Linux、Windows、watchOS、tvOS、WebAssembly 和 Web 上的原生 GUI 和 CLI 应用。无需运行时。无需 Electron。只有原生二进制文件。

terminal

$ perry compile main.ts

正在编译 main.ts...

✓ 已编译可执行文件:main(2.3 MB)

$ ./main

Hello, World!

10
目标平台
25+
原生 UI 组件
0 ms
启动时间
App Store
就绪

为什么选择 Perry

将 TypeScript 编译为原生应用所需的一切

无需运行时

生成独立的原生可执行文件。无需 Node.js、无需 V8、无运行时依赖。只需一个二进制文件即可在任何地方运行。

快速编译

使用 SWC 解析和 Cranelift 代码生成,将 TypeScript 直接编译为原生代码。无中间 JavaScript。

体积小巧

输出的二进制文件通常只有 2-5 MB。搭配可选的 V8 运行时(用于 JS npm 包)为 15-20 MB。分发更少,部署更快。

类型安全

利用 TypeScript 的类型系统进行优化。类型通过 Monomorphization 实现更好的代码生成。

全面的标准库

内置 fs、path、crypto、os、Buffer、child_process 等原生实现。使用您熟悉的 Node.js API。

可选 V8 运行时

需要使用纯 JavaScript npm 包?启用 V8 运行时标志即可获得完整的 npm 生态系统兼容性。

25+ 原生 UI 组件

按钮、文本框、文本区域、表格、Canvas、滚动视图、二维码、安全输入框、启动画面等——全部编译为通过 AppKit、GTK4、Win32、UIKit 和 JNI 实现的真正平台组件。

编译时插件系统

模块在构建时组合——无运行时插件开销,无 IPC 边界。您的依赖项成为最终二进制文件中的直接原生函数调用。

真正的多线程

通过 parallelMap、parallelFilter 和 spawn 使用真正的操作系统线程。编译时安全性拒绝可变捕获——无需 SharedArrayBuffer,无需 Worker,只有线程。

编译时 i18n

自动字符串提取、30+ 语言环境的 CLDR 复数规则、编译时验证。翻译被嵌入二进制文件中,运行时查找几乎为零。

每个平台上原生运行

Perry 将您的 TypeScript 编译为原生 UI 框架、WebAssembly 和 JavaScript——不是 Web 视图,不是 Electron。每个平台上都是真正的原生组件,外加 Web。

macOS

AppKit

稳定

iOS

UIKit

稳定

iPadOS

UIKit

稳定

Android

Views

稳定

Linux

GTK4

稳定

Windows

Win32

稳定

watchOS

SwiftUI

稳定

tvOS

SwiftUI

稳定

WASM

WebAssembly

稳定

Web

JavaScript

稳定
框架对比

唯一满足所有条件的框架

TypeScript 编译为原生代码。真正的平台组件。零运行时开销。

框架语言原生代码原生组件运行时开销
PerryAOT compiled to native binary
TypeScript
None
React NativeJIT / interpreted at runtime
JS / TypeScript
Hermes / V8 + Bridge
FlutterAOT compiled, custom renderer
Dart
Dart VM + Skia engine
KMP + ComposeJVM on Android, native on iOS
Kotlin
部分
Kotlin runtime + Skia
Swift for AndroidNative binary, no shared UI
Swift
无共享 UI
Swift runtime on Android
.NET MAUIPartial AOT via Mono
C#
部分
.NET / Mono runtime
NativeScriptJS runtime, native widget access
JS / TypeScript
V8 / JavaScriptCore
IonicWeb app in native wrapper
JS / TypeScript
WebView + Capacitor
原生编译
真正的平台组件
零运行时开销

编写 TypeScript,交付原生应用

使用熟悉的 TypeScript 语法和 API。Perry 处理剩下的一切。

hello.ts
// hello.ts
const greeting = "Hello, World!";
console.log(greeting);
 
// Compiles to ~2MB native executable
// No runtime needed!
$ perry build hello.ts
原生二进制文件

性能对比

原生编译带来无与伦比的效率

指标PerryNode.jsBun
二进制文件大小2-5 MB~80 MB~90 MB
启动时间~1 ms~30 ms~10 ms
运行时依赖Node.jsBun
内存开销极少V8 + GCJSC + GC

基准测试结果:快 2.2 倍

Perry 对比 Node.js v24(macOS ARM64,越低越好)

closure
4.5x
object create
3.5x
array read
3.0x
math intensive
3.0x
method calls
3.0x
binary trees
2.7x
string concat
2.5x
fibonacci
2.1x
mandelbrot
1.9x
factorial
1.7x
二进制文件大小越低越好
Perry
5 MB
Node.js
80 MB
Bun
90 MB

开始使用

安装 Perry,开始将 TypeScript 编译为原生可执行文件

1安装

terminal
$ brew tap PerryTS/perry
$ brew install perry

需要 Homebrew。支持 macOS arm64 和 x86_64。

2使用

编译文件
perry build main.ts

将 main.ts 编译为原生可执行文件

自定义输出
perry build main.ts -o myapp

指定输出可执行文件名称

附带 V8 运行时
perry build main.ts --enable-js-runtime

启用 V8 以兼容 JavaScript npm 包

检查兼容性
perry check ./src

验证 TypeScript 代码是否可进行原生编译

功能支持

全面覆盖 TypeScript 和 Node.js API

Core Language

  • Numbers64-bit floating point (f64)
  • StringsUTF-8, all common methods
  • Booleanstrue/false, logical operators
  • ArraysTyped and mixed-type arrays
  • ObjectsObject literals and field access
  • BigInt256-bit integer support
  • EnumsNumeric and string enums

Functions

  • Function DeclarationNamed functions
  • Arrow Functions() => {} syntax
  • Default ParametersParameters with defaults
  • Rest Parameters...args syntax
  • ClosuresIncluding mutable captures
  • Higher-Order FunctionsFunctions as arguments/returns
  • Async/AwaitAsync function support

Classes

  • Class DeclarationBasic class syntax
  • ConstructorsWith parameters
  • Private Fields (#)ES2022 #privateField syntax
  • Static Methods/FieldsClass-level members
  • Getters/Settersget/set accessors
  • Inheritanceextends keyword
  • Super Callssuper() constructor calls

Type System

  • Type AnnotationsExplicit type declarations
  • Type InferenceAutomatic type detection
  • GenericsMonomorphization (like Rust)
  • InterfacesInterface declarations
  • Union Typesstring | number support
  • Type Guardstypeof operator
  • Type Aliasestype X = ... declarations

Standard Library

  • fsreadFileSync, writeFileSync, existsSync, etc.
  • pathjoin, dirname, basename, extname, resolve
  • cryptorandomBytes, randomUUID, sha256, md5
  • osplatform, arch, hostname, memory info
  • Bufferfrom, alloc, toString, slice, copy
  • child_processexecSync, spawnSync
  • JSON/Math/DateFull implementations
完全支持
部分

30+ 原生 npm 包

热门 npm 包以原生 Rust 重新实现。无需 npm install,无需 node_modules,只有快速的原生代码。

数据库

mysql2pgmongodbbetter-sqlite3ioredis

安全

bcryptargon2jsonwebtokencrypto

HTTP

httphttpsaxiosnode-fetchwsnodemailer

数据处理

cheeriosharpzliblodash

日期和时间

dayjsmomentdate-fnsnode-cron

工具

uuidnanoidslugifyvalidatordotenvrate-limiter-flexible
只需 import 即可使用——Perry 自动使用原生实现

从代码到 App Store

Perry 不仅编译您的应用——还将其送到用户手中。

perry build编译并签名
perry publish打包并提交
商店和下载App Store、Play Store、直接分发
perry verify测试每个平台

构建并签名

一条命令完成跨平台构建。macOS、iOS、Android 和 Windows 的代码签名自动处理。无需与 Xcode 配置文件或 Android 密钥库搏斗。

分发

推送到 App Store、Play Store,或提供直接下载。Perry Publish 处理打包、公证和提交。

验证

由 Geisterhand 驱动。在全部 6 个平台上进行自动化 UI 测试。在用户告诉您之前,确保您的应用在所有地方都能正常工作。

开源项目免费。 团队方案 → /publish

工作原理

从 TypeScript 源码到原生可执行文件,仅需数秒

TypeScript.ts 文件
SWC
解析器快速解析
HIR
转换Monomorphization
Crane
lift
代码生成机器码
可执行文件2-5 MB 二进制文件

想了解编译器内部是如何工作的吗? 编译器内部原理