From 73a4db4d40ea43442a4b6b3880fde6111f3fc777 Mon Sep 17 00:00:00 2001 From: coreybutler <770982+coreybutler@users.noreply.github.com> Date: Tue, 10 Nov 2026 09:55:52 -0600 Subject: [PATCH] fix: make latest alias skip Node.js prereleases index.tab can lead with alphas (e.g. 27.0.0-alpha) before GA exists. Taking the first row then stripping the suffix resolved latest to a missing 27.0.0 and 404d SHASUMS256.txt (nvm#1554). Signed-off-by: Corey Butler <770982+coreybutler@users.noreply.github.com> --- resolver/resolver.go | 33 ++++++++++++++++++++++++++------- resolver/resolver_test.go | 25 +++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/resolver/resolver.go b/resolver/resolver.go index 49cfbbc..07834e4 100644 --- a/resolver/resolver.go +++ b/resolver/resolver.go @@ -34,9 +34,10 @@ func Find(version string) (string, string, error) { v = resolved } - // Strip prerelease/build metadata for matching purposes. - // Prereleases will not be supported until the new Node.js schedule is - // implemented with Alpha releases. + // Strip prerelease/build metadata for partial/exact matching. Explicit + // prerelease installs are not supported yet (reserved aliases alpha/beta); + // `latest` already skips prerelease rows so this strip does not invent a + // missing GA tag like 27.0.0 from 27.0.0-alpha.0.0.0 (nvm#1554). v = strings.Split(v, "-")[0] // Exact x.y.z is already concrete (typed by the user, or after alias @@ -120,10 +121,7 @@ func alias(version string) (string, error) { if err != nil { return "", err } - if len(all) == 0 { - return "", fmt.Errorf("no versions found") - } - return all[0][0], nil + return latestStable(all) } if v == "lts" { @@ -167,6 +165,27 @@ func alias(version string) (string, error) { return "", fmt.Errorf("unknown alias: %s", version) } +// latestStable returns the newest index.tab row that is not a prerelease +// (no '-' in the version). Node publishes alphas at the head of index.tab +// before the matching GA exists, so taking all[0] would resolve latest to a +// stripped tag that 404s on SHASUMS256.txt (nvm#1554 / nodejs/node#67367). +func latestStable(versions [][]string) (string, error) { + if len(versions) == 0 { + return "", fmt.Errorf("no versions found") + } + for _, ver := range versions { + if len(ver) == 0 { + continue + } + tag := strings.TrimPrefix(strings.TrimSpace(ver[0]), "v") + if tag == "" || strings.Contains(tag, "-") { + continue + } + return tag, nil + } + return "", fmt.Errorf("no stable versions found") +} + // Resolve returns the best concrete Node.js version for the given input. // It accepts: // - Named aliases: "latest", "lts", "lts/" diff --git a/resolver/resolver_test.go b/resolver/resolver_test.go index e751b9f..23d942f 100644 --- a/resolver/resolver_test.go +++ b/resolver/resolver_test.go @@ -16,3 +16,28 @@ func TestFindExactVersionSkipsCatalog(t *testing.T) { } } } + +func TestLatestStableSkipsPrereleaseHead(t *testing.T) { + // Mirrors nodejs.org/dist/index.tab order when an alpha leads the catalog. + rows := [][]string{ + {"27.0.0-alpha.0.0.0", "2026-10-29", "12.1.0", "", "-"}, + {"26.13.0", "2026-10-28", "11.20.0", "Lithium", "-"}, + {"26.12.1", "2026-10-21", "11.20.0", "", "true"}, + } + got, err := latestStable(rows) + if err != nil { + t.Fatalf("latestStable error = %v", err) + } + if got != "26.13.0" { + t.Fatalf("latestStable = %q, want 26.13.0", got) + } +} + +func TestLatestStableEmptyOrOnlyPrerelease(t *testing.T) { + if _, err := latestStable(nil); err == nil { + t.Fatal("expected error for empty catalog") + } + if _, err := latestStable([][]string{{"27.0.0-alpha.0.0.0", "", "", "", ""}}); err == nil { + t.Fatal("expected error when only prereleases exist") + } +}