mirror of
https://github.com/bower/bower.git
synced 2026-04-24 03:00:19 -04:00
Important fixes to the update command.
- 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
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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 = {};
|
||||
names = names.length ? _.uniq(names) : null;
|
||||
|
||||
_.each(manager.dependencies, function (value, name) {
|
||||
packages[name] = value[0];
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user