Skip to content

fix: rewatch not rebuilding on change #7690

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#### :bug: Bug fix

- Fix `--create-sourcedirs` generation with for a single project. https://github.com/rescript-lang/rescript/pull/7671
- Fix rewatch not recompiling on changes under windows. https://github.com/rescript-lang/rescript/pull/7690

# 12.0.0-beta.2

Expand Down
15 changes: 13 additions & 2 deletions rewatch/src/watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,20 @@ async fn async_watch(
) => {
// if we are going to do a full compile, we don't need to bother marking
// files dirty because we do a full scan anyway
log::debug!("received {:?} while needs_compile_type was {needs_compile_type:?} -> full compile", event.kind);
needs_compile_type = CompileType::Full;
}

(
CompileType::None | CompileType::Incremental,
// when we have a data change event, we can do an incremental compile
EventKind::Modify(ModifyKind::Data(_)),
EventKind::Modify(ModifyKind::Data(_)) |
// windows sends ModifyKind::Any on file content changes
EventKind::Modify(ModifyKind::Any),
) => {
// if we are going to compile incrementally, we need to mark the exact files
// dirty
log::debug!("received {:?} while needs_compile_type was {needs_compile_type:?} -> incremental compile", event.kind);
if let Ok(canonicalized_path_buf) = path_buf
.canonicalize()
.map(StrippedVerbatimPath::to_stripped_verbatim_path)
Expand Down Expand Up @@ -208,7 +212,6 @@ async fn async_watch(
// these are not relevant events for compilation
EventKind::Access(_)
| EventKind::Other
| EventKind::Modify(ModifyKind::Any)
| EventKind::Modify(ModifyKind::Metadata(_))
| EventKind::Modify(ModifyKind::Other),
) => (),
Expand All @@ -217,6 +220,11 @@ async fn async_watch(
}
}
}

if needs_compile_type != CompileType::None {
log::debug!("doing {needs_compile_type:?}");
}

match needs_compile_type {
CompileType::Incremental => {
let timing_total = Instant::now();
Expand Down Expand Up @@ -316,6 +324,9 @@ pub fn start(

let mut watcher = RecommendedWatcher::new(move |res| producer.push(res), Config::default())
.expect("Could not create watcher");

log::debug!("watching {folder}");

watcher
.watch(folder.as_ref(), RecursiveMode::Recursive)
.expect("Could not start watcher");
Expand Down