BREAKING CHANGE(smartwatch): Introduce Smartwatch: cross-runtime native file watching for Node.js, Deno and Bun; rename smartchok to smartwatch and bump major version to 2.0.0

This commit is contained in:
2025-11-30 03:04:49 +00:00
parent aab3ce213b
commit 0f17be179c
16 changed files with 1011 additions and 162 deletions

33
ts/watchers/index.ts Normal file
View File

@@ -0,0 +1,33 @@
import { Smartenv } from '@push.rocks/smartenv';
import type { IWatcher, IWatcherOptions, IWatchEvent, TWatchEventType } from './interfaces.js';
export type { IWatcher, IWatcherOptions, IWatchEvent, TWatchEventType };
/**
* Creates a platform-appropriate file watcher based on the current runtime
* Uses @push.rocks/smartenv for runtime detection
*/
export async function createWatcher(options: IWatcherOptions): Promise<IWatcher> {
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);
}
}
/**
* Default watcher options
*/
export const defaultWatcherOptions: IWatcherOptions = {
basePaths: [],
depth: 4,
followSymlinks: false,
stabilityThreshold: 300,
pollInterval: 100
};