简体   繁体   English

如何传播npm脚本命令行参数?

[英]How to propagate npm script command line arguments?

My package.json has few scripts defined in this manner. 我的package.json中很少有以此方式定义的脚本。

{
  "name": "project",
  "scripts": {
    "standard": "./node_modules/.bin/standard",
    "lint": "npm run standard",
    "lint:fix": "npm run lint -- --fix"
  }
}

When I execute $ npm run lint:fix I find that the argument --fix does not propagate to ./node_modules/.bin/standard . 当我执行$ npm run lint:fix我发现--fix参数不会传播到./node_modules/.bin/standard This is the output that I get. 这是我得到的输出。

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

Here there's an error because --fix argument didn't propagate correctly. 这是一个错误,因为--fix参数未正确传播。

Well, my question is not around linting or standardJs. 好吧,我的问题不是棉绒或标准棉。 I would like to know how to get the arguments propagate correctly till the top level script. 我想知道如何使参数正确传播到顶层脚本。

Well, this is what I found after sweating a lot on this issue. 好吧,这是我在这个问题上出汗很多之后发现的。 (It is very silly, though). (但是,这很愚蠢)。

The error was caused not because the argument didn't propagate. 引起该错误的原因不是因为参数没有传播。 Instead, it was because the --fix flag in standard doesn't auto-fix the semicolon issues during linting. 相反,这是因为standard中的--fix标志不会自动修复--fix期间的分号问题。

In the given set of scripts (in the question). 在给定的脚本集中(在问题中)。 The argument successfully propagated. 该论点成功传播。 Therefore, that's the way to propagate arguments till the top level script. 因此,这是将参数传播到顶级脚本的方法。

You shouldn't need a double -- -- in your npm script. 你不应该需要一个双-- --在您的NPM脚本。

Your lint:fix script should be: "npm run lint --fix" 您的lint:fix脚本应为: "npm run lint --fix"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM