Serverless: API for allowing plugins to access other plugins

Created on 24 Nov 2016  ·  3Comments  ·  Source: serverless/serverless

Working on the OpenWhisk provider implementation for Serverless I've hit a challenge trying to access other plugin instances from within my plugins.

In the deployFunction plugin, we need to access the existing package plugin to manage packaging a single function artifact.

In the AWS provider implementation, the class can directly reference the module through a local file path. https://github.com/serverless/serverless/blob/master/lib/plugins/aws/deployFunction/index.js#L9

The OpenWhisk plugin is a third-party plugin and cannot do this.

I'm currently working around this by iterating over the installed plugin instances, from the plugin manager, but this relies on monkey-testing the instance to assume we have the correct instance.
https://github.com/serverless/serverless-ibm-openwhisk/blob/master/deployFunction/index.js#L15-L16

Could we add some API method to help me find installed plugins by their name?


Implementation proposal

Identify plugins by unique name, which should be resolved either from plugin.name property or uncapitalized constructor name.

If two plugins of same name are detected, show deprecation message that with next major version such setup will throw

Plugins should be referenced by name on serverless.plugins collection, and through that accessible to other plugins.

Name resolution and serlveress.plugins assignment should happen in scope of pluginManager.addPlugin logic: https://github.com/serverless/serverless/blob/5096534a80e211b947e59d7283cfdfdd1711e7ea/lib/classes/PluginManager.js#L93-L122

caplugin deprecation enhancement good first issue help wanted

Most helpful comment

@jthomas thank you for opening this! 👍 Perfect timing 🕐

We're currently discussing how we can improve the overall plugin architecture / UX.
Great to have such a feedback about current pain points (please submit more if you have anything else). 💯

/cc @ac360 @nikgraf @eahefnawy @mthenw

All 3 comments

@jthomas thank you for opening this! 👍 Perfect timing 🕐

We're currently discussing how we can improve the overall plugin architecture / UX.
Great to have such a feedback about current pain points (please submit more if you have anything else). 💯

/cc @ac360 @nikgraf @eahefnawy @mthenw

Indeed, very good feedback! We make sure this is possible in the future.

I've updated main description with implementation proposal. It can be achieved quite simply (I think), and added value is real

Was this page helpful?
0 / 5 - 0 ratings