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
Add support for ESM modules and async plugin initializers. #2915
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your PR.
I'm not sure about the support for async functions exported by a homebridge plugin, everything else looks good 👍
Have you tested this with a ESM module?
Yup, I tested with a custom module and it works awesomely. The only thing I haven't tested is child bridges. |
Hello! Any chance for this to be merged? |
any news of pulling this in ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @ShogunPanda, this looks great! Sorry it's been sitting for so long! If you don't mind addressing at least the import comment, then I'd be happy to spin this up locally and verify it's working against an ESM version of one of my plugins.
@dgreif As all comments are resolved, I just rebased my PR against the latest master, so this should be good to go. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved for beta branch.
Beta v1.3.6-beta.1
On line 60 in
to something like
As it seems an ESM package.json example Edit, maybe not. I didn't realise the |
Yup, I think so. Probably I would have been more restrictive to something like:
But for now seems to be fine. Let's see if this becomes an issue. |
We have most likely an Issue related to this PR. Could one please investigate: #3013 (comment)? EDIT: I think the issue is the migration of the for loop in the |
Hey guys, does anyone else have the following problem on Windows?
Line 24 in ef242e9
|
Most likely it will happen to everybody on Windows. |
Will post a PR later with a fix edit: see #3070 |
Add support for ESM modules and async plugin initializers
Add support for ESM modules and async plugin initializers.
♻️ Current situation
Today, if you try to load a package which
type=module
in package.json it throws an error as it tries to userequire()
on a ESM module.💡 Proposed solution
This PR introduces detection of ESM module and if detect it uses
await import()
.Implications
By using
await import
, by definition the entire plugin loading phase has become asynchronous. All affected code places have been refactored to beasync function
and toawait
for plugin loading and initialization.Almost for free, HomeBridge plugins can now export a
async function
as default and this will be awaited. This means that now plugin can do async initialization.Reviewer Nudging
Plugin and PluginManager code.