From 48c5c3a3fb2f43716528db8915b36e55c411d94f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Mon, 30 Oct 2023 23:58:57 +0100 Subject: feat(doc): support multiple file entry (#21018) This commit adds support for multiple entry points to `deno doc`. Unfortunately to achieve that, I had to change the semantics of the command to explicitly require `--filter` parameter for filtering symbols, instead of treating second free argument as the filter argument. `deno doc --builtin` is still supported, but cannot be mixed with actual entrypoints. --- cli/tools/doc.rs | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'cli/tools') diff --git a/cli/tools/doc.rs b/cli/tools/doc.rs index 1a770b2d3..5e87e7917 100644 --- a/cli/tools/doc.rs +++ b/cli/tools/doc.rs @@ -33,7 +33,7 @@ pub async fn print_docs( let capturing_parser = CapturingModuleParser::new(Some(&source_parser), &store); - let mut doc_nodes = match doc_flags.source_file { + let mut doc_nodes = match doc_flags.source_files { DocSourceFileFlag::Builtin => { let source_file_specifier = ModuleSpecifier::parse("internal://lib.deno.d.ts").unwrap(); @@ -64,18 +64,23 @@ pub async fn print_docs( doc::DocParser::new(&graph, doc_flags.private, capturing_parser)?; doc_parser.parse_module(&source_file_specifier)?.definitions } - DocSourceFileFlag::Path(source_file) => { + DocSourceFileFlag::Paths(source_files) => { let module_graph_builder = factory.module_graph_builder().await?; let maybe_lockfile = factory.maybe_lockfile(); - let module_specifier = - resolve_url_or_path(&source_file, cli_options.initial_cwd())?; - + let module_specifiers: Result, AnyError> = + source_files + .iter() + .map(|source_file| { + Ok(resolve_url_or_path(source_file, cli_options.initial_cwd())?) + }) + .collect(); + let module_specifiers = module_specifiers?; let mut loader = module_graph_builder.create_graph_loader(); let graph = module_graph_builder .create_graph_with_options(CreateGraphOptions { graph_kind: GraphKind::TypesOnly, - roots: vec![module_specifier.clone()], + roots: module_specifiers.clone(), loader: &mut loader, analyzer: &analyzer, }) @@ -85,8 +90,17 @@ pub async fn print_docs( graph_lock_or_exit(&graph, &mut lockfile.lock()); } - doc::DocParser::new(&graph, doc_flags.private, capturing_parser)? - .parse_with_reexports(&module_specifier)? + let doc_parser = + doc::DocParser::new(&graph, doc_flags.private, capturing_parser)?; + + let mut doc_nodes = vec![]; + + for module_specifier in module_specifiers { + let nodes = doc_parser.parse_with_reexports(&module_specifier)?; + doc_nodes.extend_from_slice(&nodes); + } + + doc_nodes } }; -- cgit v1.2.3