1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00

fix(cli): allow importMap to be an absolute URL within the deno config file (#16234)

This commit is contained in:
Mark Gibson 2022-10-13 10:01:11 +01:00 committed by GitHub
parent 06ccb6d41e
commit fda24b54e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -420,6 +420,10 @@ fn resolve_import_map_specifier(
// and with config files, we support both local and remote config files,
// so we have treat them differently.
if let Some(import_map_path) = config_file.to_import_map_path() {
// if the import map is an absolute URL, use it as is
if let Ok(specifier) = deno_core::resolve_url(&import_map_path) {
return Ok(Some(specifier));
}
let specifier =
// with local config files, it might be common to specify an import
// map like `"importMap": "import-map.json"`, which is resolvable if
@ -471,6 +475,25 @@ mod test {
);
}
#[test]
fn resolve_import_map_remote_config_file_local() {
let config_text = r#"{
"importMap": "https://example.com/import_map.json"
}"#;
let config_specifier =
ModuleSpecifier::parse("file:///deno/deno.jsonc").unwrap();
let config_file = ConfigFile::new(config_text, &config_specifier).unwrap();
let actual = resolve_import_map_specifier(None, Some(&config_file));
assert!(actual.is_ok());
let actual = actual.unwrap();
assert_eq!(
actual,
Some(
ModuleSpecifier::parse("https://example.com/import_map.json").unwrap()
)
);
}
#[test]
fn resolve_import_map_config_file_remote() {
let config_text = r#"{