[Fix] install.sh: nvm_check_global_modules: don't run a Windows npm under WSL
Under WSL, `PATH` can include a Windows Node install, so `command -v npm` can find its `npm` shell shim, which then failed against Windows paths. That npm is not a system node that nvm would shadow, so under WSL, skip an npm that has an `npm.cmd` beside it: both the Node installer and npm's own shims put one there. Outside WSL (eg, Git Bash or Cygwin), a Windows npm is the system node, so the warning is kept. Fixes #3700. Signed-off-by: NUAAwqy <146524024+NUAAwqy@users.noreply.github.com> Co-Authored-By: Codex <noreply@openai.com>
This commit is contained in:
1 parent
3fda4d5542
commit
f0d372b01b
3 files changed
+79
-2
No files matched your search
@@ -5,11 +5,12 @@ cleanup () {
|
||||
unset npm_config_prefix
|
||||
|
||||
rm -f npm
|
||||
[ -z "${WINDOWS_NPM_DIR-}" ] || rm -rf "${WINDOWS_NPM_DIR}"
|
||||
PATH="$ORIGINAL_PATH"
|
||||
NVM_DIR="$ORIGINAL_NVM_DIR"
|
||||
|
||||
unset -f setup cleanup die
|
||||
unset message ORIGINAL_PATH ORIGINAL_NVM_DIR
|
||||
unset message ORIGINAL_PATH ORIGINAL_NVM_DIR WINDOWS_NPM_DIR
|
||||
}
|
||||
die () { echo "$@" ; cleanup ; exit 1; }
|
||||
|
||||
@@ -61,5 +62,26 @@ chmod +x npm
|
||||
message=$(nvm_check_global_modules)
|
||||
[ -z "$message" ] || die "nvm_check_global_modules should have not printed a notice when npm was unavailable; got:\n${message}"
|
||||
|
||||
# Faking a Windows Node's npm, with a global module installed
|
||||
WINDOWS_NPM_DIR="$(mktemp -d)"
|
||||
cat <<'SH' >"${WINDOWS_NPM_DIR}/npm"
|
||||
#!/bin/sh
|
||||
case "$1" in
|
||||
--version) echo '10.0.0' ;;
|
||||
list) printf '%s\n' 'npm@10.0.0' '└── windows-global@1.0.0' ;;
|
||||
esac
|
||||
SH
|
||||
touch "${WINDOWS_NPM_DIR}/npm.cmd"
|
||||
chmod +x "${WINDOWS_NPM_DIR}/npm"
|
||||
PATH="${WINDOWS_NPM_DIR}:${ORIGINAL_PATH}"
|
||||
|
||||
nvm_is_wsl() { return 0; }
|
||||
message=$(nvm_check_global_modules)
|
||||
[ -z "$message" ] || die "nvm_check_global_modules should not run a Windows npm under WSL; got:\n${message}"
|
||||
|
||||
nvm_is_wsl() { return 1; }
|
||||
message=$(nvm_check_global_modules)
|
||||
[ -n "$message" ] || die 'nvm_check_global_modules should still warn about a Windows npm outside WSL, where it is the system node'
|
||||
|
||||
|
||||
cleanup
|
||||
Reference in new issue
Block a user