@rsbuild/core 2.0.0-alpha.0 → 2.0.0-alpha.2

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.
@@ -0,0 +1,90 @@
1
+ import type { FSWatcher as NativeFsWatcher, Stats, WatchEventType } from 'node:fs';
2
+ import type { EntryInfo } from 'readdirp';
3
+ import type { FSWatcher, Throttler, WatchHelper } from './index.js';
4
+ export type Path = string;
5
+ export declare const STR_DATA = "data";
6
+ export declare const STR_END = "end";
7
+ export declare const STR_CLOSE = "close";
8
+ export declare const EMPTY_FN: () => void;
9
+ export declare const IDENTITY_FN: (val: unknown) => unknown;
10
+ export declare const isWindows: boolean;
11
+ export declare const isMacos: boolean;
12
+ export declare const isLinux: boolean;
13
+ export declare const isFreeBSD: boolean;
14
+ export declare const isIBMi: boolean;
15
+ export declare const EVENTS: {
16
+ readonly ALL: "all";
17
+ readonly READY: "ready";
18
+ readonly ADD: "add";
19
+ readonly CHANGE: "change";
20
+ readonly ADD_DIR: "addDir";
21
+ readonly UNLINK: "unlink";
22
+ readonly UNLINK_DIR: "unlinkDir";
23
+ readonly RAW: "raw";
24
+ readonly ERROR: "error";
25
+ };
26
+ export type EventName = (typeof EVENTS)[keyof typeof EVENTS];
27
+ export type FsWatchContainer = {
28
+ listeners: (path: string) => void | Set<any>;
29
+ errHandlers: (err: unknown) => void | Set<any>;
30
+ rawEmitters: (ev: WatchEventType, path: string, opts: unknown) => void | Set<any>;
31
+ watcher: NativeFsWatcher;
32
+ watcherUnusable?: boolean;
33
+ };
34
+ export interface WatchHandlers {
35
+ listener: (path: string) => void;
36
+ errHandler: (err: unknown) => void;
37
+ rawEmitter: (ev: WatchEventType, path: string, opts: unknown) => void;
38
+ }
39
+ /**
40
+ * @mixin
41
+ */
42
+ export declare class NodeFsHandler {
43
+ fsw: FSWatcher;
44
+ _boundHandleError: (error: unknown) => void;
45
+ constructor(fsW: FSWatcher);
46
+ /**
47
+ * Watch file for changes with fs_watchFile or fs_watch.
48
+ * @param path to file or dir
49
+ * @param listener on fs change
50
+ * @returns closer for the watcher instance
51
+ */
52
+ _watchWithNodeFs(path: string, listener: (path: string, newStats?: any) => void | Promise<void>): (() => void) | undefined;
53
+ /**
54
+ * Watch a file and emit add event if warranted.
55
+ * @returns closer for the watcher instance
56
+ */
57
+ _handleFile(file: Path, stats: Stats, initialAdd: boolean): (() => void) | undefined;
58
+ /**
59
+ * Handle symlinks encountered while reading a dir.
60
+ * @param entry returned by readdirp
61
+ * @param directory path of dir being read
62
+ * @param path of this item
63
+ * @param item basename of this item
64
+ * @returns true if no more processing is needed for this entry.
65
+ */
66
+ _handleSymlink(entry: EntryInfo, directory: string, path: Path, item: string): Promise<boolean | undefined>;
67
+ _handleRead(directory: string, initialAdd: boolean, wh: WatchHelper, target: Path | undefined, dir: Path, depth: number, throttler: Throttler): Promise<unknown> | undefined;
68
+ /**
69
+ * Read directory to add / remove files from `@watched` list and re-read it on change.
70
+ * @param dir fs path
71
+ * @param stats
72
+ * @param initialAdd
73
+ * @param depth relative to user-supplied path
74
+ * @param target child path targeted for watch
75
+ * @param wh Common watch helpers for this path
76
+ * @param realpath
77
+ * @returns closer for the watcher instance.
78
+ */
79
+ _handleDir(dir: string, stats: Stats, initialAdd: boolean, depth: number, target: string | undefined, wh: WatchHelper, realpath: string): Promise<(() => void) | undefined>;
80
+ /**
81
+ * Handle added file, directory, or glob pattern.
82
+ * Delegates call to _handleFile / _handleDir after checks.
83
+ * @param path to file or ir
84
+ * @param initialAdd was the file added at watch instantiation?
85
+ * @param priorWh depth relative to user-supplied path
86
+ * @param depth Child path actually targeted for watch
87
+ * @param target Child path actually targeted for watch
88
+ */
89
+ _addToNodeFs(path: string, initialAdd: boolean, priorWh: WatchHelper | undefined, depth: number, target?: string): Promise<string | false | undefined>;
90
+ }
@@ -1,176 +1,9 @@
1
- import { WatchEventType, Stats as Stats$1 } from 'fs';
2
- import { EventEmitter } from 'events';
3
- import { Dirent, Stats } from 'node:fs';
4
- import { Readable } from 'node:stream';
5
-
6
- /**
7
- * Recursive version of readdir. Exposes a streaming API and promise API.
8
- * Streaming API allows to use a small amount of RAM.
9
- *
10
- * @module
11
- * @example
12
- ```js
13
- import readdirp from 'readdirp';
14
- for await (const entry of readdirp('.')) {
15
- const {path} = entry;
16
- console.log(`${JSON.stringify({path})}`);
17
- }
18
- ```
19
- */
20
- /*! readdirp - MIT License (c) 2012-2019 Thorsten Lorenz, Paul Miller (https://paulmillr.com) */
21
-
22
- /** Path in file system. */
23
- type Path$1 = string;
24
- /** Emitted entry. Contains relative & absolute path, basename, and either stats or dirent. */
25
- interface EntryInfo {
26
- path: string;
27
- fullPath: string;
28
- stats?: Stats;
29
- dirent?: Dirent;
30
- basename: string;
31
- }
32
- /** Path or dir entries (files) */
33
- type PathOrDirent = Dirent | Path$1;
34
- /** Filterer for files */
35
- type Tester = (entryInfo: EntryInfo) => boolean;
36
- type Predicate = string[] | string | Tester;
37
- declare const EntryTypes: {
38
- readonly FILE_TYPE: "files";
39
- readonly DIR_TYPE: "directories";
40
- readonly FILE_DIR_TYPE: "files_directories";
41
- readonly EVERYTHING_TYPE: "all";
42
- };
43
- type EntryType = (typeof EntryTypes)[keyof typeof EntryTypes];
44
- /**
45
- * Options for readdirp.
46
- * * type: files, directories, or both
47
- * * lstat: whether to use symlink-friendly stat
48
- * * depth: max depth
49
- * * alwaysStat: whether to use stat (more resources) or dirent
50
- * * highWaterMark: streaming param, specifies max amount of resources per entry
51
- */
52
- type ReaddirpOptions = {
53
- root: string;
54
- fileFilter?: Predicate;
55
- directoryFilter?: Predicate;
56
- type?: EntryType;
57
- lstat?: boolean;
58
- depth?: number;
59
- alwaysStat?: boolean;
60
- highWaterMark?: number;
61
- };
62
- /** Directory entry. Contains path, depth count, and files. */
63
- interface DirEntry$1 {
64
- files: PathOrDirent[];
65
- depth: number;
66
- path: Path$1;
67
- }
68
- /** Readable readdir stream, emitting new files as they're being listed. */
69
- declare class ReaddirpStream extends Readable {
70
- parents: any[];
71
- reading: boolean;
72
- parent?: DirEntry$1;
73
- _stat: Function;
74
- _maxDepth: number;
75
- _wantsDir: boolean;
76
- _wantsFile: boolean;
77
- _wantsEverything: boolean;
78
- _root: Path$1;
79
- _isDirent: boolean;
80
- _statsProp: 'dirent' | 'stats';
81
- _rdOptions: {
82
- encoding: 'utf8';
83
- withFileTypes: boolean;
84
- };
85
- _fileFilter: Tester;
86
- _directoryFilter: Tester;
87
- constructor(options?: Partial<ReaddirpOptions>);
88
- _read(batch: number): Promise<void>;
89
- _exploreDir(path: Path$1, depth: number): Promise<{
90
- files: string[] | undefined;
91
- depth: number;
92
- path: string;
93
- }>;
94
- _formatEntry(dirent: PathOrDirent, path: Path$1): Promise<EntryInfo | undefined>;
95
- _onError(err: Error): void;
96
- _getEntryType(entry: EntryInfo): Promise<void | '' | 'file' | 'directory'>;
97
- _includeAsFile(entry: EntryInfo): boolean | undefined;
98
- }
99
-
100
- type Path = string;
101
- declare const EVENTS: {
102
- readonly ALL: "all";
103
- readonly READY: "ready";
104
- readonly ADD: "add";
105
- readonly CHANGE: "change";
106
- readonly ADD_DIR: "addDir";
107
- readonly UNLINK: "unlink";
108
- readonly UNLINK_DIR: "unlinkDir";
109
- readonly RAW: "raw";
110
- readonly ERROR: "error";
111
- };
112
- type EventName = (typeof EVENTS)[keyof typeof EVENTS];
113
- interface WatchHandlers {
114
- listener: (path: string) => void;
115
- errHandler: (err: unknown) => void;
116
- rawEmitter: (ev: WatchEventType, path: string, opts: unknown) => void;
117
- }
118
- /**
119
- * @mixin
120
- */
121
- declare class NodeFsHandler {
122
- fsw: FSWatcher;
123
- _boundHandleError: (error: unknown) => void;
124
- constructor(fsW: FSWatcher);
125
- /**
126
- * Watch file for changes with fs_watchFile or fs_watch.
127
- * @param path to file or dir
128
- * @param listener on fs change
129
- * @returns closer for the watcher instance
130
- */
131
- _watchWithNodeFs(path: string, listener: (path: string, newStats?: any) => void | Promise<void>): (() => void) | undefined;
132
- /**
133
- * Watch a file and emit add event if warranted.
134
- * @returns closer for the watcher instance
135
- */
136
- _handleFile(file: Path, stats: Stats$1, initialAdd: boolean): (() => void) | undefined;
137
- /**
138
- * Handle symlinks encountered while reading a dir.
139
- * @param entry returned by readdirp
140
- * @param directory path of dir being read
141
- * @param path of this item
142
- * @param item basename of this item
143
- * @returns true if no more processing is needed for this entry.
144
- */
145
- _handleSymlink(entry: EntryInfo, directory: string, path: Path, item: string): Promise<boolean | undefined>;
146
- _handleRead(directory: string, initialAdd: boolean, wh: WatchHelper, target: Path, dir: Path, depth: number, throttler: Throttler): Promise<unknown> | undefined;
147
- /**
148
- * Read directory to add / remove files from `@watched` list and re-read it on change.
149
- * @param dir fs path
150
- * @param stats
151
- * @param initialAdd
152
- * @param depth relative to user-supplied path
153
- * @param target child path targeted for watch
154
- * @param wh Common watch helpers for this path
155
- * @param realpath
156
- * @returns closer for the watcher instance.
157
- */
158
- _handleDir(dir: string, stats: Stats$1, initialAdd: boolean, depth: number, target: string, wh: WatchHelper, realpath: string): Promise<(() => void) | undefined>;
159
- /**
160
- * Handle added file, directory, or glob pattern.
161
- * Delegates call to _handleFile / _handleDir after checks.
162
- * @param path to file or ir
163
- * @param initialAdd was the file added at watch instantiation?
164
- * @param priorWh depth relative to user-supplied path
165
- * @param depth Child path actually targeted for watch
166
- * @param target Child path actually targeted for watch
167
- */
168
- _addToNodeFs(path: string, initialAdd: boolean, priorWh: WatchHelper | undefined, depth: number, target?: string): Promise<string | false | undefined>;
169
- }
170
-
171
1
  /*! chokidar - MIT License (c) 2012 Paul Miller (paulmillr.com) */
