use std::path::{Path, PathBuf};
use fallow_config::TsconfigOutputMap;
use fallow_types::discover::EntryPointSource;
use super::entry_points::{
EntryTargets, OutputDirEntry, entry_has_parent_dir, resolve_entry_via_output_dir,
};
use crate::plugins::config_parser::lexical_normalize;
pub fn output_entry_source_file(base: &Path, entry: &str) -> Option<PathBuf> {
if entry.contains('*') || entry_has_parent_dir(entry) {
return None;
}
let canonical_base = dunce::canonicalize(base).ok()?;
let output_map = TsconfigOutputMap::from_project(base);
let targets = EntryTargets {
output_map: &output_map,
discovered: None,
};
match resolve_entry_via_output_dir(
base,
entry,
&canonical_base,
EntryPointSource::PackageJsonMain,
None,
targets,
) {
OutputDirEntry::ShortCircuit(entry_point) => {
entry_point.map(|entry_point| lexical_normalize(&entry_point.path))
}
OutputDirEntry::Continue => None,
}
}