Skip to content

Commit

Permalink
fix race condition when loading config file
Browse files Browse the repository at this point in the history
  • Loading branch information
eahefnawy committed Feb 5, 2019
1 parent 04a2a65 commit 5896f0c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 24 deletions.
41 changes: 20 additions & 21 deletions lib/Serverless.js
Expand Up @@ -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();

// 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();

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();
});
// 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);

// 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);

// 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() {
Expand Down
8 changes: 5 additions & 3 deletions lib/classes/PluginManager.js
Expand Up @@ -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) {
Expand Down

0 comments on commit 5896f0c

Please sign in to comment.