Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move plugin conditions from code into plugin metadata #32

Open
martinheidegger opened this issue Feb 22, 2022 · 0 comments
Open

Move plugin conditions from code into plugin metadata #32

martinheidegger opened this issue Feb 22, 2022 · 0 comments
Labels
plugin related to the plugin mechanism

Comments

@martinheidegger
Copy link
Contributor

The current plugin mechanism utilizes conditionals like if (handleMessages) to determine which plugins need to be loaded and which do not.

Example:

if (ONFIDO_RELATED_EVENTS.includes(event) && plugins.onfido && plugins.onfido.apiKey) {
attachPlugin({ name: 'onfido' })
}

This makes two things difficult.

  1. When modifying a plugin we can not easily see under which conditions the plugin is executed.
  2. It is difficult to determine before the plugins get loaded which plugins will be necessary for certain event. This is of note as we want to load plugins dynamically and need to know this in advance, without the plugins themselves being loaded.

To change this I am planning to turn current conditional plugin loading into a meta-data that can be evaluated non-sequentially). For example, this:

if (
handleMessages ||
runAsyncHandlers ||
event.startsWith('deployment:') ||
event === LambdaEvents.COMMAND ||
event === LambdaEvents.SCHEDULER
) {
attachPlugin({ name: 'deployment', requiresConf: false })

would be turned into configuration like below:

{
  name: 'deployment',
  visible: true, // To show the plugin in the tradle plugins dialog
  requiresConf: false, // Configuration required for the plugin to be loaded
  hooks: [{
    condition: { isTradle: true }, // we put currently distributed "conditions" into a single object
    events: [
      'message', // on every event of type 'message'
      'resourcestream',
      'deployment:*', // to support .startsWith(...) we need to support patterns
      'command',
      'scheduler'
    ]
  }]
}

This data format externally defined plugins can provide this data-structure as part of the package.json.

@martinheidegger martinheidegger added the plugin related to the plugin mechanism label Feb 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin related to the plugin mechanism
Projects
None yet
Development

No branches or pull requests

1 participant