bower

package
v0.3.0 Latest Latest
Warning

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

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

Documentation

Overview

Package bower validates Bower package trees and indexes versions from their bower.json manifest. A hosted version's files live in one tree, <name>/<version>/, and its bower.json, whose name and version must match that path, is what indexes the version. The item tree remains the source of truth.

Role

artifacts module, ecosystem layer: the Bower package tree validation and index of the Bower slice. Its Handler plugs into the item service through the format hooks (decision 0032); the slice's http package (artifacts/ecosystem/bower/http) serves the Bower registry and bower-art-resolver protocol over what it keeps.

Inputs

  • Driving: the format registry (artifacts/ecosystem), which hands the item service's hooks for bower repositories to Handler, and the work queue, which runs every format's reindex through it; and the protocol, which checks names, versions and paths (ValidName, ValidVersion, ParsePath, ManifestPath) and decodes the manifests it serves and fetches (DecodeManifest, DecodeGitManifest, MaxManifestBytes).
  • Driven: the format hooks' environment (format.Env), whose blobs hold the manifests and through whose store Handler lists a repository's manifests and keeps the package index (artifacts/core/pkgindex); and the generic deploy policy (artifacts/ecosystem/generic), which Handler embeds and applies first.
  • Settings: none.

Outputs

  • Handler: the hooks that admit a file only inside a versioned package tree and a bower.json only when it matches its path (Inspect, Admit), index a version once its bower.json is stored (Deployed) and rebuild the index from the stored manifests (Reindex). Deletes need no hook: the item service prunes a version whose manifest is gone.
  • The package index: a package per name, with a version per stored bower.json, whose file is that manifest.
  • The rules the protocol shares: Manifest, DecodeManifest, DecodeGitManifest, ValidName, ValidVersion, ParsePath, ManifestPath and MaxManifestBytes.

Invariants

  • A hosted file's path is <name>/<version>/<file>, with a valid name, a semantic version, and a file path with no empty, . or .. segment and no colon.
  • A bower.json is one JSON object of at most MaxManifestBytes with no repeated key, and its name and version match its path; only a manifest fetched from a Git tag may omit the version, which the tag supplies.
  • The index is derived from the stored manifests, never from a client's claim.

References

Status

Implemented P9c, which delivered the plan's P30 group (issues #762 to #768). Moved here in P9d.

Testing

  • bower_test.go: manifest identity and package paths.
  • security_test.go: ambiguous, unsafe and interrupted manifests, admission from the stored manifest, corrupt stored manifests, and reindex order, validation and cancellation.

Index

Constants

View Source
const MaxManifestBytes = 1 << 20

MaxManifestBytes bounds a bower.json, hosted or fetched, at 1 MiB; a larger one is refused before it is parsed.

Variables

View Source
var ErrManifest = errors.New("bower: invalid bower manifest")

ErrManifest is what DecodeManifest and DecodeGitManifest return for every manifest they refuse.

Functions

func ManifestPath

func ManifestPath(name, version string) string

ManifestPath is the item path of the bower.json of package name at version: <name>/<version>/bower.json.

func ParsePath

func ParsePath(p string) (name, version, file string, ok bool)

ParsePath accepts files inside a single versioned Bower package tree.

func Serves

func Serves(t repo.PackageType) bool

Serves reports whether t is the Bower package type.

func ValidName

func ValidName(name string) bool

ValidName reports whether name is a Bower package name the registry accepts: a letter, then up to 99 letters, digits, dots, underscores and hyphens.

func ValidVersion

func ValidVersion(version string) bool

ValidVersion reports whether version is a full semantic version, major.minor.patch with an optional pre-release and build, written without the v that a Git tag adds.

Types

type Handler

type Handler struct{ generic.Handler }

Handler is the Bower format's hooks. It embeds the generic hooks, so a delete and the class of a path are handled as for generic content.

func (Handler) Admit

func (Handler) Admit(
	ctx context.Context,
	env format.Env,
	c repo.Config,
	w format.Write,
) (format.Write, error)

Admit applies the generic deploy policy, wrapping its refusal, then passes a checksum deploy. Any other write must be inside a versioned package tree (400), and a bower.json must pass the checks Inspect makes, which Admit repeats unless Inspect already read the same content at the same path. A remote's copy outside a package tree is kept as a plain file (format.RemoteCopy).

func (Handler) Deployed

func (Handler) Deployed(ctx context.Context, env format.Env, c repo.Config, it model.Item) error

Deployed links a stored bower.json to its version in the package index, creating the package and version when they are new. Folders and other files change nothing, and so does a bower.json outside a package tree, which only a remote's cache keeps (format.RemoteCopy).

func (Handler) Inspect

func (Handler) Inspect(
	ctx context.Context,
	env format.Env,
	c repo.Config,
	w format.Write,
) (any, error)

Inspect reads and checks the stored bower.json a write puts at a manifest path, before the write's transaction, and returns it for Admit, so a manifest is read once per write. A checksum deploy, a remote's copy outside the package layout and any other file inspect nothing. A manifest that is invalid or does not match its path is refused with 400.

func (Handler) Reindex

func (Handler) Reindex(ctx context.Context, env format.Env, c repo.Config) error

Reindex rebuilds repository c's package index from its stored manifests (a remote's from its cache): a package per name and a version per bower.json, its versions sorted by version string and the package taking the first one's creation time. It fails on the first manifest that is missing or invalid.

type Manifest

type Manifest struct {
	Name         string            `json:"name"`
	Version      string            `json:"version"`
	Dependencies map[string]string `json:"dependencies,omitempty"`
}

Manifest is the part of a bower.json the registry checks: the name and version that identify the package, and its dependencies, at most 1,000, each a valid name with a non-empty target of at most 512 bytes.

func DecodeGitManifest

func DecodeGitManifest(body []byte) (Manifest, error)

DecodeGitManifest accepts upstream Git tags whose bower.json omits version; Bower takes that version from the selected Git tag. A stated version must still agree with the tag before the archive enters the remote cache.

func DecodeManifest

func DecodeManifest(body []byte) (Manifest, error)

DecodeManifest accepts one bounded JSON object and rejects duplicate security-sensitive keys, since clients can interpret duplicate keys differently when selecting a package identity or dependency.

Directories

Path Synopsis
Package bowerhttp serves the Bower registry and bower-art-resolver 2.0 protocol at /artifactory/api/bower/{repoKey}: the package list, search and lookup, which name a package by an art:// URL, the refs that list a package's versions as tags, the binaries that deliver a version's archive, and registration of a package's Git URL with a remote or virtual repository.
Package bowerhttp serves the Bower registry and bower-art-resolver 2.0 protocol at /artifactory/api/bower/{repoKey}: the package list, search and lookup, which name a package by an art:// URL, the refs that list a package's versions as tags, the binaries that deliver a version's archive, and registration of a package's Git URL with a remote or virtual repository.

Jump to

Keyboard shortcuts

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