From a817d5d688a187bf1c83a58afb0be0b1b84e4883 Mon Sep 17 00:00:00 2001 From: isaacs Date: Mon, 9 Jun 2014 14:53:53 -0700 Subject: Only spin the spinner when we're fetching stuff --- lib/cache.js | 10 ++++++++++ lib/npm.js | 5 +++-- 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/cache.js b/lib/cache.js index 99e85a0f9..9905ea4a7 100644 --- a/lib/cache.js +++ b/lib/cache.js @@ -207,6 +207,8 @@ cache.add = function (pkg, ver, scrub, cb) { return add([pkg, ver], cb) } + +var adding = 0 function add (args, cb) { // this is hot code. almost everything passes through here. // the args can be any of: @@ -240,6 +242,10 @@ function add (args, cb) { if (!name && !spec) return cb(usage) + if (adding <= 0) { + npm.spinner.start() + } + adding ++ cb = afterAdd([name, spec], cb) // see if the spec is a url @@ -298,6 +304,10 @@ function unpack (pkg, ver, unpackTarget, dMode, fMode, uid, gid, cb) { } function afterAdd (arg, cb) { return function (er, data) { + adding -- + if (adding <= 0) { + npm.spinner.stop() + } if (er || !data || !data.name || !data.version) { return cb(er, data) } diff --git a/lib/npm.js b/lib/npm.js index c0c744f99..f2319bfd5 100644 --- a/lib/npm.js +++ b/lib/npm.js @@ -163,13 +163,16 @@ var commandCache = {} 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) @@ -199,8 +202,6 @@ Object.keys(abbrevs).concat(plumbing).forEach(function addCommand (c) { } if (args.length === 1) args.unshift([]) - npm.spinner.start() - npm.registry.version = npm.version if (!npm.registry.refer) { npm.registry.refer = [a].concat(args[0]).map(function (arg) { -- cgit v1.2.3