diff --git a/src/handler.ts b/src/handler.ts index 33118e54..840e0a47 100644 --- a/src/handler.ts +++ b/src/handler.ts @@ -11,15 +11,15 @@ export type Path = string; export const STR_DATA = 'data'; export const STR_END = 'end'; export const STR_CLOSE = 'close'; -export const EMPTY_FN = () => {}; -export const IDENTITY_FN = (val: unknown) => val; +export const EMPTY_FN = (): void => {}; +export const IDENTITY_FN = (val: unknown): unknown => val; const pl = process.platform; -export const isWindows = pl === 'win32'; -export const isMacos = pl === 'darwin'; -export const isLinux = pl === 'linux'; -export const isFreeBSD = pl === 'freebsd'; -export const isIBMi = osType() === 'OS400'; +export const isWindows: boolean = pl === 'win32'; +export const isMacos: boolean = pl === 'darwin'; +export const isLinux: boolean = pl === 'linux'; +export const isFreeBSD: boolean = pl === 'freebsd'; +export const isIBMi: boolean = osType() === 'OS400'; export const EVENTS = { ALL: 'all', @@ -375,7 +375,10 @@ export class NodeFsHandler { * @param listener on fs change * @returns closer for the watcher instance */ - _watchWithNodeFs(path: string, listener: (path: string, newStats?: any) => void | Promise) { + _watchWithNodeFs( + path: string, + listener: (path: string, newStats?: any) => void | Promise + ): (() => void) | undefined { const opts = this.fsw.options; const directory = sysPath.dirname(path); const basename = sysPath.basename(path); @@ -532,7 +535,7 @@ export class NodeFsHandler { dir: Path, depth: number, throttler: Throttler - ) { + ): Promise | undefined { // Normalize the directory name on Windows directory = sysPath.join(directory, ''); @@ -677,7 +680,7 @@ export class NodeFsHandler { priorWh: WatchHelper | undefined, depth: number, target?: string - ) { + ): Promise { const ready = this.fsw._emitReady; if (this.fsw._isIgnored(path) || this.fsw.closed) { ready(); diff --git a/src/index.ts b/src/index.ts index 46b4bc92..14006da6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -214,13 +214,13 @@ class DirEntry { this.items = new Set(); } - add(item: string) { + add(item: string): void { const { items } = this; if (!items) return; if (item !== ONE_DOT && item !== TWO_DOTS) items.add(item); } - async remove(item: string) { + async remove(item: string): Promise { const { items } = this; if (!items) return; items.delete(item); @@ -236,7 +236,7 @@ class DirEntry { } } - has(item: string) { + has(item: string): boolean | undefined { const { items } = this; if (!items) return; return items.has(item); @@ -248,7 +248,7 @@ class DirEntry { return [...items.values()]; } - dispose() { + dispose(): void { this.items.clear(); this.path = ''; this._removeWatcher = EMPTY_FN; @@ -581,7 +581,7 @@ export class FSWatcher extends EventEmitter { return watchList; } - emitWithAll(event: EventName, args: EmitArgs) { + emitWithAll(event: EventName, args: EmitArgs): void { this.emit(event, ...args); if (event !== EV.ERROR) this.emit(EV.ALL, event, ...args); } @@ -597,7 +597,7 @@ export class FSWatcher extends EventEmitter { * @param stats arguments to be passed with event * @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag */ - async _emit(event: EventName, path: Path, stats?: Stats) { + async _emit(event: EventName, path: Path, stats?: Stats): Promise { if (this.closed) return; const opts = this.options; @@ -735,7 +735,7 @@ export class FSWatcher extends EventEmitter { return thr; } - _incrReadyCount() { + _incrReadyCount(): number { return this._readyCount++; } @@ -752,7 +752,7 @@ export class FSWatcher extends EventEmitter { threshold: number, event: EventName, awfEmit: (err?: Error, stat?: Stats) => void - ) { + ): void { const awf = this.options.awaitWriteFinish; if (typeof awf !== 'object') return; const pollInterval = awf.pollInterval as unknown as number; @@ -821,7 +821,7 @@ export class FSWatcher extends EventEmitter { return this._userIgnored(path, stats); } - _isntIgnored(path: Path, stat?: Stats) { + _isntIgnored(path: Path, stat?: Stats): boolean { return !this._isIgnored(path, stat); } @@ -926,7 +926,7 @@ export class FSWatcher extends EventEmitter { /** * Closes all watchers for a path */ - _closePath(path: Path) { + _closePath(path: Path): void { this._closeFile(path); const dir = sysPath.dirname(path); this._getWatchedDir(dir).remove(sysPath.basename(path)); @@ -935,14 +935,14 @@ export class FSWatcher extends EventEmitter { /** * Closes only file-specific watchers */ - _closeFile(path: Path) { + _closeFile(path: Path): void { const closers = this._closers.get(path); if (!closers) return; closers.forEach((closer) => closer()); this._closers.delete(path); } - _addPathCloser(path: Path, closer: () => void) { + _addPathCloser(path: Path, closer: () => void): void { if (!closer) return; let list = this._closers.get(path); if (!list) { @@ -952,7 +952,7 @@ export class FSWatcher extends EventEmitter { list.push(closer); } - _readdirp(root: Path, opts?: Partial) { + _readdirp(root: Path, opts?: Partial): ReaddirpStream | undefined { if (this.closed) return; const options = { type: EV.ALL, alwaysStat: true, lstat: true, ...opts, depth: 0 }; let stream: ReaddirpStream | undefined = readdirp(root, options); @@ -985,4 +985,4 @@ export function watch(paths: string | string[], options: ChokidarOptions = {}): return watcher; } -export default { watch, FSWatcher }; +export default { watch: watch as typeof watch, FSWatcher: FSWatcher as typeof FSWatcher }; diff --git a/tsconfig.esm.json b/tsconfig.esm.json index 3ca59b38..ac719249 100644 --- a/tsconfig.esm.json +++ b/tsconfig.esm.json @@ -7,7 +7,8 @@ "moduleResolution": "bundler", "noImplicitReturns": false, "sourceMap": false, - "declarationMap": false + "declarationMap": false, + "isolatedDeclarations": true }, "include": [ "src" diff --git a/tsconfig.json b/tsconfig.json index c9932bcd..370ee502 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,7 +5,8 @@ "outDir": ".", "noImplicitReturns": false, "sourceMap": false, - "declarationMap": false + "declarationMap": false, + "isolatedDeclarations": true }, "include": [ "src"