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.rs77
1 files changed, 1 insertions, 76 deletions
diff --git a/cli/file_fetcher.rs b/cli/file_fetcher.rs
index 7ab2f5cce..4d3048750 100644
--- a/cli/file_fetcher.rs
+++ b/cli/file_fetcher.rs
@@ -178,33 +178,7 @@ pub fn map_content_type(
if let Some(content_type) = maybe_content_type {
let mut content_types = content_type.split(';');
let content_type = content_types.next().unwrap();
- let media_type = match content_type.trim().to_lowercase().as_ref() {
- "application/typescript"
- | "text/typescript"
- | "video/vnd.dlna.mpeg-tts"
- | "video/mp2t"
- | "application/x-typescript" => {
- map_js_like_extension(specifier, MediaType::TypeScript)
- }
- "application/javascript"
- | "text/javascript"
- | "application/ecmascript"
- | "text/ecmascript"
- | "application/x-javascript"
- | "application/node" => {
- map_js_like_extension(specifier, MediaType::JavaScript)
- }
- "text/jsx" => MediaType::Jsx,
- "text/tsx" => MediaType::Tsx,
- "application/json" | "text/json" => MediaType::Json,
- "application/wasm" => MediaType::Wasm,
- // Handle plain and possibly webassembly
- "text/plain" | "application/octet-stream" => MediaType::from(specifier),
- _ => {
- debug!("unknown content type: {}", content_type);
- MediaType::Unknown
- }
- };
+ let media_type = MediaType::from_content_type(specifier, content_type);
let charset = content_types
.map(str::trim)
.find_map(|s| s.strip_prefix("charset="))
@@ -216,55 +190,6 @@ pub fn map_content_type(
}
}
-/// Used to augment media types by using the path part of a module specifier to
-/// resolve to a more accurate media type.
-fn map_js_like_extension(
- specifier: &ModuleSpecifier,
- default: MediaType,
-) -> MediaType {
- let path = if specifier.scheme() == "file" {
- if let Ok(path) = specifier.to_file_path() {
- path
- } else {
- PathBuf::from(specifier.path())
- }
- } else {
- PathBuf::from(specifier.path())
- };
- match path.extension() {
- None => default,
- Some(os_str) => match os_str.to_str() {
- 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,
- },
- }
-}
-
/// Remove shebangs from the start of source code strings
fn strip_shebang(mut value: String) -> String {
if value.starts_with("#!") {