From ce48b32979b007c35130321ed0f91d8ffdb6d593 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Mon, 10 May 2021 18:16:39 +0200 Subject: refactor(cli): replace loading file for --config flag with generic structure (#10481) Currently file passed to --config file is parsed using TsConfig structure that does multiple things when loading the file. Instead of relying on that structure I've introduced ConfigFile structure that can be updated to sniff out more fields from the config file in the future. --- cli/program_state.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'cli/program_state.rs') diff --git a/cli/program_state.rs b/cli/program_state.rs index e8d2c163e..0051e744b 100644 --- a/cli/program_state.rs +++ b/cli/program_state.rs @@ -1,5 +1,6 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +use crate::config_file::ConfigFile; use crate::deno_dir; use crate::file_fetcher::CacheSetting; use crate::file_fetcher::FileFetcher; @@ -46,6 +47,7 @@ pub struct ProgramState { pub modules: Arc>>>, pub lockfile: Option>>, + pub maybe_config_file: Option, pub maybe_import_map: Option, pub maybe_inspector_server: Option>, pub ca_data: Option>, @@ -91,6 +93,13 @@ impl ProgramState { None }; + let maybe_config_file = + if let Some(config_path) = flags.config_path.as_ref() { + Some(ConfigFile::read(config_path)?) + } else { + None + }; + let maybe_import_map: Option = match flags.import_map_path.as_ref() { None => None, @@ -129,6 +138,7 @@ impl ProgramState { file_fetcher, modules: Default::default(), lockfile, + maybe_config_file, maybe_import_map, maybe_inspector_server, ca_data, @@ -160,12 +170,12 @@ impl ProgramState { let mut graph = builder.get_graph(); let debug = self.flags.log_level == Some(log::Level::Debug); - let maybe_config_path = self.flags.config_path.clone(); + let maybe_config_file = self.maybe_config_file.clone(); let result_modules = if self.flags.no_check { let result_info = graph.transpile(TranspileOptions { debug, - maybe_config_path, + maybe_config_file, reload: self.flags.reload, })?; debug!("{}", result_info.stats); @@ -178,7 +188,7 @@ impl ProgramState { debug, emit: true, lib, - maybe_config_path, + maybe_config_file, reload: self.flags.reload, })?; @@ -229,12 +239,12 @@ impl ProgramState { builder.add(&specifier, is_dynamic).await?; let mut graph = builder.get_graph(); let debug = self.flags.log_level == Some(log::Level::Debug); - let maybe_config_path = self.flags.config_path.clone(); + let maybe_config_file = self.maybe_config_file.clone(); let result_modules = if self.flags.no_check { let result_info = graph.transpile(TranspileOptions { debug, - maybe_config_path, + maybe_config_file, reload: self.flags.reload, })?; debug!("{}", result_info.stats); @@ -247,7 +257,7 @@ impl ProgramState { debug, emit: true, lib, - maybe_config_path, + maybe_config_file, reload: self.flags.reload, })?; -- cgit v1.2.3