Skip to content

Commit

Permalink
fixed various Matter.Plugin issues
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Nov 3, 2016
1 parent 0e5a457 commit 05d0961
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/core/Plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@ var Common = require('./Common');
}

if (plugin.name in Plugin._registry) {
var registered = Plugin._registry[plugin.name];
var registered = Plugin._registry[plugin.name],
pluginVersion = Plugin.versionParse(plugin.version).number,
registeredVersion = Plugin.versionParse(registered.version).number;

if (Plugin.versionParse(plugin.version).number >= Plugin.versionParse(registered.version).number) {
if (pluginVersion > registeredVersion) {
Common.warn('Plugin.register:', Plugin.toString(registered), 'was upgraded to', Plugin.toString(plugin));
Plugin._registry[plugin.name] = plugin;
} else {
} else if (pluginVersion < registeredVersion) {
Common.warn('Plugin.register:', Plugin.toString(registered), 'can not be downgraded to', Plugin.toString(plugin));
} else if (plugin !== registered) {
Common.warn('Plugin.register:', Plugin.toString(plugin), 'is already registered to different plugin object');
}
} else {
Plugin._registry[plugin.name] = plugin;
Expand All @@ -59,7 +63,7 @@ var Common = require('./Common');
* @return {string} Pretty printed plugin name and version.
*/
Plugin.toString = function(plugin) {
return (plugin.name || 'anonymous') + '@' + (plugin.version || plugin.range || '0.0.0');
return typeof plugin === 'string' ? plugin : (plugin.name || 'anonymous') + '@' + (plugin.version || plugin.range || '0.0.0');
};

/**
Expand Down Expand Up @@ -191,6 +195,10 @@ var Common = require('./Common');
module = Plugin.resolve(module) || module;

tracked[name] = Common.map(module.uses || [], function(dependency) {
if (Plugin.isPlugin(dependency)) {
Plugin.register(dependency);
}

var parsed = Plugin.dependencyParse(dependency),
resolved = Plugin.resolve(dependency);

Expand All @@ -204,7 +212,7 @@ var Common = require('./Common');
module._warned = true;
} else if (!resolved) {
Common.warn(
'Plugin.dependencies:', dependency, 'used by',
'Plugin.dependencies:', Plugin.toString(dependency), 'used by',
Plugin.toString(parsedBase), 'could not be resolved.'
);

Expand Down

0 comments on commit 05d0961

Please sign in to comment.