[Perf] nvm_resolve_local_alias: skip nvm_version for an exact, installed version

See #3416
This commit is contained in:
Hridhin Varkey Joseph
2026-10-04 02:22:58 +05:30
committed by Jordan Harband
parent f1f3d463ab
commit 913b8cb625
2 changed files with 30 additions and 3 deletions
+10 -3
View File
@@ -1673,11 +1673,18 @@ nvm_resolve_local_alias() {
if [ -z "${VERSION}" ]; then
return $EXIT_CODE
fi
if [ "_${VERSION}" != '_∞' ]; then
nvm_version "${VERSION}"
else
if [ "_${VERSION}" = '_∞' ]; then
nvm_echo "${VERSION}"
return
fi
# Fast path: an exact, installed vX.Y.Z needs no further resolution.
if nvm_is_installed_exact_version "${VERSION}"; then
nvm_echo "${VERSION}"
return
fi
nvm_version "${VERSION}"
}
nvm_iojs_prefix() {
@@ -0,0 +1,20 @@
#!/bin/sh
die () { echo "$@" ; exit 1; }
: nvm.sh
\. ../../../nvm.sh
nvm_version() {
echo 'nvm_version was called' >&2
return 42
}
EXACT="$(nvm_resolve_local_alias test-stable-1)"
[ "_$EXACT" = "_v0.0.1" ] || die "'nvm_resolve_local_alias test-stable-1' was not v0.0.1; got $EXACT"
echo v0.0.99 > ../../../alias/test-not-installed
NOT_INSTALLED="$(nvm_resolve_local_alias test-not-installed 2>/dev/null)"
EXIT_CODE=$?
rm -f ../../../alias/test-not-installed
[ "_$EXIT_CODE" = "_42" ] || die "an exact version that is not installed should still go through nvm_version; got exit code $EXIT_CODE"