Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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" {
Expand Down Expand Up @@ -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/<name>"
Expand Down
25 changes: 25 additions & 0 deletions resolver/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
Loading