mirror of
https://github.com/denoland/deno.git
synced 2024-12-27 17:49:08 -05:00
fix(vendor): do not add absolute specifiers to scopes (#13710)
This commit is contained in:
parent
bb5ea17439
commit
1e617ea2d4
2 changed files with 52 additions and 6 deletions
51
cli/tools/vendor/build.rs
vendored
51
cli/tools/vendor/build.rs
vendored
|
@ -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()
|
||||
|
|
7
cli/tools/vendor/import_map.rs
vendored
7
cli/tools/vendor/import_map.rs
vendored
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue