Documentation
¶
Overview ¶
Package manifests parses dependency manifest and lockfile formats across package ecosystems.
It supports 40+ ecosystems including npm, gem, pypi, cargo, maven, and more. Each ecosystem uses its PURL type as the identifier.
Basic usage:
result, err := manifests.Parse("package.json", content)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Ecosystem: %s, Kind: %s\n", result.Ecosystem, result.Kind)
for _, dep := range result.Dependencies {
fmt.Printf(" %s %s\n", dep.Name, dep.Version)
}
Index ¶
Constants ¶
const ( Manifest Kind = core.Manifest Lockfile Kind = core.Lockfile Supplement Kind = core.Supplement Vendor Kind = core.Vendor Runtime Scope = core.Runtime Development Scope = core.Development Test Scope = core.Test Build Scope = core.Build Optional Scope = core.Optional )
Re-export constants.
Variables ¶
This section is empty.
Functions ¶
func Ecosystems ¶
func Ecosystems() []string
Ecosystems returns a list of all supported PURL ecosystem types.
Types ¶
type Dependency ¶
type Dependency = core.Dependency
Re-export types from internal/core for public API.
type DiscoveredManifest ¶ added in v0.8.0
DiscoveredManifest identifies a project or workspace manifest. ParentPath is the repository-relative workspace configuration that selected a nested manifest; it is empty for root and path-based manifests.
func DiscoverManifests ¶ added in v0.8.0
func DiscoverManifests(reader RepositoryReader) ([]DiscoveredManifest, []error)
DiscoverManifests returns the project and workspace manifests selected from a rooted repository. It does not parse dependency declarations. Warnings report workspace configurations or lookups that could not be processed; successfully discovered manifests are still returned.
type FSReader ¶ added in v0.8.0
type FSReader struct {
// contains filtered or unexported fields
}
FSReader adapts an fs.FS to RepositoryReader. It supports recursive ** globs.
func NewFSReader ¶ added in v0.8.0
NewFSReader returns a repository reader rooted at fsys. Use os.DirFS to discover manifests in a working tree.
type Match ¶
Match represents a file type match.
func IdentifyAll ¶
IdentifyAll returns all matching ecosystems for a filename.
type Options ¶ added in v0.5.1
type Options struct {
// FSRoot, when non-empty, allows parsers that consult neighbouring
// files on disk (currently only pom.xml, for parent <relativePath>
// resolution) to do so within this directory. Paths outside it are
// refused. When empty, parsing is a pure function of content and no
// filesystem access occurs; this is the safe choice for untrusted
// input.
FSRoot string
}
Options configures Parse.
type ParseResult ¶
type ParseResult struct {
Ecosystem string
Kind Kind
// Name is the package's own name as declared in the manifest, when
// the format has one. Empty for lockfiles and for formats that
// only list dependencies (Gemfile, requirements.txt, etc.).
Name string
// Version is the package's own version as declared in the
// manifest, when present.
Version string
// Licenses holds the package's declared license values, verbatim as
// written in the manifest. Empty when the format has no license field
// or none is set. Scalar formats produce a single-element slice.
Licenses []string
// LicenseFile is a manifest-relative path to a license file when the
// format declares one instead of, or as well as, an expression.
LicenseFile string
Dependencies []Dependency
}
ParseResult contains the parsed dependencies from a manifest or lockfile.
type RepositoryReader ¶ added in v0.8.0
type RepositoryReader interface {
ReadFile(name string) ([]byte, error)
Glob(pattern string) ([]string, error)
}
RepositoryReader provides bounded access to files in a repository. Paths and glob patterns use forward slashes and are relative to the repository root. Glob must support the doublestar dialect, including recursive ** patterns. ReadFile should return an error matching fs.ErrNotExist for absent files.
type UnknownFileError ¶
type UnknownFileError struct {
Filename string
}
UnknownFileError is returned when a file type is not recognized.
func (*UnknownFileError) Error ¶
func (e *UnknownFileError) Error() string
type VendorDiscovery ¶ added in v0.8.0
type VendorDiscovery struct {
Roots []VendorRoot
Dependencies []VendoredDependency
}
VendorDiscovery contains classified vendor roots and the package identities discovered beneath them.
func DiscoverVendors ¶ added in v0.8.0
func DiscoverVendors(reader RepositoryReader) (VendorDiscovery, []error)
DiscoverVendors finds package-manager vendor roots and exact package identities in a rooted repository. Warnings report malformed configuration, unreadable evidence, or incomplete package identities while retaining all successfully discovered results.
type VendorRoot ¶ added in v0.8.0
VendorRoot identifies a repository directory containing vendored packages. ConfigPath is the configuration or inventory that selected the root. It is empty for convention-based roots such as node_modules.
type VendoredDependency ¶ added in v0.8.0
type VendoredDependency struct {
Name string
Version string
Ecosystem string
Kind Kind
PURL string
RootPath string
EvidencePath string
}
VendoredDependency is an exact package version stored under a vendor root. EvidencePath identifies the repository file from which the package identity was read.