-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathweak-node-api.ts
More file actions
51 lines (47 loc) · 1.55 KB
/
weak-node-api.ts
File metadata and controls
51 lines (47 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import fs from "node:fs";
import assert from "node:assert/strict";
import path from "node:path";
import {
isAndroidTriplet,
isAppleTriplet,
SupportedTriplet,
} from "react-native-node-api-modules";
import { ANDROID_ARCHITECTURES } from "./android.js";
import { getNodeAddonHeadersPath, getNodeApiHeadersPath } from "./headers.js";
export function getWeakNodeApiPath(triplet: SupportedTriplet): string {
const { pathname } = new URL(
import.meta.resolve("react-native-node-api-modules/weak-node-api")
);
assert(fs.existsSync(pathname), "Weak Node API path does not exist");
if (isAppleTriplet(triplet)) {
const xcframeworkPath = path.join(pathname, "weak-node-api.xcframework");
assert(
fs.existsSync(xcframeworkPath),
`Expected an XCFramework at ${xcframeworkPath}`
);
return xcframeworkPath;
} else if (isAndroidTriplet(triplet)) {
const libraryPath = path.join(
pathname,
"weak-node-api.android.node",
ANDROID_ARCHITECTURES[triplet],
"libweak-node-api.so"
);
assert(fs.existsSync(libraryPath), `Expected library at ${libraryPath}`);
return libraryPath;
}
return pathname;
}
export function getWeakNodeApiVariables(triplet: SupportedTriplet) {
const includePaths = [getNodeApiHeadersPath(), getNodeAddonHeadersPath()];
for (const includePath of includePaths) {
assert(
!includePath.includes(";"),
`Include path with a ';' is not supported: ${includePath}`
);
}
return {
CMAKE_JS_INC: includePaths.join(";"),
CMAKE_JS_LIB: getWeakNodeApiPath(triplet),
};
}