summaryrefslogtreecommitdiff
path: root/cli/file_fetcher.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/file_fetcher.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/file_fetcher.rs')
-rw-r--r--cli/file_fetcher.rs11
1 files changed, 10 insertions, 1 deletions
diff --git a/cli/file_fetcher.rs b/cli/file_fetcher.rs
index ca8fcbee4..2f4b0b3dc 100644
--- a/cli/file_fetcher.rs
+++ b/cli/file_fetcher.rs
@@ -138,11 +138,20 @@ fn fetch_local(specifier: &ModuleSpecifier) -> Result<File, AnyError> {
let local = specifier.to_file_path().map_err(|_| {
uri_error(format!("Invalid file path.\n Specifier: {specifier}"))
})?;
+ // If it doesnt have a extension, we want to treat it as typescript by default
+ let headers = if local.extension().is_none() {
+ Some(HashMap::from([(
+ "content-type".to_string(),
+ "application/typescript".to_string(),
+ )]))
+ } else {
+ None
+ };
let bytes = fs::read(local)?;
Ok(File {
specifier: specifier.clone(),
- maybe_headers: None,
+ maybe_headers: headers,
source: bytes.into(),
})
}