Skip to content

Latest commit

 

History

History
76 lines (48 loc) · 1.69 KB

File metadata and controls

76 lines (48 loc) · 1.69 KB

Contributing

Contributions are welcome to the Astro compiler!

Setup

Rust

Rust is needed to work with this repo. Install it via rustup.

Node

You will also need Node.js installed, as well as pnpm (npm i -g pnpm). Run pnpm install to install dependencies.

Code Structure

The compiler is split into two Rust crates:

  • crates/astro_codegen/ - The core code generation engine that transforms Astro ASTs into JavaScript
  • crates/astro_napi/ - Node.js NAPI bindings that expose the compiler to JavaScript

The compilation pipeline is:

  1. Parsing - oxc_parser (from the oxc project) parses .astro files into an AST
  2. Scanning - AstroScanner pre-analyzes the AST to collect metadata (hydrated components, scripts, etc.)
  3. Printing - AstroCodegen generates JavaScript code from the AST

The packages/compiler/ TypeScript package provides the @astrojs/compiler-rs npm API, wrapping the NAPI bindings.

Building

# 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

Tests

Rust tests

# Run all Rust tests (unit + snapshot)
cargo test

# Run only astro_codegen tests
cargo test -p astro_codegen

# Update snapshots after changes
cargo insta review

TypeScript tests

pnpm run test

Adding new test cases

Add a new .astro fixture file in crates/astro_codegen/tests/fixtures/ and run:

cargo test -p astro_codegen

A new .snap file will be created. Review it with cargo insta review.