use rustc_hash::FxHashSet;
use crate::discover::FileId;
use crate::graph::{ExportNamespace, ModuleGraph, ModuleNode};
use super::ExportKey;
pub(super) fn exposes_entry_members(
module: &ModuleNode,
entry_exports_config: Option<&fallow_config::ResolvedConfig>,
) -> bool {
module.is_entry_point() && !requires_project_consumers(module, entry_exports_config)
}
fn requires_project_consumers(
module: &ModuleNode,
entry_exports_config: Option<&fallow_config::ResolvedConfig>,
) -> bool {
module.is_consumer_checked()
|| entry_exports_config.is_some_and(|config| config.include_entry_exports_for(&module.path))
}
pub(super) fn public_member_entries(
graph: &ModuleGraph,
public_api_entry_points: &FxHashSet<FileId>,
entry_exports_config: Option<&fallow_config::ResolvedConfig>,
) -> Option<FxHashSet<FileId>> {
let removes = |file_id: &FileId| {
graph
.modules()
.get(file_id.0 as usize)
.is_some_and(|module| requires_project_consumers(module, entry_exports_config))
};
if !public_api_entry_points.iter().any(removes) {
return None;
}
Some(
public_api_entry_points
.iter()
.copied()
.filter(|file_id| !removes(file_id))
.collect(),
)
}
pub(super) fn public_declaration_keys(
graph: &ModuleGraph,
entries: &FxHashSet<FileId>,
) -> FxHashSet<ExportKey> {
[ExportNamespace::Value, ExportNamespace::Type]
.into_iter()
.flat_map(|namespace| graph.public_export_origins_in_namespace(entries, namespace))
.map(|origin| ExportKey::new(origin.file_id(), origin.export_name()))
.collect()
}