index.d.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. declare type FilePath = string;
  2. declare type GlobPattern = string;
  3. declare namespace ParcelWatcher {
  4. export type BackendType =
  5. | 'fs-events'
  6. | 'watchman'
  7. | 'inotify'
  8. | 'windows'
  9. | 'brute-force';
  10. export type EventType = 'create' | 'update' | 'delete';
  11. export interface Options {
  12. ignore?: (FilePath|GlobPattern)[];
  13. backend?: BackendType;
  14. }
  15. export type SubscribeCallback = (
  16. err: Error | null,
  17. events: Event[]
  18. ) => unknown;
  19. export interface AsyncSubscription {
  20. unsubscribe(): Promise<void>;
  21. }
  22. export interface Event {
  23. path: FilePath;
  24. type: EventType;
  25. }
  26. export function getEventsSince(
  27. dir: FilePath,
  28. snapshot: FilePath,
  29. opts?: Options
  30. ): Promise<Event[]>;
  31. export function subscribe(
  32. dir: FilePath,
  33. fn: SubscribeCallback,
  34. opts?: Options
  35. ): Promise<AsyncSubscription>;
  36. export function unsubscribe(
  37. dir: FilePath,
  38. fn: SubscribeCallback,
  39. opts?: Options
  40. ): Promise<void>;
  41. export function writeSnapshot(
  42. dir: FilePath,
  43. snapshot: FilePath,
  44. opts?: Options
  45. ): Promise<FilePath>;
  46. }
  47. export = ParcelWatcher;