1
1
import fs from "node:fs" ;
2
2
import assert from "node:assert/strict" ;
3
3
import path from "node:path" ;
4
+ import { fileURLToPath } from "node:url" ;
4
5
5
6
import {
6
7
isAndroidTriplet ,
@@ -16,28 +17,29 @@ export function toCmakePath(input: string) {
16
17
}
17
18
18
19
export function getWeakNodeApiPath ( triplet : SupportedTriplet ) : string {
19
- const { pathname } = new URL (
20
+ const basePath = fileURLToPath (
20
21
import . meta. resolve ( "react-native-node-api/weak-node-api" )
21
22
) ;
22
- assert ( fs . existsSync ( pathname ) , "Weak Node API path does not exist" ) ;
23
+ assert ( fs . existsSync ( basePath ) , "Weak Node API path does not exist" ) ;
23
24
if ( isAppleTriplet ( triplet ) ) {
24
- const xcframeworkPath = path . join ( pathname , "weak-node-api.xcframework" ) ;
25
+ const xcframeworkPath = path . join ( basePath , "weak-node-api.xcframework" ) ;
25
26
assert (
26
27
fs . existsSync ( xcframeworkPath ) ,
27
28
`Expected an XCFramework at ${ xcframeworkPath } `
28
29
) ;
29
30
return xcframeworkPath ;
30
31
} else if ( isAndroidTriplet ( triplet ) ) {
31
32
const libraryPath = path . join (
32
- pathname ,
33
+ basePath ,
33
34
"weak-node-api.android.node" ,
34
35
ANDROID_ARCHITECTURES [ triplet ] ,
35
36
"libweak-node-api.so"
36
37
) ;
37
38
assert ( fs . existsSync ( libraryPath ) , `Expected library at ${ libraryPath } ` ) ;
38
39
return libraryPath ;
40
+ } else {
41
+ throw new Error ( `Unexpected triplet: ${ triplet } ` ) ;
39
42
}
40
- return pathname ;
41
43
}
42
44
43
45
export function getWeakNodeApiVariables ( triplet : SupportedTriplet ) {
0 commit comments