Skip to content

Commit 6c50eac

Browse files
committed
feat(watch): enable full functional fs watcher in wasm
1 parent 461527b commit 6c50eac

File tree

6 files changed

+38
-69
lines changed

6 files changed

+38
-69
lines changed

Cargo.lock

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ pnp = "0.12.7"
194194
rayon = "1.10.0"
195195
regex = "1.11.1"
196196
regress = "0.10.3"
197-
rolldown-notify = "10.1.0"
198-
rolldown-notify-debouncer-full = "0.7.4"
197+
rolldown-notify = "10.2.0"
198+
rolldown-notify-debouncer-full = "0.7.5"
199199
ropey = "1.6.1"
200200
rustc-hash = { version = "2.1.1" }
201201
schemars = "1.0.0"

crates/rolldown_fs_watcher/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ description = "Filesystem watching implementation for Rolldown"
1010

1111
[dependencies]
1212
rolldown-notify = { workspace = true }
13-
rolldown_error = { workspace = true }
14-
15-
[target.'cfg(not(target_family = "wasm"))'.dependencies]
1613
rolldown-notify-debouncer-full = { workspace = true }
14+
rolldown_error = { workspace = true }
1715

1816
[lints]
1917
workspace = true

crates/rolldown_fs_watcher/src/lib.rs

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,13 @@ mod paths_mut;
1111
mod recommended_fs_watcher;
1212
mod utils;
1313

14-
#[cfg(not(target_family = "wasm"))]
1514
mod poll_fs_watcher;
16-
#[cfg(not(target_family = "wasm"))]
1715
pub use poll_fs_watcher::PollFsWatcher;
1816

19-
#[cfg(not(target_family = "wasm"))]
2017
mod debounced_poll_fs_watcher;
21-
#[cfg(not(target_family = "wasm"))]
2218
pub use debounced_poll_fs_watcher::DebouncedPollFsWatcher;
2319

24-
#[cfg(not(target_family = "wasm"))]
2520
mod debounced_recommended_fs_watcher;
26-
#[cfg(not(target_family = "wasm"))]
2721
pub use debounced_recommended_fs_watcher::DebouncedRecommendedFsWatcher;
2822

