@rsbuild/core 2.0.8 → 2.0.9

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 (75) hide show
  1. package/dist/1~rslib-runtime.js +8 -5
  2. package/dist/756.js +13 -7
  3. package/dist/memfs.js +4 -4
  4. package/dist-types/build.d.ts +1 -1
  5. package/dist-types/cli/init.d.ts +1 -1
  6. package/dist-types/configChain.d.ts +59 -118
  7. package/dist-types/constants.d.ts +35 -31
  8. package/dist-types/createContext.d.ts +1 -2
  9. package/dist-types/createRsbuild.d.ts +1 -2
  10. package/dist-types/defaultConfig.d.ts +2 -4
  11. package/dist-types/helpers/exitHook.d.ts +1 -1
  12. package/dist-types/helpers/format.d.ts +2 -1
  13. package/dist-types/helpers/fs.d.ts +2 -4
  14. package/dist-types/helpers/index.d.ts +1 -2
  15. package/dist-types/helpers/path.d.ts +4 -8
  16. package/dist-types/helpers/stats.d.ts +3 -5
  17. package/dist-types/helpers/url.d.ts +1 -0
  18. package/dist-types/helpers/vendors.d.ts +2 -3
  19. package/dist-types/helpers/version.d.ts +2 -3
  20. package/dist-types/hooks.d.ts +6 -8
  21. package/dist-types/index.d.ts +10 -5
  22. package/dist-types/initConfigs.d.ts +2 -3
  23. package/dist-types/initPlugins.d.ts +1 -1
  24. package/dist-types/inspectConfig.d.ts +1 -1
  25. package/dist-types/loadConfig.d.ts +24 -32
  26. package/dist-types/loadEnv.d.ts +48 -57
  27. package/dist-types/loader/transformRawLoader.d.ts +1 -0
  28. package/dist-types/logger.d.ts +1 -2
  29. package/dist-types/mergeConfig.d.ts +1 -2
  30. package/dist-types/pluginHelper.d.ts +1 -2
  31. package/dist-types/pluginManager.d.ts +4 -7
  32. package/dist-types/plugins/basic.d.ts +1 -2
  33. package/dist-types/plugins/css.d.ts +4 -0
  34. package/dist-types/plugins/fileSize.d.ts +6 -5
  35. package/dist-types/plugins/rspackProfile.d.ts +2 -0
  36. package/dist-types/plugins/server.d.ts +1 -0
  37. package/dist-types/plugins/swc.d.ts +1 -2
  38. package/dist-types/restart.d.ts +4 -5
  39. package/dist-types/rspack-plugins/RsbuildHtmlPlugin.d.ts +2 -3
  40. package/dist-types/rspack-plugins/resource-hints/HtmlResourceHintsPlugin.d.ts +2 -3
  41. package/dist-types/rspack-plugins/resource-hints/doesChunkBelongToHtml.d.ts +3 -4
  42. package/dist-types/rspack-plugins/resource-hints/extractChunks.d.ts +1 -2
  43. package/dist-types/rspack-plugins/resource-hints/getResourceType.d.ts +2 -3
  44. package/dist-types/rspackConfig.d.ts +1 -1
  45. package/dist-types/server/ansiHTML.d.ts +1 -2
  46. package/dist-types/server/assets-middleware/getFileFromUrl.d.ts +1 -2
  47. package/dist-types/server/assets-middleware/index.d.ts +3 -5
  48. package/dist-types/server/assets-middleware/setupWriteToDisk.d.ts +1 -2
  49. package/dist-types/server/browserLogs.d.ts +1 -2
  50. package/dist-types/server/buildManager.d.ts +4 -6
  51. package/dist-types/server/cliShortcuts.d.ts +3 -1
  52. package/dist-types/server/devMiddlewares.d.ts +2 -3
  53. package/dist-types/server/devServer.d.ts +18 -23
  54. package/dist-types/server/gracefulShutdown.d.ts +2 -4
  55. package/dist-types/server/gzipMiddleware.d.ts +1 -1
  56. package/dist-types/server/helper.d.ts +36 -45
  57. package/dist-types/server/historyApiFallback.d.ts +8 -1
  58. package/dist-types/server/httpServer.d.ts +1 -1
  59. package/dist-types/server/middlewares.d.ts +4 -8
  60. package/dist-types/server/open.d.ts +1 -1
  61. package/dist-types/server/runner/basic.d.ts +4 -5
  62. package/dist-types/server/runner/index.d.ts +3 -1
  63. package/dist-types/server/socketServer.d.ts +24 -18
  64. package/dist-types/server/watchFiles.d.ts +1 -1
  65. package/dist-types/types/config.d.ts +1192 -1465
  66. package/dist-types/types/context.d.ts +63 -92
  67. package/dist-types/types/hooks.d.ts +106 -150
  68. package/dist-types/types/plugin.d.ts +359 -444
  69. package/dist-types/types/rsbuild.d.ts +156 -191
  70. package/dist-types/types/thirdParty.d.ts +101 -132
  71. package/dist-types/types/utils.d.ts +2 -5
  72. package/package.json +3 -3
  73. package/dist-types/client/hmr.d.ts +0 -3
  74. package/dist-types/client/log.d.ts +0 -13
  75. package/dist-types/client/overlay.d.ts +0 -1
