@push.rocks/smartchok
Version:
A cross-runtime file watcher with glob pattern support for Node.js, Deno, and Bun.
51 lines (50 loc) • 1.5 kB
TypeScript
import * as plugins from './smartwatch.plugins.js';
export type TSmartwatchStatus = 'idle' | 'starting' | 'watching';
export type TFsEvent = 'add' | 'addDir' | 'change' | 'error' | 'unlink' | 'unlinkDir' | 'ready' | 'raw';
/**
* Smartwatch allows easy watching of files
* Uses native file watching APIs (Node.js fs.watch, Deno.watchFs) for cross-runtime support
*/
export declare class Smartwatch {
watchStringmap: plugins.lik.Stringmap;
status: TSmartwatchStatus;
private watcher;
private globPatterns;
private globMatchers;
private watchingDeferred;
private eventSubjects;
/**
* constructor of class Smartwatch
*/
constructor(watchArrayArg: string[]);
private getGlobBase;
/**
* adds files to the list of watched files
*/
add(pathArrayArg: string[]): void;
/**
* removes files from the list of watched files
*/
remove(pathArg: string): void;
/**
* gets an observable for a certain event
*/
getObservableFor(fsEvent: TFsEvent): Promise<plugins.smartrx.rxjs.Observable<[string, plugins.fs.Stats]>>;
/**
* starts the watcher
* @returns Promise<void>
*/
start(): Promise<void>;
/**
* Handle events from the native watcher
*/
private handleWatchEvent;
/**
* stop the watcher process if watching
*/
stop(): Promise<void>;
/**
* Checks if a path should be watched based on glob patterns
*/
private shouldWatchPath;
}