discovery

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package discovery provides version source detection and discovery services for the sley CLI. It scans for .version files and manifest files (package.json, Cargo.toml, etc.) to help users understand their project structure and suggest appropriate configurations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetUniqueVersions

func GetUniqueVersions(result *Result) []string

GetUniqueVersions returns a list of unique versions found in the discovery result.

func IsVersionConsistent

func IsVersionConsistent(result *Result) bool

IsVersionConsistent returns true if all discovered sources have the same version.

Types

type DetectionMode

type DetectionMode int

DetectionMode indicates the type of project structure detected.

const (
	// NoModules indicates no .version files were found.
	NoModules DetectionMode = iota

	// SingleModule indicates a single .version file was found.
	SingleModule

	// MultiModule indicates multiple .version files were found.
	MultiModule
)

func (DetectionMode) String

func (m DetectionMode) String() string

String returns a human-readable representation of the detection mode.

type FileFilter

type FileFilter func(path string, info fs.FileInfo) bool

FileFilter is a function type for filtering discovered files.

type KnownManifest

type KnownManifest struct {
	// Filename is the expected filename.
	Filename string

	// Format is the file format.
	Format parser.Format

	// Field is the dot-notation path to the version field.
	Field string

	// Description is a human-readable description.
	Description string

	// Priority determines discovery order (lower = higher priority).
	Priority int
}

KnownManifest describes a known manifest file type for discovery.

func DefaultKnownManifests

func DefaultKnownManifests() []KnownManifest

DefaultKnownManifests returns the list of known manifest files to discover.

type ManifestSource

type ManifestSource struct {
	// Path is the absolute path to the manifest file.
	Path string

	// RelPath is the relative path from the discovery root.
	RelPath string

	// Filename is the base name of the file (e.g., "package.json").
	Filename string

	// Version is the extracted version string.
	Version string

	// Format is the file format (json, yaml, toml, etc.).
	Format parser.Format

	// Field is the dot-notation path to the version field.
	Field string

	// Description is a human-readable description of the file type.
	Description string
}

ManifestSource represents a discovered manifest file with version information.

type Mismatch

type Mismatch struct {
	// Source is the path of the file with the mismatched version.
	Source string

	// ExpectedVersion is what the version should be.
	ExpectedVersion string

	// ActualVersion is the version found in the file.
	ActualVersion string
}

Mismatch represents a version mismatch between sources.

func DetectMismatches

func DetectMismatches(result *Result) []Mismatch

DetectMismatches analyzes discovery results and identifies version inconsistencies. It uses the primary version as the expected version and flags any sources that differ.

func DetectMismatchesWithCustomBase

func DetectMismatchesWithCustomBase(result *Result, baseVersion string) []Mismatch

DetectMismatchesWithCustomBase checks for mismatches using a specified base version.

type Module

type Module struct {
	// Name is the module name (typically the directory name).
	Name string

	// Path is the absolute path to the .version file.
	Path string

	// RelPath is the relative path from the discovery root.
	RelPath string

	// Version is the current version string.
	Version string

	// Dir is the directory containing the .version file.
	Dir string
}

Module represents a discovered .version file.

type Result

type Result struct {
	// Mode indicates the detected project mode.
	Mode DetectionMode

	// Modules contains discovered .version files (monorepo modules).
	Modules []Module

	// Manifests contains discovered manifest files with version information.
	Manifests []ManifestSource

	// SyncCandidates contains files suitable for dependency-check sync.
	SyncCandidates []SyncCandidate

	// Mismatches contains detected version mismatches.
	Mismatches []Mismatch
}

Result represents the complete discovery result for a project.

func DiscoverAt

func DiscoverAt(ctx context.Context, fsys core.FileSystem, cfg *config.Config, root string) (*Result, error)

DiscoverAt is a convenience function that creates a Service and runs discovery.

func (*Result) HasManifests

func (r *Result) HasManifests() bool

HasManifests returns true if any manifest files were found.

func (*Result) HasMismatches

func (r *Result) HasMismatches() bool

HasMismatches returns true if version mismatches were detected.

func (*Result) HasModules

func (r *Result) HasModules() bool

HasModules returns true if any .version files were found.

func (*Result) IsEmpty

func (r *Result) IsEmpty() bool

IsEmpty returns true if no version sources were found.

func (*Result) PrimaryVersion

func (r *Result) PrimaryVersion() string

PrimaryVersion returns the recommended primary version based on discovery. Priority: .version in cwd > first module > first manifest

func (*Result) WithFilter

func (r *Result) WithFilter(filter FileFilter) []Module

WithFilter returns a filtered list of modules.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service provides version source discovery functionality.

func NewService

func NewService(fs core.FileSystem, cfg *config.Config) *Service

NewService creates a new discovery Service.

func (*Service) Discover

func (s *Service) Discover(ctx context.Context, root string) (*Result, error)

Discover scans the given root directory and returns discovery results.

func (*Service) DiscoverManifestsOnly

func (s *Service) DiscoverManifestsOnly(ctx context.Context, root string) ([]ManifestSource, error)

DiscoverManifestsOnly is a convenience method that only discovers manifest files. It uses the configured manifest max depth (default: 3).

func (*Service) DiscoverModulesOnly

func (s *Service) DiscoverModulesOnly(ctx context.Context, root string) ([]Module, error)

DiscoverModulesOnly is a convenience method that only discovers .version files.

func (*Service) DiscoverWithDepth

func (s *Service) DiscoverWithDepth(ctx context.Context, root string, manifestMaxDepth int) (*Result, error)

DiscoverWithDepth scans the given root directory with a specified manifest discovery depth. If manifestMaxDepth is -1, the configured default (or 3) is used.

type SyncCandidate

type SyncCandidate struct {
	// Path is the relative path to the file.
	Path string

	// Format is the file format.
	Format parser.Format

	// Field is the dot-notation path to the version field.
	Field string

	// Pattern is the regex pattern (for regex format).
	Pattern string

	// Version is the current version in the file.
	Version string

	// Description is a human-readable description.
	Description string
}

SyncCandidate represents a file that can be synced via dependency-check.

func (SyncCandidate) ToFileConfig

func (s SyncCandidate) ToFileConfig() parser.FileConfig

ToFileConfig converts a SyncCandidate to a parser.FileConfig.

type VersionSummary

type VersionSummary struct {
	// Version is the version string.
	Version string

	// Count is how many sources have this version.
	Count int

	// Sources lists the paths with this version.
	Sources []string
}

VersionSummary provides a summary of version distribution.

func GetVersionSummary

func GetVersionSummary(result *Result) []VersionSummary

GetVersionSummary returns a summary of version distribution across sources.

Jump to

Keyboard shortcuts

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