@rsbuild/core 1.1.1 → 1.1.3

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 (37) hide show
  1. package/bin/rsbuild.js +2 -10
  2. package/compiled/chokidar/index.d.ts +318 -189
  3. package/compiled/chokidar/index.js +1069 -4439
  4. package/compiled/chokidar/license +1 -1
  5. package/compiled/chokidar/package.json +1 -1
  6. package/compiled/css-loader/index.js +46 -46
  7. package/compiled/html-rspack-plugin/index.js +14 -14
  8. package/compiled/postcss/index.js +135 -117
  9. package/compiled/postcss/package.json +1 -1
  10. package/compiled/postcss-load-config/index.js +10 -10
  11. package/compiled/postcss-loader/index.js +11 -11
  12. package/compiled/rspack-manifest-plugin/index.js +4 -4
  13. package/compiled/tinyglobby/index.d.ts +25 -0
  14. package/compiled/tinyglobby/index.js +2749 -0
  15. package/compiled/tinyglobby/index1.js +17 -0
  16. package/compiled/tinyglobby/license +21 -0
  17. package/compiled/tinyglobby/package.json +1 -0
  18. package/dist/client/hmr.js +10 -1
  19. package/dist/ignoreCssLoader.cjs +22 -44
  20. package/dist/index.cjs +4019 -8237
  21. package/dist/index.js +3982 -8172
  22. package/dist/transformLoader.cjs +26 -44
  23. package/dist/transformRawLoader.cjs +26 -53
  24. package/dist-types/cli/commands.d.ts +1 -1
  25. package/dist-types/cli/index.d.ts +1 -0
  26. package/dist-types/cli/init.d.ts +2 -1
  27. package/dist-types/config.d.ts +2 -2
  28. package/dist-types/helpers/stats.d.ts +2 -3
  29. package/dist-types/index.d.ts +2 -1
  30. package/dist-types/internal.d.ts +1 -15
  31. package/dist-types/plugins/css.d.ts +1 -2
  32. package/dist-types/provider/helpers.d.ts +12 -0
  33. package/dist-types/server/restart.d.ts +4 -0
  34. package/dist-types/server/watchFiles.d.ts +4 -1
  35. package/dist-types/types/config.d.ts +14 -6
  36. package/dist-types/types/rsbuild.d.ts +3 -1
  37. package/package.json +6 -8
package/bin/rsbuild.js CHANGED
@@ -13,16 +13,8 @@ if (enableCompileCache) {
13
13
  }
14
14
 
15
15
  async function main() {
16
- const { __internalHelper, logger } = await import('../dist/index.js');
17
- const { runCli, prepareCli } = __internalHelper;
18
-
19
- prepareCli();
20
-
21
- try {
22
- runCli();
23
- } catch (err) {
24
- logger.error(err);
25
- }
16
+ const { runCLI } = await import('../dist/index.js');
17
+ runCLI();
26
18
  }
27
19
 
28
20
  main();
@@ -1,198 +1,327 @@
1
- /// <reference types="node" />
2
- import * as fs from 'fs';
1
+ import { Stats, Dirent } from 'fs';
3
2
  import { EventEmitter } from 'events';
