|
1 | 1 | # The `react-native-node-api` command-line interface (CLI) |
2 | 2 |
|
3 | | -<!-- TODO: Write detailed documentation of each command and their parameters --> |
| 3 | +The `react-native-node-api` package installs a `react-native-node-api` binary, which app and library authors use to vendor Hermes, link Node-API modules into an app and inspect how the library-naming scheme resolves for a given module. |
| 4 | + |
| 5 | +```bash |
| 6 | +npx react-native-node-api <command> [options] |
| 7 | +``` |
| 8 | + |
| 9 | +Run `npx react-native-node-api help` or `npx react-native-node-api help <command>` to see this same information from the CLI itself. |
| 10 | + |
| 11 | +> [!NOTE] |
| 12 | +> This document is hand-written from the [Commander](https://github.com/tj/commander.js) program definition in [`packages/host/src/node/cli/program.ts`](../packages/host/src/node/cli/program.ts) (with the `vendor-hermes` command defined in [`hermes.ts`](../packages/host/src/node/cli/hermes.ts)). It needs to be kept in sync by hand whenever a command or its options change. |
| 13 | +
|
| 14 | +## `vendor-hermes [from]` |
| 15 | + |
| 16 | +Clones the pinned commit of Hermes' `static_h` branch (which carries Hermes' first-party Node-API implementation) into the `sdks/node-api-hermes` directory of the app's `react-native` package, so the native build can compile against it. Prints the path to the vendored checkout on success. |
| 17 | + |
| 18 | +- `[from]` — Path to a file inside the app package. Defaults to the current working directory. |
| 19 | +- `--react-native-package <package-name>` — The React Native package to vendor Hermes into. Defaults to `react-native`. |
| 20 | +- `--silent` — Don't print anything except the final path. Defaults to `false`. |
| 21 | +- `--force` — Don't check timestamps of input files to skip unnecessary rebuilds; removes and re-clones an existing checkout. Defaults to `false`. |
| 22 | + |
| 23 | +## `link [path]` |
| 24 | + |
| 25 | +Auto-links the Node-API modules found among the app's dependencies for one or more platforms, copying (and, on Apple, signing) them into place. |
| 26 | + |
| 27 | +- `[path]` — Some path inside the app package. Defaults to the current working directory. |
| 28 | +- `--android` — Link Android modules. |
| 29 | +- `--apple` — Link Apple modules. |
| 30 | +- `--prune` — Delete previously vendored modules that are no longer auto-linked. Defaults to `true`. |
| 31 | +- `--package-name <strategy>` — Controls how a dependency's package name is transformed into a library name. One of `strip`, `keep` or `omit` (see [Library naming](#library-naming) below). Defaults to `strip`, or the `NODE_API_PACKAGE_NAME` environment variable if set. |
| 32 | +- `--path-suffix <strategy>` — Controls how the path of the addon inside a package is transformed into a library name. One of `strip`, `keep` or `omit` (see [Library naming](#library-naming) below). Defaults to `strip`, or the `NODE_API_PATH_SUFFIX` environment variable if set. |
| 33 | + |
| 34 | +At least one of `--android` / `--apple` must be passed, or the command exits with an error listing the supported platforms. |
| 35 | + |
| 36 | +## `list [from-path]` |
| 37 | + |
| 38 | +Lists the Node-API modules found among the dependencies of the package at (or above) a path, without linking them. |
| 39 | + |
| 40 | +- `[from-path]` — Some path inside the app package. Defaults to the current working directory. |
| 41 | +- `--json` — Output the result as JSON instead of a human-readable summary. Defaults to `false`. |
| 42 | +- `--package-name <strategy>` — Same as for `link` (see [Library naming](#library-naming)). |
| 43 | +- `--path-suffix <strategy>` — Same as for `link` (see [Library naming](#library-naming)). |
| 44 | + |
| 45 | +## `info <path>` |
| 46 | + |
| 47 | +Utility to print the resolved module path, package name and computed library name for a single Node-API module, given its path. Useful for debugging naming collisions. |
| 48 | + |
| 49 | +- `<path>` — Path to a Node-API module (e.g. an `*.android.node` directory or `*.apple.node` framework). |
| 50 | +- `--package-name <strategy>` — Same as for `link` (see [Library naming](#library-naming)). |
| 51 | +- `--path-suffix <strategy>` — Same as for `link` (see [Library naming](#library-naming)). |
| 52 | + |
| 53 | +## `patch-xcode-project [path]` |
| 54 | + |
| 55 | +Patches the app's Xcode project to add a build phase which copies, renames and signs the Node-API frameworks (equivalent to running `link --apple` as part of the Xcode build). Only supported on macOS. |
| 56 | + |
| 57 | +- `[path]` — Some path inside the app package. Defaults to the current working directory. |
| 58 | + |
| 59 | +## Library naming |
| 60 | + |
| 61 | +`--package-name` and `--path-suffix` both control how the [cross-platform library name](./PREBUILDS.md) (`package-name--path-component--addon-name`) is derived, and accept the same three strategies. Given a package `@my-org/my-pkg` with an addon at `build/Release/my-addon.node`: |
| 62 | + |
| 63 | +| Strategy | `--package-name` effect | `--path-suffix` effect | |
| 64 | +| -------- | ----------------------------------------- | --------------------------------------------------- | |
| 65 | +| `strip` | Scope is dropped: `my-pkg--my-addon` | Path is reduced to its basename: `my-pkg--my-addon` | |
| 66 | +| `keep` | Scope is kept: `my-org--my-pkg--my-addon` | Full path is kept: `my-pkg--build-Release-my-addon` | |
| 67 | +| `omit` | Package name is dropped: `my-addon` | Path is dropped: `my-pkg` | |
0 commit comments