Documentation
¶
Overview ¶
Package npm is the Source for the npm registry. It lists the versions of a package from its packument, GET {base}/{name}.
Abbreviated or full metadata ¶
The registry serves two shapes of the packument. The abbreviated one (Accept: application/vnd.npm.install-v1+json) is small but has no "time" map. The full one has it. A Version needs PublishedAt, and an unpublished version is only visible as a key of "time" with no entry in "versions", so the default is the full document. WithAbbreviated opts in to the smaller shape for callers that can live without both: it leaves PublishedAt zero and cannot report unpublished versions. Full packuments of busy packages are large. Decompressed sizes measured in November 2026:
package full abbreviated react 7.1 MB 3.0 MB @types/node 11.2 MB aws-sdk 10.6 MB 3.8 MB typescript 15.9 MB 8.8 MB next 31.5 MB 25.7 MB
netguard's default body cap is 10 MiB, so several popular packages exceed it. netguard has a built-in 64 MiB cap for registry.npmjs.org (overridable with netguard.HostLimit.MaxBodyBytes), so a netguard client needs no configuration. A mirror on another host keeps the global cap unless the client is built with a HostLimits entry for it. A response over the cap makes List fail with an error wrapping netguard.ErrBodyTooLarge.
Errors and ordering ¶
A 404 (a package that never existed, or whose registry document is gone) is returned as an error wrapping *netguard.StatusError, never as an empty result. Versions are sorted newest first by PublishedAt, ties by Raw. In abbreviated mode there is no PublishedAt, so the order is only by Raw (string order, not semantic); the core must not rely on it.
What a Version carries ¶
Raw is the version key. PublishedAt comes from "time". A version that is in "time" but not in "versions" was unpublished and is Yanked. A deprecated version is not Yanked; its message is Metadata["deprecated"]. Metadata also has "dist-tags" (the tags pointing at the version, sorted), "tarball", "integrity" and "shasum" when the registry gives them, and "unpublished": true for unpublished versions. Prerelease is left nil: npm has no such flag and the core derives it from the version.
Index ¶
Constants ¶
const ( // Kind is the registry key of this source. Kind = "npm" // DefaultBaseURL is the public npm registry. DefaultBaseURL = "https://registry.npmjs.org" // DefaultPackageURL is the prefix of package pages on the public registry. DefaultPackageURL = "https://www.npmjs.com/package" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*Source)
Option configures a Source.
func WithAbbreviated ¶
func WithAbbreviated() Option
WithAbbreviated requests the abbreviated packument. See the package documentation for what is lost.
func WithPackageURL ¶
WithPackageURL sets the prefix of the release page URL, to which "/{name}/v/{version}" is appended. Without it, URL is set only for the public registry.
type Source ¶
type Source struct {
// contains filtered or unexported fields
}
Source implements source.Source for npm.
func New ¶
New returns an npm Source reading from baseURL (DefaultBaseURL if empty) with hc, normally the HTTPClient of a netguard client.