diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2024-01-08 12:18:42 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-08 17:18:42 +0000 |
commit | e212e1fc35ddae63f457f0f2a2e95154e008941f (patch) | |
tree | 6c1f553fbc529bfcab6413049af8f32ed31d1dfd /cli/tools/doc.rs | |
parent | ee45d5bf8f2e1826b2a106b030abe891cfc0b37c (diff) |
perf: skip expanding exclude globs (#21817)
We were calling `expand_glob` on our excludes, which is very expensive
and unnecessary because we can pattern match while traversing instead.
1. Doesn't expand "exclude" globs. Instead pattern matches while walking
the directory.
2. Splits up the "include" into base paths and applicable file patterns.
This causes less pattern matching to occur because we're only pattern
matching on patterns that might match and not ones in completely
unrelated directories.
Diffstat (limited to 'cli/tools/doc.rs')
-rw-r--r-- | cli/tools/doc.rs | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/cli/tools/doc.rs b/cli/tools/doc.rs index b0eecd044..b8d6b8a87 100644 --- a/cli/tools/doc.rs +++ b/cli/tools/doc.rs @@ -12,12 +12,13 @@ use crate::factory::CliFactory; use crate::graph_util::graph_lock_or_exit; use crate::graph_util::CreateGraphOptions; use crate::tsc::get_types_declaration_file_text; -use crate::util::glob::expand_globs; +use crate::util::fs::collect_specifiers; +use crate::util::glob::FilePatterns; +use crate::util::glob::PathOrPatternSet; use deno_core::anyhow::bail; use deno_core::anyhow::Context; use deno_core::error::AnyError; use deno_core::futures::FutureExt; -use deno_core::resolve_url_or_path; use deno_doc as doc; use deno_graph::CapturingModuleParser; use deno_graph::DefaultParsedSourceStore; @@ -100,19 +101,28 @@ pub async fn doc(flags: Flags, doc_flags: DocFlags) -> Result<(), AnyError> { let module_graph_builder = factory.module_graph_builder().await?; let maybe_lockfile = factory.maybe_lockfile(); - let expanded_globs = - expand_globs(source_files.iter().map(PathBuf::from).collect())?; - let module_specifiers: Result<Vec<ModuleSpecifier>, AnyError> = - expanded_globs - .iter() - .map(|source_file| { - Ok(resolve_url_or_path( - &source_file.to_string_lossy(), - cli_options.initial_cwd(), - )?) - }) - .collect(); - let module_specifiers = module_specifiers?; + let module_specifiers = collect_specifiers( + FilePatterns { + include: Some(PathOrPatternSet::from_absolute_paths( + source_files + .iter() + .map(|p| { + if p.starts_with("https:") + || p.starts_with("http:") + || p.starts_with("file:") + { + // todo(dsherret): don't store URLs in PathBufs + PathBuf::from(p) + } else { + cli_options.initial_cwd().join(p) + } + }) + .collect(), + )?), + exclude: Default::default(), + }, + |_, _| true, + )?; let mut loader = module_graph_builder.create_graph_loader(); let graph = module_graph_builder .create_graph_with_options(CreateGraphOptions { |