summaryrefslogtreecommitdiff
path: root/cli/file_fetcher.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/file_fetcher.rs')
-rw-r--r--cli/file_fetcher.rs45
1 files changed, 44 insertions, 1 deletions
diff --git a/cli/file_fetcher.rs b/cli/file_fetcher.rs
index 25e9e8835..c0a9c7227 100644
--- a/cli/file_fetcher.rs
+++ b/cli/file_fetcher.rs
@@ -579,6 +579,29 @@ fn map_js_like_extension(path: &Path, default: MediaType) -> MediaType {
None => default,
Some("jsx") => MediaType::JSX,
Some("tsx") => MediaType::TSX,
+ // Because DTS files do not have a separate media type, or a unique
+ // extension, we have to "guess" at those things that we consider that
+ // look like TypeScript, and end with `.d.ts` are DTS files.
+ Some("ts") => {
+ if default == MediaType::TypeScript {
+ match path.file_stem() {
+ None => default,
+ Some(os_str) => {
+ if let Some(file_stem) = os_str.to_str() {
+ if file_stem.ends_with(".d") {
+ MediaType::Dts
+ } else {
+ default
+ }
+ } else {
+ default
+ }
+ }
+ }
+ } else {
+ default
+ }
+ }
Some(_) => default,
},
}
@@ -1564,7 +1587,7 @@ mod tests {
);
assert_eq!(
map_content_type(Path::new("foo/bar.d.ts"), None).0,
- MediaType::TypeScript
+ MediaType::Dts
);
assert_eq!(
map_content_type(Path::new("foo/bar.js"), None).0,
@@ -1741,6 +1764,26 @@ mod tests {
.0,
MediaType::JSX
);
+ assert_eq!(
+ map_content_type(
+ Path::new("foo/bar.d.ts"),
+ Some("application/x-javascript")
+ )
+ .0,
+ MediaType::JavaScript
+ );
+ assert_eq!(
+ map_content_type(Path::new("foo/bar.d.ts"), Some("text/plain")).0,
+ MediaType::Dts
+ );
+ assert_eq!(
+ map_content_type(
+ Path::new("foo/bar.d.ts"),
+ Some("video/vnd.dlna.mpeg-tts"),
+ )
+ .0,
+ MediaType::Dts
+ );
}
#[test]