diff options
author | Kitson Kelly <me@kitsonkelly.com> | 2020-10-28 20:38:09 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-28 20:38:09 +1100 |
commit | e01664d0ae6259022a901b0dea026ca350a49446 (patch) | |
tree | e87f55f4b267dd0d0847d0ba764884cfc61ca1a5 /cli/module_graph2.rs | |
parent | a2f126068e17f6b586a049d5167f48284ed14f8e (diff) |
fix(cli): module graph handles redirects properly (#8159)
Fixes #8154
Diffstat (limited to 'cli/module_graph2.rs')
-rw-r--r-- | cli/module_graph2.rs | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/cli/module_graph2.rs b/cli/module_graph2.rs index 6c25ca8f2..df2e5fc61 100644 --- a/cli/module_graph2.rs +++ b/cli/module_graph2.rs @@ -763,7 +763,14 @@ impl Graph2 { let root_names: Vec<(ModuleSpecifier, MediaType)> = self .roots .iter() - .map(|ms| (ms.clone(), self.get_media_type(ms).unwrap())) + .map(|ms| { + ( + // 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(), + ) + }) .collect(); let maybe_tsbuildinfo = self.maybe_tsbuildinfo.clone(); let hash_data = @@ -793,7 +800,9 @@ impl Graph2 { for emit in &response.emitted_files { if let Some(specifiers) = &emit.maybe_specifiers { assert!(specifiers.len() == 1, "Unexpected specifier length"); - let specifier = specifiers[0].clone(); + // The specifier emitted might not be the redirected specifier, and + // therefore we need to ensure it is the correct one. + let specifier = graph.resolve_specifier(&specifiers[0]); // Sometimes if tsc sees a CommonJS file it will _helpfully_ output it // to ESM, which we don't really want unless someone has enabled the // check_js option. @@ -805,10 +814,10 @@ impl Graph2 { } match emit.media_type { MediaType::JavaScript => { - codes.insert(specifier, emit.data.clone()); + codes.insert(specifier.clone(), emit.data.clone()); } MediaType::SourceMap => { - maps.insert(specifier, emit.data.clone()); + maps.insert(specifier.clone(), emit.data.clone()); } _ => unreachable!(), } @@ -1139,9 +1148,11 @@ impl Graph2 { // instead. let result = if prefer_types && dep_module.maybe_types.is_some() { let (_, types) = dep_module.maybe_types.clone().unwrap(); - types + // It is possible that `types` points to a redirected specifier, so we + // need to ensure it resolves to the final specifier in the graph. + self.resolve_specifier(&types).clone() } else { - resolved_specifier + dep_module.specifier.clone() }; Ok(result) |