summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/tools/vendor/build.rs51
-rw-r--r--cli/tools/vendor/import_map.rs7
2 files changed, 52 insertions, 6 deletions
diff --git a/cli/tools/vendor/build.rs b/cli/tools/vendor/build.rs
index 58f351dd8..260aa39f5 100644
--- a/cli/tools/vendor/build.rs
+++ b/cli/tools/vendor/build.rs
@@ -568,6 +568,57 @@ mod test {
);
}
+ #[tokio::test]
+ async fn same_origin_absolute_with_redirect() {
+ let mut builder = VendorTestBuilder::with_default_setup();
+ let output = builder
+ .with_loader(|loader| {
+ loader
+ .add(
+ "/mod.ts",
+ r#"import "https://localhost/subdir/sub/mod.ts";"#,
+ )
+ .add(
+ "https://localhost/subdir/sub/mod.ts",
+ "import 'https://localhost/std/hash/mod.ts'",
+ )
+ .add_redirect(
+ "https://localhost/std/hash/mod.ts",
+ "https://localhost/std@0.1.0/hash/mod.ts",
+ )
+ .add(
+ "https://localhost/std@0.1.0/hash/mod.ts",
+ "export class Test {}",
+ );
+ })
+ .build()
+ .await
+ .unwrap();
+
+ assert_eq!(
+ output.import_map,
+ Some(json!({
+ "imports": {
+ "https://localhost/": "./localhost/",
+ "https://localhost/std/hash/mod.ts": "./localhost/std@0.1.0/hash/mod.ts"
+ }
+ }))
+ );
+ assert_eq!(
+ output.files,
+ to_file_vec(&[
+ (
+ "/vendor/localhost/std@0.1.0/hash/mod.ts",
+ "export class Test {}"
+ ),
+ (
+ "/vendor/localhost/subdir/sub/mod.ts",
+ "import 'https://localhost/std/hash/mod.ts'"
+ ),
+ ]),
+ );
+ }
+
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 7e18d56aa..502b12f6e 100644
--- a/cli/tools/vendor/import_map.rs
+++ b/cli/tools/vendor/import_map.rs
@@ -213,12 +213,7 @@ fn handle_dep_specifier(
return;
}
- if referrer.origin() == specifier.origin() {
- let imports = import_map.scope(base_specifier);
- imports.add(sub_path.to_string(), &specifier);
- } else {
- import_map.imports.add(text.to_string(), &specifier);
- }
+ import_map.imports.add(text.to_string(), &specifier);
} else {
let expected_relative_specifier_text =
mappings.relative_specifier_text(referrer, &specifier);