use std::path::Path;
use super::path_info::{extract_package_name, is_bare_specifier};
use super::types::{ResolveContext, ResolveResult};
use super::workspace_alias::{aliased_specifier, try_aliased_workspace_package_fallback};
pub(super) fn is_inside_project_root(ctx: &ResolveContext<'_>, path: &Path) -> bool {
if path.starts_with(ctx.root) {
return true;
}
ctx.canonicalize_cache
.get(ctx.root)
.is_some_and(|canonical_root| path.starts_with(canonical_root))
}
pub(super) fn try_project_package_outside_root(
ctx: &ResolveContext<'_>,
from_file: &Path,
specifier: &str,
style_context: bool,
path: &Path,
) -> Option<ResolveResult> {
if !is_bare_specifier(specifier) || is_inside_project_root(ctx, path) {
return None;
}
let aliased = aliased_specifier(ctx, from_file, specifier);
let package_name = extract_package_name(aliased.as_deref().unwrap_or(specifier));
if !ctx.workspace_roots.contains_key(package_name.as_str()) {
return None;
}
try_aliased_workspace_package_fallback(ctx, from_file, specifier, style_context)
}