diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2023-05-22 16:55:04 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-22 16:55:04 -0400 |
commit | 7b4c483aa159794cdb9d57d3252c2980fba45469 (patch) | |
tree | b1c3b0ab080e98ab20f470fbad5b1aba05045dfb /cli/npm/installer.rs | |
parent | 612226de8e2fe3068d981866242bacedfceb9734 (diff) |
fix(npm): store npm binary command resolution in lockfile (#19219)
Part of #19038
Closes #19034 (eliminates the time spent re-resolving)
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()); } |