mirror of
https://github.com/denoland/deno.git
synced 2024-12-23 15:49:44 -05:00
fix(vendor): better handling of redirects (#19063)
Closes #17582 Closes #19057
This commit is contained in:
parent
cb63db459c
commit
50618fc0bc
2 changed files with 58 additions and 9 deletions
48
cli/tools/vendor/build.rs
vendored
48
cli/tools/vendor/build.rs
vendored
|
@ -378,6 +378,54 @@ mod test {
|
|||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn remote_redirect_entrypoint() {
|
||||
let mut builder = VendorTestBuilder::with_default_setup();
|
||||
let output = builder
|
||||
.with_loader(|loader| {
|
||||
loader
|
||||
.add(
|
||||
"/mod.ts",
|
||||
concat!(
|
||||
"import * as test from 'https://x.nest.land/Yenv@1.0.0/mod.ts';\n",
|
||||
"console.log(test)",
|
||||
),
|
||||
)
|
||||
.add_redirect("https://x.nest.land/Yenv@1.0.0/mod.ts", "https://arweave.net/VFtWNW3QZ-7__v7c7kck22eFI24OuK1DFzyQHKoZ9AE/mod.ts")
|
||||
.add(
|
||||
"https://arweave.net/VFtWNW3QZ-7__v7c7kck22eFI24OuK1DFzyQHKoZ9AE/mod.ts",
|
||||
"export * from './src/mod.ts'",
|
||||
)
|
||||
.add(
|
||||
"https://arweave.net/VFtWNW3QZ-7__v7c7kck22eFI24OuK1DFzyQHKoZ9AE/src/mod.ts",
|
||||
"export class Test {}",
|
||||
);
|
||||
})
|
||||
.build()
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
output.import_map,
|
||||
Some(json!({
|
||||
"imports": {
|
||||
"https://x.nest.land/Yenv@1.0.0/mod.ts": "./arweave.net/VFtWNW3QZ-7__v7c7kck22eFI24OuK1DFzyQHKoZ9AE/mod.ts",
|
||||
"https://arweave.net/": "./arweave.net/"
|
||||
},
|
||||
}))
|
||||
);
|
||||
assert_eq!(
|
||||
output.files,
|
||||
to_file_vec(&[
|
||||
("/vendor/arweave.net/VFtWNW3QZ-7__v7c7kck22eFI24OuK1DFzyQHKoZ9AE/mod.ts", "export * from './src/mod.ts'"),
|
||||
(
|
||||
"/vendor/arweave.net/VFtWNW3QZ-7__v7c7kck22eFI24OuK1DFzyQHKoZ9AE/src/mod.ts",
|
||||
"export class Test {}",
|
||||
),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn same_target_filename_specifiers() {
|
||||
let mut builder = VendorTestBuilder::with_default_setup();
|
||||
|
|
19
cli/tools/vendor/import_map.rs
vendored
19
cli/tools/vendor/import_map.rs
vendored
|
@ -326,15 +326,16 @@ fn handle_remote_dep_specifier(
|
|||
) {
|
||||
if is_remote_specifier_text(text) {
|
||||
let base_specifier = mappings.base_specifier(specifier);
|
||||
if !text.starts_with(base_specifier.as_str()) {
|
||||
panic!("Expected {text} to start with {base_specifier}");
|
||||
}
|
||||
|
||||
let sub_path = &text[base_specifier.as_str().len()..];
|
||||
let relative_text =
|
||||
mappings.relative_specifier_text(base_specifier, specifier);
|
||||
let expected_sub_path = relative_text.trim_start_matches("./");
|
||||
if expected_sub_path != sub_path {
|
||||
if text.starts_with(base_specifier.as_str()) {
|
||||
let sub_path = &text[base_specifier.as_str().len()..];
|
||||
let relative_text =
|
||||
mappings.relative_specifier_text(base_specifier, specifier);
|
||||
let expected_sub_path = relative_text.trim_start_matches("./");
|
||||
if expected_sub_path != sub_path {
|
||||
import_map.imports.add(text.to_string(), specifier);
|
||||
}
|
||||
} else {
|
||||
// it's probably a redirect. Add it explicitly to the import map
|
||||
import_map.imports.add(text.to_string(), specifier);
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue