[英]How to propagate npm script command line arguments?
我的package.json
中很少有以此方式定义的脚本。
{
"name": "project",
"scripts": {
"standard": "./node_modules/.bin/standard",
"lint": "npm run standard",
"lint:fix": "npm run lint -- --fix"
}
}
当我执行$ npm run lint:fix
我发现--fix
参数不会传播到./node_modules/.bin/standard
。 这是我得到的输出。
bash-3.2$ npm run lint:fix > project@0.0.1 lint:fix /path/to/my/project > npm run lint -- --fix > project@0.0.1 lint /path/to/my/project > npm run standard "--fix" > project@0.0.1 standard /path/to/my/project > standard standard: Use JavaScript Standard Style (http://standardjs.com) standard: Run `standard --fix` to automatically fix some problems. /path/to/my/project/data/someFile.js:38:34: Extra semicolon. npm ERR! Darwin 16.0.0 npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "standard" "--fix" npm ERR! node v6.9.4 npm ERR! npm v3.10.10 npm ERR! code ELIFECYCLE
这是一个错误,因为--fix
参数未正确传播。
好吧,我的问题不是棉绒或标准棉。 我想知道如何使参数正确传播到顶层脚本。
好吧,这是我在这个问题上出汗很多之后发现的。 (但是,这很愚蠢)。
引起该错误的原因不是因为参数没有传播。 相反,这是因为standard
中的--fix
标志不会自动修复--fix
期间的分号问题。
在给定的脚本集中(在问题中)。 该论点成功传播。 因此,这是将参数传播到顶级脚本的方法。
你不应该需要一个双-- --
在您的NPM脚本。
您的lint:fix
脚本应为: "npm run lint --fix"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.