mswjs / interceptors

Low-level network interception library.
https://npm.im/@mswjs/interceptors
MIT License
563 stars 127 forks source link

fix: add root-level "browser" export #421

Closed blaenk closed 11 months ago

blaenk commented 1 year ago

This, in combination with configuring my tsconfig.ts to 'activate' the browser condition when evaluating this package's exports field via customConditions, allows typescript to automatically (well, via exports) pick all of the right types and compile cleanly!

Here is the customConditions field in my tsconfig.ts:

"customConditions": ["browser"]

I think having the user enable this is not onerous at all and probably ideal if they are indeed targeting the browser. Compare that to requiring the user to explicitly override paths via paths and then requiring the bundler to know about that (via some tsconfig-paths plugin).

This way, it will ignore the root level "types" if browser is activated/true, in which case it instead uses the browser ones, solving the issue where otherwise the root typings file was used, so the browserInterceptors would not match with the BatchInterceptor since the one being used was the node one.

I'm not sure what other effects this would have, but I don't see why it would have any, and it appears to be consistent with everything else we're doing with the browser condition.

blaenk commented 1 year ago

@kettanaito any chance you can look at this? I would appreciate it!

Thank you for working on this project!

kettanaito commented 11 months ago

Released: v0.25.12 🎉

This has been released in v0.25.12!

Make sure to always update to the latest version (npm i @mswjs/interceptors@latest) to get the newest features and bug fixes.


Predictable release automation by @ossjs/release.

steve-zhu-sh commented 11 months ago

Woo didn't realize this had already been addressed, thanks for the fix!