import { Smartenv } from '@push.rocks/smartenv'; import type { IWatcher, IWatcherOptions, IWatchEvent, TWatchEventType } from './interfaces.js'; export type { IWatcher, IWatcherOptions, IWatchEvent, TWatchEventType }; /** * 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 { // 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) { const { DenoWatcher } = await import('./watcher.deno.js'); return new DenoWatcher(options); } else { const { NodeWatcher } = await import('./watcher.node.js'); return new NodeWatcher(options); } } /** * Default watcher options */ export const defaultWatcherOptions: IWatcherOptions = { basePaths: [], depth: 4, followSymlinks: false, debounceMs: 100 };