summaryrefslogtreecommitdiff
path: root/cli/module_graph.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/module_graph.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/module_graph.rs')
-rw-r--r--cli/module_graph.rs63
1 files changed, 33 insertions, 30 deletions
diff --git a/cli/module_graph.rs b/cli/module_graph.rs
index 2300e89d6..a70a124a7 100644
--- a/cli/module_graph.rs
+++ b/cli/module_graph.rs
@@ -7,6 +7,9 @@ use crate::ast::Location;
use crate::ast::ParsedModule;
use crate::checksum;
use crate::colors;
+use crate::config_file::ConfigFile;
+use crate::config_file::IgnoredCompilerOptions;
+use crate::config_file::TsConfig;
use crate::diagnostics::Diagnostics;
use crate::import_map::ImportMap;
use crate::info;
@@ -19,8 +22,6 @@ use crate::specifier_handler::Emit;
use crate::specifier_handler::FetchFuture;
use crate::specifier_handler::SpecifierHandler;
use crate::tsc;
-use crate::tsc_config::IgnoredCompilerOptions;
-use crate::tsc_config::TsConfig;
use crate::version;
use deno_core::error::anyhow;
use deno_core::error::custom_error;
@@ -579,10 +580,10 @@ impl Serialize for TypeLib {
pub struct BundleOptions {
/// If `true` then debug logging will be output from the isolate.
pub debug: bool,
- /// An optional string that points to a user supplied TypeScript configuration
- /// file that augments the the default configuration passed to the TypeScript
+ /// An optional config file with user supplied TypeScript configuration
+ /// that augments the the default configuration passed to the TypeScript
/// compiler.
- pub maybe_config_path: Option<String>,
+ pub maybe_config_file: Option<ConfigFile>,
}
#[derive(Debug, Default)]
@@ -593,10 +594,10 @@ pub struct CheckOptions {
pub emit: bool,
/// The base type libraries that should be used when type checking.
pub lib: TypeLib,
- /// An optional string that points to a user supplied TypeScript configuration
- /// file that augments the the default configuration passed to the TypeScript
+ /// An optional config file with user supplied TypeScript configuration
+ /// that augments the the default configuration passed to the TypeScript
/// compiler.
- pub maybe_config_path: Option<String>,
+ pub maybe_config_file: Option<ConfigFile>,
/// Ignore any previously emits and ensure that all files are emitted from
/// source.
pub reload: bool,
@@ -642,10 +643,10 @@ pub struct EmitOptions {
pub struct TranspileOptions {
/// If `true` then debug logging will be output from the isolate.
pub debug: bool,
- /// An optional string that points to a user supplied TypeScript configuration
- /// file that augments the the default configuration passed to the TypeScript
+ /// An optional config file with user supplied TypeScript configuration
+ /// that augments the the default configuration passed to the TypeScript
/// compiler.
- pub maybe_config_path: Option<String>,
+ pub maybe_config_file: Option<ConfigFile>,
/// Ignore any previously emits and ensure that all files are emitted from
/// source.
pub reload: bool,
@@ -773,8 +774,8 @@ impl Graph {
"jsxFactory": "React.createElement",
"jsxFragmentFactory": "React.Fragment",
}));
- let maybe_ignored_options =
- ts_config.merge_tsconfig(options.maybe_config_path)?;
+ let maybe_ignored_options = ts_config
+ .merge_tsconfig_from_config_file(options.maybe_config_file.as_ref())?;
let s = self.emit_bundle(
&root_specifier,
@@ -823,8 +824,8 @@ impl Graph {
"noEmit": true,
}));
}
- let maybe_ignored_options =
- config.merge_tsconfig(options.maybe_config_path)?;
+ let maybe_ignored_options = config
+ .merge_tsconfig_from_config_file(options.maybe_config_file.as_ref())?;
// Short circuit if none of the modules require an emit, or all of the
// modules that require an emit have a valid emit. There is also an edge
@@ -1610,8 +1611,8 @@ impl Graph {
"jsxFragmentFactory": "React.Fragment",
}));
- let maybe_ignored_options =
- ts_config.merge_tsconfig(options.maybe_config_path)?;
+ let maybe_ignored_options = ts_config
+ .merge_tsconfig_from_config_file(options.maybe_config_file.as_ref())?;
let config = ts_config.as_bytes();
let emit_options: ast::EmitOptions = ts_config.into();
@@ -2178,7 +2179,7 @@ pub mod tests {
debug: false,
emit: true,
lib: TypeLib::DenoWindow,
- maybe_config_path: None,
+ maybe_config_file: None,
reload: false,
})
.expect("should have checked");
@@ -2200,7 +2201,7 @@ pub mod tests {
debug: false,
emit: false,
lib: TypeLib::DenoWindow,
- maybe_config_path: None,
+ maybe_config_file: None,
reload: false,
})
.expect("should have checked");
@@ -2217,7 +2218,7 @@ pub mod tests {
debug: false,
emit: true,
lib: TypeLib::DenoWindow,
- maybe_config_path: None,
+ maybe_config_file: None,
reload: false,
})
.expect("should have checked");
@@ -2241,7 +2242,7 @@ pub mod tests {
debug: false,
emit: false,
lib: TypeLib::DenoWindow,
- maybe_config_path: None,
+ maybe_config_file: None,
reload: false,
})
.expect("should have checked");
@@ -2263,7 +2264,7 @@ pub mod tests {
debug: false,
emit: true,
lib: TypeLib::DenoWindow,
- maybe_config_path: None,
+ maybe_config_file: None,
reload: false,
})
.expect("should have checked");
@@ -2284,7 +2285,7 @@ pub mod tests {
debug: false,
emit: false,
lib: TypeLib::DenoWindow,
- maybe_config_path: None,
+ maybe_config_file: None,
reload: false,
})
.expect("should have checked");
@@ -2296,14 +2297,14 @@ pub mod tests {
let specifier = resolve_url_or_path("file:///tests/checkwithconfig.ts")
.expect("could not resolve module");
let (graph, handler) = setup(specifier.clone()).await;
+ let config_file =
+ ConfigFile::read("tests/module_graph/tsconfig_01.json").unwrap();
let result_info = graph
.check(CheckOptions {
debug: false,
emit: true,
lib: TypeLib::DenoWindow,
- maybe_config_path: Some(
- "tests/module_graph/tsconfig_01.json".to_string(),
- ),
+ maybe_config_file: Some(config_file),
reload: true,
})
.expect("should have checked");
@@ -2317,14 +2318,14 @@ pub mod tests {
// let's do it all over again to ensure that the versions are determinstic
let (graph, handler) = setup(specifier).await;
+ let config_file =
+ ConfigFile::read("tests/module_graph/tsconfig_01.json").unwrap();
let result_info = graph
.check(CheckOptions {
debug: false,
emit: true,
lib: TypeLib::DenoWindow,
- maybe_config_path: Some(
- "tests/module_graph/tsconfig_01.json".to_string(),
- ),
+ maybe_config_file: Some(config_file),
reload: true,
})
.expect("should have checked");
@@ -2545,10 +2546,12 @@ pub mod tests {
let specifier = resolve_url_or_path("https://deno.land/x/transpile.tsx")
.expect("could not resolve module");
let (mut graph, handler) = setup(specifier).await;
+ let config_file =
+ ConfigFile::read("tests/module_graph/tsconfig.json").unwrap();
let result_info = graph
.transpile(TranspileOptions {
debug: false,
- maybe_config_path: Some("tests/module_graph/tsconfig.json".to_string()),
+ maybe_config_file: Some(config_file),
reload: false,
})
.unwrap();