-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.cjs
More file actions
42 lines (39 loc) · 1.54 KB
/
Copy pathindex.cjs
File metadata and controls
42 lines (39 loc) · 1.54 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
const isNativeScriptRuntime =
typeof globalThis.interop !== "undefined" ||
typeof globalThis.NSObject !== "undefined";
if (!isNativeScriptRuntime) {
// deno-lint-ignore no-process-globals
if (
typeof process !== "undefined" &&
typeof process.dlopen === "function" &&
typeof process.env === "object" &&
typeof URL === "function" &&
typeof __filename === "string"
) {
// ===
// If we're in a Node-like environment (e.g. Node.js, Deno, or Bun)
// ===
const module = { exports: {} };
// `URL.pathname` is percent-encoded, but `process.dlopen` takes a filesystem path. Without
// decoding, a space in the path arrives as "%20" and the load fails with "no such file" —
// which happens for any app bundle whose path contains a space, e.g.
// /Applications/My App.app/… → /Applications/My%20App.app/…
process.dlopen(
module,
decodeURIComponent(
new URL(
"./build/RelWithDebInfo/NativeScript.apple.node/macos-arm64/NativeScript.framework/Versions/A/NativeScript",
`file://${__filename}`,
).pathname,
),
);
module.exports.init(process.env.METADATA_PATH);
} else if (typeof require !== "undefined") {
// ===
// If we're in a React Native-like environment
// ===
// react-native-node-api/babel-plugin will rewrite this to:
// module.exports = require("react-native-node-api").requireNodeAddon("-nativescript-macos-node-api—-NativeScript");
module.exports = require("./build/RelWithDebInfo/NativeScript.apple.node");
}
}