@ohos-ports/rsbuild-core 2.2.13-beta.0 → 2.3.3-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +7 -9
  2. package/compiled/@rstackjs/load-config/index.d.ts +10 -1
  3. package/compiled/@rstackjs/load-config/package.json +1 -1
  4. package/compiled/chokidar/index.d.ts +448 -161
  5. package/compiled/chokidar/package.json +1 -1
  6. package/compiled/css-loader/index.js +2 -2
  7. package/compiled/html-rspack-plugin/index.js +14 -14
  8. package/compiled/http-proxy-middleware/index.d.ts +10 -10
  9. package/compiled/http-proxy-middleware/package.json +1 -1
  10. package/compiled/jiti/dist/babel.cjs +1 -1
  11. package/compiled/postcss/index.js +1 -1
  12. package/compiled/postcss/lib/declaration.d.ts +2 -2
  13. package/compiled/postcss/package.json +1 -1
  14. package/compiled/postcss-loader/index.js +6 -6
  15. package/compiled/rspack-chain/package.json +1 -1
  16. package/compiled/rspack-chain/types/index.d.ts +1 -0
  17. package/dist/1.js +1 -0
  18. package/dist/chokidar.js +1 -1
  19. package/dist/client/hmr.js +26 -8
  20. package/dist/client/overlay.js +6 -5
  21. package/dist/defaultConfig.d.ts +7 -2
  22. package/dist/helpers/compilation.d.ts +2 -0
  23. package/dist/helpers/stats.d.ts +1 -0
  24. package/dist/helpers/workspace.d.ts +1 -0
  25. package/dist/hooks.d.ts +2 -1
  26. package/dist/http-proxy-middleware.js +4 -4
  27. package/dist/index.d.ts +1 -1
  28. package/dist/m.js +1515 -1387
  29. package/dist/m.js.LICENSE.txt +0 -13
  30. package/dist/manifest-plugin.js +1 -1
  31. package/dist/memfs.js +1 -1
  32. package/dist/open.js +2 -2
  33. package/dist/server/assets-middleware/getFileFromUrl.d.ts +3 -1
  34. package/dist/server/assets-middleware/index.d.ts +2 -1
  35. package/dist/server/assets-middleware/middleware.d.ts +4 -6
  36. package/dist/server/assets-middleware/setupMemoryFileSystemCleanup.d.ts +3 -0
  37. package/dist/server/devMiddlewares.d.ts +1 -1
  38. package/dist/server/helper.d.ts +5 -2
  39. package/dist/server/socketServer.d.ts +18 -2
  40. package/dist/server/watchFiles.d.ts +3 -1
  41. package/dist/sirv.js +3 -2
  42. package/dist/transformLoader.mjs +10 -10
  43. package/dist/transformRawLoader.mjs +2 -2
  44. package/dist/types/config.d.ts +17 -4
  45. package/dist/types/hooks.d.ts +1 -0
  46. package/dist/types/plugin.d.ts +26 -4
  47. package/dist/types/rsbuild.d.ts +1 -1
  48. package/dist/workerLoader.mjs +3 -3
  49. package/dist/ws.js +2 -2
  50. package/package.json +5 -5
@@ -1,5 +1,5 @@
1
1
  import { EventEmitter } from 'node:events';
2
- import { Dirent, Stats, WatchEventType } from 'node:fs';
2
+ import { Stats, Dirent, WatchEventType } from 'node:fs';
3
3
  import { Readable } from 'node:stream';
4
4
 
5
5
  /**
@@ -60,13 +60,24 @@ type ReaddirpOptions = {
60
60
  };
61
61
  /** Directory entry. Contains path, depth count, and files. */
62
62
  interface DirEntry$1 {
63
- files: PathOrDirent[];
63
+ /** Undefined when the directory could not be read (a 'warn' was emitted). */
64
+ files: PathOrDirent[] | undefined;
64
65
  depth: number;
65
66
  path: Path$1;
66
67
  }
67
68
  /** Readable readdir stream, emitting new files as they're being listed. */
69
+ interface PendingDir {
70
+ path: Path$1;
71
+ depth: number;
72
+ pending?: Promise<DirEntry$1>;
73
+ }
68
74
  declare class ReaddirpStream extends Readable {
69
- parents: any[];
75
+ /**
76
+ * Directories discovered but not yet emitted from. Listings are read
77
+ * lazily (on pop, plus one prefetch) instead of eagerly on discovery:
78
+ * keeping whole listings for every queued dir balloons RAM on wide trees.
79
+ */
80
+ parents: PendingDir[];
70
81
  reading: boolean;
71
82
  parent?: DirEntry$1;
72
83
  _stat: Function;
@@ -83,20 +94,40 @@ declare class ReaddirpStream extends Readable {
83
94
  };
84
95
  _fileFilter: Tester;
85
96
  _directoryFilter: Tester;
97
+ _relStart: number;
86
98
  constructor(options?: Partial<ReaddirpOptions>);
87
99
  _read(batch: number): Promise<void>;
88
- _exploreDir(path: Path$1, depth: number): Promise<{
89
- files: string[] | undefined;
90
- depth: number;
91
- path: string;
92
- }>;
93
- _formatEntry(dirent: PathOrDirent, path: Path$1): Promise<EntryInfo | undefined>;
100
+ _exploreDir(path: Path$1, depth: number): Promise<DirEntry$1>;
101
+ _formatEntry(dirent: PathOrDirent, path: Path$1): EntryInfo | undefined | Promise<EntryInfo | undefined>;
94
102
  _onError(err: Error): void;
95
- _getEntryType(entry: EntryInfo): Promise<void | '' | 'file' | 'directory'>;
103
+ _getEntryType(entry: EntryInfo): '' | 'file' | 'directory' | Promise<'' | 'file' | 'directory'>;
104
+ _getSymlinkEntryType(entry: EntryInfo): Promise<'' | 'file' | 'directory'>;
96
105
  _includeAsFile(entry: EntryInfo): boolean | undefined;
97
106
  }
