pub

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: AGPL-3.0 Imports: 17 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package pub holds the naming rules, the request grammar, the package documents and the archive reader of the Dart and Flutter pub format: the hosted pub repository spec v2 served by pub.dev, spoken by "dart pub" and "flutter pub".

Index

Constants

View Source
const (
	// MaxArchiveBytes bounds the compressed archive of one release (pub.dev's limit).
	MaxArchiveBytes = 100 << 20
	// MaxUncompressedBytes bounds the total size of the files of an archive.
	MaxUncompressedBytes = 256 << 20
	// MaxPubspecBytes bounds pubspec.yaml (pub.dev's limit).
	MaxPubspecBytes = 128 << 10
	// MaxPubspecJSONBytes bounds the JSON a pubspec expands to; YAML aliases can
	// make it far larger than the source.
	MaxPubspecJSONBytes = 1 << 20
)

Limits on what ReadArchive accepts from an untrusted upload.

View Source
const (
	// MaxDocBytes bounds a package document read from an upstream. Packages with
	// hundreds of releases carry a full pubspec each, so it is generous.
	MaxDocBytes = 64 << 20
	// MaxVersions bounds the releases of one package document.
	MaxVersions = 50_000
	// ContentType is the media type of the package documents and of the Accept
	// header the pub client sends for them.
	ContentType = "application/vnd.pub.v2+json"
)
View Source
const (
	// MaxNameLen is the longest package name (pub.dev's limit).
	MaxNameLen = 64
	// MaxVersionLen is the longest package version.
	MaxVersionLen = 128
	// ArchiveSuffix ends every package archive file name.
	ArchiveSuffix = ".tar.gz"
)
View Source
const (
	// PackagesDir is the directory of the package documents.
	PackagesDir = "api/packages/"
	// ArchivesDir is the directory of the package archives.
	ArchivesDir = "api/archives/"
	// NewPath, UploadPath and FinishPath are the three publish endpoints.
	NewPath    = "api/packages/versions/new"
	UploadPath = "api/packages/versions/newUpload"
	FinishPath = "api/packages/versions/newUploadFinish"
)

Path route segments shared by the handlers, the proxy and the group.

Variables

View Source
var ErrInvalid = errors.New("invalid package")

ErrInvalid marks an archive that is not a valid package; its message says what is wrong and is meant for the publisher.

View Source
var ErrInvalidDoc = errors.New("invalid pub package document")

ErrInvalidDoc marks a document that is not a package document of the spec.

Functions

func ArchiveName

func ArchiveName(name, version string) string

ArchiveName is the archive file name of a package version.

func ArchivePath

func ArchivePath(name, version string) string

ArchivePath is the path of a package archive.

func CheckDoc

func CheckDoc(r io.Reader, name string) error

CheckDoc reads a package document from r and checks it is the one of name.

func CompareVersions

func CompareVersions(a, b string) int

CompareVersions orders valid versions by precedence, the way pub_semver does: the numbers, then a pre-release below its release, then the build part (a version with a build part is above the one without). The result is 0 only for identical numbers, pre-release and build.

func IsPrerelease

func IsPrerelease(v string) bool

IsPrerelease reports whether the valid version v has a pre-release part.

func IsReserved

func IsReserved(name string) bool

IsReserved reports whether name is a Dart reserved word.

func MarshalVersion

func MarshalVersion(v *Version, link Link) (json.RawMessage, error)

MarshalVersion renders one release entry with its archive URL replaced by link(v).

func PackagePath

func PackagePath(name string) string

PackagePath is the path of a package document.

func ParseArchiveName

func ParseArchiveName(file string) (string, string, bool)

ParseArchiveName splits "name-version.tar.gz" and reports whether both parts are valid.

func ValidName

func ValidName(s string) bool

ValidName reports whether s is a valid package name: 1 to MaxNameLen lower-case letters, digits and underscores, not starting with a digit. The shape keeps every name safe in a URL path and a file name, and a name never holds "-", so an archive file name splits unambiguously.

func ValidVersion

func ValidVersion(v string) bool

ValidVersion reports whether v is a package version (pub_semver).

Types

type Doc

