Skip to content

Commit a1f30db

Browse files
committed
chore: update macOS build scripts and enhance module resolution
- Modified `build_all_macos.sh` to include the `--no-vision` flag for `build_tklivesync.sh`, refining build options. - Added support for resolving module paths with `.mjs` and `.js` extensions in `BundleLoader.mm`, improving module loading flexibility. - Enhanced `ModuleInternal.cpp` to handle directory resolution for `package.json`, allowing for better module entry point detection.
1 parent 9475d09 commit a1f30db

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

NativeScript/cli/BundleLoader.mm

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@
2424
if ([fileManager fileExistsAtPath:mainPath]) {
2525
return std::string([mainPath UTF8String]);
2626
}
27+
28+
if ([[mainEntry pathExtension] length] == 0) {
29+
NSString* mainPathMjs = [mainPath stringByAppendingPathExtension:@"mjs"];
30+
if ([fileManager fileExistsAtPath:mainPathMjs]) {
31+
return std::string([mainPathMjs UTF8String]);
32+
}
33+
34+
NSString* mainPathJs = [mainPath stringByAppendingPathExtension:@"js"];
35+
if ([fileManager fileExistsAtPath:mainPathJs]) {
36+
return std::string([mainPathJs UTF8String]);
37+
}
38+
}
2739
}
2840
}
2941
}

NativeScript/runtime/modules/module/ModuleInternal.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ void ModuleInternal::Init(napi_env env, const std::string& baseDir) {
8484
napi_value global;
8585
napi_get_global(env, &global);
8686

87+
napi_value globalEnv;
88+
napi_create_external(env, env, nullptr, nullptr, &globalEnv);
89+
napi_set_named_property(env, global, "__globalEnv", globalEnv);
90+
8791
napi_value result;
8892
status = napi_run_script(env, source, &result);
8993
assert(status == napi_ok);
@@ -535,6 +539,23 @@ napi_value ModuleInternal::LoadImpl(napi_env env, const std::string& moduleName,
535539
result = LoadData(env, path);
536540
} else {
537541
std::filesystem::path filePath(path);
542+
543+
if (std::filesystem::is_directory(filePath)) {
544+
std::filesystem::path packageJson = filePath / "package.json";
545+
if (std::filesystem::is_regular_file(packageJson)) {
546+
bool error = false;
547+
std::string packageMain =
548+
ResolvePathFromPackageJson(env, packageJson.string(), error);
549+
if (error) {
550+
throw NativeScriptException("Unable to locate main entry in " +
551+
packageJson.string());
552+
}
553+
if (!packageMain.empty() && packageMain != path) {
554+
return LoadImpl(env, packageMain, baseDir, isData);
555+
}
556+
}
557+
}
558+
538559
std::filesystem::path fileWithIndexJs = filePath / "index.js";
539560
std::filesystem::path fileWithIndexMjs = filePath / "index.mjs";
540561
if (std::filesystem::exists(fileWithIndexMjs)) {

build_all_macos.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ fi
1111

1212
./build_metadata_generator.sh
1313
./build_nativescript.sh --no-catalyst --no-iphone --no-sim --macos
14-
./build_tklivesync.sh --no-catalyst --no-iphone --no-sim --macos
14+
./build_tklivesync.sh --no-catalyst --no-iphone --no-sim --no-vision --macos
1515
./prepare_dSYMs.sh
1616
./build_npm_macos.sh

build_nativescript.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ function cmake_build () {
5959
shift
6060
local archs=("$@")
6161
local is_macos_cli=false
62+
local is_macos_napi=false
6263

6364
if [ "$platform" == "macos-cli" ]; then
6465
platform="macos"

0 commit comments

Comments
 (0)