Skip to content

Commit

Permalink
「取り込む」でモジュールのロードが不便なのを修正(#387)
Browse files Browse the repository at this point in the history
  • Loading branch information
kujirahand committed Jun 5, 2019
1 parent f99147b commit 846c91c
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/cnako3.js
Original file line number Diff line number Diff line change
Expand Up @@ -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を更新する
Expand Down

0 comments on commit 846c91c

Please sign in to comment.