diff options
Diffstat (limited to 'cli/deno_dir.rs')
-rw-r--r-- | cli/deno_dir.rs | 605 |
1 files changed, 269 insertions, 336 deletions
diff --git a/cli/deno_dir.rs b/cli/deno_dir.rs index 990d3c661..8695b0578 100644 --- a/cli/deno_dir.rs +++ b/cli/deno_dir.rs @@ -30,6 +30,18 @@ use std::sync::Mutex; use url; use url::Url; +fn normalize_path(path: &Path) -> PathBuf { + let s = String::from(path.to_str().unwrap()); + let normalized_string = if cfg!(windows) { + // TODO This isn't correct. Probbly should iterate over components. + s.replace("\\", "/") + } else { + s + }; + + PathBuf::from(normalized_string) +} + #[derive(Clone, Default)] pub struct DownloadCache(Arc<Mutex<HashSet<String>>>); @@ -134,62 +146,36 @@ impl DenoDir { // https://github.com/denoland/deno/blob/golang/deno_dir.go#L32-L35 pub fn cache_path( self: &Self, - filename: &str, + filepath: &Path, source_code: &[u8], ) -> (PathBuf, PathBuf) { let cache_key = - source_code_hash(filename, source_code, version::DENO, &self.config); + source_code_hash(filepath, source_code, version::DENO, &self.config); ( self.gen.join(cache_key.to_string() + ".js"), self.gen.join(cache_key.to_string() + ".js.map"), ) } - pub fn code_cache( - self: &Self, - module_meta_data: &ModuleMetaData, - ) -> std::io::Result<()> { - let (cache_path, source_map_path) = self - .cache_path(&module_meta_data.filename, &module_meta_data.source_code); - // TODO(ry) This is a race condition w.r.t to exists() -- probably should - // create the file in exclusive mode. A worry is what might happen is there - // are two processes and one reads the cache file while the other is in the - // midst of writing it. - if cache_path.exists() && source_map_path.exists() { - Ok(()) - } else { - match &module_meta_data.maybe_output_code { - Some(output_code) => fs::write(cache_path, output_code), - _ => Ok(()), - }?; - match &module_meta_data.maybe_source_map { - Some(source_map) => fs::write(source_map_path, source_map), - _ => Ok(()), - }?; - Ok(()) - } - } - pub fn fetch_module_meta_data_async( self: &Self, specifier: &str, - referrer: &str, use_cache: bool, no_fetch: bool, ) -> impl Future<Item = ModuleMetaData, Error = deno_error::DenoError> { - debug!( - "fetch_module_meta_data. specifier {} referrer {}", - specifier, referrer - ); + debug!("fetch_module_meta_data. specifier {} ", specifier); + // TODO: rename specifier? let specifier = specifier.to_string(); - let referrer = referrer.to_string(); + // TODO: url resolution should happen here + // let module_name = ... - let result = self.resolve_module(&specifier, &referrer); + // TODO: this should return only deps filepath for given module URL + let result = self.resolve_module(&specifier, "."); if let Err(err) = result { return Either::A(futures::future::err(DenoError::from(err))); } - let (module_name, filename) = result.unwrap(); + let (module_name, filepath) = result.unwrap(); let gen = self.gen.clone(); @@ -202,7 +188,7 @@ impl DenoDir { get_source_code_async( self, module_name.as_str(), - filename.as_str(), + filepath, use_cache, no_fetch, ).then(move |result| { @@ -213,10 +199,7 @@ impl DenoDir { // For NotFound, change the message to something better. return Err(deno_error::new( ErrorKind::NotFound, - format!( - "Cannot resolve module \"{}\" from \"{}\"", - specifier, referrer - ), + format!("Cannot resolve module \"{}\"", specifier), )); } else { return Err(err); @@ -235,7 +218,7 @@ impl DenoDir { } let cache_key = source_code_hash( - &out.filename, + &PathBuf::from(&out.filename), &out.source_code, version::DENO, &config, @@ -260,10 +243,8 @@ impl DenoDir { Ok((output_code, source_map)) => { out.maybe_output_code = Some(output_code); out.maybe_source_map = Some(source_map); - out.maybe_output_code_filename = - Some(output_code_filename.to_str().unwrap().to_string()); - out.maybe_source_map_filename = - Some(output_source_map_filename.to_str().unwrap().to_string()); + out.maybe_output_code_filename = Some(output_code_filename); + out.maybe_source_map_filename = Some(output_source_map_filename); Ok(out) } } @@ -276,17 +257,16 @@ impl DenoDir { pub fn fetch_module_meta_data( self: &Self, specifier: &str, - referrer: &str, use_cache: bool, no_fetch: bool, ) -> Result<ModuleMetaData, deno_error::DenoError> { tokio_util::block_on( - self - .fetch_module_meta_data_async(specifier, referrer, use_cache, no_fetch), + self.fetch_module_meta_data_async(specifier, use_cache, no_fetch), ) } // Prototype: https://github.com/denoland/deno/blob/golang/os.go#L56-L68 + // TODO: this method should take deps filepath and return URL for module fn src_file_to_url(self: &Self, filename: &str) -> String { let filename_path = Path::new(filename); if filename_path.starts_with(&self.deps) { @@ -319,6 +299,11 @@ impl DenoDir { specifier: &str, referrer: &str, ) -> Result<Url, url::ParseError> { + debug!( + "pre-resolve_module specifier {} referrer {}", + specifier, referrer + ); + let specifier = self.src_file_to_url(specifier); let referrer = self.src_file_to_url(referrer); @@ -330,42 +315,34 @@ impl DenoDir { resolve_file_url(specifier, referrer) } + // TODO(bartlomieju): this method should return only `local filepath` + // it should be called with already resolved URLs + // TODO(bartlomieju): rename to url_to_deps_path /// Returns (module name, local filename) pub fn resolve_module( self: &Self, specifier: &str, referrer: &str, - ) -> Result<(String, String), url::ParseError> { + ) -> Result<(String, PathBuf), url::ParseError> { let j = self.resolve_module_url(specifier, referrer)?; let module_name = j.to_string(); - let filename; - match j.scheme() { - "file" => { - filename = deno_fs::normalize_path(j.to_file_path().unwrap().as_ref()); - } - "https" => { - filename = deno_fs::normalize_path( - get_cache_filename(self.deps_https.as_path(), &j).as_ref(), - ) - } - "http" => { - filename = deno_fs::normalize_path( - get_cache_filename(self.deps_http.as_path(), &j).as_ref(), - ) - } + let filename = match j.scheme() { + "file" => j.to_file_path().unwrap(), + "https" => get_cache_filename(self.deps_https.as_path(), &j), + "http" => get_cache_filename(self.deps_http.as_path(), &j), // TODO(kevinkassimo): change this to support other protocols than http. _ => unimplemented!(), - } + }; - debug!("module_name: {}, filename: {}", module_name, filename); - Ok((module_name, filename)) + debug!("module_name: {}, filename: {:?}", module_name, filename); + Ok((module_name, normalize_path(&filename))) } } impl SourceMapGetter for DenoDir { fn get_source_map(&self, script_name: &str) -> Option<Vec<u8>> { - match self.fetch_module_meta_data(script_name, ".", true, true) { + match self.fetch_module_meta_data(script_name, true, true) { Err(_e) => None, Ok(out) => match out.maybe_source_map { None => None, @@ -375,7 +352,7 @@ impl SourceMapGetter for DenoDir { } fn get_source_line(&self, script_name: &str, line: usize) -> Option<String> { - match self.fetch_module_meta_data(script_name, ".", true, true) { + match self.fetch_module_meta_data(script_name, true, true) { Ok(out) => match str::from_utf8(&out.source_code) { Ok(v) => { let lines: Vec<&str> = v.lines().collect(); @@ -405,11 +382,11 @@ impl SourceMapGetter for DenoDir { fn get_source_code_async( deno_dir: &DenoDir, module_name: &str, - filename: &str, + filepath: PathBuf, use_cache: bool, no_fetch: bool, ) -> impl Future<Item = ModuleMetaData, Error = DenoError> { - let filename = filename.to_string(); + let filename = filepath.to_str().unwrap().to_string(); let module_name = module_name.to_string(); let is_module_remote = is_remote(&module_name); // We try fetch local. Three cases: @@ -426,7 +403,7 @@ fn get_source_code_async( module_name, is_module_remote ); // Note that local fetch is done synchronously. - match fetch_local_source(deno_dir, &module_name, &filename, None) { + match fetch_local_source(deno_dir, &module_name, &filepath, None) { Ok(Some(output)) => { debug!("found local source "); return Either::A(futures::future::ok(output)); @@ -446,7 +423,7 @@ fn get_source_code_async( return Either::A(futures::future::err(DenoError::from( std::io::Error::new( std::io::ErrorKind::NotFound, - format!("cannot find local file '{}'", &filename), + format!("cannot find local file '{}'", filename), ), ))); } @@ -457,7 +434,7 @@ fn get_source_code_async( return Either::A(futures::future::err(DenoError::from( std::io::Error::new( std::io::ErrorKind::NotFound, - format!("cannot find remote file '{}' in cache", &filename), + format!("cannot find remote file '{}' in cache", filename), ), ))); } @@ -468,7 +445,7 @@ fn get_source_code_async( // not cached/local, try remote. Either::B( - fetch_remote_source_async(deno_dir, &module_name, &filename).and_then( + fetch_remote_source_async(deno_dir, &module_name, &filepath).and_then( move |maybe_remote_source| match maybe_remote_source { Some(output) => { download_cache.mark(&module_name); @@ -476,7 +453,7 @@ fn get_source_code_async( } None => Err(DenoError::from(std::io::Error::new( std::io::ErrorKind::NotFound, - format!("cannot find remote file '{}'", &filename), + format!("cannot find remote file '{}'", filename), ))), }, ), @@ -489,14 +466,14 @@ fn get_source_code_async( fn get_source_code( deno_dir: &DenoDir, module_name: &str, - filename: &str, + filepath: PathBuf, use_cache: bool, no_fetch: bool, ) -> DenoResult<ModuleMetaData> { tokio_util::block_on(get_source_code_async( deno_dir, module_name, - filename, + filepath, use_cache, no_fetch, )) @@ -536,14 +513,14 @@ fn load_cache2( /// Generate an SHA1 hash for source code, to be used to determine if a cached /// version of the code is valid or invalid. fn source_code_hash( - filename: &str, + filename: &Path, source_code: &[u8], version: &str, config: &[u8], ) -> String { let mut ctx = ring::digest::Context::new(&ring::digest::SHA1); ctx.update(version.as_bytes()); - ctx.update(filename.as_bytes()); + ctx.update(filename.to_str().unwrap().as_bytes()); ctx.update(source_code); ctx.update(config); let digest = ctx.finish(); @@ -555,10 +532,12 @@ fn source_code_hash( out } +// TODO: module_name should be Url fn is_remote(module_name: &str) -> bool { module_name.starts_with("http://") || module_name.starts_with("https://") } +// TODO: basically parse or resolve from_file_path fn parse_local_or_remote(p: &str) -> Result<url::Url, url::ParseError> { if is_remote(p) || p.starts_with("file:") { Url::parse(p) @@ -624,34 +603,32 @@ fn filter_shebang(bytes: Vec<u8>) -> Vec<u8> { /// Save source code and related headers for given module fn save_module_code_and_headers( - filename: &str, + filepath: PathBuf, module_name: &str, source: &str, maybe_content_type: Option<String>, - maybe_initial_filename: Option<String>, + maybe_initial_filepath: Option<PathBuf>, ) -> DenoResult<()> { - let p = PathBuf::from(filename); - match p.parent() { + match filepath.parent() { Some(ref parent) => fs::create_dir_all(parent), None => Ok(()), }?; // Write file and create .headers.json for the file. - deno_fs::write_file(&p, &source, 0o666)?; + deno_fs::write_file(&filepath, &source, 0o666)?; { - save_source_code_headers(filename, maybe_content_type.clone(), None); + save_source_code_headers(&filepath, maybe_content_type.clone(), None); } // Check if this file is downloaded due to some old redirect request. - if maybe_initial_filename.is_some() { + if maybe_initial_filepath.is_some() { // If yes, record down the headers for redirect. // Also create its containing folder. - let pp = PathBuf::from(filename); - match pp.parent() { + match filepath.parent() { Some(ref parent) => fs::create_dir_all(parent), None => Ok(()), }?; { save_source_code_headers( - &maybe_initial_filename.clone().unwrap(), + &maybe_initial_filepath.unwrap(), maybe_content_type.clone(), Some(module_name.to_string()), ); @@ -666,7 +643,7 @@ fn save_module_code_and_headers( fn fetch_remote_source_async( deno_dir: &DenoDir, module_name: &str, - filename: &str, + filepath: &Path, ) -> impl Future<Item = Option<ModuleMetaData>, Error = DenoError> { use crate::http_util::FetchOnceResult; @@ -674,8 +651,8 @@ fn fetch_remote_source_async( .progress .add(format!("Downloading {}", module_name)); - let filename = filename.to_owned(); let module_name = module_name.to_owned(); + let filepath = filepath.to_owned(); // We write a special ".headers.json" file into the `.deno/deps` directory along side the // cached file, containing just the media type and possible redirect target (both are http headers). @@ -687,14 +664,14 @@ fn fetch_remote_source_async( None, None, module_name.clone(), - filename.clone(), + filepath.clone(), ), |( dir, mut maybe_initial_module_name, - mut maybe_initial_filename, + mut maybe_initial_filepath, module_name, - filename, + filepath, )| { let url = module_name.parse::<http::uri::Uri>().unwrap(); // Single pass fetch, either yields code or yields redirect. @@ -702,43 +679,42 @@ fn fetch_remote_source_async( match fetch_once_result { FetchOnceResult::Redirect(url) => { // If redirects, update module_name and filename for next looped call. - let (new_module_name, new_filename) = dir + let (new_module_name, new_filepath) = dir .resolve_module(&url.to_string(), ".")?; if maybe_initial_module_name.is_none() { maybe_initial_module_name = Some(module_name.clone()); - maybe_initial_filename = Some(filename.clone()); + maybe_initial_filepath = Some(filepath.clone()); } // Not yet completed. Follow the redirect and loop. Ok(Loop::Continue(( dir, maybe_initial_module_name, - maybe_initial_filename, + maybe_initial_filepath, new_module_name, - new_filename, + new_filepath, ))) } FetchOnceResult::Code(source, maybe_content_type) => { // We land on the code. save_module_code_and_headers( - &filename.clone(), + filepath.clone(), &module_name.clone(), &source, maybe_content_type.clone(), - maybe_initial_filename, + maybe_initial_filepath, )?; - let p = PathBuf::from(filename.clone()); let media_type = map_content_type( - &p, + &filepath, maybe_content_type.as_ref().map(String::as_str), ); let module_meta_data = ModuleMetaData { module_name: module_name.to_string(), module_redirect_source_name: maybe_initial_module_name, - filename: filename.to_string(), + filename: filepath.clone(), media_type, source_code: source.as_bytes().to_owned(), maybe_output_code_filename: None, @@ -764,12 +740,12 @@ fn fetch_remote_source_async( fn fetch_remote_source( deno_dir: &DenoDir, module_name: &str, - filename: &str, + filepath: &Path, ) -> DenoResult<Option<ModuleMetaData>> { tokio_util::block_on(fetch_remote_source_async( deno_dir, module_name, - filename, + filepath, )) } @@ -785,11 +761,10 @@ fn fetch_remote_source( fn fetch_local_source( deno_dir: &DenoDir, module_name: &str, - filename: &str, + filepath: &Path, module_initial_source_name: Option<String>, ) -> DenoResult<Option<ModuleMetaData>> { - let p = Path::new(&filename); - let source_code_headers = get_source_code_headers(&filename); + let source_code_headers = get_source_code_headers(&filepath); // If source code headers says that it would redirect elsewhere, // (meaning that the source file might not exist; only .headers.json is present) // Abort reading attempts to the cached source file and and follow the redirect. @@ -800,8 +775,9 @@ fn fetch_local_source( // redirect_to https://import-meta.now.sh/sub/final1.js // real_filename /Users/kun/Library/Caches/deno/deps/https/import-meta.now.sh/sub/final1.js // real_module_name = https://import-meta.now.sh/sub/final1.js - let (real_module_name, real_filename) = + let (real_module_name, real_filepath) = deno_dir.resolve_module(&redirect_to, ".")?; + let mut module_initial_source_name = module_initial_source_name; // If this is the first redirect attempt, // then module_initial_source_name should be None. @@ -813,13 +789,13 @@ fn fetch_local_source( return fetch_local_source( deno_dir, &real_module_name, - &real_filename, + &real_filepath, module_initial_source_name, ); } // No redirect needed or end of redirects. // We can try read the file - let source_code = match fs::read(p) { + let source_code = match fs::read(filepath) { Err(e) => { if e.kind() == std::io::ErrorKind::NotFound { return Ok(None); @@ -832,9 +808,9 @@ fn fetch_local_source( Ok(Some(ModuleMetaData { module_name: module_name.to_string(), module_redirect_source_name: module_initial_source_name, - filename: filename.to_string(), + filename: filepath.to_owned(), media_type: map_content_type( - &p, + &filepath, source_code_headers.mime_type.as_ref().map(String::as_str), ), source_code, @@ -860,16 +836,16 @@ pub struct SourceCodeHeaders { static MIME_TYPE: &'static str = "mime_type"; static REDIRECT_TO: &'static str = "redirect_to"; -fn source_code_headers_filename(filename: &str) -> String { - [&filename, ".headers.json"].concat() +fn source_code_headers_filename(filepath: &Path) -> PathBuf { + PathBuf::from([filepath.to_str().unwrap(), ".headers.json"].concat()) } /// Get header metadata associated with a single source code file. /// NOTICE: chances are that the source code itself is not downloaded due to redirects. /// In this case, the headers file provides info about where we should go and get /// the source code that redirect eventually points to (which should be cached). -fn get_source_code_headers(filename: &str) -> SourceCodeHeaders { - let headers_filename = source_code_headers_filename(filename); +fn get_source_code_headers(filepath: &Path) -> SourceCodeHeaders { + let headers_filename = source_code_headers_filename(filepath); let hd = Path::new(&headers_filename); // .headers.json file might not exists. // This is okay for local source. @@ -897,15 +873,14 @@ fn get_source_code_headers(filename: &str) -> SourceCodeHeaders { /// content type of "text/javascript", then we would not save the mime type. /// If nothing needs to be saved, the headers file is not created. fn save_source_code_headers( - filename: &str, + filepath: &Path, mime_type: Option<String>, redirect_to: Option<String>, ) { - let headers_filename = source_code_headers_filename(filename); + let headers_filename = source_code_headers_filename(filepath); // Remove possibly existing stale .headers.json file. // May not exist. DON'T unwrap. let _ = std::fs::remove_file(&headers_filename); - let p = PathBuf::from(filename); // TODO(kevinkassimo): consider introduce serde::Deserialize to make things simpler. // This is super ugly at this moment... // Had trouble to make serde_derive work: I'm unable to build proc-macro2. @@ -914,7 +889,7 @@ fn save_source_code_headers( let mime_type_string = mime_type.clone().unwrap(); let resolved_mime_type = { map_content_type(Path::new(""), Some(mime_type_string.as_str())) }; - let ext_based_mime_type = map_file_extension(&p); + let ext_based_mime_type = map_file_extension(filepath); // Add mime to headers only when content type is different from extension. if ext_based_mime_type == msg::MediaType::Unknown || resolved_mime_type != ext_based_mime_type @@ -941,6 +916,36 @@ fn save_source_code_headers( } } +// TODO(bartlomieju): this method should be moved, it doesn't belong to deno_dir.rs +// it's a general utility +pub fn resolve_from_cwd(path: &str) -> Result<(PathBuf, String), DenoError> { + let candidate_path = Path::new(path); + + let resolved_path = if candidate_path.is_absolute() { + candidate_path.to_owned() + } else { + let cwd = std::env::current_dir().unwrap(); + cwd.join(path) + }; + + // HACK: `Url::from_directory_path` is used here because it normalizes the path. + // Joining `/dev/deno/" with "./tests" using `PathBuf` yields `/deno/dev/./tests/`. + // On the other hand joining `/dev/deno/" with "./tests" using `Url` yields "/dev/deno/tests" + // - and that's what we want. + // There exists similar method on `PathBuf` - `PathBuf.canonicalize`, but the problem + // is `canonicalize` resolves symlinks and we don't want that. + // We just want o normalize the path... + let resolved_url = Url::from_file_path(resolved_path) + .expect("PathBuf should be parseable URL"); + let normalized_path = resolved_url + .to_file_path() + .expect("URL from PathBuf should be valid path"); + + let path_string = normalized_path.to_str().unwrap().to_string(); + + Ok((normalized_path, path_string)) +} + pub fn resolve_file_url( specifier: String, mut referrer: String, @@ -951,6 +956,7 @@ pub fn resolve_file_url( referrer = referrer_path.to_str().unwrap().to_string() + "/"; } + // let j = if is_remote(&specifier) || (Path::new(&specifier).is_absolute() && !is_remote(&referrer)) { @@ -970,19 +976,15 @@ pub fn resolve_file_url( Ok(j) } -pub fn resolve_path(path: &str) -> Result<(PathBuf, String), DenoError> { - let url = resolve_file_url(path.to_string(), ".".to_string()) - .map_err(DenoError::from)?; - let path = url.to_file_path().unwrap(); - let path_string = path.to_str().unwrap().to_string(); - Ok((path, path_string)) -} - #[cfg(test)] mod tests { use super::*; use tempfile::TempDir; + fn normalize_to_str(path: &Path) -> String { + normalize_path(path).to_str().unwrap().to_string() + } + fn setup_deno_dir(dir_path: &Path) -> DenoDir { let config = Some(b"{}".to_vec()); DenoDir::new(Some(dir_path.to_path_buf()), &config, Progress::new()) @@ -1031,7 +1033,7 @@ mod tests { #[test] fn test_cache_path() { let (temp_dir, deno_dir) = test_setup(); - let filename = "hello.js"; + let filename = &PathBuf::from("hello.js"); let source_code = b"1+2"; let config = b"{}"; let hash = source_code_hash(filename, source_code, version::DENO, config); @@ -1049,7 +1051,7 @@ mod tests { // We are changing the compiler config from the "mock" and so we expect the // resolved files coming back to not match the calculated hash. let (temp_dir, deno_dir) = test_setup(); - let filename = "hello.js"; + let filename = &PathBuf::from("hello.js"); let source_code = b"1+2"; let config = b"{\"compilerOptions\":{}}"; let hash = source_code_hash(filename, source_code, version::DENO, config); @@ -1063,71 +1065,40 @@ mod tests { } #[test] - fn test_code_cache() { - let (_temp_dir, deno_dir) = test_setup(); - - let filename = "hello.js"; - let source_code = b"1+2"; - let output_code = b"1+2 // output code"; - let source_map = b"{}"; - let config = b"{}"; - let hash = source_code_hash(filename, source_code, version::DENO, config); - let (cache_path, source_map_path) = - deno_dir.cache_path(filename, source_code); - assert!(cache_path.ends_with(format!("gen/{}.js", hash))); - assert!(source_map_path.ends_with(format!("gen/{}.js.map", hash))); - - let out = ModuleMetaData { - filename: filename.to_owned(), - source_code: source_code[..].to_owned(), - module_name: "hello.js".to_owned(), - module_redirect_source_name: None, - media_type: msg::MediaType::TypeScript, - maybe_output_code: Some(output_code[..].to_owned()), - maybe_output_code_filename: None, - maybe_source_map: Some(source_map[..].to_owned()), - maybe_source_map_filename: None, - }; - - let r = deno_dir.code_cache(&out); - r.expect("code_cache error"); - assert!(cache_path.exists()); - assert_eq!(output_code[..].to_owned(), fs::read(&cache_path).unwrap()); - } - - #[test] fn test_source_code_hash() { assert_eq!( "830c8b63ba3194cf2108a3054c176b2bf53aee45", - source_code_hash("hello.ts", b"1+2", "0.2.11", b"{}") + source_code_hash(&PathBuf::from("hello.ts"), b"1+2", "0.2.11", b"{}") ); // Different source_code should result in different hash. assert_eq!( "fb06127e9b2e169bea9c697fa73386ae7c901e8b", - source_code_hash("hello.ts", b"1", "0.2.11", b"{}") + source_code_hash(&PathBuf::from("hello.ts"), b"1", "0.2.11", b"{}") ); // Different filename should result in different hash. assert_eq!( "3a17b6a493ff744b6a455071935f4bdcd2b72ec7", - source_code_hash("hi.ts", b"1+2", "0.2.11", b"{}") + source_code_hash(&PathBuf::from("hi.ts"), b"1+2", "0.2.11", b"{}") ); // Different version should result in different hash. assert_eq!( "d6b2cfdc39dae9bd3ad5b493ee1544eb22e7475f", - source_code_hash("hi.ts", b"1+2", "0.2.0", b"{}") + source_code_hash(&PathBuf::from("hi.ts"), b"1+2", "0.2.0", b"{}") ); } #[test] fn test_source_code_headers_get_and_save() { let (temp_dir, _deno_dir) = test_setup(); - let filename = - deno_fs::normalize_path(temp_dir.into_path().join("f.js").as_ref()); - let headers_file_name = source_code_headers_filename(&filename); - assert_eq!(headers_file_name, [&filename, ".headers.json"].concat()); - let _ = deno_fs::write_file(&PathBuf::from(&headers_file_name), + let filepath = temp_dir.into_path().join("f.js"); + let headers_filepath = source_code_headers_filename(&filepath); + assert_eq!( + headers_filepath.to_str().unwrap().to_string(), + [filepath.to_str().unwrap(), ".headers.json"].concat() + ); + let _ = deno_fs::write_file(headers_filepath.as_path(), "{\"mime_type\":\"text/javascript\",\"redirect_to\":\"http://example.com/a.js\"}", 0o666); - let headers = get_source_code_headers(&filename); + let headers = get_source_code_headers(&filepath); assert_eq!(headers.mime_type.clone().unwrap(), "text/javascript"); assert_eq!( headers.redirect_to.clone().unwrap(), @@ -1135,11 +1106,11 @@ mod tests { ); save_source_code_headers( - &filename, + &filepath, Some("text/typescript".to_owned()), Some("http://deno.land/a.js".to_owned()), ); - let headers2 = get_source_code_headers(&filename); + let headers2 = get_source_code_headers(&filepath); assert_eq!(headers2.mime_type.clone().unwrap(), "text/typescript"); assert_eq!( headers2.redirect_to.clone().unwrap(), @@ -1153,16 +1124,13 @@ mod tests { // http_util::fetch_sync_string requires tokio tokio_util::init(|| { let module_name = "http://localhost:4545/tests/subdir/mod2.ts"; - let filename = deno_fs::normalize_path( - deno_dir - .deps_http - .join("localhost_PORT4545/tests/subdir/mod2.ts") - .as_ref(), - ); - let headers_file_name = source_code_headers_filename(&filename); + let filepath = deno_dir + .deps_http + .join("localhost_PORT4545/tests/subdir/mod2.ts"); + let headers_file_name = source_code_headers_filename(&filepath); let result = - get_source_code(&deno_dir, module_name, &filename, true, false); + get_source_code(&deno_dir, module_name, filepath.clone(), true, false); assert!(result.is_ok()); let r = result.unwrap(); assert_eq!( @@ -1177,7 +1145,7 @@ mod tests { let _ = fs::write(&headers_file_name, "{ \"mime_type\": \"text/javascript\" }"); let result2 = - get_source_code(&deno_dir, module_name, &filename, true, false); + get_source_code(&deno_dir, module_name, filepath.clone(), true, false); assert!(result2.is_ok()); let r2 = result2.unwrap(); assert_eq!( @@ -1188,18 +1156,18 @@ mod tests { // as we modified before! (we do not overwrite .headers.json due to no http fetch) assert_eq!(&(r2.media_type), &msg::MediaType::JavaScript); assert_eq!( - get_source_code_headers(&filename).mime_type.unwrap(), + get_source_code_headers(&filepath).mime_type.unwrap(), "text/javascript" ); // Modify .headers.json again, but the other way around save_source_code_headers( - &filename, + &filepath, Some("application/json".to_owned()), None, ); let result3 = - get_source_code(&deno_dir, module_name, &filename, true, false); + get_source_code(&deno_dir, module_name, filepath.clone(), true, false); assert!(result3.is_ok()); let r3 = result3.unwrap(); assert_eq!( @@ -1219,7 +1187,7 @@ mod tests { // and don't use cache let deno_dir = setup_deno_dir(temp_dir.path()); let result4 = - get_source_code(&deno_dir, module_name, &filename, false, false); + get_source_code(&deno_dir, module_name, filepath.clone(), false, false); assert!(result4.is_ok()); let r4 = result4.unwrap(); let expected4 = @@ -1237,16 +1205,13 @@ mod tests { // http_util::fetch_sync_string requires tokio tokio_util::init(|| { let module_name = "http://localhost:4545/tests/subdir/mismatch_ext.ts"; - let filename = deno_fs::normalize_path( - deno_dir - .deps_http - .join("localhost_PORT4545/tests/subdir/mismatch_ext.ts") - .as_ref(), - ); - let headers_file_name = source_code_headers_filename(&filename); + let filepath = deno_dir + .deps_http + .join("localhost_PORT4545/tests/subdir/mismatch_ext.ts"); + let headers_file_name = source_code_headers_filename(&filepath); let result = - get_source_code(&deno_dir, module_name, &filename, true, false); + get_source_code(&deno_dir, module_name, filepath.clone(), true, false); assert!(result.is_ok()); let r = result.unwrap(); let expected = "export const loaded = true;\n".as_bytes(); @@ -1254,18 +1219,18 @@ mod tests { // Mismatch ext with content type, create .headers.json assert_eq!(&(r.media_type), &msg::MediaType::JavaScript); assert_eq!( - get_source_code_headers(&filename).mime_type.unwrap(), + get_source_code_headers(&filepath).mime_type.unwrap(), "text/javascript" ); // Modify .headers.json save_source_code_headers( - &filename, + &filepath, Some("text/typescript".to_owned()), None, ); let result2 = - get_source_code(&deno_dir, module_name, &filename, true, false); + get_source_code(&deno_dir, module_name, filepath.clone(), true, false); assert!(result2.is_ok()); let r2 = result2.unwrap(); let expected2 = "export const loaded = true;\n".as_bytes(); @@ -1279,7 +1244,7 @@ mod tests { // and don't use cache let deno_dir = setup_deno_dir(temp_dir.path()); let result3 = - get_source_code(&deno_dir, module_name, &filename, false, false); + get_source_code(&deno_dir, module_name, filepath.clone(), false, false); assert!(result3.is_ok()); let r3 = result3.unwrap(); let expected3 = "export const loaded = true;\n".as_bytes(); @@ -1288,7 +1253,7 @@ mod tests { // (due to http fetch) assert_eq!(&(r3.media_type), &msg::MediaType::JavaScript); assert_eq!( - get_source_code_headers(&filename).mime_type.unwrap(), + get_source_code_headers(&filepath).mime_type.unwrap(), "text/javascript" ); }); @@ -1300,17 +1265,14 @@ mod tests { // http_util::fetch_sync_string requires tokio tokio_util::init(|| { let module_name = "http://localhost:4545/tests/subdir/mismatch_ext.ts"; - let filename = deno_fs::normalize_path( - deno_dir - .deps_http - .join("localhost_PORT4545/tests/subdir/mismatch_ext.ts") - .as_ref(), - ); - let headers_file_name = source_code_headers_filename(&filename); + let filepath = deno_dir + .deps_http + .join("localhost_PORT4545/tests/subdir/mismatch_ext.ts"); + let headers_file_name = source_code_headers_filename(&filepath); // first download let result = - get_source_code(&deno_dir, module_name, &filename, false, false); + get_source_code(&deno_dir, module_name, filepath.clone(), false, false); assert!(result.is_ok()); let result = fs::File::open(&headers_file_name); @@ -1324,7 +1286,7 @@ mod tests { // false, this can be verified using source header file creation timestamp (should be // the same as after first download) let result = - get_source_code(&deno_dir, module_name, &filename, false, false); + get_source_code(&deno_dir, module_name, filepath.clone(), false, false); assert!(result.is_ok()); let result = fs::File::open(&headers_file_name); @@ -1345,24 +1307,23 @@ mod tests { tokio_util::init(|| { let redirect_module_name = "http://localhost:4546/tests/subdir/redirects/redirect1.js"; - let redirect_source_filename = deno_fs::normalize_path( - deno_dir - .deps_http - .join("localhost_PORT4546/tests/subdir/redirects/redirect1.js") - .as_ref(), - ); + let redirect_source_filepath = deno_dir + .deps_http + .join("localhost_PORT4546/tests/subdir/redirects/redirect1.js"); + let redirect_source_filename = + redirect_source_filepath.to_str().unwrap().to_string(); let target_module_name = "http://localhost:4545/tests/subdir/redirects/redirect1.js"; - let redirect_target_filename = deno_fs::normalize_path( - deno_dir - .deps_http - .join("localhost_PORT4545/tests/subdir/redirects/redirect1.js") - .as_ref(), - ); + let redirect_target_filepath = deno_dir + .deps_http + .join("localhost_PORT4545/tests/subdir/redirects/redirect1.js"); + let redirect_target_filename = + redirect_target_filepath.to_str().unwrap().to_string(); + let mod_meta = get_source_code( &deno_dir, redirect_module_name, - &redirect_source_filename, + redirect_source_filepath.clone(), true, false, ).unwrap(); @@ -1370,7 +1331,7 @@ mod tests { assert!(fs::read_to_string(&redirect_source_filename).is_err()); // ... but its .headers.json is created. let redirect_source_headers = - get_source_code_headers(&redirect_source_filename); + get_source_code_headers(&redirect_source_filepath); assert_eq!( redirect_source_headers.redirect_to.unwrap(), "http://localhost:4545/tests/subdir/redirects/redirect1.js" @@ -1381,7 +1342,7 @@ mod tests { "export const redirect = 1;\n" ); let redirect_target_headers = - get_source_code_headers(&redirect_target_filename); + get_source_code_headers(&redirect_target_filepath); assert!(redirect_target_headers.redirect_to.is_none()); // Examine the meta result. @@ -1400,13 +1361,12 @@ mod tests { tokio_util::init(|| { let redirect_module_name = "http://localhost:4548/tests/subdir/redirects/redirect1.js"; - let redirect_source_filename = deno_fs::normalize_path( - deno_dir - .deps_http - .join("localhost_PORT4548/tests/subdir/redirects/redirect1.js") - .as_ref(), - ); - let redirect_source_filename_intermediate = deno_fs::normalize_path( + let redirect_source_filepath = deno_dir + .deps_http + .join("localhost_PORT4548/tests/subdir/redirects/redirect1.js"); + let redirect_source_filename = + redirect_source_filepath.to_str().unwrap().to_string(); + let redirect_source_filename_intermediate = normalize_to_str( deno_dir .deps_http .join("localhost_PORT4546/tests/subdir/redirects/redirect1.js") @@ -1414,16 +1374,16 @@ mod tests { ); let target_module_name = "http://localhost:4545/tests/subdir/redirects/redirect1.js"; - let redirect_target_filename = deno_fs::normalize_path( - deno_dir - .deps_http - .join("localhost_PORT4545/tests/subdir/redirects/redirect1.js") - .as_ref(), - ); + let redirect_target_filepath = deno_dir + .deps_http + .join("localhost_PORT4545/tests/subdir/redirects/redirect1.js"); + let redirect_target_filename = + redirect_target_filepath.to_str().unwrap().to_string(); + let mod_meta = get_source_code( &deno_dir, redirect_module_name, - &redirect_source_filename, + redirect_source_filepath.clone(), true, false, ).unwrap(); @@ -1432,7 +1392,7 @@ mod tests { assert!(fs::read_to_string(&redirect_source_filename).is_err()); // ... but its .headers.json is created. let redirect_source_headers = - get_source_code_headers(&redirect_source_filename); + get_source_code_headers(&redirect_source_filepath); assert_eq!( redirect_source_headers.redirect_to.unwrap(), target_module_name @@ -1449,7 +1409,7 @@ mod tests { "export const redirect = 1;\n" ); let redirect_target_headers = - get_source_code_headers(&redirect_target_filename); + get_source_code_headers(&redirect_target_filepath); assert!(redirect_target_headers.redirect_to.is_none()); // Examine the meta result. @@ -1466,28 +1426,25 @@ mod tests { let (_temp_dir, deno_dir) = test_setup(); tokio_util::init(|| { let module_name = "http://localhost:4545/tests/002_hello.ts"; - let filename = deno_fs::normalize_path( - deno_dir - .deps_http - .join("localhost_PORT4545/tests/002_hello.ts") - .as_ref(), - ); + let filepath = deno_dir + .deps_http + .join("localhost_PORT4545/tests/002_hello.ts"); // file hasn't been cached before and remote downloads are not allowed let result = - get_source_code(&deno_dir, module_name, &filename, true, true); + get_source_code(&deno_dir, module_name, filepath.clone(), true, true); assert!(result.is_err()); let err = result.err().unwrap(); assert_eq!(err.kind(), ErrorKind::NotFound); // download and cache file let result = - get_source_code(&deno_dir, module_name, &filename, true, false); + get_source_code(&deno_dir, module_name, filepath.clone(), true, false); assert!(result.is_ok()); // module is already cached, should be ok even with `no_fetch` let result = - get_source_code(&deno_dir, module_name, &filename, true, true); + get_source_code(&deno_dir, module_name, filepath.clone(), true, true); assert!(result.is_ok()); }); } @@ -1500,18 +1457,15 @@ mod tests { let (_temp_dir, deno_dir) = test_setup(); let module_name = "http://127.0.0.1:4545/tests/subdir/mt_video_mp2t.t3.ts".to_string(); - let filename = deno_fs::normalize_path( - deno_dir - .deps_http - .join("127.0.0.1_PORT4545/tests/subdir/mt_video_mp2t.t3.ts") - .as_ref(), - ); - let headers_file_name = source_code_headers_filename(&filename); + let filepath = deno_dir + .deps_http + .join("127.0.0.1_PORT4545/tests/subdir/mt_video_mp2t.t3.ts"); + let headers_file_name = source_code_headers_filename(&filepath); let result = tokio_util::block_on(fetch_remote_source_async( &deno_dir, &module_name, - &filename, + &filepath, )); assert!(result.is_ok()); let r = result.unwrap().unwrap(); @@ -1522,12 +1476,12 @@ mod tests { // Modify .headers.json, make sure read from local save_source_code_headers( - &filename, + &filepath, Some("text/javascript".to_owned()), None, ); let result2 = - fetch_local_source(&deno_dir, &module_name, &filename, None); + fetch_local_source(&deno_dir, &module_name, &filepath, None); assert!(result2.is_ok()); let r2 = result2.unwrap().unwrap(); assert_eq!(r2.source_code, b"export const loaded = true;\n"); @@ -1544,15 +1498,12 @@ mod tests { let (_temp_dir, deno_dir) = test_setup(); let module_name = "http://localhost:4545/tests/subdir/mt_video_mp2t.t3.ts"; - let filename = deno_fs::normalize_path( - deno_dir - .deps_http - .join("localhost_PORT4545/tests/subdir/mt_video_mp2t.t3.ts") - .as_ref(), - ); - let headers_file_name = source_code_headers_filename(&filename); + let filepath = deno_dir + .deps_http + .join("localhost_PORT4545/tests/subdir/mt_video_mp2t.t3.ts"); + let headers_file_name = source_code_headers_filename(&filepath); - let result = fetch_remote_source(&deno_dir, module_name, &filename); + let result = fetch_remote_source(&deno_dir, module_name, &filepath); assert!(result.is_ok()); let r = result.unwrap().unwrap(); assert_eq!(r.source_code, "export const loaded = true;\n".as_bytes()); @@ -1562,11 +1513,11 @@ mod tests { // Modify .headers.json, make sure read from local save_source_code_headers( - &filename, + &filepath, Some("text/javascript".to_owned()), None, ); - let result2 = fetch_local_source(&deno_dir, module_name, &filename, None); + let result2 = fetch_local_source(&deno_dir, module_name, &filepath, None); assert!(result2.is_ok()); let r2 = result2.unwrap().unwrap(); assert_eq!(r2.source_code, "export const loaded = true;\n".as_bytes()); @@ -1582,57 +1533,48 @@ mod tests { tokio_util::init(|| { let (_temp_dir, deno_dir) = test_setup(); let module_name = "http://localhost:4545/tests/subdir/no_ext"; - let filename = deno_fs::normalize_path( - deno_dir - .deps_http - .join("localhost_PORT4545/tests/subdir/no_ext") - .as_ref(), - ); - let result = fetch_remote_source(&deno_dir, module_name, &filename); + let filepath = deno_dir + .deps_http + .join("localhost_PORT4545/tests/subdir/no_ext"); + let result = fetch_remote_source(&deno_dir, module_name, &filepath); assert!(result.is_ok()); let r = result.unwrap().unwrap(); assert_eq!(r.source_code, "export const loaded = true;\n".as_bytes()); assert_eq!(&(r.media_type), &msg::MediaType::TypeScript); // no ext, should create .headers.json file assert_eq!( - get_source_code_headers(&filename).mime_type.unwrap(), + get_source_code_headers(&filepath).mime_type.unwrap(), "text/typescript" ); let module_name_2 = "http://localhost:4545/tests/subdir/mismatch_ext.ts"; - let filename_2 = deno_fs::normalize_path( - deno_dir - .deps_http - .join("localhost_PORT4545/tests/subdir/mismatch_ext.ts") - .as_ref(), - ); - let result_2 = fetch_remote_source(&deno_dir, module_name_2, &filename_2); + let filepath_2 = deno_dir + .deps_http + .join("localhost_PORT4545/tests/subdir/mismatch_ext.ts"); + let result_2 = fetch_remote_source(&deno_dir, module_name_2, &filepath_2); assert!(result_2.is_ok()); let r2 = result_2.unwrap().unwrap(); assert_eq!(r2.source_code, "export const loaded = true;\n".as_bytes()); assert_eq!(&(r2.media_type), &msg::MediaType::JavaScript); // mismatch ext, should create .headers.json file assert_eq!( - get_source_code_headers(&filename_2).mime_type.unwrap(), + get_source_code_headers(&filepath_2).mime_type.unwrap(), "text/javascript" ); // test unknown extension let module_name_3 = "http://localhost:4545/tests/subdir/unknown_ext.deno"; - let filename_3 = deno_fs::normalize_path( - deno_dir - .deps_http - .join("localhost_PORT4545/tests/subdir/unknown_ext.deno") - .as_ref(), - ); - let result_3 = fetch_remote_source(&deno_dir, module_name_3, &filename_3); + let filepath_3 = deno_dir + .deps_http + .join("localhost_PORT4545/tests/subdir/unknown_ext.deno"); + let result_3 = fetch_remote_source(&deno_dir, module_name_3, &filepath_3); assert!(result_3.is_ok()); let r3 = result_3.unwrap().unwrap(); assert_eq!(r3.source_code, "export const loaded = true;\n".as_bytes()); assert_eq!(&(r3.media_type), &msg::MediaType::TypeScript); // unknown ext, should create .headers.json file assert_eq!( - get_source_code_headers(&filename_3).mime_type.unwrap(), + get_source_code_headers(&filepath_3).mime_type.unwrap(), "text/typescript" ); }); @@ -1643,12 +1585,10 @@ mod tests { // only local, no http_util::fetch_sync_string called let (_temp_dir, deno_dir) = test_setup(); let cwd = std::env::current_dir().unwrap(); - let cwd_string = cwd.to_str().unwrap(); let module_name = "http://example.com/mt_text_typescript.t1.ts"; // not used - let filename = - format!("{}/tests/subdir/mt_text_typescript.t1.ts", &cwd_string); + let filepath = cwd.join("tests/subdir/mt_text_typescript.t1.ts"); - let result = fetch_local_source(&deno_dir, module_name, &filename, None); + let result = fetch_local_source(&deno_dir, module_name, &filepath, None); assert!(result.is_ok()); let r = result.unwrap().unwrap(); assert_eq!(r.source_code, "export const loaded = true;\n".as_bytes()); @@ -1664,15 +1604,13 @@ mod tests { tokio_util::init(|| { // Test failure case. - let specifier = "hello.ts"; - let referrer = add_root!("/baddir/badfile.ts"); - let r = deno_dir.fetch_module_meta_data(specifier, referrer, true, false); + let specifier = add_root!("/baddir/hello.ts"); + let r = deno_dir.fetch_module_meta_data(specifier, true, false); assert!(r.is_err()); // Assuming cwd is the deno repo root. - let specifier = "./js/main.ts"; - let referrer = cwd_string.as_str(); - let r = deno_dir.fetch_module_meta_data(specifier, referrer, true, false); + let specifier = &format!("{}{}", cwd_string.as_str(), "js/main.ts"); + let r = deno_dir.fetch_module_meta_data(specifier, true, false); assert!(r.is_ok()); }) } @@ -1687,17 +1625,13 @@ mod tests { tokio_util::init(|| { // Test failure case. - let specifier = "hello.ts"; - let referrer = add_root!("/baddir/badfile.ts"); - let r = - deno_dir.fetch_module_meta_data(specifier, referrer, false, false); + let specifier = add_root!("/baddir/hello.ts"); + let r = deno_dir.fetch_module_meta_data(specifier, false, false); assert!(r.is_err()); // Assuming cwd is the deno repo root. - let specifier = "./js/main.ts"; - let referrer = cwd_string.as_str(); - let r = - deno_dir.fetch_module_meta_data(specifier, referrer, false, false); + let specifier = &format!("{}{}", cwd_string.as_str(), "js/main.ts"); + let r = deno_dir.fetch_module_meta_data(specifier, false, false); assert!(r.is_ok()); }) } @@ -1783,7 +1717,7 @@ mod tests { let (module_name, filename) = deno_dir.resolve_module(&specifier, &referrer).unwrap(); assert_eq!(module_name, test.2); - assert_eq!(filename, test.3); + assert_eq!(filename.to_str().unwrap().to_string(), test.3); } } @@ -1796,7 +1730,7 @@ mod tests { let expected_module_name = "http://localhost:4545/testdata/subdir/print_hello.ts"; - let expected_filename = deno_fs::normalize_path( + let expected_filename = normalize_to_str( deno_dir .deps_http .join("localhost_PORT4545/testdata/subdir/print_hello.ts") @@ -1806,7 +1740,7 @@ mod tests { let (module_name, filename) = deno_dir.resolve_module(specifier, referrer).unwrap(); assert_eq!(module_name, expected_module_name); - assert_eq!(filename, expected_filename); + assert_eq!(filename.to_str().unwrap().to_string(), expected_filename); } #[test] @@ -1819,7 +1753,7 @@ mod tests { let referrer = "."; let expected_module_name = "http://unpkg.com/liltest@0.0.5/index.ts"; - let expected_filename = deno_fs::normalize_path( + let expected_filename = normalize_to_str( deno_dir .deps_http .join("unpkg.com/liltest@0.0.5/index.ts") @@ -1829,7 +1763,7 @@ mod tests { let (module_name, filename) = deno_dir.resolve_module(specifier, referrer).unwrap(); assert_eq!(module_name, expected_module_name); - assert_eq!(filename, expected_filename); + assert_eq!(filename.to_str().unwrap().to_string(), expected_filename); } #[test] @@ -1842,7 +1776,7 @@ mod tests { // http containing files -> load relative import with http let expected_module_name = "http://unpkg.com/liltest@0.0.5/util"; - let expected_filename = deno_fs::normalize_path( + let expected_filename = normalize_to_str( deno_dir .deps_http .join("unpkg.com/liltest@0.0.5/util") @@ -1852,7 +1786,7 @@ mod tests { let (module_name, filename) = deno_dir.resolve_module(specifier, referrer).unwrap(); assert_eq!(module_name, expected_module_name); - assert_eq!(filename, expected_filename); + assert_eq!(filename.to_str().unwrap().to_string(), expected_filename); } #[test] @@ -1866,7 +1800,7 @@ mod tests { // https containing files -> load relative import with https let expected_module_name = "https://unpkg.com/liltest@0.0.5/util"; - let expected_filename = deno_fs::normalize_path( + let expected_filename = normalize_to_str( deno_dir .deps_https .join("unpkg.com/liltest@0.0.5/util") @@ -1876,7 +1810,7 @@ mod tests { let (module_name, filename) = deno_dir.resolve_module(specifier, referrer).unwrap(); assert_eq!(module_name, expected_module_name); - assert_eq!(filename, expected_filename); + assert_eq!(filename.to_str().unwrap().to_string(), expected_filename); } #[test] @@ -1886,7 +1820,7 @@ mod tests { let specifier = "http://localhost:4545/tests/subdir/mod2.ts"; let referrer = add_root!("/deno/tests/006_url_imports.ts"); let expected_module_name = "http://localhost:4545/tests/subdir/mod2.ts"; - let expected_filename = deno_fs::normalize_path( + let expected_filename = normalize_to_str( deno_dir .deps_http .join("localhost_PORT4545/tests/subdir/mod2.ts") @@ -1896,7 +1830,7 @@ mod tests { let (module_name, filename) = deno_dir.resolve_module(specifier, referrer).unwrap(); assert_eq!(module_name, expected_module_name); - assert_eq!(filename, expected_filename); + assert_eq!(filename.to_str().unwrap().to_string(), expected_filename); } #[test] @@ -1912,7 +1846,7 @@ mod tests { let (module_name, filename) = deno_dir.resolve_module(specifier, referrer).unwrap(); assert_eq!(module_name, expected_module_name); - assert_eq!(filename, expected_filename); + assert_eq!(filename.to_str().unwrap().to_string(), expected_filename); } #[test] @@ -1925,14 +1859,13 @@ mod tests { let referrer = referrer_.to_str().unwrap(); let expected_module_name = "https://unpkg.com/util"; - let expected_filename = deno_fs::normalize_path( - deno_dir.deps_https.join("unpkg.com/util").as_ref(), - ); + let expected_filename = + normalize_to_str(deno_dir.deps_https.join("unpkg.com/util").as_ref()); let (module_name, filename) = deno_dir.resolve_module(specifier, referrer).unwrap(); assert_eq!(module_name, expected_module_name); - assert_eq!(filename, expected_filename); + assert_eq!(filename.to_str().unwrap().to_string(), expected_filename); } #[test] @@ -1945,17 +1878,17 @@ mod tests { let expected_path = cwd.join(specifier); let expected_module_name = Url::from_file_path(&expected_path).unwrap().to_string(); - let expected_filename = deno_fs::normalize_path(&expected_path); + let expected_filename = normalize_to_str(&expected_path); let (module_name, filename) = deno_dir.resolve_module(specifier, ".").unwrap(); assert_eq!(module_name, expected_module_name); - assert_eq!(filename, expected_filename); + assert_eq!(filename.to_str().unwrap().to_string(), expected_filename); let (module_name, filename) = deno_dir.resolve_module(specifier, "./").unwrap(); assert_eq!(module_name, expected_module_name); - assert_eq!(filename, expected_filename); + assert_eq!(filename.to_str().unwrap().to_string(), expected_filename); } #[test] @@ -1968,17 +1901,17 @@ mod tests { let expected_path = cwd.join("..").join(specifier); let expected_module_name = Url::from_file_path(&expected_path).unwrap().to_string(); - let expected_filename = deno_fs::normalize_path(&expected_path); + let expected_filename = normalize_to_str(&expected_path); let (module_name, filename) = deno_dir.resolve_module(specifier, "..").unwrap(); assert_eq!(module_name, expected_module_name); - assert_eq!(filename, expected_filename); + assert_eq!(filename.to_str().unwrap().to_string(), expected_filename); let (module_name, filename) = deno_dir.resolve_module(specifier, "../").unwrap(); assert_eq!(module_name, expected_module_name); - assert_eq!(filename, expected_filename); + assert_eq!(filename.to_str().unwrap().to_string(), expected_filename); } #[test] |