thlorenz / proxyquireify

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

Doesn't work with compiled code #24

Closed bendrucker closed 9 years ago

bendrucker commented 9 years ago

Anything that's compiled from a non-JS language will retain its file extension and be skipped because of https://github.com/thlorenz/proxyquireify/blob/09d6452dc3de14b0faf9463eecb3590381b56360/lib/transform.js#L16

Instead the transform should exclude .json files and assume everything else is valid JS.

thlorenz commented 9 years ago

Not sure about just json files, we could end up parsing all kinds of files that run through including .coffee (coffeify), .txt (brfs) and so on.

I'd vote for making this configurable instead.

bendrucker commented 9 years ago

Right, but the user is expected to order transforms correctly such that by the time code is making it to proxyquireify it's valid js. Except for json, which Browserify handles directly and represents a special case.

https://github.com/substack/brfs/blob/5e977999074eca120c93659dd971c203e78d6857/index.js#L9 https://github.com/substack/bulkify/blob/799f4420c1aa9173ed395a2425f7974077e06333/index.js#L7

The only time you need to specify a whitelist of extensions for a transform is when it receives input that's not JavaScript. The extension (except w/ JSON) isn't relevant.

thlorenz commented 9 years ago

Well they may not order it correctly and I'd like this to be easy to use. I'd expect lots of filed issues if we change this now.

Two options I see here:

bendrucker commented 9 years ago

I don't see this as nearly as disruptive a change. I found one issue at brfs about it:

https://github.com/substack/brfs/issues/15

None at https://github.com/hughsk/envify

Allowing people to opt in/out doesn't prevent them from causing problems as far as I can think of. If you're using CoffeeScript or any other compiled-to-JS language + proxyquireify, you need to order your transforms correctly anyway for things to work.

This would only affect transforms that take in text files and output module.exports=${text}. I'm speculating that people with that kind of setup are sophisticated enough to understand how to order their transforms or at least interpret an error.

thlorenz commented 9 years ago

Well but if it breaks backwards compat it needs to go out as major. And it would break in situations where transforms aren't correctly ordered.

alanrubin commented 9 years ago

Wow @bendrucker thanks for the great work, you were much faster then me. Looking forward to see those PR merged to the proxyquireify project !