Contributions are welcome to the Astro compiler!
Rust is needed to work with this repo. Install it via rustup.
You will also need Node.js installed, as well as pnpm (npm i -g pnpm). Run pnpm install to install dependencies.
The compiler is split into two Rust crates:
crates/astro_codegen/- The core code generation engine that transforms Astro ASTs into JavaScriptcrates/astro_napi/- Node.js NAPI bindings that expose the compiler to JavaScript
The compilation pipeline is:
- Parsing -
oxc_parser(from the oxc project) parses.astrofiles into an AST - Scanning -
AstroScannerpre-analyzes the AST to collect metadata (hydrated components, scripts, etc.) - Printing -
AstroCodegengenerates JavaScript code from the AST
The packages/compiler/ TypeScript package provides the @astrojs/compiler-rs npm API, wrapping the NAPI bindings.
# Build the NAPI native addon (debug mode)
pnpm run build:napi
# Build the TypeScript package
pnpm run build:compiler
# Build everything
pnpm run build:all# Run all Rust tests (unit + snapshot)
cargo test
# Run only astro_codegen tests
cargo test -p astro_codegen
# Update snapshots after changes
cargo insta reviewpnpm run testAdd a new .astro fixture file in crates/astro_codegen/tests/fixtures/ and run:
cargo test -p astro_codegenA new .snap file will be created. Review it with cargo insta review.