diff options
author | Rebecca Turner <turner@mikomi.org> | 2014-12-09 01:02:15 +0300 |
---|---|---|
committer | Rebecca Turner <me@re-becca.org> | 2015-06-26 03:26:38 +0300 |
commit | 192d5e09c685c40c7d48fa4a732ef2da6156886d (patch) | |
tree | 72fcdf3affeb0f79bbd6304fdd9c1bdc8cb97e16 | |
parent | ad0153f0c9edc3dbe2bd613e76184aa372153232 (diff) |
Swap the spinner out for the new progress bar code in npmlog
-rwxr-xr-x | bin/npm-cli.js | 2 | ||||
-rw-r--r-- | doc/misc/npm-config.md | 11 | ||||
-rw-r--r-- | lib/adduser.js | 4 | ||||
-rw-r--r-- | lib/cache.js | 4 | ||||
-rw-r--r-- | lib/config/defaults.js | 2 | ||||
-rw-r--r-- | lib/explore.js | 2 | ||||
-rw-r--r-- | lib/help.js | 1 | ||||
-rw-r--r-- | lib/init.js | 1 | ||||
-rw-r--r-- | lib/npm.js | 23 | ||||
-rw-r--r-- | lib/utils/error-handler.js | 3 | ||||
-rw-r--r-- | lib/utils/lifecycle.js | 8 | ||||
-rw-r--r-- | node_modules/char-spinner/LICENSE | 15 | ||||
-rw-r--r-- | node_modules/char-spinner/README.md | 31 | ||||
-rw-r--r-- | node_modules/char-spinner/package.json | 54 | ||||
-rw-r--r-- | node_modules/char-spinner/spin.js | 51 | ||||
-rw-r--r-- | node_modules/char-spinner/test/basic.js | 35 | ||||
-rw-r--r-- | package.json | 2 |
17 files changed, 13 insertions, 236 deletions
diff --git a/bin/npm-cli.js b/bin/npm-cli.js index ace40ca79..b01e8477e 100755 --- a/bin/npm-cli.js +++ b/bin/npm-cli.js @@ -17,6 +17,8 @@ process.title = "npm" var log = require("npmlog") log.pause() // will be unpaused when config is loaded. +log.enableProgress() + log.info("it worked if it ends with", "ok") var path = require("path") diff --git a/doc/misc/npm-config.md b/doc/misc/npm-config.md index 4b9d32ba3..c5cfbe943 100644 --- a/doc/misc/npm-config.md +++ b/doc/misc/npm-config.md @@ -772,17 +772,6 @@ using `-s` to add a signature. Note that git requires you to have set up GPG keys in your git configs for this to work properly. -### spin - -* Default: true -* Type: Boolean or `"always"` - -When set to `true`, npm will display an ascii spinner while it is doing -things, if `process.stderr` is a TTY. - -Set to `false` to suppress the spinner, or set to `always` to output -the spinner even for non-TTY outputs. - ### strict-ssl * Default: true diff --git a/lib/adduser.js b/lib/adduser.js index f59372a29..3b876f04b 100644 --- a/lib/adduser.js +++ b/lib/adduser.js @@ -14,7 +14,6 @@ try { adduser.usage = "npm adduser\nThen enter stuff at the prompts" function adduser (args, cb) { - npm.spinner.stop() if (!crypto) return cb(new Error( "You must compile node with ssl support to use the adduser feature")) @@ -124,8 +123,6 @@ function readEmail (c, u, cb) { } function save (c, u, cb) { - npm.spinner.start() - // save existing configs, but yank off for this PUT var uri = npm.config.get("registry") var scope = npm.config.get("scope") @@ -147,7 +144,6 @@ function save (c, u, cb) { } } npm.registry.adduser(uri, params, function (er, doc) { - npm.spinner.stop() if (er) return cb(er) // don't want this polluting the configuration diff --git a/lib/cache.js b/lib/cache.js index cae09b181..05d6ca595 100644 --- a/lib/cache.js +++ b/lib/cache.js @@ -270,9 +270,6 @@ function add (args, where, cb) { if (!spec) return cb(usage) - if (adding <= 0) { - npm.spinner.start() - } adding++ cb = afterAdd(cb) @@ -330,7 +327,6 @@ function unpack (pkg, ver, unpackTarget, dMode, fMode, uid, gid, cb) { function afterAdd (cb) { return function (er, data) { adding-- - if (adding <= 0) npm.spinner.stop() if (er || !data || !data.name || !data.version) return cb(er, data) log.silly("cache", "afterAdd", data.name+"@"+data.version) diff --git a/lib/config/defaults.js b/lib/config/defaults.js index a90d4c22b..0925779b6 100644 --- a/lib/config/defaults.js +++ b/lib/config/defaults.js @@ -193,7 +193,6 @@ Object.defineProperty(exports, "defaults", {get: function () { , shell : osenv.shell() , shrinkwrap: true , "sign-git-tag": false - , spin: true , "strict-ssl": true , tag : "latest" , "tag-version-prefix" : "v" @@ -298,7 +297,6 @@ exports.types = , shell : String , shrinkwrap: Boolean , "sign-git-tag": Boolean - , spin: ["always", Boolean] , "strict-ssl": Boolean , tag : String , tmp : path diff --git a/lib/explore.js b/lib/explore.js index 96475a069..1a40633ab 100644 --- a/lib/explore.js +++ b/lib/explore.js @@ -9,6 +9,7 @@ var npm = require("./npm.js") , spawn = require("./utils/spawn") , path = require("path") , fs = require("graceful-fs") + , log = require("npmlog") function explore (args, cb) { if (args.length < 1 || !args[0]) return cb(explore.usage) @@ -26,7 +27,6 @@ function explore (args, cb) { "\nExploring "+cwd+"\n"+ "Type 'exit' or ^D when finished\n") - npm.spinner.stop() var shell = spawn(sh, args, { cwd: cwd, stdio: "inherit" }) shell.on("close", function (er) { // only fail if non-interactive. diff --git a/lib/help.js b/lib/help.js index 942d27b41..481a07169 100644 --- a/lib/help.js +++ b/lib/help.js @@ -14,7 +14,6 @@ var path = require("path") , glob = require("glob") function help (args, cb) { - npm.spinner.stop() var argv = npm.config.get("argv").cooked var argnum = 0 diff --git a/lib/init.js b/lib/init.js index a889774b0..ffea8461e 100644 --- a/lib/init.js +++ b/lib/init.js @@ -12,7 +12,6 @@ init.usage = "npm init [--force/-f]" function init (args, cb) { var dir = process.cwd() log.pause() - npm.spinner.stop() var initFile = npm.config.get("init-module") if (!initJson.yes(npm.config)) { console.log( diff --git a/lib/npm.js b/lib/npm.js index a2756ed7d..d530ea8d7 100644 --- a/lib/npm.js +++ b/lib/npm.js @@ -20,7 +20,6 @@ var EventEmitter = require("events").EventEmitter , abbrev = require("abbrev") , which = require("which") , CachingRegClient = require("./cache/caching-client.js") - , charSpin = require("char-spinner") npm.config = { loaded: false, @@ -158,24 +157,7 @@ fullList = npm.fullList = fullList.filter(function (c) { return littleGuys.indexOf(c) === -1 }) -npm.spinner = - { int: null - , started: false - , start: function () { - if (npm.spinner.int) return - var c = npm.config.get("spin") - if (!c) return - var stream = npm.config.get("logstream") - var opt = { tty: c !== "always", stream: stream } - opt.cleanup = !npm.spinner.started - npm.spinner.int = charSpin(opt) - npm.spinner.started = true - } - , stop: function () { - clearInterval(npm.spinner.int) - npm.spinner.int = null - } - } +showProgress = log.progressEnabled Object.keys(abbrevs).concat(plumbing).forEach(function addCommand (c) { Object.defineProperty(npm.commands, c, { get : function () { @@ -196,6 +178,7 @@ Object.keys(abbrevs).concat(plumbing).forEach(function addCommand (c) { var args = Array.prototype.slice.call(arguments, 0) if (typeof args[args.length - 1] !== "function") { args.push(defaultCb) + log.enableProgress() } if (args.length === 1) args.unshift([]) @@ -233,6 +216,7 @@ Object.keys(abbrevs).concat(plumbing).forEach(function addCommand (c) { }) function defaultCb (er, data) { + log.disableProgress() if (er) console.error(er.stack || er.message) else console.log(data) } @@ -454,7 +438,6 @@ Object.getOwnPropertyNames(npm.commands).forEach(function (n) { if (typeof args[args.length - 1] === "function") { cb = args.pop() } - npm.commands[n](args, cb) } }, enumerable: false, configurable: true }) diff --git a/lib/utils/error-handler.js b/lib/utils/error-handler.js index 6ffb2867e..6848a3239 100644 --- a/lib/utils/error-handler.js +++ b/lib/utils/error-handler.js @@ -16,6 +16,7 @@ var cbCalled = false process.on("exit", function (code) { + log.disableProgress() // console.error("exit", code) if (!npm.config || !npm.config.loaded) return if (code) itWorked = false @@ -92,12 +93,12 @@ function exit (code, noLog) { // if we're really exiting, then let it exit on its own, so that // in-process stuff can finish or clean up first. if (!doExit) process.emit("exit", code) - npm.spinner.stop() } } function errorHandler (er) { + log.disableProgress() // console.error("errorHandler", er) if (!npm.config || !npm.config.loaded) { // logging won't work unless we pretend that it's ready diff --git a/lib/utils/lifecycle.js b/lib/utils/lifecycle.js index 299fa5698..8f9233488 100644 --- a/lib/utils/lifecycle.js +++ b/lib/utils/lifecycle.js @@ -157,10 +157,9 @@ function runCmd (note, cmd, pkg, env, stage, wd, unsafe, cb) { , group = unsafe ? null : npm.config.get("group") if (log.level !== 'silent') { - if (npm.spinner.int) { - npm.config.get("logstream").write("\r \r") - } + log.clearProgress() console.log(note) + log.showProgress() } log.verbose("unsafe-perm in lifecycle", unsafe) @@ -204,7 +203,9 @@ function runCmd_ (cmd, pkg, env, wd, stage, unsafe, uid, gid, cb_) { conf.windowsVerbatimArguments = true } + log.disableProgress() var proc = spawn(sh, [shFlag, cmd], conf) + proc.on("error", procError) proc.on("close", function (code, signal) { if (signal) { @@ -216,6 +217,7 @@ function runCmd_ (cmd, pkg, env, wd, stage, unsafe, uid, gid, cb_) { }) function procError (er) { + log.enableProgress() if (er && !npm.ROLLBACK) { log.info(pkg._id, "Failed to exec "+stage+" script") er.message = pkg._id + " " diff --git a/node_modules/char-spinner/LICENSE b/node_modules/char-spinner/LICENSE deleted file mode 100644 index 05eeeb88c..000000000 --- a/node_modules/char-spinner/LICENSE +++ /dev/null @@ -1,15 +0,0 @@ -The ISC License - -Copyright (c) Isaac Z. Schlueter - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR -IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/node_modules/char-spinner/README.md b/node_modules/char-spinner/README.md deleted file mode 100644 index b1290f592..000000000 --- a/node_modules/char-spinner/README.md +++ /dev/null @@ -1,31 +0,0 @@ -# char-spinner - -Put a little spinner on process.stderr, as unobtrusively as possible. - -## USAGE - -```javascript -var spinner = require("char-spinner") - -// All options are optional -// even the options argument itself is optional -spinner(options) -``` - -## OPTIONS - -Usually the defaults are what you want. Mostly they're just -configurable for testing purposes. - -* `stream` Output stream. Default=`process.stderr` -* `tty` Only show spinner if output stream has a truish `.isTTY`. Default=`true` -* `string` String of chars to spin. Default=`'/-\\|'` -* `interval` Number of ms between frames, bigger = slower. Default=`50` -* `cleanup` Print `'\r \r'` to stream on process exit. Default=`true` -* `unref` Unreference the spinner interval so that the process can - exit normally. Default=`true` -* `delay` Number of frames to "skip over" before printing the spinner. - Useful if you want to avoid showing the spinner for very fast - actions. Default=`2` - -Returns the generated interval, if one was created. diff --git a/node_modules/char-spinner/package.json b/node_modules/char-spinner/package.json deleted file mode 100644 index 91092d84b..000000000 --- a/node_modules/char-spinner/package.json +++ /dev/null @@ -1,54 +0,0 @@ -{ - "name": "char-spinner", - "version": "1.0.1", - "description": "Put a little spinner on process.stderr, as unobtrusively as possible.", - "main": "spin.js", - "directories": { - "test": "test" - }, - "dependencies": {}, - "devDependencies": { - "tap": "^0.4.10" - }, - "scripts": { - "test": "tap test/*.js" - }, - "repository": { - "type": "git", - "url": "git://github.com/isaacs/char-spinner" - }, - "keywords": [ - "char", - "spinner" - ], - "author": { - "name": "Isaac Z. Schlueter", - "email": "i@izs.me", - "url": "http://blog.izs.me/" - }, - "license": "ISC", - "bugs": { - "url": "https://github.com/isaacs/char-spinner/issues" - }, - "homepage": "https://github.com/isaacs/char-spinner", - "gitHead": "091b2ff5960aa083f68a5619fa93999d072aa152", - "_id": "char-spinner@1.0.1", - "_shasum": "e6ea67bd247e107112983b7ab0479ed362800081", - "_from": "char-spinner@latest", - "_npmVersion": "1.4.13", - "_npmUser": { - "name": "isaacs", - "email": "i@izs.me" - }, - "maintainers": [ - { - "name": "isaacs", - "email": "i@izs.me" - } - ], - "dist": { - "shasum": "e6ea67bd247e107112983b7ab0479ed362800081", - "tarball": "http://registry.npmjs.org/char-spinner/-/char-spinner-1.0.1.tgz" - }, - "_resolved": "https://registry.npmjs.org/char-spinner/-/char-spinner-1.0.1.tgz" -} diff --git a/node_modules/char-spinner/spin.js b/node_modules/char-spinner/spin.js deleted file mode 100644 index cae8540c6..000000000 --- a/node_modules/char-spinner/spin.js +++ /dev/null @@ -1,51 +0,0 @@ -module.exports = spinner - -function spinner(opt) { - opt = opt || {} - var str = opt.stream || process.stderr - var tty = typeof opt.tty === 'boolean' ? opt.tty : true - var string = opt.string || '/-\\|' - var ms = typeof opt.interval === 'number' ? opt.interval : 50 - if (ms < 0) ms = 0 - if (tty && !str.isTTY) return false - var CR = str.isTTY ? '\u001b[0G' : '\u000d'; - var CLEAR = str.isTTY ? '\u001b[2K' : '\u000d \u000d'; - - var s = 0 - var sprite = string.split('') - var wrote = false - - var delay = typeof opt.delay === 'number' ? opt.delay : 2 - - var interval = setInterval(function() { - if (--delay >= 0) return - s = ++s % sprite.length - var c = sprite[s] - str.write(c + CR) - wrote = true - }, ms) - - var unref = typeof opt.unref === 'boolean' ? opt.unref : true - if (unref && typeof interval.unref === 'function') { - interval.unref() - } - - var cleanup = typeof opt.cleanup === 'boolean' ? opt.cleanup : true - if (cleanup) { - process.on('exit', function() { - if (wrote) { - str.write(CLEAR); - } - }) - } - - module.exports.clear = function () { - str.write(CLEAR); - }; - - return interval -} - -module.exports.clear = function () {}; - - diff --git a/node_modules/char-spinner/test/basic.js b/node_modules/char-spinner/test/basic.js deleted file mode 100644 index ed91b984f..000000000 --- a/node_modules/char-spinner/test/basic.js +++ /dev/null @@ -1,35 +0,0 @@ -var test = require('tap').test -var spinner = require('../spin.js') - -test('does nothing when not a tty', function(t) { - var int = spinner({ - stream: { write: function(c) { - throw new Error('wrote something: ' + JSON.stringify(c)) - }, isTTY: false }, - }) - t.notOk(int) - t.end() -}) - -test('write spinny stuff', function(t) { - var output = '' - var written = 0 - var expect = "b\u001b[0Gc\u001b[0Gd\u001b[0Ge\u001b[0Gf\u001b[0Gg\u001b[0Gh\u001b[0Gi\u001b[0Gj\u001b[0Gk\u001b[0Gl\u001b[0Gm\u001b[0Gn\u001b[0Go\u001b[0Gp\u001b[0Ga\u001b[0Gb\u001b[0Gc\u001b[0Gd\u001b[0Ge\u001b[0Gf\u001b[0Gg\u001b[0Gh\u001b[0Gi\u001b[0Gj\u001b[0Gk\u001b[0Gl\u001b[0Gm\u001b[0Gn\u001b[0Go\u001b[0Gp\u001b[0Ga\u001b[0Gb\u001b[0Gc\u001b[0Gd\u001b[0Ge\u001b[0Gf\u001b[0Gg\u001b[0Gh\u001b[0Gi\u001b[0Gj\u001b[0Gk\u001b[0Gl\u001b[0Gm\u001b[0Gn\u001b[0Go\u001b[0Gp\u001b[0Ga\u001b[0Gb\u001b[0Gc\u001b[0G" - - var int = spinner({ - interval: 0, - string: 'abcdefghijklmnop', - stream: { - write: function(c) { - output += c - if (++written == 50) { - t.equal(output, expect) - clearInterval(int) - t.end() - } - }, - isTTY: true - }, - cleanup: false - }) -}) diff --git a/package.json b/package.json index ff11895fe..44ac49871 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,6 @@ "archy": "~1.0.0", "async-some": "~1.0.2", "block-stream": "0.0.8", - "char-spinner": "~1.0.1", "chmodr": "~0.1.1", "chownr": "0.0.2", "cmd-shim": "~2.0.1", @@ -114,7 +113,6 @@ "archy", "async-some", "block-stream", - "char-spinner", "chmodr", "chownr", "cmd-shim", |