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