Skip to content

Commit

Permalink
refactor: Refactor to async/await
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Sep 3, 2020
1 parent 10d5f2c commit 651b375
Showing 1 changed file with 27 additions and 25 deletions.
52 changes: 27 additions & 25 deletions lib/Serverless.js
Expand Up @@ -116,7 +116,7 @@ class Serverless {
});
});
}
eventuallyFallbackToLocal() {
async eventuallyFallbackToLocal() {
if (
this.pluginManager.serverlessConfigFile &&
this.pluginManager.serverlessConfigFile.enableLocalInstallationFallback != null
Expand All @@ -128,32 +128,34 @@ class Serverless {
'Remove this setting to clear this deprecation warning'
);
}
return resolve(process.cwd(), 'serverless').then(
({ realPath }) => {
if (realPath === __filename) {
this.isLocallyInstalled = true;
return null;
}
if (
this.pluginManager.serverlessConfigFile &&
this.pluginManager.serverlessConfigFile.enableLocalInstallationFallback != null &&
!this.pluginManager.serverlessConfigFile.enableLocalInstallationFallback
) {
return null;
}
this.cli.log('Running "serverless" installed locally (in service node_modules)');
// TODO: Replace below fallback logic with more straightforward one at top of the CLI
// when we willl drop support for the "disableLocalInstallationFallback" setting
this.isOverridenByLocal = true;
const ServerlessLocal = require(realPath);
const serverlessLocal = new ServerlessLocal();
this.invokedInstance = serverlessLocal;
return serverlessLocal.init();
},
error => {
const localServerlessPath = await (async () => {
try {
return (await resolve(process.cwd(), 'serverless')).realPath;
} catch (error) {
if (!isModuleNotFoundError(error, 'serverless')) throw error;
return null;
}
);
})();
if (!localServerlessPath) return;
if (localServerlessPath === __filename) {
this.isLocallyInstalled = true;
return;
}
if (
this.pluginManager.serverlessConfigFile &&
this.pluginManager.serverlessConfigFile.enableLocalInstallationFallback != null &&
!this.pluginManager.serverlessConfigFile.enableLocalInstallationFallback
) {
return;
}
this.cli.log('Running "serverless" installed locally (in service node_modules)');
// TODO: Replace below fallback logic with more straightforward one at top of the CLI
// when we willl drop support for the "disableLocalInstallationFallback" setting
this.isOverridenByLocal = true;
const ServerlessLocal = require(localServerlessPath);
const serverlessLocal = new ServerlessLocal();
this.invokedInstance = serverlessLocal;
await serverlessLocal.init();
}

run() {
Expand Down

0 comments on commit 651b375

Please sign in to comment.