handler.d.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import type { WatchEventType, Stats, FSWatcher as NativeFsWatcher } from 'fs';
  2. import type { FSWatcher, WatchHelper, Throttler } from './index.js';
  3. import type { EntryInfo } from 'readdirp';
  4. export type Path = string;
  5. export declare const STR_DATA = "data";
  6. export declare const STR_END = "end";
  7. export declare const STR_CLOSE = "close";
  8. export declare const EMPTY_FN: () => void;
  9. export declare const IDENTITY_FN: (val: unknown) => unknown;
  10. export declare const isWindows: boolean;
  11. export declare const isMacos: boolean;
  12. export declare const isLinux: boolean;
  13. export declare const isIBMi: boolean;
  14. export declare const EVENTS: {
  15. readonly ALL: "all";
  16. readonly READY: "ready";
  17. readonly ADD: "add";
  18. readonly CHANGE: "change";
  19. readonly ADD_DIR: "addDir";
  20. readonly UNLINK: "unlink";
  21. readonly UNLINK_DIR: "unlinkDir";
  22. readonly RAW: "raw";
  23. readonly ERROR: "error";
  24. };
  25. export type EventName = (typeof EVENTS)[keyof typeof EVENTS];
  26. export type FsWatchContainer = {
  27. listeners: (path: string) => void | Set<any>;
  28. errHandlers: (err: unknown) => void | Set<any>;
  29. rawEmitters: (ev: WatchEventType, path: string, opts: unknown) => void | Set<any>;
  30. watcher: NativeFsWatcher;
  31. watcherUnusable?: boolean;
  32. };
  33. export interface WatchHandlers {
  34. listener: (path: string) => void;
  35. errHandler: (err: unknown) => void;
  36. rawEmitter: (ev: WatchEventType, path: string, opts: unknown) => void;
  37. }
  38. /**
  39. * @mixin
  40. */
  41. export declare class NodeFsHandler {
  42. fsw: FSWatcher;
  43. _boundHandleError: (error: unknown) => void;
  44. constructor(fsW: FSWatcher);
  45. /**
  46. * Watch file for changes with fs_watchFile or fs_watch.
  47. * @param path to file or dir
  48. * @param listener on fs change
  49. * @returns closer for the watcher instance
  50. */
  51. _watchWithNodeFs(path: string, listener: (path: string, newStats?: any) => void | Promise<void>): (() => void) | undefined;
  52. /**
  53. * Watch a file and emit add event if warranted.
  54. * @returns closer for the watcher instance
  55. */
  56. _handleFile(file: Path, stats: Stats, initialAdd: boolean): (() => void) | undefined;
  57. /**
  58. * Handle symlinks encountered while reading a dir.
  59. * @param entry returned by readdirp
  60. * @param directory path of dir being read
  61. * @param path of this item
  62. * @param item basename of this item
  63. * @returns true if no more processing is needed for this entry.
  64. */
  65. _handleSymlink(entry: EntryInfo, directory: string, path: Path, item: string): Promise<boolean | undefined>;
  66. _handleRead(directory: string, initialAdd: boolean, wh: WatchHelper, target: Path, dir: Path, depth: number, throttler: Throttler): Promise<unknown> | undefined;
  67. /**
  68. * Read directory to add / remove files from `@watched` list and re-read it on change.
  69. * @param dir fs path
  70. * @param stats
  71. * @param initialAdd
  72. * @param depth relative to user-supplied path
  73. * @param target child path targeted for watch
  74. * @param wh Common watch helpers for this path
  75. * @param realpath
  76. * @returns closer for the watcher instance.
  77. */
  78. _handleDir(dir: string, stats: Stats, initialAdd: boolean, depth: number, target: string, wh: WatchHelper, realpath: string): Promise<(() => void) | undefined>;
  79. /**
  80. * Handle added file, directory, or glob pattern.
  81. * Delegates call to _handleFile / _handleDir after checks.
  82. * @param path to file or ir
  83. * @param initialAdd was the file added at watch instantiation?
  84. * @param priorWh depth relative to user-supplied path
  85. * @param depth Child path actually targeted for watch
  86. * @param target Child path actually targeted for watch
  87. */
  88. _addToNodeFs(path: string, initialAdd: boolean, priorWh: WatchHelper | undefined, depth: number, target?: string): Promise<string | false | undefined>;
  89. }
  90. //# sourceMappingURL=handler.d.ts.map