mirror of
https://github.com/nvm-sh/nvm.git
synced 2026-07-18 12:58:21 +08:00
[Fix] nvm install: migrate packages/set alias when target is already installed
When `nvm install <target>` found that `<target>` was already installed, the post-`nvm use` steps (`--reinstall-packages-from`, default packages, and `--alias`/`--default`) were gated on `[ $EXIT_CODE -ne 0 ]`. Since that branch is only entered when `nvm use` succeeded (EXIT_CODE == 0), those conditions were always false, so the steps were silently skipped. The fresh-install branch correctly uses `-eq 0`; mirror that here so `--reinstall-packages-from` actually migrates global packages (and the alias/default get set) when the target version already exists. Includes a regression test covering the already-installed path. Fixes #3858
This commit is contained in:
@@ -3736,10 +3736,10 @@ nvm() {
|
||||
nvm install-latest-npm
|
||||
EXIT_CODE=$?
|
||||
fi
|
||||
if [ $EXIT_CODE -ne 0 ] && [ -z "${SKIP_DEFAULT_PACKAGES-}" ]; then
|
||||
if [ $EXIT_CODE -eq 0 ] && [ -z "${SKIP_DEFAULT_PACKAGES-}" ]; then
|
||||
nvm_install_default_packages
|
||||
fi
|
||||
if [ $EXIT_CODE -ne 0 ] && [ -n "${REINSTALL_PACKAGES_FROM-}" ] && [ "_${REINSTALL_PACKAGES_FROM}" != "_N/A" ]; then
|
||||
if [ $EXIT_CODE -eq 0 ] && [ -n "${REINSTALL_PACKAGES_FROM-}" ] && [ "_${REINSTALL_PACKAGES_FROM}" != "_N/A" ]; then
|
||||
nvm reinstall-packages "${REINSTALL_PACKAGES_FROM}"
|
||||
EXIT_CODE=$?
|
||||
fi
|
||||
@@ -3757,7 +3757,7 @@ nvm() {
|
||||
EXIT_CODE=$?
|
||||
fi
|
||||
|
||||
if [ $EXIT_CODE -ne 0 ] && [ -n "${ALIAS-}" ]; then
|
||||
if [ $EXIT_CODE -eq 0 ] && [ -n "${ALIAS-}" ]; then
|
||||
nvm alias "${ALIAS}" "${provided_version}"
|
||||
EXIT_CODE=$?
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user