fix the plugin commands bug

This commit is contained in:
horike37 2017-12-12 05:05:00 +09:00
parent 1fb90f6dc1
commit 355bfa01c0
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');
});