Skip to content

Commit 4887af6

Browse files
committed
Fix getting the WeakNodeApi path
1 parent f077f7f commit 4887af6

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,
@@ -16,28 +17,29 @@ export function toCmakePath(input: string) {
1617
}
1718

1819
export function getWeakNodeApiPath(triplet: SupportedTriplet): string {
19-
const { pathname } = new URL(
20+
const basePath = fileURLToPath(
2021
import.meta.resolve("react-native-node-api/weak-node-api")
2122
);
22-
assert(fs.existsSync(pathname), "Weak Node API path does not exist");
23+
assert(fs.existsSync(basePath), "Weak Node API path does not exist");
2324
if (isAppleTriplet(triplet)) {
24-
const xcframeworkPath = path.join(pathname, "weak-node-api.xcframework");
25+
const xcframeworkPath = path.join(basePath, "weak-node-api.xcframework");
2526
assert(
2627
fs.existsSync(xcframeworkPath),
2728
`Expected an XCFramework at ${xcframeworkPath}`
2829
);
2930
return xcframeworkPath;
3031
} else if (isAndroidTriplet(triplet)) {
3132
const libraryPath = path.join(
32-
pathname,
33+
basePath,
3334
"weak-node-api.android.node",
3435
ANDROID_ARCHITECTURES[triplet],
3536
"libweak-node-api.so"
3637
);
3738
assert(fs.existsSync(libraryPath), `Expected library at ${libraryPath}`);
3839
return libraryPath;
40+
} else {
41+
throw new Error(`Unexpected triplet: ${triplet}`);
3942
}
40-
return pathname;
4143
}
4244

4345
export function getWeakNodeApiVariables(triplet: SupportedTriplet) {

0 commit comments

Comments
 (0)