From 9eaa1fb71d03679367ebca0e0361fa0e47a1274f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Thu, 19 Nov 2020 19:19:34 +0100 Subject: [PATCH] refactor(cli): move tooling to cli/tools/ (#8424) This commit moves following tools into a single "tools" module located at "cli/tools/mod.rs": - formatter - linter - test runner - coverage collector - installer - binary upgrader - repl --- cli/main.rs | 42 ++++++++++++++++------------------ cli/{ => tools}/coverage.rs | 0 cli/{ => tools}/fmt.rs | 0 cli/{ => tools}/installer.rs | 0 cli/{ => tools}/lint.rs | 2 +- cli/tools/mod.rs | 9 ++++++++ cli/{ => tools}/repl.rs | 0 cli/{ => tools}/test_runner.rs | 2 +- cli/{ => tools}/upgrade.rs | 0 9 files changed, 31 insertions(+), 24 deletions(-) rename cli/{ => tools}/coverage.rs (100%) rename cli/{ => tools}/fmt.rs (100%) rename cli/{ => tools}/installer.rs (100%) rename cli/{ => tools}/lint.rs (99%) create mode 100644 cli/tools/mod.rs rename cli/{ => tools}/repl.rs (100%) rename cli/{ => tools}/test_runner.rs (99%) rename cli/{ => tools}/upgrade.rs (100%) diff --git a/cli/main.rs b/cli/main.rs index 11674a8b66..160b98674f 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -10,7 +10,6 @@ extern crate log; mod ast; mod checksum; mod colors; -mod coverage; mod deno_dir; mod diagnostics; mod diff; @@ -20,7 +19,6 @@ mod file_fetcher; mod file_watcher; mod flags; mod flags_allow_net; -mod fmt; mod fmt_errors; mod fs_util; mod http_cache; @@ -28,9 +26,7 @@ mod http_util; mod import_map; mod info; mod inspector; -mod installer; mod js; -mod lint; mod lockfile; mod media_type; mod metrics; @@ -39,22 +35,18 @@ mod module_loader; mod ops; mod permissions; mod program_state; -mod repl; mod resolve_addr; mod signal; mod source_maps; mod specifier_handler; -mod test_runner; mod text_encoding; mod tokio_util; +mod tools; mod tsc; mod tsc_config; -mod upgrade; mod version; mod worker; -use crate::coverage::CoverageCollector; -use crate::coverage::PrettyCoverageReporter; use crate::file_fetcher::File; use crate::file_fetcher::FileFetcher; use crate::media_type::MediaType; @@ -88,7 +80,6 @@ use std::path::PathBuf; use std::pin::Pin; use std::rc::Rc; use std::sync::Arc; -use upgrade::upgrade_command; fn write_to_stdout_ignore_sigpipe(bytes: &[u8]) -> Result<(), std::io::Error> { use std::io::ErrorKind; @@ -213,7 +204,7 @@ async fn install_command( MainWorker::new(&program_state, main_module.clone(), permissions); // First, fetch and compile the module; this step ensures that the module exists. worker.preload_module(&main_module).await?; - installer::install(flags, &module_url, args, name, root, force) + tools::installer::install(flags, &module_url, args, name, root, force) } async fn lint_command( @@ -228,11 +219,11 @@ async fn lint_command( } if list_rules { - lint::print_rules_list(json); + tools::lint::print_rules_list(json); return Ok(()); } - lint::lint_files(files, ignore, json).await + tools::lint::lint_files(files, ignore, json).await } async fn cache_command( @@ -523,7 +514,7 @@ async fn run_repl(flags: Flags) -> Result<(), AnyError> { MainWorker::new(&program_state, main_module.clone(), permissions); worker.run_event_loop().await?; - repl::run(&program_state, worker).await + tools::repl::run(&program_state, worker).await } async fn run_from_stdin(flags: Flags) -> Result<(), AnyError> { @@ -643,7 +634,8 @@ async fn test_command( let permissions = Permissions::from_flags(&flags); let cwd = std::env::current_dir().expect("No current directory"); let include = include.unwrap_or_else(|| vec![".".to_string()]); - let test_modules = test_runner::prepare_test_modules_urls(include, &cwd)?; + let test_modules = + tools::test_runner::prepare_test_modules_urls(include, &cwd)?; if test_modules.is_empty() { println!("No matching test modules found"); @@ -656,7 +648,7 @@ async fn test_command( let test_file_path = cwd.join("$deno$test.ts"); let test_file_url = Url::from_file_path(&test_file_path).expect("Should be valid file url"); - let test_file = test_runner::render_test_file( + let test_file = tools::test_runner::render_test_file( test_modules.clone(), fail_fast, quiet, @@ -680,7 +672,8 @@ async fn test_command( let mut maybe_coverage_collector = if flags.coverage { let session = worker.create_inspector_session(); - let mut coverage_collector = CoverageCollector::new(session); + let mut coverage_collector = + tools::coverage::CoverageCollector::new(session); coverage_collector.start_collecting().await?; Some(coverage_collector) @@ -699,10 +692,14 @@ async fn test_command( let coverages = coverage_collector.collect().await?; coverage_collector.stop_collecting().await?; - let filtered_coverages = - coverage::filter_script_coverages(coverages, test_file_url, test_modules); + let filtered_coverages = tools::coverage::filter_script_coverages( + coverages, + test_file_url, + test_modules, + ); - let mut coverage_reporter = PrettyCoverageReporter::new(quiet); + let mut coverage_reporter = + tools::coverage::PrettyCoverageReporter::new(quiet); for coverage in filtered_coverages { coverage_reporter.visit_coverage(&coverage); } @@ -796,7 +793,7 @@ pub fn main() { check, files, ignore, - } => fmt::format(files, check, ignore).boxed_local(), + } => tools::fmt::format(files, check, ignore).boxed_local(), DenoSubcommand::Info { file, json } => { info_command(flags, file, json).boxed_local() } @@ -847,7 +844,8 @@ pub fn main() { output, ca_file, } => { - upgrade_command(dry_run, force, version, output, ca_file).boxed_local() + tools::upgrade::upgrade_command(dry_run, force, version, output, ca_file) + .boxed_local() } }; diff --git a/cli/coverage.rs b/cli/tools/coverage.rs similarity index 100% rename from cli/coverage.rs rename to cli/tools/coverage.rs diff --git a/cli/fmt.rs b/cli/tools/fmt.rs similarity index 100% rename from cli/fmt.rs rename to cli/tools/fmt.rs diff --git a/cli/installer.rs b/cli/tools/installer.rs similarity index 100% rename from cli/installer.rs rename to cli/tools/installer.rs diff --git a/cli/lint.rs b/cli/tools/lint.rs similarity index 99% rename from cli/lint.rs rename to cli/tools/lint.rs index e319a7be6d..f17709c8b6 100644 --- a/cli/lint.rs +++ b/cli/tools/lint.rs @@ -8,10 +8,10 @@ //! the same functions as ops available in JS runtime. use crate::ast; use crate::colors; -use crate::fmt::run_parallelized; use crate::fmt_errors; use crate::fs_util::{collect_files, is_supported_ext}; use crate::media_type::MediaType; +use crate::tools::fmt::run_parallelized; use deno_core::error::{generic_error, AnyError, JsStackFrame}; use deno_core::serde_json; use deno_lint::diagnostic::LintDiagnostic; diff --git a/cli/tools/mod.rs b/cli/tools/mod.rs new file mode 100644 index 0000000000..be76968fb4 --- /dev/null +++ b/cli/tools/mod.rs @@ -0,0 +1,9 @@ +// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. + +pub mod coverage; +pub mod fmt; +pub mod installer; +pub mod lint; +pub mod repl; +pub mod test_runner; +pub mod upgrade; diff --git a/cli/repl.rs b/cli/tools/repl.rs similarity index 100% rename from cli/repl.rs rename to cli/tools/repl.rs diff --git a/cli/test_runner.rs b/cli/tools/test_runner.rs similarity index 99% rename from cli/test_runner.rs rename to cli/tools/test_runner.rs index cd8a394c50..599a950590 100644 --- a/cli/test_runner.rs +++ b/cli/tools/test_runner.rs @@ -1,7 +1,7 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. use crate::fs_util; -use crate::installer::is_remote_url; +use crate::tools::installer::is_remote_url; use deno_core::error::AnyError; use deno_core::serde_json::json; use deno_core::url::Url; diff --git a/cli/upgrade.rs b/cli/tools/upgrade.rs similarity index 100% rename from cli/upgrade.rs rename to cli/tools/upgrade.rs