WXL
4 天以前 3bd962a6d7f61239c020e2dbbeb7341e5b842dd1
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
export = Watchpack;
/**
 * @typedef {object} WatchpackEvents
 * @property {(file: string, mtime: number, type: EventType) => void} change change event
 * @property {(file: string, type: EventType) => void} remove remove event
 * @property {(changes: Changes, removals: Removals) => void} aggregated aggregated event
 */
/**
 * @extends {EventEmitter<{ [K in keyof WatchpackEvents]: Parameters<WatchpackEvents[K]> }>}
 */
declare class Watchpack extends EventEmitter<{
    /**
     * change event
     */
    change: [file: string, mtime: number, type: EventType];
    /**
     * remove event
     */
    remove: [file: string, type: EventType];
    /**
     * aggregated event
     */
    aggregated: [changes: Changes, removals: Removals];
}> {
    /**
     * @param {WatchOptions=} options options
     */
    constructor(options?: WatchOptions | undefined);
    /** @type {WatchOptions} */
    options: WatchOptions;
    aggregateTimeout: number;
    /** @type {NormalizedWatchOptions} */
    watcherOptions: NormalizedWatchOptions;
    /** @type {WatcherManager} */
    watcherManager: WatcherManager;
    /** @type {Map<string, WatchpackFileWatcher>} */
    fileWatchers: Map<string, WatchpackFileWatcher>;
    /** @type {Map<string, WatchpackDirectoryWatcher>} */
    directoryWatchers: Map<string, WatchpackDirectoryWatcher>;
    /** @type {Set<string>} */
    _missing: Set<string>;
    startTime: number | undefined;
    paused: boolean;
    /** @type {Changes} */
    aggregatedChanges: Changes;
    /** @type {Removals} */
    aggregatedRemovals: Removals;
    /** @type {undefined | NodeJS.Timeout} */
    aggregateTimer: undefined | NodeJS.Timeout;
    _onTimeout(): void;
    /**
     * @overload
     * @param {Iterable<string>} arg1 files
     * @param {Iterable<string>} arg2 directories
     * @param {number=} arg3 startTime
     * @returns {void}
     */
    watch(
        arg1: Iterable<string>,
        arg2: Iterable<string>,
        arg3?: number | undefined,
    ): void;
    /**
     * @overload
     * @param {WatchMethodOptions} arg1 watch options
     * @returns {void}
     */
    watch(arg1: WatchMethodOptions): void;
    close(): void;
    pause(): void;
    /**
     * @returns {Record<string, number>} times
     */
    getTimes(): Record<string, number>;
    /**
     * @returns {TimeInfoEntries} time info entries
     */
    getTimeInfoEntries(): TimeInfoEntries;
    /**
     * @param {TimeInfoEntries} fileTimestamps file timestamps
     * @param {TimeInfoEntries} directoryTimestamps directory timestamps
     */
    collectTimeInfoEntries(
        fileTimestamps: TimeInfoEntries,
        directoryTimestamps: TimeInfoEntries,
    ): void;
    /**
     * @returns {Aggregated} aggregated info
     */
    getAggregated(): Aggregated;
    /**
     * @param {string} item item
     * @param {number} mtime mtime
     * @param {string} file file
     * @param {EventType} type type
     */
    _onChange(item: string, mtime: number, file: string, type: EventType): void;
    /**
     * @param {string} item item
     * @param {string} file file
     * @param {EventType} type type
     */
    _onRemove(item: string, file: string, type: EventType): void;
}
declare namespace Watchpack {
    export {
        WatcherManager,
        DirectoryWatcher,
        DirectoryWatcherEvents,
        FileWatcherEvents,
        EventMap,
        Watcher,
        IgnoredFunction,
        Ignored,
        WatcherOptions,
        WatchOptions,
        NormalizedWatchOptions,
        EventType,
        Entry,
        OnlySafeTimeEntry,
        ExistenceOnlyTimeEntry,
        TimeInfoEntries,
        Changes,
        Removals,
        Aggregated,
        WatchMethodOptions,
        Times,
        WatchpackEvents,
    };
}
import { EventEmitter } from "events";
declare class WatchpackFileWatcher {
    /**
     * @param {Watchpack} watchpack watchpack
     * @param {Watcher<FileWatcherEvents>} watcher watcher
     * @param {string | string[]} files files
     */
    constructor(
        watchpack: Watchpack,
        watcher: Watcher<FileWatcherEvents>,
        files: string | string[],
    );
    /** @type {string[]} */
    files: string[];
    watcher: import("./DirectoryWatcher").Watcher<
        import("./DirectoryWatcher").FileWatcherEvents
    >;
    /**
     * @param {string | string[]} files files
     */
    update(files: string | string[]): void;
    close(): void;
}
declare class WatchpackDirectoryWatcher {
    /**
     * @param {Watchpack} watchpack watchpack
     * @param {Watcher<DirectoryWatcherEvents>} watcher watcher
     * @param {string} directories directories
     */
    constructor(
        watchpack: Watchpack,
        watcher: Watcher<DirectoryWatcherEvents>,
        directories: string,
    );
    /** @type {string[]} */
    directories: string[];
    watcher: import("./DirectoryWatcher").Watcher<
        import("./DirectoryWatcher").DirectoryWatcherEvents
    >;
    /**
     * @param {string | string[]} directories directories
     */
    update(directories: string | string[]): void;
    close(): void;
}
type WatcherManager = import("./getWatcherManager").WatcherManager;
type DirectoryWatcher = import("./DirectoryWatcher");
type DirectoryWatcherEvents =
    import("./DirectoryWatcher").DirectoryWatcherEvents;
