@rsbuild/core 2.2.7 → 2.2.8

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,2 @@
1
+ import { type IFs } from 'memfs';
2
+ export declare function createMemoryFileSystem(): IFs;
@@ -1,11 +1,12 @@
1
1
  import type { InternalContext, NormalizedConfig, Rspack } from '../types/index.js';
2
2
  import { type AssetsMiddleware } from './assets-middleware/index.js';
3
- import { SocketServer } from './socketServer.js';
3
+ import { type SocketConnectionListener, SocketServer } from './socketServer.js';
4
4
  type Options = {
5
5
  context: InternalContext;
6
6
  config: NormalizedConfig;
7
7
  compiler: Rspack.Compiler | Rspack.MultiCompiler;
8
8
  resolvedPort: number;
9
+ onSocketConnect?: SocketConnectionListener;
9
10
  };
10
11
  /**
11
12
  * Setup compiler related logic:
@@ -19,7 +20,7 @@ type Options = {
19
20
  private config;
20
21
  private resolvedPort;
21
22
  private context;
22
- constructor({ config, context, compiler, resolvedPort }: Options);
23
+ constructor({ config, context, compiler, resolvedPort, onSocketConnect }: Options);
23
24
  init(): Promise<void>;
24
25
  /**
25
26
  * Call `compiler.watch()` to start compiling.
@@ -10,6 +10,11 @@ type ExtractSocketMessageData<T extends ServerMessage['type']> = 'data' extends
10
10
  type: T;
11
11
  }>['data'] : undefined;
12
12
  export type HotSend = <T extends ServerMessage['type']>(type: T, data?: ExtractSocketMessageData<T>) => void;
13
+ export type HotClient = {
14
+ /** Send an HMR message to this connection only. */ send: HotSend;
15
+ };
16
+ type HotConnectCallback = (client: HotClient) => void | Promise<void>;
17
+ export type HotOnConnect = (callback: HotConnectCallback) => () => void;
13
18
  export type RsbuildDevServer = RsbuildServerBase & {
14
19
  /**
15
20
  * Notifies Rsbuild that the custom server has successfully started.
@@ -1,5 +1,6 @@
1
1
  import type { IncomingMessage } from 'node:http';
2
2
  import type { Socket } from 'node:net';
3
+ import type { WebSocket } from 'ws';
3
4
  import type { DevConfig, InternalContext, Rspack } from '../types/index.js';
4
5
  export type ServerMessageFullReload = {
5
6
  type: 'full-reload';
@@ -61,6 +62,7 @@ export type ClientMessagePing = {
61
62
  type: 'ping';
62
63
  };
63
64
  export type ClientMessage = ClientMessagePing | ClientMessageError;
65
+ export type SocketConnectionListener = (socket: WebSocket, token: string) => void;
64
66
  export declare class SocketServer {
65
67
  private wsServer;
66
68
  private readonly socketsMap;
@@ -71,7 +73,8 @@ export declare class SocketServer {
71
73
  private getOutputFileSystem;
72
74
  private reportedBrowserLogs;
73
75
  private currentHash;
74
- constructor(context: InternalContext, options: DevConfig, getOutputFileSystem: () => Rspack.OutputFileSystem);
76
+ private onSocketConnect?;
77
+ constructor(context: InternalContext, options: DevConfig, getOutputFileSystem: () => Rspack.OutputFileSystem, onSocketConnect?: SocketConnectionListener);
75
78
  // subscribe upgrade event to handle socket
76
79
  upgrade: (req: IncomingMessage, socket: Socket, head: Buffer) => void;
77
80
  // detect and close broken connections
@@ -90,9 +93,9 @@ export declare class SocketServer {
90
93
  /**
91
94
  * Send a server message to matching client sockets.
92
95
  * @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
+ * @param target - An environment token or a single socket.
97
+ * If not provided, the message will be sent to all sockets.
98
+ */ sendMessage(message: ServerMessage, target?: string | WebSocket): void;
96
99
  close(): Promise<void>;
97
100
  private onConnect;
98
101
  private getEnvironmentByToken;
@@ -8,7 +8,7 @@ import type Cors from '../../compiled/cors/index.js';
8
8
  import type { Options as HttpProxyOptions, Filter as ProxyFilter } from '../../compiled/http-proxy-middleware/index.js';
9
9
  import type { RspackChain } from '../../compiled/rspack-chain/types/index.js';
10
10
  import type { FileDescriptor } from '../../compiled/rspack-manifest-plugin/index.js';
11
- import type { HotSend, RsbuildDevServer } from '../server/devServer.js';
11
+ import type { HotOnConnect, HotSend, RsbuildDevServer } from '../server/devServer.js';
12
12
  import type { RsbuildPreviewServer } from '../server/previewServer.js';
13
13
  import type { Logger } from '../logger.js';
14
14
  import type { EnvironmentContext, ModifyBundlerChainUtils, ModifyChainUtils, ReadonlyRoutes, WatchFileEvent } from './hooks.js';
@@ -1444,9 +1444,13 @@ export type EnvironmentAPI = Record<string, {
1444
1444
  * Get the compiled HTML template.
1445
1445
  */ getTransformedHtml: (entryName: string) => Promise<string>;
1446
1446
  /**
1447
- * Send HMR message to the current environment only.
1447
+ * HMR communication for the current environment.
1448
1448
  */ hot: {
1449
1449
  send: HotSend;
1450
+ /**
1451
+ * Listen for accepted HMR connections in this environment.
1452
+ * Returns a function that removes the listener.
1453
+ */ onConnect: HotOnConnect;
1450
1454
  };
1451
1455
  /**
1452
1456
  * Provides some context information about the current environment
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/core",
3
- "version": "2.2.7",
3
+ "version": "2.2.8",
4
4
  "description": "The Rspack-based build tool.",
5
5
  "homepage": "https://rsbuild.rs",
6
6
  "bugs": {
@@ -35,12 +35,13 @@
35
35
  "types.d.ts"
36
36
  ],
37
37
  "dependencies": {
38
- "@rspack/core": "~2.2.5",
38
+ "@rspack/core": "~2.2.6",
39
39
  "@swc/helpers": "^0.5.23"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@jridgewell/remapping": "^2.3.5",
43
43
  "@jridgewell/trace-mapping": "^0.3.31",
44
+ "@jsonjoy.com/fs-core": "4.78.0",
44
45
  "@rstackjs/load-config": "^1.0.0",
45
46
  "@types/cors": "^2.8.19",
46
47
  "@types/node": "^24.13.4",
@@ -61,7 +62,7 @@
61
62
  "http-proxy-middleware": "4.2.0",
62
63
  "jiti": "^2.7.0",
63
64
  "launch-editor-middleware": "^2.14.1",
64
- "memfs": "^4.76.0",
65
+ "memfs": "4.78.0",
65
66
  "mrmime": "^2.0.1",
66
67
  "on-finished": "2.4.1",
67
68
  "open": "^11.0.3",