summaryrefslogtreecommitdiff
path: root/cli/module_loader.rs
diff options
context:
space:
mode:
authorLeo Kettmeir <crowlkats@toaxl.com>2024-09-18 12:15:13 -0700
committerGitHub <noreply@github.com>2024-09-18 21:15:13 +0200
commita1d0a427e807959666a6b23ae015e4e04659abf5 (patch)
treec588767979d1f7ded1830d042f737774b23addf6 /cli/module_loader.rs
parent7a41a939972b701e96cb70cbf0516595fefcae02 (diff)
feat: default to TS for file extension and support ext flag in more scenarios (#25472)
Closes #11220 Currently does lint, fmt, and repl
Diffstat (limited to 'cli/module_loader.rs')
-rw-r--r--cli/module_loader.rs22
1 files changed, 22 insertions, 0 deletions
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<TGraphContainer: ModuleGraphContainer> ModuleLoader
is_dynamic,
lib,
root_permissions.into(),
+ None,
)
.await?;
update_permit.commit();