Skip to content

Commit 99bc1d4

Browse files
committed
use URL instead of node:path to avoid bundling failures in a React Native environment
1 parent 0734412 commit 99bc1d4

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

packages/macos/index.cjs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,24 @@ const isNativeScriptRuntime =
44

55
if (!isNativeScriptRuntime) {
66
// deno-lint-ignore no-process-globals
7-
if (typeof process !== "undefined" && typeof process.dlopen === "function") {
7+
if (
8+
typeof process !== "undefined" &&
9+
typeof process.dlopen === "function" &&
10+
typeof process.env === "object" &&
11+
typeof URL === "function" &&
12+
typeof __filename === "string"
13+
) {
814
// ===
915
// If we're in a Node-like environment (e.g. Node.js, Deno, or Bun)
1016
// ===
1117

1218
const module = { exports: {} };
1319
process.dlopen(
1420
module,
15-
require("node:path").resolve(
16-
__dirname,
21+
new URL(
1722
"./build/RelWithDebInfo/NativeScript.apple.node/macos-arm64/NativeScript.framework/Versions/A/NativeScript",
18-
),
23+
`file://${__filename}`,
24+
).pathname,
1925
);
2026
module.exports.init(process.env.METADATA_PATH);
2127
} else if (typeof require !== "undefined") {

packages/macos/index.mjs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ const isNativeScriptRuntime =
44

55
if (!isNativeScriptRuntime) {
66
// deno-lint-ignore no-process-globals
7-
if (typeof process !== "undefined" && typeof process.dlopen === "function") {
7+
if (
8+
typeof process !== "undefined" &&
9+
typeof process.dlopen === "function" &&
10+
typeof process.env === "object" &&
11+
typeof URL === "function"
12+
) {
813
// ===
914
// If we're in a Node-like environment (e.g. Node.js, Deno, or Bun)
1015
// ===

packages/macos/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nativescript/macos-node-api",
3-
"version": "0.4.3",
3+
"version": "0.4.4",
44
"description": "An embeddable, engine-agnostic NativeScript runtime for macOS based on Node-API",
55
"repository": {
66
"type": "git",

0 commit comments

Comments
 (0)