Skip to content

Commit

Permalink
loader.Resolve compat
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieyang committed Jul 31, 2023
1 parent 418db38 commit 8c283e5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.

Large diffs are not rendered by default.

13 changes: 10 additions & 3 deletions unity/Assets/webgl/upm/Javascripts~/PuertsDLLMock/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,20 @@ global.PuertsWebGL = {
},
GetModuleExecutor: function () {
loader = typeof __tgjsGetLoader != 'undefined' ? __tgjsGetLoader() : null;
const loaderResolve = loader.Resolve ? (function(fileName: string, to: string = "") {
const resolvedName = loader.Resolve(fileName, to);
if (!resolvedName) {
throw new Error('module not found: ' + fileName);
}
return resolvedName;
}) : null;

var jsfunc = jsFunctionOrObjectFactory.getOrCreateJSFunction(function (fileName: string) {
if (['puerts/log.mjs', 'puerts/timer.mjs'].indexOf(fileName) != -1) {
return {};
}
if (loader.Resolve) {
fileName = loader.Resolve(fileName, "");
if (loaderResolve) {
fileName = loaderResolve(fileName, "");
}
if (typeof wx != 'undefined') {
const result = wxRequire('puerts_minigame_js_resources/' + (fileName.endsWith('.js') ? fileName : fileName + ".js"));
Expand Down Expand Up @@ -128,7 +135,7 @@ global.PuertsWebGL = {
executeModuleCache[specifier] = -1;
try {
PUERTS_JS_RESOURCES[specifier](result.exports, function mRequire(specifierTo: string) {
return mockRequire(loader.Resolve ? loader.Resolve(specifierTo, specifier) : normalize(specifier, specifierTo));
return mockRequire(loaderResolve ? loaderResolve(specifierTo, specifier) : normalize(specifier, specifierTo));
}, result);
} catch (e) {
delete executeModuleCache[specifier];
Expand Down

0 comments on commit 8c283e5

Please sign in to comment.