| 
 | 1 | +# Copilot Instructions for React Native Node-API  | 
 | 2 | + | 
 | 3 | +This is a **monorepo** that brings Node-API support to React Native, enabling native addons written in C/C++/Rust to run on React Native across iOS and Android.  | 
 | 4 | + | 
 | 5 | +## Package-Specific Instructions  | 
 | 6 | + | 
 | 7 | +**IMPORTANT**: Before working on any package, always check for and read package-specific `copilot-instructions.md` files in the package directory. These contain critical preferences and patterns for that specific package.  | 
 | 8 | + | 
 | 9 | +## Architecture Overview  | 
 | 10 | + | 
 | 11 | +**Core Flow**: JS `require("./addon.node")` → Babel transform → `requireNodeAddon()` TurboModule call → native library loading → Node-API module initialization  | 
 | 12 | + | 
 | 13 | +### Package Architecture  | 
 | 14 | + | 
 | 15 | +See the [README.md](../README.md#packages) for detailed descriptions of each package and their roles in the system. Key packages include:  | 
 | 16 | + | 
 | 17 | +- `packages/host` - Core Node-API runtime and Babel plugin  | 
 | 18 | +- `packages/cmake-rn` - CMake wrapper for native builds  | 
 | 19 | +- `packages/cmake-file-api` - TypeScript wrapper for CMake File API with Zod validation  | 
 | 20 | +- `packages/ferric` - Rust/Cargo wrapper with napi-rs integration  | 
 | 21 | +- `packages/gyp-to-cmake` - Legacy binding.gyp compatibility  | 
 | 22 | +- `apps/test-app` - Integration testing harness  | 
 | 23 | + | 
 | 24 | +## Critical Build Dependencies  | 
 | 25 | + | 
 | 26 | +- **Custom Hermes**: Currently depends on a patched Hermes with Node-API support (see [facebook/hermes#1377](https://github.com/facebook/hermes/pull/1377))  | 
 | 27 | +- **Prebuilt Binary Spec**: All tools must output to the exact naming scheme:  | 
 | 28 | +  - Android: `*.android.node/` with jniLibs structure + `react-native-node-api-module` marker file  | 
 | 29 | +  - iOS: `*.apple.node` (XCFramework renamed) + marker file  | 
 | 30 | + | 
 | 31 | +## Essential Workflows  | 
 | 32 | + | 
 | 33 | +### Development Setup  | 
 | 34 | + | 
 | 35 | +```bash  | 
 | 36 | +npm ci && npm run build      # Install deps and build all packages  | 
 | 37 | +npm run bootstrap           # Build native components (weak-node-api, examples)  | 
 | 38 | +```  | 
 | 39 | + | 
 | 40 | +### Package Development  | 
 | 41 | + | 
 | 42 | +- **TypeScript project references**: Use `tsc --build` for incremental compilation  | 
 | 43 | +- **Workspace scripts**: Most build/test commands use npm workspaces (`--workspace` flag)  | 
 | 44 | +- **Focus on Node.js packages**: AI development primarily targets the Node.js tooling packages rather than native mobile code  | 
 | 45 | +- **No TypeScript type asserts**: You have to ask explicitly and justify if you want to add `as` type assertions.  | 
 | 46 | + | 
 | 47 | +## Key Patterns  | 
 | 48 | + | 
 | 49 | +### Babel Transformation  | 
 | 50 | + | 
 | 51 | +The core magic happens in `packages/host/src/node/babel-plugin/plugin.ts`:  | 
 | 52 | + | 
 | 53 | +```js  | 
 | 54 | +// Input:  require("./addon.node")  | 
 | 55 | +// Output: require("react-native-node-api").requireNodeAddon("pkg-name--addon")  | 
 | 56 | +```  | 
 | 57 | + | 
 | 58 | +### CMake Integration  | 
 | 59 | + | 
 | 60 | +For linking against Node-API in CMakeLists.txt:  | 
 | 61 | + | 
 | 62 | +```cmake  | 
 | 63 | +include(${WEAK_NODE_API_CONFIG})  | 
 | 64 | +target_link_libraries(addon PRIVATE weak-node-api)  | 
 | 65 | +```  | 
 | 66 | + | 
 | 67 | +### Cross-Platform Naming  | 
 | 68 | + | 
 | 69 | +Library names use double-dash separation: `package-name--path-component--addon-name`  | 
 | 70 | + | 
 | 71 | +### Testing  | 
 | 72 | + | 
 | 73 | +- **Individual packages**: Some packages have VS Code test tasks and others have their own `npm test` scripts for focused iteration (e.g., `npm test --workspace cmake-rn`). Use the latter only if the former is missing.  | 
 | 74 | +- **Cross-package**: Use root-level `npm test` for cross-package testing once individual package tests pass  | 
 | 75 | +- **Mobile integration**: Available but not the primary AI development focus - ask the developer to run those tests as needed  | 
 | 76 | + | 
 | 77 | +**Documentation**: Integration details, platform setup, and toolchain configuration are covered in existing repo documentation files.  | 
0 commit comments