defunctzombie / node-required

identifies which modules your script is using
67 stars 15 forks source link

support expression based requires #6

Closed bmeck closed 8 years ago

bmeck commented 11 years ago

For now at least filename / dirname and constants. Difficult when tracking anything more.

defunctzombie commented 11 years ago

Why do you need this when you have relative requires? Expression based requires lead to dark places imho.

I am willing to entertain valid examples that have no better way to do this without fixed require strings. On Feb 20, 2013 7:17 PM, "Bradley Meck" notifications@github.com wrote:

For now at least filename / dirname and constants. Difficult when tracking anything more.

— Reply to this email directly or view it on GitHubhttps://github.com/shtylman/node-required/issues/6.

bmeck commented 11 years ago

plugin based systems that are determined at runtime, this is a starting place.

On Wed, Feb 20, 2013 at 7:24 PM, Roman Shtylman notifications@github.comwrote:

Why do you need this when you have relative requires? Expression based requires lead to dark places imho.

I am willing to entertain valid examples that have no better way to do this without fixed require strings. On Feb 20, 2013 7:17 PM, "Bradley Meck" notifications@github.com wrote:

For now at least filename / dirname and constants. Difficult when tracking anything more.

— Reply to this email directly or view it on GitHub< https://github.com/shtylman/node-required/issues/6>.

— Reply to this email directly or view it on GitHubhttps://github.com/shtylman/node-required/issues/6#issuecomment-13867542.

defunctzombie commented 11 years ago

Sounds like people using the wrong approach honestly. I would like to see some actual js to support this claim. First thought is abuse of require instead of just doing something better or more applicable. On Feb 20, 2013 8:26 PM, "Bradley Meck" notifications@github.com wrote:

plugin based systems that are determined at runtime, this is a starting place.

On Wed, Feb 20, 2013 at 7:24 PM, Roman Shtylman notifications@github.comwrote:

Why do you need this when you have relative requires? Expression based requires lead to dark places imho.

I am willing to entertain valid examples that have no better way to do this without fixed require strings. On Feb 20, 2013 7:17 PM, "Bradley Meck" notifications@github.com wrote:

For now at least filename / dirname and constants. Difficult when tracking anything more.

— Reply to this email directly or view it on GitHub< https://github.com/shtylman/node-required/issues/6>.

— Reply to this email directly or view it on GitHub< https://github.com/shtylman/node-required/issues/6#issuecomment-13867542>.

— Reply to this email directly or view it on GitHubhttps://github.com/shtylman/node-required/issues/6#issuecomment-13867579.

bmeck commented 11 years ago

https://github.com/bmeck/broadway-pluggable

We use this to run configurations for plugins on various environments. Having to manually connect everything is troublesome when it differs per environ.

On Wed, Feb 20, 2013 at 7:28 PM, Roman Shtylman notifications@github.comwrote:

Sounds like people using the wrong approach honestly. I would like to see some actual js to support this claim. First thought is abuse of require instead of just doing something better or more applicable. On Feb 20, 2013 8:26 PM, "Bradley Meck" notifications@github.com wrote:

plugin based systems that are determined at runtime, this is a starting place.

On Wed, Feb 20, 2013 at 7:24 PM, Roman Shtylman < notifications@github.com>wrote:

Why do you need this when you have relative requires? Expression based requires lead to dark places imho.

I am willing to entertain valid examples that have no better way to do this without fixed require strings. On Feb 20, 2013 7:17 PM, "Bradley Meck" notifications@github.com wrote:

For now at least filename / dirname and constants. Difficult when tracking anything more.

— Reply to this email directly or view it on GitHub< https://github.com/shtylman/node-required/issues/6>.

— Reply to this email directly or view it on GitHub< https://github.com/shtylman/node-required/issues/6#issuecomment-13867542>.

— Reply to this email directly or view it on GitHub< https://github.com/shtylman/node-required/issues/6#issuecomment-13867579>.

— Reply to this email directly or view it on GitHubhttps://github.com/shtylman/node-required/issues/6#issuecomment-13867637.

bmeck commented 11 years ago

If not this, how about a hook that I can see the ast and change what the dep becomes in the final callback instead of null. If this is delegated to a plugin outside of required that seems fine.

defunctzombie commented 11 years ago

My gut feeling is that this is a bit abusive of require. The issue is that some things are only know at runtime require. That is just how it is. I don't want to turn this into a full interpreter to handle all sorts of crazy things. I would personally keep require fixed and simple and expose loading plugins via some other method. Or realize that you can't know ahead of time that you will be loading until you run it.

I am leaving the issue open for now as maybe supporting __dirname could be reasonable, but I don't think anything else is a good thing to do. Require is not a plugin system imho.

ghost commented 11 years ago

This would now be relatively straight-forward to implement using lexical-scope to only execute require() expressions that depend on known implicit values, but it seems like not such a great thing to support since static require strings are much simpler and generally a better idea. Instead of hacking this directly into required, it would make more sense for required to take a detective-style static analysis function as an optional parameter. Then you could pass in whichever kind of custom static analysis you like and even support in-memory transpilers, not that those are a particularly good idea either.