fix(check): should not panic when all specified files excluded (#21929)

Closes #21926
This commit is contained in:
David Sherret 2024-01-13 16:06:18 -05:00 committed by GitHub
parent daed588557
commit d88c869917
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 25 additions and 0 deletions

View file

@ -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,

View file

@ -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();

View file

@ -0,0 +1 @@
Warning No matching files found.

View file

@ -0,0 +1,6 @@
{
"compilerOptions": {
"types": ["./lib/types.d.ts"]
},
"exclude": ["lib"]
}

View file

@ -0,0 +1,2 @@
// deno-lint-ignore-file
declare var test: number;

View file

@ -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)