Documentation
¶
Overview ¶
Package core provides shared types and the parser registry.
Index ¶
- func AddScript(scripts *map[string][]string, name string, commands ...string)
- func EstimateDeps(size int) int
- func ExtractQuotedValue(line, prefix string) (string, bool)
- func ForEachLine(content string, fn func(line string) bool)
- func GitCoordinate(rawURL string) string
- func IdentifyParser(filename string) (Parser, string, Kind)
- func IsYAMLComment(line string) bool
- func LeadingSpaces(line string) int
- func NextLocation(seen map[string]int, base string) string
- func ParseDockerImage(image string) (name, version string)
- func Register(ecosystem string, kind Kind, parser Parser, matcher Matcher)
- func ShellInstall(content string) string
- func StringScripts(values map[string]any) map[string][]string
- func SupportedEcosystems() []string
- type Declaration
- type Dependency
- type FSRootParser
- type Kind
- type Match
- type Matcher
- type ParseError
- type Parser
- type Registration
- type Result
- type Scope
- type Source
- type SourceKind
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EstimateDeps ¶
EstimateDeps estimates the number of dependencies based on file size.
func ExtractQuotedValue ¶
ExtractQuotedValue extracts value from lines like: key = "value"
func ForEachLine ¶
ForEachLine iterates over lines in content without allocating a slice.
func GitCoordinate ¶ added in v0.12.4
GitCoordinate returns the host/path identity of a Git clone URL, with the host lowercased and any .git suffix dropped. It accepts scheme URLs and scp-style user@host:path forms and returns "" for relative or local paths, whose host is unknown.
func IdentifyParser ¶
IdentifyParser returns the first matching parser for a filename.
func IsYAMLComment ¶ added in v0.12.4
IsYAMLComment reports whether line holds only a YAML comment.
func LeadingSpaces ¶ added in v0.12.4
LeadingSpaces returns the number of space characters at the start of line.
func NextLocation ¶ added in v0.11.0
NextLocation returns base with a numeric suffix when seen already contains it, so repeated declarations at the same logical position stay addressable.
func ParseDockerImage ¶
ParseDockerImage parses a Docker image reference like "nginx:1.19" or "nginx@sha256:abc". When both tag and digest are present (nginx:1.19@sha256:abc), the digest is used as version and the tag is stripped from the name.
func ShellInstall ¶ added in v0.12.3
ShellInstall extracts a top-level install assignment without shell expansion.
func StringScripts ¶ added in v0.12.3
StringScripts accepts string commands and ordered lists of string commands.
func SupportedEcosystems ¶
func SupportedEcosystems() []string
SupportedEcosystems returns all registered ecosystem types.
Types ¶
type Declaration ¶ added in v0.9.0
type Declaration struct {
Name string
Version string
Scope Scope
// Direct reports whether the manifest declares the package as a direct
// dependency rather than a generated or transitive requirement.
Direct bool
// PURL identifies the declared package without a version. Parsers may set
// it when a file can contain references from more than one ecosystem.
PURL string
// Ecosystem is the declaration's ecosystem name, in the same form as
// ParseResult.Ecosystem. A parser sets it when the package belongs to a
// different ecosystem than the file. Parse fills in the file's ecosystem
// otherwise and leaves it empty when NoPURL is set.
Ecosystem string
// NoPURL marks a source-only entry whose package identity is unknown.
// Parse leaves its PURL empty.
NoPURL bool
Location string
Source Source
}
Declaration is a dependency-like reference at a stable logical location in a manifest. Version is the requirement as written in that location, before effective-model resolution or inheritance. Location is ecosystem-specific and should be treated as an opaque identity.
type Dependency ¶
type Dependency struct {
Name string
Version string
Scope Scope
// Integrity is an opaque verification value derived from the manifest or
// lockfile. Its digest encoding is ecosystem-specific.
Integrity string
Direct bool
// PURL identifies the package. Parse preserves a parser-supplied value and
// otherwise builds it from Ecosystem, Name and, for lockfiles and
// supplements, Version.
PURL string
// Ecosystem is the dependency's ecosystem name, in the same form as
// ParseResult.Ecosystem. A parser sets it when the package belongs to a
// different ecosystem than the file, such as an npm package imported from
// deno.json. Parse fills in the file's ecosystem otherwise and leaves it
// empty when NoPURL is set.
Ecosystem string
// NoPURL marks a source-only entry, such as a direct download URL, whose
// package identity is unknown. Parse leaves its PURL empty.
NoPURL bool
RegistryURL string
// Source is set only when this dependency has an explicit source override.
// It is intentionally separate from RegistryURL because paths and Git
// repositories are not package registries.
Source Source
}
Dependency represents a parsed dependency from a manifest or lockfile.
type FSRootParser ¶ added in v0.5.1
type FSRootParser interface {
ParseInRoot(filename string, content []byte, fsRoot string) (*Result, error)
}
FSRootParser is optionally implemented by parsers that can consult neighbouring files on disk (e.g. pom.xml following <relativePath> to a parent). The fsRoot argument bounds that lookup; an empty string means no filesystem access.
type Match ¶
Match represents a file type match.
func IdentifyAllParsers ¶
IdentifyAllParsers returns all matching parsers for a filename.
type Matcher ¶ added in v0.8.0
type Matcher struct {
// contains filtered or unexported fields
}
Matcher describes filename matching rules that the registry can index.
func CustomMatch ¶ added in v0.8.0
CustomMatch returns a matcher backed by a custom matching function.
func ExactMatch ¶
ExactMatch returns a matcher for exact filename matches.
func PrefixMatch ¶
PrefixMatch returns a matcher for prefix matches.
func SuffixMatch ¶
SuffixMatch returns a matcher for suffix matches.
type ParseError ¶
ParseError is returned when parsing fails.
func (*ParseError) Error ¶
func (e *ParseError) Error() string
func (*ParseError) Unwrap ¶
func (e *ParseError) Unwrap() error
type Registration ¶
type Registration struct {
Ecosystem string
Kind Kind
Parser Parser
Match func(filename string) bool
}
Registration holds parser metadata.
type Result ¶ added in v0.6.0
type Result struct {
// Name is the package's own name as declared in the manifest, when
// the format has one. Empty for lockfiles and for manifest formats
// that only list dependencies (Gemfile, requirements.txt, etc.).
Name string
// Version is the package's own version as declared in the manifest.
Version string
// Licenses holds the package's declared license values, without
// normalization.
Licenses []string
// LicenseFile is a manifest-relative path to a declared license file.
LicenseFile string
// Digest is a file-level verification value whose meaning is defined by
// the manifest format. It does not apply to individual dependencies.
Digest string
Dependencies []Dependency
Declarations []Declaration
// Sources preserves manifest-level source declarations in source order.
// These entries are configuration, not evidence that any dependency was
// resolved from a particular source.
Sources []Source
// Scripts maps declared hook or task names to ordered commands or script paths.
Scripts map[string][]string
}
Result is the output of a single parser.
type Source ¶ added in v0.11.0
Source preserves an explicit source declaration without claiming that a dependency was resolved from it. Value is the literal URL, path, or ecosystem-specific coordinate.
type SourceKind ¶ added in v0.11.0
type SourceKind string
SourceKind identifies the kind of location named by a source declaration. The value describes syntax in the manifest, not a resolved package source.
const ( SourceRegistry SourceKind = "registry" SourceGit SourceKind = "git" SourcePath SourceKind = "path" SourceGitHub SourceKind = "github" SourceURL SourceKind = "url" )