简体   繁体   中英

How to propagate npm script command line arguments?

My package.json has few scripts defined in this manner.

{
  "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 . 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.

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.

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.

Your lint:fix script should be: "npm run lint --fix"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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