Skip to content

Commit b6ffa7d

Browse files
feat: support rspack native fs watcher (#10658)
* feat: support rspack native fs watcher * Refactor watcher module: Enhance event handling and introduce Executor - Updated `Cargo.toml` to include the "time" feature for Tokio. - Refactored `WatcherDirectoriesAnalyzer` to use `WatchTarget` instead of `WatchInfo`. - Introduced `Executor` struct to manage file system event handling and aggregation. - Removed the old `WatcherExecutor` implementation and replaced it with the new `Executor`. - Improved `DiskWatcher` to manage watched paths more effectively. - Enhanced `Trigger` to facilitate dependency resolution for file system events. - Updated the `FsWatcher` struct to integrate the new `Executor` and streamline event processing. - Added detailed documentation for new and modified structs and methods. * Refactor watcher module Introduce PathManager and PathAccessor - Removed the PathRegister and its associated logic, replacing it with PathManager to manage paths, directories, and missing paths. - Introduced PathAccessor for accessing registered paths. - Updated Analyzer trait to work with the new PathAccessor. - Modified DiskWatcher to handle WatchPattern instead of raw paths. - Enhanced Executor to manage event execution with aggregate handling. - Updated NativeWatchFileSystem to include pause functionality and improved callback handling. - Added tests for PathManager and related structures to ensure correct functionality. * feat: implement Scanner for path existence checks and event triggering * Refactor path handling to use ArcPath for improved memory efficiency * fix: pass testing * Refactor NativeWatcher and executor for improved pause functionality and add native watcher support in test tools * refactor: clean up code formatting and improve readability across multiple files * Smplify NativeWatcher implementation and update RecommendedAnalyzer result * Add NativeWatcher module for file system watching capabilities * Update API report files for consistency * format js * update Zod shema and split test into nativeWatcher.test.js * fix typo * Adjest ts import order * fix typo * Adjust using FxHashMap instead of std hashmap * Update path_manager comments * fix: add external dependencies to skip list in deny.toml * Add nativeWatcher experiment option for improved file change monitoring * feat: add safety documentation for NativeWatcher watch method and improve import order in watch.ts * fix: update concurrent mode for native watcher and remove platform check * Remove unused import * fix: update path manager references and enhance DiskWatcher initialization * fix: improve documentation for nativeWatcher performance issues * fix: enhance safety documentation for NativeWatcher methods and update method signatures to async * fix: update NativeWatcher safety documentation and adjust internal dependency accessors * fix: correct variable name from 'close' to 'closed' and update default symlink behavior in NativeWatcher * fix: update NativeWatcher ignored option to synchronous and enhance glob pattern handling * fix: remove trailing newline at the end of experiments documentation * fix: update native watcher to disable concurrent mode * fix: add conditional check for WASM platform in nativeWatcher tests * fix: refactor nativeWatcher tests to always run without WASM condition * fix: remove WASM condition for NativeWatcher test in jest config * fix: temporarily skip NativeWatcher tests due to instability in CI * fix: temporarily skip NativeWatcher tests due to instability in CI * fix: correct file extension for NativeWatcher test exclusion in Jest config * fix: update nativeWatcher ApiMeta version to 1.4.4 * Set default-features=false to notify dependency for reduce binary size * feat: update NativeWatcher API to use NativeWatchResult and improve event handling * fix: allow clippy warning for too many arguments in NativeWatcher::watch method * fix: remove unused parameter from watch method in MultiCompiler test * fix: skip test due to parse error in MultiCompiler * feat: implement watcher instance with close, pause, and getInfo methods in MultiCompiler * chore: update nativeWatcher version to 1.4.6 in documentation * Update core.api.md * refactor: simplify Analyzer trait and improve Watcher analyzers for incremental path management * docs: update experiments documentation for `nativeWatcher` and add details for `inlineConst` feature * chore: update glob-to-regexp dependency in package.json and prebundle.config.mjs * refactor: update WatcherIncrementalDependencies to use Iterable types with added and removed properties * fix: correct file reference in MultiCompiler test for first run condition * fix: update missingDependencies to reference addedMissingDependencies instead of removedMissingDependencies
1 parent e78688e commit b6ffa7d

File tree

38 files changed

+2533
-42
lines changed

38 files changed

+2533
-42
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ micromegas-perfetto = { version = "0.9.0", default-features = false }
6363
miette = { version = "7.5.0", default-features = false }
6464
mimalloc = { version = "0.2.4", package = "mimalloc-rspack", default-features = false }
6565
mime_guess = { version = "2.0.5", default-features = false, features = ["rev-mappings"] }
66+
notify = { version = "8.1.0", default-features = false }
6667
num-bigint = { version = "0.4.6", default-features = false }
6768
once_cell = { version = "1.20.2", default-features = false }
6869
oneshot = { version = "0.1.8", default-features = false, features = ["std", "async"] }

crates/node_binding/binding.d.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,25 @@ export declare class ModuleGraphConnection {
441441
get originModule(): Module | null
442442
}
443443

444+
export declare class NativeWatcher {
445+
constructor(options: NativeWatcherOptions)
446+
watch(files: [Array<string>, Array<string>], directories: [Array<string>, Array<string>], missing: [Array<string>, Array<string>], callback: (err: Error | null, result: NativeWatchResult) => void, callbackUndelayed: (path: string) => void): void
447+
/**
448+
* # Safety
449+
*
450+
* This function is unsafe because it uses `&mut self` to call the watcher asynchronously.
451+
* It's important to ensure that the watcher is not used in any other places before this function is finished.
452+
* You must ensure that the watcher not call watch, close or pause in the same time, otherwise it may lead to undefined behavior.
453+
*/
454+
close(): Promise<void>
455+
pause(): void
456+
}
457+
458+
export declare class NativeWatchResult {
459+
changedFiles: Array<string>
460+
removedFiles: Array<string>
461+
}
462+
444463

445464
export declare class RawExternalItemFnCtx {
446465
data(): RawExternalItemFnCtxData
@@ -1487,6 +1506,14 @@ export declare function minify(source: string, options: string): Promise<Transfo
14871506

14881507
export declare function minifySync(source: string, options: string): TransformOutput
14891508

1509+
export interface NativeWatcherOptions {
1510+
followSymlinks?: boolean
1511+
pollInterval?: number
1512+
aggregateTimeout?: number
1513+
/** A function that will be called with the path of a file or directory that is ignored. */
1514+
ignored?: (path: string) => boolean
1515+
}
1516+
14901517
export interface NodeFsStats {
14911518
isFile: boolean
14921519
isDirectory: boolean

crates/rspack_binding_api/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ mod module;
5656
mod module_graph;
5757
mod module_graph_connection;
5858
mod modules;
59+
mod native_watcher;
5960
mod normal_module_factory;
6061
mod options;
6162
mod panic;
@@ -99,6 +100,7 @@ pub use module::*;
99100
pub use module_graph::*;
100101
pub use module_graph_connection::*;
101102
pub use modules::*;
103+
pub use native_watcher::*;
102104
pub use normal_module_factory::*;
103105
pub use options::*;
104106
pub use path_data::*;

0 commit comments

Comments
 (0)