Closed edemaine closed 6 months ago
LGTM, @antfu could plz you review together?
@antfu This should be ready for re-review when you get a chance. Thanks!
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.
Thank you!!
π Linked issue
53 (for esbuild)
β Type of change
π Description
This PR adds
this.addWatchFile
support for esbuild in the context of hooksresolveId
,load
, andtransform
.this.warn
andthis.error
were already implemented, which is to build an array for the hook context and then return it from the esbuild hook.resolveId
, I had to.call
resolveId
withthis
set to the actual context, whereas previouslyresolveId
was called withthis
set to the options object. I believe the new behavior aligns with the Rollup spec.createEsbuildPluginContext
helper because we needed it for both resolve and build.I also added a basic
this.getWatchFiles()
which returns the current array of watched files added viathis.addWatchFile
.Context:
this.addWatchFile
for a transpiling unplugin becauseresolveId
returns a not-real filename (with added.tsx
extension to force the output to behave like TypeScript)."file"
, and unplugin sets the context to the plugin name, soesbuild --watch
currently doesn't work at all.I also removed some accidental (I think) modification of the
context
object viaObject.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