From 4f67f0cc6033983540ed51f1270fb420cac45487 Mon Sep 17 00:00:00 2001 From: Kitson Kelly Date: Sat, 7 Nov 2020 06:53:37 +1100 Subject: =?UTF-8?q?fix(cli):=20properly=20handle=20type=20checking=20root?= =?UTF-8?q?=20modules=20with=20type=20defini=E2=80=A6=20(#8263)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cli/module_graph.rs | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'cli/module_graph.rs') diff --git a/cli/module_graph.rs b/cli/module_graph.rs index 7a6d68086..9b3d79a94 100644 --- a/cli/module_graph.rs +++ b/cli/module_graph.rs @@ -1154,11 +1154,21 @@ impl Graph { .roots .iter() .map(|ms| { + // if the root module has a types specifier, we should be sending that + // to tsc instead of the original specifier + let specifier = self.resolve_specifier(ms); + let module = self.get_module(specifier).unwrap(); + let specifier = if let Some((_, types_specifier)) = &module.maybe_types + { + self.resolve_specifier(types_specifier) + } else { + specifier + }; ( // root modules can be redirects, so before we pass it to tsc we need // to resolve the redirect - self.resolve_specifier(ms).clone(), - self.get_media_type(ms).unwrap(), + specifier.clone(), + self.get_media_type(specifier).unwrap(), ) }) .collect() @@ -1934,6 +1944,23 @@ pub mod tests { assert_eq!(h.tsbuildinfo_calls.len(), 1); } + #[tokio::test] + async fn fix_graph_check_types_root() { + let specifier = ModuleSpecifier::resolve_url_or_path("file:///typesref.js") + .expect("could not resolve module"); + let (graph, _) = setup(specifier).await; + let result_info = graph + .check(CheckOptions { + debug: false, + emit: false, + lib: TypeLib::DenoWindow, + maybe_config_path: None, + reload: false, + }) + .expect("should have checked"); + assert!(result_info.diagnostics.is_empty()); + } + #[tokio::test] async fn test_graph_check_user_config() { let specifier = -- cgit v1.2.3