Open TheAsda opened 3 weeks ago
So i did some tesing with import and require.
Branch with import-in-the-middle: https://github.com/TheAsda/import-in-the-middle-issue/tree/master
Branch with require-in-the-middle: https://github.com/TheAsda/import-in-the-middle-issue/tree/require
There are two scripts that apply some patching to fastify package. With require everything works as expected:
But the same example with import applies only the latest patch:
I also tried different methods such as using
register
from the module package, applying patches in single file. The result is the same
Looks like the issue is with proxy created in https://github.com/DataDog/import-in-the-middle/blob/main/lib/register.js. hook
is called with the scoped namespace that is the same every time the hook is called
So the issue is that in register only setter is used so every time hook is called with the original namespace
I added getter
similar to setter
to be able to get the latest namespace after modification
I added
getter
similar tosetter
to be able to get the latest namespace after modification
Could you submit a PR to fix this or do you have a patch I could try?
I managed to fix the issue with default import patching but when i tested patching named exports tests failed :( Right now i don't have a solution to this problem
As far as i understand and according to some testing being done if there are multiple multiple hooks attached to the same package the last one will be eventually used in application. Am i right? If so are there any methods to apply sequential patches to the package. The case is that i'm using library that's patched the package i want to patch.
Library version: 1.8.0 Node version: 20.11.1