type Doc struct {
	Name     string
	Versions []*Version
	// contains filtered or unexported fields
}

Doc is the package document of the spec: GET /api/packages/<name>.

func Merge

func Merge(docs []*Doc) *Doc

Merge combines the documents of one package from several repositories. A version listed by more than one document is taken from the first; the top-level fields besides the releases come from the first document; the releases are ordered by precedence.

func NewDoc

func NewDoc(name string, versions []*Version) *Doc

NewDoc builds the document of a package from the releases a repository holds.

func ParseDoc

func ParseDoc(data []byte) (*Doc, error)

ParseDoc reads a package document. Entries without a valid version or without an archive URL are dropped, and the first entry of a repeated version wins.

func (*Doc) Find

func (d *Doc) Find(version string) *Version

Find returns the entry of version, nil when the document has none.

func (*Doc) Marshal

func (d *Doc) Marshal(link Link, keep func(*Version) bool) ([]byte, error)

Marshal renders the document with every archive URL replaced by link(v), listing only the releases keep accepts (nil keeps all), and recomputes "latest" from what is listed.

type Kind

type Kind uint8

Kind says what a request path of a pub repository asks for.

const (
	// KindPackage is api/packages/<name>: the version list of a package.
	KindPackage Kind = iota + 1
	// KindVersion is api/packages/<name>/versions/<version>.
	KindVersion
	// KindArchive is api/archives/<name>-<version>.tar.gz.
	KindArchive
	// KindNew is api/packages/versions/new: the start of a publish.
	KindNew
	// KindUpload is api/packages/versions/newUpload: the archive upload.
	KindUpload
	// KindFinish is api/packages/versions/newUploadFinish: the end of a publish.
	KindFinish
)

The kinds of ParsePath.

type Link func(v *Version) string

Link maps a release to the archive URL a client is told to fetch it from.

type Package

type Package struct {
	Name    string
	Version string
	// Pubspec is pubspec.yaml as JSON.
	Pubspec json.RawMessage
}

Package is what a package archive says about itself.

func ParsePubspec

func ParsePubspec(data []byte) (*Package, error)

ParsePubspec reads pubspec.yaml and checks the identity it states. The YAML is untrusted: it is size-bounded, its nesting is bounded, only the first document counts, and the JSON it expands to is bounded too.

func ReadArchive

func ReadArchive(r io.Reader) (*Package, error)

ReadArchive parses the gzipped tar archive of a release and checks it: the pubspec.yaml at its root (a valid package name that is not a reserved word, and a valid version) and the shape of the tar stream. An error wraps ErrInvalid when the archive is at fault, and is an I/O error otherwise.

type Path

type Path struct {
	Kind    Kind
	Name    string
	Version string
}

Path is a parsed request path.

func ParsePath

func ParsePath(rel string) (Path, bool)

ParsePath parses a request path relative to the repository root, without a leading or trailing slash. ok is false for a path that is no pub endpoint or that holds an invalid name or version.

type Version

type Version struct {
	Version    string
	ArchiveURL string
	// SHA256 is the lower-case hex digest of the archive, "" when none is listed.
	SHA256 string
	// Published is when the release was published, zero when the document has no time.
	Published time.Time
	// Retracted marks a release its publisher withdrew.
	Retracted bool
	// contains filtered or unexported fields
}

Version is one release of a package document. Fields the spec does not name (and the ones a repository adds) are kept as they came, so a proxy hands a client everything the upstream said except the archive location.

func Latest

func Latest(versions []*Version) *Version

Latest returns the release a client resolves "any" to: the highest stable release that is not retracted, else the highest pre-release that is not retracted, else the highest release. nil for an empty list.

func NewVersion

func NewVersion(version, archiveURL, sha256 string, published time.Time, pubspec json.RawMessage) *Version

NewVersion builds the document entry of a release a repository holds. pubspec is the release's pubspec as JSON.

func (*Version) Pubspec

func (v *Version) Pubspec() json.RawMessage

Pubspec is the pubspec of the release as JSON, nil when the entry has none.

Directories

Path Synopsis
Package pubtest builds pub package archives for tests.
Package pubtest builds pub package archives for tests.

Jump to

Keyboard shortcuts

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