Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions NativeScript/runtime/ModuleInternal.mm
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,14 @@ throw NativeScriptException(isolate,
stringByDeletingLastPathComponent] UTF8String];

// Shorten the parentDir for GetRequireFunction to avoid V8 parsing issues with long paths
std::string shortParentDir = "/app" + parentDir.substr(RuntimeConfig.ApplicationPath.length());
std::string shortParentDir;
if (parentDir.length() >= RuntimeConfig.ApplicationPath.length() &&
parentDir.compare(0, RuntimeConfig.ApplicationPath.length(), RuntimeConfig.ApplicationPath) == 0) {
shortParentDir = "/app" + parentDir.substr(RuntimeConfig.ApplicationPath.length());
} else {
// Fallback: use the entire path if it doesn't start with ApplicationPath
shortParentDir = parentDir;
}

Local<v8::Function> require = GetRequireFunction(isolate, shortParentDir);
// Use full paths for __filename and __dirname to match module.id
Expand Down Expand Up @@ -1566,7 +1573,14 @@ throw NativeScriptException(
}

std::string ModuleInternal::GetCacheFileName(const std::string& path) {
std::string key = path.substr(RuntimeConfig.ApplicationPath.size() + 1);
std::string key;
if (path.length() > RuntimeConfig.ApplicationPath.size() &&
path.compare(0, RuntimeConfig.ApplicationPath.size(), RuntimeConfig.ApplicationPath) == 0) {
key = path.substr(RuntimeConfig.ApplicationPath.size() + 1);
} else {
// Fallback: use the entire path if it doesn't start with ApplicationPath
key = path;
}
std::replace(key.begin(), key.end(), '/', '-');

NSArray* paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
Expand Down