11import fs from "node:fs" ;
22import assert from "node:assert/strict" ;
33import path from "node:path" ;
4+ import { fileURLToPath } from "node:url" ;
45
56import {
67 isAndroidTriplet ,
@@ -12,28 +13,29 @@ import { ANDROID_ARCHITECTURES } from "./android.js";
1213import { getNodeAddonHeadersPath , getNodeApiHeadersPath } from "./headers.js" ;
1314
1415export 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
3941export function getWeakNodeApiVariables ( triplet : SupportedTriplet ) {
0 commit comments