-
Notifications
You must be signed in to change notification settings - Fork 69
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
WIP: Make examples ESM and add ESM to node-ble #422
WIP: Make examples ESM and add ESM to node-ble #422
Conversation
c313555
to
d075351
Compare
I need to check the exports on a big screen (just mobile right now) but yes that require thingy seems to be that way as only available option. Will check latest tomorrow. |
Don't know, it actually surprised me that there's little discussion related to this. I am thinking about importing the dual format require with relative path as well, what do you think? |
@vilicfor the "require": We could also simply make the "loading"methdod async and use await import? |
@Apollon77 Yes but that would introduce noticeable changes. Currently both |
wait ... look deeper ... bleno and noble requires ia both "lazy" in a method, e,.g. https://github.com/project-chip/matter.js/blob/main/packages/matter-node-ble.js/src/ble/BlenoBleServer.ts#L31 so it is not top level :-) so when we make this "Initialize" method async then all should be fine. PS: Yes because initialize is done in constrzuctore we would needs to adjust that a bit, but like the "create" methods we use elsewhere for the same reasons |
Yes, I mentioned top-level await because if that could be done, there's nothing need to change elsewhere. And asynchronousness is contagious, I took some reference looking up, and there might be a tree to update. I'll do whatever you want. ;) |
I think given the migration to ESM top-level await is fine, desirable even in this case. |
SO tehe question is still if we should use this "extra exposed require" or if we just switch the "Inititialize" methdos to async and use an await import there ... then we do dnot need this requiets special stuff |
Switching to async initialization would be ideal but I'd leave up to @vilic since he's doing the work. :) Could also accept with the require and add a TODO for swapping to async. @vilic FWIW we've dealt with "cascading async refactors" before and they aren't usually too terrible since a lot of our initialization code is already async. |
d075351
to
1760e6b
Compare
@lauckhart I'll leave the PR as-is then. 😄 I just tried the "cascading async refactor" (nearly finished) but as it changes some API (e.g. Also, there are some issues with I think it's better to be done by you guys so you can make sure there's no unnecessary compromises. |
I know it's a bit late :-) But "npm run bundle-device" in the examples directory no longer works: [ERROR] Could not resolve "dist/cjs/examples/DeviceNode.js" Is that a result of this change? |
@JimBuzbee Seems to be caused by this PR. Turned out to be a little bit more complicated than I thought. |
@JimBuzbee I have submitted a PR fixing this, please check it out. |
Fix released as new Nightly |
@vilicvane - Thanks for the quick response - works for me now. |
Next nightly is also on it's way, sorry |
type
for bothmatter-node-ble.js
andmatter-node.js-examples
to"module"
..js
file extension formatter-node-ble.js
.require
that works in both CJS and ESM using Node.jspackage.json
. Other better ways?