use std::path::{Path, PathBuf};
use rustc_hash::FxHashMap;
use super::PackageJson;
use super::deno_json::load_member_package_manifest_in;
type ManifestOutcome = Result<Option<(String, PackageJson, Vec<String>)>, String>;
#[derive(Debug, Default)]
pub(super) struct ManifestCache {
scope: Option<PathBuf>,
outcomes: FxHashMap<PathBuf, ManifestOutcome>,
}
impl ManifestCache {
pub(super) fn new(root: &Path) -> Self {
Self {
scope: Some(crate::project_scope_base(root)),
outcomes: FxHashMap::default(),
}
}
#[cfg(test)]
pub(super) fn len(&self) -> usize {
self.outcomes.len()
}
}
pub(super) fn load_member_package_manifest_cached(
dir: &Path,
cache: &mut ManifestCache,
) -> ManifestOutcome {
if let Some(cached) = cache.outcomes.get(dir) {
return cached.clone();
}
let outcome = load_member_package_manifest_in(cache.scope.as_deref(), dir);
cache.outcomes.insert(dir.to_path_buf(), outcome.clone());
outcome
}