refactor: Remove BbPromise.bind usage (#11875)

This commit is contained in:
Duy Tran 2023-03-31 22:32:37 +08:00 committed by GitHub
parent 0d850fcca7
commit 30dd50a90c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 68 additions and 82 deletions

View File

@ -9,7 +9,7 @@ class AwsCompileActiveMQEvents {
this.provider = this.serverless.getProvider('aws');
this.hooks = {
'package:compileEvents': this.compileActiveMQEvents.bind(this),
'package:compileEvents': async () => this.compileActiveMQEvents(),
};
this.serverless.configSchemaHandler.defineFunctionEvent('aws', 'activemq', {

View File

@ -37,7 +37,7 @@ class AwsCompileAlexaSkillEvents {
);
}
},
'package:compileEvents': this.compileAlexaSkillEvents.bind(this),
'package:compileEvents': async () => this.compileAlexaSkillEvents(),
};
}

View File

@ -9,7 +9,7 @@ class AwsCompileAlexaSmartHomeEvents {
this.provider = this.serverless.getProvider('aws');
this.hooks = {
'package:compileEvents': this.compileAlexaSmartHomeEvents.bind(this),
'package:compileEvents': async () => this.compileAlexaSmartHomeEvents(),
};
this.serverless.configSchemaHandler.defineFunctionEvent('aws', 'alexaSmartHome', {

View File

@ -211,13 +211,13 @@ class AwsCompileCloudFrontEvents {
});
this.hooks = {
'package:initialize': this.validate.bind(this),
'before:package:compileFunctions': this.prepareFunctions.bind(this),
'package:initialize': async () => this.validate(),
'before:package:compileFunctions': async () => this.prepareFunctions(),
'package:compileEvents': () => {
this.compileCloudFrontCachePolicies();
this.compileCloudFrontEvents();
},
'before:remove:remove': this.logRemoveReminder.bind(this),
'before:remove:remove': async () => this.logRemoveReminder(),
};
}

View File

@ -10,7 +10,7 @@ class AwsCompileCloudWatchEventEvents {
this.provider = this.serverless.getProvider('aws');
this.hooks = {
'package:compileEvents': this.compileCloudWatchEventEvents.bind(this),
'package:compileEvents': async () => this.compileCloudWatchEventEvents(),
};
this.serverless.configSchemaHandler.defineFunctionEvent('aws', 'cloudwatchEvent', {

View File

@ -10,7 +10,7 @@ class AwsCompileCloudWatchLogEvents {
this.provider = this.serverless.getProvider('aws');
this.hooks = {
'package:compileEvents': this.compileCloudWatchLogEvents.bind(this),
'package:compileEvents': async () => this.compileCloudWatchLogEvents(),
};
this.serverless.configSchemaHandler.defineFunctionEvent('aws', 'cloudwatchLog', {

View File

@ -34,7 +34,7 @@ class AwsCompileCognitoUserPoolEvents {
.then(this.newCognitoUserPools)
.then(this.existingCognitoUserPools);
},
'after:package:finalize': this.mergeWithCustomResources.bind(this),
'after:package:finalize': async () => this.mergeWithCustomResources(),
};
this.serverless.configSchemaHandler.defineFunctionEvent('aws', 'cognitoUserPool', {

View File

@ -48,7 +48,7 @@ class AwsCompileEventBridgeEvents {
);
}
},
'package:compileEvents': this.compileEventBridgeEvents.bind(this),
'package:compileEvents': async () => this.compileEventBridgeEvents(),
};
this.serverless.configSchemaHandler.defineFunctionEvent('aws', 'eventBridge', {

View File

@ -10,7 +10,7 @@ class AwsCompileIotFleetProvisioningEvents {
this.provider = this.serverless.getProvider('aws');
this.hooks = {
'package:compileEvents': this.compileIotFleetProvisioningEvents.bind(this),
'package:compileEvents': async () => this.compileIotFleetProvisioningEvents(),
};
this.serverless.configSchemaHandler.defineFunctionEvent('aws', 'iotFleetProvisioning', {

View File

@ -9,7 +9,7 @@ class AwsCompileIoTEvents {
this.provider = this.serverless.getProvider('aws');
this.hooks = {
'package:compileEvents': this.compileIoTEvents.bind(this),
'package:compileEvents': async () => this.compileIoTEvents(),
};
this.serverless.configSchemaHandler.defineFunctionEvent('aws', 'iot', {

View File

@ -10,7 +10,7 @@ class AwsCompileKafkaEvents {
this.provider = this.serverless.getProvider('aws');
this.hooks = {
'package:compileEvents': this.compileKafkaEvents.bind(this),
'package:compileEvents': async () => this.compileKafkaEvents(),
};
this.serverless.configSchemaHandler.defineFunctionEvent('aws', 'kafka', {

View File

@ -10,7 +10,7 @@ class AwsCompileMSKEvents {
this.provider = this.serverless.getProvider('aws');
this.hooks = {
'package:compileEvents': this.compileMSKEvents.bind(this),
'package:compileEvents': async () => this.compileMSKEvents(),
};
this.serverless.configSchemaHandler.defineFunctionEvent('aws', 'msk', {

View File

@ -9,7 +9,7 @@ class AwsCompileRabbitMQEvents {
this.provider = this.serverless.getProvider('aws');
this.hooks = {
'package:compileEvents': this.compileRabbitMQEvents.bind(this),
'package:compileEvents': async () => this.compileRabbitMQEvents(),
};
this.serverless.configSchemaHandler.defineFunctionEvent('aws', 'rabbitmq', {

View File

@ -14,7 +14,7 @@ class AwsCompileScheduledEvents {
this.provider = this.serverless.getProvider('aws');
this.hooks = {
'package:compileEvents': this.compileScheduledEvents.bind(this),
'package:compileEvents': async () => this.compileScheduledEvents(),
};
this.serverless.configSchemaHandler.defineFunctionEvent('aws', 'schedule', {

View File

@ -10,7 +10,7 @@ class AwsCompileSNSEvents {
this.provider = this.serverless.getProvider('aws');
this.options = options;
this.hooks = {
'package:compileEvents': this.compileSNSEvents.bind(this),
'package:compileEvents': async () => this.compileSNSEvents(),
};
this.serverless.configSchemaHandler.defineFunctionEvent('aws', 'sns', {

View File

@ -9,7 +9,7 @@ class AwsCompileSQSEvents {
this.provider = this.serverless.getProvider('aws');
this.hooks = {
'package:compileEvents': this.compileSQSEvents.bind(this),
'package:compileEvents': async () => this.compileSQSEvents(),
};
this.serverless.configSchemaHandler.defineFunctionEvent('aws', 'sqs', {

View File

@ -10,7 +10,7 @@ class AwsCompileStreamEvents {
this.provider = this.serverless.getProvider('aws');
this.hooks = {
'package:compileEvents': this.compileStreamEvents.bind(this),
'package:compileEvents': async () => this.compileStreamEvents(),
};
this.serverless.configSchemaHandler.defineFunctionEvent('aws', 'stream', {

View File

@ -19,7 +19,7 @@ class AwsCompileLayers {
this.provider = this.serverless.getProvider('aws');
this.hooks = {
'package:compileLayers': async () => BbPromise.bind(this).then(this.compileLayers),
'package:compileLayers': async () => this.compileLayers(),
};
}

View File

@ -1,7 +1,5 @@
'use strict';
const BbPromise = require('bluebird');
module.exports = {
async remove() {
const stackName = this.provider.naming.getStackName();
@ -22,6 +20,6 @@ module.exports = {
},
async removeStack() {
return BbPromise.bind(this).then(this.remove);
return this.remove();
},
};

View File

@ -28,7 +28,7 @@ class Create {
};
this.hooks = {
'create:create': async () => BbPromise.bind(this).then(this.create),
'create:create': async () => this.create(),
};
}

View File

@ -1,7 +1,5 @@
'use strict';
const BbPromise = require('bluebird');
const cliCommandsSchema = require('../cli/commands-schema');
const download = require('../utils/download-template-from-repo');
const { log, progress, style } = require('@serverless/utils/log');
@ -18,7 +16,7 @@ class Install {
};
this.hooks = {
'install:install': async () => BbPromise.bind(this).then(this.install),
'install:install': async () => this.install(),
};
}

View File

@ -1,6 +1,5 @@
'use strict';
const BbPromise = require('bluebird');
const _ = require('lodash');
const cliCommandsSchema = require('../cli/commands-schema');
@ -24,9 +23,9 @@ class Invoke {
'initialize': () => {
this.options = this.serverless.processedInput.options;
},
'invoke:local:loadEnvVars': async () => BbPromise.bind(this).then(this.loadEnvVarsForLocal),
'after:invoke:invoke': async () => BbPromise.bind(this).then(this.trackInvoke),
'after:invoke:local:invoke': async () => BbPromise.bind(this).then(this.trackInvokeLocal),
'invoke:local:loadEnvVars': async () => this.loadEnvVarsForLocal(),
'after:invoke:invoke': async () => this.trackInvoke(),
'after:invoke:local:invoke': async () => this.trackInvokeLocal(),
};
}

View File

@ -53,8 +53,7 @@ class Package {
);
}
},
'package:createDeploymentArtifacts': async () =>
BbPromise.bind(this).then(this.packageService),
'package:createDeploymentArtifacts': async () => this.packageService(),
'package:function:package': async () => {
if (this.options.function) {

View File

@ -1,6 +1,5 @@
'use strict';
const BbPromise = require('bluebird');
const cliCommandsSchema = require('../../cli/commands-schema');
const pluginUtils = require('./lib/utils');
@ -22,14 +21,13 @@ class PluginList {
};
this.hooks = {
'plugin:list:list': async () => BbPromise.bind(this).then(this.list),
'plugin:list:list': async () => this.list(),
};
}
async list() {
return BbPromise.bind(this)
.then(this.getPlugins)
.then((plugins) => this.display(plugins));
const plugins = await this.getPlugins();
await this.display(plugins);
}
}

View File

@ -1,6 +1,5 @@
'use strict';
const BbPromise = require('bluebird');
const { log } = require('@serverless/utils/log');
const cliCommandsSchema = require('../../cli/commands-schema');
const pluginUtils = require('./lib/utils');
@ -23,32 +22,27 @@ class PluginSearch {
};
this.hooks = {
'plugin:search:search': async () => BbPromise.bind(this).then(this.search),
'plugin:search:search': async () => this.search(),
};
}
async search() {
return BbPromise.bind(this)
.then(this.getPlugins)
.then((plugins) => {
// filter out plugins which match the query
const regex = new RegExp(this.options.query);
const plugins = await this.getPlugins();
const filteredPlugins = plugins.filter(
(plugin) => plugin.name.match(regex) || plugin.description.match(regex)
);
// filter out plugins which match the query
const regex = new RegExp(this.options.query);
// print a message with the search result
const pluginCount = filteredPlugins.length;
const query = this.options.query;
log.notice(`${pluginCount} plugin(s) found matching "${query}":`);
log.notice();
const filteredPlugins = plugins.filter(
(plugin) => plugin.name.match(regex) || plugin.description.match(regex)
);
return filteredPlugins;
})
.then((plugins) => {
this.display(plugins);
});
// print a message with the search result
const pluginCount = filteredPlugins.length;
const query = this.options.query;
log.notice(`${pluginCount} plugin(s) found matching "${query}":`);
log.notice();
await this.display(filteredPlugins);
}
}

View File

@ -15,7 +15,7 @@ class PackageArtifactPlugin {
constructor(serverless) {
this.serverless = serverless;
this.hooks = {
'before:package:createDeploymentArtifacts': this.package.bind(this),
'before:package:createDeploymentArtifacts': async () => this.package(),
};
}

View File

@ -64,8 +64,8 @@ class PromisePluginMock {
};
this.hooks = {
'deploy:functions': this.functions.bind(this),
'before:deploy:onpremises:functions': this.resources.bind(this),
'deploy:functions': async () => this.functions(),
'before:deploy:onpremises:functions': async () => this.resources(),
};
// used to test if the function was executed correctly
@ -118,8 +118,8 @@ class SynchronousPluginMock {
};
this.hooks = {
'deploy:functions': this.functions.bind(this),
'before:deploy:onpremises:functions': this.resources.bind(this),
'deploy:functions': async () => this.functions(),
'before:deploy:onpremises:functions': async () => this.resources(),
};
// used to test if the function was executed correctly
@ -164,7 +164,7 @@ describe('PluginManager', () => {
};
this.hooks = {
'deploy:functions': this.functions.bind(this),
'deploy:functions': async () => this.functions(),
};
// used to test if the function was executed correctly
@ -187,7 +187,7 @@ describe('PluginManager', () => {
};
this.hooks = {
'deploy:functions': this.functions.bind(this),
'deploy:functions': async () => this.functions(),
};
// used to test if the function was executed correctly
@ -236,8 +236,8 @@ describe('PluginManager', () => {
};
this.hooks = {
'deploy:functions': this.functions.bind(this),
'before:deploy:onpremises:functions': this.resources.bind(this),
'deploy:functions': async () => this.functions(),
'before:deploy:onpremises:functions': async () => this.resources(),
};
// used to test if the function was executed correctly
@ -292,13 +292,13 @@ describe('PluginManager', () => {
};
this.hooks = {
'myep:initialize': this.initialize.bind(this),
'myep:finalize': this.finalize.bind(this),
'myep:mysubep:initialize': this.subEPInitialize.bind(this),
'myep:mysubep:finalize': this.subEPFinalize.bind(this),
'mycmd:mysubcmd:initialize': this.subInitialize.bind(this),
'mycmd:mysubcmd:finalize': this.subFinalize.bind(this),
'mycmd:run': this.run.bind(this),
'myep:initialize': async () => this.initialize(),
'myep:finalize': async () => this.finalize(),
'myep:mysubep:initialize': async () => this.subEPInitialize(),
'myep:mysubep:finalize': async () => this.subEPFinalize(),
'mycmd:mysubcmd:initialize': async () => this.subInitialize(),
'mycmd:mysubcmd:finalize': async () => this.subFinalize(),
'mycmd:run': async () => this.run(),
// Event1 spawns mysubcmd, then myep
// Event2 spawns mycmd, then mysubep
'myep:spawnep:event1': async () =>
@ -359,8 +359,8 @@ describe('PluginManager', () => {
};
this.hooks = {
'mycontainer:mysubcmd:event1': this.eventOne.bind(this),
'mycontainer:mysubcmd:event2': this.eventTwo.bind(this),
'mycontainer:mysubcmd:event1': async () => this.eventOne(),
'mycontainer:mysubcmd:event2': async () => this.eventTwo(),
};
this.callResult = '';
@ -378,8 +378,8 @@ describe('PluginManager', () => {
class DeprecatedLifecycleEventsPluginMock {
constructor() {
this.hooks = {
'deprecated:deprecated': this.deprecated, // NOTE: we assume that this is deprecated
'untouched:untouched': this.untouched,
'deprecated:deprecated': async () => this.deprecated(), // NOTE: we assume that this is deprecated
'untouched:untouched': async () => this.untouched(),
};
}
@ -1180,10 +1180,10 @@ describe('PluginManager', () => {
};
this.hooks = {
'initialize': this.initializeHookStatus.bind(this),
'before:run:beforeHookStatus': this.beforeHookStatus.bind(this),
'run:midHookStatus': this.midHookStatus.bind(this),
'after:run:afterHookStatus': this.afterHookStatus.bind(this),
'initialize': async () => this.initializeHookStatus(),
'before:run:beforeHookStatus': async () => this.beforeHookStatus(),
'run:midHookStatus': async () => this.midHookStatus(),
'after:run:afterHookStatus': async () => this.afterHookStatus(),
};
// used to test if the hooks were run in the correct order