npm

package
v0.3.21 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package npm resolves npm package versions from an npm registry. A package's packument lists every published version and its publication date in a single response, so discovery is one fetch with no pagination; each candidate carries the date the registry supplies and its tarball as an asset, which a sha256 follower can hash. The package key names the package to track, scoped names (@scope/name) included; the dist-tag key narrows the candidates to the version a registry channel pointer names; the deprecated key keeps deprecated versions eligible; the registry key swaps the public registry for any npm-compatible base URL.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Provider)

Option configures a Provider.

func WithTransport

func WithTransport(rt http.RoundTripper) Option

WithTransport overrides the HTTP transport, for tests.

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider resolves npm package versions from the public npm registry. A package's packument holds its whole version history in one response, so the provider fetches it once and lets the framework own selection; it only lists candidates and tags each with the publication date the registry returns for free.

func New

func New(opts ...Option) *Provider

New returns the npm provider. The registry is public for reads and publishes no rate-limit headers, so the client is a plain cached one with no ratelimit wrapper or credentials.

func (*Provider) Color added in v0.3.10

func (p *Provider) Color(dark bool) color.Color

Color is the provider's brand color. See provider.Provider.Color.

func (*Provider) Dated

func (p *Provider) Dated()

Dated marks the listing as date-bearing: the packument's time map dates every version, so cooldown applies.

func (*Provider) Describe

func (p *Provider) Describe(r provider.Resource) string

Describe returns a human-readable label for a resource: the npm web host for the public registry, the custom registry's scheme-stripped base otherwise. A tracked dist-tag is appended in npm's own package@tag spelling.

func (*Provider) Discover

func (p *Provider) Discover(ctx context.Context, r provider.Resource) ([]model.Candidate, error)

Discover lists candidate versions of a package, reading its packument in one fetch. The packument holds the whole version history in a single response - keyed in publish order, not version order - so there is no pagination, nothing is ever left unread, and --deep has no work to do here. Deprecated versions are dropped unless the directive keeps them eligible.

func (*Provider) Identify added in v0.3.10

func (p *Provider) Identify(r provider.Resource) (string, string)

Identify returns the package name and its npmjs.com page. A custom registry has no public page, so its id links nowhere - matching URL - rather than to a same-named, unrelated public package.

func (*Provider) Keys

func (p *Provider) Keys() []provider.Key

Keys reports the directive keys npm accepts, in canonical order.

func (*Provider) Name

func (p *Provider) Name() string

Name identifies the provider.

func (*Provider) Resource

func (p *Provider) Resource(d directive.Directive) (provider.Resource, error)

Resource validates a directive into an npm resource.

func (*Provider) URL

URL builds the web page for a resolved candidate: the version's page on npmjs.com. npm versions are bare semver, so the current-version candidate's Version and Ref agree; the ref is still preferred for symmetry with the providers whose upstream form carries a prefix. A scoped name keeps its literal slash, which the web path expects. Empty when the version is unknown or the package lives on a custom registry, whose web UI (if any) is unknown.

Jump to

Keyboard shortcuts

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