|
|
|
|
|
import { Stats } from 'fs'; |
|
|
import { EventEmitter } from 'events'; |
|
|
import { ReaddirpStream, ReaddirpOptions, EntryInfo } from 'readdirp'; |
|
|
import { NodeFsHandler, EventName, Path, EVENTS as EV, WatchHandlers } from './handler.js'; |
|
|
type AWF = { |
|
|
stabilityThreshold: number; |
|
|
pollInterval: number; |
|
|
}; |
|
|
type BasicOpts = { |
|
|
persistent: boolean; |
|
|
ignoreInitial: boolean; |
|
|
followSymlinks: boolean; |
|
|
cwd?: string; |
|
|
usePolling: boolean; |
|
|
interval: number; |
|
|
binaryInterval: number; |
|
|
alwaysStat?: boolean; |
|
|
depth?: number; |
|
|
ignorePermissionErrors: boolean; |
|
|
atomic: boolean | number; |
|
|
}; |
|
|
export type Throttler = { |
|
|
timeoutObject: NodeJS.Timeout; |
|
|
clear: () => void; |
|
|
count: number; |
|
|
}; |
|
|
export type ChokidarOptions = Partial<BasicOpts & { |
|
|
ignored: Matcher | Matcher[]; |
|
|
awaitWriteFinish: boolean | Partial<AWF>; |
|
|
}>; |
|
|
export type FSWInstanceOptions = BasicOpts & { |
|
|
ignored: Matcher[]; |
|
|
awaitWriteFinish: false | AWF; |
|
|
}; |
|
|
export type ThrottleType = 'readdir' | 'watch' | 'add' | 'remove' | 'change'; |
|
|
export type EmitArgs = [path: Path, stats?: Stats]; |
|
|
export type EmitErrorArgs = [error: Error, stats?: Stats]; |
|
|
export type EmitArgsWithName = [event: EventName, ...EmitArgs]; |
|
|
export type MatchFunction = (val: string, stats?: Stats) => boolean; |
|
|
export interface MatcherObject { |
|
|
path: string; |
|
|
recursive?: boolean; |
|
|
} |
|
|
export type Matcher = string | RegExp | MatchFunction | MatcherObject; |
|
|
|
|
|
|
|
|
|
|
|
declare class DirEntry { |
|
|
path: Path; |
|
|
_removeWatcher: (dir: string, base: string) => void; |
|
|
items: Set<Path>; |
|
|
constructor(dir: Path, removeWatcher: (dir: string, base: string) => void); |
|
|
add(item: string): void; |
|
|
remove(item: string): Promise<void>; |
|
|
has(item: string): boolean | undefined; |
|
|
getChildren(): string[]; |
|
|
dispose(): void; |
|
|
} |
|
|
export declare class WatchHelper { |
|
|
fsw: FSWatcher; |
|
|
path: string; |
|
|
watchPath: string; |
|
|
fullWatchPath: string; |
|
|
dirParts: string[][]; |
|
|
followSymlinks: boolean; |
|
|
statMethod: 'stat' | 'lstat'; |
|
|
constructor(path: string, follow: boolean, fsw: FSWatcher); |
|
|
entryPath(entry: EntryInfo): Path; |
|
|
filterPath(entry: EntryInfo): boolean; |
|
|
filterDir(entry: EntryInfo): boolean; |
|
|
} |
|
|
export interface FSWatcherKnownEventMap { |
|
|
[EV.READY]: []; |
|
|
[EV.RAW]: Parameters<WatchHandlers['rawEmitter']>; |
|
|
[EV.ERROR]: Parameters<WatchHandlers['errHandler']>; |
|
|
[EV.ALL]: [event: EventName, ...EmitArgs]; |
|
|
} |
|
|
export type FSWatcherEventMap = FSWatcherKnownEventMap & { |
|
|
[k in Exclude<EventName, keyof FSWatcherKnownEventMap>]: EmitArgs; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export declare class FSWatcher extends EventEmitter<FSWatcherEventMap> { |
|
|
closed: boolean; |
|
|
options: FSWInstanceOptions; |
|
|
_closers: Map<string, Array<any>>; |
|
|
_ignoredPaths: Set<Matcher>; |
|
|
_throttled: Map<ThrottleType, Map<any, any>>; |
|
|
_streams: Set<ReaddirpStream>; |
|
|
_symlinkPaths: Map<Path, string | boolean>; |
|
|
_watched: Map<string, DirEntry>; |
|
|
_pendingWrites: Map<string, any>; |
|
|
_pendingUnlinks: Map<string, EmitArgsWithName>; |
|
|
_readyCount: number; |
|
|
_emitReady: () => void; |
|
|
_closePromise?: Promise<void>; |
|
|
_userIgnored?: MatchFunction; |
|
|
_readyEmitted: boolean; |
|
|
_emitRaw: WatchHandlers['rawEmitter']; |
|
|
_boundRemove: (dir: string, item: string) => void; |
|
|
_nodeFsHandler: NodeFsHandler; |
|
|
constructor(_opts?: ChokidarOptions); |
|
|
_addIgnoredPath(matcher: Matcher): void; |
|
|
_removeIgnoredPath(matcher: Matcher): void; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
add(paths_: Path | Path[], _origAdd?: string, _internal?: boolean): FSWatcher; |
|
|
|
|
|
|
|
|
|
|
|
unwatch(paths_: Path | Path[]): FSWatcher; |
|
|
|
|
|
|
|
|
|
|
|
close(): Promise<void>; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getWatched(): Record<string, string[]>; |
|
|
emitWithAll(event: EventName, args: EmitArgs): void; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_emit(event: EventName, path: Path, stats?: Stats): Promise<this | undefined>; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_handleError(error: Error): Error | boolean; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_throttle(actionType: ThrottleType, path: Path, timeout: number): Throttler | false; |
|
|
_incrReadyCount(): number; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_awaitWriteFinish(path: Path, threshold: number, event: EventName, awfEmit: (err?: Error, stat?: Stats) => void): void; |
|
|
|
|
|
|
|
|
|
|
|
_isIgnored(path: Path, stats?: Stats): boolean; |
|
|
_isntIgnored(path: Path, stat?: Stats): boolean; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_getWatchHelpers(path: Path): WatchHelper; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_getWatchedDir(directory: string): DirEntry; |
|
|
|
|
|
|
|
|
|
|
|
_hasReadPermissions(stats: Stats): boolean; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_remove(directory: string, item: string, isDirectory?: boolean): void; |
|
|
|
|
|
|
|
|
|
|
|
_closePath(path: Path): void; |
|
|
|
|
|
|
|
|
|
|
|
_closeFile(path: Path): void; |
|
|
_addPathCloser(path: Path, closer: () => void): void; |
|
|
_readdirp(root: Path, opts?: Partial<ReaddirpOptions>): ReaddirpStream | undefined; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export declare function watch(paths: string | string[], options?: ChokidarOptions): FSWatcher; |
|
|
declare const _default: { |
|
|
watch: typeof watch; |
|
|
FSWatcher: typeof FSWatcher; |
|
|
}; |
|
|
export default _default; |
|
|
|