diff --git a/lib/plugins/aws/package/compile/events/activemq.js b/lib/plugins/aws/package/compile/events/activemq.js index f8c6ffe81..85faf53c8 100644 --- a/lib/plugins/aws/package/compile/events/activemq.js +++ b/lib/plugins/aws/package/compile/events/activemq.js @@ -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', { diff --git a/lib/plugins/aws/package/compile/events/alexa-skill.js b/lib/plugins/aws/package/compile/events/alexa-skill.js index 5db3684db..e8f49da64 100644 --- a/lib/plugins/aws/package/compile/events/alexa-skill.js +++ b/lib/plugins/aws/package/compile/events/alexa-skill.js @@ -37,7 +37,7 @@ class AwsCompileAlexaSkillEvents { ); } }, - 'package:compileEvents': this.compileAlexaSkillEvents.bind(this), + 'package:compileEvents': async () => this.compileAlexaSkillEvents(), }; } diff --git a/lib/plugins/aws/package/compile/events/alexa-smart-home.js b/lib/plugins/aws/package/compile/events/alexa-smart-home.js index feeda24ed..6d5df827b 100644 --- a/lib/plugins/aws/package/compile/events/alexa-smart-home.js +++ b/lib/plugins/aws/package/compile/events/alexa-smart-home.js @@ -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', { diff --git a/lib/plugins/aws/package/compile/events/cloud-front.js b/lib/plugins/aws/package/compile/events/cloud-front.js index 1078c6b73..ed45e1eb3 100644 --- a/lib/plugins/aws/package/compile/events/cloud-front.js +++ b/lib/plugins/aws/package/compile/events/cloud-front.js @@ -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(), }; } diff --git a/lib/plugins/aws/package/compile/events/cloud-watch-event.js b/lib/plugins/aws/package/compile/events/cloud-watch-event.js index 4e3736620..6fef2f0f7 100644 --- a/lib/plugins/aws/package/compile/events/cloud-watch-event.js +++ b/lib/plugins/aws/package/compile/events/cloud-watch-event.js @@ -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', { diff --git a/lib/plugins/aws/package/compile/events/cloud-watch-log.js b/lib/plugins/aws/package/compile/events/cloud-watch-log.js index fe9df3289..d7bc61b37 100644 --- a/lib/plugins/aws/package/compile/events/cloud-watch-log.js +++ b/lib/plugins/aws/package/compile/events/cloud-watch-log.js @@ -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', { diff --git a/lib/plugins/aws/package/compile/events/cognito-user-pool.js b/lib/plugins/aws/package/compile/events/cognito-user-pool.js index 6cfeb46cb..aaeb4cceb 100644 --- a/lib/plugins/aws/package/compile/events/cognito-user-pool.js +++ b/lib/plugins/aws/package/compile/events/cognito-user-pool.js @@ -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', { diff --git a/lib/plugins/aws/package/compile/events/event-bridge/index.js b/lib/plugins/aws/package/compile/events/event-bridge/index.js index 701451bb7..4192a9b36 100644 --- a/lib/plugins/aws/package/compile/events/event-bridge/index.js +++ b/lib/plugins/aws/package/compile/events/event-bridge/index.js @@ -48,7 +48,7 @@ class AwsCompileEventBridgeEvents { ); } }, - 'package:compileEvents': this.compileEventBridgeEvents.bind(this), + 'package:compileEvents': async () => this.compileEventBridgeEvents(), }; this.serverless.configSchemaHandler.defineFunctionEvent('aws', 'eventBridge', { diff --git a/lib/plugins/aws/package/compile/events/iot-fleet-provisioning.js b/lib/plugins/aws/package/compile/events/iot-fleet-provisioning.js index 69618f188..c72ab92b8 100644 --- a/lib/plugins/aws/package/compile/events/iot-fleet-provisioning.js +++ b/lib/plugins/aws/package/compile/events/iot-fleet-provisioning.js @@ -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', { diff --git a/lib/plugins/aws/package/compile/events/iot.js b/lib/plugins/aws/package/compile/events/iot.js index 17c3c42ef..586901870 100644 --- a/lib/plugins/aws/package/compile/events/iot.js +++ b/lib/plugins/aws/package/compile/events/iot.js @@ -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', { diff --git a/lib/plugins/aws/package/compile/events/kafka.js b/lib/plugins/aws/package/compile/events/kafka.js index 34a37c5bc..b15c13fcf 100644 --- a/lib/plugins/aws/package/compile/events/kafka.js +++ b/lib/plugins/aws/package/compile/events/kafka.js @@ -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', { diff --git a/lib/plugins/aws/package/compile/events/msk/index.js b/lib/plugins/aws/package/compile/events/msk/index.js index 4f6e771b2..4efbed5a6 100644 --- a/lib/plugins/aws/package/compile/events/msk/index.js +++ b/lib/plugins/aws/package/compile/events/msk/index.js @@ -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', { diff --git a/lib/plugins/aws/package/compile/events/rabbitmq.js b/lib/plugins/aws/package/compile/events/rabbitmq.js index 9bde8b01f..f2a42339a 100644 --- a/lib/plugins/aws/package/compile/events/rabbitmq.js +++ b/lib/plugins/aws/package/compile/events/rabbitmq.js @@ -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', { diff --git a/lib/plugins/aws/package/compile/events/schedule.js b/lib/plugins/aws/package/compile/events/schedule.js index 91fbaab7a..85d3b339b 100644 --- a/lib/plugins/aws/package/compile/events/schedule.js +++ b/lib/plugins/aws/package/compile/events/schedule.js @@ -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', { diff --git a/lib/plugins/aws/package/compile/events/sns.js b/lib/plugins/aws/package/compile/events/sns.js index bf5724f07..af8c0e4ec 100644 --- a/lib/plugins/aws/package/compile/events/sns.js +++ b/lib/plugins/aws/package/compile/events/sns.js @@ -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', { diff --git a/lib/plugins/aws/package/compile/events/sqs.js b/lib/plugins/aws/package/compile/events/sqs.js index 059cc6863..53934d906 100644 --- a/lib/plugins/aws/package/compile/events/sqs.js +++ b/lib/plugins/aws/package/compile/events/sqs.js @@ -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', { diff --git a/lib/plugins/aws/package/compile/events/stream.js b/lib/plugins/aws/package/compile/events/stream.js index 129997eed..6824e9b69 100644 --- a/lib/plugins/aws/package/compile/events/stream.js +++ b/lib/plugins/aws/package/compile/events/stream.js @@ -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', { diff --git a/lib/plugins/aws/package/compile/layers.js b/lib/plugins/aws/package/compile/layers.js index bb6f054fe..21053b5ce 100644 --- a/lib/plugins/aws/package/compile/layers.js +++ b/lib/plugins/aws/package/compile/layers.js @@ -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(), }; } diff --git a/lib/plugins/aws/remove/lib/stack.js b/lib/plugins/aws/remove/lib/stack.js index c3baa80d1..429801bd4 100644 --- a/lib/plugins/aws/remove/lib/stack.js +++ b/lib/plugins/aws/remove/lib/stack.js @@ -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(); }, }; diff --git a/lib/plugins/create/create.js b/lib/plugins/create/create.js index e540a0fcb..f5d658424 100644 --- a/lib/plugins/create/create.js +++ b/lib/plugins/create/create.js @@ -28,7 +28,7 @@ class Create { }; this.hooks = { - 'create:create': async () => BbPromise.bind(this).then(this.create), + 'create:create': async () => this.create(), }; } diff --git a/lib/plugins/install.js b/lib/plugins/install.js index c2a358373..1117e7d3c 100644 --- a/lib/plugins/install.js +++ b/lib/plugins/install.js @@ -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(), }; } diff --git a/lib/plugins/invoke.js b/lib/plugins/invoke.js index a9254a52c..7a28cf075 100644 --- a/lib/plugins/invoke.js +++ b/lib/plugins/invoke.js @@ -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(), }; } diff --git a/lib/plugins/package/package.js b/lib/plugins/package/package.js index 97d5b0517..3726b381f 100644 --- a/lib/plugins/package/package.js +++ b/lib/plugins/package/package.js @@ -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) { diff --git a/lib/plugins/plugin/list.js b/lib/plugins/plugin/list.js index 6a342b984..305675f31 100644 --- a/lib/plugins/plugin/list.js +++ b/lib/plugins/plugin/list.js @@ -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); } } diff --git a/lib/plugins/plugin/search.js b/lib/plugins/plugin/search.js index 46bff0910..8da3e893a 100644 --- a/lib/plugins/plugin/search.js +++ b/lib/plugins/plugin/search.js @@ -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); } } diff --git a/test/fixtures/programmatic/package-artifact-in-serverless-dir/package-artifact-plugin.js b/test/fixtures/programmatic/package-artifact-in-serverless-dir/package-artifact-plugin.js index 79db9a173..6b1c1fc11 100644 --- a/test/fixtures/programmatic/package-artifact-in-serverless-dir/package-artifact-plugin.js +++ b/test/fixtures/programmatic/package-artifact-in-serverless-dir/package-artifact-plugin.js @@ -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(), }; } diff --git a/test/unit/lib/classes/plugin-manager.test.js b/test/unit/lib/classes/plugin-manager.test.js index b83d9e8a3..8447eaab5 100644 --- a/test/unit/lib/classes/plugin-manager.test.js +++ b/test/unit/lib/classes/plugin-manager.test.js @@ -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