diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2020-07-17 15:50:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-17 15:50:17 +0200 |
commit | 6e34f6a7cca11ba245f0b55c3b956b59948b37b7 (patch) | |
tree | 6263c56dc09c24d2bfa57505223e6932c7cf9fa7 /cli/global_state.rs | |
parent | 121eaa4efcaa5c8a4cab25eed15de07642e0407d (diff) |
fix: providing empty source code for missing compiled files (#6760)
This commit adds a fallback mechanism for absent compiled source file.
Because imported type declaration files are not emitted by TS compiler
and their imports are not elided users often hit "No such file or directory"
error. With this commit in such situation an empty source file will be
provided to V8 with a warning to the user suggesting using "import type"/
"export type" syntax instead.
Diffstat (limited to 'cli/global_state.rs')
-rw-r--r-- | cli/global_state.rs | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/cli/global_state.rs b/cli/global_state.rs index 3290be25f..8e5808c90 100644 --- a/cli/global_state.rs +++ b/cli/global_state.rs @@ -9,7 +9,6 @@ use crate::module_graph::ModuleGraphFile; use crate::module_graph::ModuleGraphLoader; use crate::msg; use crate::msg::MediaType; -use crate::op_error::OpError; use crate::permissions::Permissions; use crate::state::exit_unstable; use crate::tsc::CompiledModule; @@ -236,16 +235,22 @@ impl GlobalState { }; let compiled_module = if was_compiled { - state1 - .ts_compiler - .get_compiled_module(&out.url) - .map_err(|e| { - let msg = e.to_string(); - OpError::other(format!( - "Failed to get compiled source code of {}.\nReason: {}", - out.url, msg - )) - })? + match state1.ts_compiler.get_compiled_module(&out.url) { + Ok(module) => module, + Err(e) => { + let msg = format!( + "Failed to get compiled source code of \"{}\".\nReason: {}\n\ + If the source file provides only type exports, prefer to use \"import type\" or \"export type\" syntax instead.", + out.url, e.to_string() + ); + info!("{} {}", crate::colors::yellow("Warning"), msg); + + CompiledModule { + code: "".to_string(), + name: out.url.to_string(), + } + } + } } else { CompiledModule { code: String::from_utf8(out.source_code.clone())?, |