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

iitm wrappers copy exported primitives #118

Closed timfish closed 1 week ago

timfish commented 1 week ago

When you export primitives in ESM, they are exposed as references which means they can be written to from elsewhere within the module. A reproduction of this behaviour can be seen in #113.

Because the iitm wrappers assign each export to a variable before re-exporting, primitive exports have their original value copied and the reference is lost.

This is where the code generation does that: https://github.com/nodejs/import-in-the-middle/blob/57d2459748492abd55e04a679d8b5752b90dfab4/hook.js#L189-L190

timfish commented 1 week ago

Ah, just realised this is a duplicate of #38