mirror of
https://github.com/denoland/deno.git
synced 2024-12-11 01:58:05 -05:00
fix(vendor): existing import map with bare specifier in remote (#15390)
This commit is contained in:
parent
2205d9345e
commit
967b7f8b5b
2 changed files with 49 additions and 4 deletions
47
cli/tools/vendor/build.rs
vendored
47
cli/tools/vendor/build.rs
vendored
|
@ -66,7 +66,6 @@ pub fn build(
|
|||
|
||||
// build the graph
|
||||
graph.lock()?;
|
||||
graph.valid()?;
|
||||
|
||||
let graph_errors = graph.errors();
|
||||
if !graph_errors.is_empty() {
|
||||
|
@ -828,6 +827,52 @@ mod test {
|
|||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn existing_import_map_remote_dep_bare_specifier() {
|
||||
let mut builder = VendorTestBuilder::with_default_setup();
|
||||
let mut original_import_map = builder.new_import_map("/import_map2.json");
|
||||
original_import_map
|
||||
.imports_mut()
|
||||
.append(
|
||||
"twind".to_string(),
|
||||
"https://localhost/twind.ts".to_string(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let output = builder
|
||||
.with_loader(|loader| {
|
||||
loader.add("/mod.ts", "import 'https://remote/mod.ts';");
|
||||
loader.add("https://remote/mod.ts", "import 'twind';");
|
||||
loader.add("https://localhost/twind.ts", "export class Test {}");
|
||||
})
|
||||
.set_original_import_map(original_import_map.clone())
|
||||
.build()
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
output.import_map,
|
||||
Some(json!({
|
||||
"imports": {
|
||||
"https://localhost/": "./localhost/",
|
||||
"https://remote/": "./remote/"
|
||||
},
|
||||
"scopes": {
|
||||
"./remote/": {
|
||||
"twind": "./localhost/twind.ts"
|
||||
},
|
||||
}
|
||||
}))
|
||||
);
|
||||
assert_eq!(
|
||||
output.files,
|
||||
to_file_vec(&[
|
||||
("/vendor/localhost/twind.ts", "export class Test {}"),
|
||||
("/vendor/remote/mod.ts", "import 'twind';"),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn existing_import_map_mapped_bare_specifier() {
|
||||
let mut builder = VendorTestBuilder::with_default_setup();
|
||||
|
|
6
cli/tools/vendor/import_map.rs
vendored
6
cli/tools/vendor/import_map.rs
vendored
|
@ -333,12 +333,12 @@ fn handle_remote_dep_specifier(
|
|||
return;
|
||||
}
|
||||
|
||||
let base_specifier = mappings.base_specifier(specifier);
|
||||
let base_referrer = mappings.base_specifier(referrer);
|
||||
let base_dir = import_map.base_dir().clone();
|
||||
let imports = import_map.scope(base_specifier);
|
||||
let imports = import_map.scope(base_referrer);
|
||||
if text.starts_with("./") || text.starts_with("../") {
|
||||
// resolve relative specifier key
|
||||
let mut local_base_specifier = mappings.local_uri(base_specifier);
|
||||
let mut local_base_specifier = mappings.local_uri(base_referrer);
|
||||
local_base_specifier = local_base_specifier
|
||||
// path includes "/" so make it relative
|
||||
.join(&format!(".{}", unresolved_specifier.path()))
|
||||
|
|
Loading…
Reference in a new issue