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;
|
|
|
|
|
2024-12-16 18:39:40 -05:00
|
|
|
use crate::file_fetcher::CliFileFetcher;
|
|
|
|
use crate::file_fetcher::TextDecodedFile;
|
2023-01-25 16:51:04 -05:00
|
|
|
|
2024-07-03 20:54:33 -04:00
|
|
|
pub async fn resolve_import_map_value_from_specifier(
|
|
|
|
specifier: &Url,
|
2024-12-16 18:39:40 -05:00
|
|
|
file_fetcher: &CliFileFetcher,
|
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-12-16 18:39:40 -05:00
|
|
|
let file = TextDecodedFile::decode(
|
|
|
|
file_fetcher.fetch_bypass_permissions(specifier).await?,
|
|
|
|
)?;
|
2024-07-03 20:54:33 -04:00
|
|
|
Ok(serde_json::from_str(&file.source)?)
|
2023-01-25 15:13:40 -05:00
|
|
|
}
|
|
|
|
}
|