From 846c91c4b5dbb42da9abf67ab422230bc49ce952 Mon Sep 17 00:00:00 2001 From: kujirahand Date: Wed, 5 Jun 2019 17:01:57 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=8C=E5=8F=96=E3=82=8A=E8=BE=BC=E3=82=80?= =?UTF-8?q?=E3=80=8D=E3=81=A7=E3=83=A2=E3=82=B8=E3=83=A5=E3=83=BC=E3=83=AB?= =?UTF-8?q?=E3=81=AE=E3=83=AD=E3=83=BC=E3=83=89=E3=81=8C=E4=B8=8D=E4=BE=BF?= =?UTF-8?q?=E3=81=AA=E3=81=AE=E3=82=92=E4=BF=AE=E6=AD=A3(#387)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cnako3.js | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/cnako3.js b/src/cnako3.js index b5f0502e..5138ce44 100755 --- a/src/cnako3.js +++ b/src/cnako3.js @@ -178,10 +178,40 @@ class CNako3 extends NakoCompiler { let fullpath = pname try { let plugmod = {} - if (fullpath.substr(0, 1) === '.') { // 相対パス指定 + // プラグインフォルダを検索 + // フルパス指定か相対パスの指定か? + const p1 = fullpath.substr(0, 1) + if (p1 === '/') { + // フルパス指定なので何もしない + } + else if (p1 === '.') { + // 相対パス指定なので、なでしこのプログラムからの相対指定を調べる + const basedir = path.dirname(this.filename) + fullpath = path.resolve(path.join(basedir, pname)) + } + else { + // 同じフォルダにあるか? const basedir = path.dirname(this.filename) fullpath = path.resolve(path.join(basedir, pname)) + if (!fs.existsSync(fullpath)) { + // node_modules 以下にあるか? + fullpath = path.resolve(path.join(basedir, 'node_modules', pname)) + if (!fs.existsSync(fullpath)) { + // NAKO_HOME 以下にあるか? + if (process.env['NAKO_HOME']) { + fullpath = path.resolve(path.join(process.env['NAKO_HOME'], 'node_modules', pname)) + } + if (!fs.existsSync(fullpath)) { + // NODE_PATH 以下にあるか? + fullpath = path.resolve(path.join(process.env.NODE_PATH, 'node_modules', pname)) + if (!fs.existsSync(fullpath)) { + fullpath = pname + } + } + } + } } + // モジュールを実際に取り込む plugmod = require(fullpath) this.addPluginFile(pname, fullpath, plugmod) // this.funclistを更新する