From df9ac58f8b73f7cdddad67396f1992acb0706b02 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 11 Mar 2025 13:16:58 -0700 Subject: [PATCH] [Fix] `reinstall-packages`: do not reinstall corepack Fixes #3544 --- nvm.sh | 2 +- .../should work as expected | 2 +- .../nvm reinstall-packages/works with no installs | 15 ++++++++++++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/nvm.sh b/nvm.sh index 736fb8e..6540356 100755 --- a/nvm.sh +++ b/nvm.sh @@ -2740,7 +2740,7 @@ nvm_npm_global_modules() { NPMLIST=$(nvm use "${VERSION}" >/dev/null && npm list -g --depth=0 2>/dev/null | command sed -e '1d' -e '/UNMET PEER DEPENDENCY/d') local INSTALLS - INSTALLS=$(nvm_echo "${NPMLIST}" | command sed -e '/ -> / d' -e '/\(empty\)/ d' -e 's/^.* \(.*@[^ ]*\).*/\1/' -e '/^npm@[^ ]*.*$/ d' | command xargs) + INSTALLS=$(nvm_echo "${NPMLIST}" | command sed -e '/ -> / d' -e '/\(empty\)/ d' -e 's/^.* \(.*@[^ ]*\).*/\1/' -e '/^npm@[^ ]*.*$/ d' -e '/^corepack@[^ ]*.*$/ d' | command xargs) local LINKS LINKS="$(nvm_echo "${NPMLIST}" | command sed -n 's/.* -> \(.*\)/\1/ p')" diff --git a/test/slow/nvm reinstall-packages/should work as expected b/test/slow/nvm reinstall-packages/should work as expected index 755c6f6..b705188 100755 --- a/test/slow/nvm reinstall-packages/should work as expected +++ b/test/slow/nvm reinstall-packages/should work as expected @@ -16,7 +16,7 @@ EXPECTED_PACKAGES_INSTALL="autoprefixer bower david@11 grunt-cli grunth-cli http echo "$EXPECTED_PACKAGES_INSTALL" | sed -e 's/test-npmlink //' | xargs npm install -g --quiet get_packages() { - npm list -g --depth=0 | \sed -e '1 d' -e 's/^.* \(.*\)@.*/\1/' -e '/^npm$/ d' | xargs + npm list -g --depth=0 | \sed -e '1 d' -e 's/^.* \(.*\)@.*/\1/' -e '/^npm$/ d' -e '/^corepack$/ d' | xargs } nvm use 0.10.29 diff --git a/test/slow/nvm reinstall-packages/works with no installs b/test/slow/nvm reinstall-packages/works with no installs index ade209a..ccd4632 100755 --- a/test/slow/nvm reinstall-packages/works with no installs +++ b/test/slow/nvm reinstall-packages/works with no installs @@ -5,7 +5,7 @@ die () { echo "$@" ; exit 1; } \. ../../../nvm.sh get_packages() { - npm list -g --depth=0 | \sed -e '1 d' -e 's/^.* \(.*\)@.*/\1/' -e '/^npm$/ d' | xargs + npm list -g --depth=0 | \sed -e '1 d' -e 's/^.* \(.*\)@.*/\1/' -e '/^npm$/ d' -e '/^corepack$/ d' | xargs } nvm use 4.7.2 @@ -14,5 +14,14 @@ ORIGINAL_PACKAGES=$(get_packages) nvm reinstall-packages 4.7.1 FINAL_PACKAGES=$(get_packages) -[ -z "${ORIGINAL_PACKAGES}" ] || die "original packages were not empty: ${ORIGINAL_PACKAGES}" -[ -z "${FINAL_PACKAGES}" ] || die "final packages were not empty: ${FINAL_PACKAGES}" +[ -z "${ORIGINAL_PACKAGES}" ] || die "v4: original packages were not empty: ${ORIGINAL_PACKAGES}" +[ -z "${FINAL_PACKAGES}" ] || die "v4: final packages were not empty: ${FINAL_PACKAGES}" + +nvm use 23.8.20 +ORIGINAL_PACKAGES=$(get_packages) + +nvm reinstall-packages 23.8.0 +FINAL_PACKAGES=$(get_packages) + +[ -z "${ORIGINAL_PACKAGES}" ] || die "v23: original packages were not empty: ${ORIGINAL_PACKAGES}" +[ -z "${FINAL_PACKAGES}" ] || die "v23: final packages were not empty: ${FINAL_PACKAGES}"