fix(Plugins): Fix resolution of config when installing plugin

Fixes #7130
This commit is contained in:
Mariusz Nowak 2019-12-23 16:23:26 +01:00 committed by Mariusz Nowak
parent e662a91d92
commit b5dbdafe5b
4 changed files with 8 additions and 25 deletions

View File

@ -49,6 +49,7 @@ describe('PluginInstall', () => {
beforeEach(() => {
serverless = new Serverless();
serverless.cli = new CLI(serverless);
serverless.processedInput = serverless.cli.processInput();
const options = {};
pluginInstall = new PluginInstall(serverless, options);
consoleLogStub = sinon.stub(serverless.cli, 'consoleLog').returns();

View File

@ -4,10 +4,9 @@ const fetch = require('node-fetch');
const BbPromise = require('bluebird');
const HttpsProxyAgent = require('https-proxy-agent');
const url = require('url');
const path = require('path');
const chalk = require('chalk');
const _ = require('lodash');
const fileExists = require('../../../utils/fs/fileExists');
const { getServerlessConfigFilePath } = require('../../../utils/getServerlessConfigFile');
module.exports = {
validate() {
@ -21,29 +20,10 @@ module.exports = {
},
getServerlessFilePath() {
const servicePath = this.serverless.config.servicePath;
const ymlFilePath = path.join(servicePath, 'serverless.yml');
const yamlFilePath = path.join(servicePath, 'serverless.yaml');
const jsonFilePath = path.join(servicePath, 'serverless.json');
const jsFilePath = path.join(servicePath, 'serverless.js');
return BbPromise.props({
json: fileExists(jsonFilePath),
yml: fileExists(ymlFilePath),
yaml: fileExists(yamlFilePath),
js: fileExists(jsFilePath),
}).then(exists => {
if (exists.yml) {
return ymlFilePath;
} else if (exists.yaml) {
return yamlFilePath;
} else if (exists.json) {
return jsonFilePath;
} else if (exists.js) {
return jsFilePath;
}
return BbPromise.reject(
new this.serverless.classes.Error('Could not find any serverless service definition file.')
return getServerlessConfigFilePath(this.serverless).then(filePath => {
if (filePath) return filePath;
throw new this.serverless.classes.Error(
'Could not find any serverless service definition file.'
);
});
},

View File

@ -40,6 +40,7 @@ describe('PluginUtils', () => {
beforeEach(() => {
serverless = new Serverless();
serverless.cli = new CLI(serverless);
serverless.processedInput = serverless.cli.processInput();
const options = {};
pluginUtils = new PluginInstall(serverless, options);
consoleLogStub = sinon.stub(serverless.cli, 'consoleLog').returns();

View File

@ -43,6 +43,7 @@ describe('PluginUninstall', () => {
beforeEach(() => {
serverless = new Serverless();
serverless.cli = new CLI(serverless);
serverless.processedInput = serverless.cli.processInput();
const options = {};
pluginUninstall = new PluginUninstall(serverless, options);
consoleLogStub = sinon.stub(serverless.cli, 'consoleLog').returns();