How napi-rs/napi-rs works
Project type and purpose
• This is a monorepo for a polyglot toolkit (“napi-rs”) that lets Rust code compile to Node-API modules and ships a companion JavaScript/TypeScript CLI, supporting benchmarks, examples, WASM runtime, target-triple utilities, CI configurations, and Dockerfiles.
File structure
• Top-level divides into:
• “crates/”: five Rust crates—sys (low-level bindings to Node C-API), macro (procedural macro for #[napi] annotations), napi (the Rust → N-API façade building on sys + macro), build (build scripts for various targets), backend (code-generation library used by the CLI).
• “cli/”: a Node.js/TS CLI wrapper that calls into the backend crate to scaffold projects, generate bindings, and publish NPM artifacts.
• “examples/”, “bench/”, “memory-testing/”, “wasm-runtime/”, “triples/”: demonstration, performance, testing, and auxiliary packages.
• CI & infra: .github/workflows for tests, Dockerfiles for Alpine/Debian/Zig toolchains, Yarn/Cargo workspace configs.
README insights
• The crates/napi README details the Rust → Node integration, features (async callbacks, type conversions, module registration), and target support. It confirms the layered architecture: sys → napi → user code.