Skip to content
Browse files

add: only one in-flight request per component. Closes #47

  • Loading branch information...
1 parent 3bcfd9f commit f535c655f3c29e80cd1f3682f1b94191cc7df75c @tj tj committed
Showing with 13 additions and 1 deletion.
  1. +2 −1 bin/component-install
  2. +11 −0 lib/Package.js
View
3 bin/component-install
@@ -135,6 +135,7 @@ function normalize(deps) {
function report(pkg, options) {
options = options || {};
+ if (pkg.inFlight) return;
log('install', pkg.name + '@' + pkg.version);
pkg.on('error', function(err){
@@ -219,4 +220,4 @@ function loadConfig() {
function saveConfig() {
var path = resolve('component.json');
fs.writeFileSync(path, JSON.stringify(conf, null, 2));
-}
+}
View
11 lib/Package.js
@@ -18,6 +18,12 @@ var Emitter = require('events').EventEmitter
, fs = require('fs');
/**
+ * In-flight requests.
+ */
+
+var inFlight = {};
+
+/**
* Expose installer.
*/
@@ -46,11 +52,14 @@ function Package(pkg, version, options) {
if (!pkg) throw new Error('pkg required');
if (!version) throw new Error('version required');
this.name = pkg;
+ this.slug = pkg + '@' + version;
this.dest = options.dest || 'components';
this.remotes = options.remotes || ['https://raw.github.com'];
this.auth = options.auth;
this.force = !! options.force;
this.version = version;
+ this.inFlight = inFlight[this.slug];
+ inFlight[this.slug] = true;
}
/**
@@ -273,6 +282,8 @@ Package.prototype.install = function(){
return this.emit('error', new Error('invalid component name "' + name + '"'));
}
+ if (this.inFlight) return;
+
this.getLocalJSON(function(err, json){
if (err && err.code == 'ENOENT') {
self.reallyInstall();

0 comments on commit f535c65

Please sign in to comment.
Something went wrong with that request. Please try again.