###前提・実現したいこと
Node.js でコンソールアプリケーション(自作プログラミング言語「Xemime」で書かれたソースファイルを js ファイルに変換するトランスパイラ)を開発しています。
2つのコマンドライン引数で2つのファイル名を指定し、
1つ目の引数で指定されたファイルを変換したものを
2つ目の引数で指定したファイル名で保存する、といったものです。
以下の4つのファイルが、同じ transpiler フォルダに入っています。
- package.json
- index.js (エントリーポイント)
- sample.xemime
- out.js (このコンソールアプリによって生成されるファイル)
###発生している問題・エラーメッセージ
transpiler フォルダがカレントディレクトリになっている状態で、
コマンドライン上でnode index.js "sample.xemime" "out.js"
を実行すれば
正しく変換処理が行われエラーを吐かずに終了します。
しかしnpm link
を実行して xemime-transpiler コマンドを使えるようにした後
xemime-transpiler "sample.xemime" "out.js"
を実行したところ、
index.js が呼び出されてはいますがコマンドライン引数の3つ目(インデックスでは2)以降が取得できず
エラーを吐いてしまいます。
C:\xampp\htdocs\Xemime\transpiler> xemime-transpiler "sample.xemime" "out.js" fs.js:549 return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode); ^ TypeError: path must be a string at TypeError (native) at Object.fs.openSync (fs.js:549:18) at Object.fs.readFileSync (fs.js:397:15) at Object.<anonymous> (C:\Users\user\AppData\Roaming\npm\node_modules\xemime-transpiler\index.js:155:14) at Module._compile (module.js:409:26) at Object.Module._extensions..js (module.js:416:10) at Module.load (module.js:343:32) at Function.Module._load (module.js:300:12) at Function.Module.runMain (module.js:441:10) at startup (node.js:139:18)
###該当のソースコード
以下は package.json のソースコードです。
json
1{ 2 "name": "xemime-transpiler", 3 "version": "1.0.0", 4 "main": "index.js", 5 "description": "This is the transpiler that converts Xemime code to JavaScript code.", 6 "scripts": { 7 "test": "echo \"Error: no test specified\" && exit 1" 8 }, 9 "repository": { 10 "type": "git", 11 "url": "git+https://github.com/0918nobita/Xemime.git" 12 }, 13 "keywords": [ 14 "transpiler" 15 ], 16 "author": "0918nobita", 17 "license": "GPL-3.0", 18 "bugs": { 19 "url": "https://github.com/0918nobita/Xemime/issues" 20 }, 21 "homepage": "https://github.com/0918nobita/Xemime#readme", 22 "preferGlobal": true, 23 "bin": { 24 "xemime-transpiler": "index.js" 25 } 26}
以下は index.js のソースコードです。
javascript
1'use strict'; 2const fs = require('fs'); 3/* 4 この部分に generateSyntaxTree 関数と XemimeTranspiler クラスの定義がありますが、 5 この件と一切関連のない部分なので省略してあります。 6*/ 7var transpiler = new XemimeTranspiler; 8var src = fs.readFileSync(process.argv[2], 'utf-8'); 9var tree = generateSyntaxTree(src.replace(/\r?\n/g,'')); 10var result = ''; 11for (var i = 0; i < tree.length; i++) { 12 result += (transpiler.trans(tree[i]) + ';'); 13} 14fs.writeFile(process.argv[3], result);
###試したこと
- node.js, npm のアップデート
###補足情報(言語/FW/ツール等のバージョンなど)
- node v4.4.4
- npm v2.15.1
- Windows 10 Pro 64bit
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。