run-script: Add option to ignore the current node executable for PATH #13409
Conversation
c893c10
to
99ed709
Compare
I assume the |
That's part of what the I'll flag this again and see if we can discuss whatever made us want to discuss it. Thanks for the patch! :) |
Aye, thanks for the explanation! |
The CLI team finally had an opportunity to discuss this. Previous discussions:
As you can see, this has been a long and thorny discussion, and we've reversed ourselves a number of times. Our first task was to look at the discussion thus far, and determine whether it's possible to resolve this issue without adding additional configuration (i.e. find some kind of default behavior that will satisfy all of the use cases enumerated in this discussion). The answer to that appears to be "no", because there are two conflicting use cases:
If we were able to determine at runtime unerringly that a tool is meant to be run with Node, then we could just invoke those scripts with the Therefore, yeah, this needs to be something configurable, and put in the hands of the end user, who has the most information available to determine what behavior is going to break the fewest things. Additionally, @zkat made a persuasive case that the most reasonable default behavior is to not prepend One last thing that would be extremely helpful for users would be to add to the code that determines which version of node to use a check to see whether These are a bunch of changes, and I understand if that’s too much for you to pick up and change here, but this is what we’d like to see land as part of |
Yes! It’s late here and I’m busy tomorrow, so give me a few days, but I still care about this and feel like I’m already getting more than I asked for.
Ack! I’ll definitely think about this in more detail, though, because doing this in the naïve way would probably mean showing that warning to everyone who runs something like To clarify, you’d like to see:
|
If you want access to this in
Correct. Thanks for being flexible! |
Yeah no, of course the former is most important; UX > code aesthetics, no doubt about that. I think most of the time I can tell my personal motivation from what’s important in the big picture pretty well, even if they are not the same. ;) I think I was just misunderstanding you – what I was trying to say is that I’d like to see ways to explicitly tell npm which behaviour to assume (always prepend to I’ve been busy today, but I should be able to update this PR tomorrow. (And just to be sure we’re on the same page: the 1:1 reversed logic of this would be an option that tells npm to auto-determine whether it should prepend Sorry if you feel like I’m holding anything up here! |
There's no rush! The CLI team decided, in our usual, free-wheeling manner, that our target release date for
As an |
Add a `--scripts-prepend-node-path` option that controls `npm`’s behaviour with respect to adding the directory of the current `node` executable to the `PATH`, even if that means that `npm` will invoke a different `node` executable than the one which it is running. This is a non-invasive solution to some of the problems described in npm#12318. It should not come with any drawbacks for npm’s side, as it shifts the responsibility of making sure that the `PATH` variable contains everything it should to whoever invoked npm with `--scripts-prepend-node-path=false`. While npm#12968 may have addressed some of the problems described there, it does not help in the case that the `PATH` has explicitly been overridden with the intention of having a different `node` executed.
…-prepend-node-path As one of the motivations for introducing `--scripts-prepend-node-path` is that `spawn-wrap` (which npm itself uses for coverage) can make use of that option, anticipate that change in order to not break the test suite when updating that dependency at a later point.
Adds a setting that is basically equivalent to `--scripts-prepend-node-path=false` but emits a warning informing the user about the existence of the option in the cases in which `npm` currently modifies `PATH`, as sometimes that’s in the user’s interest.
99ed709
to
aaba792
Compare
So, I’ve updated this! I’ve called the option I’ve expanded it a tiny bit to address all the use cases that are at the table (I think), to have So… yeah, please review and let me hear your thoughts. I know it seems like the complexity has increased a bit here, but the diff for the actual logic is no bigger than +23/-3, I’d consider that okay.
That’s your call, for the And on the chance of going overly off-topic here… if your plan is releasing |
…-only` Change the default behaviour of npm to never prepending the current node executable’s directory to `PATH` but printing a warning in the cases in which it previously did.
aaba792
to
63fc204
Compare
Add a `--scripts-prepend-node-path` option that controls `npm`’s behaviour with respect to adding the directory of the current `node` executable to the `PATH`, even if that means that `npm` will invoke a different `node` executable than the one which it is running. This is a non-invasive solution to some of the problems described in #12318. It should not come with any drawbacks for npm’s side, as it shifts the responsibility of making sure that the `PATH` variable contains everything it should to whoever invoked npm with `--scripts-prepend-node-path=false`. While #12968 may have addressed some of the problems described there, it does not help in the case that the `PATH` has explicitly been overridden with the intention of having a different `node` executed. [squash] test: anticipate coverage tooling possibly setting --scripts-prepend-node-path As one of the motivations for introducing `--scripts-prepend-node-path` is that `spawn-wrap` (which npm itself uses for coverage) can make use of that option, anticipate that change in order to not break the test suite when updating that dependency at a later point. [squash] tests for scripts-prepend-node-path=auto [squash] implement `warn-only` setting for `--scripts-prepend-node-path` Adds a setting that is basically equivalent to `--scripts-prepend-node-path=false` but emits a warning informing the user about the existence of the option in the cases in which `npm` currently modifies `PATH`, as sometimes that’s in the user’s interest. [squash] fixup tests for windows PR-URL: #13409 Credit: @addaleax Reviewed-By: @zkat Reviewed-By: @othiym23
I know a lot of time has already been spent arguing about this topic, but I still think this is the right thing to do and I at least want to propose it. No hard feelings if you decide to turn this PR down on principle!
Also, ping @isaacs on whether he’d accept a patch like addaleax/spawn-wrap@e4294c0 that could, in the long run, replace all other npm-specific hacks that needed to be built into
spawn-wrap
in the past few months.Add a
--scripts-ignore-node-path
option that makesnpm
assume its behaviour from prior to v3.7.0, namely not adding the directory of the currentnode
executable to thePATH
, even if that means thatnpm
will invoke a differentnode
executable than the one which it is running.This is a non-invasive solution to some of the problems described in #12318. It should not come with any drawbacks for npm’s side, as it shifts the responsibility of making sure that the
PATH
variable contains everything it should to whoever invoked npm with--scripts-ignore-node-path
.While #12968 may have addressed some of the problems described there, it does not help in the case that the
PATH
has explicitly been overridden with the intention of having a differentnode
executed (This is the case forspawn-wrap
).