@rsbuild/core 2.3.3 → 2.3.4

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.
@@ -1,55 +1,93 @@
1
1
  /*! LICENSE: range-parser.js.LICENSE.txt */
2
- import { rspackRequire, moduleFactories } from "./rslib-runtime.js";
3
- moduleFactories.add({
4
- "../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/range-parser/1.3.0/d49e5dcb9d0e39475844e240fad8cd1db6a58f4144f7ede43d9755e2fce5babc/node_modules/range-parser/index.js" (module) {
5
- function parsePos(str) {
6
- return /^\d+$/.test(str) ? Number(str) : 0 / 0;
2
+ function format(obj) {
3
+ let { type, ranges } = obj;
4
+ if (!type || /[^!#$%&'*+\-.^_`|~0-9A-Za-z]/.test(type)) throw TypeError("Invalid range type");
5
+ if (!ranges || 0 === ranges.length) throw TypeError("At least one range is required");
6
+ let parts = [];
7
+ for (let range of ranges){
8
+ if (!range || !Number.isSafeInteger(range.start) || !Number.isSafeInteger(range.end) || range.start < 0 || range.end < range.start) throw TypeError("Invalid range");
9
+ parts.push(`${range.start}-${range.end}`);
10
+ }
11
+ return `${type}=${parts.join(",")}`;
12
+ }
13
+ function parse(size, str) {
14
+ if (!Number.isSafeInteger(size) || size < 0) throw TypeError(`Invalid size: ${size}`);
15
+ let ranges = [], eqIndex = str.indexOf("=");
16
+ if (-1 === eqIndex) return {
17
+ code: 1,
18
+ type: "",
19
+ ranges
20
+ };
21
+ let type = str.slice(0, eqIndex).toLowerCase(), len = str.length, index = eqIndex + 1, code = 0, hasRange = !1, dashIndex = -1;
22
+ do {
23
+ let commaIndex = str.indexOf(",", index), endIndex = -1 !== commaIndex ? commaIndex : len, startStrIndex = index, endStrIndex = endIndex;
24
+ for(; 32 === str.charCodeAt(startStrIndex) || 9 === str.charCodeAt(startStrIndex);)startStrIndex++;
25
+ for(; 32 === str.charCodeAt(endStrIndex - 1) || 9 === str.charCodeAt(endStrIndex - 1);)endStrIndex--;
26
+ if (index = endIndex + 1, startStrIndex >= endStrIndex) continue;
27
+ if (hasRange = !0, dashIndex < startStrIndex && -1 === (dashIndex = str.indexOf("-", startStrIndex)) && (dashIndex = len), dashIndex >= endStrIndex) {
28
+ code |= 1;
29
+ continue;
7
30
  }
8
- function combineRanges(ranges) {
9
- for(var ordered = ranges.map(mapWithIndex).sort(sortByRangeStart), j = 0, i = 1; i < ordered.length; i++){
10
- var range = ordered[i], current = ordered[j];
11
- range.start > current.end + 1 ? ordered[++j] = range : range.end > current.end && (current.end = range.end, current.index = Math.min(current.index, range.index));
31
+ let start = 0 / 0, end = 0 / 0;
32
+ if (startStrIndex === dashIndex) {
33
+ if (endStrIndex === dashIndex + 1) {
34
+ code |= 1;
35
+ continue;
12
36
  }
13
- ordered.length = j + 1;
14
- var combined = ordered.sort(sortByRangeIndex).map(mapWithoutIndex);
15
- return combined.type = ranges.type, combined;
16
- }
17
- function mapWithIndex(range, index) {
18
- return {
19
- start: range.start,
20
- end: range.end,
21
- index: index
22
- };
23
- }
24
- function mapWithoutIndex(range) {
25
- return {
26
- start: range.start,
27
- end: range.end
28
- };
37
+ let suffixLength = parsePos(str, dashIndex + 1, endStrIndex);
38
+ if (0 === size && suffixLength > 0) continue;
39
+ start = Math.max(size - suffixLength, 0), end = size - 1;
40
+ } else if (start = parsePos(str, startStrIndex, dashIndex), endStrIndex === dashIndex + 1) end = size - 1;
41
+ else {
42
+ if (start > (end = parsePos(str, dashIndex + 1, endStrIndex))) {
43
+ code |= 1;
44
+ continue;
45
+ }
46
+ end > size - 1 && (end = size - 1);
29
47
  }
30
- function sortByRangeIndex(a, b) {
31
- return a.index - b.index;
48
+ if (Number.isNaN(start) || Number.isNaN(end)) {
49
+ code |= 1;
50
+ continue;
32
51
  }
33
- function sortByRangeStart(a, b) {
34
- return a.start - b.start;
52
+ if (start > end) {
53
+ code |= 2;
54
+ continue;
35
55
  }
36
- module.exports = function rangeParser(size, str, options) {
37
- if ('string' != typeof str) throw TypeError('argument str must be a string');
38
- var index = str.indexOf('=');
39
- if (-1 === index) return -2;
40
- var arr = str.slice(index + 1).split(','), ranges = [];
41
- ranges.type = str.slice(0, index);
42
- for(var i = 0; i < arr.length; i++){
43
- var indexOf = arr[i].indexOf('-');
44
- if (-1 === indexOf) return -2;
45
- var startStr = arr[i].slice(0, indexOf).trim(), endStr = arr[i].slice(indexOf + 1).trim(), start = parsePos(startStr), end = parsePos(endStr);
46
- if (0 === startStr.length ? (start = size - end, end = size - 1) : 0 === endStr.length && (end = size - 1), end > size - 1 && (end = size - 1), isNaN(start) || isNaN(end)) return -2;
47
- start > end || start < 0 || ranges.push({
48
- start: start,
49
- end: end
50
- });
51
- }
52
- return ranges.length < 1 ? -1 : options && options.combine ? combineRanges(ranges) : ranges;
53
- };
56
+ ranges.push({
57
+ start: start,
58
+ end: end
59
+ });
60
+ }while (index < len);
61
+ return hasRange ? {
62
+ code,
63
+ type,
64
+ ranges
65
+ } : {
66
+ code: 1,
67
+ type,
68
+ ranges
69
+ };
70
+ }
71
+ function parsePos(str, start, end) {
72
+ let value = 0;
73
+ for(let i = start; i < end; i++){
74
+ let code = str.charCodeAt(i);
75
+ if (code < 48 || code > 57) return 0 / 0;
76
+ value = 10 * value + (code - 48);
77
+ }
78
+ return value;
79
+ }
80
+ function combineRanges(ranges) {
81
+ if (0 === ranges.length) return [];
82
+ let ordered = ranges.map((range, index)=>({
83
+ start: range.start,
84
+ end: range.end,
85
+ index
86
+ })).sort((a, b)=>a.start - b.start), j = 0;
87
+ for(let i = 1; i < ordered.length; i++){
88
+ let range = ordered[i], current = ordered[j];
89
+ range.start > current.end + 1 ? ordered[++j] = range : (current.end = Math.max(current.end, range.end), current.index = Math.min(current.index, range.index));
54
90
  }
55
- }), rspackRequire("../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/range-parser/1.3.0/d49e5dcb9d0e39475844e240fad8cd1db6a58f4144f7ede43d9755e2fce5babc/node_modules/range-parser/index.js");
91
+ return ordered.length = j + 1, ordered.sort((a, b)=>a.index - b.index);
92
+ }
93
+ export { combineRanges, format, parse };
@@ -12,12 +12,12 @@ var moduleFactories = modules, compatGetDefaultExport = (module)=>{
12
12
  return definePropertyGetters(getter, {
13
13
  a: getter
14
14
  }), getter;
15
- }, getProto = Object.getPrototypeOf ? (obj)=>Object.getPrototypeOf(obj) : (obj)=>obj.__proto__, createFakeNamespaceObject = function(value, mode) {
15
+ }, getProto = Object.getPrototypeOf, createFakeNamespaceObject = function(value, mode) {
16
16
  if (1 & mode && (value = ("function" == typeof this ? this : this.r)(value)), 8 & mode || 'object' == typeof value && value && (4 & mode && value.__esModule || 16 & mode && 'function' == typeof value.then)) return value;
17
17
  var ns = Object.create(null);
18
18
  makeNamespaceObject(ns);
19
19
  var def = {};
20
- leafPrototypes = leafPrototypes || [
20
+ leafPrototypes ||= [
21
21
  null,
22
22
  getProto({}),
23
23
  getProto([]),
@@ -40,10 +40,13 @@ moduleFactories.add = function registerModules(modules) {
40
40
  Object.assign(moduleFactories, modules);
41
41
  };
42
42
  var hasOwnProperty = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop), makeNamespaceObject = (exports)=>{
43
- "u" > typeof Symbol && Symbol.toStringTag && Object.defineProperty(exports, Symbol.toStringTag, {
44
- value: 'Module'
45
- }), Object.defineProperty(exports, '__esModule', {
46
- value: !0
43
+ Object.defineProperties(exports, {
44
+ [Symbol.toStringTag]: {
45
+ value: 'Module'
46
+ },
47
+ __esModule: {
48
+ value: !0
49
+ }
47
50
  });
48
51
  };
49
52
  export { rspackRequire, moduleFactories, compatGetDefaultExport, createFakeNamespaceObject, definePropertyGetters, makeNamespaceObject };
@@ -1,12 +1,13 @@
1
1
  import type { InternalContext, NormalizedConfig, Rspack } from '../types/index.js';
2
2
  import { type AssetsMiddleware } from './assets-middleware/index.js';
3
- import { type SocketConnectionListener, SocketServer } from './socketServer.js';
3
+ import { type SocketConnectionListener, type SocketCustomMessageListener, 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
9
  onSocketConnect?: SocketConnectionListener;
10
+ onSocketCustomMessage?: SocketCustomMessageListener;
10
11
  };
11
12
  /**
12
13
  * Setup compiler related logic:
@@ -20,7 +21,7 @@ type Options = {
20
21
  private config;
21
22
  private resolvedPort;
22
23
  private context;
23
- constructor({ config, context, compiler, resolvedPort, onSocketConnect }: Options);
24
+ constructor({ config, context, compiler, resolvedPort, onSocketConnect, onSocketCustomMessage }: Options);
24
25
  init(): Promise<void>;
25
26
  /**
26
27
  * Call `compiler.watch()` to start compiling.
@@ -15,6 +15,8 @@ export type HotClient = {
15
15
  };
16
16
  type HotConnectCallback = (client: HotClient) => void | Promise<void>;
17
17
  export type HotOnConnect = (callback: HotConnectCallback) => () => void;
18
+ type HotEventCallback<Data = any> = (data: Data, client: HotClient) => void | Promise<void>;
19
+ export type HotOn = <Data = any>(event: string, callback: HotEventCallback<Data>) => () => void;
18
20
  export type RsbuildDevServer = RsbuildServerBase & {
19
21
  /**
20
22
  * Notifies Rsbuild that the custom server has successfully started.
@@ -66,8 +66,14 @@ export type ClientMessageError = {
66
66
  export type ClientMessagePing = {
67
67
  type: 'ping';
68
68
  };
69
- export type ClientMessage = ClientMessagePing | ClientMessageError;
69
+ export type ClientMessageCustom = {
70
+ type: 'custom';
71
+ event: string;
72
+ data?: unknown;
73
+ };
74
+ export type ClientMessage = ClientMessagePing | ClientMessageError | ClientMessageCustom;
70
75
  export type SocketConnectionListener = (socket: WebSocket, token: string) => void;
76
+ export type SocketCustomMessageListener = (socket: WebSocket, token: string, event: string, data: unknown) => void;
71
77
  export declare class SocketServer {
72
78
  private wsServer;
73
79
  private readonly socketsMap;
@@ -83,7 +89,8 @@ export declare class SocketServer {
83
89
  * multi-environment build is done, keyed by WebSocket token.
84
90
  */ private environmentStats;
85
91
  private onSocketConnect?;
86
- constructor(context: InternalContext, options: DevConfig, getOutputFileSystem: () => Rspack.OutputFileSystem, onSocketConnect?: SocketConnectionListener);
92
+ private onSocketCustomMessage?;
93
+ constructor(context: InternalContext, options: DevConfig, getOutputFileSystem: () => Rspack.OutputFileSystem, onSocketConnect?: SocketConnectionListener, onSocketCustomMessage?: SocketCustomMessageListener);
87
94
  // subscribe upgrade event to handle socket
88
95
  upgrade: (req: IncomingMessage, socket: Socket, head: Buffer) => void;
89
96
  // detect and close broken connections
@@ -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 { HotOnConnect, HotSend, RsbuildDevServer } from '../server/devServer.js';
11
+ import type { HotOn, 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';
@@ -1478,6 +1478,11 @@ export type EnvironmentAPI = Record<string, {
1478
1478
  * Listen for accepted HMR connections in this environment.
1479
1479
  * Returns a function that removes the listener.
1480
1480
  */ onConnect: HotOnConnect;
1481
+ /**
1482
+ * Listen for custom events sent by `import.meta.webpackHot.send()`
1483
+ * from HMR clients in this environment.
1484
+ * Returns a function that removes the listener.
1485
+ */ on: HotOn;
1481
1486
  };
1482
1487
  /**
1483
1488
  * Provides some context information about the current environment
@@ -1599,7 +1604,7 @@ export interface DevConfig {
1599
1604
  };
1600
1605
  /**
1601
1606
  * Whether to enable Hot Module Replacement.
1602
- * @default true
1607
+ * @default true in `development` mode, false otherwise
1603
1608
  */ hmr?: boolean;
1604
1609
  /**
1605
1610
  * Whether to reload the page when file changes are detected.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/core",
3
- "version": "2.3.3",
3
+ "version": "2.3.4",
4
4
  "description": "The Rspack-based build tool.",
5
5
  "homepage": "https://rsbuild.rs",
6
6
  "bugs": {
@@ -14,10 +14,7 @@
14
14
  "license": "MIT",
15
15
  "type": "module",
16
16
  "exports": {
17
- ".": {
18
- "types": "./dist/index.d.ts",
19
- "default": "./dist/index.js"
20
- },
17
+ ".": "./dist/index.js",
21
18
  "./jiti": {
22
19
  "types": "./compiled/jiti/lib/jiti.d.mts",
23
20
  "default": "./compiled/jiti/lib/jiti.mjs"
@@ -39,7 +36,7 @@
39
36
  "types.d.ts"
40
37
  ],
41
38
  "dependencies": {
42
- "@rspack/core": "~2.3.3",
39
+ "@rspack/core": "~2.3.4",
43
40
  "@swc/helpers": "^0.5.24"
44
41
  },
45
42
  "devDependencies": {
@@ -49,10 +46,9 @@
49
46
  "@rstackjs/load-config": "^1.0.2",
50
47
  "@types/cors": "^2.8.19",
51
48
  "@types/node": "^26.6.6",
52
- "@types/range-parser": "^1.2.7",
53
49
  "@types/ws": "^8.18.2",
54
50
  "browserslist-load-config": "^1.0.4",
55
- "cac": "^7.1.0",
51
+ "cac": "^7.1.1",
56
52
  "chokidar": "^6.0.0",
57
53
  "connect-next": "5.0.0",
58
54
  "core-js": "^3.51.0",
@@ -62,7 +58,7 @@
62
58
  "dotenv-expand": "^13.0.0",
63
59
  "fresh-import": "^0.2.1",
64
60
  "html-rspack-plugin": "6.1.11",
65
- "http-proxy-middleware": "4.2.1",
61
+ "http-proxy-middleware": "4.2.2",
66
62
  "jiti": "^2.7.0",
67
63
  "launch-editor-middleware": "^2.14.2",
68
64
  "memfs": "4.80.1",
@@ -70,9 +66,9 @@
70
66
  "open": "^11.0.4",
71
67
  "postcss": "^8.5.33",
72
68
  "postcss-load-config": "6.0.1",
73
- "postcss-loader": "8.2.1",
69
+ "postcss-loader": "8.2.2",
74
70
  "prebundle": "1.6.5",
75
- "range-parser": "^1.3.0",
71
+ "range-parser": "^2.0.0",
76
72
  "reduce-configs": "^2.0.1",
77
73
  "rslog": "^2.3.0",
78
74
  "rspack-chain": "^2.3.3",
package/types.d.ts CHANGED
@@ -80,7 +80,16 @@ interface ImportMeta {
80
80
 
81
81
  declare namespace Rspack {
82
82
  interface Hot {
83
+ /**
84
+ * Listen for custom events sent by the dev server.
85
+ */
83
86
  on: <Data = any>(event: string, cb: (data: Data) => void) => void;
87
+ /**
88
+ * Send a custom event to the dev server, handled by
89
+ * `server.environments[name].hot.on()`.
90
+ * The data must be JSON serializable.
91
+ */
92
+ send: <Data = unknown>(event: string, data?: Data) => void;
84
93
  }
85
94
  }
86
95