-
Notifications
You must be signed in to change notification settings - Fork 128
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
Enable rewiring rewired modules #78
Conversation
👍 |
without this, rewire fails when running code with wallaby.js |
@jhnns Can this get some love? |
Mhmm I'm not sure... @boneskull In your example, wouldn't redefining Usually, |
@jhnns From your comments it seems like there is some misunderstanding between how all of our different rewire based packages work. Your modules rewire and rewire-weback have the same use case. You can call rewireify, rewire-global, and babel-plugin-rewire have a slightly different usage pattern. Instead of explicitly calling So I think all of the module authors want us to all have the same API once rewire is enabled for a module, but we have different requirements for how rewire is injected into a module. In order for our modules to all be closer to rewire core, rewire-core needs to support both function injection patterns. I'm open to suggestions as to how you propose we get there. |
@jhnns regardless, rewire fails to work when run under wallaby due to this problem. @ArtemGovorov could probably provided more accurate information if asked, but I think what's happening is:
Unless it can be shown that setting In case you disagree on philosophical grounds, I'm of the opinion that the responsibility of a JS library ends once it has done what it was intended to do. It is not necessary for any library to prevent a consumer from augmenting its functionality thereafter, except in rare circumstances. Perhaps this is especially so for rewire, which is intended to be run in test and augments its consumers' module(s)? If JS didn't allow this behavior by nature, rewire probably wouldn't even exist. (FWIW, babel-plugin-rewire accepted a PR of mine to address this very issue.) |
@boneskull You've described it pretty accurately for |
@ArtemGovorov I don't have one handy, but I can provide an example if it crops up again |
@TheSavior that are all valid points. Maybe we should change the way how I'm just not happy that there are so many modules that do it "almost" the rewire way, because it can behave very differently in certain situations. It's just too much confusion for beginners. Concerning this PR: I'm not quite sure... maybe I'll merge this PR as a quickfix. But it's not ideal because it obscures a conceptional problem underneath. |
@jhnns, I too am unhappy that rewire, rewireify, rewire-global, and babel-plugin-rewire are all slightly different. That is part of why I've been starting the discussions about how to make them all have the same api. This PR is a requirement that is blocking rewireify and rewire-global from using the same modules as rewire and thus having more shared functionality. I think we want the same things here. |
babel-plugin-rewire, rewireify, and rewire-global all hook require, injecting the functions into every module.
When we use getDefinePropertySrc we run into problems on modules that pass through their dependencies unchanged. See this failing test on rewire-global: https://github.com/TheSavior/rewire-global/pull/13/files
The error we get is:
Before starting to use the upstream modules from rewire in rewireify and rewire-global, we got around this by setting the properties to writable: https://github.com/i-like-robots/rewireify/blob/master/lib/index.js#L37
Rewire does not set them to writable.