diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2023-03-12 23:32:59 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-12 23:32:59 -0400 |
commit | bcb6ee9d0864f490f6da47cbe2593310b21333ff (patch) | |
tree | e2e06d2466dec8022645e368455c1ed8f59cab7f /cli/args/mod.rs | |
parent | 8db853514caae431a0ce91360d854c1b7f3c405f (diff) |
refactor(npm): push npm struct creation to a higher level (#18139)
This has been bothering me for a while and it became more painful while
working on #18136 because injecting the shared progress bar became very
verbose. Basically we should move the creation of all these npm structs
up to a higher level.
This is a stepping stone for a future refactor where we can improve how
we create all our structs.
Diffstat (limited to 'cli/args/mod.rs')
-rw-r--r-- | cli/args/mod.rs | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/cli/args/mod.rs b/cli/args/mod.rs index 71cc4e218..5be5fc7ab 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -12,6 +12,7 @@ use self::package_json::PackageJsonDeps; use ::import_map::ImportMap; use indexmap::IndexMap; +use crate::npm::NpmRegistryApi; use crate::npm::NpmResolutionSnapshot; pub use config_file::BenchConfig; pub use config_file::CompilerOptions; @@ -664,13 +665,31 @@ impl CliOptions { .map(Some) } - pub fn get_npm_resolution_snapshot(&self) -> Option<NpmResolutionSnapshot> { + pub async fn resolve_npm_resolution_snapshot( + &self, + api: &NpmRegistryApi, + ) -> Result<Option<NpmResolutionSnapshot>, AnyError> { if let Some(state) = &*NPM_PROCESS_STATE { // TODO(bartlomieju): remove this clone - return Some(state.snapshot.clone()); + return Ok(Some(state.snapshot.clone())); + } + + if let Some(lockfile) = self.maybe_lock_file() { + if !lockfile.lock().overwrite { + return Ok(Some( + NpmResolutionSnapshot::from_lockfile(lockfile.clone(), api) + .await + .with_context(|| { + format!( + "failed reading lockfile '{}'", + lockfile.lock().filename.display() + ) + })?, + )); + } } - None + Ok(None) } // If the main module should be treated as being in an npm package. |