Fix plugins are loaded twice bug

This commit is contained in:
Philipp Muens 2016-07-26 11:03:31 +02:00
parent 11fcea1331
commit 4630f02f2f
2 changed files with 10 additions and 6 deletions

View File

@ -129,13 +129,15 @@ class PluginManager {
}
addPlugin(Plugin) {
this.loadCommands(Plugin);
const pluginInstance = new Plugin(this.serverless, this.cliOptions);
this.loadCommands(pluginInstance);
// shortcuts should be converted into options so that the plugin
// author can use the option (instead of the shortcut)
this.convertShortcutsIntoOptions(this.cliOptions, this.commands);
this.plugins.push(new Plugin(this.serverless, this.cliOptions));
this.plugins.push(pluginInstance);
}
loadCorePlugins() {
@ -172,8 +174,8 @@ class PluginManager {
}
}
loadCommands(Plugin) {
this.commandsList.push((new Plugin(this.serverless)).commands);
loadCommands(pluginInstance) {
this.commandsList.push(pluginInstance.commands);
// TODO: refactor ASAP as it slows down overall performance
// rebuild the commands

View File

@ -410,7 +410,8 @@ describe('PluginManager', () => {
describe('#loadCommands()', () => {
it('should load the plugin commands', () => {
pluginManager.loadCommands(SynchronousPluginMock);
const synchronousPluginMockInstance = new SynchronousPluginMock();
pluginManager.loadCommands(synchronousPluginMockInstance);
expect(pluginManager.commandsList[0]).to.have.property('deploy');
});
@ -418,7 +419,8 @@ describe('PluginManager', () => {
describe('#getEvents()', () => {
beforeEach(() => {
pluginManager.loadCommands(SynchronousPluginMock);
const synchronousPluginMockInstance = new SynchronousPluginMock();
pluginManager.loadCommands(synchronousPluginMockInstance);
});
it('should get all the matching events for a root level command in the correct order', () => {