From b6cb141ae16ef4cb2f53fc2ed47886399c4faea1 Mon Sep 17 00:00:00 2001 From: Jaap Frolich Date: Wed, 3 Apr 2024 14:54:34 +0200 Subject: [PATCH] :lipstick: - Improve output --- benches/base_bench.rs | 2 +- src/build.rs | 80 ++++++++++--------- src/build/clean.rs | 6 +- src/build/packages.rs | 2 +- src/helpers.rs | 18 +++-- src/watcher.rs | 6 +- tests/snapshots/dependency-cycle.txt | 13 +-- tests/snapshots/remove-file.txt | 31 +++++-- .../snapshots/rename-file-with-interface.txt | 18 +++-- tests/snapshots/rename-file.txt | 16 ++-- tests/snapshots/rename-interface-file.txt | 18 +++-- 11 files changed, 119 insertions(+), 91 deletions(-) diff --git a/benches/base_bench.rs b/benches/base_bench.rs index 5eefbae..8b781a0 100644 --- a/benches/base_bench.rs +++ b/benches/base_bench.rs @@ -1,7 +1,7 @@ use criterion::{criterion_group, criterion_main, Criterion}; use rewatch::build; +use rewatch::build::clean; use rewatch::build::packages; -use rewatch::clean; use rewatch::helpers; use std::fs::File; diff --git a/src/build.rs b/src/build.rs index 28df745..90ac962 100644 --- a/src/build.rs +++ b/src/build.rs @@ -117,21 +117,17 @@ pub fn initialize_build<'a>( let root_config_name = packages::get_package_name(&project_root); let rescript_version = helpers::get_rescript_version(&bsc_path); - print!( - "{} {} Building package tree...", - style("[1/7]").bold().dim(), - TREE - ); + print!("{}{}Building package tree...", style("[1/7]").bold().dim(), TREE); let _ = stdout().flush(); let timing_package_tree = Instant::now(); let packages = packages::make(&filter, &project_root, &workspace_root); let timing_package_tree_elapsed = timing_package_tree.elapsed(); println!( - "{}\r{} {}Built package tree in {:.2}s", + "{}{} {}Built package tree in {:.2}s", LINE_CLEAR, style("[1/7]").bold().dim(), - CHECKMARK, + TREE, default_timing .unwrap_or(timing_package_tree_elapsed) .as_secs_f64() @@ -144,7 +140,7 @@ pub fn initialize_build<'a>( let timing_source_files = Instant::now(); print!( - "{} {} Finding source files...", + "{} {}Finding source files...", style("[2/7]").bold().dim(), LOOKING_GLASS ); @@ -160,36 +156,36 @@ pub fn initialize_build<'a>( packages::parse_packages(&mut build_state); let timing_source_files_elapsed = timing_source_files.elapsed(); println!( - "{}\r{} {}Found source files in {:.2}s", + "{}{} {}Found source files in {:.2}s", LINE_CLEAR, style("[2/7]").bold().dim(), - CHECKMARK, + LOOKING_GLASS, default_timing .unwrap_or(timing_source_files_elapsed) .as_secs_f64() ); print!( - "{} {} Reading compile state...", + "{} {}Reading compile state...", style("[3/7]").bold().dim(), - LOOKING_GLASS + COMPILE_STATE ); let _ = stdout().flush(); let timing_compile_state = Instant::now(); let compile_assets_state = read_compile_state::read(&mut build_state); let timing_compile_state_elapsed = timing_compile_state.elapsed(); println!( - "{}\r{} {}Read compile state {:.2}s", + "{}{} {}Read compile state {:.2}s", LINE_CLEAR, style("[3/7]").bold().dim(), - CHECKMARK, + COMPILE_STATE, default_timing .unwrap_or(timing_compile_state_elapsed) .as_secs_f64() ); print!( - "{} {} Cleaning up previous build...", + "{} {}Cleaning up previous build...", style("[4/7]").bold().dim(), SWEEP ); @@ -197,10 +193,10 @@ pub fn initialize_build<'a>( let (diff_cleanup, total_cleanup) = clean::cleanup_previous_build(&mut build_state, compile_assets_state); let timing_cleanup_elapsed = timing_cleanup.elapsed(); println!( - "{}\r{} {}Cleaned {}/{} {:.2}s", + "{}{} {}Cleaned {}/{} {:.2}s", LINE_CLEAR, style("[4/7]").bold().dim(), - CHECKMARK, + SWEEP, diff_cleanup, total_cleanup, default_timing.unwrap_or(timing_cleanup_elapsed).as_secs_f64() @@ -208,19 +204,25 @@ pub fn initialize_build<'a>( Ok(build_state) } +fn format_step(current: usize, total: usize) -> console::StyledObject { + style(format!("[{}/{}]", current, total)).bold().dim() +} + pub fn incremental_build( build_state: &mut BuildState, default_timing: Option, initial_build: bool, + only_incremental: bool, ) -> Result<(), ()> { logs::initialize(&build_state.packages); let num_dirty_modules = build_state.modules.values().filter(|m| is_dirty(m)).count() as u64; - let pb = ProgressBar::new(num_dirty_modules); + let mut current_step = if only_incremental { 1 } else { 5 }; + let total_steps = if only_incremental { 3 } else { 7 }; pb.set_style( ProgressStyle::with_template(&format!( - "{} {} Parsing... {{spinner}} {{pos}}/{{len}} {{msg}}", - style("[5/7]").bold().dim(), + "{} {}Parsing... {{spinner}} {{pos}}/{{len}} {{msg}}", + format_step(current_step, total_steps), CODE )) .unwrap(), @@ -233,10 +235,10 @@ pub fn incremental_build( match result_asts { Ok(err) => { println!( - "{}\r{} {}Parsed {} source files in {:.2}s", + "{}{} {}Parsed {} source files in {:.2}s", LINE_CLEAR, - style("[5/7]").bold().dim(), - CHECKMARK, + format_step(current_step, total_steps), + CODE, num_dirty_modules, default_timing.unwrap_or(timing_ast_elapsed).as_secs_f64() ); @@ -245,9 +247,9 @@ pub fn incremental_build( Err(err) => { logs::finalize(&build_state.packages); println!( - "{}\r{} {}Error parsing source files in {:.2}s", + "{}{} {}Error parsing source files in {:.2}s", LINE_CLEAR, - style("[5/7]").bold().dim(), + format_step(current_step, total_steps), CROSS, default_timing.unwrap_or(timing_ast_elapsed).as_secs_f64() ); @@ -258,12 +260,13 @@ pub fn incremental_build( let timing_deps = Instant::now(); deps::get_deps(build_state, &build_state.deleted_modules.to_owned()); let timing_deps_elapsed = timing_deps.elapsed(); + current_step += 1; println!( - "{}\r{} {}Collected deps in {:.2}s", + "{}{} {}Collected deps in {:.2}s", LINE_CLEAR, - style("[6/7]").bold().dim(), - CHECKMARK, + format_step(current_step, total_steps), + DEPS, default_timing.unwrap_or(timing_deps_elapsed).as_secs_f64() ); @@ -279,6 +282,7 @@ pub fn incremental_build( mark_modules_with_expired_deps_dirty(build_state); } mark_modules_with_deleted_deps_dirty(build_state); + current_step += 1; // print all the compile_dirty modules // for (module_name, module) in build_state.modules.iter() { @@ -291,8 +295,8 @@ pub fn incremental_build( let pb = ProgressBar::new(build_state.modules.len().try_into().unwrap()); pb.set_style( ProgressStyle::with_template(&format!( - "{} {} Compiling... {{spinner}} {{pos}}/{{len}} {{msg}}", - style("[7/7]").bold().dim(), + "{} {}Compiling... {{spinner}} {{pos}}/{{len}} {{msg}}", + format_step(current_step, total_steps), SWORDS )) .unwrap(), @@ -308,9 +312,9 @@ pub fn incremental_build( println!("{}", &compile_warnings); } println!( - "{}\r{} {}Compiled {} modules in {:.2}s", + "{}{} {}Compiled {} modules in {:.2}s", LINE_CLEAR, - style("[7/7]").bold().dim(), + format_step(current_step, total_steps), CROSS, num_compiled_modules, default_timing.unwrap_or(compile_duration).as_secs_f64() @@ -325,10 +329,10 @@ pub fn incremental_build( return Err(()); } else { println!( - "{}\r{} {}Compiled {} modules in {:.2}s", + "{}{} {}Compiled {} modules in {:.2}s", LINE_CLEAR, - style("[7/7]").bold().dim(), - CHECKMARK, + format_step(current_step, total_steps), + SWORDS, num_compiled_modules, default_timing.unwrap_or(compile_duration).as_secs_f64() ); @@ -347,13 +351,13 @@ pub fn build(filter: &Option, path: &str, no_timing: bool) -> Resu }; let timing_total = Instant::now(); let mut build_state = initialize_build(default_timing, filter, path)?; - match incremental_build(&mut build_state, default_timing, true) { + match incremental_build(&mut build_state, default_timing, true, false) { Ok(_) => { let timing_total_elapsed = timing_total.elapsed(); println!( - "{}\r{}Finished Compilation in {:.2}s", + "\n{}{}Finished Compilation in {:.2}s", LINE_CLEAR, - CHECKMARK, + SPARKLES, default_timing.unwrap_or(timing_total_elapsed).as_secs_f64() ); clean::cleanup_after_build(&build_state); diff --git a/src/build/clean.rs b/src/build/clean.rs index bb85958..361829c 100644 --- a/src/build/clean.rs +++ b/src/build/clean.rs @@ -359,7 +359,7 @@ pub fn clean(path: &str) { std::io::stdout().flush().unwrap(); packages.iter().for_each(|(_, package)| { print!( - "{}\r{} {} Cleaning {}...", + "{}{} {} Cleaning {}...", LINE_CLEAR, style("[1/2]").bold().dim(), SWEEP, @@ -378,7 +378,7 @@ pub fn clean(path: &str) { let timing_clean_compiler_assets_elapsed = timing_clean_compiler_assets.elapsed(); println!( - "{}\r{} {}Cleaned compiler assets in {:.2}s", + "{}{} {}Cleaned compiler assets in {:.2}s", LINE_CLEAR, style("[1/2]").bold().dim(), CHECKMARK, @@ -401,7 +401,7 @@ pub fn clean(path: &str) { clean_mjs_files(&build_state); let timing_clean_mjs_elapsed = timing_clean_mjs.elapsed(); println!( - "{}\r{} {}Cleaned mjs files in {:.2}s", + "{}{} {}Cleaned mjs files in {:.2}s", LINE_CLEAR, style("[2/2]").bold().dim(), CHECKMARK, diff --git a/src/build/packages.rs b/src/build/packages.rs index f61fb8a..52e8ed2 100644 --- a/src/build/packages.rs +++ b/src/build/packages.rs @@ -683,7 +683,7 @@ pub fn parse_packages(build_state: &mut BuildState) { match source_files.get(&implementation_filename) { None => { println!( - "{}\rWarning: No implementation file found for interface file (skipping): {}", + "{}Warning: No implementation file found for interface file (skipping): {}", LINE_CLEAR, file ) } diff --git a/src/helpers.rs b/src/helpers.rs index 4a219ba..a71e0e8 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -9,15 +9,17 @@ use std::time::{SystemTime, UNIX_EPOCH}; pub mod emojis { use console::Emoji; pub static COMMAND: Emoji<'_, '_> = Emoji("πŸƒ ", ""); - pub static TREE: Emoji<'_, '_> = Emoji("🌴 ", ""); + pub static TREE: Emoji<'_, '_> = Emoji("πŸ“¦ ", ""); pub static SWEEP: Emoji<'_, '_> = Emoji("🧹 ", ""); - pub static LOOKING_GLASS: Emoji<'_, '_> = Emoji("πŸ” ", ""); - pub static CODE: Emoji<'_, '_> = Emoji("🟰 ", ""); - pub static SWORDS: Emoji<'_, '_> = Emoji("βš”οΈ ", ""); - pub static DEPS: Emoji<'_, '_> = Emoji("οΈπŸ•ΈοΈ ", ""); - pub static CHECKMARK: Emoji<'_, '_> = Emoji("οΈβœ… ", ""); - pub static CROSS: Emoji<'_, '_> = Emoji("οΈπŸ›‘ ", ""); - pub static LINE_CLEAR: &str = "\x1b[2K"; + pub static LOOKING_GLASS: Emoji<'_, '_> = Emoji("πŸ•΅οΈ ", ""); + pub static CODE: Emoji<'_, '_> = Emoji("🧱 ", ""); + pub static SWORDS: Emoji<'_, '_> = Emoji("🀺 ️", ""); + pub static DEPS: Emoji<'_, '_> = Emoji("️🌴 ", ""); + pub static CHECKMARK: Emoji<'_, '_> = Emoji("οΈβœ… ", ""); + pub static CROSS: Emoji<'_, '_> = Emoji("οΈπŸ›‘ ", ""); + pub static SPARKLES: Emoji<'_, '_> = Emoji("✨ ", ""); + pub static COMPILE_STATE: Emoji<'_, '_> = Emoji("πŸ“ ", ""); + pub static LINE_CLEAR: &str = "\x1b[2K\r"; } pub trait LexicalAbsolute { diff --git a/src/watcher.rs b/src/watcher.rs index d02761f..0728c22 100644 --- a/src/watcher.rs +++ b/src/watcher.rs @@ -204,13 +204,13 @@ async fn async_watch( CompileType::Full => { let timing_total = Instant::now(); build_state = build::initialize_build(None, filter, path).expect("Can't initialize build"); - let _ = build::incremental_build(&mut build_state, None, initial_build); + let _ = build::incremental_build(&mut build_state, None, initial_build, false); after_build.clone().map(|command| cmd::run(command)); let timing_total_elapsed = timing_total.elapsed(); println!( - "{}\r{}Finished compilation in {:.2}s", + "\n{}{}Finished compilation in {:.2}s\n", LINE_CLEAR, - CHECKMARK, + SPARKLES, timing_total_elapsed.as_secs_f64() ); needs_compile_type = CompileType::None; diff --git a/tests/snapshots/dependency-cycle.txt b/tests/snapshots/dependency-cycle.txt index 5ca12c8..05c2e65 100644 --- a/tests/snapshots/dependency-cycle.txt +++ b/tests/snapshots/dependency-cycle.txt @@ -1,9 +1,10 @@ -[1/7] 🌴 Building package tree... [1/7] οΈβœ… Built package tree in 0.00s -[2/7] πŸ” Finding source files... [2/7] οΈβœ… Found source files in 0.00s -[3/7] 🧹 Cleaning up previous build... [3/7] οΈβœ… Cleaned 0/10 0.00s - [4/7] οΈβœ… Parsed 1 source files in 0.00s - [5/7] οΈβœ… Collected deps in 0.00s - [6/7] οΈπŸ›‘ Compiled 0 modules in 0.00s +[1/7]πŸ“¦ Building package tree... [1/7] πŸ“¦ Built package tree in 0.00s +[2/7] πŸ•΅οΈ Finding source files... [2/7] πŸ•΅οΈ Found source files in 0.00s +[3/7] πŸ“ Reading compile state... [3/7] πŸ“ Read compile state 0.00s +[4/7] 🧹 Cleaning up previous build... [4/7] 🧹 Cleaned 0/10 0.00s + [5/7] 🧱 Parsed 1 source files in 0.00s + [6/7] ️🌴 Collected deps in 0.00s + [7/7] οΈπŸ›‘ Compiled 0 modules in 0.00s Can't continue... Found a circular dependency in your code: NewNamespace.NS_alias -> Dep01 -> Dep02 -> NS -> NewNamespace.NS_alias diff --git a/tests/snapshots/remove-file.txt b/tests/snapshots/remove-file.txt index 9e2bf71..602ab44 100644 --- a/tests/snapshots/remove-file.txt +++ b/tests/snapshots/remove-file.txt @@ -1,8 +1,23 @@ -[1/7] 🌴 Building package tree... [1/7] οΈβœ… Built package tree in 0.00s -[2/7] πŸ” Finding source files... [2/7] οΈβœ… Found source files in 0.00s -[3/7] πŸ” Reading compile state... [3/7] οΈβœ… Read compile state 0.00s -[4/7] 🧹 Cleaning up previous build... [4/7] οΈβœ… Cleaned 1/10 0.00s - [5/7] οΈβœ… Parsed 0 source files in 0.00s - [6/7] οΈβœ… Collected deps in 0.00s - [7/7] οΈβœ… Compiled 0 modules in 0.00s - οΈβœ… Finished Compilation in 0.00s +[1/7]πŸ“¦ Building package tree... [1/7] πŸ“¦ Built package tree in 0.00s +[2/7] πŸ•΅οΈ Finding source files... [2/7] πŸ•΅οΈ Found source files in 0.00s +[3/7] πŸ“ Reading compile state... [3/7] πŸ“ Read compile state 0.00s +[4/7] 🧹 Cleaning up previous build... [4/7] 🧹 Cleaned 1/10 0.00s + [5/7] 🧱 Parsed 0 source files in 0.00s + [6/7] ️🌴 Collected deps in 0.00s + [7/7] οΈπŸ›‘ Compiled 1 modules in 0.00s + + We've found a bug for you! + /packages/dep01/src/Dep01.res:3:9-17 + + 1 β”‚ let log = () => { + 2 β”‚ Js.log("02") + 3 β”‚ Dep02.log() + 4 β”‚ } + 5 β”‚ + + The module or file Dep02 can't be found. + - If it's a third-party dependency: + - Did you add it to the "bs-dependencies" or "bs-dev-dependencies" in bsconfig.json? + - Did you include the file's directory to the "sources" in bsconfig.json? + + diff --git a/tests/snapshots/rename-file-with-interface.txt b/tests/snapshots/rename-file-with-interface.txt index bf46b58..e16ce55 100644 --- a/tests/snapshots/rename-file-with-interface.txt +++ b/tests/snapshots/rename-file-with-interface.txt @@ -1,8 +1,10 @@ -[1/7] 🌴 Building package tree... [1/7] οΈβœ… Built package tree in 0.00s -[2/7] πŸ” Finding source files... Warning: No implementation file found for interface file (skipping): src/ModuleWithInterface.resi - [2/7] οΈβœ… Found source files in 0.00s -[3/7] 🧹 Cleaning up previous build... [3/7] οΈβœ… Cleaned 2/10 0.00s - [4/7] οΈβœ… Parsed 1 source files in 0.00s - [5/7] οΈβœ… Collected deps in 0.00s - [6/7] οΈβœ… Compiled 1 modules in 0.00s - [7/7] οΈβœ… Finished Compilation in 0.00s +[1/7]πŸ“¦ Building package tree... [1/7] πŸ“¦ Built package tree in 0.00s +[2/7] πŸ•΅οΈ Finding source files... Warning: No implementation file found for interface file (skipping): src/ModuleWithInterface.resi + [2/7] πŸ•΅οΈ Found source files in 0.00s +[3/7] πŸ“ Reading compile state... [3/7] πŸ“ Read compile state 0.00s +[4/7] 🧹 Cleaning up previous build... [4/7] 🧹 Cleaned 2/10 0.00s + [5/7] 🧱 Parsed 1 source files in 0.00s + [6/7] ️🌴 Collected deps in 0.00s + [7/7] 🀺 ️Compiled 1 modules in 0.00s + + ✨ Finished Compilation in 0.00s diff --git a/tests/snapshots/rename-file.txt b/tests/snapshots/rename-file.txt index a365e15..68d3ebf 100644 --- a/tests/snapshots/rename-file.txt +++ b/tests/snapshots/rename-file.txt @@ -1,7 +1,9 @@ -[1/7] 🌴 Building package tree... [1/7] οΈβœ… Built package tree in 0.00s -[2/7] πŸ” Finding source files... [2/7] οΈβœ… Found source files in 0.00s -[3/7] 🧹 Cleaning up previous build... [3/7] οΈβœ… Cleaned 1/10 0.00s - [4/7] οΈβœ… Parsed 1 source files in 0.00s - [5/7] οΈβœ… Collected deps in 0.00s - [6/7] οΈβœ… Compiled 1 modules in 0.00s - [7/7] οΈβœ… Finished Compilation in 0.00s +[1/7]πŸ“¦ Building package tree... [1/7] πŸ“¦ Built package tree in 0.00s +[2/7] πŸ•΅οΈ Finding source files... [2/7] πŸ•΅οΈ Found source files in 0.00s +[3/7] πŸ“ Reading compile state... [3/7] πŸ“ Read compile state 0.00s +[4/7] 🧹 Cleaning up previous build... [4/7] 🧹 Cleaned 1/10 0.00s + [5/7] 🧱 Parsed 1 source files in 0.00s + [6/7] ️🌴 Collected deps in 0.00s + [7/7] 🀺 ️Compiled 1 modules in 0.00s + + ✨ Finished Compilation in 0.00s diff --git a/tests/snapshots/rename-interface-file.txt b/tests/snapshots/rename-interface-file.txt index 4dae4fe..d980584 100644 --- a/tests/snapshots/rename-interface-file.txt +++ b/tests/snapshots/rename-interface-file.txt @@ -1,8 +1,10 @@ -[1/7] 🌴 Building package tree... [1/7] οΈβœ… Built package tree in 0.00s -[2/7] πŸ” Finding source files... Warning: No implementation file found for interface file (skipping): src/ModuleWithInterface2.resi - [2/7] οΈβœ… Found source files in 0.00s -[3/7] 🧹 Cleaning up previous build... [3/7] οΈβœ… Cleaned 1/10 0.00s - [4/7] οΈβœ… Parsed 1 source files in 0.00s - [5/7] οΈβœ… Collected deps in 0.00s - [6/7] οΈβœ… Compiled 1 modules in 0.00s - [7/7] οΈβœ… Finished Compilation in 0.00s +[1/7]πŸ“¦ Building package tree... [1/7] πŸ“¦ Built package tree in 0.00s +[2/7] πŸ•΅οΈ Finding source files... Warning: No implementation file found for interface file (skipping): src/ModuleWithInterface2.resi + [2/7] πŸ•΅οΈ Found source files in 0.00s +[3/7] πŸ“ Reading compile state... [3/7] πŸ“ Read compile state 0.00s +[4/7] 🧹 Cleaning up previous build... [4/7] 🧹 Cleaned 1/10 0.00s + [5/7] 🧱 Parsed 1 source files in 0.00s + [6/7] ️🌴 Collected deps in 0.00s + [7/7] 🀺 ️Compiled 1 modules in 0.00s + + ✨ Finished Compilation in 0.00s