Skip to content

Build addon paths in TypeScript and expose dlopen(module, filename) #498

Closed

Description

@kraenhansen

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's process.dlopen and nothing added, so a difference from Node is a bug.
  • Name: exported as dlopen from react-native-node-api, and proposed as react-native/node-api for core. A bare dlopen is too ambiguous as a top-level react-native export. See Rename `requireNodeAddon` to `dlopen`? #263.
  • filename: what gets passed to the system's dlopen: lib<name>.so on 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 flags for now: adding an optional argument later breaks nobody.

Steps

  • Move the path construction in CxxNodeApiHostModule::loadNodeAddon into TypeScript.
  • Expose dlopen(module, filename). Exports reach JS through a generated global today (RN$NodeAddon_%p), so this needs a way to set module.exports.
  • Rebuild requireNodeAddon on top of it, moving the exports cache out of nodeAddons_ 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

The { packageName, path } resolver is #222, layered on top of this.

Metadata

Metadata

Assignees

Labels

Host 🏡Our `react-native-node-api-modules` packageLinking 🔗Discovering and copying prebuilds from packages into the hostenhancementNew feature or request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions