interceptors icon indicating copy to clipboard operation
interceptors copied to clipboard

Distribute interceptors properly

Open kettanaito opened this issue 4 years ago • 3 comments

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).

kettanaito avatar Aug 30 '20 11:08 kettanaito

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.

kettanaito avatar Aug 31 '20 19:08 kettanaito

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.

kettanaito avatar Feb 23 '22 17:02 kettanaito

I also think the import pattern should be

import interceptor from '@mswjs/interceptors/[interceptor]'

kettanaito avatar Feb 23 '22 17:02 kettanaito

We can use "exports" in package.json to do this but it'll only work in ESM, I assume.

kettanaito avatar Nov 19 '22 01:11 kettanaito

Already implemented in #313.

kettanaito avatar Feb 27 '23 00:02 kettanaito