summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-01-13 16:06:18 -0500
committerGitHub <noreply@github.com>2024-01-13 16:06:18 -0500
commitd88c8699173020df2d9827a5ae62e168941902f4 (patch)
tree03437e3497e29a98c915f6489974c6f7d06e56de /cli
parentdaed58855775b4da042272a296b500d9b9e76e7d (diff)
fix(check): should not panic when all specified files excluded (#21929)
Closes #21926
Diffstat (limited to 'cli')
-rw-r--r--cli/module_loader.rs6
-rw-r--r--cli/tests/integration/check_tests.rs6
-rw-r--r--cli/tests/testdata/check/excluded_file_specified/check.out1
-rw-r--r--cli/tests/testdata/check/excluded_file_specified/deno.json6
-rw-r--r--cli/tests/testdata/check/excluded_file_specified/lib/types.d.ts2
-rw-r--r--cli/tools/check.rs4
6 files changed, 25 insertions, 0 deletions
diff --git a/cli/module_loader.rs b/cli/module_loader.rs
index 9deb13b7d..dc7b2b9b6 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 36b80149d..6b2bf96d4 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 000000000..2bc26aaaf
--- /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 000000000..039be18df
--- /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 000000000..a02ad0cbe
--- /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 7133f4d3f..7ce9c578c 100644
--- a/cli/tools/check.rs
+++ b/cli/tools/check.rs
@@ -87,6 +87,10 @@ impl TypeChecker {
graph: Arc<ModuleGraph>,
options: CheckOptions,
) -> Result<Diagnostics, AnyError> {
+ 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)