|
1 |
| -// react-native-node-api/babel-plugin will rewrite this path to: |
2 |
| -// module.exports = require("react-native-node-api").requireNodeAddon("-nativescript-ios-node-api—-NativeScript"); |
3 |
| -// ... And some other build-time tooling in react-native-node-api searches this |
4 |
| -// package for `*.node` files to point `requireNodeAddon()` to the true path. |
5 |
| -// |
6 |
| -// This is why we've added react-native-node-api as a peer dependency. We've |
7 |
| -// marked it as optional, however, because other hosts may choose not to use |
8 |
| -// that Babel transform. |
9 |
| -module.exports = require("./build/Release/NativeScript.apple.node"); |
| 1 | +if (typeof interop === "undefined") { |
| 2 | + // deno-lint-ignore no-process-globals |
| 3 | + if (process) { |
| 4 | + // === |
| 5 | + // If we're in a Node-like environment (e.g. Node.js for Mobile) |
| 6 | + // === |
10 | 7 |
|
11 |
| -// Out of interest, we could alternatively write the path as follows: |
12 |
| -// module.exports = require("bindings")("NativeScript"); |
13 |
| -// |
14 |
| -// react-native-node-api/babel-plugin would recognise and rewrite it all the |
15 |
| -// same. That approach might make sense if we were also supporting Node.js with |
16 |
| -// this package (as in the case of Node.js, you'd omit the Babel transform and |
17 |
| -// you would actually depend on the "bindings" package), but unless we one day |
18 |
| -// merge the iOS and macOS packages into one, it feels better to reduce the |
19 |
| -// amount of magic involved. |
| 8 | + const path = |
| 9 | + "./build/RelWithDebInfo/NativeScript.apple.node/ios-arm64/NativeScript.framework/NativeScript"; |
| 10 | + |
| 11 | + let metaURL = import.meta.url; |
| 12 | + if (!metaURL.includes("://")) { |
| 13 | + metaURL = "file://" + metaURL; |
| 14 | + } |
| 15 | + |
| 16 | + const module = { exports: {} }; |
| 17 | + |
| 18 | + // deno-lint-ignore no-process-globals |
| 19 | + process.dlopen(module, new URL(path, metaURL).pathname); |
| 20 | + |
| 21 | + module.exports.init( |
| 22 | + // deno-lint-ignore no-process-globals |
| 23 | + process.env.METADATA_PATH |
| 24 | + ); |
| 25 | + } else { |
| 26 | + // === |
| 27 | + // If we're in a React Native-like environment |
| 28 | + // === |
| 29 | + |
| 30 | + // react-native-node-api/babel-plugin will rewrite this to: |
| 31 | + // module.exports = require("react-native-node-api").requireNodeAddon("-nativescript-macos-node-api—-NativeScript"); |
| 32 | + module.exports = require("./build/RelWithDebInfo/NativeScript.apple.node"); |
| 33 | + } |
| 34 | +} |
0 commit comments