172
-
173
- type AWF = {
2
+ import { EventEmitter } from 'node:events';
3
+ import { Stats } from 'node:fs';
4
+ import { type EntryInfo, type ReaddirpOptions, ReaddirpStream } from 'readdirp';
5
+ import { EVENTS as EV, type EventName, NodeFsHandler, type Path, type WatchHandlers } from './handler.js';
6
+ export type AWF = {
174
7
  stabilityThreshold: number;
175
8
  pollInterval: number;
176
9
  };
@@ -187,29 +20,29 @@ type BasicOpts = {
187
20
  ignorePermissionErrors: boolean;
188
21
  atomic: boolean | number;
189
22
  };
190
- type Throttler = {
23
+ export type Throttler = {
191
24
  timeoutObject: NodeJS.Timeout;
192
25
  clear: () => void;
193
26
  count: number;
194
27
  };
195
- type ChokidarOptions = Partial<BasicOpts & {
28
+ export type ChokidarOptions = Partial<BasicOpts & {
196
29
  ignored: Matcher | Matcher[];
197
30
  awaitWriteFinish: boolean | Partial<AWF>;
198
31
  }>;
199
- type FSWInstanceOptions = BasicOpts & {
32
+ export type FSWInstanceOptions = BasicOpts & {
200
33
  ignored: Matcher[];
201
34
  awaitWriteFinish: false | AWF;
202
35
  };
203
- type ThrottleType = 'readdir' | 'watch' | 'add' | 'remove' | 'change';
204
- type EmitArgs = [path: Path, stats?: Stats$1];
205
- type EmitErrorArgs = [error: Error, stats?: Stats$1];
206
- type EmitArgsWithName = [event: EventName, ...EmitArgs];
207
- type MatchFunction = (val: string, stats?: Stats$1) => boolean;
208
- interface MatcherObject {
36
+ export type ThrottleType = 'readdir' | 'watch' | 'add' | 'remove' | 'change';
37
+ export type EmitArgs = [path: Path, stats?: Stats];
38
+ export type EmitErrorArgs = [error: Error, stats?: Stats];
39
+ export type EmitArgsWithName = [event: EventName, ...EmitArgs];
40
+ export type MatchFunction = (val: string, stats?: Stats) => boolean;
41
+ export interface MatcherObject {
209
42
  path: string;
210
43
  recursive?: boolean;
211
44
  }
212
- type Matcher = string | RegExp | MatchFunction | MatcherObject;
45
+ export type Matcher = string | RegExp | MatchFunction | MatcherObject;
213
46
  /**
214
47
  * Directory entry.
215
48
  */
@@ -224,7 +57,7 @@ declare class DirEntry {
224
57
  getChildren(): string[];
225
58
  dispose(): void;
226
59
  }
227
- declare class WatchHelper {
60
+ export declare class WatchHelper {
228
61
  fsw: FSWatcher;
229
62
  path: string;
230
63
  watchPath: string;
@@ -237,15 +70,17 @@ declare class WatchHelper {
237
70
  filterPath(entry: EntryInfo): boolean;
238
71
  filterDir(entry: EntryInfo): boolean;
239
72
  }
240
- interface FSWatcherKnownEventMap {
241
- [EVENTS.READY]: [];
242
- [EVENTS.RAW]: Parameters<WatchHandlers['rawEmitter']>;
243
- [EVENTS.ERROR]: Parameters<WatchHandlers['errHandler']>;
244
- [EVENTS.ALL]: [event: EventName, ...EmitArgs];
73
+ export interface FSWatcherEventMap {
74
+ [EV.READY]: [];
75
+ [EV.RAW]: Parameters<WatchHandlers['rawEmitter']>;
76
+ [EV.ERROR]: Parameters<WatchHandlers['errHandler']>;
77
+ [EV.ALL]: [event: EventName, ...EmitArgs];
78
+ [EV.ADD]: EmitArgs;
79
+ [EV.CHANGE]: EmitArgs;
80
+ [EV.ADD_DIR]: EmitArgs;
81
+ [EV.UNLINK]: EmitArgs;
82
+ [EV.UNLINK_DIR]: EmitArgs;
245
83
  }
246
- type FSWatcherEventMap = FSWatcherKnownEventMap & {
247
- [k in Exclude<EventName, keyof FSWatcherKnownEventMap>]: EmitArgs;
248
- };
249
84
  /**
250
85
  * Watches files & directories for changes. Emitted events:
251
86
  * `add`, `addDir`, `change`, `unlink`, `unlinkDir`, `all`, `error`
@@ -254,7 +89,7 @@ type FSWatcherEventMap = FSWatcherKnownEventMap & {
254
89
  * .add(directories)
255
90
  * .on('add', path => log('File', path, 'was added'))
256
91
  */
257
- declare class FSWatcher extends EventEmitter<FSWatcherEventMap> {
92
+ export declare class FSWatcher extends EventEmitter<FSWatcherEventMap> {
258
93
  closed: boolean;
259
94
  options: FSWInstanceOptions;
260
95
  _closers: Map<string, Array<any>>;
@@ -303,7 +138,7 @@ declare class FSWatcher extends EventEmitter<FSWatcherEventMap> {
303
138
  * @param stats arguments to be passed with event
304
139
  * @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
305
140
  */
306
- _emit(event: EventName, path: Path, stats?: Stats$1): Promise<this | undefined>;
141
+ _emit(event: EventName, path: Path, stats?: Stats): Promise<this | undefined>;
307
142
  /**
308
143
  * Common handler for errors
309
144
  * @returns The error if defined, otherwise the value of the FSWatcher instance's `closed` flag
@@ -326,12 +161,12 @@ declare class FSWatcher extends EventEmitter<FSWatcherEventMap> {
326
161
  * @param event
327
162
  * @param awfEmit Callback to be called when ready for event to be emitted.
328
163
  */
329
- _awaitWriteFinish(path: Path, threshold: number, event: EventName, awfEmit: (err?: Error, stat?: Stats$1) => void): void;
164
+ _awaitWriteFinish(path: Path, threshold: number, event: EventName, awfEmit: (err?: Error, stat?: Stats) => void): void;
330
165
  /**
331
166
  * Determines whether user has asked to ignore this path.
332
167
  */
333
- _isIgnored(path: Path, stats?: Stats$1): boolean;
334
- _isntIgnored(path: Path, stat?: Stats$1): boolean;
168
+ _isIgnored(path: Path, stats?: Stats): boolean;
169
+ _isntIgnored(path: Path, stat?: Stats): boolean;
335
170
  /**
336
171
  * Provides a set of common helpers and properties relating to symlink handling.
337
172
  * @param path file or directory pattern being watched
@@ -345,7 +180,7 @@ declare class FSWatcher extends EventEmitter<FSWatcherEventMap> {
345
180
  /**
346
181
  * Check for read permissions: https://stackoverflow.com/a/11781404/1358405
347
182
  */
348
- _hasReadPermissions(stats: Stats$1): boolean;
183
+ _hasReadPermissions(stats: Stats): boolean;
349
184
  /**
350
185
  * Handles emitting unlink events for
351
186
  * files and directories, and via recursion, for
@@ -374,11 +209,9 @@ declare class FSWatcher extends EventEmitter<FSWatcherEventMap> {
374
209
  * const watcher = watch('.').on('all', (event, path) => { console.log(event, path); });
375
210
  * watch('.', { atomic: true, awaitWriteFinish: true, ignored: (f, stats) => stats?.isFile() && !f.endsWith('.js') })
376
211
  */
377
- declare function watch(paths: string | string[], options?: ChokidarOptions): FSWatcher;
212
+ export declare function watch(paths: string | string[], options?: ChokidarOptions): FSWatcher;
378
213
  declare const _default: {
379
214
  watch: typeof watch;
380
215
  FSWatcher: typeof FSWatcher;
381
216
  };
382
-
383
- export { FSWatcher, WatchHelper, _default as default, watch };
384
- export type { ChokidarOptions, EmitArgs, EmitArgsWithName, EmitErrorArgs, FSWInstanceOptions, FSWatcherEventMap, FSWatcherKnownEventMap, MatchFunction, Matcher, MatcherObject, ThrottleType, Throttler };
217
+ export default _default;
@@ -1 +1 @@
1
- {"name":"chokidar","author":"Paul Miller (https://paulmillr.com)","version":"4.0.3","funding":"https://paulmillr.com/funding/","license":"MIT","types":"index.d.ts","type":"commonjs"}
1
+ {"name":"chokidar","author":"Paul Miller (https://paulmillr.com)","version":"5.0.0","funding":"https://paulmillr.com/funding/","license":"MIT","type":"module"}