Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Silencing errors on failures for npm run-script

Tags:

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. 

However, I made a custom script called lint, like so:

// package.json {   // ...   "scripts": {     // ... definition for test ...     "lint": "./node_modules/jsxhint/cli.js src/",   } } 

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

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!

But if I am, would I be better off just pushing off a task like this to a tool like Grunt? Thanks!

like image 858
osdiab Avatar asked Nov 08 '14 05:11

osdiab


1 Answers

Use the npm run --silent option:

$ npm run --silent test 

Even less typing if you define a shell alias:

$ alias run='npm run --silent' $ run test 
like image 131
Stuart Rackham Avatar answered Sep 20 '22 18:09

Stuart Rackham