thlorenz / proxyquireify

browserify >= v2 version of proxyquire. Mocks out browserify's require to allow stubbing out dependencies while testing.
MIT License
152 stars 24 forks source link

[X-Post] Help find a reasonable solution to work with babel-plugin-rewire #52

Closed TheSavior closed 8 years ago

TheSavior commented 8 years ago

This is a cross post of issue https://github.com/speedskater/babel-plugin-rewire/issues/117 in order for us to figure out how these two modules can not break each other.

Babel-plugin-rewire, in order to support rewriting const variables, modifies the source of files to have every variable access go through a proxy function.

This is breaking proxyquireify's ability to find the requires and add the call to require to get browserify to include the file:

/* proxyquireify injected requires to make browserify include dependencies in the bundle */ 
/* istanbul ignore next */; 
(function __makeBrowserifyIncludeModule__() { require('./other_file');});

While it is directly babel-plugin-rewire's fault for breaking compatibility with proxyquireify, I'm not sure what the correct approach is. This is a cross post from the issue at babel-plugin-rewire. Reasonable approaches might be to make proxyquireify's detection of requires a little more robust, or to have babel-plugin-rewire support blacklisting certain things.

bendrucker commented 8 years ago

I'm up for reviewing a PR if you can figure out a solution but can't offer much beyond that. Static analysis is inherently limited and requires parseable syntax. From looking at your other issue the only fix would be to specifically hardcode knowledge of rewire's code generation which I'm not up for doing.