98
107
 
108
+ type BackendCapabilities = Readonly<{
109
+ kind: BackendStrategy;
110
+ polling: boolean;
111
+ recursive: boolean;
112
+ perDirectory: boolean;
113
+ }>;
114
+
115
+ interface SchedulerTimer {
116
+ ref(): SchedulerTimer;
117
+ unref(): SchedulerTimer;
118
+ }
119
+ interface Scheduler {
120
+ now(): number;
121
+ setTimeout(callback: () => void, delay: number): SchedulerTimer;
122
+ clearTimeout(timer: SchedulerTimer | undefined): void;
123
+ }
99
124
  type Path = string;
125
+ type LogicalPathKey = string & {
126
+ readonly __logicalPathKey: unique symbol;
127
+ };
128
+ type BackendResourceKey = string & {
129
+ readonly __backendResourceKey: unique symbol;
130
+ };
100
131
  declare const EVENTS: {
101
132
  readonly ALL: "all";
102
133
  readonly READY: "ready";
@@ -109,30 +140,320 @@ declare const EVENTS: {
109
140
  readonly ERROR: "error";
110
141
  };
111
142
  type EventName = (typeof EVENTS)[keyof typeof EVENTS];
143
+ type NativeTrigger = {
144
+ kind: 'native';
145
+ resource: BackendResourceKey;
146
+ rawEvent: WatchEventType;
147
+ relativePath: string | null;
148
+ sequence: number;
149
+ observedAt: number;
150
+ };
151
+ type MissingPollObservation = {
152
+ missing: true;
153
+ };
154
+ type PollObservation = Stats | MissingPollObservation;
155
+ type PollTrigger = {
156
+ kind: 'poll';
157
+ resource: BackendResourceKey;
158
+ current: PollObservation;
159
+ previous?: PollObservation;
160
+ sequence: number;
161
+ observedAt: number;
162
+ };
163
+ type BackendTrigger = NativeTrigger | PollTrigger;
112
164
  interface WatchHandlers {
113
- listener: (path: string) => void;
114
165
  errHandler: (err: unknown) => void;
115
- rawEmitter: (ev: WatchEventType, path: string, opts: unknown) => void;
166
+ rawEmitter: (ev: WatchEventType, path: string | null, opts: unknown) => void;
116
167
  }
168
+ type AWF = {
169
+ stabilityThreshold: number;
170
+ pollInterval: number;
171
+ };
172
+ type WatchBackend = 'auto' | 'native' | 'native-recursive' | 'polling';
173
+ type BackendStrategy = 'polling' | 'native-per-directory' | 'native-recursive-preferred';
174
+ type MatcherObject = {
175
+ path: string;
176
+ recursive?: boolean;
177
+ };
178
+ type MatchFunction = (val: string, stats?: Stats) => boolean;
179
+ type Matcher = string | RegExp | MatchFunction | MatcherObject;
180
+ type BasicOptions = {
181
+ persistent: boolean;
182
+ ignoreInitial: boolean;
183
+ followSymlinks: boolean;
184
+ cwd?: string;
185
+ backend: WatchBackend;
186
+ /** @deprecated Use `backend: 'polling'` instead. */
187
+ usePolling: boolean;
188
+ pollingInterval: number;
189
+ pollingBinaryInterval: number;
190
+ /** @deprecated Use `pollingInterval` instead. */
191
+ interval: number;
192
+ /** @deprecated Use `pollingBinaryInterval` instead. */
193
+ binaryInterval: number;
194
+ alwaysStat?: boolean;
195
+ depth?: number;
196
+ ignorePermissionErrors: boolean;
197
+ atomic: boolean | number;
198
+ };
199
+ type ChokidarOptions = Partial<BasicOptions & {
200
+ ignored: Matcher | Matcher[];
201
+ awaitWriteFinish: boolean | Partial<AWF>;
202
+ }>;
203
+ type FSWInstanceOptions = BasicOptions & {
204
+ ignored: readonly Matcher[];
205
+ awaitWriteFinish: false | AWF;
206
+ backendStrategy: BackendStrategy;
207
+ backendCapabilities: BackendCapabilities;
208
+ };
209
+ type ThrottleType = 'readdir' | 'watch' | 'add' | 'remove' | 'change';
210
+ type Throttler = {
211
+ timeoutObject: SchedulerTimer;
212
+ clear: (invokeRelease?: boolean) => number;
213
+ count: number;
214
+ };
215
+ type EmitArgs = [path: Path, stats?: Stats];
216
+ type EmitErrorArgs = [error: Error, stats?: Stats];
217
+ type EmitArgsWithName = [event: EventName, ...EmitArgs];
218
+ type WatchHelperContext = {
219
+ capturePathGeneration: () => number;
220
+ isntIgnored: (path: Path, stats?: EntryInfo['stats']) => boolean;
221
+ };
222
+ /** Temporary traversal scope; replaced by the observation engine's root scope. */
223
+ declare class WatchHelper {
224
+ watchPath: string;
225
+ followSymlinks: boolean;
226
+ recursiveRoot?: string;
227
+ recursiveDisabled?: boolean;
228
+ observationTrigger?: NativeTrigger;
229
+ realpathAncestry: Set<string>;
230
+ pathGeneration: number;
231
+ private readonly context;
232
+ constructor(path: string, follow: boolean, context: WatchHelperContext);
233
+ fork(path: string): WatchHelper;
234
+ withObservation(trigger: NativeTrigger): WatchHelper;
235
+ filterPath(entry: EntryInfo): boolean;
236
+ filterDir(entry: EntryInfo): boolean;
237
+ }
238
+
239
+ type LifecycleState = 'OPEN' | 'CLOSING' | 'CLOSED';
240
+ type Closer = () => void | Promise<void>;
241
+ /**
242
+ * Owns every asynchronous task and backend subscription created by one public
243
+ * watcher. It deliberately knows nothing about paths, events, or backends.
244
+ */
245
+ declare class LifecycleScope {
246
+ state: LifecycleState;
247
+ generation: number;
248
+ readonly abortController: AbortController;
249
+ readonly tasks: Set<Promise<unknown>>;
250
+ readonly closers: Map<string, Closer[]>;
251
+ private readonly onTaskSettled;
252
+ private readonly onTaskError;
253
+ constructor(onTaskSettled: () => void, onTaskError: (error: unknown) => void);
254
+ isActive(generation: number): boolean;
255
+ track<T>(task: Promise<T>): Promise<T>;
256
+ addCloser(key: string, closer: Closer): void;
257
+ takeClosers(key: string): Closer[];
258
+ beginClose(): Promise<void>[];
259
+ drain(): Promise<void>;
260
+ finishClose(): void;
261
+ }
262
+ type PendingReconciliation = {
263
+ promise: Promise<void>;
264
+ work: () => Promise<void>;
265
+ replay: boolean;
266
+ };
267
+ /** Serializes commits per root and coalesces redundant candidate invalidations. */
268
+ declare class ReconciliationQueue {
269
+ readonly queues: Map<string, Promise<void>>;
270
+ readonly pending: Map<string, PendingReconciliation>;
271
+ private readonly lifecycle;
272
+ constructor(lifecycle: LifecycleScope);
273
+ enqueue(scope: Path, work: () => Promise<void>, coalescePath?: Path | false): Promise<void>;
274
+ forgetPending(predicate: (scope: string, candidate: string) => boolean): void;
275
+ clear(): void;
276
+ }
277
+ type ObservedPathFact = {
278
+ size: number;
279
+ mtimeMs: number;
280
+ ino: number;
281
+ kind: 'file' | 'directory' | 'symlink' | 'other';
282
+ transition?: 'add' | 'change';
283
+ rawEvent?: NativeTrigger['rawEvent'];
284
+ relativePath?: string | null;
285
+ observedAt?: number;
286
+ initialRecursive?: boolean;
287
+ };
288
+ /** A directory membership snapshot owned by one public watcher. */
289
+ declare class DirEntry {
290
+ path: Path;
291
+ private readonly items;
292
+ constructor(dir: Path);
293
+ add(item: string): void;
294
+ /** Returns true when removing `item` left the directory empty. */
295
+ remove(item: string): boolean;
296
+ has(item: string): boolean;
297
+ getChildren(): string[];
298
+ dispose(): void;
299
+ }
300
+ /**
301
+ * Per-watcher filesystem truth. Backends never mutate this object directly;
302
+ * scanner and reconciliation stages commit observations through it.
303
+ */
304
+ declare class TreeState {
305
+ readonly watched: Map<string, DirEntry>;
306
+ readonly observed: Map<string, ObservedPathFact>;
307
+ readonly symlinkPaths: Map<Path, string | boolean>;
308
+ readonly recursiveRoots: Set<string>;
309
+ private readonly observesNative;
310
+ constructor(observesNative: () => boolean);
311
+ getDirectory(directory: string): DirEntry;
312
+ /** Looks up a directory entry without creating one. */
313
+ peekDirectory(directory: string): DirEntry | undefined;
314
+ recordObserved(path: Path, stats: Stats, transition?: ObservedPathFact['transition'], trigger?: NativeTrigger, initialRecursive?: boolean, retainWithoutTrigger?: boolean): void;
315
+ consumeInitialCreate(path: Path, stats: Stats, trigger: NativeTrigger, ignoreInitial: boolean): EventName | false | undefined;
316
+ markInitialCreate(path: Path): void;
317
+ clearInitialCreate(path: Path): void;
318
+ clearInitialCreates(root: Path): void;
319
+ /** True when a tracked directory path now names a different directory inode. */
320
+ replacedSinceObserved(path: Path, stats: Stats): boolean;
321
+ /** True when `stats` no longer matches a recorded fact of the same kind. */
322
+ changedSinceObserved(path: Path, stats: Stats): boolean;
323
+ isDuplicateObservation(path: Path, stats: Stats, trigger: NativeTrigger): boolean;
324
+ dispose(): void;
325
+ }
326
+ type PathCloser = () => void | Promise<void>;
117
327
  /**
118
- * @mixin
328
+ * The private port used by filesystem orchestration. It prevents a backend or
329
+ * scanner from depending on EventEmitter or the public FSWatcher API.
119
330
  */
120
- declare class NodeFsHandler {
121
- fsw: FSWatcher;
122
- _boundHandleError: (error: unknown) => void;
123
- constructor(fsW: FSWatcher);
331
+ interface WatcherContext {
332
+ readonly closed: boolean;
333
+ readonly options: FSWInstanceOptions;
334
+ readonly lifecycle: LifecycleScope;
335
+ readonly tree: TreeState;
336
+ readonly reconciliation: ReconciliationQueue;
337
+ readonly events: EventPolicy;
338
+ readonly scheduler: Scheduler;
339
+ readonly emitRaw: WatchHandlers['rawEmitter'];
340
+ addPathCloser(path: Path, closer: PathCloser): void;
341
+ capturePathGeneration(): number;
342
+ closePath(path: Path, recursive?: boolean): void;
343
+ emitEvent(event: EventName, path: Path, stats?: Stats): Promise<void>;
344
+ createHelper(path: Path): WatchHelper;
345
+ handleError(error: unknown): void;
346
+ isIgnored(path: Path, stats?: Stats): boolean;
347
+ isPathGenerationActive(path: Path, generation: number): boolean;
348
+ isUnwatched(path: Path): boolean;
349
+ createScanStream(root: Path, options?: Partial<ReaddirpOptions>): ReaddirpStream | undefined;
350
+ removePath(directory: string, item: string, isDirectory?: boolean): void;
351
+ rewatchMissingPath(path: Path): void;
352
+ }
353
+
354
+ type PendingWrite = {
355
+ lastChange: number;
356
+ cancelWait: () => EventName;
357
+ };
358
+ type PendingChangeEmission = {
359
+ path: Path;
360
+ stats?: Stats;
361
+ replay: boolean;
362
+ /** A held leading change that reported an empty file; `release` publishes it. */
363
+ held?: {
364
+ timer: SchedulerTimer;
365
+ release: () => void;
366
+ };
367
+ };
368
+ /** A file `add` held while its stats showed an empty file. */
369
+ type HeldAdd = {
370
+ path: Path;
371
+ stats?: Stats;
372
+ timer?: SchedulerTimer;
373
+ release: () => void;
374
+ };
375
+ type EventPolicyContext = {
376
+ options: FSWInstanceOptions;
377
+ scheduler: Scheduler;
378
+ lifecycle: LifecycleScope;
379
+ isClosed: () => boolean;
380
+ capturePathGeneration: () => number;
381
+ isPathGenerationActive: (path: Path, generation: number) => boolean;
382
+ isReady: () => boolean;
383
+ remove: (directory: string, item: string) => void;
384
+ handleError: (error: unknown) => void;
385
+ publish: (event: EventName, args: EmitArgs | EmitErrorArgs) => void;
386
+ };
387
+ /** Converts truthful tree transitions into the public, timing-aware event API. */
388
+ declare class EventPolicy {
389
+ readonly pendingWrites: Map<string, PendingWrite>;
390
+ readonly pendingUnlinks: Map<string, {
391
+ event: EmitArgsWithName;
392
+ timer: SchedulerTimer;
393
+ }>;
394
+ readonly pendingChanges: Map<string, PendingChangeEmission>;
395
+ readonly heldAdds: Map<string, HeldAdd>;
396
+ readonly throttled: Map<ThrottleType, Map<string, Throttler>>;
397
+ private readonly context;
398
+ constructor(context: EventPolicyContext);
399
+ private presentPath;
400
+ private dropHeldAdd;
401
+ private dropPendingChange;
402
+ private setTimeout;
403
+ emit(event: EventName, path: Path, stats?: Stats): Promise<void>;
404
+ throttle(actionType: ThrottleType, path: Path, timeout: number, onRelease?: (suppressedCount: number) => void): Throttler | false;
405
+ awaitWriteFinish(path: Path, threshold: number, event: EventName, awfEmit: (error?: Error, stats?: Stats) => void, logicalKey?: LogicalPathKey): void;
406
+ cancelPath(path: Path): void;
407
+ cancelWhere(contains: (path: string) => boolean): void;
408
+ close(): void;
409
+ }
410
+
411
+ type AddPathOutcome = 'complete' | 'watch-parent';
412
+ /** Reconcile exactly one candidate path; its siblings are never scanned. */
413
+ type ExactCandidate = {
414
+ onRootMissing?: () => void;
415
+ };
416
+ /** Collects what a recursive rescan saw so absent tracked entries can be removed. */
417
+ type RecursiveRescan = {
418
+ seen: Set<string>;
419
+ directories: string[];
420
+ complete: boolean;
421
+ };
422
+ /** The only scanner, subscriber, and filesystem transition engine. */
423
+ declare class ObservationEngine {
424
+ fsw: WatcherContext;
425
+ reportError: (error: unknown) => void;
426
+ constructor(fsW: WatcherContext);
124
427
  /**
125
- * Watch file for changes with fs_watchFile or fs_watch.
428
+ * Watch a path with the owned polling scheduler or fs.watch.
126
429
  * @param path to file or dir
127
430
  * @param listener on fs change
128
431
  * @returns closer for the watcher instance
129
432
  */
130
- _watchWithNodeFs(path: string, listener: (path: string, newStats?: any) => void | Promise<void>): (() => void) | undefined;
433
+ subscribePath(path: string, listener: (path: string, newStats: Stats | undefined, trigger: BackendTrigger) => void | Promise<void>, initialStats?: Stats, mapRelative?: boolean, queueScope?: string): (() => void | Promise<void>) | undefined;
434
+ /**
435
+ * Watch a followed file symlink through the target's parent directory.
436
+ * macOS also starts a one-shot exact-target fallback: FSEvents can omit the
437
+ * first directory callback immediately after a subscription is established.
438
+ */
439
+ subscribeMappedFile(logicalPath: string, targetPath: string, helper: WatchHelper, depth: number, useExactFallback?: boolean): (() => void | Promise<void>) | undefined;
440
+ private mappedFileSnapshot;
441
+ /**
442
+ * macOS can follow an exact symlink handle and miss the link's own removal.
443
+ * Check only link existence so target-directory activity stays invisible when
444
+ * followSymlinks is disabled.
445
+ */
446
+ watchSymlinkDeletion(path: string, force?: boolean): (() => void) | undefined;
447
+ /**
448
+ * Map one backend notification into a logical candidate and serialize its
449
+ * filesystem reconciliation in the owning watcher instance.
450
+ */
451
+ reconcileBackendTrigger(scope: string, mapRelative: boolean, trigger: BackendTrigger, reconcile: (candidate: string) => void | Promise<void>, isActive?: () => boolean, coalesce?: boolean, queueScope?: string): Promise<void>;
131
452
  /**
132
453
  * Watch a file and emit add event if warranted.
133
454
  * @returns closer for the watcher instance
134
455
  */
135
- _handleFile(file: Path, stats: Stats, initialAdd: boolean): (() => void) | undefined;
456
+ handleFile(file: Path, stats: Stats, initialAdd: boolean, watchResource?: boolean, trigger?: NativeTrigger, initialRecursive?: boolean, retainObservation?: boolean): (() => void | Promise<void>) | undefined;
136
457
  /**
137
458
  * Handle symlinks encountered while reading a dir.
138
459
  * @param entry returned by readdirp
@@ -141,8 +462,39 @@ declare class NodeFsHandler {
141
462
  * @param item basename of this item
142
463
  * @returns true if no more processing is needed for this entry.
143
464
  */
144
- _handleSymlink(entry: EntryInfo, directory: string, path: Path, item: string): Promise<boolean | undefined>;
145
- _handleRead(directory: string, initialAdd: boolean, wh: WatchHelper, target: Path | undefined, dir: Path, depth: number, throttler: Throttler): Promise<unknown> | undefined;
465
+ handleSymlink(entry: EntryInfo, directory: string, path: Path, item: string, initialAdd: boolean, wh?: WatchHelper): Promise<boolean | undefined>;
466
+ readDirectory(directory: string, initialAdd: boolean, wh: WatchHelper, target: Path | undefined, dir: Path, depth: number): Promise<void> | undefined;
467
+ private removeIfMissing;
468
+ /**
469
+ * Populate the logical directory tree beneath one native recursive watcher.
470
+ * Regular entries are consumed synchronously from readdirp's stat-bearing
471
+ * stream; only symlinks need the full per-path add machinery.
472
+ */
473
+ scanRecursiveTree(dir: string, initialAdd: boolean, wh: WatchHelper, baseDepth: number, rescan?: RecursiveRescan): Promise<void> | undefined;
474
+ /**
475
+ * Reconcile a whole recursive root after an invalidation that names no path
476
+ * (a backend buffer overflow) or a replay buffer overflow. A shallow root
477
+ * listing would miss every change below the first level.
478
+ */
479
+ rescanRecursiveTree(dir: string, wh: WatchHelper, baseDepth: number): Promise<void>;
480
+ isHelperActive(wh: WatchHelper, path?: string): boolean;
481
+ private candidateDepth;
482
+ private candidateIgnored;
483
+ private highestMissingPath;
484
+ reconcileNativeTrigger(root: string, rootHelper: WatchHelper, trigger: NativeTrigger, candidateOverride?: string, baseDepth?: number, exact?: ExactCandidate): Promise<void>;
485
+ /**
486
+ * Keep a Windows parent handle for a directly watched directory. Windows can
487
+ * silently retire the directory's own handle when an empty root is removed;
488
+ * its parent still receives the namespace transition and can reconcile it.
489
+ */
490
+ watchRootParent(dir: string, wh: WatchHelper): (() => void | Promise<void>) | undefined;
491
+ watchRecursiveDirectory(dir: string, initialAdd: boolean, depth: number, wh: WatchHelper): Promise<(() => void | Promise<void>) | false | undefined>;
492
+ /**
493
+ * A recursive root that falls back to per-directory handles already tracks
494
+ * every subdirectory, so the fallback scan sees none of them as new. Give
495
+ * each its own subscription; existing entries emit nothing.
496
+ */
497
+ private subscribeTrackedDirectories;
146
498
  /**
147
499
  * Read directory to add / remove files from `@watched` list and re-read it on change.
148
500
  * @param dir fs path
@@ -151,91 +503,24 @@ declare class NodeFsHandler {
151
503
  * @param depth relative to user-supplied path
152
504
  * @param target child path targeted for watch
153
505
  * @param wh Common watch helpers for this path
154
- * @param realpath
155
506
  * @returns closer for the watcher instance.
156
507
  */
157
- _handleDir(dir: string, stats: Stats, initialAdd: boolean, depth: number, target: string | undefined, wh: WatchHelper, realpath: string): Promise<(() => void) | undefined>;
508
+ handleDirectory(dir: string, stats: Stats, initialAdd: boolean, depth: number, target: string | undefined, wh: WatchHelper): Promise<(() => void | Promise<void>) | undefined>;
158
509
  /**
159
510
  * Handle added file, directory, or glob pattern.
160
- * Delegates call to _handleFile / _handleDir after checks.
511
+ * Delegates call to handleFile / handleDirectory after checks.
161
512
  * @param path to file or ir
162
513
  * @param initialAdd was the file added at watch instantiation?
163
514
  * @param priorWh depth relative to user-supplied path
164
515
  * @param depth Child path actually targeted for watch
165
516
  * @param target Child path actually targeted for watch
166
517
  */
167
- _addToNodeFs(path: string, initialAdd: boolean, priorWh: WatchHelper | undefined, depth: number, target?: string): Promise<string | false | undefined>;
518
+ addRoot(path: string, initialAdd: boolean, pathGeneration: number, target?: string): Promise<void>;
519
+ addPathOnce(path: string, initialAdd: boolean, priorWh: WatchHelper | undefined, depth: number, target?: string, pathGeneration?: number): Promise<AddPathOutcome>;
168
520
  }
169
521
 
170
522
  /*! chokidar - MIT License (c) 2012 Paul Miller (paulmillr.com) */
171
523
 
172
- type AWF = {
173
- stabilityThreshold: number;
174
- pollInterval: number;
175
- };
176
- type BasicOpts = {
177
- persistent: boolean;
178
- ignoreInitial: boolean;
179
- followSymlinks: boolean;
180
- cwd?: string;
181
- usePolling: boolean;
182
- interval: number;
183
- binaryInterval: number;
184
- alwaysStat?: boolean;
185
- depth?: number;
186
- ignorePermissionErrors: boolean;
187
- atomic: boolean | number;
188
- };
189
- type Throttler = {
190
- timeoutObject: NodeJS.Timeout;
191
- clear: () => void;
192
- count: number;
193
- };
194
- type ChokidarOptions = Partial<BasicOpts & {
195
- ignored: Matcher | Matcher[];
196
- awaitWriteFinish: boolean | Partial<AWF>;
197
- }>;
198
- type FSWInstanceOptions = BasicOpts & {
199
- ignored: Matcher[];
200
- awaitWriteFinish: false | AWF;
201
- };
202
- type ThrottleType = 'readdir' | 'watch' | 'add' | 'remove' | 'change';
203
- type EmitArgs = [path: Path, stats?: Stats];
204
- type EmitErrorArgs = [error: Error, stats?: Stats];
205
- type EmitArgsWithName = [event: EventName, ...EmitArgs];
206
- type MatchFunction = (val: string, stats?: Stats) => boolean;
207
- interface MatcherObject {
208
- path: string;
209
- recursive?: boolean;
210
- }
211
- type Matcher = string | RegExp | MatchFunction | MatcherObject;
212
- /**
213
- * Directory entry.
214
- */
215
- declare class DirEntry {
216
- path: Path;
217
- _removeWatcher: (dir: string, base: string) => void;
218
- items: Set<Path>;
219
- constructor(dir: Path, removeWatcher: (dir: string, base: string) => void);
220
- add(item: string): void;
221
- remove(item: string): Promise<void>;
222
- has(item: string): boolean | undefined;
223
- getChildren(): string[];
224
- dispose(): void;
225
- }
226
- declare class WatchHelper {
227
- fsw: FSWatcher;
228
- path: string;
229
- watchPath: string;
230
- fullWatchPath: string;
231
- dirParts: string[][];
232
- followSymlinks: boolean;
233
- statMethod: 'stat' | 'lstat';
234
- constructor(path: string, follow: boolean, fsw: FSWatcher);
235
- entryPath(entry: EntryInfo): Path;
236
- filterPath(entry: EntryInfo): boolean;
237
- filterDir(entry: EntryInfo): boolean;
238
- }
239
524
  interface FSWatcherEventMap {
240
525
  [EVENTS.READY]: [];
241
526
  [EVENTS.RAW]: Parameters<WatchHandlers['rawEmitter']>;
@@ -256,32 +541,40 @@ interface FSWatcherEventMap {
256
541
  * .on('add', path => log('File', path, 'was added'))
257
542
  */
258
543
  declare class FSWatcher extends EventEmitter<FSWatcherEventMap> {
259
- closed: boolean;
544
+ #private;
260
545
  options: FSWInstanceOptions;
261
- _closers: Map<string, Array<any>>;
262
- _ignoredPaths: Set<Matcher>;
263
- _throttled: Map<ThrottleType, Map<any, any>>;
264
- _streams: Set<ReaddirpStream>;
265
- _symlinkPaths: Map<Path, string | boolean>;
266
- _watched: Map<string, DirEntry>;
267
- _pendingWrites: Map<string, any>;
268
- _pendingUnlinks: Map<string, EmitArgsWithName>;
269
- _readyCount: number;
270
- _emitReady: () => void;
271
- _closePromise?: Promise<void>;
272
- _userIgnored?: MatchFunction;
273
- _readyEmitted: boolean;
274
- _emitRaw: WatchHandlers['rawEmitter'];
275
- _boundRemove: (dir: string, item: string) => void;
276
- _nodeFsHandler: NodeFsHandler;
277
- constructor(_opts?: ChokidarOptions);
278
- _addIgnoredPath(matcher: Matcher): void;
279
- _removeIgnoredPath(matcher: Matcher): void;
546
+ /** @internal */
547
+ readonly lifecycle: LifecycleScope;
548
+ /** @internal */
549
+ readonly tree: TreeState;
550
+ /** @internal */
551
+ readonly reconciliation: ReconciliationQueue;
552
+ /** @internal */
553
+ readonly events: EventPolicy;
554
+ /** @internal */
555
+ readonly scheduler: Scheduler;
556
+ /** @internal */
557
+ readonly handler: ObservationEngine;
558
+ /** @internal */
559
+ readyEmitted: boolean;
560
+ /** @internal */
561
+ readonly streams: Set<ReaddirpStream>;
562
+ get closed(): boolean;
563
+ constructor(_opts?: ChokidarOptions, scheduler?: Scheduler);
564
+ private addIgnoredPath;
565
+ private removeIgnoredPath;
566
+ private ignoredMatcher;
567
+ /** @internal */
568
+ capturePathGeneration(): number;
569
+ private invalidatePath;
570
+ /** @internal */
571
+ isPathGenerationActive(path: Path, generation: number): boolean;
572
+ private queueReady;
280
573
  /**
281
574
  * Adds paths to be watched on an existing FSWatcher instance.
282
- * @param paths_ file or file list. Other arguments are unused
575
+ * @param paths_ file or file list
283
576
  */
284
- add(paths_: Path | Path[], _origAdd?: string, _internal?: boolean): FSWatcher;
577
+ add(paths_: Path | Path[]): FSWatcher;
285
578
  /**
286
579
  * Close watchers or start ignoring events from specified paths.
287
580
  */
@@ -291,80 +584,74 @@ declare class FSWatcher extends EventEmitter<FSWatcherEventMap> {
291
584
  */
292
585
  close(): Promise<void>;
293
586
  /**
294
- * Expose list of watched paths
295
- * @returns for chaining
587
+ * Expose list of watched paths. The result has a null prototype, so a
588
+ * directory named `__proto__` is an ordinary own key.
296
589
  */
297
590
  getWatched(): Record<string, string[]>;
298
- emitWithAll(event: EventName, args: EmitArgs): void;
591
+ /** @internal */
592
+ emitRaw(...args: Parameters<WatchHandlers['rawEmitter']>): void;
593
+ private emitWithAll;
299
594
  /**
300
595
  * Normalize and emit events.
301
- * Calling _emit DOES NOT MEAN emit() would be called!
596
+ * Calling emitEvent DOES NOT MEAN emit() would be called!
302
597
  * @param event Type of event
303
598
  * @param path File or directory path
304
599
  * @param stats arguments to be passed with event
305
- * @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
600
+ * @internal
306
601
  */
307
- _emit(event: EventName, path: Path, stats?: Stats): Promise<this | undefined>;
602
+ emitEvent(event: EventName, path: Path, stats?: Stats): Promise<void>;
308
603
  /**
309
- * Common handler for errors
310
- * @returns The error if defined, otherwise the value of the FSWatcher instance's `closed` flag
604
+ * Common handler for backend and reconciliation failures.
605
+ * @internal
311
606
  */
312
- _handleError(error: Error): Error | boolean;
313
- /**
314
- * Helper utility for throttling
315
- * @param actionType type being throttled
316
- * @param path being acted upon
317
- * @param timeout duration of time to suppress duplicate actions
318
- * @returns tracking object or false if action should be suppressed
319
- */
320
- _throttle(actionType: ThrottleType, path: Path, timeout: number): Throttler | false;
321
- _incrReadyCount(): number;
322
- /**
323
- * Awaits write operation to finish.
324
- * Polls a newly created file for size variations. When files size does not change for 'threshold' milliseconds calls callback.
325
- * @param path being acted upon
326
- * @param threshold Time in milliseconds a file size must be fixed before acknowledging write OP is finished
327
- * @param event
328
- * @param awfEmit Callback to be called when ready for event to be emitted.
329
- */
330
- _awaitWriteFinish(path: Path, threshold: number, event: EventName, awfEmit: (err?: Error, stat?: Stats) => void): void;
607
+ handleError(error: unknown): void;
331
608
  /**
332
609
  * Determines whether user has asked to ignore this path.
610
+ * @internal
333
611
  */
334
- _isIgnored(path: Path, stats?: Stats): boolean;
335
- _isntIgnored(path: Path, stat?: Stats): boolean;
612
+ isIgnored(path: Path, stats?: Stats): boolean;
613
+ private isRootAncestor;
614
+ /** Records every directory above a requested root; refcounted across roots. */
615
+ private addRootAncestors;
616
+ private removeRootAncestors;
617
+ private realDirectory;
618
+ /** @internal */
619
+ isUnwatched(path: Path): boolean;
336
620
  /**
337
621
  * Provides a set of common helpers and properties relating to symlink handling.
338
622
  * @param path file or directory pattern being watched
623
+ * @internal
339
624
  */
340
- _getWatchHelpers(path: Path): WatchHelper;
341
- /**
342
- * Provides directory tracking objects
343
- * @param directory path of the directory
344
- */
345
- _getWatchedDir(directory: string): DirEntry;
346
- /**
347
- * Check for read permissions: https://stackoverflow.com/a/11781404/1358405
348
- */
349
- _hasReadPermissions(stats: Stats): boolean;
625
+ createHelper(path: Path): WatchHelper;
626
+ private removeTreeItem;
350
627
  /**
351
628
  * Handles emitting unlink events for
352
629
  * files and directories, and via recursion, for
353
630
  * files and directories within directories that are unlinked
354
631
  * @param directory within which the following item is located
355
632
  * @param item base path of item/directory
633
+ * @internal
634
+ */
635
+ removePath(directory: string, item: string, isDirectory?: boolean): void;
636
+ /**
637
+ * Replaces every watch keyed at `path` with a wait from its nearest existing
638
+ * ancestor, so the path is reported again when it reappears.
639
+ * @internal
356
640
  */
357
- _remove(directory: string, item: string, isDirectory?: boolean): void;
641
+ rewatchMissingPath(path: Path): void;
358
642
  /**
359
643
  * Closes all watchers for a path
644
+ * @internal
360
645
  */
361
- _closePath(path: Path): void;
646
+ closePath(path: Path, recursive?: boolean): void;
362
647
  /**
363
648
  * Closes only file-specific watchers
364
649
  */
365
- _closeFile(path: Path): void;
366
- _addPathCloser(path: Path, closer: () => void): void;
367
- _readdirp(root: Path, opts?: Partial<ReaddirpOptions>): ReaddirpStream | undefined;
650
+ private closeFile;
651
+ /** @internal */
652
+ addPathCloser(path: Path, closer: () => void | Promise<void>): void;
653
+ /** @internal */
654
+ createScanStream(root: Path, opts?: Partial<ReaddirpOptions>): ReaddirpStream | undefined;
368
655
  }
369
656
  /**
370
657
  * Instantiates watcher with paths to be tracked.
@@ -381,5 +668,5 @@ declare const _default: {
381
668
  FSWatcher: typeof FSWatcher;
382
669
  };
383
670
 
384
- export { FSWatcher, WatchHelper, _default as default, watch };
385
- export type { AWF, ChokidarOptions, EmitArgs, EmitArgsWithName, EmitErrorArgs, FSWInstanceOptions, FSWatcherEventMap, MatchFunction, Matcher, MatcherObject, ThrottleType, Throttler };
671
+ export { FSWatcher, _default as default, watch };
672
+ export type { AWF, BackendStrategy, ChokidarOptions, EmitArgs, EmitArgsWithName, EmitErrorArgs, FSWInstanceOptions, FSWatcherEventMap, MatchFunction, Matcher, MatcherObject, Scheduler, SchedulerTimer, ThrottleType, Throttler, WatchBackend };