summaryrefslogtreecommitdiff
path: root/cli/module_loader.rs
diff options
context:
space:
mode:
authornokazn <41154684+nokazn@users.noreply.github.com>2024-01-04 10:43:17 +0900
committerGitHub <noreply@github.com>2024-01-03 20:43:17 -0500
commita0b687235907ce91358677353c00f575548313b4 (patch)
tree5a91d08d997ac7226208f3a24211fef9ef1123ef /cli/module_loader.rs
parent00970daea2245bf4af6b3ee21d0e522fec5638b8 (diff)
fix(cli): respect `exclude` option for `deno check` command (#21779)
This PR fixes #21658. - `check` subcommand sees `exclude` option in `deno.json`. When some paths passed with `check` command listed in `exclude`, they are ignored. - When some files are listed in `exclude` and imported indirectly among module graph, they are checked.
Diffstat (limited to 'cli/module_loader.rs')
-rw-r--r--cli/module_loader.rs29
1 files changed, 25 insertions, 4 deletions
diff --git a/cli/module_loader.rs b/cli/module_loader.rs
index 445cf4902..f79576108 100644
--- a/cli/module_loader.rs
+++ b/cli/module_loader.rs
@@ -224,10 +224,7 @@ impl ModuleLoadPreparer {
) -> Result<(), AnyError> {
let lib = self.options.ts_type_lib_window();
- let specifiers = files
- .iter()
- .map(|file| resolve_url_or_path(file, self.options.initial_cwd()))
- .collect::<Result<Vec<_>, _>>()?;
+ let specifiers = self.collect_specifiers(files);
self
.prepare_module_load(
specifiers,
@@ -237,6 +234,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<_>>()
+ }
}
pub struct ModuleCodeSource {