Skip to main content

Crate projectdetect

Crate projectdetect 

Source
Expand description

Detect what kind of project a directory is — Go module, Node app, Rust crate, Xcode project, Terraform stack, and 20+ more — by checking canonical indicator files and directories.

This is a Rust port of the Go library github.com/richardwooding/projectdetect.

§What it does

  • detect — what project type(s) does this directory look like? A directory can match several at once (a Go module that also ships a docker-compose.yml matches both go and docker-compose).
  • Registry::find — recursively walk a tree for project roots.
  • Registry::resolve_for_path / Resolver — which project does a given file belong to (nearest-ancestor walk-up)?
  • Registry::collect_build_excludes — the union of canonical build-artefact dirs (vendor, node_modules, target, …) under a tree.

§Quick start

for m in projectdetect::detect(".") {
    println!("{} (via {})", m.r#type, m.indicator);
}

§Indicators

A ProjectType matches by Indicators: an exact filename (Indicator::HasFile, case-insensitive), a file-basename glob (Indicator::HasGlob), a subdirectory-basename glob (Indicator::HasSubdirGlob, for directory markers like *.xcodeproj), or — with the cel feature — a CEL expression (Indicator::Cel) over the directory’s files / subdirs.

§Custom types

Extra types load from YAML (Registry::load_from_file) or via layered discovery.

Structs§

Config
The YAML schema accepted by Registry::load_from_file.
ConfigEntry
One project type declared in a config file.
ConfigIndicator
The YAML representation of an Indicator. Exactly one field should be set; if several are, precedence is has_file > has_glob > has_subdir_glob > cel (matching the Go loader).
DiscoveryEntry
One config search location with its scope.
FindOptions
Configures a recursive search for project roots under a starting directory.
FindResult
The structured output of Registry::find.
FoundProject
One project root found during a Registry::find walk.
Match
Couples a matched project type with the indicator that fired. Surfaced by crate::Registry::detect so consumers can audit detection decisions.
ProjectType
Describes a kind of project and the Indicators that identify it.
Registry
Holds the registered ProjectTypes used for detection.
Resolver
A caching file→project resolver bound to a registry and a walk-up root.

Enums§

Error
Errors surfaced by registration, config loading, and CEL compilation.
Indicator
A single match rule evaluated against a directory’s listing.

Constants§

CONFIG_DIR_NAME
The user-wide config subdirectory (under the platform config dir).
CONFIG_FILE_NAME
The config file basename searched in each layer.
PER_PROJECT_DIR_NAME
The per-project config subdirectory (under the current directory).

Functions§

collect_build_excludes
Returns the union of build-artefact dirs under root using the default registry. See Registry::collect_build_excludes.
detect
Detects the project type(s) of dir using the default registry. See Registry::detect.
discovery_entries
Returns the ordered config search locations: user-wide first, then per-project. Entries whose anchor cannot be resolved (no platform config dir, or no current dir) are omitted.
discovery_paths
Returns just the candidate paths from discovery_entries.
find
Recursively finds project roots under root using the default registry. See Registry::find.
load_discovered
Loads all discovered configs into the default registry. See Registry::load_discovered.
load_from_file
Loads a YAML project-type config into the default registry, returning the number of types registered. See Registry::load_from_file.
register
Registers a project type into the default registry at runtime.
resolve_for_path
Resolves the nearest project root for file_path using the default registry. See Registry::resolve_for_path.
type_names
Returns the names of every type registered in the default registry, sorted.

Type Aliases§

Result
Convenience alias used throughout the crate.