extpkg

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ParserNPMJSON    = "npm-json"
	ParserPNPMJSON   = "pnpm-json"
	ParserPipxJSON   = "pipx-json"
	ParserUVToolText = "uv-tool-text"
	ParserCargoText  = "cargo-text"
	ParserBunText    = "bun-text"
	ParserScoopTable = "scoop-table"
	ParserLinesRegex = "lines-regex"
)

Parser identifiers for built-in manager output formats. Each manager names one parser for list output and reuses it for outdated output.

View Source
const DefaultTimeout = 60 * time.Second

DefaultTimeout bounds one manager command.

Variables

This section is empty.

Functions

func BuiltinNames added in v1.10.2

func BuiltinNames() []string

BuiltinNames lists the built-in manager names in display order.

Types

type CommandResult

type CommandResult struct {
	Stdout   []byte
	Stderr   []byte
	ExitCode int
}

CommandResult is the outcome of one manager command. All three parts matter: npm exits non-zero when it finds outdated packages and reports errors on stdout, while pipx keeps stdout clean and writes its notes to stderr.

type ExecRunner

type ExecRunner struct{}

ExecRunner runs manager commands as child processes.

It deliberately inherits the parent environment and does not inject eget's own proxy settings: each manager has its own registry/proxy configuration.

func (ExecRunner) Run

func (ExecRunner) Run(ctx context.Context, bin string, args []string, timeout time.Duration) (CommandResult, error)

type Failure

type Failure struct {
	Manager string
	Err     error
}

Failure is a manager-level failure, e.g. the manager command failed or its output could not be parsed. It is reported per manager so one broken manager never hides the others.

func (Failure) Error

func (f Failure) Error() string

func (Failure) Unwrap

func (f Failure) Unwrap() error

type Manager

type Manager struct {
	Name string
	Bin  string

	ListArgs       []string
	OutdatedArgs   []string
	UpgradeArgs    []string
	UpgradeAllArgs []string

	Parser        string
	ListRegex     string
	OutdatedRegex string

	Enabled bool
	Timeout time.Duration
}

Manager describes how to drive one external package manager.

func Managers

func Managers(cfg *cfgpkg.File) []Manager

Managers merges the built-in adapters with the [ext.<name>] config sections:

  • a section named after a builtin overrides that builtin
  • enabled = false removes the manager (builtin or configured)
  • an unknown name adds a new manager

The result is sorted by name and always carries a usable Bin, Parser and Timeout.

func (Manager) SupportsList

func (m Manager) SupportsList() bool

SupportsList reports whether the manager can list installed packages.

func (Manager) SupportsOutdated

func (m Manager) SupportsOutdated() bool

SupportsOutdated reports whether the manager can detect outdated packages. uv tool list --outdated and friends; cargo has no built-in equivalent.

type Package

type Package struct {
	Manager string
	Name    string
	Version string
	Latest  string
}

Package is one package installed by an external manager.

func ParseList

func ParseList(manager Manager, res CommandResult) ([]Package, error)

ParseList parses the output of a manager's list command into installed packages. An empty slice is a valid result: no packages are installed.

func ParseOutdated

func ParseOutdated(manager Manager, res CommandResult) ([]Package, error)

ParseOutdated parses the output of a manager's outdated command, which only reports the packages that are behind.

type Runner

type Runner interface {
	Run(ctx context.Context, bin string, args []string, timeout time.Duration) (CommandResult, error)
}

Runner runs one manager command. It is an interface so tests can drive the service without any manager installed.

func NewExecRunner

func NewExecRunner() Runner

type Service

type Service struct {
	Managers []Manager
	Runner   Runner
	LookPath func(string) (string, error)
}

Service lists and upgrades packages owned by external managers.

func NewService

func NewService(cfg *cfgpkg.File) Service

NewService builds the service from config, using the real process runner.

func (Service) List

func (s Service) List(ctx context.Context, only ...string) ([]Package, []Failure, error)

List returns the packages installed by the given managers (all of them when only is empty). Managers that are missing or fail are reported as failures instead of aborting the rest.

func (Service) Manager

func (s Service) Manager(name string) (Manager, bool)

Manager returns the manager with the given name.

func (Service) Names

func (s Service) Names() []string

Names returns every configured manager name, sorted.

func (Service) Outdated

func (s Service) Outdated(ctx context.Context, only ...string) ([]Package, []Failure, error)

Outdated returns the packages that are behind, using only the managers that can detect it.

func (Service) Path

func (s Service) Path(manager Manager) (string, bool)

Path reports the resolved binary path of a manager. A configured bin that contains a path separator is used as-is, which is the escape hatch for tools installed outside PATH (pipx, cargo, ...).

func (Service) Resolve

func (s Service) Resolve(ref string) (Manager, string, bool)

Resolve splits a "<manager>:<pkg>" reference. An empty manager name or an unknown manager is not a valid reference.

func (Service) Upgrade

func (s Service) Upgrade(ctx context.Context, managerName string, names []string) (UpgradeResult, error)

Upgrade runs the upgrade command of one manager. names may be empty, which means "the whole manager": that uses the manager's upgrade-all command when it has one, otherwise every installed package is upgraded by name.

The returned From/To fields are left empty: the caller already knows the versions under check.

type UpgradeResult

type UpgradeResult struct {
	Manager string
	Names   []string
	From    string
	To      string
	Output  string
}

UpgradeResult is the outcome of running one manager upgrade command. From and To are filled by the caller when it already knows the versions under check.

Jump to

Keyboard shortcuts

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