summaryrefslogtreecommitdiff
path: root/cli/program_state.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2021-05-10 18:16:39 +0200
committerGitHub <noreply@github.com>2021-05-10 18:16:39 +0200
commitce48b32979b007c35130321ed0f91d8ffdb6d593 (patch)
tree6cab6a1349fb9541eac0324efbfc563625d5e656 /cli/program_state.rs
parent7fc211e62752dddd4f70f8feef24dbcea795c1eb (diff)
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.
Diffstat (limited to 'cli/program_state.rs')
-rw-r--r--cli/program_state.rs22
1 files changed, 16 insertions, 6 deletions
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<Mutex<HashMap<ModuleSpecifier, Result<ModuleSource, AnyError>>>>,
pub lockfile: Option<Arc<Mutex<Lockfile>>>,
+ pub maybe_config_file: Option<ConfigFile>,
pub maybe_import_map: Option<ImportMap>,
pub maybe_inspector_server: Option<Arc<InspectorServer>>,
pub ca_data: Option<Vec<u8>>,
@@ -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<ImportMap> =
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,
})?;