summaryrefslogtreecommitdiff
path: root/cli/main.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/main.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/main.rs')
-rw-r--r--cli/main.rs82
1 files changed, 46 insertions, 36 deletions
diff --git a/cli/main.rs b/cli/main.rs
index 43c1cd0b2..35a0fed6e 100644
--- a/cli/main.rs
+++ b/cli/main.rs
@@ -4,6 +4,7 @@ mod ast;
mod auth_tokens;
mod checksum;
mod colors;
+mod config_file;
mod deno_dir;
mod diagnostics;
mod diff;
@@ -33,7 +34,6 @@ mod text_encoding;
mod tokio_util;
mod tools;
mod tsc;
-mod tsc_config;
mod unix_util;
mod version;
@@ -359,7 +359,8 @@ async fn compile_command(
colors::green("Bundle"),
module_specifier.to_string()
);
- let bundle_str = bundle_module_graph(module_graph, flags, debug)?;
+ let bundle_str =
+ bundle_module_graph(module_graph, program_state.clone(), flags, debug)?;
info!(
"{} {}",
@@ -565,7 +566,7 @@ async fn create_module_graph_and_maybe_check(
debug,
emit: false,
lib,
- maybe_config_path: program_state.flags.config_path.clone(),
+ maybe_config_file: program_state.maybe_config_file.clone(),
reload: program_state.flags.reload,
})?;
@@ -583,13 +584,14 @@ async fn create_module_graph_and_maybe_check(
fn bundle_module_graph(
module_graph: module_graph::Graph,
+ program_state: Arc<ProgramState>,
flags: Flags,
debug: bool,
) -> Result<String, AnyError> {
let (bundle, stats, maybe_ignored_options) =
module_graph.bundle(module_graph::BundleOptions {
debug,
- maybe_config_path: flags.config_path,
+ maybe_config_file: program_state.maybe_config_file.clone(),
})?;
match maybe_ignored_options {
Some(ignored_options) if flags.no_check => {
@@ -636,13 +638,15 @@ async fn bundle_command(
.push(fs_util::resolve_from_cwd(std::path::Path::new(import_map))?);
}
- Ok((paths_to_watch, module_graph))
+ Ok((paths_to_watch, module_graph, program_state))
}
.map(move |result| match result {
- Ok((paths_to_watch, module_graph)) => ResolutionResult::Restart {
- paths_to_watch,
- result: Ok(module_graph),
- },
+ Ok((paths_to_watch, module_graph, program_state)) => {
+ ResolutionResult::Restart {
+ paths_to_watch,
+ result: Ok((program_state, module_graph)),
+ }
+ }
Err(e) => ResolutionResult::Restart {
paths_to_watch: vec![PathBuf::from(source_file2)],
result: Err(e),
@@ -650,13 +654,17 @@ async fn bundle_command(
})
};
- let operation = |module_graph: module_graph::Graph| {
+ let operation = |(program_state, module_graph): (
+ Arc<ProgramState>,
+ module_graph::Graph,
+ )| {
let flags = flags.clone();
let out_file = out_file.clone();
async move {
info!("{} {}", colors::green("Bundle"), module_graph.info()?.root);
- let output = bundle_module_graph(module_graph, flags, debug)?;
+ let output =
+ bundle_module_graph(module_graph, program_state, flags, debug)?;
debug!(">>>>> bundle END");
@@ -794,13 +802,15 @@ async fn run_with_watch(flags: Flags, script: String) -> Result<(), AnyError> {
.push(fs_util::resolve_from_cwd(std::path::Path::new(import_map))?);
}
- Ok((paths_to_watch, main_module))
+ Ok((paths_to_watch, main_module, program_state))
}
.map(move |result| match result {
- Ok((paths_to_watch, module_info)) => ResolutionResult::Restart {
- paths_to_watch,
- result: Ok(module_info),
- },
+ Ok((paths_to_watch, module_info, program_state)) => {
+ ResolutionResult::Restart {
+ paths_to_watch,
+ result: Ok((program_state, module_info)),
+ }
+ }
Err(e) => ResolutionResult::Restart {
paths_to_watch: vec![PathBuf::from(script2)],
result: Err(e),
@@ -808,26 +818,26 @@ async fn run_with_watch(flags: Flags, script: String) -> Result<(), AnyError> {
})
};
- let operation = |main_module: ModuleSpecifier| {
- let flags = flags.clone();
- let permissions = Permissions::from_options(&flags.clone().into());
- async move {
- let main_module = main_module.clone();
- let program_state = ProgramState::build(flags).await?;
- let mut worker = create_main_worker(
- &program_state,
- main_module.clone(),
- permissions,
- false,
- );
- debug!("main_module {}", main_module);
- worker.execute_module(&main_module).await?;
- worker.execute("window.dispatchEvent(new Event('load'))")?;
- worker.run_event_loop().await?;
- worker.execute("window.dispatchEvent(new Event('unload'))")?;
- Ok(())
- }
- };
+ let operation =
+ |(program_state, main_module): (Arc<ProgramState>, ModuleSpecifier)| {
+ let flags = flags.clone();
+ let permissions = Permissions::from_options(&flags.into());
+ async move {
+ let main_module = main_module.clone();
+ let mut worker = create_main_worker(
+ &program_state,
+ main_module.clone(),
+ permissions,
+ false,
+ );
+ debug!("main_module {}", main_module);
+ worker.execute_module(&main_module).await?;
+ worker.execute("window.dispatchEvent(new Event('load'))")?;
+ worker.run_event_loop().await?;
+ worker.execute("window.dispatchEvent(new Event('unload'))")?;
+ Ok(())
+ }
+ };
file_watcher::watch_func(resolver, operation, "Process").await
}