Comparing version 0.1.1 to 0.1.2
@@ -63,6 +63,3 @@ var dirname = require('path').dirname; | ||
checkCycles(config); | ||
// Stamp it approved so we don't check it again. | ||
config.checked = true; | ||
return checkCycles(config); | ||
} | ||
@@ -76,3 +73,4 @@ | ||
provides: pluginConfig.provides.concat(), | ||
consumes: pluginConfig.consumes.concat() | ||
consumes: pluginConfig.consumes.concat(), | ||
config: pluginConfig | ||
}); | ||
@@ -85,2 +83,3 @@ }); | ||
var changed = true; | ||
var sorted = []; | ||
@@ -110,2 +109,3 @@ while(plugins.length && changed) { | ||
}); | ||
sorted.push(plugin.config); | ||
changed = true; | ||
@@ -120,2 +120,4 @@ }); | ||
} | ||
return sorted; | ||
} | ||
@@ -134,60 +136,41 @@ | ||
// Check the config if it's not already checked. | ||
if (!config.checked) { | ||
try { | ||
checkConfig(config) | ||
} catch (err) { | ||
app.emit("error", err); | ||
} | ||
// Check the config | ||
try { | ||
var sortedPlugins = checkConfig(config) | ||
} catch (err) { | ||
return app.emit("error", err); | ||
} | ||
var running; | ||
var destructors = []; | ||
(function startPlugins() { | ||
if (running) return; | ||
running = true; | ||
var pending = 0; | ||
do { | ||
var changed = false; | ||
config.forEach(function (plugin) { | ||
// Skip already-started and not-yet-ready plugins | ||
if (plugin.started) return; | ||
if (!plugin.consumes.every(function (name) { | ||
return services[name]; | ||
})) { return; } | ||
var plugin = sortedPlugins.shift(); | ||
if (!plugin) | ||
return app.emit("ready", app); | ||
pending++; | ||
var imports = {}; | ||
plugin.consumes.forEach(function (name) { | ||
imports[name] = services[name]; | ||
}); | ||
plugin.started = true; | ||
plugin.setup(plugin, imports, function (err, provided) { | ||
if (err) { return app.emit("error", err); } | ||
plugin.provides.forEach(function (name) { | ||
if (!provided.hasOwnProperty(name)) { | ||
var err = new Error("Plugin failed to provide " + name + " service. " + JSON.stringify(plugin)); | ||
return app.emit("error", err); | ||
} | ||
services[name] = provided[name]; | ||
app.emit("service", name, services[name]); | ||
changed = true; | ||
}); | ||
if (provided && provided.hasOwnProperty("onDestroy")) | ||
destructors.push(provided.onDestroy); | ||
pending--; | ||
app.emit("plugin", plugin); | ||
if (changed) { startPlugins(); } | ||
}); | ||
var imports = {}; | ||
if (plugin.consumes) { | ||
plugin.consumes.forEach(function (name) { | ||
imports[name] = services[name]; | ||
}); | ||
} while (changed); | ||
running = false; | ||
if (!pending) { | ||
app.emit("ready", app); | ||
} | ||
}()); | ||
plugin.setup(plugin, imports, function (err, provided) { | ||
if (err) { return app.emit("error", err); } | ||
plugin.provides.forEach(function (name) { | ||
if (!provided.hasOwnProperty(name)) { | ||
var err = new Error("Plugin failed to provide " + name + " service. " + JSON.stringify(plugin)); | ||
return app.emit("error", err); | ||
} | ||
services[name] = provided[name]; | ||
app.emit("service", name, services[name]); | ||
}); | ||
if (provided && provided.hasOwnProperty("onDestroy")) | ||
destructors.push(provided.onDestroy); | ||
app.emit("plugin", plugin); | ||
startPlugins(); | ||
}); | ||
})(); | ||
this.destroy = function() { | ||
@@ -194,0 +177,0 @@ destructors.forEach(function(destroy) { |
{ | ||
"name": "architect", | ||
"description": "A Simple yet powerful plugin system for node applications", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"author": "ajax.org B.V. <info@ajax.org>", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
20899
365