feat(watchers): add Rust-powered watcher backend with runtime fallback and cross-platform test coverage
This commit is contained in:
@@ -4,18 +4,27 @@ import type { IWatcher, IWatcherOptions, IWatchEvent, TWatchEventType } from './
|
||||
export type { IWatcher, IWatcherOptions, IWatchEvent, TWatchEventType };
|
||||
|
||||
/**
|
||||
* Creates a platform-appropriate file watcher based on the current runtime
|
||||
* Uses @push.rocks/smartenv for runtime detection
|
||||
* Creates a file watcher, preferring the Rust backend when available.
|
||||
* Falls back to chokidar (Node.js/Bun) or Deno.watchFs based on runtime.
|
||||
*/
|
||||
export async function createWatcher(options: IWatcherOptions): Promise<IWatcher> {
|
||||
// Try Rust watcher first (works on all runtimes via smartrust IPC)
|
||||
try {
|
||||
const { RustWatcher } = await import('./watcher.rust.js');
|
||||
if (await RustWatcher.isAvailable()) {
|
||||
return new RustWatcher(options);
|
||||
}
|
||||
} catch {
|
||||
// Rust watcher not available, fall back
|
||||
}
|
||||
|
||||
// Fall back to runtime-specific watchers
|
||||
const env = new Smartenv();
|
||||
|
||||
if (env.isDeno) {
|
||||
// Deno runtime - use Deno.watchFs
|
||||
const { DenoWatcher } = await import('./watcher.deno.js');
|
||||
return new DenoWatcher(options);
|
||||
} else {
|
||||
// Node.js or Bun - both use fs.watch (Bun has Node.js compatibility)
|
||||
const { NodeWatcher } = await import('./watcher.node.js');
|
||||
return new NodeWatcher(options);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user