From 5896f0c43bd7f48cf736e36dfc48108064904a8a Mon Sep 17 00:00:00 2001 From: "Eslam A. Hefnawy" Date: Tue, 5 Feb 2019 15:05:31 +0300 Subject: [PATCH] fix race condition when loading config file --- lib/Serverless.js | 35 +++++++++++++++++------------------ lib/classes/PluginManager.js | 8 +++++--- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/lib/Serverless.js b/lib/Serverless.js index 20cd886f3..a547d1001 100644 --- a/lib/Serverless.js +++ b/lib/Serverless.js @@ -55,27 +55,26 @@ class Serverless { // get an array of commands and options that should be processed this.processedInput = this.cli.processInput(); - // make the serverless config file available to the PluginManager - this.pluginManager.loadConfigFile(); + // load config file + return this.pluginManager.loadConfigFile().then(() => { + // set the options and commands which were processed by the CLI + this.pluginManager.setCliOptions(this.processedInput.options); + this.pluginManager.setCliCommands(this.processedInput.commands); - // set the options and commands which were processed by the CLI - this.pluginManager.setCliOptions(this.processedInput.options); - this.pluginManager.setCliCommands(this.processedInput.commands); + // Check if update is available + updateNotifier({ pkg }).notify(); - // Check if update is available - updateNotifier({ pkg }).notify(); + return this.service.load(this.processedInput.options); + }).then(() => { + // load all plugins + this.pluginManager.loadAllPlugins(this.service.plugins); - return this.service.load(this.processedInput.options) - .then(() => { - // load all plugins - this.pluginManager.loadAllPlugins(this.service.plugins); - - // give the CLI the plugins and commands so that it can print out - // information such as options when the user enters --help - this.cli.setLoadedPlugins(this.pluginManager.getPlugins()); - this.cli.setLoadedCommands(this.pluginManager.getCommands()); - return this.pluginManager.updateAutocompleteCacheFile(); - }); + // give the CLI the plugins and commands so that it can print out + // information such as options when the user enters --help + this.cli.setLoadedPlugins(this.pluginManager.getPlugins()); + this.cli.setLoadedCommands(this.pluginManager.getCommands()); + return this.pluginManager.updateAutocompleteCacheFile(); + }); } run() { diff --git a/lib/classes/PluginManager.js b/lib/classes/PluginManager.js index a93c8d28a..561b2a02e 100644 --- a/lib/classes/PluginManager.js +++ b/lib/classes/PluginManager.js @@ -42,9 +42,11 @@ class PluginManager { } loadConfigFile() { - getServerlessConfigFile(this.serverless.config.servicePath).then((serverlessConfigFile) => { - this.serverlessConfigFile = serverlessConfigFile; - }); + return getServerlessConfigFile(this.serverless.config.servicePath) + .then((serverlessConfigFile) => { + this.serverlessConfigFile = serverlessConfigFile; + return; + }); } setCliOptions(options) {