Skip to main content

fallow_graph/graph/
support_reach.rs

1//! Reach of the support entry points, such as files that package.json scripts
2//! run. The graph build does not mark this reach; a caller computes it on
3//! demand.
4
5use fallow_types::discover::EntryPoint;
6use fixedbitset::FixedBitSet;
7use rustc_hash::FxHashSet;
8
9use super::ModuleGraph;
10
11impl ModuleGraph {
12    /// Record the support entry points of the graph. A path that is not a
13    /// module of the graph adds nothing.
14    pub fn set_support_entry_points(&mut self, entry_points: &[EntryPoint]) {
15        let paths: FxHashSet<&std::path::Path> =
16            entry_points.iter().map(|ep| ep.path.as_path()).collect();
17        self.support_entry_points = self
18            .modules
19            .iter()
20            .filter(|module| paths.contains(module.path.as_path()))
21            .map(|module| module.file_id)
22            .collect();
23    }
24
25    /// The modules that a support entry point reaches, the entry points
26    /// included, as a bitset indexed by `FileId`.
27    #[must_use]
28    pub fn support_reachable(&self) -> FixedBitSet {
29        self.collect_reachable(&self.support_entry_points, self.modules.len())
30    }
31}