type FileWatcherEvents = import("./DirectoryWatcher").FileWatcherEvents;
type EventMap = Record<string, (...args: any[]) => any>;
type Watcher<T extends EventMap> = import("./DirectoryWatcher").Watcher<T>;
type IgnoredFunction = (item: string) => boolean;
type Ignored = string[] | RegExp | string | IgnoredFunction;
type WatcherOptions = {
    /**
     * 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?: Ignored | undefined;
    /**
     * true when need to enable polling mode for watching, otherwise false
     */
    poll?: (number | boolean) | undefined;
};
type WatchOptions = WatcherOptions & {
    aggregateTimeout?: number;
};
type NormalizedWatchOptions = {
    /**
     * true when need to resolve symlinks and watch symlink and real file, otherwise false
     */
    followSymlinks: boolean;
    /**
     * ignore some files from watching (glob pattern or regexp)
     */
    ignored: IgnoredFunction;
    /**
     * true when need to enable polling mode for watching, otherwise false
     */
    poll?: (number | boolean) | undefined;
};
type EventType =
    | `scan (${string})`
    | "change"
    | "rename"
    | `watch ${string}`
    | `directory-removed ${string}`;
type Entry = {
    safeTime: number;
    timestamp: number;
    accuracy: number;
};
type OnlySafeTimeEntry = {
    safeTime: number;
};
type ExistenceOnlyTimeEntry = {};
type TimeInfoEntries = Map<
    string,
    Entry | OnlySafeTimeEntry | ExistenceOnlyTimeEntry | null
>;
type Changes = Set<string>;
type Removals = Set<string>;
type Aggregated = {
    changes: Changes;
    removals: Removals;
};
type WatchMethodOptions = {
    files?: Iterable<string>;
    directories?: Iterable<string>;
    missing?: Iterable<string>;
    startTime?: number;
};
type Times = Record<string, number>;
type WatchpackEvents = {
    /**
     * change event
     */
    change: (file: string, mtime: number, type: EventType) => void;
    /**
     * remove event
     */
    remove: (file: string, type: EventType) => void;
    /**
     * aggregated event
     */
    aggregated: (changes: Changes, removals: Removals) => void;
};