diff options
author | Satya Rohith <me@satyarohith.com> | 2021-09-13 09:49:23 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-13 09:49:23 +0530 |
commit | 84f874715763df71bb3bbf77f0714f8afdc17bb3 (patch) | |
tree | 1d4b2b5da1a79fab2f6ccec4fd15601057afbc77 /cli/standalone.rs | |
parent | a442821d9790489242e8cdb9286ae3b237e4705c (diff) |
fix(lsp): support data urls in `deno.importMap` option (#11397)
Diffstat (limited to 'cli/standalone.rs')
-rw-r--r-- | cli/standalone.rs | 20 |
1 files changed, 2 insertions, 18 deletions
diff --git a/cli/standalone.rs b/cli/standalone.rs index 800dca4cb..a3ace49f7 100644 --- a/cli/standalone.rs +++ b/cli/standalone.rs @@ -1,16 +1,13 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. use crate::colors; -use crate::file_fetcher::get_source_from_bytes; -use crate::file_fetcher::strip_shebang; +use crate::file_fetcher::get_source_from_data_url; use crate::flags::Flags; use crate::ops; use crate::program_state::ProgramState; use crate::version; -use data_url::DataUrl; use deno_core::error::anyhow; use deno_core::error::type_error; -use deno_core::error::uri_error; use deno_core::error::AnyError; use deno_core::error::Context; use deno_core::futures::FutureExt; @@ -123,19 +120,6 @@ fn read_string_slice( Ok(string) } -fn get_source_from_data_url( - specifier: &ModuleSpecifier, -) -> Result<String, AnyError> { - let data_url = DataUrl::process(specifier.as_str()) - .map_err(|e| uri_error(format!("{:?}", e)))?; - let mime = data_url.mime_type(); - let charset = mime.get_parameter("charset").map(|v| v.to_string()); - let (bytes, _) = data_url - .decode_to_vec() - .map_err(|e| uri_error(format!("{:?}", e)))?; - Ok(strip_shebang(get_source_from_bytes(bytes, charset)?)) -} - const SPECIFIER: &str = "file://$deno$/bundle.js"; struct EmbeddedModuleLoader(String); @@ -169,7 +153,7 @@ impl ModuleLoader for EmbeddedModuleLoader { ) -> Pin<Box<deno_core::ModuleSourceFuture>> { let module_specifier = module_specifier.clone(); let is_data_uri = get_source_from_data_url(&module_specifier).ok(); - let code = if let Some(ref source) = is_data_uri { + let code = if let Some((ref source, _)) = is_data_uri { source.to_string() } else { self.0.to_string() |