Repository navigation
Closed
Labels
Host 🏡Our `react-native-node-api-modules` packageOur `react-native-node-api-modules` packageLinking 🔗Discovering and copying prebuilds from packages into the hostDiscovering and copying prebuilds from packages into the hostenhancementNew feature or requestNew feature or request
Description
Move platform path construction out of native code and expose a raw loading function that matches Node's process.dlopen. This is the shape core would eventually own (#447).
Decisions
- Signature:
dlopen(module, filename), with the same semantics as Node'sprocess.dlopenand nothing added, so a difference from Node is a bug. - Name: exported as
dlopenfromreact-native-node-api, and proposed asreact-native/node-apifor core. A baredlopenis too ambiguous as a top-levelreact-nativeexport. See Rename `requireNodeAddon` to `dlopen`? #263. filename: what gets passed to the system's dlopen:lib<name>.soon Android,@rpath/<name>.framework/<name>on Apple. Core knows nothing about our layouts or naming.- No cache: a second call runs the addon's init again, as in Node.
- No
flagsfor now: adding an optional argument later breaks nobody.
Steps
- Move the path construction in
CxxNodeApiHostModule::loadNodeAddoninto TypeScript. - Expose
dlopen(module, filename). Exports reach JS through a generated global today (RN$NodeAddon_%p), so this needs a way to setmodule.exports. - Rebuild
requireNodeAddonon top of it, moving the exports cache out ofnodeAddons_into TypeScript. Keep the behaviour of not caching a failed load. Its library name argument and the Babel output don't change here. - Confirm the cache stays per runtime.
Known differences
hermes_napi_load_modulecreates its own exports object, whereas Node handsmodule.exportsto the addon's init. Until Hermes changes, the result is assigned tomodule.exports.- Each load creates a new
napi_env, which lives until the runtime is torn down. - Removing the cache exposes a Hermes bug: NAPI: hermes_napi_load_module can run another addon's init through lastRegisteredModule meta/hermes#2280 can run the wrong init for addons using
napi_module_register. TodaynodeAddons_hides the reload case.
The { packageName, path } resolver is #222, layered on top of this.
Metadata
Metadata
Assignees
Labels
Host 🏡Our `react-native-node-api-modules` packageOur `react-native-node-api-modules` packageLinking 🔗Discovering and copying prebuilds from packages into the hostDiscovering and copying prebuilds from packages into the hostenhancementNew feature or requestNew feature or request
Activity
Build addon paths in TypeScript and expose `dlopen(module, filename)` (…