summaryrefslogtreecommitdiff
path: root/cli/args/config_file.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-01-25 21:13:40 +0100
committerGitHub <noreply@github.com>2023-01-25 21:13:40 +0100
commitc6c8c91a6e4b7a2b6eed02d3e2f5db25c124d9a0 (patch)
tree1fe8e9ab2175154d44e78d153dd760e56dc1c860 /cli/args/config_file.rs
parentb5b4887c4a5fefdeb5592ebaadcc941281d0c4d5 (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/config_file.rs')
-rw-r--r--cli/args/config_file.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/cli/args/config_file.rs b/cli/args/config_file.rs
index c31f09960..82ae7e5d7 100644
--- a/cli/args/config_file.rs
+++ b/cli/args/config_file.rs
@@ -465,6 +465,8 @@ pub enum LockConfig {
pub struct ConfigFileJson {
pub compiler_options: Option<Value>,
pub import_map: Option<String>,
+ pub imports: Option<Value>,
+ pub scopes: Option<Value>,
pub lint: Option<Value>,
pub fmt: Option<Value>,
pub tasks: Option<Value>,
@@ -667,6 +669,21 @@ impl ConfigFile {
self.json.import_map.clone()
}
+ pub fn to_import_map_value(&self) -> Value {
+ let mut value = serde_json::Map::with_capacity(2);
+ if let Some(imports) = &self.json.imports {
+ value.insert("imports".to_string(), imports.clone());
+ }
+ if let Some(scopes) = &self.json.scopes {
+ value.insert("scopes".to_string(), scopes.clone());
+ }
+ value.into()
+ }
+
+ pub fn is_an_import_map(&self) -> bool {
+ self.json.imports.is_some() || self.json.scopes.is_some()
+ }
+
pub fn to_fmt_config(&self) -> Result<Option<FmtConfig>, AnyError> {
if let Some(config) = self.json.fmt.clone() {
let fmt_config: SerializedFmtConfig = serde_json::from_value(config)