2024-01-01 14:58:21 -05:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2023-01-25 15:13:40 -05:00
|
|
|
|
|
|
|
use deno_core::error::AnyError;
|
|
|
|
use deno_core::serde_json;
|
|
|
|
use deno_core::url::Url;
|
|
|
|
|
2023-01-25 16:51:04 -05:00
|
|
|
use crate::file_fetcher::FileFetcher;
|
|
|
|
|
2024-07-03 20:54:33 -04:00
|
|
|
pub async fn resolve_import_map_value_from_specifier(
|
|
|
|
specifier: &Url,
|
2023-01-25 16:51:04 -05:00
|
|
|
file_fetcher: &FileFetcher,
|
2024-07-03 20:54:33 -04:00
|
|
|
) -> Result<serde_json::Value, AnyError> {
|
|
|
|
if specifier.scheme() == "data" {
|
2024-01-31 22:15:22 -05:00
|
|
|
let data_url_text =
|
2024-07-03 20:54:33 -04:00
|
|
|
deno_graph::source::RawDataUrl::parse(specifier)?.decode()?;
|
|
|
|
Ok(serde_json::from_str(&data_url_text)?)
|
2023-01-25 16:51:04 -05:00
|
|
|
} else {
|
2024-02-24 00:21:09 -05:00
|
|
|
let file = file_fetcher
|
2024-09-16 16:39:37 -04:00
|
|
|
.fetch_bypass_permissions(specifier)
|
2024-02-24 00:21:09 -05:00
|
|
|
.await?
|
|
|
|
.into_text_decoded()?;
|
2024-07-03 20:54:33 -04:00
|
|
|
Ok(serde_json::from_str(&file.source)?)
|
2023-01-25 15:13:40 -05:00
|
|
|
}
|
|
|
|
}
|