nodejs / import-in-the-middle

Like `require-in-the-middle`, but for ESM import
https://www.npmjs.com/package/import-in-the-middle
Apache License 2.0
52 stars 20 forks source link

feat: Add `Hook` named export #88

Closed timfish closed 1 month ago

timfish commented 1 month ago

import-in-the-middle has some ESM interop issues.

From here:

Specifically, namespace imports are required by the ESM spec to be objects. IITM's top-level export is not an object, but a callable function

This causes issues with some bundlers. Obviously bundled imports will not go through import-in-the-middle but using it should not inhibit bundlers as iitm can still hook build-in modules.

This PR adds a Hook named export and changes one cjs and esm test to use that new export.

AbhiPrasad commented 1 month ago

should we also update the README to make the named export the recommended usage?

bengl commented 1 month ago

@timfish should there best test additions too? I.e. if something's exported, it should be tested that that interface works?

timfish commented 1 month ago

should there best test additions too? I.e. if something's exported, it should be tested that that interface works?

I modified both an ESM and CJS test to use this new export!

bengl commented 1 month ago

I modified both an ESM and CJS test to use this new export!

Oops! I should have noticed that. 😅

And I see that other test files retain the usage of the default export. SGTM/LGTM.