Closed w8jcik closed 6 years ago
That's tricky. If the node module is in CJS there's nothing this plugin can do, since there are no exports to rewire. If it's in ESM, you could try configuring Babel to process that module, which should add the rewire
functions.
This plugin doesn't touch your imports, but there are other tools that do: e.g. proxyquire, rewire or babel-plugin-rewire.
I could try looking at rewiring imports (e.g. create a new plugin - babel-plugin-rewire-imports
) if you have any good suggestions on how the API should look.
Yeah, forgot to mention that imports might be tricky to mock/stub/rewire, because unlike CJS, in ESM you're importing a live binding and not a value (explanation). So we first need to find a reliable technique to do this without breaking existing code.
Sorry for being not responsive and thank you for great explanation.
It is logical that this package cannot do it and it is not that big issue.
Of course some babel-rewire-imports
with matching API would be great but I am happy enough with this one being stable and working as intended.
You could still put it into the README.md
for clarification (and close this issue).
Readme kind of already mentions this:
Unlike babel-plugin-rewire it doesn't modify the module internals (e.g. imports and top-level variables and functions).
Because modules coming from
node_modules
are not handled by Babel they don't haverewire$
functions. Do you have some solution for this problem?