diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2023-01-25 21:13:40 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-25 21:13:40 +0100 |
commit | c6c8c91a6e4b7a2b6eed02d3e2f5db25c124d9a0 (patch) | |
tree | 1fe8e9ab2175154d44e78d153dd760e56dc1c860 /cli/args/import_map.rs | |
parent | b5b4887c4a5fefdeb5592ebaadcc941281d0c4d5 (diff) |
feat: embed import map in the config file (#17478)
This commit changes handling of config file to enable
specifying "imports" and "scopes" objects effectively making
the configuration file an import map.
"imports" and "scopes" take precedence over "importMap" configuration,
but have lower priority than "--importmap" CLI flag.
Co-authored-by: David Sherret <dsherret@users.noreply.github.com>
Co-authored-by: David Sherret <dsherret@gmail.com>
Diffstat (limited to 'cli/args/import_map.rs')
-rw-r--r-- | cli/args/import_map.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/cli/args/import_map.rs b/cli/args/import_map.rs new file mode 100644 index 000000000..200336c43 --- /dev/null +++ b/cli/args/import_map.rs @@ -0,0 +1,35 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. + +use deno_core::error::AnyError; +use deno_core::serde_json; +use deno_core::url::Url; +use import_map::ImportMap; +use import_map::ImportMapDiagnostic; +use log::warn; + +pub fn import_map_from_value( + specifier: &Url, + json_value: serde_json::Value, +) -> Result<ImportMap, AnyError> { + debug_assert!( + !specifier.as_str().contains("../"), + "Import map specifier incorrectly contained ../: {}", + specifier.as_str() + ); + let result = import_map::parse_from_value(specifier, json_value)?; + print_import_map_diagnostics(&result.diagnostics); + Ok(result.import_map) +} + +fn print_import_map_diagnostics(diagnostics: &[ImportMapDiagnostic]) { + if !diagnostics.is_empty() { + warn!( + "Import map diagnostics:\n{}", + diagnostics + .iter() + .map(|d| format!(" - {}", d)) + .collect::<Vec<_>>() + .join("\n") + ); + } +} |