Skip to content

Commit 7ccdc2d

Browse files
committed
Move weak-node-api into its own package
1 parent d875557 commit 7ccdc2d

29 files changed

+206
-84
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/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: 2 additions & 2 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:

.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/

package-lock.json

Lines changed: 17 additions & 4 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/src/weak-node-api.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@ import {
66
isAndroidTriplet,
77
isAppleTriplet,
88
SupportedTriplet,
9-
weakNodeApiPath,
109
} from "react-native-node-api";
1110

11+
import {
12+
applePrebuildPath,
13+
androidPrebuildPath,
14+
weakNodeApiCmakePath,
15+
} from "weak-node-api";
16+
1217
import { ANDROID_ARCHITECTURES } from "./platforms/android.js";
1318
import { getNodeAddonHeadersPath, getNodeApiHeadersPath } from "./headers.js";
1419

@@ -20,19 +25,14 @@ export function getWeakNodeApiPath(
2025
triplet: SupportedTriplet | "apple",
2126
): string {
2227
if (triplet === "apple" || isAppleTriplet(triplet)) {
23-
const xcframeworkPath = path.join(
24-
weakNodeApiPath,
25-
"weak-node-api.xcframework",
26-
);
2728
assert(
28-
fs.existsSync(xcframeworkPath),
29-
`Expected an XCFramework at ${xcframeworkPath}`,
29+
fs.existsSync(applePrebuildPath),
30+
`Expected an XCFramework at ${applePrebuildPath}`,
3031
);
31-
return xcframeworkPath;
32+
return applePrebuildPath;
3233
} else if (isAndroidTriplet(triplet)) {
3334
const libraryPath = path.join(
34-
weakNodeApiPath,
35-
"weak-node-api.android.node",
35+
androidPrebuildPath,
3636
ANDROID_ARCHITECTURES[triplet],
3737
"libweak-node-api.so",
3838
);
@@ -59,7 +59,7 @@ export function getWeakNodeApiVariables(
5959
): Record<string, string> {
6060
return {
6161
// Expose an includable CMake config file declaring the weak-node-api target
62-
WEAK_NODE_API_CONFIG: path.join(weakNodeApiPath, "weak-node-api.cmake"),
62+
WEAK_NODE_API_CONFIG: weakNodeApiCmakePath,
6363
WEAK_NODE_API_INC: getNodeApiIncludePaths().join(";"),
6464
WEAK_NODE_API_LIB: getWeakNodeApiPath(triplet),
6565
};

packages/ferric/src/cargo.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
UsageError,
1010
spawn,
1111
} from "@react-native-node-api/cli-utils";
12-
import { weakNodeApiPath } from "react-native-node-api";
12+
import { applePrebuildPath, androidPrebuildPath } from "weak-node-api";
1313

1414
import {
1515
AndroidTargetName,
@@ -169,25 +169,20 @@ export function getTargetAndroidPlatform(target: AndroidTargetName) {
169169
}
170170

171171
export function getWeakNodeApiFrameworkPath(target: AppleTargetName) {
172-
const xcframeworkPath = joinPathAndAssertExistence(
173-
weakNodeApiPath,
174-
"weak-node-api.xcframework",
175-
);
176172
const result = APPLE_XCFRAMEWORK_SLICES_PER_TARGET[target].find((slice) => {
177-
const candidatePath = path.join(xcframeworkPath, slice);
173+
const candidatePath = path.join(applePrebuildPath, slice);
178174
return fs.existsSync(candidatePath);
179175
});
180176
assert(
181177
result,
182178
`No matching slice found in weak-node-api.xcframework for target ${target}`,
183179
);
184-
return joinPathAndAssertExistence(xcframeworkPath, result);
180+
return joinPathAndAssertExistence(applePrebuildPath, result);
185181
}
186182

187183
export function getWeakNodeApiAndroidLibraryPath(target: AndroidTargetName) {
188184
return joinPathAndAssertExistence(
189-
weakNodeApiPath,
190-
"weak-node-api.android.node",
185+
androidPrebuildPath,
191186
ANDROID_ARCH_PR_TARGET[target],
192187
);
193188
}

packages/host/.gitignore

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,5 @@ include/
1616
android/.cxx/
1717
android/build/
1818

19-
# Everything in weak-node-api is generated, except for the configurations
20-
# Generated and built bia `npm run build-weak-node-api-injector`
21-
/weak-node-api/build/
22-
/weak-node-api/*.xcframework
23-
/weak-node-api/*.android.node
24-
/weak-node-api/weak_node_api.cpp
25-
/weak-node-api/weak_node_api.hpp
2619
# Generated via `npm run generate-weak-node-api-injector`
2720
/cpp/WeakNodeApiInjector.cpp

packages/host/package.json

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,33 +43,18 @@
4343
],
4444
"scripts": {
4545
"build": "tsc --build",
46-
"copy-node-api-headers": "tsx scripts/copy-node-api-headers.ts",
47-
"generate-weak-node-api": "tsx scripts/generate-weak-node-api.ts",
48-
"generate-weak-node-api-injector": "tsx scripts/generate-weak-node-api-injector.ts",
49-
"prepare-weak-node-api": "node --run copy-node-api-headers && node --run generate-weak-node-api-injector && node --run generate-weak-node-api",
50-
"build-weak-node-api": "cmake-rn --no-auto-link --no-weak-node-api-linkage --xcframework-extension --source ./weak-node-api --out ./weak-node-api",
51-
"build-weak-node-api:android": "node --run build-weak-node-api -- --android",
52-
"build-weak-node-api:apple": "node --run build-weak-node-api -- --apple",
53-
"build-weak-node-api:all": "node --run build-weak-node-api -- --android --apple",
46+
"generate-weak-node-api-injector": "node scripts/generate-weak-node-api-injector.mts",
5447
"test": "tsx --test --test-reporter=@reporters/github --test-reporter-destination=stdout --test-reporter=spec --test-reporter-destination=stdout src/node/**/*.test.ts src/node/*.test.ts",
5548
"test:gradle": "ENABLE_GRADLE_TESTS=true node --run test",
56-
"bootstrap": "node --run prepare-weak-node-api && node --run build-weak-node-api",
57-
"prerelease": "node --run prepare-weak-node-api && node --run build-weak-node-api:all"
49+
"bootstrap": "node --run generate-weak-node-api-injector",
50+
"prerelease": "node --run generate-weak-node-api-injector"
5851
},
5952
"keywords": [
60-
"react-native",
6153
"node-api",
6254
"napi",
63-
"node-api",
6455
"node-addon-api",
6556
"native",
66-
"addon",
67-
"module",
68-
"c",
69-
"c++",
70-
"bindings",
71-
"buildtools",
72-
"cmake"
57+
"addon"
7358
],
7459
"author": {
7560
"name": "Callstack",
@@ -87,6 +72,7 @@
8772
"@react-native-node-api/cli-utils": "0.1.1",
8873
"pkg-dir": "^8.0.0",
8974
"read-pkg": "^9.0.1",
75+
"weak-node-api": "0.1.0",
9076
"zod": "^4.1.11"
9177
},
9278
"devDependencies": {

0 commit comments

Comments
 (0)