Skip to main content

fallow_core/discover/
mod.rs

1mod entry_points;
2mod infrastructure;
3mod parse_scripts;
4mod walk;
5
6// Re-export types from fallow-types
7pub use fallow_types::discover::{DiscoveredFile, EntryPoint, EntryPointSource, FileId};
8
9// Re-export public functions — preserves the existing `crate::discover::*` API
10pub use entry_points::{
11    compile_glob_set, discover_entry_points, discover_plugin_entry_points,
12    discover_workspace_entry_points,
13};
14pub use infrastructure::discover_infrastructure_entry_points;
15pub use walk::{PRODUCTION_EXCLUDE_PATTERNS, SOURCE_EXTENSIONS, discover_files};
16
17/// Hidden (dot-prefixed) directories that should be included in file discovery.
18///
19/// Most hidden directories (`.git`, `.cache`, etc.) should be skipped, but certain
20/// convention directories contain source or config files that fallow needs to see:
21/// - `.storybook` — Storybook configuration (the Storybook plugin depends on this)
22/// - `.well-known` — Standard web convention directory
23/// - `.changeset` — Changesets configuration
24/// - `.github` — GitHub workflows and CI scripts
25const ALLOWED_HIDDEN_DIRS: &[&str] = &[".storybook", ".well-known", ".changeset", ".github"];
26
27#[cfg(test)]
28mod tests {
29    use super::*;
30
31    // ── ALLOWED_HIDDEN_DIRS exhaustiveness ───────────────────────────
32
33    #[test]
34    fn allowed_hidden_dirs_count() {
35        // Guard: if a new dir is added, add a test for it
36        assert_eq!(
37            ALLOWED_HIDDEN_DIRS.len(),
38            4,
39            "update tests when adding new allowed hidden dirs"
40        );
41    }
42
43    #[test]
44    fn allowed_hidden_dirs_all_start_with_dot() {
45        for dir in ALLOWED_HIDDEN_DIRS {
46            assert!(
47                dir.starts_with('.'),
48                "allowed hidden dir '{dir}' must start with '.'"
49            );
50        }
51    }
52
53    #[test]
54    fn allowed_hidden_dirs_no_duplicates() {
55        let mut seen = rustc_hash::FxHashSet::default();
56        for dir in ALLOWED_HIDDEN_DIRS {
57            assert!(seen.insert(*dir), "duplicate allowed hidden dir: {dir}");
58        }
59    }
60
61    #[test]
62    fn allowed_hidden_dirs_no_trailing_slash() {
63        for dir in ALLOWED_HIDDEN_DIRS {
64            assert!(
65                !dir.ends_with('/'),
66                "allowed hidden dir '{dir}' should not have trailing slash"
67            );
68        }
69    }
70
71    // ── Re-export smoke tests ───────────────────────────────────────
72
73    #[test]
74    fn file_id_re_exported() {
75        // Verify the re-export works by constructing a FileId through the discover module
76        let id = FileId(42);
77        assert_eq!(id.0, 42);
78    }
79
80    #[test]
81    fn source_extensions_re_exported() {
82        assert!(SOURCE_EXTENSIONS.contains(&"ts"));
83        assert!(SOURCE_EXTENSIONS.contains(&"tsx"));
84    }
85
86    #[test]
87    fn compile_glob_set_re_exported() {
88        let result = compile_glob_set(&["**/*.ts".to_string()]);
89        assert!(result.is_some());
90    }
91}