2923
pub use crate::{
@@ -48,23 +42,16 @@ pub fn create_fs_watcher<F: FsEventHandler>(
4842
event_handler: F,
4943
config: FsWatcherConfig,
5044
) -> rolldown_error::BuildResult<DynFsWatcher> {
51-
#[cfg(not(target_family = "wasm"))]
52-
{
53-
match (config.use_polling, config.use_debounce) {
54-
(true, false) => Ok(PollFsWatcher::with_config(event_handler, config)?.into_dyn_fs_watcher()),
55-
(true, true) => {
56-
Ok(DebouncedPollFsWatcher::with_config(event_handler, config)?.into_dyn_fs_watcher())
57-
}
58-
(false, false) => {
59-
Ok(RecommendedFsWatcher::with_config(event_handler, config)?.into_dyn_fs_watcher())
60-
}
61-
(false, true) => {
62-
Ok(DebouncedRecommendedFsWatcher::with_config(event_handler, config)?.into_dyn_fs_watcher())
63-
}
45+
match (config.use_polling, config.use_debounce) {
46+
(true, false) => Ok(PollFsWatcher::with_config(event_handler, config)?.into_dyn_fs_watcher()),
47+
(true, true) => {
48+
Ok(DebouncedPollFsWatcher::with_config(event_handler, config)?.into_dyn_fs_watcher())
49+
}
50+
(false, false) => {
51+
Ok(RecommendedFsWatcher::with_config(event_handler, config)?.into_dyn_fs_watcher())
52+
}
53+
(false, true) => {
54+
Ok(DebouncedRecommendedFsWatcher::with_config(event_handler, config)?.into_dyn_fs_watcher())
6455
}
65-
}
66-
#[cfg(target_family = "wasm")]
67-
{
68-
Ok(RecommendedFsWatcher::with_config(event_handler, config)?.into_dyn_fs_watcher())
6956
}
7057
}

crates/rolldown_fs_watcher/src/utils.rs

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
use crate::{FsEventHandler, fs_event::FsEvent};
22
use notify::{RecursiveMode, TargetMode, WatchMode};
3+
use notify_debouncer_full::{DebounceEventHandler, DebounceEventResult};
34
use rolldown_error::{BuildResult, ResultExt};
45
use std::{path::Path, time::Instant};
56

6-
#[cfg(not(target_family = "wasm"))]
7-
pub use non_wasm::*;
8-
97
pub struct NotifyEventHandlerAdapter<T: FsEventHandler>(pub T);
108

119
/// Adapter that wraps notify's PathsMut to implement rolldown's PathsMut trait.
@@ -49,24 +47,17 @@ where
4947
}
5048
}
5149

52-
#[cfg(not(target_family = "wasm"))]
53-
mod non_wasm {
54-
55-
use crate::{FsEventHandler, fs_event::FsEvent};
56-
use notify_debouncer_full::{DebounceEventHandler, DebounceEventResult};
57-
58-
/// This makes a Rolldown `EventHandler` to be a compatible `DebounceEventHandler`.
59-
/// So we could pass a Rolldown `EventHandler` to notify-debouncer-full `Debouncer`.
60-
pub struct DebounceEventHandlerAdapter<T: FsEventHandler>(pub T);
50+
/// This makes a Rolldown `EventHandler` to be a compatible `DebounceEventHandler`.
51+
/// So we could pass a Rolldown `EventHandler` to notify-debouncer-full `Debouncer`.
52+
pub struct DebounceEventHandlerAdapter<T: FsEventHandler>(pub T);
6153

62-
impl<T> DebounceEventHandler for DebounceEventHandlerAdapter<T>
63-
where
64-
T: FsEventHandler,
65-
{
66-
fn handle_event(&mut self, event: DebounceEventResult) {
67-
self.0.handle_event(event.map(|events| {
68-
events.into_iter().map(|event| FsEvent { detail: event.event, time: event.time }).collect()
69-
}));
70-
}
54+
impl<T> DebounceEventHandler for DebounceEventHandlerAdapter<T>
55+
where
56+
T: FsEventHandler,
57+
{
58+
fn handle_event(&mut self, event: DebounceEventResult) {
59+
self.0.handle_event(event.map(|events| {
60+
events.into_iter().map(|event| FsEvent { detail: event.event, time: event.time }).collect()
61+
}));
7162
}
7263
}

crates/rolldown_watcher/src/watcher.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ use futures::future::Shared;
99
use oxc_index::IndexVec;
1010
use rolldown::BundlerConfig;
1111
use rolldown_error::BuildResult;
12-
#[cfg(target_family = "wasm")]
13-
use rolldown_fs_watcher::FsWatcher;
1412
use rolldown_fs_watcher::FsWatcherConfig;
1513
use std::future::Future;
1614
use std::pin::Pin;
@@ -137,13 +135,8 @@ impl Watcher {
137135
for (index, config) in configs.into_iter().enumerate() {
138136
let task_index = WatchTaskIdx::from_usize(index);
139137
let fs_handler = TaskFsEventHandler { task_index, tx: tx.clone() };
140-
#[cfg(not(target_family = "wasm"))]
141138
let fs_watcher =
142139
rolldown_fs_watcher::create_fs_watcher(fs_handler, fs_watcher_config.clone())?;
143-
#[cfg(target_family = "wasm")]
144-
let fs_watcher: Box<dyn FsWatcher + Send + 'static> = Box::new(
145-
rolldown_fs_watcher::NoopFsWatcher::with_config(fs_handler, fs_watcher_config.clone())?,
146-
);
147140
let task = WatchTask::new(config, fs_watcher)?;
148141
tasks.push(task);
149142
}

0 commit comments

Comments
 (0)