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

Replace prelude in pipeline when reset is called #17

Closed ellbee closed 9 years ago

ellbee commented 9 years ago

This pull request should enable proxyquireify to work when bundle() is called multiple times on the same browserify instance. This is useful e.g. if you are using watchify to take advantage of its caching facilities for faster builds.

var b = browserify(entryPoint, watchify.args);

b = watchify(b);
b.plugin(proxyquireify.plugin)
b.bundle()

b.on('update', b.bundle);

When watchify fires the update event, b.bundle() calls b.reset() which creates a new pipeline. This new pipeline does not contain the browser-pack with the modified prelude that proxyquireify spliced in when the plugin was registered. So all calls to bundle after the first use the standard browserify prelude instead of proxyquireify's.

This pull request splices the proxyquireify browser-pack into the pipeline each time the reset event is emitted by browserify.

thlorenz commented 9 years ago

Could you please provide a description, possibly an example explaining what it fixes. I see the referenced issue, but a quick summary of the problem/solution would be nice.

Otherwise LGTM, pulling in @jhiesey to give his ok as well since he did the last major overhaul.

ellbee commented 9 years ago

@thlorenz I've given the explanation a go, let me know if I need to do anything else. Cheers.

thlorenz commented 9 years ago

Makes more sense now @ellbee, gonna wait for a comment by @jhiesey but LGTM.

jhiesey commented 9 years ago

I can take a look tonight

jhiesey commented 9 years ago

Sorry I forgot to look into this. It looks fine to me.

thlorenz commented 9 years ago

Thanks, went out with 1.1.