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 adocker-compose.ymlmatches bothgoanddocker-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. - Config
Entry - One project type declared in a config file.
- Config
Indicator - The YAML representation of an
Indicator. Exactly one field should be set; if several are, precedence ishas_file>has_glob>has_subdir_glob>cel(matching the Go loader). - Discovery
Entry - One config search location with its scope.
- Find
Options - Configures a recursive search for project roots under a starting directory.
- Find
Result - The structured output of
Registry::find. - Found
Project - One project root found during a
Registry::findwalk. - Match
- Couples a matched project type with the indicator that fired. Surfaced by
crate::Registry::detectso consumers can audit detection decisions. - Project
Type - 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
rootusing the default registry. SeeRegistry::collect_build_excludes. - detect
- Detects the project type(s) of
dirusing the default registry. SeeRegistry::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
rootusing the default registry. SeeRegistry::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_pathusing the default registry. SeeRegistry::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.