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:
33
ts/watchers/index.ts
Normal file
33
ts/watchers/index.ts
Normal 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
|
||||
};
|
||||
Reference in New Issue
Block a user