diff --git a/src/main/resources/bios.js b/src/main/resources/bios.js index 5d5329a..3b8cadb 100644 --- a/src/main/resources/bios.js +++ b/src/main/resources/bios.js @@ -1,6 +1,7 @@ 'use strict'; var log; var boot; +var engineDisable; // noinspection ThisExpressionReferencesGlobalObjectJS var global = this; /** @@ -27,7 +28,7 @@ var global = this; // Plugin file decompression to folder when file not exist release(root, '(plugins)+/.*', false); load(root + '/core/ployfill.js')(root, logger); - require('@ms/core'); + engineDisable = require('@ms/core').default; }; var pluginYml; diff --git a/src/main/resources/core/ployfill.js b/src/main/resources/core/ployfill.js index de4c630..e4a32c2 100644 --- a/src/main/resources/core/ployfill.js +++ b/src/main/resources/core/ployfill.js @@ -5,7 +5,7 @@ // Init Global Function global.noop = global.engineDisable = function() { }; global.engineLoad = load; - global.load = function __PreventGlobalLoadFunction__() { + global.load = load = function __PreventGlobalLoadFunction__() { throw new Error('Internal engine system not allow use `load` function!'); }; // Init console and require diff --git a/src/main/resources/core/require.js b/src/main/resources/core/require.js index b750cf6..4194fb4 100644 --- a/src/main/resources/core/require.js +++ b/src/main/resources/core/require.js @@ -31,7 +31,6 @@ var File = Java.type("java.io.File"); var FileNotFoundException = Java.type("java.io.FileNotFoundException"); var separatorChar = File.separatorChar; - var cacheDir = parent + separatorChar + "runtime"; function __assign(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { @@ -43,12 +42,6 @@ return t; }; - try { - base.delete(cacheDir); - } catch (ex) { - console.ex(ex); - } - /** * 判断是否为一个文件 * @param file @@ -81,16 +74,6 @@ return file.absolutePath; } - /** - * 获得缓存的文件名称 - * @param file - * @returns {string} - * @private - */ - function _cacheFile(file) { - return _absolute(file).replace(parent, cacheDir); - } - /** * 解析模块名称为文件 * 按照下列顺序查找 @@ -211,19 +194,12 @@ * @returns {Object} */ function compileJs(module, file, optional) { - var cacheFile = _cacheFile(file); var origin = base.read(file); if (optional.hook) { origin = optional.hook(origin); } - base.save(cacheFile, "(function $(module, exports, require, __dirname, __filename) {" + origin + "});"); - // 使用 load 可以保留行号和文件名称 - var compiledWrapper = engineLoad(cacheFile); - try { - base.delete(cacheFile); - } catch (ex) { - cacheFile.deleteOnExit(); - } + // 2019-09-19 使用 扩展函数直接 load 无需保存文件 删除文件 + var compiledWrapper = engineLoad({ script: "(function $(module, exports, require, __dirname, __filename) {" + origin + "});", name: file }); compiledWrapper.apply(module.exports, [ module, module.exports, module.require, file.parentFile, file ]); diff --git a/src/test/java/pw/yumc/MiaoScript/MiaoScriptTest.java b/src/test/java/pw/yumc/MiaoScript/MiaoScriptTest.java index 7156258..ac3e392 100644 --- a/src/test/java/pw/yumc/MiaoScript/MiaoScriptTest.java +++ b/src/test/java/pw/yumc/MiaoScript/MiaoScriptTest.java @@ -1,7 +1,5 @@ package pw.yumc.MiaoScript; -import org.junit.Test; - /** * Created with IntelliJ IDEA * @@ -9,7 +7,6 @@ import org.junit.Test; * Created on 2017/9/14 10:08. */ public class MiaoScriptTest { - @Test public void testBoot() { } } \ No newline at end of file