[英]In a package.json script, how do I pass an argument to node, as opposed to the script?
我的package.json
中有一個腳本,如下所示:
"scripts": {
"test": "... && mocha --full-trace test/db test/http test/storage test/utils",
我想將--async-stack-traces
傳遞給 mocha,但是--async-stack-traces
是節點命令行參數,而不是 mocha 命令行參數。
我想我可以通過運行node --async-stack-traces node_modules/mocha/bin/mocha --full-trace test/db test/http test/storage test/utils
,但有些東西感覺不雅或非慣用語。 有沒有另一種方法來實現這一目標?
你寫的方式基本上就是這樣做的方式:
node --async-stack-traces node_modules/mocha/bin/mocha --full-trace test/db test/http test/storage test/utils
您可以像這樣使用node_modules/.bin
稍微整理一下:
node --async-stack-traces node_modules/.bin/mocha --full-trace test/db test/http test/storage test/utils
下一個可能不是 Windows 兼容的,也不那么容易理解,但如果你只支持類 UNIX 操作系統,你可以依靠npm
腳本的$PATH
注入來稍微整理一下:
node --async-stack-traces `which mocha` --full-trace test/db test/http test/storage test/utils
如果你不想依賴whereis
,你可以使用npm bin
:
node --async-stack-traces `npm bin`/mocha --full-trace test/db test/http test/storage test/utils
希望在這一點上,您舉手並回到上面的第一個或第二個選項。 (我推薦第二個選項,所以你不依賴於mocha
包布局,可以想象這可能會改變。)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.