-
-
Notifications
You must be signed in to change notification settings - Fork 12
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
Fix repeated execPath
directory
#5
Conversation
While it will fix my own particular case, I still have concerns about doing this in the first place. If I call a Node binary through its direct path (assuming that this binary isn't in the PATH, for example if I want to call it directly from its (That said, I think this change is the safest thing that could go in a minor so it's fine by me to land it - I'd just ask to reconsider this behavior being the default in the next major) |
@arcanis If by "local binaries" you mean the binaries inside We are working on a major new |
Yep, unfortunately in the case of Yarn we don't use The |
Correct
It's definitely needed. I don't remember exactly all the reasons, but even npm is using this technique. While |
This makes sense. Now it seems to me the core problem is that several tools are competing for priority in the Although this is more of a workaround, this PR might solve the problem for |
If we merge this, it means |
Yes I see what you mean. There should be no real cases where a user would want to use a different Node.js binary in the top process and the child processes. I.e. enforcing the same On the other hand, as a side effect, all the binaries inside the same directory as the current
Is there a way to solve the issues created by this side effect, without requiring users to use |
In the general case maybe, but those kind of assumptions are bound to break as soon as you go on slightly different setups. We have two real-life examples ( Now you might say that users can just toggle the feature off if they don't need it, but the fact is that they won't because 1/ they don't know what are the drawbacks of this option 2/ they tend to not even be aware of this option in the first place - they just use Hence why the default behavior should be the safest and most expected one imo. |
Trying to resolve the deadlock, I think the way forward might be to a boolean option
Like this What do you think? |
Unless the default is Counterproposal: do not add the node path to the PATH if Yarn is detected in the project root (ie if |
@arcanis Based on @sindresorhus comment above, a solution where Also this issue is not only about Yarn. sindresorhus/execa#153 is affecting by it as well. I.e. a way to move forward might be:
|
I probably don't get it. Sorry if I'm missing something but believe that we can fix that. But before few months created a package ( Disclaimer: THAT'S NOT A PROMOTION, please. 😺 I've done that package, exactly because I needed a way to make It was also because The thing is that I don't even use
Then just prepend them on (see the source code of So, example usage const mod = require('module');
const proc = require('process');
// which uses `global-dirs` (by @jonschlinkert) under the hood
const allModulesPaths = require('all-module-paths');
const paths = mod._nodeModulePaths(proc.cwd());
// see the screenshots below
const dirs = allModulesPaths({ paths });
console.log(dirs.allPaths.binaries)
// => binaries:
// [ '/home/charlike/dev/foo-bar/node_modules/.bin',
// '/home/charlike/dev/node_modules/.bin',
// '/home/charlike/node_modules/.bin',
// '/home/charlike/.node_modules/.bin',
// '/home/charlike/.node_libraries/.bin',
// '/home/charlike/.nvm/versions/node/v8.16.0/bin',
// '/home/charlike/.config/yarn/global/node_modules/.bin' ]
const PATH = dirs.allPaths.binaries.join(':');
proc.env.PATH = `${PATH}:${process.env.PATH}`; And that's it, it works flawlessly. I don't get why we should care and mess with the priorities inside the already given to us So, to now we have everything, except the node bin itself, right? So add it at the very first place? |
Thanks for your input @tunnckoCore! Maybe @sindresorhus will have a different take of it, but in my opinion this solution looks a little complicated and I'm wondering if this might not add extra complexity to the original problem. I think this could deserve a separate PR though with no code in the PR nor source code screenshot or implementation, but just a clear description of the algorithm. |
The thing is that I'm not exactly sure what's the problem. From the discussions around the issues here and in execa, I'm understanding that the question is where exactly to be the |
I'm having a similar problem as @arcanis in one of my projects using execa.
It is a thin wrapper around execa. The wrapper is called with the user's current Node.js version ( However that does not work with Possible workarounds in my case:
However I think it would be better to:
|
This is another implementation for #3 since that PR became stale and does not include tests.
This might solve the following issues on
execa
:npm-run-path
unshiftsdirname(process.execPath)
to the$PATH
. From my understanding (correct me if I'm wrong) the reason is this:node
installednode
different from the default one (i.e. not in$PATH
) might be the one currently runningnode
gets called in a child process, the same Node version will be used.Now I am wondering how this would happen in practice. For example,
nvm use
andnvm exec
correctly modify the$PATH
, so this is not a problem withnvm
. @sindresorhus maybe you have more information on why this is needed?Now the problem is that this conflicts with other tools that are competing for priority in the
$PATH
.I am not sure whether firing the right
node
version or giving priority to those other tools is a decidable problem with an objective solution? But at least what we could do is not do anything ifdirname(process.execPath)
is already present in the$PATH
, which this PR implements.Current limitation: this does not work if
dirname(process.execPath)
is symlinked and referenced under different symlink names under both the$PATH
andprocess.execPath
. This is harder to fix since the current code is synchronous and relies onpath.*()
notfs.*()
.