fix: require() supports npm module
This commit is contained in:
@@ -72,21 +72,12 @@ runtime.init();
|
||||
Image = com.stardust.autojs.core.image.ImageWrapper;
|
||||
|
||||
//重定向require以便支持相对路径
|
||||
|
||||
(function(){
|
||||
var __require__ = require;
|
||||
var builtInModules = ["lodash.js"];
|
||||
global.require = function(path){
|
||||
if(!path.endsWith(".js")){
|
||||
path = path + ".js";
|
||||
}
|
||||
if(builtInModules.indexOf(path) >= 0 && !files.exists(path)){
|
||||
return __require__(path);
|
||||
}
|
||||
if(path.startsWith("http://") || path.startsWith("https://")){
|
||||
return __require__(path);
|
||||
}
|
||||
return __require__(files.path(path));
|
||||
};
|
||||
var loadAssets = function(path){
|
||||
eval(files.readAssets(path));
|
||||
}
|
||||
loadAssets("jvm-npm.js");
|
||||
})();
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user