Update app.js

This commit is contained in:
Namhyeon Go 2024-07-21 19:23:38 +09:00 committed by GitHub
parent ca2976f314
commit 4db58b0a3a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

32
app.js
View File

@ -225,7 +225,26 @@ function require(pathname) {
if ('.js$.jse$.coffee$.ls$.ts$.re$.res$.enc$'.indexOf(suffix + '$') < 0) FN += ".js";
if (cache[FN]) return cache[FN];
// get file and directory name
var T = '';
if (require._scriptProviders.length > 0) {
// get a script from a custom provider (e.g., remote server)
var status = -1, i = 0;
while (status < 0 && i < require._scriptProviders.length) {
try {
var result = require._scriptProviders[i](FN);
status = result.status;
if (status > -1) {
T = result.data;
}
break;
} catch (e) {
status = -1;
T = '';
}
i++;
}
} else {
// get a script from the local
var _filename = (function(fs, path) {
var filepaths = [
FN, // default
@ -264,12 +283,13 @@ function require(pathname) {
var currentScriptDirectory = require._getCurrentScriptDirectory();
return dirname.length > 0 ? currentScriptDirectory + "\\" + dirname : currentScriptDirectory;
})(require._getDirName(_filename));
var T = require._load(_filename);
T = require._load(_filename);
// check the suffix again
suffix = (function(pos, s) {
return pos < 0 ? '.' : s.substr(pos);
})(_filename.lastIndexOf('.'), _filename);
}
// transpile
switch (suffix) {
@ -477,6 +497,14 @@ require._modernie = function(FN, params, callback) {
return exports;
};
require._scriptProviders = [];
require._addScriptProvider = function(f) {
if (typeof f === "function") {
require._scriptProviders.push(f);
} else {
console.error("This is not an function");
}
};
/////////////////////////////////////////////////////////////////////////////////
// Load script, and call app.main()