diff options
Diffstat (limited to 'cli/npm/installer.rs')
-rw-r--r-- | cli/npm/installer.rs | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/cli/npm/installer.rs b/cli/npm/installer.rs index 43f79d8f0..8590feb9c 100644 --- a/cli/npm/installer.rs +++ b/cli/npm/installer.rs @@ -25,23 +25,22 @@ struct PackageJsonDepsInstallerInner { } impl PackageJsonDepsInstallerInner { - pub fn reqs_with_info_futures( + pub fn reqs_with_info_futures<'a>( &self, + reqs: &'a [&'a NpmPackageReq], ) -> FuturesOrdered< impl Future< Output = Result< - (&NpmPackageReq, Arc<deno_npm::registry::NpmPackageInfo>), + (&'a NpmPackageReq, Arc<deno_npm::registry::NpmPackageInfo>), NpmRegistryPackageInfoLoadError, >, >, > { - let package_reqs = self.deps_provider.reqs(); - - FuturesOrdered::from_iter(package_reqs.into_iter().map(|req| { + FuturesOrdered::from_iter(reqs.iter().map(|req| { let api = self.npm_registry_api.clone(); async move { let info = api.package_info(&req.name).await?; - Ok::<_, NpmRegistryPackageInfoLoadError>((req, info)) + Ok::<_, NpmRegistryPackageInfoLoadError>((*req, info)) } })) } @@ -77,7 +76,24 @@ impl PackageJsonDepsInstaller { return Ok(()); // already installed by something else } - let mut reqs_with_info_futures = inner.reqs_with_info_futures(); + let package_reqs = inner.deps_provider.reqs(); + + // check if something needs resolving before bothering to load all + // the package information (which is slow) + if package_reqs.iter().all(|req| { + inner + .npm_resolution + .resolve_pkg_id_from_pkg_req(req) + .is_ok() + }) { + log::debug!( + "All package.json deps resolvable. Skipping top level install." + ); + return Ok(()); // everything is already resolvable + } + + let mut reqs_with_info_futures = + inner.reqs_with_info_futures(&package_reqs); while let Some(result) = reqs_with_info_futures.next().await { let (req, info) = result?; @@ -88,7 +104,7 @@ impl PackageJsonDepsInstaller { if inner.npm_registry_api.mark_force_reload() { log::debug!("Failed to resolve package. Retrying. Error: {err:#}"); // re-initialize - reqs_with_info_futures = inner.reqs_with_info_futures(); + reqs_with_info_futures = inner.reqs_with_info_futures(&package_reqs); } else { return Err(err.into()); } |