Skip to content

Commit

Permalink
config: Add option to turn off progress bars
Browse files Browse the repository at this point in the history
PR-URL: npm/npm#9037
Fixes: npm/npm#8704
  • Loading branch information
iarna committed Jul 25, 2015
1 parent 28ebc6c commit 423d8f7
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 2 deletions.
2 changes: 0 additions & 2 deletions bin/npm-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

var log = require('npmlog')
log.pause() // will be unpaused when config is loaded.
log.enableProgress()

log.info('it worked if it ends with', 'ok')

Expand Down Expand Up @@ -72,7 +71,6 @@
conf._exit = true
npm.load(conf, function (er) {
if (er) return errorHandler(er)
log.enableProgress()
npm.commands[npm.command](npm.argv, errorHandler)
})

Expand Down
10 changes: 10 additions & 0 deletions doc/misc/npm-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,16 @@ Set to true to run in "production" mode.
local `npm install` without any arguments.
2. Set the NODE_ENV="production" for lifecycle scripts.

### progress

* Default: true
* Type: Boolean

When set to `true`, npm will display a progress bar during time intensive
operations, if `process.stderr` is a TTY.

Set to `false` to suppress the progress bar.

### proprietary-attribs

* Default: true
Expand Down
2 changes: 2 additions & 0 deletions lib/config/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ Object.defineProperty(exports, 'defaults', {get: function () {
parseable: false,
prefix: globalPrefix,
production: process.env.NODE_ENV === 'production',
'progress': process.env.TRAVIS !== 'true' && process.env.CI !== 'true',
'proprietary-attribs': true,
proxy: null,
'https-proxy': null,
Expand Down Expand Up @@ -276,6 +277,7 @@ exports.types = {
parseable: Boolean,
prefix: path,
production: Boolean,
progress: Boolean,
'proprietary-attribs': Boolean,
proxy: [null, false, url], // allow proxy to be disabled explicitly
'rebuild-bundle': Boolean,
Expand Down
6 changes: 6 additions & 0 deletions lib/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,12 @@

log.resume()

if (config.get('progress')) {
log.enableProgress()
} else {
log.disableProgress()
}

// at this point the configs are all set.
// go ahead and spin up the registry client.
npm.registry = new CachingRegClient(npm.config)
Expand Down
33 changes: 33 additions & 0 deletions test/tap/progress-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict'
var test = require('tap').test
var log = require('npmlog')

// We use requireInject to get a fresh copy of
// the npm singleton each time we require it.
// If we didn't, we'd have shared state between
// these various tests.
var requireInject = require('require-inject')

test('disabled', function (t) {
t.plan(1)
var npm = requireInject('../../lib/npm.js', {})
npm.load({progress: false}, function () {
t.is(log.progressEnabled, false, 'should be disabled')
})
})

test('enabled', function (t) {
t.plan(1)
var npm = requireInject('../../lib/npm.js', {})
npm.load({progress: true}, function () {
t.is(log.progressEnabled, true, 'should be enabled')
})
})

test('default', function (t) {
t.plan(1)
var npm = requireInject('../../lib/npm.js', {})
npm.load({}, function () {
t.is(log.progressEnabled, true, 'should be enabled')
})
})

0 comments on commit 423d8f7

Please sign in to comment.