Skip to content

Commit bdc7a2f

Browse files
committed
Fix
1 parent 2c247a8 commit bdc7a2f

1 file changed

Lines changed: 28 additions & 15 deletions

File tree

rewatch/src/watcher.rs

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ enum CompileType {
2525
None,
2626
}
2727

28+
type WatchPaths = Vec<(PathBuf, RecursiveMode)>;
29+
type StartupBuildResult = (
30+
BuildCommandState,
31+
WatchPaths,
32+
Option<(Instant, build::CompilationOutcome)>,
33+
);
34+
2835
fn is_rescript_file(path_buf: &Path) -> bool {
2936
let extension = path_buf.extension().and_then(|ext| ext.to_str());
3037

@@ -257,7 +264,7 @@ async fn async_watch(
257264
}: AsyncWatchArgs<'_>,
258265
) -> Result<()> {
259266
let mut build_state = initial_build_state;
260-
let mut needs_compile_type = CompileType::Incremental;
267+
let mut needs_compile_type = CompileType::None;
261268
// create a mutex to capture if ctrl-c was pressed
262269
let ctrlc_pressed = Arc::new(Mutex::new(false));
263270
let ctrlc_pressed_clone = Arc::clone(&ctrlc_pressed);
@@ -567,7 +574,7 @@ pub fn start(
567574

568575
// Initialization can clean previous build artifacts, so it has to be serialized
569576
// with the initial compile too.
570-
let (build_state, current_watch_paths): (BuildCommandState, Vec<(PathBuf, RecursiveMode)>) =
577+
let (build_state, current_watch_paths, initial_compile_result): StartupBuildResult =
571578
build::with_build_lock(path, || {
572579
let mut build_state = build::initialize_build(
573580
None,
@@ -586,32 +593,38 @@ pub fn start(
586593
register_watches(&mut watcher, &current_watch_paths);
587594

588595
let timing_total = Instant::now();
589-
if let Ok(result) = build::incremental_build_without_lock(
596+
let initial_compile_result = build::incremental_build_without_lock(
590597
&mut build_state,
591598
None,
592599
true,
593600
show_progress,
594601
false,
595602
create_sourcedirs,
596603
plain_output,
597-
) {
598-
finish_successful_watch_compile(
599-
after_build.clone(),
600-
timing_total,
601-
show_progress,
602-
plain_output,
603-
"Finished initial compilation",
604-
Some("initial"),
605-
result,
606-
);
607-
}
604+
)
605+
.ok()
606+
.map(|result| (timing_total, result));
608607

609-
Ok::<(BuildCommandState, Vec<(PathBuf, RecursiveMode)>), anyhow::Error>((
608+
Ok::<StartupBuildResult, anyhow::Error>((
610609
build_state,
611610
current_watch_paths,
611+
initial_compile_result,
612612
))
613613
})?;
614614

615+
// Run after-build outside build.lock. Hooks may invoke ReScript commands that need the same lock.
616+
if let Some((timing_total, result)) = initial_compile_result {
617+
finish_successful_watch_compile(
618+
after_build.clone(),
619+
timing_total,
620+
show_progress,
621+
plain_output,
622+
"Finished initial compilation",
623+
Some("initial"),
624+
result,
625+
);
626+
}
627+
615628
async_watch(AsyncWatchArgs {
616629
watcher: &mut watcher,
617630
current_watch_paths,

0 commit comments

Comments
 (0)