@@ -1171,7 +1171,8 @@ class FJavascriptContextImplementation : public FJavascriptContext
1171
1171
1172
1172
auto inner = [&](const FString& script_path)
1173
1173
{
1174
- auto it = Self->Modules .Find (script_path);
1174
+ auto full_path = IFileManager::Get ().ConvertToAbsolutePathForExternalAppForRead (*script_path);
1175
+ auto it = Self->Modules .Find (full_path);
1175
1176
if (it)
1176
1177
{
1177
1178
info.GetReturnValue ().Set (Local<Value>::New (isolate, *it));
@@ -1182,8 +1183,7 @@ class FJavascriptContextImplementation : public FJavascriptContext
1182
1183
FString Text;
1183
1184
if (FFileHelper::LoadFileToString (Text, *script_path))
1184
1185
{
1185
- Text = FString::Printf (TEXT (" (function (__dirname) {\n var module = { exports : {}, filename : __dirname }, exports = module.exports;\n %s\n ;return module.exports;}('%s'));" ), *Text, *script_path);
1186
- auto full_path = IFileManager::Get ().ConvertToAbsolutePathForExternalAppForRead (*script_path);
1186
+ Text = FString::Printf (TEXT (" (function (__dirname) {\n var module = { exports : {}, filename : __dirname }, exports = module.exports;\n %s\n ;return module.exports;}('%s'));" ), *Text, *script_path);
1187
1187
#if PLATFORM_WINDOWS
1188
1188
full_path = full_path.Replace (TEXT (" /" ), TEXT (" \\ " ));
1189
1189
#endif
@@ -1192,7 +1192,7 @@ class FJavascriptContextImplementation : public FJavascriptContext
1192
1192
{
1193
1193
UE_LOG (Javascript, Log, TEXT (" Invalid script for require" ));
1194
1194
}
1195
- Self->Modules .Add (script_path , UniquePersistent<Value>(isolate, exports));
1195
+ Self->Modules .Add (full_path , UniquePersistent<Value>(isolate, exports));
1196
1196
info.GetReturnValue ().Set (exports);
1197
1197
found = true ;
1198
1198
return true ;
@@ -1265,47 +1265,43 @@ class FJavascriptContextImplementation : public FJavascriptContext
1265
1265
1266
1266
auto inner2 = [&](FString base_path)
1267
1267
{
1268
- for (;;)
1269
- {
1270
- if (!FPaths::DirectoryExists (base_path)) return false ;
1271
-
1272
- auto script_path = base_path / required_module;
1273
- if (!script_path.EndsWith (TEXT (" .js" )))
1274
- {
1275
- if (script_path.EndsWith (TEXT (" .json" )))
1276
- {
1277
- if (inner_json (script_path)) return true ;
1278
- }
1279
- else
1280
- {
1281
- if (inner (script_path + TEXT (" .js" ))) return true ;
1282
- if (inner_json (script_path + TEXT (" .json" ))) return true ;
1283
- if (inner (script_path / TEXT (" index.js" ))) return true ;
1268
+ if (!FPaths::DirectoryExists (base_path)) return false ;
1284
1269
1285
- if (inner_package_json (script_path)) return true ;
1286
- }
1287
- }
1288
- else
1289
- {
1290
- if (inner (script_path)) return true ;
1291
- }
1292
-
1293
- base_path = base_path / TEXT (" node_modules" );
1270
+ auto script_path = base_path / required_module;
1271
+ if (script_path.EndsWith (TEXT (" .js" )))
1272
+ {
1273
+ if (inner (script_path)) return true ;
1294
1274
}
1275
+ else
1276
+ {
1277
+ if (inner (script_path + TEXT (" .js" ))) return true ;
1278
+ }
1279
+ if (script_path.EndsWith (TEXT (" .json" )))
1280
+ {
1281
+ if (inner_json (script_path)) return true ;
1282
+ }
1283
+ else
1284
+ {
1285
+ if (inner_json (script_path + TEXT (" .json" ))) return true ;
1286
+ }
1287
+
1288
+ if (inner (script_path / TEXT (" index.js" ))) return true ;
1289
+ if (inner_package_json (script_path)) return true ;
1290
+
1291
+ return false ;
1295
1292
};
1296
1293
1297
1294
auto current_script_path = FPaths::GetPath (StringFromV8 (StackTrace::CurrentStackTrace (isolate, 1 , StackTrace::kScriptName )->GetFrame (0 )->GetScriptName ()));
1298
1295
#if PLATFORM_WINDOWS
1299
1296
current_script_path = current_script_path.Replace (TEXT (" \\ " ), TEXT (" /" ));
1300
1297
#endif
1301
- if (!inner2 (current_script_path))
1298
+ if (!(required_module[ 0 ] == ' . ' && inner2 (current_script_path) ))
1302
1299
{
1303
- if (! inner2 ( " . " ) )
1300
+ for ( const auto & path : Self-> Paths )
1304
1301
{
1305
- for (const auto & path : Self->Paths )
1306
- {
1307
- if (inner2 (path)) break ;
1308
- }
1302
+ if (inner2 (path)) break ;
1303
+
1304
+ if (inner2 (path / TEXT (" node_modules" ))) break ;
1309
1305
}
1310
1306
}
1311
1307
0 commit comments