From d88c8699173020df2d9827a5ae62e168941902f4 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Sat, 13 Jan 2024 16:06:18 -0500 Subject: [PATCH] fix(check): should not panic when all specified files excluded (#21929) Closes #21926 --- cli/module_loader.rs | 6 ++++++ cli/tests/integration/check_tests.rs | 6 ++++++ cli/tests/testdata/check/excluded_file_specified/check.out | 1 + cli/tests/testdata/check/excluded_file_specified/deno.json | 6 ++++++ .../testdata/check/excluded_file_specified/lib/types.d.ts | 2 ++ cli/tools/check.rs | 4 ++++ 6 files changed, 25 insertions(+) create mode 100644 cli/tests/testdata/check/excluded_file_specified/check.out create mode 100644 cli/tests/testdata/check/excluded_file_specified/deno.json create mode 100644 cli/tests/testdata/check/excluded_file_specified/lib/types.d.ts diff --git a/cli/module_loader.rs b/cli/module_loader.rs index 9deb13b7dc..dc7b2b9b67 100644 --- a/cli/module_loader.rs +++ b/cli/module_loader.rs @@ -50,6 +50,7 @@ use deno_graph::JsonModule; use deno_graph::Module; use deno_graph::Resolution; use deno_lockfile::Lockfile; +use deno_runtime::colors; use deno_runtime::deno_fs; use deno_runtime::deno_node::NodeResolution; use deno_runtime::deno_node::NodeResolutionMode; @@ -227,6 +228,11 @@ impl ModuleLoadPreparer { let lib = self.options.ts_type_lib_window(); let specifiers = self.collect_specifiers(files)?; + + if specifiers.is_empty() { + log::warn!("{} No matching files found.", colors::yellow("Warning")); + } + self .prepare_module_load( specifiers, diff --git a/cli/tests/integration/check_tests.rs b/cli/tests/integration/check_tests.rs index 36b80149d4..6b2bf96d4d 100644 --- a/cli/tests/integration/check_tests.rs +++ b/cli/tests/integration/check_tests.rs @@ -161,6 +161,12 @@ itest!(check_imported_files_listed_in_exclude_option { exit_code: 1, }); +itest!(check_with_excluded_file_specified { + args: "check lib/types.d.ts", + cwd: Some("check/excluded_file_specified/"), + output: "check/excluded_file_specified/check.out", +}); + #[test] fn cache_switching_config_then_no_config() { let context = TestContext::default(); diff --git a/cli/tests/testdata/check/excluded_file_specified/check.out b/cli/tests/testdata/check/excluded_file_specified/check.out new file mode 100644 index 0000000000..2bc26aaaf7 --- /dev/null +++ b/cli/tests/testdata/check/excluded_file_specified/check.out @@ -0,0 +1 @@ +Warning No matching files found. diff --git a/cli/tests/testdata/check/excluded_file_specified/deno.json b/cli/tests/testdata/check/excluded_file_specified/deno.json new file mode 100644 index 0000000000..039be18dfd --- /dev/null +++ b/cli/tests/testdata/check/excluded_file_specified/deno.json @@ -0,0 +1,6 @@ +{ + "compilerOptions": { + "types": ["./lib/types.d.ts"] + }, + "exclude": ["lib"] +} diff --git a/cli/tests/testdata/check/excluded_file_specified/lib/types.d.ts b/cli/tests/testdata/check/excluded_file_specified/lib/types.d.ts new file mode 100644 index 0000000000..a02ad0cbe5 --- /dev/null +++ b/cli/tests/testdata/check/excluded_file_specified/lib/types.d.ts @@ -0,0 +1,2 @@ +// deno-lint-ignore-file +declare var test: number; diff --git a/cli/tools/check.rs b/cli/tools/check.rs index 7133f4d3f8..7ce9c578cd 100644 --- a/cli/tools/check.rs +++ b/cli/tools/check.rs @@ -87,6 +87,10 @@ impl TypeChecker { graph: Arc, options: CheckOptions, ) -> Result { + if graph.roots.is_empty() { + return Ok(Default::default()); + } + // node built-in specifiers use the @types/node package to determine // types, so inject that now (the caller should do this after the lockfile // has been written)