use std::path::Path;
use fallow_types::discover::FileId;
use super::{ResolveContext, alias_match_remainder, find_scss_in_dir};
pub(super) fn lookup_scss_path(candidate: &Path, ctx: &ResolveContext<'_>) -> Option<FileId> {
if let Some(&file_id) = ctx.raw_path_to_id.get(candidate) {
return Some(file_id);
}
if let Some(canonical) = ctx.canonicalize_cache.get(candidate) {
if let Some(&file_id) = ctx.path_to_id.get(canonical.as_path()) {
return Some(file_id);
}
if let Some(fallback) = ctx.canonical_fallback
&& let Some(file_id) = fallback.get(&canonical)
{
return Some(file_id);
}
}
None
}
pub(super) fn find_scss_through_path_alias(ctx: &ResolveContext<'_>, bare: &str) -> Option<FileId> {
ctx.path_aliases.iter().find_map(|(prefix, replacement)| {
let remainder = alias_match_remainder(bare, prefix)?.trim_start_matches('/');
let target_dir = ctx.root.join(replacement);
if remainder.is_empty() {
return lookup_scss_path(&target_dir, ctx);
}
find_scss_in_dir(&target_dir, remainder, ctx)
})
}