You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.
I have the feeling that the Node community has still problems figuring out how to handle locally vs. globally installed packages and binaries despite talking about this in detail for years (like here in the official Node blog).
So what's the problem? At least that's how I understand it... A globally installed package is just so much easier to use. But besides that, we rarely really need a global package. We want a package with a specific version and configuration for all our projects - which a locally installed package solves for us. But a locally installed package isn't that easy to use. We can call node_modules/.bin/foo or we can alias the executable in the "scripts" part of our package.json and call something like npm run foo. The last way is sometimes a little bit easier and we can preset some params (like foo --bar) and it works anywhere inside the current package, but it's more verbose (and uncommon for many) to pass params with the -- limiter (see #3494). The first way is simpler to use with params, but we need to rewrite the path if we are in subdirectories of the current package. No much difference between both ways, but it's not as simple as typing foo.
So my question: Can we find a way to add locally installed packages to PATH, too? An good reasons against that? Can't we just recursively add all executables to PATH dependent on our current working directory? That would very much fit Nodes require logic.
It sound so cool (imo). Install foo locally and call foo in our current project. If we are in a different project without foo, we could fallback to a globally installed foo.
The text was updated successfully, but these errors were encountered:
To add all those directories to PATH. I know no way of adding all folders recursively up to the top, but enumerating first few paths explicitly seems to be good enough.
So yes. I wonder if there are any unwanted side-effects though.
othiym23
changed the title
Question: Can we add locally installed packages to PATH, too?
Can we add locally installed packages to PATH, too?
Jul 8, 2015
Setting up the paths is a big part of using package scripts. There are a bunch of good reasons related to trust and security to not just add arbitrary directories relative to the current path onto your PATH. That said, an alternative way to get at local scripts would be the much-mooted npm-exec helper binary, as discussed in #6053. As such, I'm going to close this issue as a duplicate of that one, with the corollary that the team (especially including me) really doesn't think it' s a good idea to tag ./node_modules/.bin onto your current path, which is part of the reason why npm will never export locally-installed binaries onto your path itself. This is pretty much the primary reason that global installs exist.
Thanks for your time, and your thoughtful description of the problem you're trying to solve.
I have the feeling that the Node community has still problems figuring out how to handle locally vs. globally installed packages and binaries despite talking about this in detail for years (like here in the official Node blog).
I think packages like grunt-cli are a good example of this. The most recent example of this (for me) was this discussion about why it is good or bad to export Karmas binary.
So what's the problem? At least that's how I understand it... A globally installed package is just so much easier to use. But besides that, we rarely really need a global package. We want a package with a specific version and configuration for all our projects - which a locally installed package solves for us. But a locally installed package isn't that easy to use. We can call
node_modules/.bin/foo
or we can alias the executable in the"scripts"
part of ourpackage.json
and call something likenpm run foo
. The last way is sometimes a little bit easier and we can preset some params (likefoo --bar
) and it works anywhere inside the current package, but it's more verbose (and uncommon for many) to pass params with the--
limiter (see #3494). The first way is simpler to use with params, but we need to rewrite the path if we are in subdirectories of the current package. No much difference between both ways, but it's not as simple as typingfoo
.So my question: Can we find a way to add locally installed packages to
PATH
, too? An good reasons against that? Can't we just recursively add all executables toPATH
dependent on our current working directory? That would very much fit Nodesrequire
logic.It sound so cool (imo). Install
foo
locally and callfoo
in our current project. If we are in a different project withoutfoo
, we could fallback to a globally installedfoo
.The text was updated successfully, but these errors were encountered: