-
Notifications
You must be signed in to change notification settings - Fork 30.5k
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
module: require relative from package root #1979
Comments
+0 from me. If we add it, I'd rather have this in a seperate method to avoid dealing with special characters. |
totally ok with separate method. Can even omit the ./ then.
|
I prefer a non-magic |
Could you clarify a bit what you want? As for packages, it should already work as expected and search the parent directories containing |
requiring files. especially helpful when you have a few top-level singletons, like 'services' 'router' etc. so in ./router/public/whatever you could just grab a service via:
|
It would seem like proof-of-concept for this could happen in user-land as a module published to npm. And, in fact, that might be the better place for it to live permanently. Currently, So that would have to be added in just for this functionality. I am aware of at least two projects that have a sort of "find the root of this project" logic/module in them. The first is |
Ah, alright. Now I get what you meant. Maybe |
@Trott yeah I was thinking a userland module would be the best way to do it, but then it's going to be an uphill battle to get things like browserify to support it (since a userland module would be digging into the extra stuff that node require has on it). Might be possible with a browserify transform I guess..? also, node does know about node_modules, in which case this issue could be redefined to say, go to the closes folder that contains node_modules. |
Why does this have to be in core? Unobvious require semantics for files could introduce weird bugs when one has several files with the same name in different places. If this was really needed, there would have been a module that does that already. If you base on |
On behalf of Babel, it would be easier for our ES6 import <-> node modules interop if there was not a different As for the functionality itself, this is a common problem, and it would be nice to have a canonical solution to it. OTOH making a symlink isn't that big of a deal. So I guess I'm neutral. |
|
@KoryNunn What will happen if you (accidently or not) put an unrelated |
@ChALkeR it wouldn't work. Bit of an edge case, and easy to debug, since the error would be:
which would tell you where the package.json is. |
@KoryNunn may I ask why you chose I think I would perfer less magic also, ala Is there any significant disadvantages to having such functionality in an npm module? |
@Fishrock123 I used ^ because it wasn't a standard path operator. Didn't want it to clash with anything else. As above, the reason to make it a 'nodeism' and not a module, is that it would create a standard which could be followed by other implementation such as browserify. I actually don't agree that a path symbol such as '^' is "magic" any more than '..' or '.', it'd just be new syntax. |
@KoryNunn That's quite common actually (I just made a quick search for Also, if we start to speak about standards, there are ES6 modules, and I hope to see everything converted to that at some point. And AFAIK there is no such thing as Also, please note that the
|
Implementing this would require unlocking the |
That isn't entirely correct per-say, but it is very likely to be, yes. |
Why isn't it? |
-1. This seems like something that can be done in userland. We shouldn't add more edge cases to the already locked module system. |
While I understand why this would be useful, I'm -1 on this for the reasons that I mentioned above. |
@KoryNunn A browserify transform should be able to pick this style of require up, especially if it's added as a separate API or module. One thing to note about changing the require statement – any package published that relies on new behavior has an implicit hard dependency on whatever version of io.js/node that it was first published in. That means packages that use that package also inherit that implicit hard dependency. It's difficult to introduce such changes because they have the potential of fracturing the ecosystem. It's safer to write this as a module + browserify transform that way the effects are self-contained. Packages using this functionality through such a module are usable by any version of Node, too! Closing this for now – if you write a package + transform for this functionality, let me know on this thread! I'd love to add it to a "modules solving common pain points" document that I'm working on. |
@chrisdickinson just noticed you asked to be informed of the userland implementations as per this discussion we created rooty and for browserify rootify |
Hope this hasn't been raised before, i did search..
Everyone has done this:
Why not add a symbol that resolves to the closest package.json?
Doesn't have to be a ^.
The text was updated successfully, but these errors were encountered: