diff --git a/cli/tools/vendor/build.rs b/cli/tools/vendor/build.rs index 260aa39f5e..0e42edb4ac 100644 --- a/cli/tools/vendor/build.rs +++ b/cli/tools/vendor/build.rs @@ -619,6 +619,55 @@ mod test { ); } + #[tokio::test] + async fn remote_relative_specifier_with_scheme_like_folder_name() { + let mut builder = VendorTestBuilder::with_default_setup(); + let output = builder + .with_loader(|loader| { + loader + .add("/mod.ts", "import 'https://localhost/mod.ts';") + .add( + "https://localhost/mod.ts", + "import './npm:test@1.0.0/test/test!cjs';", + ) + .add_with_headers( + "https://localhost/npm:test@1.0.0/test/test!cjs", + "console.log(5);", + &[("content-type", "application/javascript")], + ); + }) + .build() + .await + .unwrap(); + + assert_eq!( + output.import_map, + Some(json!({ + "imports": { + "https://localhost/": "./localhost/" + }, + "scopes": { + "./localhost/": { + "./localhost/npm:test@1.0.0/test/test!cjs": "./localhost/npm_test@1.0.0/test/test!cjs.js" + } + } + })) + ); + assert_eq!( + output.files, + to_file_vec(&[ + ( + "/vendor/localhost/mod.ts", + "import './npm:test@1.0.0/test/test!cjs';" + ), + ( + "/vendor/localhost/npm_test@1.0.0/test/test!cjs.js", + "console.log(5);" + ), + ]), + ); + } + fn to_file_vec(items: &[(&str, &str)]) -> Vec<(String, String)> { items .iter() diff --git a/cli/tools/vendor/import_map.rs b/cli/tools/vendor/import_map.rs index 502b12f6e4..1df6e36d1a 100644 --- a/cli/tools/vendor/import_map.rs +++ b/cli/tools/vendor/import_map.rs @@ -226,7 +226,8 @@ fn handle_dep_specifier( let mut local_base_specifier = mappings.local_uri(base_specifier); local_base_specifier.set_query(unresolved_specifier.query()); local_base_specifier = local_base_specifier - .join(&unresolved_specifier.path()[1..]) + // path includes "/" so make it relative + .join(&format!(".{}", unresolved_specifier.path())) .unwrap_or_else(|_| { panic!( "Error joining {} to {}",