WXL
3 天以前 2cc85c64f1c64a2dbaeae276a3e2ca8420de76b7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
export = DirectoryWatcher;
/** @typedef {Set<string>} InitialScanRemoved */
/**
 * @typedef {object} WatchpackEvents
 * @property {(target: string, mtime: string, type: EventType, initial: boolean) => void} change change event
 * @property {() => void} closed closed event
 */
/**
 * @typedef {object} DirectoryWatcherOptions
 * @property {boolean=} followSymlinks true when need to resolve symlinks and watch symlink and real file, otherwise false
 * @property {IgnoredFunction=} ignored ignore some files from watching (glob pattern or regexp)
 * @property {number | boolean=} poll true when need to enable polling mode for watching, otherwise false
 */
/**
 * @extends {EventEmitter<{ [K in keyof WatchpackEvents]: Parameters<WatchpackEvents[K]> }>}
 */
declare class DirectoryWatcher extends EventEmitter<{
    /**
     * change event
     */
    change: [
        target: string,
        mtime: string,
        type: import("./index").EventType,
        initial: boolean,
    ];
    /**
     * closed event
     */
    closed: [];
}> {
    /**
     * @param {WatcherManager} watcherManager a watcher manager
     * @param {string} directoryPath directory path
     * @param {DirectoryWatcherOptions=} options options
     */
    constructor(
        watcherManager: WatcherManager,
        directoryPath: string,
        options?: DirectoryWatcherOptions | undefined,
    );
    watcherManager: import("./getWatcherManager").WatcherManager;
    options: DirectoryWatcherOptions;
    path: string;
    /** @type {Map<string, Entry>} */
    files: Map<string, Entry>;
    /** @type {Map<string, number>} */
    filesWithoutCase: Map<string, number>;
    /** @type {Map<string, Watcher<DirectoryWatcherEvents> | boolean>} */
    directories: Map<string, Watcher<DirectoryWatcherEvents> | boolean>;
    lastWatchEvent: number;
    initialScan: boolean;
    ignored: import("./index").IgnoredFunction;
    nestedWatching: boolean;
    /** @type {number | false} */
    polledWatching: number | false;
    /** @type {undefined | NodeJS.Timeout} */
    timeout: undefined | NodeJS.Timeout;
    /** @type {null | InitialScanRemoved} */
    initialScanRemoved: null | InitialScanRemoved;
    /** @type {undefined | number} */
    initialScanFinished: undefined | number;
    /** @type {Map<string, Set<Watcher<DirectoryWatcherEvents> | Watcher<FileWatcherEvents>>>} */
    watchers: Map<
        string,
        Set<Watcher<DirectoryWatcherEvents> | Watcher<FileWatcherEvents>>
    >;
    /** @type {Watcher<FileWatcherEvents> | null} */
    parentWatcher: Watcher<FileWatcherEvents> | null;
    refs: number;
    /** @type {Map<string, boolean>} */
    _activeEvents: Map<string, boolean>;
    closed: boolean;
    scanning: boolean;
    scanAgain: boolean;
    scanAgainInitial: boolean;
    createWatcher(): void;
    watcher: watchEventSource.Watcher | null | undefined;
    /**
     * @template {(watcher: Watcher<EventMap>) => void} T
     * @param {string} path path
     * @param {T} fn function
     */
    forEachWatcher<T extends (watcher: Watcher<EventMap>) => void>(
        path: string,
        fn: T,
    ): void;
    /**
     * @param {string} itemPath an item path
     * @param {boolean} initial true when initial, otherwise false
     * @param {EventType} type even type
     */
    setMissing(itemPath: string, initial: boolean, type: EventType): void;
    /**
     * @param {string} target a target to set file time
     * @param {number} mtime mtime
     * @param {boolean} initial true when initial, otherwise false
     * @param {boolean} ignoreWhenEqual true to ignore when equal, otherwise false
     * @param {EventType} type type
     */
    setFileTime(
        target: string,
        mtime: number,
        initial: boolean,
        ignoreWhenEqual: boolean,
        type: EventType,
    ): void;
    /**
     * @param {string} directoryPath directory path
     * @param {number} birthtime birthtime
     * @param {boolean} initial true when initial, otherwise false
     * @param {EventType} type even type
     */
    setDirectory(
        directoryPath: string,
        birthtime: number,
        initial: boolean,
        type: EventType,
    ): void;
    /**
     * @param {string} directoryPath directory path
     */
    createNestedWatcher(directoryPath: string): void;
    /**
     * @param {boolean} flag true when nested, otherwise false
     */
    setNestedWatching(flag: boolean): void;
    /**
     * @param {string} target a target to watch
     * @param {number=} startTime start time
     * @returns {Watcher<DirectoryWatcherEvents> | Watcher<FileWatcherEvents>} watcher
     */
    watch(
        target: string,
        startTime?: number | undefined,
    ): Watcher<DirectoryWatcherEvents> | Watcher<FileWatcherEvents>;
    /**
     * @param {EventType} eventType event type
     * @param {string=} filename filename
     */
    onWatchEvent(eventType: EventType, filename?: string | undefined): void;
    /**
     * @param {unknown=} err error
     */
    onWatcherError(err?: unknown | undefined): void;
    /**
     * @param {Error | NodeJS.ErrnoException=} err error
     */
    onStatsError(err?: (Error | NodeJS.ErrnoException) | undefined): void;
    /**
     * @param {Error | NodeJS.ErrnoException=} err error
     */
    onScanError(err?: (Error | NodeJS.ErrnoException) | undefined): void;
    onScanFinished(): void;
    /**
     * @param {string} reason a reason
     */
    onDirectoryRemoved(reason: string): void;
    watchInParentDirectory(): void;
    /**
     * @param {boolean} initial true when initial, otherwise false
     */
    doScan(initial: boolean): void;
    /**
     * @returns {Record<string, number>} times
     */
    getTimes(): Record<string, number>;
    /**
     * @param {TimeInfoEntries} fileTimestamps file timestamps
     * @param {TimeInfoEntries} directoryTimestamps directory timestamps
     * @returns {number} safe time
     */
    collectTimeInfoEntries(
        fileTimestamps: TimeInfoEntries,
        directoryTimestamps: TimeInfoEntries,
    ): number;
    close(): void;
}
declare namespace DirectoryWatcher {
    export {
        EXISTANCE_ONLY_TIME_ENTRY,
        Watcher,
        IgnoredFunction,
        EventType,
        TimeInfoEntries,
        Entry,
        ExistenceOnlyTimeEntry,
        OnlySafeTimeEntry,
        EventMap,
        WatcherManager,
        EventSourceWatcher,
        FileWatcherEvents,
        DirectoryWatcherEvents,
        InitialScanRemoved,
        WatchpackEvents,
        DirectoryWatcherOptions,
    };
}
import { EventEmitter } from "events";
/**
 * @typedef {object} FileWatcherEvents
 * @property {(type: EventType) => void} initial-missing initial missing event
 * @property {(mtime: number, type: EventType, initial: boolean) => void} change change event
 * @property {(type: EventType) => void} remove remove event
 * @property {() => void} closed closed event
 */
