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

support loading of plugins in a smart order based on dependency #30

Merged
merged 7 commits into from
Apr 12, 2019

Conversation

salmanm
Copy link
Member

@salmanm salmanm commented Apr 11, 2019

Fixes #29

  • Auto loads plugins in the order they are needed (checks for the dependencies array).
  • Checks for cyclic dependencies and returns error, if found.

@Eomm
Copy link
Member

Eomm commented Apr 11, 2019

Hi,
thanks for the PR!

Could you fix the error for Node.js 6?
It should be necessary replace the Object.value with a Object.keys() and then grab the value.

Meanwhile, I'll check deeper the code, for now, I'm thinking that a hidden limit is that it will be not possible load twice a plugin with the same name but I need to think if it is a real use case

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work! Instead of extending the “basic” app, can you create a new one?

if (plugin.prefixOverride !== void 0) {
pluginOptions.prefix = plugin.prefixOverride
}

if (plugin.autoload !== false) {
fastify.register(plugin.default || plugin, pluginOptions)
allPlugins[pluginName] = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should throw if two plugins have the same name.z

@salmanm
Copy link
Member Author

salmanm commented Apr 12, 2019

Thanks @mcollina, done those changes.

@salmanm
Copy link
Member Author

salmanm commented Apr 12, 2019

@Eomm I tried to think about the hidden limit you mentioned. Loading a plugin twice in the same load chain is a result of cyclic dependency. I couldn't think of a case where one would load a plugin twice in the same load chain and still not cause cyclic dependency.

It's however fine to load a plugin from two separate load sequence. i.e. plugin-a & plugin-b both needs plugin-c.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some decorators/checks in the dependency test plugins so that it won't load unless we the order is correct?

@mcollina
Copy link
Member

Also, CI is failing.

@salmanm
Copy link
Member Author

salmanm commented Apr 12, 2019

Yep, good idea.
I didn't do it earlier as I thought fastify already blocks when dependencies aren't loaded already.
But no harm checking.

All done now.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mcollina mcollina requested a review from Eomm April 12, 2019 09:11
Copy link
Member

@Eomm Eomm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add 2 hints

index.js Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
@salmanm
Copy link
Member Author

salmanm commented Apr 12, 2019

@Eomm Done

Copy link
Member

@Eomm Eomm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will release it by the week end as semver-minor 👍

@Eomm Eomm merged commit 76be90c into fastify:master Apr 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature: load plugins in order based on dependencies
3 participants