node

package
v0.27.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// StrategyLockfile parses the committed lockfile directly, without
	// running the package manager.
	StrategyLockfile = "lockfile"
	// StrategyBuildTool resolves the graph by invoking the package manager
	// CLI.
	StrategyBuildTool = "buildtool"
)

Strategy action names accepted by StrategyConfig.Strategy.

Variables

This section is empty.

Functions

func AddNodeIfMissing

func AddNodeIfMissing(depsGraph *model.Graph, node model.GraphNode) error

AddNodeIfMissing adds a package to a graph or merges scope into the existing package. AddNodeIfMissing inserts any node kind, folding a repeat into the node that already carries its identity. Node detectors add module roots through it as well as dependencies, so it takes the union.

func AnnotateScopesFromPackageJSON

func AnnotateScopesFromPackageJSON(projectPath string, depsGraph *model.Graph) error

AnnotateScopesFromPackageJSON annotates graph packages using direct dependency scopes from package.json.

func ApplyDirectDependencyScopes

func ApplyDirectDependencyScopes(depsGraph *model.Graph, rootID string, directScopes map[string]model.Scope)

ApplyDirectDependencyScopes annotates direct root dependencies and their transitive dependencies with normalized scopes.

func DepGraphFromNPMJSON

func DepGraphFromNPMJSON(raw []byte) (*model.Graph, error)

DepGraphFromNPMJSON maps npm list JSON output into a dependency graph.

func DepGraphFromNPMNode

func DepGraphFromNPMNode(root *NPMListNode) (*model.Graph, error)

DepGraphFromNPMNode maps a npm dependency tree node into a dependency graph.

func DepGraphFromPNPMJSON

func DepGraphFromPNPMJSON(raw []byte) (*model.Graph, error)

DepGraphFromPNPMJSON maps pnpm list JSON output into a dependency graph.

func DepGraphFromYarnJSON

func DepGraphFromYarnJSON(raw []byte) (*model.Graph, error)

DepGraphFromYarnJSON maps Yarn list JSON output into a dependency graph.

func DependencySourceFromSpecifier added in v0.19.0

func DependencySourceFromSpecifier(value string) model.DependencySource

DependencySourceFromSpecifier classifies a Node dependency specifier by where its resolved artifact originates.

func DirectDependencyScopes

func DirectDependencyScopes(manifest PackageJSONManifest) map[string]model.Scope

DirectDependencyScopes builds direct dependency scopes from package.json dependency maps.

func MergeStringMaps

func MergeStringMaps(left map[string]string, right map[string]string) map[string]string

MergeStringMaps returns a shallow merge of two string maps.

func NormalizeVersionToken

func NormalizeVersionToken(value string) string

NormalizeVersionToken removes common package-manager range and protocol markers from a version token.

func PackageManagerWarnings added in v0.20.2

func PackageManagerWarnings(projectDir string, manager model.PackageManager, lockfile LockfileFormat) []plugin.DetectorWarning

PackageManagerWarnings reports non-fatal problems with a Node project's package-manager configuration: the detector resolved a correct graph, but the project as committed will trip up an install elsewhere, typically in CI. lockfile describes the lockfile the caller parsed, if any.

Every check reads committed files only — package.json, that lockfile, pnpm-workspace.yaml, and .npmrc. Nothing is executed: `pnpm`/`yarn` on PATH are frequently Corepack shims, and running one can download the pinned manager on demand, which would put a network call in a plain scan. Comparing what the repository declares is also the more accurate question, since that is what CI installs with, not whatever is on this machine's PATH.

Unreadable or unrecognized inputs are skipped: malformed lockfiles are the detector's error to report, not this check's.

func ParseIntegrityDigests

func ParseIntegrityDigests(integrity string) []model.Digest

ParseIntegrityDigests parses a space-separated integrity string (for example "sha512-abc sha1-xyz") into Digest values. Returns nil when the string is empty.

func ResolveStrategyOrder added in v0.22.0

func ResolveStrategyOrder(c StrategyConfig) ([]string, error)

ResolveStrategyOrder validates and normalizes the configured action order. An empty configuration yields the default lockfile-first order.

func RunStrategies added in v0.22.0

func RunStrategies(ctx context.Context, req plugin.DetectionRequest, detectorName string, strategies []Strategy, logger *zap.Logger) (plugin.DetectionResult, error)

RunStrategies executes the configured actions in order with the historical chain semantics: a strategy that is not ready or fails records its error and hands off to the next one; a strategy that is not applicable hands off silently; the first strategy that produces a non-empty graph wins and its technique is stamped on the result. When every strategy fails the joined errors are returned.

func StrategiesApplicable added in v0.22.0

func StrategiesApplicable(ctx context.Context, req plugin.DetectionRequest, strategies []Strategy) (bool, error)

StrategiesApplicable reports whether any configured strategy applies to the request.

func StrategiesReady added in v0.22.0

