Skip to content

Commit b6cb141

Browse files
committed
💄 - Improve output
1 parent 08ebaaa commit b6cb141

File tree

11 files changed

+119
-91
lines changed

11 files changed

+119
-91
lines changed

benches/base_bench.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use criterion::{criterion_group, criterion_main, Criterion};
22
use rewatch::build;
3+
use rewatch::build::clean;
34
use rewatch::build::packages;
4-
use rewatch::clean;
55
use rewatch::helpers;
66

77
use std::fs::File;

src/build.rs

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -117,21 +117,17 @@ pub fn initialize_build<'a>(
117117
let root_config_name = packages::get_package_name(&project_root);
118118
let rescript_version = helpers::get_rescript_version(&bsc_path);
119119

120-
print!(
121-
"{} {} Building package tree...",
122-
style("[1/7]").bold().dim(),
123-
TREE
124-
);
120+
print!("{}{}Building package tree...", style("[1/7]").bold().dim(), TREE);
125121
let _ = stdout().flush();
126122
let timing_package_tree = Instant::now();
127123
let packages = packages::make(&filter, &project_root, &workspace_root);
128124
let timing_package_tree_elapsed = timing_package_tree.elapsed();
129125

130126
println!(
131-
"{}\r{} {}Built package tree in {:.2}s",
127+
"{}{} {}Built package tree in {:.2}s",
132128
LINE_CLEAR,
133129
style("[1/7]").bold().dim(),
134-
CHECKMARK,
130+
TREE,
135131
default_timing
136132
.unwrap_or(timing_package_tree_elapsed)
137133
.as_secs_f64()
@@ -144,7 +140,7 @@ pub fn initialize_build<'a>(
144140
let timing_source_files = Instant::now();
145141

146142
print!(
147-
"{} {} Finding source files...",
143+
"{} {}Finding source files...",
148144
style("[2/7]").bold().dim(),
149145
LOOKING_GLASS
150146
);
@@ -160,67 +156,73 @@ pub fn initialize_build<'a>(
160156
packages::parse_packages(&mut build_state);
161157
let timing_source_files_elapsed = timing_source_files.elapsed();
162158
println!(
163-
"{}\r{} {}Found source files in {:.2}s",
159+
"{}{} {}Found source files in {:.2}s",
164160
LINE_CLEAR,
165161
style("[2/7]").bold().dim(),
166-
CHECKMARK,
162+
LOOKING_GLASS,
167163
default_timing
168164
.unwrap_or(timing_source_files_elapsed)
169165
.as_secs_f64()
170166
);
171167

172168
print!(
173-
"{} {} Reading compile state...",
169+
"{} {}Reading compile state...",
174170
style("[3/7]").bold().dim(),
175-
LOOKING_GLASS
171+
COMPILE_STATE
176172
);
177173
let _ = stdout().flush();
178174
let timing_compile_state = Instant::now();
179175
let compile_assets_state = read_compile_state::read(&mut build_state);
180176
let timing_compile_state_elapsed = timing_compile_state.elapsed();
181177
println!(
182-
"{}\r{} {}Read compile state {:.2}s",
178+
"{}{} {}Read compile state {:.2}s",
183179
LINE_CLEAR,
184180
style("[3/7]").bold().dim(),
185-
CHECKMARK,
181+
COMPILE_STATE,
186182
default_timing
187183
.unwrap_or(timing_compile_state_elapsed)
188184
.as_secs_f64()
189185
);
190186

191187
print!(
192-
"{} {} Cleaning up previous build...",
188+
"{} {}Cleaning up previous build...",
193189
style("[4/7]").bold().dim(),
194190
SWEEP
195191
);
196192
let timing_cleanup = Instant::now();
197193
let (diff_cleanup, total_cleanup) = clean::cleanup_previous_build(&mut build_state, compile_assets_state);
198194
let timing_cleanup_elapsed = timing_cleanup.elapsed();
199195
println!(
200-
"{}\r{} {}Cleaned {}/{} {:.2}s",
196+
"{}{} {}Cleaned {}/{} {:.2}s",
201197
LINE_CLEAR,
202198
style("[4/7]").bold().dim(),
203-
CHECKMARK,
199+
SWEEP,
204200
diff_cleanup,
205201
total_cleanup,
206202
default_timing.unwrap_or(timing_cleanup_elapsed).as_secs_f64()
207203
);
208204
Ok(build_state)
209205
}
210206

207+
fn format_step(current: usize, total: usize) -> console::StyledObject<String> {
208+
style(format!("[{}/{}]", current, total)).bold().dim()
209+
}
210+
211211
pub fn incremental_build(
212212
build_state: &mut BuildState,
213213
default_timing: Option<Duration>,
214214
initial_build: bool,
215+
only_incremental: bool,
215216
) -> Result<(), ()> {
216217
logs::initialize(&build_state.packages);
217218
let num_dirty_modules = build_state.modules.values().filter(|m| is_dirty(m)).count() as u64;
218-
219219
let pb = ProgressBar::new(num_dirty_modules);
220+
let mut current_step = if only_incremental { 1 } else { 5 };
221+
let total_steps = if only_incremental { 3 } else { 7 };
220222
pb.set_style(
221223
ProgressStyle::with_template(&format!(
222-
"{} {} Parsing... {{spinner}} {{pos}}/{{len}} {{msg}}",
223-
style("[5/7]").bold().dim(),
224+
"{} {}Parsing... {{spinner}} {{pos}}/{{len}} {{msg}}",
225+
format_step(current_step, total_steps),
224226
CODE
225227
))
226228
.unwrap(),
@@ -233,10 +235,10 @@ pub fn incremental_build(
233235
match result_asts {
234236
Ok(err) => {
235237
println!(
236-
"{}\r{} {}Parsed {} source files in {:.2}s",
238+
"{}{} {}Parsed {} source files in {:.2}s",
237239
LINE_CLEAR,
238-
style("[5/7]").bold().dim(),
239-
CHECKMARK,
240+
format_step(current_step, total_steps),
241+
CODE,
240242
num_dirty_modules,
241243
default_timing.unwrap_or(timing_ast_elapsed).as_secs_f64()
242244
);
@@ -245,9 +247,9 @@ pub fn incremental_build(
245247
Err(err) => {
246248
logs::finalize(&build_state.packages);
247249
println!(
248-
"{}\r{} {}Error parsing source files in {:.2}s",
250+
"{}{} {}Error parsing source files in {:.2}s",
249251
LINE_CLEAR,
250-
style("[5/7]").bold().dim(),
252+
format_step(current_step, total_steps),
251253
CROSS,
252254
default_timing.unwrap_or(timing_ast_elapsed).as_secs_f64()
253255
);
@@ -258,12 +260,13 @@ pub fn incremental_build(
258260
let timing_deps = Instant::now();
259261
deps::get_deps(build_state, &build_state.deleted_modules.to_owned());
260262
let timing_deps_elapsed = timing_deps.elapsed();
263+
current_step += 1;
261264

262265
println!(
263-
"{}\r{} {}Collected deps in {:.2}s",
266+
"{}{} {}Collected deps in {:.2}s",
264267
LINE_CLEAR,
265-
style("[6/7]").bold().dim(),
266-
CHECKMARK,
268+
format_step(current_step, total_steps),
269+
DEPS,
267270
default_timing.unwrap_or(timing_deps_elapsed).as_secs_f64()
268271
);
269272

@@ -279,6 +282,7 @@ pub fn incremental_build(
279282
mark_modules_with_expired_deps_dirty(build_state);
280283
}
281284
mark_modules_with_deleted_deps_dirty(build_state);
285+
current_step += 1;
282286

283287
// print all the compile_dirty modules
284288
// for (module_name, module) in build_state.modules.iter() {
@@ -291,8 +295,8 @@ pub fn incremental_build(
291295
let pb = ProgressBar::new(build_state.modules.len().try_into().unwrap());
292296
pb.set_style(
293297
ProgressStyle::with_template(&format!(
294-
"{} {} Compiling... {{spinner}} {{pos}}/{{len}} {{msg}}",
295-
style("[7/7]").bold().dim(),
298+
"{} {}Compiling... {{spinner}} {{pos}}/{{len}} {{msg}}",
299+
format_step(current_step, total_steps),
296300
SWORDS
297301
))
298302
.unwrap(),
@@ -308,9 +312,9 @@ pub fn incremental_build(
308312
println!("{}", &compile_warnings);
309313
}
310314
println!(
311-
"{}\r{} {}Compiled {} modules in {:.2}s",
315+
"{}{} {}Compiled {} modules in {:.2}s",
312316
LINE_CLEAR,
313-
style("[7/7]").bold().dim(),
317+
format_step(current_step, total_steps),
314318
CROSS,
315319
num_compiled_modules,
316320
default_timing.unwrap_or(compile_duration).as_secs_f64()
@@ -325,10 +329,10 @@ pub fn incremental_build(
325329
return Err(());
326330
} else {
327331
println!(
328-
"{}\r{} {}Compiled {} modules in {:.2}s",
332+
"{}{} {}Compiled {} modules in {:.2}s",
329333
LINE_CLEAR,
330-
style("[7/7]").bold().dim(),
331-
CHECKMARK,
334+
format_step(current_step, total_steps),
335+
SWORDS,
332336
num_compiled_modules,
333337
default_timing.unwrap_or(compile_duration).as_secs_f64()
334338
);
@@ -347,13 +351,13 @@ pub fn build(filter: &Option<regex::Regex>, path: &str, no_timing: bool) -> Resu
347351
};
348352
let timing_total = Instant::now();
349353
let mut build_state = initialize_build(default_timing, filter, path)?;
350-
match incremental_build(&mut build_state, default_timing, true) {
354+
match incremental_build(&mut build_state, default_timing, true, false) {
351355
Ok(_) => {
352356
let timing_total_elapsed = timing_total.elapsed();
353357
println!(
354-
"{}\r{}Finished Compilation in {:.2}s",
358+
"\n{}{}Finished Compilation in {:.2}s",
355359
LINE_CLEAR,
356-
CHECKMARK,
360+
SPARKLES,
357361
default_timing.unwrap_or(timing_total_elapsed).as_secs_f64()
358362
);
359363
clean::cleanup_after_build(&build_state);

src/build/clean.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ pub fn clean(path: &str) {
359359
std::io::stdout().flush().unwrap();
360360
packages.iter().for_each(|(_, package)| {
361361
print!(
362-
"{}\r{} {} Cleaning {}...",
362+
"{}{} {} Cleaning {}...",
363363
LINE_CLEAR,
364364
style("[1/2]").bold().dim(),
365365
SWEEP,
@@ -378,7 +378,7 @@ pub fn clean(path: &str) {
378378
let timing_clean_compiler_assets_elapsed = timing_clean_compiler_assets.elapsed();
379379

380380
println!(
381-
"{}\r{} {}Cleaned compiler assets in {:.2}s",
381+
"{}{} {}Cleaned compiler assets in {:.2}s",
382382
LINE_CLEAR,
383383
style("[1/2]").bold().dim(),
384384
CHECKMARK,
@@ -401,7 +401,7 @@ pub fn clean(path: &str) {
401401
clean_mjs_files(&build_state);
402402
let timing_clean_mjs_elapsed = timing_clean_mjs.elapsed();
403403
println!(
404-
"{}\r{} {}Cleaned mjs files in {:.2}s",
404+
"{}{} {}Cleaned mjs files in {:.2}s",
405405
LINE_CLEAR,
406406
style("[2/2]").bold().dim(),
407407
CHECKMARK,

src/build/packages.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ pub fn parse_packages(build_state: &mut BuildState) {
683683
match source_files.get(&implementation_filename) {
684684
None => {
685685
println!(
686-
"{}\rWarning: No implementation file found for interface file (skipping): {}",
686+
"{}Warning: No implementation file found for interface file (skipping): {}",
687687
LINE_CLEAR, file
688688
)
689689
}

src/helpers.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@ use std::time::{SystemTime, UNIX_EPOCH};
99
pub mod emojis {
1010
use console::Emoji;
1111
pub static COMMAND: Emoji<'_, '_> = Emoji("🏃 ", "");
12-
pub static TREE: Emoji<'_, '_> = Emoji("🌴 ", "");
12+
pub static TREE: Emoji<'_, '_> = Emoji("📦 ", "");
1313
pub static SWEEP: Emoji<'_, '_> = Emoji("🧹 ", "");
14-
pub static LOOKING_GLASS: Emoji<'_, '_> = Emoji("🔍 ", "");
15-
pub static CODE: Emoji<'_, '_> = Emoji("🟰 ", "");
16-
pub static SWORDS: Emoji<'_, '_> = Emoji("⚔️ ", "");
17-
pub static DEPS: Emoji<'_, '_> = Emoji("️🕸️ ", "");
18-
pub static CHECKMARK: Emoji<'_, '_> = Emoji("️✅ ", "");
19-
pub static CROSS: Emoji<'_, '_> = Emoji("️🛑 ", "");
20-
pub static LINE_CLEAR: &str = "\x1b[2K";
14+
pub static LOOKING_GLASS: Emoji<'_, '_> = Emoji("🕵️ ", "");
15+
pub static CODE: Emoji<'_, '_> = Emoji("🧱 ", "");
16+
pub static SWORDS: Emoji<'_, '_> = Emoji("🤺 ️", "");
17+
pub static DEPS: Emoji<'_, '_> = Emoji("️🌴 ", "");
18+
pub static CHECKMARK: Emoji<'_, '_> = Emoji("️✅ ", "");
19+
pub static CROSS: Emoji<'_, '_> = Emoji("️🛑 ", "");
20+
pub static SPARKLES: Emoji<'_, '_> = Emoji("✨ ", "");
21+
pub static COMPILE_STATE: Emoji<'_, '_> = Emoji("📝 ", "");
22+
pub static LINE_CLEAR: &str = "\x1b[2K\r";
2123
}
2224

2325
pub trait LexicalAbsolute {

src/watcher.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,13 @@ async fn async_watch(
204204
CompileType::Full => {
205205
let timing_total = Instant::now();
206206
build_state = build::initialize_build(None, filter, path).expect("Can't initialize build");
207-
let _ = build::incremental_build(&mut build_state, None, initial_build);
207+
let _ = build::incremental_build(&mut build_state, None, initial_build, false);
208208
after_build.clone().map(|command| cmd::run(command));
209209
let timing_total_elapsed = timing_total.elapsed();
210210
println!(
211-
"{}\r{}Finished compilation in {:.2}s",
211+
"\n{}{}Finished compilation in {:.2}s\n",
212212
LINE_CLEAR,
213-
CHECKMARK,
213+
SPARKLES,
214214
timing_total_elapsed.as_secs_f64()
215215
);
216216
needs_compile_type = CompileType::None;

tests/snapshots/dependency-cycle.txt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
[1/7] 🌴 Building package tree...[1/7] ️✅ Built package tree in 0.00s
2-
[2/7] 🔍 Finding source files...[2/7] ️✅ Found source files in 0.00s
3-
[3/7] 🧹 Cleaning up previous build...[3/7] ️✅ Cleaned 0/10 0.00s
4-
[4/7] ️✅ Parsed 1 source files in 0.00s
5-
[5/7] ️✅ Collected deps in 0.00s
6-
[6/7] ️🛑 Compiled 0 modules in 0.00s
1+
[1/7]📦 Building package tree...[1/7] 📦 Built package tree in 0.00s
2+
[2/7] 🕵️ Finding source files...[2/7] 🕵️ Found source files in 0.00s
3+
[3/7] 📝 Reading compile state...[3/7] 📝 Read compile state 0.00s
4+
[4/7] 🧹 Cleaning up previous build...[4/7] 🧹 Cleaned 0/10 0.00s
5+
[5/7] 🧱 Parsed 1 source files in 0.00s
6+
[6/7] ️🌴 Collected deps in 0.00s
7+
[7/7] ️🛑 Compiled 0 modules in 0.00s
78

89
Can't continue... Found a circular dependency in your code:
910
NewNamespace.NS_alias -> Dep01 -> Dep02 -> NS -> NewNamespace.NS_alias

tests/snapshots/remove-file.txt

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
1-
[1/7] 🌴 Building package tree...[1/7] ️✅ Built package tree in 0.00s
2-
[2/7] 🔍 Finding source files...[2/7] ️✅ Found source files in 0.00s
3-
[3/7] 🔍 Reading compile state...[3/7] ️✅ Read compile state 0.00s
4-
[4/7] 🧹 Cleaning up previous build...[4/7] ️✅ Cleaned 1/10 0.00s
5-
[5/7] ️✅ Parsed 0 source files in 0.00s
6-
[6/7] ️✅ Collected deps in 0.00s
7-
[7/7] ️✅ Compiled 0 modules in 0.00s
8-
️✅ Finished Compilation in 0.00s
1+
[1/7]📦 Building package tree...[1/7] 📦 Built package tree in 0.00s
2+
[2/7] 🕵️ Finding source files...[2/7] 🕵️ Found source files in 0.00s
3+
[3/7] 📝 Reading compile state...[3/7] 📝 Read compile state 0.00s
4+
[4/7] 🧹 Cleaning up previous build...[4/7] 🧹 Cleaned 1/10 0.00s
5+
[5/7] 🧱 Parsed 0 source files in 0.00s
6+
[6/7] ️🌴 Collected deps in 0.00s
7+
[7/7] ️🛑 Compiled 1 modules in 0.00s
8+
9+
We've found a bug for you!
10+
/packages/dep01/src/Dep01.res:3:9-17
11+
12+
1 │ let log = () => {
13+
2 │ Js.log("02")
14+
3 │ Dep02.log()
15+
4 │ }
16+
5 │
17+
18+
The module or file Dep02 can't be found.
19+
- If it's a third-party dependency:
20+
- Did you add it to the "bs-dependencies" or "bs-dev-dependencies" in bsconfig.json?
21+
- Did you include the file's directory to the "sources" in bsconfig.json?
22+
23+

tests/snapshots/rename-file-with-interface.txt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
[1/7] 🌴 Building package tree...[1/7] ️✅ Built package tree in 0.00s
2-
[2/7] 🔍 Finding source files...Warning: No implementation file found for interface file (skipping): src/ModuleWithInterface.resi
3-
[2/7] ️✅ Found source files in 0.00s
4-
[3/7] 🧹 Cleaning up previous build...[3/7] ️✅ Cleaned 2/10 0.00s
5-
[4/7] ️✅ Parsed 1 source files in 0.00s
6-
[5/7] ️✅ Collected deps in 0.00s
7-
[6/7] ️✅ Compiled 1 modules in 0.00s
8-
[7/7] ️✅ Finished Compilation in 0.00s
1+
[1/7]📦 Building package tree...[1/7] 📦 Built package tree in 0.00s
2+
[2/7] 🕵️ Finding source files...Warning: No implementation file found for interface file (skipping): src/ModuleWithInterface.resi
3+
[2/7] 🕵️ Found source files in 0.00s
4+
[3/7] 📝 Reading compile state...[3/7] 📝 Read compile state 0.00s
5+
[4/7] 🧹 Cleaning up previous build...[4/7] 🧹 Cleaned 2/10 0.00s
6+
[5/7] 🧱 Parsed 1 source files in 0.00s
7+
[6/7] ️🌴 Collected deps in 0.00s
8+
[7/7] 🤺 ️Compiled 1 modules in 0.00s
9+
10+
✨ Finished Compilation in 0.00s

tests/snapshots/rename-file.txt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
[1/7] 🌴 Building package tree...[1/7] ️✅ Built package tree in 0.00s
2-
[2/7] 🔍 Finding source files...[2/7] ️✅ Found source files in 0.00s
3-
[3/7] 🧹 Cleaning up previous build...[3/7] ️✅ Cleaned 1/10 0.00s
4-
[4/7] ️✅ Parsed 1 source files in 0.00s
5-
[5/7] ️✅ Collected deps in 0.00s
6-
[6/7] ️✅ Compiled 1 modules in 0.00s
7-
[7/7] ️✅ Finished Compilation in 0.00s
1+
[1/7]📦 Building package tree...[1/7] 📦 Built package tree in 0.00s
2+
[2/7] 🕵️ Finding source files...[2/7] 🕵️ Found source files in 0.00s
3+
[3/7] 📝 Reading compile state...[3/7] 📝 Read compile state 0.00s
4+
[4/7] 🧹 Cleaning up previous build...[4/7] 🧹 Cleaned 1/10 0.00s
5+
[5/7] 🧱 Parsed 1 source files in 0.00s
6+
[6/7] ️🌴 Collected deps in 0.00s
7+
[7/7] 🤺 ️Compiled 1 modules in 0.00s
8+
9+
✨ Finished Compilation in 0.00s

0 commit comments

Comments
 (0)