4
-
5
- type AnymatchFn = (testString: string) => boolean;
6
- type AnymatchPattern = string|RegExp|AnymatchFn;
7
- type AnymatchMatcher = AnymatchPattern|AnymatchPattern[]
8
-
9
- // TypeScript Version: 3.0
10
-
11
-
12
-
13
- declare class FSWatcher extends EventEmitter implements fs.FSWatcher {
14
- options: WatchOptions;
15
-
16
- /**
17
- * Constructs a new FSWatcher instance with optional WatchOptions parameter.
18
- */
19
- constructor(options?: WatchOptions);
20
-
21
- /**
22
- * Add files, directories, or glob patterns for tracking. Takes an array of strings or just one
23
- * string.
24
- */
25
- add(paths: string | ReadonlyArray<string>): this;
26
-
27
- /**
28
- * Stop watching files, directories, or glob patterns. Takes an array of strings or just one
29
- * string.
30
- */
31
- unwatch(paths: string | ReadonlyArray<string>): this;
32
-
33
- /**
34
- * Returns an object representing all the paths on the file system being watched by this
35
- * `FSWatcher` instance. The object's keys are all the directories (using absolute paths unless
36
- * the `cwd` option was used), and the values are arrays of the names of the items contained in
37
- * each directory.
38
- */
39
- getWatched(): {
40
- [directory: string]: string[];
41
- };
42
-
43
- /**
44
- * Removes all listeners from watched files.
45
- */
46
- close(): Promise<void>;
47
-
48
- on(event: 'add'|'addDir'|'change', listener: (path: string, stats?: fs.Stats) => void): this;
49
-
50
- on(event: 'all', listener: (eventName: 'add'|'addDir'|'change'|'unlink'|'unlinkDir', path: string, stats?: fs.Stats) => void): this;
51
-
52
- /**
53
- * Error occurred
54
- */
55
- on(event: 'error', listener: (error: Error) => void): this;
56
-
57
- /**
58
- * Exposes the native Node `fs.FSWatcher events`
59
- */
60
- on(event: 'raw', listener: (eventName: string, path: string, details: any) => void): this;
61
-
62
- /**
63
- * Fires when the initial scan is complete
64
- */
65
- on(event: 'ready', listener: () => void): this;
66
-
67
- on(event: 'unlink'|'unlinkDir', listener: (path: string) => void): this;
68
-
69
- on(event: string, listener: (...args: any[]) => void): this;
70
-
71
- ref(): this;
72
-
73
- unref(): this;
3
+ import { Readable } from 'stream';
4
+
5
+ type Path$1 = string;
6
+ interface EntryInfo {
7
+ path: string;
8
+ fullPath: string;
9
+ stats?: Stats;
10
+ dirent?: Dirent;
11
+ basename: string;
74
12
  }
75
-
76
- interface WatchOptions {
77
- /**
78
- * Indicates whether the process should continue to run as long as files are being watched. If
79
- * set to `false` when using `fsevents` to watch, no more events will be emitted after `ready`,
80
- * even if the process continues to run.
81
- */
82
- persistent?: boolean;
83
-
84
- /**
85
- * ([anymatch](https://github.com/micromatch/anymatch)-compatible definition) Defines files/paths to
86
- * be ignored. The whole relative or absolute path is tested, not just filename. If a function
87
- * with two arguments is provided, it gets called twice per path - once with a single argument
88
- * (the path), second time with two arguments (the path and the
89
- * [`fs.Stats`](https://nodejs.org/api/fs.html#fs_class_fs_stats) object of that path).
90
- */
91
- ignored?: AnymatchMatcher;
92
-
93
- /**
94
- * If set to `false` then `add`/`addDir` events are also emitted for matching paths while
95
- * instantiating the watching as chokidar discovers these file paths (before the `ready` event).
96
- */
97
- ignoreInitial?: boolean;
98
-
99
- /**
100
- * When `false`, only the symlinks themselves will be watched for changes instead of following
101
- * the link references and bubbling events through the link's path.
102
- */
103
- followSymlinks?: boolean;
104
-
105
- /**
106
- * The base directory from which watch `paths` are to be derived. Paths emitted with events will
107
- * be relative to this.
108
- */
109
- cwd?: string;
110
-
111
- /**
112
- * If set to true then the strings passed to .watch() and .add() are treated as literal path
113
- * names, even if they look like globs. Default: false.
114
- */
115
- disableGlobbing?: boolean;
116
-
117
- /**
118
- * Whether to use fs.watchFile (backed by polling), or fs.watch. If polling leads to high CPU
119
- * utilization, consider setting this to `false`. It is typically necessary to **set this to
120
- * `true` to successfully watch files over a network**, and it may be necessary to successfully
121
- * watch files in other non-standard situations. Setting to `true` explicitly on OS X overrides
122
- * the `useFsEvents` default.
123
- */
124
- usePolling?: boolean;
125
-
126
- /**
127
- * Whether to use the `fsevents` watching interface if available. When set to `true` explicitly
128
- * and `fsevents` is available this supercedes the `usePolling` setting. When set to `false` on
129
- * OS X, `usePolling: true` becomes the default.
130
- */
131
- useFsEvents?: boolean;
132
-
133
- /**
134
- * If relying upon the [`fs.Stats`](https://nodejs.org/api/fs.html#fs_class_fs_stats) object that
135
- * may get passed with `add`, `addDir`, and `change` events, set this to `true` to ensure it is
136
- * provided even in cases where it wasn't already available from the underlying watch events.
137
- */
138
- alwaysStat?: boolean;
139
-
140
- /**
141
- * If set, limits how many levels of subdirectories will be traversed.
142
- */
143
- depth?: number;
144
-
145
- /**
146
- * Interval of file system polling.
147
- */
148
- interval?: number;
149
-
150
- /**
151
- * Interval of file system polling for binary files. ([see list of binary extensions](https://gi
152
- * thub.com/sindresorhus/binary-extensions/blob/master/binary-extensions.json))
153
- */
154
- binaryInterval?: number;
155
-
156
- /**
157
- * Indicates whether to watch files that don't have read permissions if possible. If watching
158
- * fails due to `EPERM` or `EACCES` with this set to `true`, the errors will be suppressed
159
- * silently.
160
- */
161
- ignorePermissionErrors?: boolean;
162
-
163
- /**
164
- * `true` if `useFsEvents` and `usePolling` are `false`). Automatically filters out artifacts
165
- * that occur when using editors that use "atomic writes" instead of writing directly to the
166
- * source file. If a file is re-added within 100 ms of being deleted, Chokidar emits a `change`
167
- * event rather than `unlink` then `add`. If the default of 100 ms does not work well for you,
168
- * you can override it by setting `atomic` to a custom value, in milliseconds.
169
- */
170
- atomic?: boolean | number;
171
-
172
- /**
173
- * can be set to an object in order to adjust timing params:
174
- */
175
- awaitWriteFinish?: AwaitWriteFinishOptions | boolean;
13
+ type PathOrDirent = Dirent | Path$1;
14
+ type Tester = (path: EntryInfo) => boolean;
15
+ declare function defaultOptions(): {
16
+ root: string;
17
+ fileFilter: (_path: EntryInfo) => boolean;
18
+ directoryFilter: (_path: EntryInfo) => boolean;
19
+ type: string;
20
+ lstat: boolean;
21
+ depth: number;
22
+ alwaysStat: boolean;
23
+ highWaterMark: number;
24
+ };
25
+ type ReaddirpOptions = ReturnType<typeof defaultOptions>;
26
+ interface DirEntry$1 {
27
+ files: PathOrDirent[];
28
+ depth: number;
29
+ path: Path$1;
30
+ }
31
+ declare class ReaddirpStream extends Readable {
32
+ parents: any[];
33
+ reading: boolean;
34
+ parent?: DirEntry$1;
35
+ _stat: Function;
36
+ _maxDepth: number;
37
+ _wantsDir: boolean;
38
+ _wantsFile: boolean;
39
+ _wantsEverything: boolean;
40
+ _root: Path$1;
41
+ _isDirent: boolean;
42
+ _statsProp: 'dirent' | 'stats';
43
+ _rdOptions: {
44
+ encoding: 'utf8';
45
+ withFileTypes: boolean;
46
+ };
47
+ _fileFilter: Tester;
48
+ _directoryFilter: Tester;
49
+ constructor(options?: Partial<ReaddirpOptions>);
50
+ _read(batch: number): Promise<void>;
51
+ _exploreDir(path: Path$1, depth: number): Promise<{
52
+ files: string[] | undefined;
53
+ depth: number;
54
+ path: string;
55
+ }>;
56
+ _formatEntry(dirent: PathOrDirent, path: Path$1): Promise<EntryInfo | undefined>;
57
+ _onError(err: Error): void;
58
+ _getEntryType(entry: EntryInfo): Promise<void | "" | "file" | "directory">;
59
+ _includeAsFile(entry: EntryInfo): boolean | undefined;
176
60
  }
177
61
 
178
- interface AwaitWriteFinishOptions {
179
- /**
180
- * Amount of time in milliseconds for a file size to remain constant before emitting its event.
181
- */
182
- stabilityThreshold?: number;
183
-
184
- /**
185
- * File size polling interval.
186
- */
187
- pollInterval?: number;
62
+ type Path = string;
63
+ declare const EVENTS: {
64
+ readonly ALL: "all";
65
+ readonly READY: "ready";
66
+ readonly ADD: "add";
67
+ readonly CHANGE: "change";
68
+ readonly ADD_DIR: "addDir";
69
+ readonly UNLINK: "unlink";
70
+ readonly UNLINK_DIR: "unlinkDir";
71
+ readonly RAW: "raw";
72
+ readonly ERROR: "error";
73
+ };
74
+ type EventName = (typeof EVENTS)[keyof typeof EVENTS];
75
+ /**
76
+ * @mixin
77
+ */
78
+ declare class NodeFsHandler {
79
+ fsw: FSWatcher;
80
+ _boundHandleError: (error: unknown) => void;
81
+ constructor(fsW: FSWatcher);
82
+ /**
83
+ * Watch file for changes with fs_watchFile or fs_watch.
84
+ * @param path to file or dir
85
+ * @param listener on fs change
86
+ * @returns closer for the watcher instance
87
+ */
88
+ _watchWithNodeFs(path: string, listener: (path: string, newStats?: any) => void | Promise<void>): (() => void) | undefined;
89
+ /**
90
+ * Watch a file and emit add event if warranted.
91
+ * @returns closer for the watcher instance
92
+ */
93
+ _handleFile(file: Path, stats: Stats, initialAdd: boolean): (() => void) | undefined;
94
+ /**
95
+ * Handle symlinks encountered while reading a dir.
96
+ * @param entry returned by readdirp
97
+ * @param directory path of dir being read
98
+ * @param path of this item
99
+ * @param item basename of this item
100
+ * @returns true if no more processing is needed for this entry.
101
+ */
102
+ _handleSymlink(entry: EntryInfo, directory: string, path: Path, item: string): Promise<boolean | undefined>;
103
+ _handleRead(directory: string, initialAdd: boolean, wh: WatchHelper, target: Path, dir: Path, depth: number, throttler: Throttler): Promise<unknown> | undefined;
104
+ /**
105
+ * Read directory to add / remove files from `@watched` list and re-read it on change.
106
+ * @param dir fs path
107
+ * @param stats
108
+ * @param initialAdd
109
+ * @param depth relative to user-supplied path
110
+ * @param target child path targeted for watch
111
+ * @param wh Common watch helpers for this path
112
+ * @param realpath
113
+ * @returns closer for the watcher instance.
114
+ */
115
+ _handleDir(dir: string, stats: Stats, initialAdd: boolean, depth: number, target: string, wh: WatchHelper, realpath: string): Promise<(() => void) | undefined>;
116
+ /**
117
+ * Handle added file, directory, or glob pattern.
118
+ * Delegates call to _handleFile / _handleDir after checks.
119
+ * @param path to file or ir
120
+ * @param initialAdd was the file added at watch instantiation?
121
+ * @param priorWh depth relative to user-supplied path
122
+ * @param depth Child path actually targeted for watch
123
+ * @param target Child path actually targeted for watch
124
+ */
125
+ _addToNodeFs(path: string, initialAdd: boolean, priorWh: WatchHelper | undefined, depth: number, target?: string): Promise<string | false | undefined>;
188
126
  }
189
127
 
128
+ type AWF = {
129
+ stabilityThreshold: number;
130
+ pollInterval: number;
131
+ };
132
+ type BasicOpts = {
133
+ persistent: boolean;
134
+ ignoreInitial: boolean;
135
+ followSymlinks: boolean;
136
+ cwd?: string;
137
+ usePolling: boolean;
138
+ interval: number;
139
+ binaryInterval: number;
140
+ alwaysStat?: boolean;
141
+ depth?: number;
142
+ ignorePermissionErrors: boolean;
143
+ atomic: boolean | number;
144
+ };
145
+ type Throttler = {
146
+ timeoutObject: NodeJS.Timeout;
147
+ clear: () => void;
148
+ count: number;
149
+ };
150
+ type ChokidarOptions = Partial<BasicOpts & {
151
+ ignored: Matcher | Matcher[];
152
+ awaitWriteFinish: boolean | Partial<AWF>;
153
+ }>;
154
+ type FSWInstanceOptions = BasicOpts & {
155
+ ignored: Matcher[];
156
+ awaitWriteFinish: false | AWF;
157
+ };
158
+ type ThrottleType = 'readdir' | 'watch' | 'add' | 'remove' | 'change';
159
+ type EmitArgs = [EventName, Path | Error, any?, any?, any?];
160
+ type MatchFunction = (val: string, stats?: Stats) => boolean;
161
+ interface MatcherObject {
162
+ path: string;
163
+ recursive?: boolean;
164
+ }
165
+ type Matcher = string | RegExp | MatchFunction | MatcherObject;
166
+ /**
167
+ * Directory entry.
168
+ */
169
+ declare class DirEntry {
170
+ path: Path;
171
+ _removeWatcher: (dir: string, base: string) => void;
172
+ items: Set<Path>;
173
+ constructor(dir: Path, removeWatcher: (dir: string, base: string) => void);
174
+ add(item: string): void;
175
+ remove(item: string): Promise<void>;
176
+ has(item: string): boolean | undefined;
177
+ getChildren(): string[];
178
+ dispose(): void;
179
+ }
180
+ declare class WatchHelper {
181
+ fsw: FSWatcher;
182
+ path: string;
183
+ watchPath: string;
184
+ fullWatchPath: string;
185
+ dirParts: string[][];
186
+ followSymlinks: boolean;
187
+ statMethod: 'stat' | 'lstat';
188
+ constructor(path: string, follow: boolean, fsw: FSWatcher);
189
+ entryPath(entry: EntryInfo): Path;
190
+ filterPath(entry: EntryInfo): boolean;
191
+ filterDir(entry: EntryInfo): boolean;
192
+ }
193
+ /**
194
+ * Watches files & directories for changes. Emitted events:
195
+ * `add`, `addDir`, `change`, `unlink`, `unlinkDir`, `all`, `error`
196
+ *
197
+ * new FSWatcher()
198
+ * .add(directories)
199
+ * .on('add', path => log('File', path, 'was added'))
200
+ */
201
+ declare class FSWatcher extends EventEmitter {
202
+ closed: boolean;
203
+ options: FSWInstanceOptions;
204
+ _closers: Map<string, Array<any>>;
205
+ _ignoredPaths: Set<Matcher>;
206
+ _throttled: Map<ThrottleType, Map<any, any>>;
207
+ _streams: Set<ReaddirpStream>;
208
+ _symlinkPaths: Map<Path, string | boolean>;
209
+ _watched: Map<string, DirEntry>;
210
+ _pendingWrites: Map<string, any>;
211
+ _pendingUnlinks: Map<string, EmitArgs>;
212
+ _readyCount: number;
213
+ _emitReady: () => void;
214
+ _closePromise?: Promise<void>;
215
+ _userIgnored?: MatchFunction;
216
+ _readyEmitted: boolean;
217
+ _emitRaw: () => void;
218
+ _boundRemove: (dir: string, item: string) => void;
219
+ _nodeFsHandler: NodeFsHandler;
220
+ constructor(_opts?: ChokidarOptions);
221
+ _addIgnoredPath(matcher: Matcher): void;
222
+ _removeIgnoredPath(matcher: Matcher): void;
223
+ /**
224
+ * Adds paths to be watched on an existing FSWatcher instance.
225
+ * @param paths_ file or file list. Other arguments are unused
226
+ */
227
+ add(paths_: Path | Path[], _origAdd?: string, _internal?: boolean): FSWatcher;
228
+ /**
229
+ * Close watchers or start ignoring events from specified paths.
230
+ */
231
+ unwatch(paths_: Path | Path[]): FSWatcher;
232
+ /**
233
+ * Close watchers and remove all listeners from watched paths.
234
+ */
235
+ close(): Promise<void>;
236
+ /**
237
+ * Expose list of watched paths
238
+ * @returns for chaining
239
+ */
240
+ getWatched(): Record<string, string[]>;
241
+ emitWithAll(event: EventName, args: EmitArgs): void;
242
+ /**
243
+ * Normalize and emit events.
244
+ * Calling _emit DOES NOT MEAN emit() would be called!
245
+ * @param event Type of event
246
+ * @param path File or directory path
247
+ * @param stats arguments to be passed with event
248
+ * @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
249
+ */
250
+ _emit(event: EventName, path: Path, stats?: Stats): Promise<this | undefined>;
251
+ /**
252
+ * Common handler for errors
253
+ * @returns The error if defined, otherwise the value of the FSWatcher instance's `closed` flag
254
+ */
255
+ _handleError(error: Error): Error | boolean;
256
+ /**
257
+ * Helper utility for throttling
258
+ * @param actionType type being throttled
259
+ * @param path being acted upon
260
+ * @param timeout duration of time to suppress duplicate actions
261
+ * @returns tracking object or false if action should be suppressed
262
+ */
263
+ _throttle(actionType: ThrottleType, path: Path, timeout: number): Throttler | false;
264
+ _incrReadyCount(): number;
265
+ /**
266
+ * Awaits write operation to finish.
267
+ * Polls a newly created file for size variations. When files size does not change for 'threshold' milliseconds calls callback.
268
+ * @param path being acted upon
269
+ * @param threshold Time in milliseconds a file size must be fixed before acknowledging write OP is finished
270
+ * @param event
271
+ * @param awfEmit Callback to be called when ready for event to be emitted.
272
+ */
273
+ _awaitWriteFinish(path: Path, threshold: number, event: EventName, awfEmit: (err?: Error, stat?: Stats) => void): void;
274
+ /**
275
+ * Determines whether user has asked to ignore this path.
276
+ */
277
+ _isIgnored(path: Path, stats?: Stats): boolean;
278
+ _isntIgnored(path: Path, stat?: Stats): boolean;
279
+ /**
280
+ * Provides a set of common helpers and properties relating to symlink handling.
281
+ * @param path file or directory pattern being watched
282
+ */
283
+ _getWatchHelpers(path: Path): WatchHelper;
284
+ /**
285
+ * Provides directory tracking objects
286
+ * @param directory path of the directory
287
+ */
288
+ _getWatchedDir(directory: string): DirEntry;
289
+ /**
290
+ * Check for read permissions: https://stackoverflow.com/a/11781404/1358405
291
+ */
292
+ _hasReadPermissions(stats: Stats): boolean;
293
+ /**
294
+ * Handles emitting unlink events for
295
+ * files and directories, and via recursion, for
296
+ * files and directories within directories that are unlinked
297
+ * @param directory within which the following item is located
298
+ * @param item base path of item/directory
299
+ */
300
+ _remove(directory: string, item: string, isDirectory?: boolean): void;
301
+ /**
302
+ * Closes all watchers for a path
303
+ */
304
+ _closePath(path: Path): void;
305
+ /**
306
+ * Closes only file-specific watchers
307
+ */
308
+ _closeFile(path: Path): void;
309
+ _addPathCloser(path: Path, closer: () => void): void;
310
+ _readdirp(root: Path, opts?: Partial<ReaddirpOptions>): ReaddirpStream | undefined;
311
+ }
190
312
  /**
191
- * produces an instance of `FSWatcher`.
313
+ * Instantiates watcher with paths to be tracked.
314
+ * @param paths file / directory paths
315
+ * @param options opts, such as `atomic`, `awaitWriteFinish`, `ignored`, and others
316
+ * @returns an instance of FSWatcher for chaining.
317
+ * @example
318
+ * const watcher = watch('.').on('all', (event, path) => { console.log(event, path); });
319
+ * watch('.', { atomic: true, awaitWriteFinish: true, ignored: (f, stats) => stats?.isFile() && !f.endsWith('.js') })
192
320
  */
193
- declare function watch(
194
- paths: string | ReadonlyArray<string>,
195
- options?: WatchOptions
196
- ): FSWatcher;
321
+ declare function watch(paths: string | string[], options?: ChokidarOptions): FSWatcher;
322
+ declare const _default: {
323
+ watch: typeof watch;
324
+ FSWatcher: typeof FSWatcher;
325
+ };
197
326
 
198
- export { type AwaitWriteFinishOptions, FSWatcher, type WatchOptions, watch };
327
+ export { type ChokidarOptions, type EmitArgs, type FSWInstanceOptions, FSWatcher, type MatchFunction, type Matcher, type MatcherObject, type ThrottleType, type Throttler, WatchHelper, _default as default, watch };