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
12 changes: 12 additions & 0 deletions src/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ import (

func init() {
verifycache.SetCertifiedVerifyKeyLogging(!license.IsCommunityBuild())
resolver.OnLegacyLatestResolved = func(resolved string) {
fmt.Fprintf(os.Stderr, "Warning: latest resolved to v%s under LatestIncludesPrerelease policy (legacy tip-of-index).\n", resolved)
log.WarnStructured("nvm.resolution.legacy_latest", log.StructuredPayload{
"ResolvedVersion": resolved,
"LatestMode": "legacy",
"User": log.Actor(),
"sid": log.ActorSid(),
"hostname": log.Hostname(),
"correlation_id": log.NewCorrelationID(),
"Detail": "LatestIncludesPrerelease policy is active; prefer nvm install alpha or a pinned version",
})
}
}

var (
Expand Down
2 changes: 1 addition & 1 deletion src/commands/alias/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var (
"lts": true,
"last": true,
"daily": true, // Reserved for future
"alpha": true, // Reserved for future
"alpha": true, // Built-in: newest -alpha* catalog release
"beta": true, // Reserved for future
"prerelease": true, // Reserved for future
"link": true,
Expand Down
12 changes: 10 additions & 2 deletions src/commands/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Install struct {
Insecure bool `flag:"insecure" help:"Accept invalid TLS/SSL certs from download sources."`
RelaxDeadlines constant.RelaxDeadlines `optional:"" placeholder:"MS" help:"Relax network deadlines for this command. Omit a value to triple the configured budgets, or pass milliseconds."`
Deadlines constant.DeadlineFlags `embed:""`
constant.ArgVersion
constant.ArgVersionOptional
}

func (s *Install) Run(ctx *kong.Context) error {
Expand All @@ -42,11 +42,19 @@ func (s *Install) Run(ctx *kong.Context) error {
NoCache: s.NoCache,
Force: s.Force,
CacheDir: cacheRoot,
Versions: s.Version,
Versions: defaultInstallVersions(s.Version),
AllowInsecure: s.Insecure,
CopyModulesFrom: s.CopyFrom,
ModulesFrom: s.From,
AutoInstallModuleList: cfg.AutoInstallModuleList,
LocalOnly: cfg.LocalInstallOnly,
})
}

// defaultInstallVersions makes bare `nvm install` equivalent to `nvm install latest`.
func defaultInstallVersions(versions []string) []string {
if len(versions) == 0 {
return []string{"latest"}
}
return versions
}
27 changes: 27 additions & 0 deletions src/commands/install/install_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package install

import (
"reflect"
"testing"
)

func TestDefaultInstallVersionsEmptyIsLatest(t *testing.T) {
got := defaultInstallVersions(nil)
want := []string{"latest"}
if !reflect.DeepEqual(got, want) {
t.Fatalf("defaultInstallVersions(nil) = %#v, want %#v", got, want)
}

got = defaultInstallVersions([]string{})
if !reflect.DeepEqual(got, want) {
t.Fatalf("defaultInstallVersions([]) = %#v, want %#v", got, want)
}
}

func TestDefaultInstallVersionsPreservesExplicit(t *testing.T) {
in := []string{"24", "lts", "alpha"}
got := defaultInstallVersions(in)
if !reflect.DeepEqual(got, in) {
t.Fatalf("defaultInstallVersions(%#v) = %#v, want same slice", in, got)
}
}
4 changes: 2 additions & 2 deletions src/constant/flag_version.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package constant

type ArgVersion struct {
Version []string `arg:"version" required:"" help:"The version of Node.js to install (e.g. latest, lts, lts/iron, x.x.x, x.x, x)."`
Version []string `arg:"version" required:"" help:"The version of Node.js to install (e.g. latest, alpha, lts, lts/iron, x.x.x, x.x, x). Omitting the version on nvm install installs latest (stable)."`
}

type ArgVersionOptional struct {
Version []string `arg:"version" optional:"" help:"The version of Node.js to install (e.g. latest, lts, lts/iron, x.x.x, x.x, x)."`
Version []string `arg:"version" optional:"" help:"The version of Node.js to install (e.g. latest, alpha, lts, lts/iron, x.x.x, x.x, x). Omit to install latest (stable)."`
}
15 changes: 15 additions & 0 deletions src/installer/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,16 @@ func Install(cfg InstallConfig) error {
}

status.Done()

if failures.Load() == 0 && status.TotalInstalled > 0 {
for version := range dedupe {
if strings.EqualFold(strings.TrimSpace(version), "alpha") {
fmt.Println("Note: alpha releases are unstable and may change without notice.")
break
}
}
}

if failures.Load() > 0 {
return fmt.Errorf("%d version(s) failed to install", failures.Load())
}
Expand Down Expand Up @@ -345,6 +355,11 @@ func install(
if npmVersion, ok := installedNpmVersion(txn.installDir); ok {
extras["NpmVersion"] = npmVersion
}
if strings.EqualFold(strings.TrimSpace(version), "latest") &&
resolver.LatestIncludesPrerelease != nil &&
resolver.LatestIncludesPrerelease() {
extras["LatestMode"] = "legacy"
}
log.LogSystemChanged("install", nodeVersion, txn.installDir, log.OutcomeSucceeded, "", extras)
}

Expand Down
11 changes: 10 additions & 1 deletion src/log/audit.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package log

import "strings"
import (
"common/resolver"
"strings"
)

const (
OutcomeSucceeded = "Succeeded"
Expand All @@ -17,9 +20,15 @@ func LogSystemChanged(action, nodeVersion, resolvedPath, outcome, detail string,
return
}

releaseType := "stable"
if resolver.IsUnstableVersion(nodeVersion) {
releaseType = "unstable"
}

payload := StructuredPayload{
"Action": action,
"NodeVersion": nodeVersion,
"ReleaseType": releaseType,
"Outcome": outcome,
"User": Actor(),
"sid": ActorSid(),
Expand Down
7 changes: 3 additions & 4 deletions src/test/commands/cli_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,10 @@ func TestCLIUnknownCommand(t *testing.T) {
func TestCLIInstallTypoAliasParses(t *testing.T) {
sb := clitest.NewSandbox(t)

// `instal` is an install typo alias. Bare install defaults to latest, so a
// missing version is no longer a parse/run error by itself.
_, stderr, err := sb.Execute("instal")
if err == nil {
t.Fatal("Execute(instal) expected run error without version, got nil")
}
if strings.Contains(strings.ToLower(err.Error()), "unknown command") {
if err != nil && strings.Contains(strings.ToLower(err.Error()), "unknown command") {
t.Fatalf("Execute(instal) error = %v, typo alias should resolve to install", err)
}
_ = stderr
Expand Down
Loading