1 |
|
2 |
|
3 | import { EventEmitter } from "events";
|
4 | import Watcher = require("./Watcher");
|
5 |
|
6 | interface Entry {
|
7 |
|
8 | safeTime: number;
|
9 |
|
10 | timestamp: number;
|
11 | }
|
12 |
|
13 | declare class Watchpack extends EventEmitter {
|
14 | aggregatedChanges: Set<string>;
|
15 | aggregatedRemovals: Set<string>;
|
16 |
|
17 | aggregateTimeout: NodeJS.Timer;
|
18 | dirWatchers: Watcher[];
|
19 | fileWatchers: Watcher[];
|
20 |
|
21 | mtimes: {
|
22 | [path: string]: number;
|
23 | };
|
24 | options: Watchpack.WatchOptions;
|
25 | paused: boolean;
|
26 | watcherOptions: Watchpack.WatcherOptions;
|
27 |
|
28 | constructor(options: Watchpack.WatchOptions);
|
29 |
|
30 | /**
|
31 | * Starts watching these files and directories
|
32 | * Calling this again will override the files and directories
|
33 | */
|
34 | watch(options: {
|
35 | |
36 |
|
37 |
|
38 |
|
39 |
|
40 | files?: Iterable<string>;
|
41 | |
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 | directories?: Iterable<string>;
|
48 | |
49 |
|
50 |
|
51 |
|
52 |
|
53 | missing?: Iterable<string>;
|
54 | startTime?: number;
|
55 | }): void;
|
56 |
|
57 | on(
|
58 | eventName: "change",
|
59 | listener: (
|
60 | /** The changed file or directory */
|
61 | filePath: string,
|
62 | /** The last modified time of the changed file */
|
63 | modifiedTime: number,
|
64 | /** Textual information how this change was detected */
|
65 | explanation: string,
|
66 | ) => void,
|
67 | ): this;
|
68 |
|
69 | on(
|
70 | eventName: "remove",
|
71 | listener: (
|
72 | /** The removed file or directory */
|
73 | filePath: string,
|
74 | /** Textual information how this change was detected */
|
75 | explanation: string,
|
76 | ) => void,
|
77 | ): this;
|
78 |
|
79 | on(
|
80 | eventName: "aggregated",
|
81 | listener: (
|
82 | /** Set of all changed files */
|
83 | changes: Set<string>,
|
84 | /** Set of all removed files */
|
85 | removals: Set<string>,
|
86 | ) => void,
|
87 | ): this;
|
88 |
|
89 | /**
|
90 | * Stops emitting events, but keeps watchers open
|
91 | * The next "watch" call can reuse the watchers
|
92 | * The watcher will keep aggregating events which can be received with `getAggregated()`
|
93 | */
|
94 | pause(): void;
|
95 |
|
96 | /**
|
97 | * Stops emitting events and closes all watchers
|
98 | */
|
99 | close(): void;
|
100 |
|
101 | /**
|
102 | * Returns the current aggregated info and removes that from the watcher
|
103 | * The next aggregated event won't include that info and will only emitted when futher changes happen
|
104 | * Can be used when paused
|
105 | */
|
106 | getAggregated(): {
|
107 | changes: Set<string>;
|
108 | removals: Set<string>;
|
109 | };
|
110 |
|
111 | |
112 |
|
113 |
|
114 |
|
115 | collectTimeInfoEntries(fileInfoEntries: Map<string, Entry>, directoryInfoEntries: Map<string, Entry>): void;
|
116 |
|
117 | |
118 |
|
119 |
|
120 |
|
121 | getTimeInfoEntries(): Map<string, Entry>;
|
122 |
|
123 | |
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 | getTimes(): {
|
130 | [path: string]: number;
|
131 | };
|
132 |
|
133 | _fileWatcher(file: string, watcher: Watcher): Watcher;
|
134 |
|
135 | _dirWatcher(item: string, watcher: Watcher): Watcher;
|
136 |
|
137 | _onChange(item: string, mtime: number, file?: string): void;
|
138 |
|
139 | _onTimeout(): void;
|
140 | }
|
141 |
|
142 | declare namespace Watchpack {
|
143 | interface WatcherOptions {
|
144 | ignored?: string[] | string | RegExp | ((path: string) => boolean) | undefined;
|
145 | poll?: boolean | number | undefined;
|
146 | followSymlinks?: boolean;
|
147 | }
|
148 | interface WatchOptions extends WatcherOptions {
|
149 | aggregateTimeout?: number | undefined;
|
150 | }
|
151 | }
|
152 |
|
153 | export = Watchpack;
|
154 |
|
\ | No newline at end of file |