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
{{ message }}
Repository navigation
Commit 29ca6a3
Browse filesBrowse the repository at this point in the historyBrowse files
Build addon paths in TypeScript and expose dlopen(module, filename) (#500)
* Build addon paths in TypeScript and expose dlopen(module, filename)
Move platform path construction and the exports cache out of
CxxNodeApiHostModule into TypeScript, replacing the native
requireNodeAddon with a dlopen(module, filename) matching Node's
process.dlopen. requireNodeAddon is rebuilt on top of it.
Refs #498
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U2xSE4KqJbTcKKr4FKKUX2
* Trigger CI with labels applied
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U2xSE4KqJbTcKKr4FKKUX2
* Trigger CI against next
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U2xSE4KqJbTcKKr4FKKUX2
---------
Co-authored-by: Claude <noreply@anthropic.com>
Export `dlopen(module, filename)`, loading a Node-API addon with the same semantics as Node's `process.dlopen`: `filename` is passed as-is to the system's `dlopen` (e.g. `lib<name>.so` on Android, `@rpath/<name>.framework/<name>` on Apple platforms), the addon's exports are assigned to `module.exports` and nothing is cached.
6
+
7
+
`requireNodeAddon` is now built on top of it, with the platform specific path and the per-runtime exports cache moving from native code into TypeScript. Its behavior is unchanged.
## `react-native-node-api` creates a `napi_env` for the addon
95
95
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.
96
+
`requireNodeAddon` returns the exports cached from an earlier load of the same library. Otherwise it turns the library name into a platform specific path (`@rpath/<name>.framework/<name>` on Apple platforms, `lib<name>.so` on Android) and calls `dlopen(module, filename)`, which has the same semantics as Node's `process.dlopen`. The native implementation of `dlopen`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 load gets its own environment.
97
97
98
98
## Hermes loads the platform specific dynamic library and initializes the addon
99
99
100
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
-
If the library cannot be opened, or exports no initialization function, `requireNodeAddon` throws.
102
+
If the library cannot be opened, or exports no initialization function, `dlopen` throws (and so does `requireNodeAddon`, without caching the failure). Otherwise the resulting exports object is assigned to `module.exports`.
103
103
104
104
## The library's C++ code initialize the `exports` object
0 commit comments