diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2023-05-01 14:35:23 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-01 14:35:23 -0400 |
commit | 9efed4c7a3d32de62e9c9b5e0c6712ce97637abb (patch) | |
tree | aa370f95df93c71f6c57d6a01a50b4df1955ee57 /cli/tools/info.rs | |
parent | 30628288ce2b411ca3def46129a4606073e16bac (diff) |
refactor(cli): remove ProcState - add CliFactory (#18900)
This removes `ProcState` and replaces it with a new `CliFactory` which
initializes our "service structs" on demand. This isn't a performance
improvement at the moment for `deno run`, but might unlock performance
improvements in the future.
Diffstat (limited to 'cli/tools/info.rs')
-rw-r--r-- | cli/tools/info.rs | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/cli/tools/info.rs b/cli/tools/info.rs index a59f8a4c8..d491f55dc 100644 --- a/cli/tools/info.rs +++ b/cli/tools/info.rs @@ -27,57 +27,61 @@ use deno_semver::npm::NpmPackageReqReference; use crate::args::Flags; use crate::args::InfoFlags; use crate::display; +use crate::factory::CliFactory; use crate::graph_util::graph_lock_or_exit; use crate::npm::CliNpmResolver; -use crate::proc_state::ProcState; use crate::util::checksum; pub async fn info(flags: Flags, info_flags: InfoFlags) -> Result<(), AnyError> { - let ps = ProcState::from_flags(flags).await?; + let factory = CliFactory::from_flags(flags).await?; + let cli_options = factory.cli_options(); if let Some(specifier) = info_flags.file { - let specifier = resolve_url_or_path(&specifier, ps.options.initial_cwd())?; - let mut loader = ps.module_graph_builder.create_graph_loader(); + let module_graph_builder = factory.module_graph_builder().await?; + let npm_resolver = factory.npm_resolver().await?; + let maybe_lockfile = factory.maybe_lockfile(); + let specifier = resolve_url_or_path(&specifier, cli_options.initial_cwd())?; + let mut loader = module_graph_builder.create_graph_loader(); loader.enable_loading_cache_info(); // for displaying the cache information - let graph = ps - .module_graph_builder + let graph = module_graph_builder .create_graph_with_loader(vec![specifier], &mut loader) .await?; - if let Some(lockfile) = &ps.lockfile { + if let Some(lockfile) = maybe_lockfile { graph_lock_or_exit(&graph, &mut lockfile.lock()); } if info_flags.json { let mut json_graph = json!(graph); - add_npm_packages_to_json(&mut json_graph, &ps.npm_resolver); + add_npm_packages_to_json(&mut json_graph, npm_resolver); display::write_json_to_stdout(&json_graph)?; } else { let mut output = String::new(); - GraphDisplayContext::write(&graph, &ps.npm_resolver, &mut output)?; + GraphDisplayContext::write(&graph, npm_resolver, &mut output)?; display::write_to_stdout_ignore_sigpipe(output.as_bytes())?; } } else { // If it was just "deno info" print location of caches and exit print_cache_info( - &ps, + &factory, info_flags.json, - ps.options.location_flag().as_ref(), + cli_options.location_flag().as_ref(), )?; } Ok(()) } fn print_cache_info( - state: &ProcState, + factory: &CliFactory, json: bool, location: Option<&deno_core::url::Url>, ) -> Result<(), AnyError> { - let deno_dir = &state.dir.root_path_for_display(); - let modules_cache = &state.file_fetcher.get_http_cache_location(); - let npm_cache = &state.npm_cache.as_readonly().get_cache_location(); - let typescript_cache = &state.dir.gen_cache.location; - let registry_cache = &state.dir.registries_folder_path(); - let mut origin_dir = state.dir.origin_data_folder_path(); + let dir = factory.deno_dir()?; + let modules_cache = factory.file_fetcher()?.get_http_cache_location(); + let npm_cache = factory.npm_cache()?.as_readonly().get_cache_location(); + let typescript_cache = &dir.gen_cache.location; + let registry_cache = dir.registries_folder_path(); + let mut origin_dir = dir.origin_data_folder_path(); + let deno_dir = dir.root_path_for_display().to_string(); if let Some(location) = &location { origin_dir = @@ -88,7 +92,7 @@ fn print_cache_info( if json { let mut output = json!({ - "denoDir": deno_dir.to_string(), + "denoDir": deno_dir, "modulesCache": modules_cache, "npmCache": npm_cache, "typescriptCache": typescript_cache, |