interceptors
interceptors copied to clipboard
Distribute interceptors properly
Expected behavior
- Exported under
node-request-interceptor/interceptors/[name]
- Distributed in a format that would allow them to be imported from both ESM and CJS context (currently importing an interceptor directly from a ESM context doesn't compile, it strips away named export of
SocketPolyfill
).
I've tried building each interceptor as a separate CJS module, but that produces the same result as with the current setup.
It comes down to which format the entire NRI should be distributed. I believe that should be CJS, as you can use CJS in another CJS context, while in ESM context you are likely to ignore transformation of CJS modules.
Can use symlinks or empty folders like we do in msw/node
:
interceptors/
fetch/
package.json
ClientRequest/
package.json
Can also use "exports"
in package.json but TypeScript doesn't play nicely with it.
I also think the import pattern should be
import interceptor from '@mswjs/interceptors/[interceptor]'
We can use "exports" in package.json to do this but it'll only work in ESM, I assume.
Already implemented in #313.