fix: Fix support for relative plugins.localPath

Fixes #7117
This commit is contained in:
Mariusz Nowak 2019-12-19 22:27:34 +01:00
parent 1b2439aabe
commit 617b479fb7
No known key found for this signature in database
GPG Key ID: B1FBDA8A182B03F2
2 changed files with 18 additions and 1 deletions

View File

@ -15,7 +15,8 @@ const getCommandSuggestion = require('../utils/getCommandSuggestion');
const requireServicePlugin = (servicePath, pluginPath, localPluginsPath) => {
if (localPluginsPath && !pluginPath.startsWith('./')) {
// TODO (BREAKING): Consider removing support for localPluginsPath with next major
const absoluteLocalPluginPath = path.join(localPluginsPath, pluginPath);
const absoluteLocalPluginPath = path.resolve(localPluginsPath, pluginPath);
try {
return require(absoluteLocalPluginPath);
} catch (error) {

View File

@ -2014,6 +2014,22 @@ describe('PluginManager', () => {
);
});
it('should load plugins from custom folder outside of serviceDir', () => {
serviceDir = path.join(tmpDir, 'serverless-plugins-custom');
const localPluginDir = path.join(serviceDir, 'local-plugin');
installPlugin(localPluginDir, SynchronousPluginMock);
pluginManager.loadAllPlugins({
localPath: '../serverless-plugins-custom',
modules: ['local-plugin'],
});
// Had to use contructor.name because the class will be loaded via
// require and the reference will not match with SynchronousPluginMock
expect(pluginManager.plugins).to.satisfy(plugins =>
plugins.some(plugin => plugin.constructor.name === 'SynchronousPluginMock')
);
});
afterEach(() => {
// eslint-disable-line prefer-arrow-callback
process.chdir(cwd);