func StrategiesReady(ctx context.Context, req plugin.DetectionRequest, strategies []Strategy) error

StrategiesReady reports readiness for a merged detector: ready when any configured strategy is ready, otherwise the joined per-strategy reasons.

func StripUTF8BOM added in v0.19.0

func StripUTF8BOM(data []byte) []byte

StripUTF8BOM removes an optional UTF-8 byte-order mark from input.

Types

type BaseDetector

type BaseDetector struct {
	Logger     *zap.Logger
	WorkingDir string
}

BaseDetector provides shared command execution behavior for Node package-manager detectors.

func (BaseDetector) Install

func (d BaseDetector) Install(ctx context.Context, req plugin.DetectionRequest, executable string, defaultArgs []string, detectorName string) error

Install runs a package-manager install command for detectors that support install-first.

func (BaseDetector) ProjectDir

func (d BaseDetector) ProjectDir(projectPath string) string

ProjectDir returns the configured working directory or falls back to the project path.

func (BaseDetector) ResolveGraph

func (d BaseDetector) ResolveGraph(stderr io.Writer, projectPath string, verbose bool, executable string, args []string, detectorName string, parse func([]byte) (*model.Graph, error)) (*model.Graph, error)

ResolveGraph runs a package-manager CLI command and maps its JSON output into a graph.

type LockfileFormat added in v0.20.2

type LockfileFormat struct {
	File    string // base name, e.g. "pnpm-lock.yaml"
	Version string // format version as written, e.g. "9.0"
}

LockfileFormat identifies the lockfile a Node detector parsed and the format version it declares. The zero value means the detector has no format version to compare (Bun text lockfiles record none), which disables the format-versus-declaration check without disabling the rest.

type NPMListNode

type NPMListNode struct {
	Name    string `json:"name"`
	Version string `json:"version"`
	// Resolved is the tarball a package was installed from. Both sources of
	// this shape record it: `npm ls --json` for registry packages, and the
	// flat "dependencies" map of a v1 package-lock.json.
	Resolved     string                  `json:"resolved"`
	Dependencies map[string]*NPMListNode `json:"dependencies"`
}

NPMListNode is the npm list JSON node shape used by npm CLI and v1 package-lock parsing.

type PackageJSONManifest

type PackageJSONManifest struct {
	Name                 string            `json:"name"`
	Version              string            `json:"version"`
	Dependencies         map[string]string `json:"dependencies"`
	OptionalDependencies map[string]string `json:"optionalDependencies"`
	PeerDependencies     map[string]string `json:"peerDependencies"`
	DevDependencies      map[string]string `json:"devDependencies"`
}

PackageJSONManifest is the subset of package.json used by Node detectors.

func ReadPackageJSONManifest

func ReadPackageJSONManifest(projectPath string) (PackageJSONManifest, error)

ReadPackageJSONManifest reads the package.json manifest used by Node lockfile parsers.

type Strategy added in v0.22.0

type Strategy struct {
	Name      string
	Detector  plugin.Detector
	Technique plugin.DetectorTechnique
}

Strategy pairs one internal detection action with the detector that implements it and the technique its results should be labelled with.

type StrategyConfig added in v0.22.0

type StrategyConfig struct {
	// Strategy reorders or subsets the internal detection actions. Valid
	// values: "lockfile", "buildtool". Empty means the default
	// lockfile-first order.
	Strategy []string `` /* 146-byte string literal not displayed */
	// InstallFirst gates install-first preparation for this detector. The
	// global --install-first flag still has to be passed for installs to
	// happen at all; setting this to false opts this detector out even then.
	InstallFirst *bool `` /* 133-byte string literal not displayed */
}

StrategyConfig is the standard configuration block shared by the merged Node detectors (npm, pnpm, yarn). It is decoded from the kind-scoped plugins.detectors.<name> block.

func (StrategyConfig) InstallFirstEnabled added in v0.22.0

func (c StrategyConfig) InstallFirstEnabled() bool

InstallFirstEnabled reports whether install-first preparation is allowed for this detector (default true).

type UnknownComponent added in v0.19.0

type UnknownComponent struct {
	RootID string
	Size   int
}

UnknownComponent describes a disconnected component attached to its owning manifest root with an unknown relationship.

func AttachUnknownComponents added in v0.19.0

func AttachUnknownComponents(graph *model.Graph, rootID string, logger *zap.Logger, detector, manifest string) ([]UnknownComponent, error)

AttachUnknownComponents attaches every component without an incoming edge beneath rootID. Only the component root is marked unknown; known descendant edges remain transitive.

func AttachUnknownComponentsToApplication added in v0.19.0

func AttachUnknownComponentsToApplication(graph *model.Graph, logger *zap.Logger, detector, manifest string) ([]UnknownComponent, error)

AttachUnknownComponentsToApplication finds the application root and delegates to AttachUnknownComponents. Graphs without an application root are left for consolidation to normalize beneath a manifest root.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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