Skip to content

Commit

Permalink
💄 - Improve output
Browse files Browse the repository at this point in the history
  • Loading branch information
jfrolich committed Apr 10, 2024
1 parent 08ebaaa commit b6cb141
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 91 deletions.
2 changes: 1 addition & 1 deletion benches/base_bench.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
80 changes: 42 additions & 38 deletions src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
);
Expand All @@ -160,67 +156,73 @@ 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
);
let timing_cleanup = Instant::now();
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()
);
Ok(build_state)
}

fn format_step(current: usize, total: usize) -> console::StyledObject<String> {
style(format!("[{}/{}]", current, total)).bold().dim()
}

pub fn incremental_build(
build_state: &mut BuildState,
default_timing: Option<Duration>,
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(),
Expand All @@ -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()
);
Expand All @@ -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()
);
Expand All @@ -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()
);

Expand All @@ -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() {
Expand All @@ -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(),
Expand All @@ -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()
Expand All @@ -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()
);
Expand All @@ -347,13 +351,13 @@ pub fn build(filter: &Option<regex::Regex>, 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);
Expand Down
6 changes: 3 additions & 3 deletions src/build/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/build/packages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
Expand Down
18 changes: 10 additions & 8 deletions src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions src/watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 7 additions & 6 deletions tests/snapshots/dependency-cycle.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
31 changes: 23 additions & 8 deletions tests/snapshots/remove-file.txt
Original file line number Diff line number Diff line change
@@ -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?


Expand Down
18 changes: 10 additions & 8 deletions tests/snapshots/rename-file-with-interface.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
16 changes: 9 additions & 7 deletions tests/snapshots/rename-file.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading

0 comments on commit b6cb141

Please sign in to comment.