Merge pull request #4559 from serverless/fix-plugin-search-bug

Fix the plugin commands fail if listed plugins does not exist
This commit is contained in:
Takahiro Horike 2017-12-12 11:43:19 +09:00 committed by GitHub
commit ce10e2c2c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -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);
}

View File

@ -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');
});