Skip to content

Commit d204f76

Browse files
committed
Fix some more errors with duplicate callbacks being called, bower#274.
1 parent 64bfbb0 commit d204f76

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

lib/core/manager.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,12 @@ Manager.prototype.resolveEndpoints = function () {
132132
this.dependencies[name] = this.dependencies[name] || [];
133133
this.dependencies[name].push(pkg);
134134

135-
pkg.once('resolve', next).resolve();
136-
this.gatherPackageErrors(pkg, next);
135+
this.gatherPackageErrors(pkg);
136+
pkg.once('error', next);
137+
pkg.once('resolve', function () {
138+
pkg.removeListener('error', next);
139+
next();
140+
}).resolve();
137141
}.bind(this), this.emit.bind(this, 'resolveEndpoints'));
138142

139143
return this;
@@ -156,8 +160,12 @@ Manager.prototype.resolveFromJson = function () {
156160
this.dependencies[name] = this.dependencies[name] || [];
157161
this.dependencies[name].push(pkg);
158162

159-
pkg.once('resolve', next).resolve();
160-
this.gatherPackageErrors(pkg, next);
163+
this.gatherPackageErrors(pkg);
164+
pkg.once('error', next);
165+
pkg.once('resolve', function () {
166+
pkg.removeListener('error', next);
167+
next();
168+
}).resolve();
161169
}.bind(this), this.emit.bind(this, 'resolveFromJson'));
162170
}.bind(this)).loadJSON();
163171

@@ -212,9 +220,7 @@ Manager.prototype.prune = function () {
212220
return true;
213221
};
214222

215-
Manager.prototype.gatherPackageErrors = function (pkg, next) {
216-
var calledNext = false;
217-
223+
Manager.prototype.gatherPackageErrors = function (pkg) {
218224
// Listen to all the errors
219225
// The first error will call the next callback and we continue to gather more until the end
220226
// This makes sense because a package forwards its deep dependencies errors
@@ -227,10 +233,6 @@ Manager.prototype.gatherPackageErrors = function (pkg, next) {
227233
}
228234

229235
this.errors.push({ pkg: pkg, error: err });
230-
if (next && !calledNext) {
231-
calledNext = true;
232-
next();
233-
}
234236
}.bind(this));
235237
};
236238

0 commit comments

Comments
 (0)