feat: add global.trace and check node module
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
31351fc393
commit
1c21792572
@ -19,6 +19,7 @@ var global = this;
|
|||||||
if (java.nio.file.Files.exists(java.nio.file.Paths.get(root, "debug"))) {
|
if (java.nio.file.Files.exists(java.nio.file.Paths.get(root, "debug"))) {
|
||||||
logger.info('Running debugging mode...');
|
logger.info('Running debugging mode...');
|
||||||
global.debug = true;
|
global.debug = true;
|
||||||
|
global.trace = true;
|
||||||
}
|
}
|
||||||
// Check Class Loader, Sometimes Server will can't find plugin.yml file
|
// Check Class Loader, Sometimes Server will can't find plugin.yml file
|
||||||
loader = checkClassLoader();
|
loader = checkClassLoader();
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
log: log,
|
log: log,
|
||||||
info: log,
|
info: log,
|
||||||
ex: log,
|
ex: log,
|
||||||
|
trace: global.trace ? _proxy('TRACE') : global.noop,
|
||||||
debug: global.debug ? _proxy('DEBUG') : global.noop,
|
debug: global.debug ? _proxy('DEBUG') : global.noop,
|
||||||
warn: _proxy('WARN'),
|
warn: _proxy('WARN'),
|
||||||
error: _proxy('ERROR')
|
error: _proxy('ERROR')
|
||||||
|
@ -39,6 +39,8 @@
|
|||||||
var URL = Java.type('java.net.URL')
|
var URL = Java.type('java.net.URL')
|
||||||
var separatorChar = File.separatorChar;
|
var separatorChar = File.separatorChar;
|
||||||
|
|
||||||
|
var CoreModules = ['assert', 'async_hooks', 'child_process', 'cluster', 'crypto', 'dns', 'domain', 'events', 'fs', 'http', 'http2', 'https', 'inspector', 'net', 'os', 'path', 'vm', 'url', 'util', 'zlib', 'worker_threads']
|
||||||
|
|
||||||
function __assign(t) {
|
function __assign(t) {
|
||||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||||
s = arguments[i];
|
s = arguments[i];
|
||||||
@ -93,9 +95,10 @@
|
|||||||
} else {
|
} else {
|
||||||
// 解析Node目录
|
// 解析Node目录
|
||||||
var dir = [parent, 'node_modules'].join(separatorChar);
|
var dir = [parent, 'node_modules'].join(separatorChar);
|
||||||
return resolveAsFile(name, dir) ||
|
if (cacheModuleIds[name]) return cacheModuleIds[name]
|
||||||
resolveAsDirectory(name, dir) ||
|
cacheModuleIds[name] = resolveAsFile(name, dir) || resolveAsDirectory(name, dir) ||
|
||||||
(parent && parent.toString().startsWith(root) ? resolve(name, new File(parent).getParent()) : undefined);
|
(parent && parent.toString().startsWith(root) ? resolve(name, new File(parent).getParent()) : undefined);
|
||||||
|
return cacheModuleIds[name];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,12 +172,12 @@
|
|||||||
if (optional.cache && module) {
|
if (optional.cache && module) {
|
||||||
return module;
|
return module;
|
||||||
}
|
}
|
||||||
console.debug('Loading module', name + '(' + id + ')', 'Optional', JSON.stringify(optional));
|
console.trace('Loading module', name + '(' + id + ')', 'Optional', JSON.stringify(optional));
|
||||||
module = {
|
module = {
|
||||||
id: id,
|
id: id,
|
||||||
exports: {},
|
exports: {},
|
||||||
loaded: false,
|
loaded: false,
|
||||||
require: exports(file.parentFile)
|
require: getRequire(file.parentFile)
|
||||||
};
|
};
|
||||||
cacheModules[id] = module;
|
cacheModules[id] = module;
|
||||||
var cfile = _canonical(file);
|
var cfile = _canonical(file);
|
||||||
@ -245,6 +248,12 @@
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkCoreModule(name) {
|
||||||
|
if (CoreModules.indexOf(name) != -1) {
|
||||||
|
throw new Error("Can't load nodejs core module " + name + " . maybe later will auto replace to @ms/" + name + ' to compatible...')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 加载模块
|
* 加载模块
|
||||||
* @param name 模块名称
|
* @param name 模块名称
|
||||||
@ -253,6 +262,7 @@
|
|||||||
* @returns {*}
|
* @returns {*}
|
||||||
*/
|
*/
|
||||||
function _require(name, path, optional) {
|
function _require(name, path, optional) {
|
||||||
|
checkCoreModule(name);
|
||||||
var file = new File(name);
|
var file = new File(name);
|
||||||
file = _isFile(file) ? file : resolve(name, path);
|
file = _isFile(file) ? file : resolve(name, path);
|
||||||
optional = __assign({ cache: true }, optional);
|
optional = __assign({ cache: true }, optional);
|
||||||
@ -285,11 +295,20 @@
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getRequire(parent) {
|
||||||
|
var require = exports(parent)
|
||||||
|
require.resolve = function __DynamicResolve__(name) {
|
||||||
|
return _canonical(new File(resolve(name, parent)))
|
||||||
|
}
|
||||||
|
return require;
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof parent === 'string') {
|
if (typeof parent === 'string') {
|
||||||
parent = new File(parent);
|
parent = new File(parent);
|
||||||
}
|
}
|
||||||
var cacheModules = [];
|
var cacheModules = [];
|
||||||
|
var cacheModuleIds = [];
|
||||||
var notFoundModules = [];
|
var notFoundModules = [];
|
||||||
console.debug('Initialization require module... ParentDir:', _canonical(parent));
|
console.info('Initialization require module... ParentDir:', _canonical(parent));
|
||||||
return exports(parent);
|
return getRequire(parent);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user