diff options
-rwxr-xr-x | bin/npm-cli.js | 2 | ||||
-rw-r--r-- | doc/misc/npm-config.md | 10 | ||||
-rw-r--r-- | lib/config/defaults.js | 2 | ||||
-rw-r--r-- | lib/npm.js | 6 | ||||
-rw-r--r-- | test/tap/progress-config.js | 33 |
5 files changed, 51 insertions, 2 deletions
diff --git a/bin/npm-cli.js b/bin/npm-cli.js index c60fd737e..60d00bf29 100755 --- a/bin/npm-cli.js +++ b/bin/npm-cli.js @@ -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') @@ -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) }) diff --git a/doc/misc/npm-config.md b/doc/misc/npm-config.md index 167aaf7d7..e9b532d1d 100644 --- a/doc/misc/npm-config.md +++ b/doc/misc/npm-config.md @@ -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 diff --git a/lib/config/defaults.js b/lib/config/defaults.js index 133b8a09a..bf19b1256 100644 --- a/lib/config/defaults.js +++ b/lib/config/defaults.js @@ -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, @@ -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, diff --git a/lib/npm.js b/lib/npm.js index 92b38ec88..b92e15266 100644 --- a/lib/npm.js +++ b/lib/npm.js @@ -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) diff --git a/test/tap/progress-config.js b/test/tap/progress-config.js new file mode 100644 index 000000000..ce6f4faa1 --- /dev/null +++ b/test/tap/progress-config.js @@ -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') + }) +}) |