execa icon indicating copy to clipboard operation
execa copied to clipboard

Improve interaction of the `preferLocal`, `node` and `nodePath` options

Open ehmicky opened this issue 1 year ago • 2 comments

Right now:

  1. If the node is true, the nodePath option is used to create the process.
  2. If the preferLocal is true, the nodePath option is used in the child process itself.
  3. If the preferLocal is true, local binaries can be run.

Using preferLocal for 2 is a little unexpected. It seems like we should be using node: true instead since this relates to running Node.js and the nodePath option. Also, running local binaries is rather unrelated to choosing the Node.js version. It is odd to couple them.

On the other hand, by making 2 use node: true instead, we would be ensuring that the nodePath option is always used both to create the process and in the child process itself. For example, execaNode() currently uses the nodePath option in one case but not the other. Users should expect a consistent Node.js version both in the child process and the "grand-child" processes.

What do you think?

ehmicky avatar Feb 13 '24 20:02 ehmicky

I agree. nodePath should be consistently used.

sindresorhus avatar Feb 13 '24 20:02 sindresorhus

I think the reason for the current situation was due to implementation details. Namely, both features are implemented using the PATH environment variable, so the nodePath feature got piggybacked onto the preferLocal feature using the npm-run-path library.

I have created https://github.com/sindresorhus/npm-run-path/issues/17 to see if we could add some options to allow decoupling those two features in npm-run-path.

ehmicky avatar Feb 13 '24 20:02 ehmicky