diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2021-02-17 13:47:18 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-17 13:47:18 -0500 |
commit | c7dabc99eed50fa20cdcafd7c0175ab615da3d50 (patch) | |
tree | ec2c611c627827bbdd61d3e27400ae1b9a50d459 /cli/specifier_handler.rs | |
parent | f6d6b24506410816833d802e1a8d9cd704f73289 (diff) |
Make ModuleSpecifier a type alias, not wrapper struct (#9531)
Diffstat (limited to 'cli/specifier_handler.rs')
-rw-r--r-- | cli/specifier_handler.rs | 62 |
1 files changed, 26 insertions, 36 deletions
diff --git a/cli/specifier_handler.rs b/cli/specifier_handler.rs index e780b94d0..0be41b929 100644 --- a/cli/specifier_handler.rs +++ b/cli/specifier_handler.rs @@ -70,7 +70,7 @@ pub struct CachedModule { impl Default for CachedModule { fn default() -> Self { - let specifier = ModuleSpecifier::resolve_url("file:///example.js").unwrap(); + let specifier = deno_core::resolve_url("file:///example.js").unwrap(); CachedModule { is_remote: false, maybe_dependencies: None, @@ -304,7 +304,7 @@ impl SpecifierHandler for FetchHandler { (requested_specifier.clone(), err) } })?; - let url = source_file.specifier.as_url(); + let url = &source_file.specifier; let is_remote = !(url.scheme() == "file" || url.scheme() == "data"); let filename = disk_cache.get_cache_filename_with_extension(url, "meta"); let maybe_version = if let Some(filename) = filename { @@ -371,7 +371,7 @@ impl SpecifierHandler for FetchHandler { ) -> Result<Option<String>, AnyError> { let filename = self .disk_cache - .get_cache_filename_with_extension(specifier.as_url(), "buildinfo"); + .get_cache_filename_with_extension(specifier, "buildinfo"); if let Some(filename) = filename { if let Ok(tsbuildinfo) = self.disk_cache.get(&filename) { Ok(Some(String::from_utf8(tsbuildinfo)?)) @@ -390,7 +390,7 @@ impl SpecifierHandler for FetchHandler { ) -> Result<(), AnyError> { let filename = self .disk_cache - .get_cache_filename_with_extension(specifier.as_url(), "buildinfo") + .get_cache_filename_with_extension(specifier, "buildinfo") .unwrap(); debug!("set_tsbuildinfo - filename {:?}", filename); self @@ -406,17 +406,16 @@ impl SpecifierHandler for FetchHandler { ) -> Result<(), AnyError> { match emit { Emit::Cli((code, maybe_map)) => { - let url = specifier.as_url(); let filename = self .disk_cache - .get_cache_filename_with_extension(url, "js") + .get_cache_filename_with_extension(specifier, "js") .unwrap(); self.disk_cache.set(&filename, code.as_bytes())?; if let Some(map) = maybe_map { let filename = self .disk_cache - .get_cache_filename_with_extension(url, "js.map") + .get_cache_filename_with_extension(specifier, "js.map") .unwrap(); self.disk_cache.set(&filename, map.as_bytes())?; } @@ -452,7 +451,7 @@ impl SpecifierHandler for FetchHandler { let compiled_file_metadata = CompiledFileMetadata { version_hash }; let filename = self .disk_cache - .get_cache_filename_with_extension(specifier.as_url(), "meta") + .get_cache_filename_with_extension(specifier, "meta") .unwrap(); self @@ -492,7 +491,7 @@ impl SpecifierHandler for MemoryHandler { } let result = if let Some(source) = self.sources.get(&specifier_text) { let media_type = MediaType::from(&specifier); - let is_remote = specifier.as_url().scheme() != "file"; + let is_remote = specifier.scheme() != "file"; Ok(CachedModule { source: source.to_string(), @@ -568,6 +567,7 @@ pub mod tests { use super::*; use crate::file_fetcher::CacheSetting; use crate::http_cache::HttpCache; + use deno_core::resolve_url_or_path; use tempfile::TempDir; macro_rules! map ( @@ -609,10 +609,9 @@ pub mod tests { async fn test_fetch_handler_fetch() { let _http_server_guard = test_util::http_server(); let (_, mut file_fetcher) = setup(); - let specifier = ModuleSpecifier::resolve_url_or_path( - "http://localhost:4545/cli/tests/subdir/mod2.ts", - ) - .unwrap(); + let specifier = + resolve_url_or_path("http://localhost:4545/cli/tests/subdir/mod2.ts") + .unwrap(); let cached_module: CachedModule = file_fetcher .fetch(specifier.clone(), None, false) .await @@ -631,10 +630,9 @@ pub mod tests { async fn test_fetch_handler_set_cache() { let _http_server_guard = test_util::http_server(); let (_, mut file_fetcher) = setup(); - let specifier = ModuleSpecifier::resolve_url_or_path( - "http://localhost:4545/cli/tests/subdir/mod2.ts", - ) - .unwrap(); + let specifier = + resolve_url_or_path("http://localhost:4545/cli/tests/subdir/mod2.ts") + .unwrap(); let cached_module: CachedModule = file_fetcher .fetch(specifier.clone(), None, false) .await @@ -658,15 +656,14 @@ pub mod tests { async fn test_fetch_handler_is_remote() { let _http_server_guard = test_util::http_server(); let (_, mut file_fetcher) = setup(); - let specifier = ModuleSpecifier::resolve_url_or_path( - "http://localhost:4545/cli/tests/subdir/mod2.ts", - ) - .unwrap(); + let specifier = + resolve_url_or_path("http://localhost:4545/cli/tests/subdir/mod2.ts") + .unwrap(); let cached_module: CachedModule = file_fetcher.fetch(specifier, None, false).await.unwrap(); assert_eq!(cached_module.is_remote, true); let c = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap()); - let specifier = ModuleSpecifier::resolve_url_or_path( + let specifier = resolve_url_or_path( c.join("tests/subdir/mod1.ts").as_os_str().to_str().unwrap(), ) .unwrap(); @@ -701,8 +698,7 @@ pub mod tests { .map(|(k, v)| (k.to_string(), v.to_string())) .collect(); let mut handler = MemoryHandler::new(sources); - let specifier = - ModuleSpecifier::resolve_url_or_path("file:///a.ts").unwrap(); + let specifier = resolve_url_or_path("file:///a.ts").unwrap(); let actual: CachedModule = handler .fetch(specifier.clone(), None, false) .await @@ -713,8 +709,7 @@ pub mod tests { assert_eq!(actual.media_type, MediaType::TypeScript); assert_eq!(actual.is_remote, false); - let specifier = - ModuleSpecifier::resolve_url_or_path("file:///b.ts").unwrap(); + let specifier = resolve_url_or_path("file:///b.ts").unwrap(); let actual: CachedModule = handler .fetch(specifier.clone(), None, false) .await @@ -725,8 +720,7 @@ pub mod tests { assert_eq!(actual.media_type, MediaType::TypeScript); assert_eq!(actual.is_remote, false); - let specifier = - ModuleSpecifier::resolve_url_or_path("https://deno.land/x/c.js").unwrap(); + let specifier = resolve_url_or_path("https://deno.land/x/c.js").unwrap(); let actual: CachedModule = handler .fetch(specifier.clone(), None, false) .await @@ -737,9 +731,7 @@ pub mod tests { assert_eq!(actual.media_type, MediaType::JavaScript); assert_eq!(actual.is_remote, true); - let specifier = - ModuleSpecifier::resolve_url_or_path("https://deno.land/x/d.d.ts") - .unwrap(); + let specifier = resolve_url_or_path("https://deno.land/x/d.d.ts").unwrap(); let actual: CachedModule = handler .fetch(specifier.clone(), None, false) .await @@ -751,14 +743,13 @@ pub mod tests { assert_eq!(actual.is_remote, true); let specifier = - ModuleSpecifier::resolve_url_or_path("https://deno.land/x/missing.ts") - .unwrap(); + resolve_url_or_path("https://deno.land/x/missing.ts").unwrap(); handler .fetch(specifier.clone(), None, false) .await .expect_err("should have errored"); - let specifier = ModuleSpecifier::resolve_url_or_path("/a.ts").unwrap(); + let specifier = resolve_url_or_path("/a.ts").unwrap(); let actual: CachedModule = handler .fetch(specifier.clone(), None, false) .await @@ -769,8 +760,7 @@ pub mod tests { assert_eq!(actual.media_type, MediaType::TypeScript); assert_eq!(actual.is_remote, false); - let specifier = - ModuleSpecifier::resolve_url_or_path("file:///C:/a.ts").unwrap(); + let specifier = resolve_url_or_path("file:///C:/a.ts").unwrap(); let actual: CachedModule = handler .fetch(specifier.clone(), None, false) .await |