Skip to content

Commit 60fae96

Browse files
authored
Separate weak-node-api package (#308)
* Don't export weakNodeApiPath from host * Move weak-node-api into its own package * Add a podspec to weak-node-api * Delete node-api headers from the host package * Remove symlink restoring of weak-node-api from host * Give preference to a Debug build of weak-node-api * Combined two buildFeatures * Error if weak-node-api is included outside of cmake-rn (for now) * Temporary work-around deep-referencing into weak-node-api * Use `find_package` instead of `include` to locate "weak-node-api" * Updates to the package lock * Moved weak-node-api into a peer dependency as it's supposed to be installed by the app * Reset weak-node-api version to 0.0.1 as published * Update readme and package description
1 parent 5dea205 commit 60fae96

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+421
-164
lines changed

.changeset/eight-walls-push.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"react-native-node-api": patch
3+
---
4+
5+
Moved weak-node-api into a separate "weak-node-api" package.

.changeset/quick-poets-greet.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"gyp-to-cmake": minor
3+
"cmake-rn": minor
4+
"react-native-node-api": minor
5+
---
6+
7+
Use `find_package` instead of `include` to locate "weak-node-api"

.changeset/spotty-beers-repeat.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"react-native-node-api": minor
3+
---
4+
5+
No longer exporting weakNodeApiPath, import from "weak-node-api" instead

.changeset/tired-words-relate.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"weak-node-api": patch
3+
---
4+
5+
Initial release!

.github/workflows/check.yml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ jobs:
4040
- run: rustup target add x86_64-linux-android
4141
- run: npm ci
4242
- run: npm run build
43-
# Bootstrap host package to get weak-node-api and ferric-example to get types
43+
# Bootstrap weak-node-api and ferric-example to get types
4444
# TODO: Solve this by adding an option to ferric to build only types or by committing the types into the repo as a fixture for an "init" command
45-
- run: npm run bootstrap --workspace react-native-node-api
45+
- run: npm run bootstrap --workspace weak-node-api
4646
- run: npm run bootstrap --workspace @react-native-node-api/ferric-example
4747
- run: npm run lint
4848
env:
@@ -184,9 +184,8 @@ jobs:
184184
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
185185
sudo udevadm control --reload-rules
186186
sudo udevadm trigger --name-match=kvm
187-
- name: Build weak-node-api for all architectures
188-
run: npm run build-weak-node-api:android
189-
working-directory: packages/host
187+
- name: Build weak-node-api for all Android architectures
188+
run: npm run build-weak-node-api:android --workspace weak-node-api
190189
- name: Build ferric-example for all architectures
191190
run: npm run build -- --android
192191
working-directory: packages/ferric-example
@@ -239,11 +238,10 @@ jobs:
239238
- run: rustup toolchain install nightly --component rust-src
240239
- run: npm ci
241240
- run: npm run build
242-
# Build weak-node-api for all Apple architectures
243-
- run: |
244-
npm run prepare-weak-node-api
245-
npm run build-weak-node-api:apple
246-
working-directory: packages/host
241+
- name: Build weak-node-api for all Apple architectures
242+
run: |
243+
npm run prepare-weak-node-api --workspace weak-node-api
244+
npm run build-weak-node-api:apple --workspace weak-node-api
247245
# Build Ferric example for all Apple architectures
248246
- run: npx ferric --apple
249247
working-directory: packages/ferric-example

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ dist/
77

88
# Treading the MacOS app as ephemeral
99
apps/macos-test-app
10+
11+
# Cache used by the rust analyzer
12+
target/rust-analyzer/

apps/test-app/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"react": "19.1.0",
4343
"react-native": "0.81.4",
4444
"react-native-node-api": "*",
45-
"react-native-test-app": "^4.4.7"
45+
"react-native-test-app": "^4.4.7",
46+
"weak-node-api": "*"
4647
}
4748
}

package-lock.json

Lines changed: 27 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"workspaces": [
77
"packages/cli-utils",
88
"packages/cmake-file-api",
9+
"packages/weak-node-api",
910
"packages/cmake-rn",
1011
"packages/ferric",
1112
"packages/gyp-to-cmake",
@@ -66,7 +67,7 @@
6667
"prettier": "^3.6.2",
6768
"react-native": "0.81.4",
6869
"read-pkg": "^9.0.1",
69-
"tsx": "^4.20.5",
70+
"tsx": "^4.20.6",
7071
"typescript": "^5.8.0",
7172
"typescript-eslint": "^8.38.0"
7273
}

packages/cmake-rn/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ Android's dynamic linker imposes restrictions on the access to global symbols (s
1010

1111
The implementation of Node-API is split between Hermes and our host package and to avoid addons having to explicitly link against either, we've introduced a `weak-node-api` library (published in `react-native-node-api` package). This library exposes only Node-API and will have its implementation injected by the host.
1212

13-
To link against `weak-node-api` just include the CMake config exposed through `WEAK_NODE_API_CONFIG` and add `weak-node-api` to the `target_link_libraries` of the addon's library target.
13+
To link against `weak-node-api` just use `find_package` to import the `weak-node-api` target and add it to the `target_link_libraries` of the addon's library target.
1414

1515
```cmake
1616
cmake_minimum_required(VERSION 3.15...3.31)
1717
project(tests-buffers)
1818
1919
# Defines the "weak-node-api" target
20-
include(${WEAK_NODE_API_CONFIG})
20+
find_package(weak-node-api REQUIRED CONFIG)
2121
2222
add_library(addon SHARED addon.c)
2323
target_link_libraries(addon PRIVATE weak-node-api)

0 commit comments

Comments
 (0)