From a1d0a427e807959666a6b23ae015e4e04659abf5 Mon Sep 17 00:00:00 2001 From: Leo Kettmeir Date: Wed, 18 Sep 2024 12:15:13 -0700 Subject: feat: default to TS for file extension and support ext flag in more scenarios (#25472) Closes #11220 Currently does lint, fmt, and repl --- cli/module_loader.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'cli/module_loader.rs') diff --git a/cli/module_loader.rs b/cli/module_loader.rs index 86824cd70..a81c5a0aa 100644 --- a/cli/module_loader.rs +++ b/cli/module_loader.rs @@ -105,11 +105,32 @@ impl ModuleLoadPreparer { is_dynamic: bool, lib: TsTypeLib, permissions: crate::file_fetcher::FetchPermissionsOption, + ext_overwrite: Option<&String>, ) -> Result<(), AnyError> { log::debug!("Preparing module load."); let _pb_clear_guard = self.progress_bar.clear_guard(); let mut cache = self.module_graph_builder.create_fetch_cacher(permissions); + if let Some(ext) = ext_overwrite { + let maybe_content_type = match ext.as_str() { + "ts" => Some("text/typescript"), + "tsx" => Some("text/tsx"), + "js" => Some("text/javascript"), + "jsx" => Some("text/jsx"), + _ => None, + }; + if let Some(content_type) = maybe_content_type { + for root in roots { + cache.file_header_overrides.insert( + root.clone(), + std::collections::HashMap::from([( + "content-type".to_string(), + content_type.to_string(), + )]), + ); + } + } + } log::debug!("Building module graph."); let has_type_checked = !graph.roots.is_empty(); @@ -763,6 +784,7 @@ impl ModuleLoader is_dynamic, lib, root_permissions.into(), + None, ) .await?; update_permit.commit(); -- cgit v1.2.3