depsource

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 15 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 depsource builds an sbom.Inventory from a project's dependency files. Lockfiles the resolver supports become a dependency graph (pkg/dependencies/resolve/lockfile), with dev members left out; manifests no lockfile covers are parsed flat (pkg/dependencies), as a list of declared packages with no edges. It is the dependency counterpart of scansource, and the only SBOM code that depends on the dependency parsers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Graph

func Graph(g resolve.Graph) sbom.Inventory

Graph projects a resolved graph into an inventory: one declared component per member of each root that is not dev, and one DependencyRoot per root. A node shared by several roots is one component carrying one evidence per root, "declared" where that root's manifest declares it and "transitive" where its lockfile pulls it in. Dev members never appear, and neither does an edge that touches one, so a root's edges only ever join components that are in the inventory. An unknown root is kept, with no members and no edges, so the output says the lockfile was there and could not be read.

func Inventory

func Inventory(ctx context.Context, root string, files []string, opts Options) (sbom.Inventory, map[string]error)

Inventory reads the dependency files of the project at root. Each supported lockfile is resolved into a graph and the graphs are merged; every root covers its manifest and its lockfile, so neither is parsed flat again. An unknown root covers them too: it says the lockfile was there and could not be read, and a flat parse would bring back the range entries and dev dependencies the graph exists to replace. Every other selected manifest is parsed flat.

failed is keyed by path and holds the lockfiles that could not be read and the manifests that could not be parsed. It is nil when nothing failed. Unknown roots are not failures: they are reported on the root itself.

func Manifests

func Manifests(parsed *parsers.LocalDependencies, root string) sbom.Inventory

Manifests builds declared components from flat-parsed manifests, with no round trip to any service: each PURL is split into its base and version (the manifest's requirement when the PURL carries none), tagged declared, and given the manifest as evidence, relative to root in slash form so it matches a root's manifest path. Exact duplicates fold into one component with one evidence per manifest; distinct versions of a package are kept, including a declared range (package.json "^1.5.5") alongside its resolved pin (package-lock.json "1.14.3").

func Resolve added in v0.18.0

func Resolve(ctx context.Context, root, rel string, o Options) (resolve.Graph, error)

Resolve builds the graph of the manifest or lockfile rel, a slash path under root. An enabled toolchain runs first; when it leaves a root unknown (tool missing, failed or timed out) its graph is dropped with a warning and the lockfile parser answers instead, as without the toolchain. A manifest only the toolchain resolves then yields an empty graph, which leaves it to the flat parser.

func Select

func Select(files []string) []string

Select keeps the files Inventory reads: the lockfiles the resolver supports and the manifests the flat parsers handle. A caller collecting a tree hands it everything and gets back what the dependency stage will open, which is also the count worth reporting as that stage's total.

Types

type Options added in v0.18.0

type Options struct {
	// Toolchain holds the base names of the manifests ("go.mod", "pom.xml") resolved by running the
	// ecosystem's own tools instead of reading a lockfile, when the toolchain package supports them.
	Toolchain map[string]bool
	// ToolchainOptions configures those tool runs: timeout, environment and limits.
	ToolchainOptions toolchain.Options
}

Options chooses how manifests are resolved. The zero value reads lockfiles only.

func (Options) Resolvable added in v0.18.0

func (o Options) Resolvable(file string) bool

Resolvable reports whether Resolve builds a graph for file: a lockfile the resolver supports, or a manifest the toolchain is enabled for.

Jump to

Keyboard shortcuts

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