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/module_loader.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/module_loader.rs')
-rw-r--r-- | cli/module_loader.rs | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/cli/module_loader.rs b/cli/module_loader.rs index f79576108..9a2c511ff 100644 --- a/cli/module_loader.rs +++ b/cli/module_loader.rs @@ -224,7 +224,7 @@ impl ModuleLoadPreparer { ) -> Result<(), AnyError> { let lib = self.options.ts_type_lib_window(); - let specifiers = self.collect_specifiers(files); + let specifiers = self.collect_specifiers(files)?; self .prepare_module_load( specifiers, @@ -235,28 +235,30 @@ impl ModuleLoadPreparer { .await } - fn collect_specifiers(&self, files: &[String]) -> Vec<ModuleSpecifier> { - let excludes = match self.options.resolve_check_options() { - Ok(o) => o.exclude, - Err(_) => vec![], - }; - files - .iter() - .filter_map(|file| { - let file_url = - resolve_url_or_path(file, self.options.initial_cwd()).ok()?; - if file_url.scheme() != "file" { - return Some(file_url); - } - // ignore local files that match any of files listed in `exclude` option - let file_path = file_url.to_file_path().ok()?; - if excludes.iter().any(|e| file_path.starts_with(e)) { - None - } else { - Some(file_url) - } - }) - .collect::<Vec<_>>() + fn collect_specifiers( + &self, + files: &[String], + ) -> Result<Vec<ModuleSpecifier>, AnyError> { + let excludes = self.options.resolve_config_excludes()?; + Ok( + files + .iter() + .filter_map(|file| { + let file_url = + resolve_url_or_path(file, self.options.initial_cwd()).ok()?; + if file_url.scheme() != "file" { + return Some(file_url); + } + // ignore local files that match any of files listed in `exclude` option + let file_path = file_url.to_file_path().ok()?; + if excludes.matches_path(&file_path) { + None + } else { + Some(file_url) + } + }) + .collect::<Vec<_>>(), + ) } } |