From fafb3eebaf27cc2ef3ffaa10be8a0c5d78a112d0 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Thu, 1 Dec 2022 11:01:19 -0500 Subject: [PATCH] fix(vendor): properly handle bare specifiers that start with http (#16885) --- cli/tools/vendor/build.rs | 35 ++++++++++++++++++++++++++++++++++ cli/tools/vendor/specifiers.rs | 3 ++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/cli/tools/vendor/build.rs b/cli/tools/vendor/build.rs index dadd84e22e..b28038a673 100644 --- a/cli/tools/vendor/build.rs +++ b/cli/tools/vendor/build.rs @@ -1064,6 +1064,41 @@ mod test { ); } + #[tokio::test] + async fn existing_import_map_http_key() { + let mut builder = VendorTestBuilder::with_default_setup(); + let mut original_import_map = builder.new_import_map("/import_map.json"); + original_import_map + .imports_mut() + .append( + "http/".to_string(), + "https://deno.land/std/http/".to_string(), + ) + .unwrap(); + let output = builder + .with_loader(|loader| { + loader.add("/mod.ts", "import 'http/mod.ts';"); + loader.add("https://deno.land/std/http/mod.ts", "console.log(5);"); + }) + .set_original_import_map(original_import_map.clone()) + .build() + .await + .unwrap(); + assert_eq!( + output.import_map, + Some(json!({ + "imports": { + "http/mod.ts": "./deno.land/std/http/mod.ts", + "https://deno.land/": "./deno.land/", + } + })) + ); + assert_eq!( + output.files, + to_file_vec(&[("/vendor/deno.land/std/http/mod.ts", "console.log(5);")]), + ); + } + #[tokio::test] async fn vendor_file_fails_loading_dynamic_import() { let mut builder = VendorTestBuilder::with_default_setup(); diff --git a/cli/tools/vendor/specifiers.rs b/cli/tools/vendor/specifiers.rs index 9d513cc92a..21ae2ca85f 100644 --- a/cli/tools/vendor/specifiers.rs +++ b/cli/tools/vendor/specifiers.rs @@ -69,7 +69,8 @@ pub fn is_remote_specifier(specifier: &ModuleSpecifier) -> bool { } pub fn is_remote_specifier_text(text: &str) -> bool { - text.trim_start().to_lowercase().starts_with("http") + let text = text.trim_start().to_lowercase(); + text.starts_with("http:") || text.starts_with("https:") } pub fn sanitize_filepath(text: &str) -> String {