From fdcc78500cc1aff8c87d76abd1692e79977ac9cc Mon Sep 17 00:00:00 2001 From: Kitson Kelly Date: Mon, 2 Nov 2020 13:51:56 +1100 Subject: refactor(cli): migrate runtime compile/bundle to new infrastructure (#8192) Fixes #8060 --- cli/media_type.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'cli/media_type.rs') diff --git a/cli/media_type.rs b/cli/media_type.rs index 7d63439f6..cb26bcff5 100644 --- a/cli/media_type.rs +++ b/cli/media_type.rs @@ -1,5 +1,6 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. +use deno_core::ModuleSpecifier; use serde::Serialize; use serde::Serializer; use std::fmt; @@ -60,6 +61,22 @@ impl<'a> From<&'a String> for MediaType { } } +impl<'a> From<&'a ModuleSpecifier> for MediaType { + fn from(specifier: &'a ModuleSpecifier) -> Self { + let url = specifier.as_url(); + let path = if url.scheme() == "file" { + if let Ok(path) = url.to_file_path() { + path + } else { + PathBuf::from(url.path()) + } + } else { + PathBuf::from(url.path()) + }; + MediaType::from_path(&path) + } +} + impl Default for MediaType { fn default() -> Self { MediaType::Unknown -- cgit v1.2.3