Skip to content

Are sequential patched supported? #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
TheAsda opened this issue Jun 10, 2024 · 6 comments · Fixed by #153
Closed

Are sequential patched supported? #98

TheAsda opened this issue Jun 10, 2024 · 6 comments · Fixed by #153
Assignees

Comments

@TheAsda
Copy link

TheAsda commented Jun 10, 2024

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

@TheAsda
Copy link
Author

TheAsda commented Jun 11, 2024

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:
image
But the same example with import applies only the latest patch:
image
I also tried different methods such as using register from the module package, applying patches in single file. The result is the same

@TheAsda
Copy link
Author

TheAsda commented Jun 11, 2024

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

@TheAsda
Copy link
Author

TheAsda commented Jun 11, 2024

So the issue is that in register only setter is used so every time hook is called with the original namespace

@TheAsda
Copy link
Author

TheAsda commented Jun 11, 2024

I added getter similar to setter to be able to get the latest namespace after modification
image

@timfish
Copy link
Contributor

timfish commented Jul 2, 2024

I added getter similar to setter 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?

@TheAsda
Copy link
Author

TheAsda commented Jul 2, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants