Skip to content

Commit cd6bc43

Browse files
authored
Reduce logs (#7971)
* Reduce logs * Fix line break * Removed unused emojis * Fix extension print * Add changelog * Add link
1 parent 5d769e9 commit cd6bc43

File tree

4 files changed

+56
-144
lines changed

4 files changed

+56
-144
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
- Rewatch: plain output when not running in tty. https://github.com/rescript-lang/rescript/pull/7970
3131
- Streamline rewatch help texts. https://github.com/rescript-lang/rescript/pull/7973
32+
- Rewatch: Reduced build progress output from 7 steps to 3 for cleaner, less verbose logging. https://github.com/rescript-lang/rescript/pull/7971
3233

3334
#### :house: Internal
3435

rewatch/src/build.rs

Lines changed: 37 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use log::log_enabled;
2424
use serde::Serialize;
2525
use std::fmt;
2626
use std::fs::File;
27-
use std::io::{Write, stdout};
27+
use std::io::Write;
2828
use std::path::{Path, PathBuf};
2929
use std::time::{Duration, Instant};
3030

@@ -137,118 +137,47 @@ pub fn initialize_build(
137137
let project_context = ProjectContext::new(path)?;
138138
let compiler = get_compiler_info(&project_context)?;
139139

140-
if !plain_output && show_progress {
141-
print!("{} {}Building package tree...", style("[1/7]").bold().dim(), TREE);
142-
let _ = stdout().flush();
143-
}
144-
145-
let timing_package_tree = Instant::now();
140+
let timing_clean_start = Instant::now();
146141
let packages = packages::make(filter, &project_context, show_progress)?;
147-
let timing_package_tree_elapsed = timing_package_tree.elapsed();
148142

149143
let compiler_check = verify_compiler_info(&packages, &compiler);
150144

145+
if !packages::validate_packages_dependencies(&packages) {
146+
return Err(anyhow!("Failed to validate package dependencies"));
147+
}
148+
149+
let mut build_state = BuildCommandState::new(project_context, packages, compiler, warn_error);
150+
packages::parse_packages(&mut build_state);
151+
152+
let compile_assets_state = read_compile_state::read(&mut build_state)?;
153+
154+
let (diff_cleanup, total_cleanup) = clean::cleanup_previous_build(&mut build_state, compile_assets_state);
155+
let timing_clean_total = timing_clean_start.elapsed();
156+
151157
if show_progress {
152158
if plain_output {
153159
if let CompilerCheckResult::CleanedPackagesDueToCompiler = compiler_check {
154160
// Snapshot-friendly output (no progress prefixes or emojis)
155161
println!("Cleaned previous build due to compiler update");
156162
}
163+
println!("Cleaned {diff_cleanup}/{total_cleanup}")
157164
} else {
158-
println!(
159-
"{}{} {}Built package tree in {:.2}s",
160-
LINE_CLEAR,
161-
style("[1/7]").bold().dim(),
162-
TREE,
163-
default_timing
164-
.unwrap_or(timing_package_tree_elapsed)
165-
.as_secs_f64()
166-
);
167165
if let CompilerCheckResult::CleanedPackagesDueToCompiler = compiler_check {
168166
println!(
169167
"{}{} {}Cleaned previous build due to compiler update",
170168
LINE_CLEAR,
171-
style("[1/7]").bold().dim(),
169+
style("[1/3]").bold().dim(),
172170
SWEEP
173171
);
174172
}
175-
}
176-
}
177-
178-
if !packages::validate_packages_dependencies(&packages) {
179-
return Err(anyhow!("Failed to validate package dependencies"));
180-
}
181-
182-
let timing_source_files = Instant::now();
183-
184-
if !plain_output && show_progress {
185-
print!(
186-
"{} {}Finding source files...",
187-
style("[2/7]").bold().dim(),
188-
LOOKING_GLASS
189-
);
190-
let _ = stdout().flush();
191-
}
192-
193-
let mut build_state = BuildCommandState::new(project_context, packages, compiler, warn_error);
194-
packages::parse_packages(&mut build_state);
195-
let timing_source_files_elapsed = timing_source_files.elapsed();
196-
197-
if !plain_output && show_progress {
198-
println!(
199-
"{}{} {}Found source files in {:.2}s",
200-
LINE_CLEAR,
201-
style("[2/7]").bold().dim(),
202-
LOOKING_GLASS,
203-
default_timing
204-
.unwrap_or(timing_source_files_elapsed)
205-
.as_secs_f64()
206-
);
207-
208-
print!(
209-
"{} {}Reading compile state...",
210-
style("[3/7]").bold().dim(),
211-
COMPILE_STATE
212-
);
213-
let _ = stdout().flush();
214-
}
215-
let timing_compile_state = Instant::now();
216-
let compile_assets_state = read_compile_state::read(&mut build_state)?;
217-
let timing_compile_state_elapsed = timing_compile_state.elapsed();
218-
219-
if !plain_output && show_progress {
220-
println!(
221-
"{}{} {}Read compile state {:.2}s",
222-
LINE_CLEAR,
223-
style("[3/7]").bold().dim(),
224-
COMPILE_STATE,
225-
default_timing
226-
.unwrap_or(timing_compile_state_elapsed)
227-
.as_secs_f64()
228-
);
229-
230-
print!(
231-
"{} {}Cleaning up previous build...",
232-
style("[4/7]").bold().dim(),
233-
SWEEP
234-
);
235-
}
236-
let timing_cleanup = Instant::now();
237-
let (diff_cleanup, total_cleanup) = clean::cleanup_previous_build(&mut build_state, compile_assets_state);
238-
let timing_cleanup_elapsed = timing_cleanup.elapsed();
239-
240-
if show_progress {
241-
if plain_output {
242-
println!("Cleaned {diff_cleanup}/{total_cleanup}")
243-
} else {
244173
println!(
245-
"{}{} {}Cleaned {}/{} {:.2}s",
174+
"{}{} {}Cleaned {}/{} in {:.2}s",
246175
LINE_CLEAR,
247-
style("[4/7]").bold().dim(),
176+
style("[1/3]").bold().dim(),
248177
SWEEP,
249178
diff_cleanup,
250179
total_cleanup,
251-
default_timing.unwrap_or(timing_cleanup_elapsed).as_secs_f64()
180+
default_timing.unwrap_or(timing_clean_total).as_secs_f64()
252181
);
253182
}
254183
}
@@ -316,8 +245,8 @@ pub fn incremental_build(
316245
} else {
317246
ProgressBar::hidden()
318247
};
319-
let mut current_step = if only_incremental { 1 } else { 5 };
320-
let total_steps = if only_incremental { 3 } else { 7 };
248+
let mut current_step = if only_incremental { 1 } else { 2 };
249+
let total_steps = if only_incremental { 2 } else { 3 };
321250
pb.set_style(
322251
ProgressStyle::with_template(&format!(
323252
"{} {}Parsing... {{spinner}} {{pos}}/{{len}} {{msg}}",
@@ -327,27 +256,14 @@ pub fn incremental_build(
327256
.unwrap(),
328257
);
329258

259+
let timing_parse_start = Instant::now();
330260
let timing_ast = Instant::now();
331261
let result_asts = parse::generate_asts(build_state, || pb.inc(1));
332262
let timing_ast_elapsed = timing_ast.elapsed();
333263

334264
match result_asts {
335265
Ok(_ast) => {
336-
if show_progress {
337-
if plain_output {
338-
println!("Parsed {num_dirty_modules} source files")
339-
} else {
340-
println!(
341-
"{}{} {}Parsed {} source files in {:.2}s",
342-
LINE_CLEAR,
343-
format_step(current_step, total_steps),
344-
CODE,
345-
num_dirty_modules,
346-
default_timing.unwrap_or(timing_ast_elapsed).as_secs_f64()
347-
);
348-
pb.finish();
349-
}
350-
}
266+
pb.finish();
351267
}
352268
Err(err) => {
353269
logs::finalize(&build_state.packages);
@@ -370,20 +286,23 @@ pub fn incremental_build(
370286
});
371287
}
372288
}
373-
let timing_deps = Instant::now();
374289
let deleted_modules = build_state.deleted_modules.clone();
375290
deps::get_deps(build_state, &deleted_modules);
376-
let timing_deps_elapsed = timing_deps.elapsed();
377-
current_step += 1;
291+
let timing_parse_total = timing_parse_start.elapsed();
378292

379-
if !plain_output && show_progress {
380-
println!(
381-
"{}{} {}Collected deps in {:.2}s",
382-
LINE_CLEAR,
383-
format_step(current_step, total_steps),
384-
DEPS,
385-
default_timing.unwrap_or(timing_deps_elapsed).as_secs_f64()
386-
);
293+
if show_progress {
294+
if plain_output {
295+
println!("Parsed {num_dirty_modules} source files")
296+
} else {
297+
println!(
298+
"{}{} {}Parsed {} source files in {:.2}s",
299+
LINE_CLEAR,
300+
format_step(current_step, total_steps),
301+
CODE,
302+
num_dirty_modules,
303+
default_timing.unwrap_or(timing_parse_total).as_secs_f64()
304+
);
305+
}
387306
}
388307

389308
mark_modules_with_expired_deps_dirty(build_state);

rewatch/src/build/clean.rs

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -367,31 +367,27 @@ pub fn clean(path: &Path, show_progress: bool, plain_output: bool) -> Result<()>
367367
let mut build_state = BuildState::new(project_context, packages, compiler_info);
368368
packages::parse_packages(&mut build_state);
369369
let root_config = build_state.get_root_config();
370-
let suffix_for_print = if plain_output || !show_progress {
371-
String::new()
372-
} else {
373-
match root_config.package_specs {
374-
None => match &root_config.suffix {
375-
None => String::from(".js"),
376-
Some(suffix) => suffix.clone(),
377-
},
378-
Some(_) => root_config
379-
.get_package_specs()
380-
.into_iter()
381-
.filter_map(|spec| {
382-
if spec.in_source {
383-
spec.suffix.or_else(|| root_config.suffix.clone())
384-
} else {
385-
None
386-
}
387-
})
388-
.collect::<Vec<String>>()
389-
.join(", "),
390-
}
370+
let suffix_for_print = match root_config.package_specs {
371+
None => match &root_config.suffix {
372+
None => String::from(".js"),
373+
Some(suffix) => suffix.clone(),
374+
},
375+
Some(_) => root_config
376+
.get_package_specs()
377+
.into_iter()
378+
.filter_map(|spec| {
379+
if spec.in_source {
380+
spec.suffix.or_else(|| root_config.suffix.clone())
381+
} else {
382+
None
383+
}
384+
})
385+
.collect::<Vec<String>>()
386+
.join(", "),
391387
};
392388

393389
if !plain_output && show_progress {
394-
println!(
390+
print!(
395391
"{} {}Cleaning {} files...",
396392
style("[2/2]").bold().dim(),
397393
SWEEP,

rewatch/src/helpers.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,12 @@ pub mod deserialize;
1919
pub mod emojis {
2020
use console::Emoji;
2121
pub static COMMAND: Emoji<'_, '_> = Emoji("🏃 ", "");
22-
pub static TREE: Emoji<'_, '_> = Emoji("📦 ", "");
2322
pub static SWEEP: Emoji<'_, '_> = Emoji("🧹 ", "");
24-
pub static LOOKING_GLASS: Emoji<'_, '_> = Emoji("👀 ", "");
2523
pub static CODE: Emoji<'_, '_> = Emoji("🧱 ", "");
2624
pub static SWORDS: Emoji<'_, '_> = Emoji("🤺 ", "");
27-
pub static DEPS: Emoji<'_, '_> = Emoji("🌴 ", "");
2825
pub static CHECKMARK: Emoji<'_, '_> = Emoji("✅ ", "");
2926
pub static CROSS: Emoji<'_, '_> = Emoji("❌ ", "");
3027
pub static SPARKLES: Emoji<'_, '_> = Emoji("✨ ", "");
31-
pub static COMPILE_STATE: Emoji<'_, '_> = Emoji("📝 ", "");
3228
pub static LINE_CLEAR: &str = "\x1b[2K\r";
3329
}
3430

0 commit comments

Comments
 (0)