diff --git a/resolver/resolver.go b/resolver/resolver.go index 04dcaef..fe6cc6e 100644 --- a/resolver/resolver.go +++ b/resolver/resolver.go @@ -26,14 +26,12 @@ func Find(version string) (string, string, error) { isUserAlias = true } - resolvedViaAlias := false if isUserAlias || lower == "latest" || lower == "lts" || strings.HasPrefix(lower, "lts/") { resolved, err := alias(lower) if err != nil { return "", "", err } v = resolved - resolvedViaAlias = true } // Strip prerelease/build metadata for matching purposes. @@ -41,9 +39,10 @@ func Find(version string) (string, string, error) { // implemented with Alpha releases. v = strings.Split(v, "-")[0] - // After alias resolution the target may already be exact (user alias, - // default/current, or latest/lts). Skip a second index.tab fetch. - if resolvedViaAlias && isExactVersionSpec(v) { + // Exact x.y.z is already concrete (typed by the user, or after alias + // resolution). Skip index.tab so air-gapped `nvm install 24.22.1` can + // use a local archive without DNS. + if isExactVersionSpec(v) { return NormalizeVersion(v), "", nil } diff --git a/resolver/resolver_test.go b/resolver/resolver_test.go new file mode 100644 index 0000000..e751b9f --- /dev/null +++ b/resolver/resolver_test.go @@ -0,0 +1,18 @@ +package resolver + +import "testing" + +func TestFindExactVersionSkipsCatalog(t *testing.T) { + for _, spec := range []string{"24.22.1", "v24.22.1", "24.22.1-rc.1"} { + got, npm, err := Find(spec) + if err != nil { + t.Fatalf("Find(%q) error = %v", spec, err) + } + if got != "24.22.1" { + t.Fatalf("Find(%q) = %q, want 24.22.1", spec, got) + } + if npm != "" { + t.Fatalf("Find(%q) npm = %q, want empty (no catalog)", spec, npm) + } + } +}