Skip to content
This repository was archived by the owner on Apr 7, 2021. It is now read-only.

Commit 16607d9

Browse files
committed
feat(quiet): added -q/--quiet to suppress output from npx itself
1 parent bec2887 commit 16607d9

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ If a full specifier is included, or if `--package` is used, npx will always use
4242

4343
* `--ignore-existing` - If this flag is set, npx will not look in `$PATH`, or in the current package's `node_modules/.bin` for an existing version before deciding whether to install. Binaries in those paths will still be available for execution, but will be shadowed by any packages requested by this install.
4444

45+
* `-q, --quiet` - Suppressed any output from npx itself (progress bars, error messages, install reports). Subcommand output itself will not be silenced.
46+
4547
* `-v, --version` - Show the current npx version.
4648

4749
## EXAMPLES

index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ function main (argv) {
2626
}
2727

2828
if (!argv.call && (!argv.command || !argv.package)) {
29-
console.error(Y()`\nERROR: You must supply a command.\n`)
30-
parseArgs.showHelp()
29+
!argv.q && console.error(Y()`\nERROR: You must supply a command.\n`)
30+
!argv.q && parseArgs.showHelp()
3131
process.exitCode = 1
3232
return
3333
}
@@ -65,7 +65,7 @@ function main (argv) {
6565
require('update-notifier')({pkg: require('./package.json')}).notify()
6666
// Some npm packages need to be installed. Let's install them!
6767
return ensurePackages(argv.package, argv).then(results => {
68-
results && console.error(Y()`npx: installed ${
68+
results && !argv.q && console.error(Y()`npx: installed ${
6969
results.added.length + results.updated.length
7070
} in ${(Date.now() - startTime) / 1000}s`)
7171
}).then(() => existing)
@@ -85,7 +85,7 @@ function main (argv) {
8585
}
8686
})
8787
}).catch(err => {
88-
console.error(err.message)
88+
!argv.q && console.error(err.message)
8989
process.exitCode = err.exitCode || 1
9090
})
9191
})
@@ -168,7 +168,7 @@ function installPackages (specs, prefix, opts) {
168168
const args = buildArgs(specs, prefix, opts)
169169
return which(opts.npm).then(npmPath => {
170170
return child.spawn(npmPath, args, {
171-
stdio: [0, 'pipe', 2]
171+
stdio: [0, 'pipe', opts.q ? 'ignore' : 2]
172172
}).then(deets => {
173173
try {
174174
return deets.stdout ? JSON.parse(deets.stdout) : null

parse-args.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ function parseArgs (argv) {
8888
describe: Y()`Ignores existing binaries in $PATH, or in the local project. This forces npx to do a temporary install and use the latest version.`,
8989
type: 'boolean'
9090
})
91+
.option('quiet', {
92+
alias: 'q',
93+
describe: Y()`Suppress output from npx itself. Subcommands will not be affected.`,
94+
type: 'boolean'
95+
})
9196
.option('npm', {
9297
describe: Y()`npm binary to use for internal operations.`,
9398
type: 'string',

0 commit comments

Comments
 (0)