vendure-ecommerce / vendure

The commerce platform with customization in its DNA.
https://www.vendure.io
MIT License
5.39k stars 944 forks source link

Hot Reload Modules #2820

Open Logic-Bits opened 2 months ago

Logic-Bits commented 2 months ago

Hello,

would it be possible to have Plugins being hot-reloaded?

https://docs.nestjs.com/recipes/hot-reload

so plugin updates can be rolled out independend, or even something like a store can be enabled by this.

Thanks!

michaelbromley commented 3 weeks ago

Hi,

I'm not sure - but if you'd like to try a proof-of-concept then I'd be interested to hear if you get it to work, and we can consider incorporating any needed changes into the core.

Logic-Bits commented 3 weeks ago

maybe you can point me in the right direction. We would need to publish a "lets reload module X" Event - to all instances and workers (in theory). Would the EventBus be the right choice?

Thanks

michaelbromley commented 3 weeks ago

I'm not really familiar with the internal workings of HMR, but I don't think the EventBus should be involved since that is for events that occur within the system itself, not in modifications to source code.

Maybe what would be needed is a custom file watcher process which is able to find the associated Module (or VendurePlugin) for any given modified file. This can be done by traversing the TypeScript AST using something like ts-morph.

And is HMR only supported if you use Webpack when developing? Because by default, projects generated with @vendure/create do not use Webpack.