update

package
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 1, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultClient *http.Client

DefaultClient is the HTTP client used for npm registry requests. Override in tests with an httptest server client.

Functions

func FetchLatest

func FetchLatest() (string, error)

FetchLatest queries the npm registry and returns the latest published version. This is a synchronous call with timeout, intended for diagnostic commands (doctor).

func IsNewer

func IsNewer(a, b string) bool

IsNewer returns true if version a should be considered an update over b.

When both parse as semver, standard comparison applies. When b cannot be parsed (e.g. bare commit hash "9b933f1"), any valid a is considered newer — an unparseable local version is assumed outdated. When a cannot be parsed, returns false (can't confirm it's newer).

func ParseVersion

func ParseVersion(v string) []int

ParseVersion parses "X.Y.Z" (with optional "v" prefix and pre-release suffix) into [major, minor, patch]. Returns nil on invalid input.

func RefreshCache

func RefreshCache(currentVersion string)

RefreshCache fetches the latest version from npm and updates the local cache. No-op if the cache is still fresh (< 24h). Safe to call from a goroutine.

func SetPending

func SetPending(info *UpdateInfo)

SetPending stores the update info for consumption by output decorators.

Types

type UpdateInfo

type UpdateInfo struct {
	Current string `json:"current"`
	Latest  string `json:"latest"`
}

UpdateInfo holds version update information.

func CheckCached

func CheckCached(currentVersion string) *UpdateInfo

CheckCached checks the local cache only (no network). Always fast.

func GetPending

func GetPending() *UpdateInfo

GetPending returns the pending update info, or nil.

func (*UpdateInfo) Message

func (u *UpdateInfo) Message() string

Message returns a concise update notification.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL