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 ,
@@ -16,28 +17,29 @@ export function toCmakePath(input: string) {
1617}
1718
1819export 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
4345export function getWeakNodeApiVariables ( triplet : SupportedTriplet ) {
0 commit comments