fallow_types/discover.rs
1//! File discovery types: discovered files, file IDs, and entry points.
2
3use std::path::PathBuf;
4
5/// A discovered source file on disk.
6#[derive(Debug, Clone)]
7pub struct DiscoveredFile {
8 /// Unique file index.
9 pub id: FileId,
10 /// Absolute path.
11 pub path: PathBuf,
12 /// File size in bytes (for sorting largest-first).
13 pub size_bytes: u64,
14}
15
16/// Compact file identifier.
17#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
18pub struct FileId(pub u32);
19
20// Size assertions to prevent memory regressions in hot-path types.
21// These types are stored in large Vecs (one per project file) and iterated
22// in tight loops during discovery, parsing, and graph construction.
23const _: () = assert!(std::mem::size_of::<FileId>() == 4);
24#[cfg(all(target_pointer_width = "64", unix))]
25const _: () = assert!(std::mem::size_of::<DiscoveredFile>() == 40);
26
27/// An entry point into the module graph.
28#[derive(Debug, Clone)]
29pub struct EntryPoint {
30 /// Absolute path to the entry point file.
31 pub path: PathBuf,
32 /// How this entry point was discovered.
33 pub source: EntryPointSource,
34}
35
36/// Where an entry point was discovered from.
37#[derive(Debug, Clone)]
38pub enum EntryPointSource {
39 /// The `main` field in package.json.
40 PackageJsonMain,
41 /// The `module` field in package.json.
42 PackageJsonModule,
43 /// The `exports` field in package.json.
44 PackageJsonExports,
45 /// The `bin` field in package.json.
46 PackageJsonBin,
47 /// A script command in package.json.
48 PackageJsonScript,
49 /// Detected by a framework plugin.
50 Plugin {
51 /// Name of the plugin that detected this entry point.
52 name: String,
53 },
54 /// A test file (e.g., `*.test.ts`, `*.spec.ts`).
55 TestFile,
56 /// A default index file (e.g., `src/index.ts`).
57 DefaultIndex,
58 /// Manually configured in fallow config.
59 ManualEntry,
60}