From 4630f02f2fca67eb97df604f26567a0bf6c3ef69 Mon Sep 17 00:00:00 2001 From: Philipp Muens Date: Tue, 26 Jul 2016 11:03:31 +0200 Subject: [PATCH] Fix plugins are loaded twice bug --- lib/classes/PluginManager.js | 10 ++++++---- tests/classes/PluginManager.js | 6 ++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/classes/PluginManager.js b/lib/classes/PluginManager.js index 8bd9d73ea..714fdab33 100644 --- a/lib/classes/PluginManager.js +++ b/lib/classes/PluginManager.js @@ -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 diff --git a/tests/classes/PluginManager.js b/tests/classes/PluginManager.js index 7dc65d6f4..79bfa8008 100644 --- a/tests/classes/PluginManager.js +++ b/tests/classes/PluginManager.js @@ -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', () => {