@@ -12,36 +12,31 @@ type ExtractSocketMessageData<T extends ServerMessage['type']> = 'data' extends
12
12
  export type HotSend = <T extends ServerMessage['type']>(type: T, data?: ExtractSocketMessageData<T>) => void;
13
13
  export type RsbuildDevServer = RsbuildServerBase & {
14
14
  /**
15
- * Notifies Rsbuild that the custom server has successfully started.
16
- * Rsbuild will trigger the `onAfterStartDevServer` hook at this stage.
17
- */
18
- afterListen: () => Promise<void>;
15
+ * Notifies Rsbuild that the custom server has successfully started.
16
+ * Rsbuild will trigger the `onAfterStartDevServer` hook at this stage.
17
+ */ afterListen: () => Promise<void>;
19
18
  /**
20
- * Activate socket connection.
21
- * This ensures that HMR works properly.
22
- */
23
- connectWebSocket: (options: {
19
+ * Activate socket connection.
20
+ * This ensures that HMR works properly.
21
+ */ connectWebSocket: (options: {
24
22
  server: HTTPServer;
25
23
  }) => void;
26
24
  /**
27
- * Environment API of Rsbuild server.
28
- */
29
- environments: EnvironmentAPI;
25
+ * Environment API of Rsbuild server.
26
+ */ environments: EnvironmentAPI;
30
27
  /**
31
- * Start listening on the Rsbuild dev server.
32
- * Do not call this method if you are using a custom server.
33
- */
34
- listen: () => Promise<StartDevServerResult>;
28
+ * Start listening on the Rsbuild dev server.
29
+ * Do not call this method if you are using a custom server.
30
+ */ listen: () => Promise<StartDevServerResult>;
35
31
  /**
36
- * Allows middleware to send some message to HMR client, and then the HMR
37
- * client will take different actions depending on the message type.
38
- * - `full-reload`: The page will reload.
39
- * - `static-changed`: Alias of `full-reload` for backward compatibility.
40
- * - `custom`: Send custom messages via `custom` type with optional data to the browser and handle them via HMR events.
41
- */
42
- sockWrite: HotSend;
32
+ * Allows middleware to send some message to HMR client, and then the HMR
33
+ * client will take different actions depending on the message type.
34
+ * - `full-reload`: The page will reload.
35
+ * - `static-changed`: Alias of `full-reload` for backward compatibility.
36
+ * - `custom`: Send custom messages via `custom` type with optional data to the browser and handle them via HMR events.
37
+ */ sockWrite: HotSend;
43
38
  };
44
39
  export declare function createDevServer<Options extends {
45
40
  context: InternalContext;
46
41
  }>(options: Options, createCompiler: CreateCompiler, config: NormalizedConfig, { getPortSilently, runCompile }?: CreateDevServerOptions): Promise<RsbuildDevServer>;
47
- export {};
42
+ export { };
@@ -1,10 +1,8 @@
1
1
  /**
2
2
  * Registers a cleanup callback to be executed before process termination
3
- */
4
- export declare const registerCleanup: (callback: () => Promise<void>) => void;
3
+ */ export declare const registerCleanup: (callback: () => Promise<void>) => void;
5
4
  export declare const removeCleanup: (callback: () => Promise<void>) => void;
6
5
  /**
7
6
  * Sets up listeners for termination signals and stdin end event
8
7
  * This should be called once during application initialization
9
- */
10
- export declare const setupGracefulShutdown: () => (() => void);
8
+ */ export declare const setupGracefulShutdown: () => (() => void);
@@ -1,2 +1,2 @@
1
1
  import type { CompressOptions, RequestHandler } from '../types';
2
- export declare function gzipMiddleware({ filter, level, }?: CompressOptions): RequestHandler;
2
+ export declare function gzipMiddleware({ filter, level }?: CompressOptions): RequestHandler;
@@ -7,31 +7,31 @@ import type { RsbuildDevServer } from './devServer';
7
7
  import type { RsbuildPreviewServer } from './previewServer';
8
8
  /**
9
9
  * It used to subscribe http upgrade event
10
- */
11
- export type UpgradeEvent = (req: IncomingMessage, socket: Socket, head: any) => void;
10
+ */ export type UpgradeEvent = (req: IncomingMessage, socket: Socket, head: any) => void;
12
11
  export type ServerStartResult<T> = {
13
12
  /**
14
- * The URLs that server is listening on.
15
- */
16
- urls: string[];
13
+ * The URLs that server is listening on.
14
+ */ urls: string[];
17
15
  /**
18
- * The actual port used by the server.
19
- */
20
- port: number;
16
+ * The actual port used by the server.
17
+ */ port: number;
21
18
  /**
22
- * The dev server or preview server instance.
23
- */
24
- server: T;
19
+ * The dev server or preview server instance.
20
+ */ server: T;
25
21
  };
26
22
  export type StartDevServerResult = ServerStartResult<RsbuildDevServer>;
27
23
  export type StartPreviewServerResult = ServerStartResult<RsbuildPreviewServer>;
24
+ // remove repeat '/'
28
25
  export declare const normalizeUrl: (url: string) => string;
26
+ // /a + /b => /a/b
29
27
  export declare const joinUrlPath: (basePath: string, pathname: string) => string;
30
28
  export declare const isUrlPathUnderBase: (pathname: string, base: string) => boolean;
31
29
  export declare const removeBasePath: (url: string, base: string) => string;
32
30
  export declare const getRoutes: (context: InternalContext) => Routes;
33
- export declare const formatRoutes: (entry: RsbuildEntry, base: string, distPathPrefix: string | undefined, outputStructure: OutputStructure | undefined) => Routes;
34
- export declare function printServerURLs({ urls: originalUrls, port, routes, protocol, printUrls, fallbackPathname, trailingLineBreak, originalConfig, logger, }: {
31
+ /*
32
+ * format route by entry and adjust the index route to be the first
33
+ */ export declare const formatRoutes: (entry: RsbuildEntry, base: string, distPathPrefix: string | undefined, outputStructure: OutputStructure | undefined) => Routes;
34
+ export declare function printServerURLs({ urls: originalUrls, port, routes, protocol, printUrls, fallbackPathname, trailingLineBreak, originalConfig, logger }: {
35
35
  urls: {
36
36
  url: string;
37
37
  label: string;
@@ -51,8 +51,7 @@ export declare function printServerURLs({ urls: originalUrls, port, routes, prot
51
51
  * @param tryLimits - Maximum number of retries.
52
52
  * @param strictPort - Whether to throw an error when the port is occupied.
53
53
  * @returns Available port number.
54
- */
55
- export declare const getPort: ({ host, port, strictPort, tryLimits, }: {
54
+ */ export declare const getPort: ({ host, port, strictPort, tryLimits }: {
56
55
  host: string;
57
56
  port: string | number;
58
57
  strictPort: boolean;
@@ -68,7 +67,7 @@ type AddressUrl = {
68
67
  label: string;
69
68
  url: string;
70
69
  };
71
- export declare const getAddressUrls: ({ protocol, port, host, }: {
70
+ export declare const getAddressUrls: ({ protocol, port, host }: {
72
71
  protocol: string;
73
72
  port: number;
74
73
  host?: string;
@@ -78,8 +77,7 @@ export declare function getServerTerminator(server: Server | Http2SecureServer):
78
77
  * Escape HTML characters
79
78
  * @example
80
79
  * escapeHtml('<div>Hello</div>') // '&lt;div&gt;Hello&lt;/div&gt;'
81
- */
82
- export declare function escapeHtml(text: string | null | undefined): string;
80
+ */ export declare function escapeHtml(text: string | null | undefined): string;
83
81
  export declare const HttpCode: {
84
82
  readonly Ok: 200;
85
83
  readonly NotModified: 304;
@@ -92,37 +90,30 @@ export declare const HttpCode: {
92
90
  };
93
91
  /**
94
92
  * The public server API shared by both the dev and preview servers.
95
- */
96
- export type RsbuildServerBase = {
93
+ */ export type RsbuildServerBase = {
97
94
  /**
98
- * Close the server.
99
- * In the dev server, this will call the `onCloseDevServer` hook.
100
- */
101
- close: () => Promise<void>;
95
+ * Close the server.
96
+ * In the dev server, this will call the `onCloseDevServer` hook.
97
+ */ close: () => Promise<void>;
102
98
  /**
103
- * The Node.js HTTP server instance.
104
- * - Will be `Http2SecureServer` if `server.https` config is used.
105
- * - Will be `null` if `server.middlewareMode` is enabled.
106
- */
107
- httpServer: import('node:http').Server | import('node:http2').Http2SecureServer | null;
99
+ * The Node.js HTTP server instance.
100
+ * - Will be `Http2SecureServer` if `server.https` config is used.
101
+ * - Will be `null` if `server.middlewareMode` is enabled.
102
+ */ httpServer: import('node:http').Server | import('node:http2').Http2SecureServer | null;
108
103
  /**
109
- * The `connect` app instance.
110
- * Can be used to attach custom middlewares to the server.
111
- */
112
- middlewares: Connect.Server;
104
+ * The `connect` app instance.
105
+ * Can be used to attach custom middlewares to the server.
106
+ */ middlewares: Connect.Server;
113
107
  /**
114
- * Open URL in the browser after starting the server.
115
- */
116
- open: () => Promise<void>;
108
+ * Open URL in the browser after starting the server.
109
+ */ open: () => Promise<void>;
117
110
  /**
118
- * The resolved port.
119
- * By default, Rsbuild server listens on port `3000` and automatically increments
120
- * the port number if the port is occupied.
121
- */
122
- port: number;
111
+ * The resolved port.
112
+ * By default, Rsbuild server listens on port `3000` and automatically increments
113
+ * the port number if the port is occupied.
114
+ */ port: number;
123
115
  /**
124
- * Print the server URLs.
125
- */
126
- printUrls: () => void;
116
+ * Print the server URLs.
117
+ */ printUrls: () => void;
127
118
  };
128
- export {};
119
+ export { };
@@ -1,3 +1,10 @@
1
- import type { Logger } from '../logger';
1
+ /**
2
+ * This module is modified based on source found in
3
+ * https://github.com/bripkens/connect-history-api-fallback
4
+ *
5
+ * MIT Licensed
6
+ * Copyright (c) 2022 Ben Blackmore and contributors
7
+ * https://github.com/bripkens/connect-history-api-fallback/blob/master/LICENSE
8
+ */ import type { Logger } from '../logger';
2
9
  import type { HistoryApiFallbackOptions, RequestHandler } from '../types';
3
10
  export declare function historyApiFallbackMiddleware(logger: Logger, options?: HistoryApiFallbackOptions): RequestHandler;
@@ -1,7 +1,7 @@
1
1
  import type { Server } from 'node:http';
2
2
  import type { Http2SecureServer } from 'node:http2';
3
3
  import type { Connect, ServerConfig } from '../types';
4
- export declare const createHttpServer: ({ serverConfig, middlewares, }: {
4
+ export declare const createHttpServer: ({ serverConfig, middlewares }: {
5
5
  serverConfig: ServerConfig;
6
6
  middlewares: Connect.Server;
7
7
  }) => Promise<Http2SecureServer | Server>;
@@ -7,29 +7,25 @@ export declare const notFoundMiddleware: RequestHandler;
7
7
  export declare const optionsFallbackMiddleware: RequestHandler;
8
8
  /**
9
9
  * Support access HTML without suffix
10
- */
11
- export declare const getHtmlCompletionMiddleware: (params: {
10
+ */ export declare const getHtmlCompletionMiddleware: (params: {
12
11
  distPath: string;
13
12
  buildManager: BuildManager;
14
13
  }) => RequestHandler;
15
14
  /**
16
15
  * handle `server.base`
17
- */
18
- export declare const getBaseUrlMiddleware: (params: {
16
+ */ export declare const getBaseUrlMiddleware: (params: {
19
17
  base: string;
20
18
  }) => RequestHandler;
21
19
  /**
22
20
  * support HTML fallback in some edge cases
23
- */
24
- export declare const getHtmlFallbackMiddleware: (params: {
21
+ */ export declare const getHtmlFallbackMiddleware: (params: {
25
22
  distPath: string;
26
23
  buildManager: BuildManager;
27
24
  logger: Logger;
28
25
  }) => RequestHandler;
29
26
  /**
30
27
  * Support viewing served files via `/rsbuild-dev-server` route
31
- */
32
- export declare const viewingServedFilesMiddleware: (params: {
28
+ */ export declare const viewingServedFilesMiddleware: (params: {
33
29
  environments: EnvironmentAPI;
34
30
  logger: Logger;
35
31
  }) => RequestHandler;
@@ -2,7 +2,7 @@ import type { Logger } from '../logger';
2
2
  import type { NormalizedConfig, Routes } from '../types';
3
3
  export declare const replacePortPlaceholder: (url: string, port: number) => string;
4
4
  export declare function resolveUrl(str: string, base: string): string;
5
- export declare function open({ port, routes, config, protocol, clearCache, logger, }: {
5
+ export declare function open({ port, routes, config, protocol, clearCache, logger }: {
6
6
  port: number;
7
7
  routes: Routes;
8
8
  config: NormalizedConfig;
@@ -18,11 +18,10 @@ export declare abstract class BasicRunner implements Runner {
18
18
  protected abstract createBaseModuleScope(): BasicModuleScope;
19
19
  protected abstract createModuleScope(requireFn: RunnerRequirer, m: ModuleObject, file: BasicRunnerFile): BasicModuleScope;
20
20
  /**
21
- * Get the file information for a given module path.
22
- *
23
- * @returns An object containing the file path, content, and subPath, or null if the module is not an rspack output.
24
- */
25
- protected getFile(modulePath: string[] | string, currentDirectory: string): BasicRunnerFile | null;
21
+ * Get the file information for a given module path.
22
+ *
23
+ * @returns An object containing the file path, content, and subPath, or null if the module is not an rspack output.
24
+ */ protected getFile(modulePath: string[] | string, currentDirectory: string): BasicRunnerFile | null;
26
25
  protected preExecute(_code: string, _file: BasicRunnerFile): void;
27
26
  protected postExecute(_m: ModuleObject, _file: BasicRunnerFile): void;
28
27
  protected createRunner(): void;
@@ -1,4 +1,6 @@
1
- import type { RunnerFactoryOptions } from './type';
1
+ /**
2
+ * The following code is modified based on @rspack/test-tools/runner
3
+ */ import type { RunnerFactoryOptions } from './type';
2
4
  export declare const run: <T>({ bundlePath, ...runnerFactoryOptions }: RunnerFactoryOptions & {
3
5
  bundlePath: string;
4
6
  }) => Promise<T>;
@@ -5,12 +5,11 @@ export type ServerMessageFullReload = {
5
5
  type: 'full-reload';
6
6
  data?: {
7
7
  /**
8
- * If `path` ends with `.html`, only the matching page will reload.
9
- * The HTML path should be relative to the dev server root and should not
10
- * include `server.base`. Use `'*'` to reload all pages.
11
- * @example `/foo.html`
12
- */
13
- path?: string;
8
+ * If `path` ends with `.html`, only the matching page will reload.
9
+ * The HTML path should be relative to the dev server root and should not
10
+ * include `server.base`. Use `'*'` to reload all pages.
11
+ * @example `/foo.html`
12
+ */ path?: string;
14
13
  };
15
14
  };
16
15
  export type ServerMessageStaticChanged = {
@@ -73,32 +72,39 @@ export declare class SocketServer {
73
72
  private reportedBrowserLogs;
74
73
  private currentHash;
75
74
  constructor(context: InternalContext, options: DevConfig, getOutputFileSystem: () => Rspack.OutputFileSystem);
75
+ // subscribe upgrade event to handle socket
76
76
  upgrade: (req: IncomingMessage, socket: Socket, head: Buffer) => void;
77
+ // detect and close broken connections
78
+ // https://github.com/websockets/ws/blob/8.18.0/README.md#how-to-detect-and-close-broken-connections
77
79
  private checkSockets;
78
80
  private clearHeartbeatTimer;
81
+ // create socket, install socket handler, bind socket event
79
82
  prepare(): Promise<void>;
80
83
  onBuildDone(): void;
81
84
  /**
82
- * Send error messages to the client.
83
- */
84
- sendError(errors: Rspack.StatsError[], token: string): void;
85
+ * Send error messages to the client.
86
+ */ sendError(errors: Rspack.StatsError[], token: string): void;
85
87
  /**
86
- * Send warning messages to the client
87
- */
88
- sendWarning(warnings: Rspack.StatsError[], token: string): void;
88
+ * Send warning messages to the client
89
+ */ sendWarning(warnings: Rspack.StatsError[], token: string): void;
89
90
  /**
90
- * Send a server message to matching client sockets.
91
- * @param message - The message to send
92
- * @param token - The token of the socket to send the message to,
93
- * if not provided, the message will be sent to all sockets
94
- */
95
- sendMessage(message: ServerMessage, token?: string): void;
91
+ * Send a server message to matching client sockets.
92
+ * @param message - The message to send
93
+ * @param token - The token of the socket to send the message to,
94
+ * if not provided, the message will be sent to all sockets
95
+ */ sendMessage(message: ServerMessage, token?: string): void;
96
96
  close(): Promise<void>;
97
97
  private onConnect;
98
98
  private getEnvironmentByToken;
99
99
  private getInitialChunks;
100
+ // Cache initial chunks for environments that have no baseline yet.
101
+ // This keeps comparison stable even when no client socket is connected
102
+ // during the first completed build.
100
103
  private ensureInitialChunks;
104
+ // Only use stats when environment is matched
101
105
  private getStats;
106
+ // determine what message should send by stats
102
107
  private sendStats;
108
+ // send a serialized message to a specific socket
103
109
  private sendRawMessage;
104
110
  }
@@ -11,4 +11,4 @@ export type WatchFilesResult = {
11
11
  };
12
12
  export declare function setupWatchFiles(options: WatchFilesOptions): Promise<WatchFilesResult | undefined>;
13
13
  export declare function createChokidar(pathOrGlobs: string[], root: string, options: ChokidarOptions): Promise<FSWatcher>;
14
- export {};
14
+ export { };