feat: compatible windows and support disable function

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
2019-09-19 14:45:06 +08:00
parent 7dad0e7abc
commit 0dfe04040e
4 changed files with 5 additions and 31 deletions

View File

@ -1,6 +1,7 @@
'use strict'; 'use strict';
var log; var log;
var boot; var boot;
var engineDisable;
// noinspection ThisExpressionReferencesGlobalObjectJS // noinspection ThisExpressionReferencesGlobalObjectJS
var global = this; var global = this;
/** /**
@ -27,7 +28,7 @@ var global = this;
// Plugin file decompression to folder when file not exist // Plugin file decompression to folder when file not exist
release(root, '(plugins)+/.*', false); release(root, '(plugins)+/.*', false);
load(root + '/core/ployfill.js')(root, logger); load(root + '/core/ployfill.js')(root, logger);
require('@ms/core'); engineDisable = require('@ms/core').default;
}; };
var pluginYml; var pluginYml;

View File

@ -5,7 +5,7 @@
// Init Global Function // Init Global Function
global.noop = global.engineDisable = function() { }; global.noop = global.engineDisable = function() { };
global.engineLoad = load; global.engineLoad = load;
global.load = function __PreventGlobalLoadFunction__() { global.load = load = function __PreventGlobalLoadFunction__() {
throw new Error('Internal engine system not allow use `load` function!'); throw new Error('Internal engine system not allow use `load` function!');
}; };
// Init console and require // Init console and require

View File

@ -31,7 +31,6 @@
var File = Java.type("java.io.File"); var File = Java.type("java.io.File");
var FileNotFoundException = Java.type("java.io.FileNotFoundException"); var FileNotFoundException = Java.type("java.io.FileNotFoundException");
var separatorChar = File.separatorChar; var separatorChar = File.separatorChar;
var cacheDir = parent + separatorChar + "runtime";
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++) {
@ -43,12 +42,6 @@
return t; return t;
}; };
try {
base.delete(cacheDir);
} catch (ex) {
console.ex(ex);
}
/** /**
* 判断是否为一个文件 * 判断是否为一个文件
* @param file * @param file
@ -81,16 +74,6 @@
return file.absolutePath; return file.absolutePath;
} }
/**
* 获得缓存的文件名称
* @param file
* @returns {string}
* @private
*/
function _cacheFile(file) {
return _absolute(file).replace(parent, cacheDir);
}
/** /**
* 解析模块名称为文件 * 解析模块名称为文件
* 按照下列顺序查找 * 按照下列顺序查找
@ -211,19 +194,12 @@
* @returns {Object} * @returns {Object}
*/ */
function compileJs(module, file, optional) { function compileJs(module, file, optional) {
var cacheFile = _cacheFile(file);
var origin = base.read(file); var origin = base.read(file);
if (optional.hook) { if (optional.hook) {
origin = optional.hook(origin); origin = optional.hook(origin);
} }
base.save(cacheFile, "(function $(module, exports, require, __dirname, __filename) {" + origin + "});"); // 2019-09-19 使用 扩展函数直接 load 无需保存文件 删除文件
// 使用 load 可以保留行号和文件名称 var compiledWrapper = engineLoad({ script: "(function $(module, exports, require, __dirname, __filename) {" + origin + "});", name: file });
var compiledWrapper = engineLoad(cacheFile);
try {
base.delete(cacheFile);
} catch (ex) {
cacheFile.deleteOnExit();
}
compiledWrapper.apply(module.exports, [ compiledWrapper.apply(module.exports, [
module, module.exports, module.require, file.parentFile, file module, module.exports, module.require, file.parentFile, file
]); ]);

View File

@ -1,7 +1,5 @@
package pw.yumc.MiaoScript; package pw.yumc.MiaoScript;
import org.junit.Test;
/** /**
* Created with IntelliJ IDEA * Created with IntelliJ IDEA
* *
@ -9,7 +7,6 @@ import org.junit.Test;
* Created on 2017/9/14 10:08. * Created on 2017/9/14 10:08.
*/ */
public class MiaoScriptTest { public class MiaoScriptTest {
@Test
public void testBoot() { public void testBoot() {
} }
} }