diff options
Diffstat (limited to 'cli/npm/managed/cache/registry_info.rs')
-rw-r--r-- | cli/npm/managed/cache/registry_info.rs | 28 |
1 files changed, 10 insertions, 18 deletions
diff --git a/cli/npm/managed/cache/registry_info.rs b/cli/npm/managed/cache/registry_info.rs index ea6b47969..24f0a12e7 100644 --- a/cli/npm/managed/cache/registry_info.rs +++ b/cli/npm/managed/cache/registry_info.rs @@ -19,7 +19,7 @@ use deno_npm::npm_rc::ResolvedNpmRc; use deno_npm::registry::NpmPackageInfo; use crate::args::CacheSetting; -use crate::http_util::HttpClient; +use crate::http_util::HttpClientProvider; use crate::npm::common::maybe_auth_header_for_npm_registry; use crate::util::progress_bar::ProgressBar; @@ -56,6 +56,7 @@ type PendingRegistryLoadFuture = #[derive(Debug)] pub struct RegistryInfoDownloader { cache: Arc<NpmCache>, + http_client_provider: Arc<HttpClientProvider>, npmrc: Arc<ResolvedNpmRc>, progress_bar: ProgressBar, memory_cache: Mutex<HashMap<String, MemoryCacheItem>>, @@ -64,11 +65,13 @@ pub struct RegistryInfoDownloader { impl RegistryInfoDownloader { pub fn new( cache: Arc<NpmCache>, + http_client_provider: Arc<HttpClientProvider>, npmrc: Arc<ResolvedNpmRc>, progress_bar: ProgressBar, ) -> Self { Self { cache, + http_client_provider, npmrc, progress_bar, memory_cache: Default::default(), @@ -78,18 +81,12 @@ impl RegistryInfoDownloader { pub async fn load_package_info( &self, name: &str, - current_runtime_http_client: &Arc<HttpClient>, ) -> Result<Option<Arc<NpmPackageInfo>>, AnyError> { let registry_url = self.npmrc.get_registry_url(name); let registry_config = self.npmrc.get_registry_config(name); self - .load_package_info_inner( - name, - registry_url, - registry_config, - current_runtime_http_client, - ) + .load_package_info_inner(name, registry_url, registry_config) .await .with_context(|| { format!( @@ -105,7 +102,6 @@ impl RegistryInfoDownloader { name: &str, registry_url: &Url, registry_config: &RegistryConfig, - current_runtime_http_client: &Arc<HttpClient>, ) -> Result<Option<Arc<NpmPackageInfo>>, AnyError> { if *self.cache.cache_setting() == CacheSetting::Only { return Err(custom_error( @@ -121,12 +117,8 @@ impl RegistryInfoDownloader { if let Some(cache_item) = mem_cache.get(name) { (false, cache_item.clone()) } else { - let future = self.create_load_future( - name, - registry_url, - registry_config, - current_runtime_http_client, - ); + let future = + self.create_load_future(name, registry_url, registry_config); let cache_item = MemoryCacheItem::PendingFuture(future); mem_cache.insert(name.to_string(), cache_item.clone()); (true, cache_item) @@ -215,20 +207,20 @@ impl RegistryInfoDownloader { name: &str, registry_url: &Url, registry_config: &RegistryConfig, - current_runtime_http_client: &Arc<HttpClient>, ) -> Shared<PendingRegistryLoadFuture> { let package_url = self.get_package_url(name, registry_url); let maybe_auth_header = maybe_auth_header_for_npm_registry(registry_config); let guard = self.progress_bar.update(package_url.as_str()); let cache = self.cache.clone(); - let http_client = current_runtime_http_client.clone(); + let http_client_provider = self.http_client_provider.clone(); let name = name.to_string(); // force this future to be polled on the current runtime because it's not // safe to share `HttpClient`s across runtimes and because a restart of // npm resolution might cause this package not to be resolved again // causing the future to never be polled deno_core::unsync::spawn(async move { - let maybe_bytes = http_client + let maybe_bytes = http_client_provider + .get_or_create()? .download_with_progress(package_url, maybe_auth_header, &guard) .await?; match maybe_bytes { |