-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Labels
Host 🏡Our `react-native-node-api-modules` packageOur `react-native-node-api-modules` package
Description
This is a suggestion which is subtly different from the one proposed in #91.
Goals
- Removing the requirement for the Babel plugin, for use-cases where a library author "controls" the code calling into the host package.
- Give more control to the host package when deciding what library files to loads (at runtime).
- Supporting multiple platforms (including Node.js) with source-code calling into the host package with the same call arguments
- In particular Node.js by providing a "node" export condition implementing
requireNodeAddon
by calling intoprocess.dlopen
.
- In particular Node.js by providing a "node" export condition implementing
Example library
Imagine a library ("my-lib") with a single index.js
entrypoint calling into our host package:
// node_modules/my-lib/index.js
import { requireNodeAddon } from "react-native-node-api";
const addon = requireNodeAddon({
packageName: "my-lib", // The name from the package.json
path: "build/Release/hello" // Path to the addon, relative to the package root, stripped from its ".*.node" file extensions.
});
export const sum = addon.sum;
and the following directory structure:
index.js
index.d.ts
build/Release
├── hello.android.node
│ ├── arm64-v8a
│ │ └── libhello.so
│ ├── armeabi-v7a
│ │ └── libhello.so
│ ├── react-native-node-api-module
│ ├── x86
│ │ └── libhello.so
│ └── x86_64
│ └── libhello.so
├── hello.apple.node
│ ├── Info.plist
│ ├── ios-arm64
│ │ └── hello.framework
│ │ ├── Headers
│ │ ├── hello
│ │ └── Info.plist
│ ├── ios-arm64-simulator
│ │ └── hello.framework
│ │ ├── Headers
│ │ ├── hello
│ │ └── Info.plist
│ ├── macos-arm64_x86_64
│ │ └── hello.framework
│ │ ├── Headers
│ │ ├── hello
│ │ └── Info.plist
│ ├── react-native-node-api-module
│ ├── tvos-arm64
│ │ └── hello.framework
│ │ ├── Headers
│ │ ├── hello
│ │ └── Info.plist
│ ├── tvos-arm64-simulator
│ │ └── hello.framework
│ │ ├── Headers
│ │ ├── hello
│ │ └── Info.plist
│ ├── xros-arm64
│ │ └── hello.framework
│ │ ├── Headers
│ │ ├── hello
│ │ └── Info.plist
│ └── xros-arm64-simulator
│ └── hello.framework
│ ├── Headers
│ ├── hello
│ └── Info.plist
└── hello.nodejs.node
├── darwin-arm64
│ └── hello.node
└── react-native-node-api-module
Metadata
Metadata
Assignees
Labels
Host 🏡Our `react-native-node-api-modules` packageOur `react-native-node-api-modules` package