静默 npm run-script 失败时的错误 [英] Silencing errors on failures for npm run-script
问题描述
当您运行 npm test
并且失败时,您会得到测试输出 + 一条错误消息,如下所示:
When you run npm test
and it fails, you get the test outputs + a single error message, like so:
npm ERR! Test failed. See above for more details.
但是,我制作了一个名为 lint
的自定义脚本,如下所示:
However, I made a custom script called lint
, like so:
// package.json
{
// ...
"scripts": {
// ... definition for test ...
"lint": "./node_modules/jsxhint/cli.js src/",
}
}
好吧,很简单.但是当你运行 npm run lint
并且它失败时,而不是 npm test
好看的错误,你会在 linter 输出后得到一个大量的错误消息:>
Alright, simple enough. But when you run npm run lint
and it fails, Rather than the nice looking error for npm test
, you get a massive error message after the output of the linter:
npm ERR! Darwin 14.0.0
npm ERR! argv "node" "/usr/local/bin/npm" "run-script" "lint"
npm ERR! node v0.10.32
npm ERR! npm v2.1.7
npm ERR! code ELIFECYCLE
# and ~15 more lines...
有没有办法让所有这些垃圾静音,这样我就可以获得像 npm test
脚本一样的干净输出?我看到他们如何在 npm
源代码中发现错误,但我认为我不能只添加一个自定义命令而不像那样分叉 npm
......希望我错了!
Is there a way to silence all this junk so I can have a clean output like the npm test
script? I see how they caught the error in the npm
source code, but I don't think I can just add a custom command without forking npm
like that... Hope I'm wrong!
但如果我是,我是否最好将这样的任务推给 Grunt 之类的工具?谢谢!
But if I am, would I be better off just pushing off a task like this to a tool like Grunt? Thanks!
推荐答案
使用 npm run --silent
选项:
Use the npm run --silent
option:
$ npm run --silent test
如果你定义了一个 shell 别名,那么输入就更少了:
Even less typing if you define a shell alias:
$ alias run='npm run --silent'
$ run test
这篇关于静默 npm run-script 失败时的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!