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
i'm coming here by way of execa having hit upon a fairly gnarly edge-case:
let's say you have a js script that tries to execute a file via execa and the file it executes runs which. if you run that script via npm - e.g. npm run my-script.js - cross-spawn's which dependency overrides the native one and can produce different / unexpected results.
this is due to the which dependency (source) installing a which bin into node_modules/.bin (source) combined with the behavior of npm run:
In addition to the shell’s pre-existing PATH, npm run adds node_modules/.bin to the PATH provided to scripts
the later uses a windows-style path b/c it relies on node's view of the environment (vs. cygwin' bash's view).
it gets worse when you try to look for an executable script that is not an .exe - e.g. bash -c "which libtool". in this case, the node / npm version of which returns nothing while the native version correctly locates the script in /usr/bin/libtool
my work-around at the moment is to simply not use npm run to execute my script. naively, i wonder if there's a way to avoid having the which dependency install a bin (since it looks like cross-spawn only ever uses the dependency via require('which').
🤷♂
The text was updated successfully, but these errors were encountered:
hey there 👋
thanks for a very helpful lib 🙏👍
i'm coming here by way of execa having hit upon a fairly gnarly edge-case:
let's say you have a js script that tries to execute a file via
execa
and the file it executes runswhich
. if you run that script via npm - e.g.npm run my-script.js
- cross-spawn'swhich
dependency overrides the native one and can produce different / unexpected results.this is due to the
which
dependency (source) installing awhich
bin intonode_modules/.bin
(source) combined with the behavior ofnpm run
:(source)
in my case, i was trying to run a script file on windows using cygwin. within powershell, running:
gave me:
but doing the same using a node script run via
npm run
:gave me:
the later uses a windows-style path b/c it relies on node's view of the environment (vs. cygwin' bash's view).
it gets worse when you try to look for an executable script that is not an
.exe
- e.g.bash -c "which libtool"
. in this case, the node / npm version ofwhich
returns nothing while the native version correctly locates the script in/usr/bin/libtool
my work-around at the moment is to simply not use
npm run
to execute my script. naively, i wonder if there's a way to avoid having thewhich
dependency install a bin (since it looks likecross-spawn
only ever uses the dependency viarequire('which')
.🤷♂
The text was updated successfully, but these errors were encountered: