Catch errors also while installing, fix mute deps.

This commit is contained in:
André Cruz
2012-11-21 22:42:59 +00:00
parent 8bfa518f15
commit a7612a8828

View File

@@ -95,8 +95,12 @@ Manager.prototype.resolveLocal = function () {
if (err) return this.emit('error', err);
dirs.forEach(function (dir) {
var name = path.basename(dir);
var pkg = new Package(name, dir, this);
this.dependencies[name] = [];
this.dependencies[name].push(new Package(name, dir, this));
this.dependencies[name].push(pkg);
pkg.on('error', function (err, origin) {
this.errors.push({ pkg: origin, error: err });
}.bind(this));
}.bind(this));
this.emit('resolveLocal');
}.bind(this));
@@ -116,11 +120,11 @@ Manager.prototype.resolveEndpoints = function () {
var pkg = new Package(name, endpoint, this);
this.dependencies[name] = this.dependencies[name] || [];
this.dependencies[name].push(pkg);
pkg.once('resolve', next).resolve();
pkg.once('error', function (err) {
this.errors.push({ pkg: pkg, error: err });
pkg.on('error', function (err, origin) {
this.errors.push({ pkg: origin, error: err });
next();
}.bind(this));
pkg.once('resolve', next).resolve();
}.bind(this), this.emit.bind(this, 'resolveEndpoints'));
return this;
@@ -140,11 +144,11 @@ Manager.prototype.resolveFromJson = function () {
var pkg = new Package(name, endpoint, this);
this.dependencies[name] = this.dependencies[name] || [];
this.dependencies[name].push(pkg);
pkg.once('resolve', next).resolve();
pkg.once('error', function (err) {
this.errors.push({ pkg: pkg, error: err });
pkg.on('error', function (err, origin) {
this.errors.push({ pkg: origin, error: err });
next();
}.bind(this));
pkg.once('resolve', next).resolve();
}.bind(this), this.emit.bind(this, 'resolveFromJson'));
}.bind(this)).loadJSON();
@@ -182,14 +186,20 @@ Manager.prototype.prune = function () {
Manager.prototype.install = function () {
async.forEach(Object.keys(this.dependencies), function (name, next) {
this.dependencies[name][0].once('install', next).install();
}.bind(this), this.emit.bind(this, 'install'));
var pkg = this.dependencies[name][0];
pkg.once('install', next).install();
pkg.once('error', next);
}.bind(this), function () {
if (this.errors.length) this.reportErrors();
return this.emit.bind(this, 'install');
}.bind(this));
};
Manager.prototype.muteDependencies = function () {
for (var name in this.dependencies) {
this.dependencies[name].forEach(function (pkg) {
pkg.removeAllListeners();
pkg.on('error', function () {});
});
}
};