mirror of
https://github.com/napi-rs/napi-rs.git
synced 2025-12-08 19:56:07 +00:00
1.9 KiB
1.9 KiB
NAPI-RS Project Guide
Project Structure
Core Architecture:
/crates/- Rust implementationnapi/- Main runtime library (Node-API bindings)napi-sys/- Low-level FFI bindingsmacro/- Procedural macros (#[napi]attributes)backend/- Code generation and TypeScript definitionsbuild/- Build utilities
/cli/- Command-line tool (@napi-rs/cli)/examples/napi/- Comprehensive test suite and examples- Monorepo using Cargo workspaces (Rust) + Yarn workspaces (JS)
Key Files:
- Root
Cargo.toml- Workspace configuration /crates/backend/src/typegen.rs- TypeScript generation logic/cli/src/utils/typegen.ts- CLI TypeScript processing
Testing, Building, and Running Tests
Building
# Build all tests
yarn build:tests
# Build specific example (most common for testing changes)
yarn workspace @examples/napi build
Testing
# Run all tests in the example project
yarn workspace @examples/napi test
# Update test snapshots after changes
yarn workspace @examples/napi test -u
# Run specific test file
yarn workspace @examples/napi test __tests__/values.spec.ts
# Run Rust unit tests
cargo test
# Run linting
yarn lint
Common Development Workflow
- Make changes to Rust code
- Build:
yarn workspace @examples/napi build - Test:
yarn workspace @examples/napi test - Update snapshots if needed:
yarn workspace @examples/napi test -u
Important Notes
- JSDoc comments (
///) in Rust become TypeScript documentation - Use
#[napi(object)]for plain objects (interfaces) - Use
#[napi]on impl blocks for classes - The
#[napi(js_name = "...")]attribute renames in JS/TS - Build output:
.nodefiles in project root - TypeScript definitions:
index.d.cts
Other notes
- Type generation: Rebuild with
yarn workspace @examples/napi buildafter changes - Test snapshots: Update with
-uflag when output changes intentionally