You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Load addons through Hermes' hermes_napi_load_module (#445)
* Load addons through Hermes' hermes_napi_load_module
The vendored Hermes ships a first-party addon loader that does what
CxxNodeApiHostModule did by hand — dlopen, resolve the init function,
create the exports object and call it — plus the deprecated
napi_module_register fallback the host never implemented.
Hand the platform specific path to it instead, and drop AddonLoaders.hpp
along with the host's own loading and initialization code.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013ugFE6vmMUVMTuoupvhMhX
* Trigger the label-gated CI jobs
The check workflow only re-evaluates its label conditions on opened,
synchronize and reopened events, so the labels added after opening this
PR need a push to take effect.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013ugFE6vmMUVMTuoupvhMhX
---------
Co-authored-by: Claude <noreply@anthropic.com>
> In the time of writing, this code only supports iOS as passes the path to the library with its .framework.
92
92
> We plan on generalizing this soon 🤞
93
93
94
-
## Transformed code calls into `react-native-node-api`, loading the platform specific dynamic library
94
+
## `react-native-node-api` creates a `napi_env` for the addon
95
95
96
-
The native implementation of `requireNodeAddon`is responsible for loading the dynamic library and allow the Node-API module to register its initialization function, either by exporting a `napi_register_module_v1` function or by calling the (deprecated) `napi_module_register` function.
96
+
The native implementation of `requireNodeAddon`turns the library name into a platform specific path (`@rpath/<name>.framework/<name>` on Apple platforms, `lib<name>.so` on Android) and creates a `napi_env` for the addon by calling `hermes_napi_create_env` with the low-level Hermes VM runtime behind the `jsi::Runtime`. As in Node.js, each addon gets its own environment.
97
97
98
-
In any case the native code stores the initialization function in a data-structure.
98
+
## Hermes loads the platform specific dynamic library and initializes the addon
99
99
100
-
## `react-native-node-api` creates a `napi_env` and initialize the Node-API module
100
+
The host hands the path and the environment to `hermes_napi_load_module`, which opens the dynamic library and finds the addon's initialization function, either by looking up an exported `napi_register_module_v1` symbol or by falling back to the `napi_module` passed to a (deprecated) `napi_module_register` call made while the library was loading. It then calls that function with the environment and a fresh `exports` object.
101
101
102
-
The initialization function of a Node-API module expects a `napi_env`, which we create by calling `hermes_napi_create_env` with the low-level Hermes VM runtime behind the `jsi::Runtime`. As in Node.js, each addon gets its own environment.
102
+
If the library cannot be opened, or exports no initialization function, `requireNodeAddon` throws.
103
103
104
104
## The library's C++ code initialize the `exports` object
0 commit comments