feat(unstable): optional deno_modules directory (#19977)

Closes #15633
This commit is contained in:
David Sherret 2023-08-01 20:49:09 -04:00 committed by GitHub
parent 36ae37604a
commit 1cefa831fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
35 changed files with 2043 additions and 707 deletions

View file

@ -13,6 +13,7 @@ use super::path_to_regex::StringOrVec;
use super::path_to_regex::Token;
use crate::args::CacheSetting;
use crate::cache::GlobalHttpCache;
use crate::cache::HttpCache;
use crate::file_fetcher::FileFetcher;
use crate::http_util::HttpClient;
@ -415,13 +416,15 @@ enum VariableItems {
pub struct ModuleRegistry {
origins: HashMap<String, Vec<RegistryConfiguration>>,
file_fetcher: FileFetcher,
http_cache: Arc<GlobalHttpCache>,
}
impl ModuleRegistry {
pub fn new(location: PathBuf, http_client: Arc<HttpClient>) -> Self {
let http_cache = HttpCache::new(location);
// the http cache should always be the global one for registry completions
let http_cache = Arc::new(GlobalHttpCache::new(location));
let mut file_fetcher = FileFetcher::new(
http_cache,
http_cache.clone(),
CacheSetting::RespectHeaders,
true,
http_client,
@ -433,6 +436,7 @@ impl ModuleRegistry {
Self {
origins: HashMap::new(),
file_fetcher,
http_cache,
}
}
@ -517,10 +521,7 @@ impl ModuleRegistry {
"cache-control".to_string(),
"max-age=604800, immutable".to_string(),
);
self
.file_fetcher
.http_cache
.set(specifier, headers_map, &[])?;
self.http_cache.set(specifier, headers_map, &[])?;
}
let file = fetch_result?;
let config: RegistryConfigurationJson = serde_json::from_str(&file.source)?;