0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 17:34:47 -05:00

core: replace ModuleSpecifier::to_url() by as_url()

This commit is contained in:
Bert Belder 2019-07-08 23:04:07 +02:00
parent 72d9045528
commit f4c9b31405
No known key found for this signature in database
GPG key ID: 7A77887B2E2ED461
4 changed files with 11 additions and 13 deletions

View file

@ -199,8 +199,8 @@ impl DenoDir {
use_cache: bool, use_cache: bool,
no_fetch: bool, no_fetch: bool,
) -> impl Future<Item = ModuleMetaData, Error = deno_error::DenoError> { ) -> impl Future<Item = ModuleMetaData, Error = deno_error::DenoError> {
let module_url = specifier.to_url(); let module_url = specifier.as_url().to_owned();
debug!("fetch_module_meta_data. specifier {} ", module_url); debug!("fetch_module_meta_data. specifier {} ", &module_url);
let result = self.url_to_deps_path(&module_url); let result = self.url_to_deps_path(&module_url);
if let Err(err) = result { if let Err(err) = result {

View file

@ -6,6 +6,7 @@ use clap::ArgMatches;
use clap::Shell; use clap::Shell;
use clap::SubCommand; use clap::SubCommand;
use crate::deno_dir; use crate::deno_dir;
use deno::ModuleSpecifier;
use log::Level; use log::Level;
use std; use std;
use std::str; use std::str;
@ -629,14 +630,11 @@ pub enum DenoSubcommand {
} }
fn get_default_bundle_filename(source_file: &str) -> String { fn get_default_bundle_filename(source_file: &str) -> String {
use deno::ModuleSpecifier; let specifier = ModuleSpecifier::resolve_url_or_path(source_file).unwrap();
let url = ModuleSpecifier::resolve_url_or_path(source_file) let path_segments = specifier.as_url().path_segments().unwrap();
.unwrap() let file_name = path_segments.last().unwrap();
.to_url(); let file_stem = file_name.trim_end_matches(".ts").trim_end_matches(".js");
let path_segments = url.path_segments().unwrap(); format!("{}.bundle.js", file_stem)
let last = path_segments.last().unwrap();
String::from(last.trim_end_matches(".ts").trim_end_matches(".js"))
+ ".bundle.js"
} }
#[test] #[test]

View file

@ -384,7 +384,7 @@ impl ImportMap {
let address = address_vec.first().unwrap(); let address = address_vec.first().unwrap();
let after_prefix = &normalized_specifier[specifier_key.len()..]; let after_prefix = &normalized_specifier[specifier_key.len()..];
let base_url = address.to_url(); let base_url = address.as_url();
if let Ok(url) = base_url.join(after_prefix) { if let Ok(url) = base_url.join(after_prefix) {
debug!("Specifier {:?} was mapped to {:?} (via prefix specifier key {:?}).", normalized_specifier, url, address); debug!("Specifier {:?} was mapped to {:?} (via prefix specifier key {:?}).", normalized_specifier, url, address);
return Ok(Some(ModuleSpecifier::from(url))); return Ok(Some(ModuleSpecifier::from(url)));

View file

@ -43,8 +43,8 @@ impl fmt::Display for ModuleResolutionError {
pub struct ModuleSpecifier(Url); pub struct ModuleSpecifier(Url);
impl ModuleSpecifier { impl ModuleSpecifier {
pub fn to_url(&self) -> Url { pub fn as_url(&self) -> &Url {
self.0.clone() &self.0
} }
/// Resolves module using this algorithm: /// Resolves module using this algorithm: