summaryrefslogtreecommitdiff
path: root/cli/media_type.rs
diff options
context:
space:
mode:
authorKitson Kelly <me@kitsonkelly.com>2020-11-02 13:51:56 +1100
committerGitHub <noreply@github.com>2020-11-02 13:51:56 +1100
commitfdcc78500cc1aff8c87d76abd1692e79977ac9cc (patch)
treeb3ce97db2d23344c9469d9488097601058b5e0e5 /cli/media_type.rs
parent3558769d4654aad478804e506ccdcac38881dac1 (diff)
refactor(cli): migrate runtime compile/bundle to new infrastructure (#8192)
Fixes #8060
Diffstat (limited to 'cli/media_type.rs')
-rw-r--r--cli/media_type.rs17
1 files changed, 17 insertions, 0 deletions
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