Documentation
¶
Index ¶
- Constants
- func AddNodeIfMissing(depsGraph *sdk.Graph, node *sdk.Dependency) error
- func AnnotateScopesFromPackageJSON(projectPath string, depsGraph *sdk.Graph) error
- func ApplyDirectDependencyScopes(depsGraph *sdk.Graph, rootID string, directScopes map[string]sdk.Scope)
- func DepGraphFromNPMJSON(raw []byte) (*sdk.Graph, error)
- func DepGraphFromNPMNode(root *NPMListNode) (*sdk.Graph, error)
- func DepGraphFromPNPMJSON(raw []byte) (*sdk.Graph, error)
- func DepGraphFromYarnJSON(raw []byte) (*sdk.Graph, error)
- func DependencySourceFromSpecifier(value string) sdk.DependencySource
- func DirectDependencyScopes(manifest PackageJSONManifest) map[string]sdk.Scope
- func MergeStringMaps(left map[string]string, right map[string]string) map[string]string
- func NormalizeVersionToken(value string) string
- func PackageManagerWarnings(projectDir string, manager sdk.PackageManager, lockfile LockfileFormat) []sdk.DetectorWarning
- func ParseIntegrityDigests(integrity string) []sdk.Digest
- func ResolveStrategyOrder(c StrategyConfig) ([]string, error)
- func RunStrategies(ctx context.Context, req sdk.DetectionRequest, detectorName string, ...) (sdk.DetectionResult, error)
- func StrategiesApplicable(ctx context.Context, req sdk.DetectionRequest, strategies []Strategy) (bool, error)
- func StrategiesReady(ctx context.Context, req sdk.DetectionRequest, strategies []Strategy) error
- func StripUTF8BOM(data []byte) []byte
- type BaseDetector
- type LockfileFormat
- type NPMListNode
- type PackageJSONManifest
- type Strategy
- type StrategyConfig
- type UnknownComponent
Constants ¶
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 *sdk.Graph, node *sdk.Dependency) error
AddNodeIfMissing adds a package to a graph or merges scope into the existing package.
func AnnotateScopesFromPackageJSON ¶
AnnotateScopesFromPackageJSON annotates graph packages using direct dependency scopes from package.json.
func ApplyDirectDependencyScopes ¶
func ApplyDirectDependencyScopes(depsGraph *sdk.Graph, rootID string, directScopes map[string]sdk.Scope)
ApplyDirectDependencyScopes annotates direct root dependencies and their transitive dependencies with normalized scopes.
func DepGraphFromNPMJSON ¶
DepGraphFromNPMJSON maps npm list JSON output into a dependency graph.
func DepGraphFromNPMNode ¶
func DepGraphFromNPMNode(root *NPMListNode) (*sdk.Graph, error)
DepGraphFromNPMNode maps a npm dependency tree node into a dependency graph.
func DepGraphFromPNPMJSON ¶
DepGraphFromPNPMJSON maps pnpm list JSON output into a dependency graph.
func DepGraphFromYarnJSON ¶
DepGraphFromYarnJSON maps Yarn list JSON output into a dependency graph.
func DependencySourceFromSpecifier ¶ added in v0.19.0
func DependencySourceFromSpecifier(value string) sdk.DependencySource
DependencySourceFromSpecifier classifies a Node dependency specifier by where its resolved artifact originates.
func DirectDependencyScopes ¶
func DirectDependencyScopes(manifest PackageJSONManifest) map[string]sdk.Scope
DirectDependencyScopes builds direct dependency scopes from package.json dependency maps.
func MergeStringMaps ¶
MergeStringMaps returns a shallow merge of two string maps.
func NormalizeVersionToken ¶
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 sdk.PackageManager, lockfile LockfileFormat) []sdk.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) []sdk.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 sdk.DetectionRequest, detectorName string, strategies []Strategy, logger *zap.Logger) (sdk.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 sdk.DetectionRequest, strategies []Strategy) (bool, error)
StrategiesApplicable reports whether any configured strategy applies to the request.
func StrategiesReady ¶ added in v0.22.0
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
StripUTF8BOM removes an optional UTF-8 byte-order mark from input.
Types ¶
type BaseDetector ¶
BaseDetector provides shared command execution behavior for Node package-manager detectors.
func (BaseDetector) Install ¶
func (d BaseDetector) Install(ctx context.Context, req sdk.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) (*sdk.Graph, error)) (*sdk.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"`
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 sdk.Detector
Technique sdk.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
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 *sdk.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 *sdk.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.