Skip to content

Commit

Permalink
Important fixes to the update command.
Browse files Browse the repository at this point in the history
- Update command now correctly process passed packages
- Fix packages in which the name couldn't be correctly extracted from the remote URL
- Add --force flag, just like the install command
  • Loading branch information
satazor committed Oct 24, 2012
1 parent d4329c3 commit 8dc17f6
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -56,7 +56,7 @@ To clean the cache:

Several packages can be cleaned at the same time.
To clean the entire cache, just call `bower cache-clean` without any names.
Also, the install command has a `--force` flag that tells bower to bypass the cache and always fetch remote sources.
Also, both the install and update commands have a `--force` flag that tells bower to bypass the cache and always fetch remote sources.

You can disable colors by using the `--no-color` flag.

Expand Down
2 changes: 1 addition & 1 deletion lib/commands/cache-clean.js
Expand Up @@ -26,7 +26,7 @@ var removePkg = function (pkg, emitter, next) {
var folder = path.join(config.cache, pkg);

fs.exists(folder, function (exists) {
if (!exists) return emitter.emit('error', new Error(pkg + ' is not cached'));
if (!exists) return emitter.emit('error', new Error('Unable to process ' + pkg + ' (does it exists?)'));

rimraf(folder, function (err) {
if (err) emitter.emit('error', err);
Expand Down
45 changes: 29 additions & 16 deletions lib/commands/update.js
Expand Up @@ -15,34 +15,47 @@ var Manager = require('../core/manager');
var install = require('./install');
var help = require('./help');

var shorthand = { 'h': ['--help'] };
var optionTypes = { help: Boolean };
var shorthand = { 'h': ['--help'], 'f': ['--force'] };
var optionTypes = { help: Boolean, force: Boolean };

module.exports = function (argv, options) {
var manager = new Manager;
module.exports = function (names, options) {
var manager = new Manager([], { force: options.force });
var emitter = new Emitter;

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

var installURLS = function (err, urls) {
var installEmitter = install(urls, options);
installEmitter.on('data', emitter.emit.bind(emitter, 'data'));
installEmitter.on('error', emitter.emit.bind(emitter, 'error'));
installEmitter.on('end', emitter.emit.bind(emitter, 'end'));
var installURLS = function (err, arr) {
var mappings = {},
urls = [];

_.each(arr, function (info) {
urls.push(info.url);
mappings[info.url] = info.name;
});

options.endpointNames = mappings;

// By default the manager will guess the name of the package from the url
// But this leads to problems when the package name does not match the one in the url
// So the manager now has an option (endpointNames) to deal with this
manager = new Manager(urls, options);
manager.on('data', emitter.emit.bind(emitter, 'data'));
manager.on('error', emitter.emit.bind(emitter, 'error'));
manager.on('install', emitter.emit.bind(emitter, 'end'));
manager.resolve();
};

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

_.each(manager.dependencies, function (value, name) {
packages[name] = value[0];
});
names = names.length ? _.uniq(names) : null;

var urls = async.map(_.values(packages), function (pkg, next) {
async.map(_.values(manager.dependencies), function (pkgs, next) {
var pkg = pkgs[0];
pkg.once('loadJSON', function () {
pkg.once('fetchURL', function (url) {
next(null, url + (pkg.json.commit && pkg.json.version === '0.0.0' ? '' : '#~' + pkg.version));
if (pkg.json.commit && pkg.json.version === '0.0.0') url += '';
else url += '#' + ((!names || names.indexOf(pkg.name) > -1) ? '~' : '') + pkg.version;
next(null, { url: url, name: pkg.name });
}).fetchURL();
}).loadJSON();
}, installURLS);
Expand Down
4 changes: 3 additions & 1 deletion lib/core/manager.js
Expand Up @@ -76,8 +76,10 @@ Manager.prototype.resolveEndpoints = function () {
// Add to depedencies array
// Prune & install

var endpointNames = this.opts.endpointNames || {};

async.forEach(this.endpoints, function (endpoint, next) {
var name = path.basename(endpoint).replace(/(\.git)?(#.*)?$/, '');
var name = endpointNames[endpoint] || path.basename(endpoint).replace(/(\.git)?(#.*)?$/, '');
var pkg = new Package(name, endpoint, this);
this.dependencies[name] = this.dependencies[name] || [];
this.dependencies[name].push(pkg);
Expand Down

0 comments on commit 8dc17f6

Please sign in to comment.