Skip to content

Commit

Permalink
Fetch versions only if necessary and if the offline option is not pas…
Browse files Browse the repository at this point in the history
…sed.
  • Loading branch information
satazor committed Dec 14, 2012
1 parent f9c1e81 commit 3dec991
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions lib/commands/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ var Package = require('../core/package');
var config = require('../core/config');
var help = require('./help');

var shorthand = { 'h': ['--help'] };
var optionTypes = { help: Boolean, paths: Boolean, map: Boolean };
var shorthand = { 'h': ['--help'], 'o': ['--offline'] };
var optionTypes = { help: Boolean, paths: Boolean, map: Boolean, offline: Boolean };

var getTree = function (packages, subPackages, result) {
result = result || {};
Expand Down Expand Up @@ -134,13 +134,21 @@ var cliTree = function (emitter, packages, tree) {
module.exports = function (options) {
var manager = new Manager;
var emitter = new Emitter;
var checkVersions = false;

options = options || {};

manager
.on('data', emitter.emit.bind(emitter, 'data'))
.on('error', emitter.emit.bind(emitter, 'error'));

// If the user passed the paths or map options, we don't need to fetch versions
if (!options.offline && !options.paths && !options.map && options.argv) {
template('action', { name: 'discover', shizzle: 'Please wait while newer package versions are being discovered' })
.on('data', emitter.emit.bind(emitter, 'data'));
checkVersions = true;
}

manager.once('resolveLocal', function () {
var packages = {};

Expand All @@ -150,7 +158,12 @@ module.exports = function (options) {

async.forEach(_.values(packages), function (pkg, next) {
pkg.once('loadJSON', function () {
if (this.json.repository && (this.json.repository.type === 'git' || this.json.repository.type === 'local-repo')) {
// Only check versions if not offline and it's a repo
var fetchVersions = checkVersions &&
this.json.repository &&
(this.json.repository.type === 'git' || this.json.repository.type === 'local-repo');

if (fetchVersions) {
pkg.once('versions', function (versions) {
pkg.tags = versions.map(function (ver) {
return semver.valid(ver) ? semver.clean(ver) : ver;
Expand Down

0 comments on commit 3dec991

Please sign in to comment.