Skip to content

Commit e01706c

Browse files
committed
Moving getWeakNodeApiPath into host package
1 parent 7a78a78 commit e01706c

File tree

3 files changed

+34
-35
lines changed

3 files changed

+34
-35
lines changed

packages/cmake-rn/src/weak-node-api.ts

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,13 @@
1-
import fs from "node:fs";
2-
import assert from "node:assert/strict";
31
import path from "node:path";
42

5-
import {
6-
isAndroidTriplet,
7-
isAppleTriplet,
8-
SupportedTriplet,
9-
weakNodeApiPath,
10-
} from "react-native-node-api";
3+
import { getWeakNodeApiPath, SupportedTriplet } from "react-native-node-api";
114

12-
import { ANDROID_ARCHITECTURES } from "./platforms/android.js";
135
import { getNodeApiIncludeDirectories } from "./headers.js";
146

157
export function toCmakePath(input: string) {
168
return input.split(path.win32.sep).join(path.posix.sep);
179
}
1810

19-
export function getWeakNodeApiPath(triplet: SupportedTriplet): string {
20-
if (isAppleTriplet(triplet)) {
21-
const xcframeworkPath = path.join(
22-
weakNodeApiPath,
23-
"weak-node-api.xcframework",
24-
);
25-
assert(
26-
fs.existsSync(xcframeworkPath),
27-
`Expected an XCFramework at ${xcframeworkPath}`,
28-
);
29-
return xcframeworkPath;
30-
} else if (isAndroidTriplet(triplet)) {
31-
const libraryPath = path.join(
32-
weakNodeApiPath,
33-
"weak-node-api.android.node",
34-
ANDROID_ARCHITECTURES[triplet],
35-
"libweak-node-api.so",
36-
);
37-
assert(fs.existsSync(libraryPath), `Expected library at ${libraryPath}`);
38-
return libraryPath;
39-
} else {
40-
throw new Error(`Unexpected triplet: ${triplet as string}`);
41-
}
42-
}
43-
4411
export function getWeakNodeApiVariables(triplet: SupportedTriplet) {
4512
return {
4613
// TODO: Make these names less "cmake-js" specific with an option to use the CMAKE_JS prefix

packages/host/src/node/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ export {
3232

3333
export { determineLibraryBasename, prettyPath } from "./path-utils.js";
3434

35-
export { weakNodeApiPath } from "./weak-node-api.js";
35+
export { weakNodeApiPath, getWeakNodeApiPath } from "./weak-node-api.js";

packages/host/src/node/weak-node-api.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,41 @@ import assert from "node:assert/strict";
22
import fs from "node:fs";
33
import path from "node:path";
44

5+
import {
6+
isAndroidTriplet,
7+
isAppleTriplet,
8+
SupportedTriplet,
9+
} from "./prebuilds/triplets";
10+
import { ANDROID_ARCHITECTURES } from "./prebuilds/android";
11+
512
export const weakNodeApiPath = path.resolve(__dirname, "../../weak-node-api");
613

714
assert(
815
fs.existsSync(weakNodeApiPath),
916
`Expected Weak Node API path to exist: ${weakNodeApiPath}`,
1017
);
18+
19+
export function getWeakNodeApiPath(triplet: SupportedTriplet): string {
20+
if (isAppleTriplet(triplet)) {
21+
const xcframeworkPath = path.join(
22+
weakNodeApiPath,
23+
"weak-node-api.xcframework",
24+
);
25+
assert(
26+
fs.existsSync(xcframeworkPath),
27+
`Expected an XCFramework at ${xcframeworkPath}`,
28+
);
29+
return xcframeworkPath;
30+
} else if (isAndroidTriplet(triplet)) {
31+
const libraryPath = path.join(
32+
weakNodeApiPath,
33+
"weak-node-api.android.node",
34+
ANDROID_ARCHITECTURES[triplet],
35+
"libweak-node-api.so",
36+
);
37+
assert(fs.existsSync(libraryPath), `Expected library at ${libraryPath}`);
38+
return libraryPath;
39+
} else {
40+
throw new Error(`Unexpected triplet: ${triplet as string}`);
41+
}
42+
}

0 commit comments

Comments
 (0)