Documentation
¶
Overview ¶
Package upd upgrades NPM package dependencies in package.json files while preserving formatting. It is usable both as a library and via the upd command-line tool.
The typical library flow is:
cfg := upd.DefaultConfig()
cfg.File = "package.json"
cfg.Registry = "https://registry.npmjs.org"
cfg.Timeout = 20 * time.Second
cfg.Retries = 3
cfg.Nop = true // dry-run
pkg, err := upd.ReadPackageFile(cfg.File)
if err != nil { return err }
args, err := pkg.GetUpdArgs()
if err != nil { return err }
manifest, warnings := upd.BuildManifest(pkg, args, false)
engine := upd.NewEngine(cfg)
results := engine.FetchAll(ctx, manifest.ToCheck())
updates, errs := engine.ApplyUpdates(manifest, results, pkg)
if updates > 0 && !cfg.Nop {
_ = pkg.Write(cfg.File)
}
Index ¶
- Constants
- Variables
- func PrintUsage(w io.Writer)
- func PrintVersion(w io.Writer)
- func RenderJSON(w io.Writer, manifest Manifest, updates int) error
- func ShouldDisableColor(w io.Writer) bool
- type Config
- type Engine
- type FetchResult
- type Manifest
- type PackageFile
- type Packument
- type ProgressReporter
- type RegistryClient
- type Renderer
- type RendererOptions
- type Reporter
- type Spec
- type State
Constants ¶
const ( ProgramName = "upd" ProgramDesc = "Upgrade NPM Package Dependencies" ProgramURL = "https://github.com/LarsArtmann/upd" )
Variables ¶
var ( ErrHelp = errors.New("help requested") ErrVersion = errors.New("version requested") )
var ( ErrFileNotFound = errorfamily.NewRejection("file.not_found", "package configuration file not found") ErrInvalidJSON = errorfamily.NewCorruption("json.invalid", "invalid JSON in package configuration file") ErrPackageNotFound = errorfamily.NewRejection( "registry.package_not_found", "package not found in NPM registry", ) ErrVersionParse = errorfamily.NewCorruption("version.parse_failed", "failed to parse semantic version") ErrNoLatestDistTag = errorfamily.NewCorruption("version.no_latest", "no \"latest\" dist-tag found") ErrNoValidVersions = errorfamily.NewCorruption("version.no_versions", "no valid versions found") ErrNoSemverVersions = errorfamily.NewCorruption("version.no_semver", "no valid semver versions found") ErrSectionNotFound = errorfamily.NewRejection( "json.section_missing", "section not found in package configuration file", ) ErrSectionNotObject = errorfamily.NewCorruption("json.section_not_object", "section is not a JSON object") ErrDependencyNotFound = errorfamily.NewRejection( "json.dependency_missing", "dependency not found in package configuration file", ) ErrConcurrentModification = errorfamily.NewConflict( "file.concurrent_modification", "package configuration file was modified concurrently since read", ) ErrPartialFailure = errorfamily.NewRejection( "update.partial_failure", "one or more dependencies could not be resolved", ) )
Domain errors — classified by behavioral family. Rejection = caller's fault (not found, bad input). Exit 1. Transient = temporary, retryable. Exit 75. Corruption = data damaged. Exit 65 (EX_DATAERR). Conflict = state mismatch. Exit 1.
Control-flow signals (ErrHelp, ErrVersion) live in config.go.
var ProgramVersion = "dev"
ProgramVersion is injected at build time via -ldflags="-X github.com/LarsArtmann/upd.ProgramVersion=1.2.3".
Functions ¶
func PrintUsage ¶
func PrintVersion ¶
func RenderJSON ¶
RenderJSON writes machine-readable JSON to w. Intended for CI pipelines and editor integrations where the table output is difficult to parse.
func ShouldDisableColor ¶
ShouldDisableColor returns true if ANSI color codes should be suppressed. It honors the NO_COLOR environment variable (https://no-color.org/) and detects non-TTY writers (e.g. piped or redirected output).
Types ¶
type Config ¶
type Config struct {
File string
Registry string
Greatest bool
All bool
Quiet bool
Nop bool
NoColor bool
PinLatest bool
JSON bool
Verbose bool
Concurrency int
Retries int
Timeout time.Duration
Patterns []string
}
func DefaultConfig ¶
func DefaultConfig() *Config
func ParseFlags ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
func (*Engine) ApplyUpdates ¶
func (e *Engine) ApplyUpdates( manifest Manifest, results map[string]*FetchResult, pkg *PackageFile, ) (int, int)
func (*Engine) WithReporter ¶
type FetchResult ¶
type FetchResult struct {
// contains filtered or unexported fields
}
FetchResult holds the outcome of fetching a single package's packument from the NPM registry. Callers receive a map of these from FetchAll and pass it opaquely to ApplyUpdates.
func (FetchResult) String ¶
func (r FetchResult) String() string
type Manifest ¶
func BuildManifest ¶
func BuildManifest(pkg *PackageFile, patterns []string, pinLatest bool) (Manifest, []string)
func (Manifest) SortedNames ¶
type PackageFile ¶
type PackageFile struct {
// contains filtered or unexported fields
}
func ReadPackageFile ¶
func ReadPackageFile(path string) (*PackageFile, error)
func (*PackageFile) GetDependencySection ¶
func (p *PackageFile) GetDependencySection(section string) (map[string]string, error)
func (*PackageFile) GetUpdArgs ¶
func (p *PackageFile) GetUpdArgs() ([]string, error)
func (*PackageFile) Raw ¶
func (p *PackageFile) Raw() []byte
func (*PackageFile) UpdateDependency ¶
func (p *PackageFile) UpdateDependency(section, name, newValue string) error
func (*PackageFile) Write ¶
func (p *PackageFile) Write(path string) error
type Packument ¶
type Packument struct {
// contains filtered or unexported fields
}
func (*Packument) GreatestVersion ¶
func (*Packument) LatestVersion ¶
func (*Packument) VersionKeys ¶
type ProgressReporter ¶
type ProgressReporter struct {
// contains filtered or unexported fields
}
func NewProgressReporter ¶
func NewProgressReporter(w io.Writer, total int, _ bool) *ProgressReporter
func (*ProgressReporter) Finish ¶
func (p *ProgressReporter) Finish()
func (*ProgressReporter) Start ¶
func (p *ProgressReporter) Start()
func (*ProgressReporter) Tick ¶
func (p *ProgressReporter) Tick(msg string, _ int)
type RegistryClient ¶
type RegistryClient struct {
// contains filtered or unexported fields
}
func NewRegistryClient ¶
func NewRegistryClient(cfg *Config) *RegistryClient
func (*RegistryClient) FetchPackument ¶
type Renderer ¶
type Renderer struct {
// contains filtered or unexported fields
}
func NewRenderer ¶
func NewRenderer(w io.Writer, opts RendererOptions) *Renderer
