Expand description
Detect the kind of a project (Rust, Node, Bun, Deno, Python, Lua, C, C++, or any custom kind you register) AND the workspace organizer (Cargo, Npm, Pnpm, Yarn, Bun, Deno, Go, Lerna, Nx, Turborepo, Mira) from on-disk signals, and scan a polyglot monorepo recursively.
§Two ways in
For the common case where the built-ins are enough:
use std::path::Path;
use standarbuild_detect::{detect_in_dir, discover, DiscoverOptions};
for hit in detect_in_dir(Path::new("./my-app")) {
println!("{:?}", hit);
}
let result = discover(Path::new("./my-monorepo"), &DiscoverOptions::default());
for p in &result.projects {
println!("{} -> {} at {} (member_of {:?})", p.label, p.kind, p.rel_path, p.member_of);
}
for w in &result.workspaces {
println!("{} workspace at {:?} with {} members", w.kind, w.root, w.members.len());
}To extend the detection space (custom kinds, custom precedence, or disabling a built-in), build your own registry:
use std::path::Path;
use standarbuild_detect::{
builtin, Detector, DetectorHit, DetectorRegistry, KindId,
};
struct WgslDetector;
impl Detector for WgslDetector {
fn name(&self) -> &str { "wgsl" }
fn priority(&self) -> i32 { 60 }
fn detect(&self, dir: &Path) -> Option<DetectorHit> {
dir.join("shaders").is_dir().then(|| DetectorHit::Project {
kind: KindId::custom("wgsl"),
signals: vec!["shaders/".into()],
})
}
}
let mut registry = DetectorRegistry::with_builtins();
registry.remove("c"); // we don't care about plain C
registry.add(WgslDetector);§Features
serde(default) — derivesSerialize/Deserializeon the public types and exposes POSIX-path serializers inpath_norm. Disable withdefault-features = falsefor the leanest dep tree.
§Breaking changes vs 0.2
Detector::kind() -> KindIdwas replaced byDetector::name() -> &str(string identifier for registry removal). Each detector decides what facet(s) to emit via itsDetectorHitreturn.Detector::detect() -> Option<DetectMatch>is nowOption<DetectorHit>.DetectMatchis gone;DetectorHitcarries project + workspace info.DetectorRegistry::detect(dir)returnsVec<DetectorHit>(previouslyOption<DetectMatch>) so multiple facets at the same dir (e.g. Cargo workspace + npm workspace) can all surface.discover()/discover_with()returnDetectionResult { projects, workspaces }instead ofVec<Discovered>.Discoveredwas renamed toProjectInfoand gainedmember_of: Vec<PathBuf>.DetectorRegistry::removenow takes&str(detector name) instead of&KindId, and returns the count of removed detectors instead of abool.
Re-exports§
pub use detect::detect_in_dir;pub use detector::Detector;pub use detector::DetectorHit;pub use detector::DetectorRegistry;pub use discover::discover;pub use discover::discover_with;pub use discover::DetectionResult;pub use discover::DiscoverOptions;pub use discover::LabelStrategy;pub use discover::ProjectInfo;pub use discover::WorkspaceInfo;pub use kind::KindId;pub use path_norm::to_posix;pub use path_norm::serialize_path;pub use path_norm::serialize_path_opt;pub use workspace::WorkspaceKindId;
Modules§
- builtin
- Built-in detectors for the project AND workspace kinds the library knows
about. Each type is
pubandDefault-constructible so callers can pick and choose, tweak the registry, or useregister_allto install the whole lot. - detect
- Convenience entry point: build a built-in registry on the fly and run a
single detection on one directory. For repeated calls, build a
crate::DetectorRegistryonce and reuse it. - detector
Detectortrait +DetectorRegistryfor composing project-AND-workspace detection. Built-ins live incrate::builtin; downstream crates implementDetectorfor any extra kind (project or workspace, or both).- discover
- Recursive workspace scan: starting from a root directory, walk down up to
max_depthlevels, run every registeredcrate::Detector, and build aDetectionResultcontaining both the projects and the workspace manifests found. - kind
- Opaque string-based identifier for a project kind. Built-in kinds are
exposed as
constitems; custom kinds (KindId::custom("wgsl")) let downstream crates extend the detection space without touching the lib. - path_
norm - POSIX-style path normalisation. Strips Windows verbatim prefixes
(
\\?\), dropsCurDirsegments, and replaces\with/. Useful when emitting paths into JSON / cross-platform tooling. - workspace
WorkspaceKindId— twin ofcrate::KindIdfor monorepo organizers.