-
-
Notifications
You must be signed in to change notification settings - Fork 148
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
fix: attach queue to fs module instead of global #184
Conversation
I've applied this patch via |
@coreyfarrell what say you? |
Is it possible to proxyquire or mock the |
If people override |
So one additional thought for a new 4.x release to put the symbol on This is a more difficult issue than I initially thought, I will have to think it over a bit more. I wonder if we could monkey-patch context creation to copy |
If it's still attached to |
Here's the idea I'm having: function publishQueue(context, queue) {
Object.defineProperty(context, gracefulQueue, {
get: function() {
return queue
}
})
}
// Once time initialization
if (!fs[gracefulQueue]) {
// This queue can be shared by multiple loaded instances
var queue = global[gracefulQueue] || []
publishQueue(fs, queue);
// ... existing code to patch fs.close / fs.closeSync
}
if (!global[gracefulQueue]) {
publishQueue(global, fs[gracefulQueue]);
} There is one "not awesome" situation here. If 4.2.3 is loaded before the code published by this PR it will patch fs.close / fs.closeSync twice. This does however avoid potential infinite patching of those functions. In theory we could have a check that would unpatch 4.2.3 before the "Once time initialization": if (global[gracefulQueue] && !fs[gracefulQueue]) {
if (fs.close[previousSymbol]) {
fs.close = fs.close[previousSymbol]
}
if (fs.closeSync[previousSymbol]) {
fs.closeSync = fs.closeSync[previousSymbol]
}
} I'm not sure dealing with this edge case is worth the additional complexity. |
@coreyfarrell if it works I'm all for it! If you can prepare a patch I can apply it in Jest and see if we OOM or not on CI (which we do without this PR) |
@SimenB I've pushed an additional commit to maintain |
@coreyfarrell thanks! I've applied that and it still works 🙂 Would love to see this land now 👍 |
@isaacs @coreyfarrell ready to land? 😀 Jest currently does |
Thank you @coreyfarrell! |
Not a problem sorry for the delay, this is a widespread module so changes face a degree of paranoia. |
Very understandable! If you publish it under |
Didn't you already test with jest using patch-package? |
Yeah, but that's to test in Jest itself, I meant to publish so others can use it as well. |
Thanks again @coreyfarrell and @isaacs - I've landed the update in Jest now and removed the |
Fixed #183. I don't know how to write a test here without basically implementing
require
within the test.fs
returns the same core module no matter what, so it should deduplicate correctly regardless ofimportFresh
or not