From 355bfa01c077b89103b02cf770ce387edc40a413 Mon Sep 17 00:00:00 2001 From: horike37 Date: Tue, 12 Dec 2017 05:05:00 +0900 Subject: [PATCH] fix the plugin commands bug --- lib/classes/PluginManager.js | 4 +++- lib/classes/PluginManager.test.js | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/classes/PluginManager.js b/lib/classes/PluginManager.js index 7cf4f75da..b2714300f 100644 --- a/lib/classes/PluginManager.js +++ b/lib/classes/PluginManager.js @@ -90,6 +90,9 @@ class PluginManager { this.addPlugin(Plugin); } catch (error) { + if (this.cliCommands[0] === 'plugin') { + return; + } let errorMessage; if (error && error.code === 'MODULE_NOT_FOUND' && error.message.endsWith(`'${plugin}'`)) { // Plugin not installed @@ -135,7 +138,6 @@ class PluginManager { if (this.serverless && this.serverless.config && this.serverless.config.servicePath) { module.paths.unshift(path.join(this.serverless.config.servicePath, '.serverless_plugins')); } - this.loadPlugins(servicePlugins); } diff --git a/lib/classes/PluginManager.test.js b/lib/classes/PluginManager.test.js index 95864844c..437a515ff 100644 --- a/lib/classes/PluginManager.test.js +++ b/lib/classes/PluginManager.test.js @@ -665,6 +665,16 @@ describe('PluginManager', () => { }); }); + it('should not throw error when running the plugin commands and given plugins does not exist', + () => { + const servicePlugins = ['ServicePluginMock3']; + const cliCommandsMock = ['plugin']; + pluginManager.setCliCommands(cliCommandsMock); + + expect(() => pluginManager.loadPlugins(servicePlugins)) + .to.not.throw(serverless.classes.Error); + }); + afterEach(() => { mockRequire.stop('ServicePluginMock1'); });