unjs / unplugin

Unified plugin system for Vite, Rollup, Webpack, esbuild, Rolldown, and more
https://unplugin.unjs.io
MIT License
2.9k stars 104 forks source link

feat: esbuild support for addWatchFile and getWatchFiles #345

Closed edemaine closed 6 months ago

edemaine commented 8 months ago

πŸ”— Linked issue

53 (for esbuild)

❓ Type of change

πŸ“š Description

This PR adds this.addWatchFile support for esbuild in the context of hooks resolveId, load, and transform.

I also added a basic this.getWatchFiles() which returns the current array of watched files added via this.addWatchFile.

Context:

I also removed some accidental (I think) modification of the context object via Object.assign.

I have tested this in the context of our unplugin, but I'm not sure how to write tests for this within the current testing infrastructure.

πŸ“ Checklist

sxzz commented 8 months ago

LGTM, @antfu could plz you review together?

edemaine commented 8 months ago

@antfu This should be ready for re-review when you get a chance. Thanks!

edemaine commented 7 months ago

Any chance this could be merged and released? It's a bottleneck for Civet now, and I'd prefer not to depend on a fork.

Alternatively, I could remove the changes to resolveId if they're too controversial, and just keep the changes for esbuild in load, which is what we really need (because this is the only place addWatchFile is supported across all build systems.

edemaine commented 6 months ago

Thank you!!