Skip to content

Commit 589eda8

Browse files
committed
Fix getting the WeakNodeApi path
1 parent 58bcea3 commit 589eda8

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

packages/cmake-rn/src/weak-node-api.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import fs from "node:fs";
22
import assert from "node:assert/strict";
33
import path from "node:path";
4+
import { fileURLToPath } from "node:url";
45

56
import {
67
isAndroidTriplet,
@@ -12,28 +13,29 @@ import { ANDROID_ARCHITECTURES } from "./android.js";
1213
import { getNodeAddonHeadersPath, getNodeApiHeadersPath } from "./headers.js";
1314

1415
export function getWeakNodeApiPath(triplet: SupportedTriplet): string {
15-
const { pathname } = new URL(
16+
const basePath = fileURLToPath(
1617
import.meta.resolve("react-native-node-api/weak-node-api")
1718
);
18-
assert(fs.existsSync(pathname), "Weak Node API path does not exist");
19+
assert(fs.existsSync(basePath), "Weak Node API path does not exist");
1920
if (isAppleTriplet(triplet)) {
20-
const xcframeworkPath = path.join(pathname, "weak-node-api.xcframework");
21+
const xcframeworkPath = path.join(basePath, "weak-node-api.xcframework");
2122
assert(
2223
fs.existsSync(xcframeworkPath),
2324
`Expected an XCFramework at ${xcframeworkPath}`
2425
);
2526
return xcframeworkPath;
2627
} else if (isAndroidTriplet(triplet)) {
2728
const libraryPath = path.join(
28-
pathname,
29+
basePath,
2930
"weak-node-api.android.node",
3031
ANDROID_ARCHITECTURES[triplet],
3132
"libweak-node-api.so"
3233
);
3334
assert(fs.existsSync(libraryPath), `Expected library at ${libraryPath}`);
3435
return libraryPath;
36+
} else {
37+
throw new Error(`Unexpected triplet: ${triplet}`);
3538
}
36-
return pathname;
3739
}
3840

3941
export function getWeakNodeApiVariables(triplet: SupportedTriplet) {

0 commit comments

Comments
 (0)