Skip to content
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

supporting require aliases #13

Open
jarofghosts opened this issue Jun 17, 2015 · 5 comments
Open

supporting require aliases #13

jarofghosts opened this issue Jun 17, 2015 · 5 comments

Comments

@jarofghosts
Copy link

hey, there!

i was wondering if there was any plan to support specifying aliases for require in the makeRequireTransform method. i ask because of things like proxyquireify and others that do "hygienic" require monkey-patching by providing an alias, but still need to be potentially transformed.

i started poking at PRing the change for discussion, but encountered a brick wall in the form of (what seems like) necessarily breaking the current API. ideally, in my estimation, the require "word" would be somehow linked to each "argument" in the transform callback. because of this, i decided to instead ask if it was even something considered worth supporting, and if so if there was any preference about how to support it. if desired, i am more than willing to do the work to support it.

thoughts?

thanks for your time!

@jwalton
Copy link
Contributor

jwalton commented Jun 17, 2015

You're looking to, for example, transform:

proxyquire "foo"

into

proxyquire "bar"

? Could you not just pass in an options.functionName and change this line to use it in place of 'require'? I wonder if it might not be better to make a functionTransform, though, since you could easily apply this same logic to just about any function you care to name.

@jarofghosts
Copy link
Author

i would prefer to support multiple in one go, so that you can use the same transform for every require alias. it might be far-fetched and possibly not a common enough case to warrant inclusion, which is why i asked.

@jarofghosts
Copy link
Author

to answer your question, though, yes i would like to, for example, have this work:

const thing = require('thing')

const otherThing = proxyquire('other-thing')

(transform happens)

const thing = require('transformed-thing')

const otherThing = proxyquire('transformed-other-thing')

@jwalton
Copy link
Contributor

jwalton commented Jun 23, 2015

So what breaking changes were you thinking about, then?

@jarofghosts
Copy link
Author

sooo.. i was actually asking about this so that i could PR pkgify to support it. in the end, i just went off and made my own that supported it rather than complicate other peoples' modules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants