Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

--quiet for npm run-script #6066

Closed
matthew-andrews opened this issue Aug 29, 2014 · 11 comments
Closed

--quiet for npm run-script #6066

matthew-andrews opened this issue Aug 29, 2014 · 11 comments
Labels

Comments

@matthew-andrews
Copy link

It would be really helpful if you could use the output of one npm script from another npm script.

E.g:

"scripts": {
  "test": "npm run jshint && npm run lintspaces",
  "jshint": "jshint `npm run js-files`",
  "lintspaces": "lintspaces -n -t -d spaces -i js-comments -s 2 `npm run js-files`",
  "js-files": "find . -name \"*.js\" ! -path \"./node_modules/*\""
}

However if you run npm run js-files, the following is sent to stdout:-


> module-name@0.0.0 js-files /Users/mandrews/sandboxes/my-module
> find . -name "*.js" ! -path "./node_modules/*"

./filename.js
# etc

Where the first 4 lines just get in the way.

I've worked around this for now with tail like this:

"scripts": {
  "test": "npm run jshint && npm run lintspaces",
  "jshint": "jshint `npm run js-files | tail -n +5`",
  "lintspaces": "lintspaces -n -t -d spaces -i js-comments -s 2 `npm run js-files | tail -n +5`",
  "js-files": "find . -name \"*.js\" ! -path \"./node_modules/*\""
}

But it would be much nicer if one or more of these two options were available:

  • npm run had a --quiet mode where it would only output the output
  • Those first 4 lines of debug were sent to stderr not stdout*

* Full disclaimer: I still consider myself a bit of a beginner at CLIs so that might not be the 'right thing' to do.

@othiym23
Copy link
Contributor

What you want is npm run -s. Reopen if you find a case where it doesn't work properly!

@matthew-andrews
Copy link
Author

Amazing! Thank you. Sorry I didn't think to try that.

@jzacsh
Copy link

jzacsh commented Jan 31, 2015

Nice! Would it make sense to put this in the npm help run output? Currently it says:

NPM-RUN-SCRIPT(1)                                                                               NPM-RUN-SCRIPT(1)



NAME
       npm-run-script -- Run arbitrary package scripts

SYNOPSIS
       npm run-script [<pkg>] [command]
       npm run [<pkg>] [command]

DESCRIPTION
       This runs an arbitrary command from a package´s "scripts" object.  If no package name is provided, it will
       search for a package.json in the current folder and use its "scripts" object. If no "command" is provided,
       it will list the available top level scripts.

       It is used by the test, start, restart, and stop commands, but can be called directly, as well.

SEE ALSO
       ·   npm help 7 scripts

       ·   npm help test

       ·   npm help start

       ·   npm help restart

       ·   npm help stop






                                                  September 2014                                NPM-RUN-SCRIPT(1)

@othiym23
Copy link
Contributor

  1. That documentation is from an older version of npm that didn't support passing arguments to run scripts. See the current docs for the current API.
  2. There's a general problem to be solved here, which is that options like --quiet and --silent are generic and shared across most of the npm subcommands. If we include them in all the docs where they're applicable, then the docs get super bulky, lessening their usefulness as quick references. On the other hand, in the absence of complete per-command documentation, it's difficult to get a grasp on all the things those generic options allow you to do with npm. In this particular case, I'm not sure that --quiet has enough specific applicability to npm run to justify its inclusion, but it's not like the docs are super long, either...

@jzacsh
Copy link

jzacsh commented Jan 31, 2015

ah, interesting. Thanks for explaining!

Perhaps, "generic"/"subcommand" doc is noteworthy for all subdocs? eg:

SEE ALSO
  npm-scripts(7)
  [...]
  npm-stop(1)
  npm-subcommand

@phoenixstormcrow
Copy link

+1 for more accessible documentation on this. Did not find it with npm help, npm help npm, nor with npm help run-script. In fact, I still don't know where these options are documented. But google led me to this thread which solved my problem, which was essentially the same as the OP.

EDIT: Ah, I see it under npm help 7 config. To me that is not obvious.

@othiym23
Copy link
Contributor

@phoenixstormcrow in general, documentation for command-line options and other config values is in npm help 7 config, which is definitely not as accessible as it could be. There is a project underway to do a better job of putting documentation for switches in places in the documentation where it's more generally useful, but that's just getting underway.

@phoenixstormcrow
Copy link

👍 Sounds awesome!

@stevemao
Copy link
Contributor

@othiym23 any news on the project?

@robey
Copy link

robey commented Oct 9, 2015

As a datapoint, I ended up on this bug because none of the following told me what to do:

npm run --help
npm help

and the -q option, which is what most unix commands use for quiet mode, didn't work.

I would:

  • update npm help
  • make -q an alias for -s, for unix people

@danielkcz
Copy link

Sorry for reviving this after year, but looks like that the -s is still not documented. It was kinda surprise to find it here buried in old issue :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

7 participants