embroider-build / embroider

Compiling Ember apps into spec-compliant, modern Javascript.
MIT License
339 stars 138 forks source link

How to watch dependencies in Classic and Embroider #2129

Open simonihmig opened 1 month ago

simonihmig commented 1 month ago

This issue is for documenting how the different Ember build systems behave regarding watching the different types of dependencies, and potentially addressing any gaps.

Classic/eai Embroider/Webpack (stable) Embroider/Vite (main) Embroider/Webpack (future IoC)
v1 addon just works [^1] just works [^1] ? ?
v2 addon needs watchDependencies needs broccoli-side-watch ^2 just works ?
npm pkg needs watchDependencies needs broccoli-side-watch ^2 just works ?

[^1]: Used to need enabling isDevelopingAddon, but seems this enabled by default when canNestRoots is true (source)

ef4 commented 1 month ago

Embroider/Vite (main) v1 Addon should work as long as we're using BROCCOLI_ENABLED_MEMOIZE the same way stable does, we should confirm that.

Embroider/Webpack (future IoC) will just work.

v2 addon and npm under both Classic/eai and Embroider/Webpack (stable) could be made to work if we start integrating Webpack's watch mode inside the broccoli pipeline.

simonihmig commented 1 month ago

v2 addon and npm under both Classic/eai and Embroider/Webpack (stable) could be made to work if we start integrating Webpack's watch mode inside the broccoli pipeline.

@ef4 Have looked into that a bit, but failed to figure out how this can be done. Like when we hook into webpack's watch mode, we would need to make the broccoli tree that is wrapping the webpack build understand that something changed so that it rebuilds, right? But AFAICT how broccoli's watch mode works is that you mark specific input nodes as being watched (WatchedDir), but the files changing that webpack is notifying us about are always outside of what is the broccoli input. So we basically need to tell broccoli that some files changed that are not covered by any input nodes, but it needs to rebuild anyway. But I don't see an API that would allow us to that? Or do I misunderstand?

Anyways, in the meantime I worked on https://github.com/embroider-build/embroider/pull/2141, which should make broccoli-side-watch work as easy as watchDependencies, so both APIs are at par. And maybe "good enough" to make the above mentioned approach not being worth the effort, given that next-gen Embroider will just work already!?