/**
 * @typedef {object} DirectoryWatcherEvents
 * @property {(type: EventType) => void} initial-missing initial missing event
 * @property {((file: string, mtime: number, type: EventType, initial: boolean) => void)} change change event
 * @property {(type: EventType) => void} remove remove event
 * @property {() => void} closed closed event
 */
/**
 * @template {EventMap} T
 * @extends {EventEmitter<{ [K in keyof T]: Parameters<T[K]> }>}
 */
declare class Watcher<T extends EventMap> extends EventEmitter<{
    [K in keyof T]: Parameters<T[K]>;
}> {
    /**
     * @param {DirectoryWatcher} directoryWatcher a directory watcher
     * @param {string} target a target to watch
     * @param {number=} startTime start time
     */
    constructor(
        directoryWatcher: DirectoryWatcher,
        target: string,
        startTime?: number | undefined,
    );
    directoryWatcher: DirectoryWatcher;
    path: string;
    startTime: number | undefined;
    /**
     * @param {number} mtime mtime
     * @param {boolean} initial true when initial, otherwise false
     * @returns {boolean} true of start time less than mtile, otherwise false
     */
    checkStartTime(mtime: number, initial: boolean): boolean;
    close(): void;
}
import watchEventSource = require("./watchEventSource");
/** @typedef {import("./index").IgnoredFunction} IgnoredFunction */
/** @typedef {import("./index").EventType} EventType */
/** @typedef {import("./index").TimeInfoEntries} TimeInfoEntries */
/** @typedef {import("./index").Entry} Entry */
/** @typedef {import("./index").ExistenceOnlyTimeEntry} ExistenceOnlyTimeEntry */
/** @typedef {import("./index").OnlySafeTimeEntry} OnlySafeTimeEntry */
/** @typedef {import("./index").EventMap} EventMap */
/** @typedef {import("./getWatcherManager").WatcherManager} WatcherManager */
/** @typedef {import("./watchEventSource").Watcher} EventSourceWatcher */
/** @type {ExistenceOnlyTimeEntry} */
declare const EXISTANCE_ONLY_TIME_ENTRY: ExistenceOnlyTimeEntry;
type IgnoredFunction = import("./index").IgnoredFunction;
type EventType = import("./index").EventType;
type TimeInfoEntries = import("./index").TimeInfoEntries;
type Entry = import("./index").Entry;
type ExistenceOnlyTimeEntry = import("./index").ExistenceOnlyTimeEntry;
type OnlySafeTimeEntry = import("./index").OnlySafeTimeEntry;
type EventMap = import("./index").EventMap;
type WatcherManager = import("./getWatcherManager").WatcherManager;
type EventSourceWatcher = import("./watchEventSource").Watcher;
type FileWatcherEvents = {
    /**
     * initial missing event
     */
    "initial-missing": (type: EventType) => void;
    /**
     * change event
     */
    change: (mtime: number, type: EventType, initial: boolean) => void;
    /**
     * remove event
     */
    remove: (type: EventType) => void;
    /**
     * closed event
     */
    closed: () => void;
};
type DirectoryWatcherEvents = {
    /**
     * initial missing event
     */
    "initial-missing": (type: EventType) => void;
    /**
     * change event
     */
    change: (
        file: string,
        mtime: number,
        type: EventType,
        initial: boolean,
    ) => void;
    /**
     * remove event
     */
    remove: (type: EventType) => void;
    /**
     * closed event
     */
    closed: () => void;
};
type InitialScanRemoved = Set<string>;
type WatchpackEvents = {
    /**
     * change event
     */
    change: (
        target: string,
        mtime: string,
        type: EventType,
        initial: boolean,
    ) => void;
    /**
     * closed event
     */
    closed: () => void;
};
type DirectoryWatcherOptions = {
    /**
     * true when need to resolve symlinks and watch symlink and real file, otherwise false
     */
    followSymlinks?: boolean | undefined;
    /**
     * ignore some files from watching (glob pattern or regexp)
     */
    ignored?: IgnoredFunction | undefined;
    /**
     * true when need to enable polling mode for watching, otherwise false
     */
    poll?: (number | boolean) | undefined;
};