[Fix] nvm_die_on_prefix: check a nonexistent prefix on Windows

On Windows, `npm_config_prefix` is resolved with `cd` + `pwd` so it can be compared with `$NVM_DIR`.
When the directory does not exist yet, that resolution fails,
the value becomes empty, and the check is skipped.
Keep the value as given in that case, like on other systems.

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Wei-Lun Li <b84330808@gmail.com>
This commit is contained in:
Wei-Lun Li authored and Jordan Harband committed 2026-10-29 09:48:45 +09:00
1 parent c7a1b344da
commit 970ed9ea18
2 files changed
+12 -2

No files matched your search

+4 -2
View File
@@ -4223,8 +4223,10 @@ nvm_die_on_prefix() {
NVM_OS="$(nvm_get_os)"
local NVM_CONFIG_VALUE
eval "NVM_CONFIG_VALUE=\"\$${NVM_NPM_CONFIG_x_PREFIX_ENV}\""
if [ -n "${NVM_CONFIG_VALUE-}" ] && [ "_${NVM_OS}" = "_win" ]; then
NVM_CONFIG_VALUE="$(nvm_cd "$NVM_CONFIG_VALUE" 2>/dev/null && pwd)"
local NVM_CONFIG_DIR
# a prefix that does not exist yet can not be resolved, so it is checked as-is
if [ -n "${NVM_CONFIG_VALUE-}" ] && [ "_${NVM_OS}" = "_win" ] && NVM_CONFIG_DIR="$(nvm_cd "$NVM_CONFIG_VALUE" 2>/dev/null && pwd)"; then
NVM_CONFIG_VALUE="${NVM_CONFIG_DIR}"
fi
if [ -n "${NVM_CONFIG_VALUE-}" ] && ! nvm_tree_contains_path "${NVM_DIR}" "${NVM_CONFIG_VALUE}"; then
nvm deactivate >/dev/null 2>&1