From 160e7f4118d29583d3d2524d77f6162e6d9b650a Mon Sep 17 00:00:00 2001 From: MiaoWoo Date: Sun, 1 Sep 2019 23:58:07 +0800 Subject: [PATCH] feat: compatible symbolic links require --- .gitignore | 3 ++- src/main/resources/core/patch/String.js | 8 ++++++-- src/main/resources/core/require.js | 17 ++++++++++++++--- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index a2d980c..8fc2d24 100644 --- a/.gitignore +++ b/.gitignore @@ -51,4 +51,5 @@ vendor/ # Minecraft Data -/world \ No newline at end of file +/world +**/node_modules/ diff --git a/src/main/resources/core/patch/String.js b/src/main/resources/core/patch/String.js index db267dc..1143d9e 100644 --- a/src/main/resources/core/patch/String.js +++ b/src/main/resources/core/patch/String.js @@ -1,10 +1,14 @@ /** * 补丁和方法扩展 */ -(function () { +(function() { // Java格式化方法 var str = Java.type('java.lang.String'); - String.prototype.format = function () { + String.prototype.format = function() { return str.format(this, Array.prototype.slice.call(arguments, 0)) }; + var indexOf = String.prototype.indexOf; + String.prototype.contains = function(searchString/*, position*/) { + return indexOf.call(this, searchString, arguments[1]) > -1; + }; })(); diff --git a/src/main/resources/core/require.js b/src/main/resources/core/require.js index b39a6c9..d144a19 100644 --- a/src/main/resources/core/require.js +++ b/src/main/resources/core/require.js @@ -60,6 +60,17 @@ return file.canonicalPath; } + /** + * 获得文件绝对路径 + * @param file + * @returns {*} + * @private + */ + function _absolute(file) { + // noinspection JSUnresolvedVariable + return file.absolutePath; + } + /** * 获得缓存的文件名称 * @param file @@ -67,7 +78,7 @@ * @private */ function _cacheFile(file) { - return _canonical(file).replace(parent, cacheDir); + return _absolute(file).replace(parent, cacheDir); } /** @@ -108,12 +119,12 @@ return file; } // JS文件 - var js = new File(normalizeName(_canonical(file), ".js")); + var js = new File(normalizeName(_absolute(file), ".js")); if (js.isFile()) { return js; } // JSON文件 - var json = new File(normalizeName(_canonical(file), ".json")); + var json = new File(normalizeName(_absolute(file), ".json")); if (json.isFile()) { return json; }