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/doc.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/doc.rs')
-rw-r--r-- | cli/tools/doc.rs | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/cli/tools/doc.rs b/cli/tools/doc.rs index a07ba175a..2cb53cb6a 100644 --- a/cli/tools/doc.rs +++ b/cli/tools/doc.rs @@ -6,9 +6,9 @@ use crate::args::Flags; use crate::colors; use crate::display::write_json_to_stdout; use crate::display::write_to_stdout_ignore_sigpipe; +use crate::factory::CliFactory; use crate::file_fetcher::File; use crate::graph_util::graph_lock_or_exit; -use crate::proc_state::ProcState; use crate::tsc::get_types_declaration_file_text; use deno_ast::MediaType; use deno_core::anyhow::bail; @@ -23,13 +23,14 @@ pub async fn print_docs( flags: Flags, doc_flags: DocFlags, ) -> Result<(), AnyError> { - let ps = ProcState::from_flags(flags).await?; + let factory = CliFactory::from_flags(flags).await?; + let cli_options = factory.cli_options(); let mut doc_nodes = match doc_flags.source_file { DocSourceFileFlag::Builtin => { let source_file_specifier = ModuleSpecifier::parse("internal://lib.deno.d.ts").unwrap(); - let content = get_types_declaration_file_text(ps.options.unstable()); + let content = get_types_declaration_file_text(cli_options.unstable()); let mut loader = deno_graph::source::MemoryLoader::new( vec![( source_file_specifier.to_string(), @@ -61,13 +62,18 @@ pub async fn print_docs( doc_parser.parse_module(&source_file_specifier)?.definitions } DocSourceFileFlag::Path(source_file) => { + let file_fetcher = factory.file_fetcher()?; + let module_graph_builder = factory.module_graph_builder().await?; + let maybe_lockfile = factory.maybe_lockfile(); + let parsed_source_cache = factory.parsed_source_cache()?; + let module_specifier = - resolve_url_or_path(&source_file, ps.options.initial_cwd())?; + resolve_url_or_path(&source_file, cli_options.initial_cwd())?; // If the root module has external types, the module graph won't redirect it, // so instead create a dummy file which exports everything from the actual file being documented. let root_specifier = - resolve_path("./$deno$doc.ts", ps.options.initial_cwd()).unwrap(); + resolve_path("./$deno$doc.ts", cli_options.initial_cwd()).unwrap(); let root = File { local: PathBuf::from("./$deno$doc.ts"), maybe_types: None, @@ -78,21 +84,20 @@ pub async fn print_docs( }; // Save our fake file into file fetcher cache. - ps.file_fetcher.insert_cached(root); + file_fetcher.insert_cached(root); - let graph = ps - .module_graph_builder + let graph = module_graph_builder .create_graph(vec![root_specifier.clone()]) .await?; - if let Some(lockfile) = &ps.lockfile { + if let Some(lockfile) = maybe_lockfile { graph_lock_or_exit(&graph, &mut lockfile.lock()); } let doc_parser = doc::DocParser::new( graph, doc_flags.private, - ps.parsed_source_cache.as_capturing_parser(), + parsed_source_cache.as_capturing_parser(), ); doc_parser.parse_with_reexports(&root_specifier)? } |