@rsbuild/core 0.5.4 → 0.5.6

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.
@@ -39,7 +39,7 @@ const applyServerOptions = (command) => {
39
39
  command.option("-o --open [url]", "open the page in browser on startup").option("--port <port>", "specify a port number for server to listen").option("--host <host>", "specify the host that the server listens to");
40
40
  };
41
41
  function runCli() {
42
- import_commander.program.name("rsbuild").usage("<command> [options]").version("0.5.4");
42
+ import_commander.program.name("rsbuild").usage("<command> [options]").version("0.5.6");
43
43
  const devCommand = import_commander.program.command("dev");
44
44
  const buildCommand = import_commander.program.command("build");
45
45
  const previewCommand = import_commander.program.command("preview");
@@ -34,7 +34,7 @@ function prepareCli() {
34
34
  if (!npm_execpath || npm_execpath.includes("npx-cli.js") || npm_execpath.includes(".bun")) {
35
35
  console.log();
36
36
  }
37
- import_rslog.logger.greet(` ${`Rsbuild v${"0.5.4"}`}
37
+ import_rslog.logger.greet(` ${`Rsbuild v${"0.5.6"}`}
38
38
  `);
39
39
  }
40
40
  // Annotate the CommonJS export names for ESM import in node:
@@ -2,7 +2,8 @@
2
2
  * hmr socket connect path
3
3
  */
4
4
  export declare const HMR_SOCK_PATH = "/rsbuild-hmr";
5
- export declare function createSocketUrl(resourceQuery: string): string;
5
+ export declare function parseParams(resourceQuery: string): Record<string, string>;
6
+ export declare function createSocketUrl(options?: Record<string, string>): string;
6
7
  export declare function formatURL({ port, protocol, hostname, pathname, }: {
7
8
  port: string;
8
9
  protocol: string;
@@ -0,0 +1,2 @@
1
+ export declare function createOverlay(err: string[]): void;
2
+ export declare function clearOverlay(): void;
@@ -7,6 +7,12 @@ function _array_like_to_array(arr, len) {
7
7
  function _array_with_holes(arr) {
8
8
  if (Array.isArray(arr)) return arr;
9
9
  }
10
+ function _assert_this_initialized(self1) {
11
+ if (self1 === void 0) {
12
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
13
+ }
14
+ return self1;
15
+ }
10
16
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
11
17
  try {
12
18
  var info = gen[key](arg);
@@ -36,6 +42,63 @@ function _async_to_generator(fn) {
36
42
  });
37
43
  };
38
44
  }
45
+ function _class_call_check(instance, Constructor) {
46
+ if (!(instance instanceof Constructor)) {
47
+ throw new TypeError("Cannot call a class as a function");
48
+ }
49
+ }
50
+ function _construct(Parent, args, Class) {
51
+ if (_is_native_reflect_construct()) {
52
+ _construct = Reflect.construct;
53
+ } else {
54
+ _construct = function construct(Parent, args, Class) {
55
+ var a = [
56
+ null
57
+ ];
58
+ a.push.apply(a, args);
59
+ var Constructor = Function.bind.apply(Parent, a);
60
+ var instance = new Constructor();
61
+ if (Class) _set_prototype_of(instance, Class.prototype);
62
+ return instance;
63
+ };
64
+ }
65
+ return _construct.apply(null, arguments);
66
+ }
67
+ function _define_property(obj, key, value) {
68
+ if (key in obj) {
69
+ Object.defineProperty(obj, key, {
70
+ value: value,
71
+ enumerable: true,
72
+ configurable: true,
73
+ writable: true
74
+ });
75
+ } else {
76
+ obj[key] = value;
77
+ }
78
+ return obj;
79
+ }
80
+ function _get_prototype_of(o) {
81
+ _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
82
+ return o.__proto__ || Object.getPrototypeOf(o);
83
+ };
84
+ return _get_prototype_of(o);
85
+ }
86
+ function _inherits(subClass, superClass) {
87
+ if (typeof superClass !== "function" && superClass !== null) {
88
+ throw new TypeError("Super expression must either be null or a function");
89
+ }
90
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
91
+ constructor: {
92
+ value: subClass,
93
+ writable: true,
94
+ configurable: true
95
+ }
96
+ });
97
+ if (superClass) _set_prototype_of(subClass, superClass);
98
+ }
99
+ function _is_native_function(fn) {
100
+ return Function.toString.call(fn).indexOf("[native code]") !== -1;
101
+ }
39
102
  function _iterable_to_array_limit(arr, i) {
40
103
  var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
41
104
  if (_i == null) return;
@@ -63,9 +126,26 @@ function _iterable_to_array_limit(arr, i) {
63
126
  function _non_iterable_rest() {
64
127
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
65
128
  }
129
+ function _possible_constructor_return(self1, call) {
130
+ if (call && (_type_of(call) === "object" || typeof call === "function")) {
131
+ return call;
132
+ }
133
+ return _assert_this_initialized(self1);
134
+ }
135
+ function _set_prototype_of(o, p) {
136
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
137
+ o.__proto__ = p;
138
+ return o;
139
+ };
140
+ return _set_prototype_of(o, p);
141
+ }
66
142
  function _sliced_to_array(arr, i) {
67
143
  return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
68
144
  }
145
+ function _type_of(obj) {
146
+ "@swc/helpers - typeof";
147
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
148
+ }
69
149
  function _unsupported_iterable_to_array(o, minLen) {
70
150
  if (!o) return;
71
151
  if (typeof o === "string") return _array_like_to_array(o, minLen);
@@ -74,6 +154,56 @@ function _unsupported_iterable_to_array(o, minLen) {
74
154
  if (n === "Map" || n === "Set") return Array.from(n);
75
155
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
76
156
  }
157
+ function _wrap_native_super(Class) {
158
+ var _cache = typeof Map === "function" ? new Map() : undefined;
159
+ _wrap_native_super = function wrapNativeSuper(Class) {
160
+ if (Class === null || !_is_native_function(Class)) return Class;
161
+ if (typeof Class !== "function") {
162
+ throw new TypeError("Super expression must either be null or a function");
163
+ }
164
+ if (typeof _cache !== "undefined") {
165
+ if (_cache.has(Class)) return _cache.get(Class);
166
+ _cache.set(Class, Wrapper);
167
+ }
168
+ function Wrapper() {
169
+ return _construct(Class, arguments, _get_prototype_of(this).constructor);
170
+ }
171
+ Wrapper.prototype = Object.create(Class.prototype, {
172
+ constructor: {
173
+ value: Wrapper,
174
+ enumerable: false,
175
+ writable: true,
176
+ configurable: true
177
+ }
178
+ });
179
+ return _set_prototype_of(Wrapper, Class);
180
+ };
181
+ return _wrap_native_super(Class);
182
+ }
183
+ function _is_native_reflect_construct() {
184
+ if (typeof Reflect === "undefined" || !Reflect.construct) return false;
185
+ if (Reflect.construct.sham) return false;
186
+ if (typeof Proxy === "function") return true;
187
+ try {
188
+ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
189
+ return true;
190
+ } catch (e) {
191
+ return false;
192
+ }
193
+ }
194
+ function _create_super(Derived) {
195
+ var hasNativeReflectConstruct = _is_native_reflect_construct();
196
+ return function _createSuperInternal() {
197
+ var Super = _get_prototype_of(Derived), result;
198
+ if (hasNativeReflectConstruct) {
199
+ var NewTarget = _get_prototype_of(this).constructor;
200
+ result = Reflect.construct(Super, arguments, NewTarget);
201
+ } else {
202
+ result = Super.apply(this, arguments);
203
+ }
204
+ return _possible_constructor_return(this, result);
205
+ };
206
+ }
77
207
  function _ts_generator(thisArg, body) {
78
208
  var f, y, t, g, _ = {
79
209
  label: 0,
@@ -229,15 +359,15 @@ function formatStatsMessages(json) {
229
359
  }
230
360
  // src/client/hmr/createSocketUrl.ts
231
361
  var HMR_SOCK_PATH = "/rsbuild-hmr";
232
- function createSocketUrl(resourceQuery) {
362
+ function parseParams(resourceQuery) {
233
363
  var searchParams = resourceQuery.substr(1).split("&");
234
- var options = {};
364
+ var options2 = {};
235
365
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
236
366
  try {
237
367
  for(var _iterator = searchParams[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
238
368
  var pair = _step.value;
239
369
  var ary = pair.split("=");
240
- options[ary[0]] = decodeURIComponent(ary[1]);
370
+ options2[ary[0]] = decodeURIComponent(ary[1]);
241
371
  }
242
372
  } catch (err) {
243
373
  _didIteratorError = true;
@@ -253,8 +383,12 @@ function createSocketUrl(resourceQuery) {
253
383
  }
254
384
  }
255
385
  }
386
+ return options2;
387
+ }
388
+ function createSocketUrl() {
389
+ var options2 = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
256
390
  var currentLocation = self.location;
257
- return getSocketUrl(options, currentLocation);
391
+ return getSocketUrl(options2, currentLocation);
258
392
  }
259
393
  function formatURL(param) {
260
394
  var port = param.port, protocol = param.protocol, hostname = param.hostname, pathname = param.pathname;
@@ -278,8 +412,125 @@ function getSocketUrl(urlParts, location) {
278
412
  pathname: path || HMR_SOCK_PATH
279
413
  });
280
414
  }
415
+ // src/client/hmr/overlay.ts
416
+ function stripAnsi(content) {
417
+ var pattern = [
418
+ "[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
419
+ "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))"
420
+ ].join("|");
421
+ var regex = new RegExp(pattern, "g");
422
+ return content.replace(regex, "");
423
+ }
424
+ function linkedText(root, selector, text) {
425
+ var _loop = function() {
426
+ var file = match[0], index = match.index;
427
+ if (index != null) {
428
+ var frag2 = text.slice(curIndex, index);
429
+ el.appendChild(document.createTextNode(frag2));
430
+ var link = document.createElement("a");
431
+ link.textContent = file;
432
+ link.className = "file-link";
433
+ link.onclick = function() {
434
+ fetch("/__open-in-editor?file=".concat(encodeURIComponent(file)));
435
+ };
436
+ el.appendChild(link);
437
+ curIndex += frag2.length + file.length;
438
+ }
439
+ match = fileRegex.exec(text);
440
+ };
441
+ var el = root.querySelector(selector);
442
+ var fileRegex = /(?:[a-zA-Z]:\\|\/).*?:\d+:\d+/g;
443
+ var curIndex = 0;
444
+ var match = fileRegex.exec(text);
445
+ while(match !== null)_loop();
446
+ var frag = text.slice(curIndex);
447
+ el.appendChild(document.createTextNode(frag));
448
+ }
449
+ var overlayTemplate = '\n<style>\n.root {\n position: fixed;\n z-index: 9999;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n overflow-y: scroll;\n margin: 0;\n background: rgba(0, 0, 0, 0.66);\n cursor: pointer;\n}\n.container {\n font-family: Menlo, Consolas, monospace;\n line-height: 1.6;\n width: 800px;\n max-width: 85%;\n color: #d8d8d8;\n margin: 32px auto;\n padding: 32px 40px;\n position: relative;\n background: #181818;\n border-radius: 24px;\n box-shadow: 0 19px 38px rgba(0,0,0,0.30), 0 15px 12px rgba(0,0,0,0.22);\n overflow: hidden;\n direction: ltr;\n text-align: left;\n box-sizing: border-box;\n cursor: default;\n}\n.title {\n margin: 0 0 20px;\n padding-bottom: 12px;\n font-size: 17px;\n font-weight: 600;\n color: #fc5e5e;\n border-bottom: 2px solid rgba(252,94,94,.66);\n}\n.content {\n margin: 0;\n font-size: 14px;\n font-family: inherit;\n overflow-x: scroll;\n scrollbar-width: none;\n color: #b8b8b8;\n}\n.content::-webkit-scrollbar {\n display: none;\n}\n.file-link {\n cursor: pointer;\n color: #27caca;\n text-decoration: underline;\n &:hover {\n opacity: 0.8;\n }\n &:active {\n opacity: 0.6;\n }\n}\n.close {\n position: absolute;\n top: 27px;\n right: 32px;\n width: 32px;\n height: 32px;\n cursor: pointer;\n}\n.close:hover {\n opacity: 0.8;\n}\n.close:active {\n opacity: 0.6;\n}\n.close:before,\n.close:after {\n position: absolute;\n left: 16px;\n top: 8px;\n content: \' \';\n height: 18px;\n width: 2px;\n border-radius: 4px;\n background-color: #b8b8b8;\n}\n.close:before {\n transform: rotate(45deg);\n}\n.close:after {\n transform: rotate(-45deg);\n}\n.footer {\n font-size: 12px;\n color: #7e6a92;\n margin-top: 20px;\n padding-top: 12px;\n border-top: 2px solid rgba(126,106,146,.6);\n}\n.footer p {\n margin: 4px 0 0;\n}\n.footer span {\n color: #a88dc3;\n}\n</style>\n\n<div class="root">\n <div class="container">\n <div class="close"></div>\n <p class="title">Compilation failed</p>\n <pre class="content"></pre>\n <footer class="footer">\n <p><span>Fix error</span>, click outside, or press Esc to close the overlay.</p>\n <p>Disable overlay by setting Rsbuild\'s <span>dev.client.overlay</span> config to false.<p>\n </footer>\n </div>\n</div>\n';
450
+ var _globalThis_HTMLElement = globalThis.HTMLElement, HTMLElement = _globalThis_HTMLElement === void 0 ? function HTMLElement() {
451
+ "use strict";
452
+ _class_call_check(this, HTMLElement);
453
+ } : _globalThis_HTMLElement, customElements = globalThis.customElements;
454
+ var ErrorOverlay = /*#__PURE__*/ function(HTMLElement) {
455
+ "use strict";
456
+ _inherits(ErrorOverlay, HTMLElement);
457
+ var _super = _create_super(ErrorOverlay);
458
+ function ErrorOverlay(message) {
459
+ _class_call_check(this, ErrorOverlay);
460
+ var _this;
461
+ var _root_querySelector;
462
+ _this = _super.call(this);
463
+ _define_property(_assert_this_initialized(_this), "close", function() {
464
+ var remove = function() {
465
+ var _this_parentNode;
466
+ return (_this_parentNode = _this.parentNode) === null || _this_parentNode === void 0 ? void 0 : _this_parentNode.removeChild(_assert_this_initialized(_this));
467
+ };
468
+ if (_this.animate) {
469
+ _this.animate([
470
+ {
471
+ opacity: 1
472
+ },
473
+ {
474
+ opacity: 0
475
+ }
476
+ ], {
477
+ duration: 300,
478
+ easing: "ease-out"
479
+ }).addEventListener("finish", remove);
480
+ } else {
481
+ remove();
482
+ }
483
+ });
484
+ if (!_this.attachShadow) {
485
+ console.warn("[Rsbuild] Current browser version does not support displaying error overlay");
486
+ return _possible_constructor_return(_this);
487
+ }
488
+ var root = _this.attachShadow({
489
+ mode: "open"
490
+ });
491
+ root.innerHTML = overlayTemplate;
492
+ linkedText(root, ".content", stripAnsi(message.join("/n")).trim());
493
+ (_root_querySelector = root.querySelector(".close")) === null || _root_querySelector === void 0 ? void 0 : _root_querySelector.addEventListener("click", _this.close);
494
+ _this.addEventListener("click", _this.close);
495
+ root.querySelector(".container").addEventListener("click", function(e) {
496
+ e.stopPropagation();
497
+ });
498
+ var onEscKeydown = function(e) {
499
+ if (e.key === "Escape" || e.code === "Escape") {
500
+ _this.close();
501
+ }
502
+ document.removeEventListener("keydown", onEscKeydown);
503
+ };
504
+ document.addEventListener("keydown", onEscKeydown);
505
+ return _this;
506
+ }
507
+ return ErrorOverlay;
508
+ }(_wrap_native_super(HTMLElement));
509
+ var overlayId = "rsbuild-error-overlay";
510
+ if (customElements && !customElements.get(overlayId)) {
511
+ customElements.define(overlayId, ErrorOverlay);
512
+ }
513
+ var documentAvailable = typeof document !== "undefined";
514
+ function createOverlay(err) {
515
+ if (!documentAvailable) {
516
+ console.info("[Rsbuild] Failed to display error overlay as document is not available, you can disable the `dev.client.overlay` option.");
517
+ return;
518
+ }
519
+ clearOverlay();
520
+ document.body.appendChild(new ErrorOverlay(err));
521
+ }
522
+ function clearOverlay() {
523
+ if (!documentAvailable) {
524
+ return;
525
+ }
526
+ document.querySelectorAll(overlayId).forEach(function(n) {
527
+ return n.close();
528
+ });
529
+ }
281
530
  // src/client/hmr/index.ts
282
- var socketUrl = createSocketUrl(__resourceQuery);
531
+ var options = parseParams(__resourceQuery);
532
+ var socketUrl = createSocketUrl(options);
533
+ var enableOverlay = options.overlay === "true";
283
534
  var isFirstCompilation = true;
284
535
  var mostRecentCompilationHash = null;
285
536
  var hasCompileErrors = false;
@@ -354,6 +605,9 @@ function handleErrors(errors) {
354
605
  }
355
606
  }
356
607
  }
608
+ if (enableOverlay) {
609
+ createOverlay(formatted.errors);
610
+ }
357
611
  }
358
612
  function handleAvailableHash(hash) {
359
613
  mostRecentCompilationHash = hash;
@@ -403,12 +657,16 @@ function onMessage(e) {
403
657
  var message = JSON.parse(e.data);
404
658
  switch(message.type){
405
659
  case "hash":
660
+ if (enableOverlay) {
661
+ clearOverlay();
662
+ }
406
663
  handleAvailableHash(message.data);
407
664
  break;
408
665
  case "still-ok":
409
666
  case "ok":
410
667
  handleSuccess();
411
668
  break;
669
+ case "static-changed":
412
670
  case "content-changed":
413
671
  window.location.reload();
414
672
  break;
package/dist/index.js CHANGED
@@ -38,7 +38,7 @@ var import_config = require("./config");
38
38
  var import_shared = require("@rsbuild/shared");
39
39
  var import_mergeConfig = require("./mergeConfig");
40
40
  var import_constants = require("./constants");
41
- const version = "0.5.4";
41
+ const version = "0.5.6";
42
42
  // Annotate the CommonJS export names for ESM import in node:
43
43
  0 && (module.exports = {
44
44
  PLUGIN_CSS_NAME,
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
  var build_exports = {};
20
30
  __export(build_exports, {
@@ -50,11 +60,13 @@ const build = async (initOptions, { mode = "production", watch, compiler: custom
50
60
  isFirstCompile = false;
51
61
  await p;
52
62
  };
53
- if ((0, import_shared.isMultiCompiler)(compiler)) {
54
- compiler.hooks.done.tap("rsbuild:done", onDone);
55
- } else {
56
- compiler.hooks.done.tapPromise("rsbuild:done", onDone);
57
- }
63
+ const { MultiStats: MultiStatsStor } = await Promise.resolve().then(() => __toESM(require("@rspack/core")));
64
+ (0, import_shared.onCompileDone)(
65
+ compiler,
66
+ onDone,
67
+ // @ts-expect-error type mismatch
68
+ MultiStatsStor
69
+ );
58
70
  if (watch) {
59
71
  compiler.watch({}, (err) => {
60
72
  if (err) {
@@ -109,11 +109,13 @@ async function createCompiler({
109
109
  isCompiling = false;
110
110
  isFirstCompile = false;
111
111
  };
112
- if ((0, import_shared.isMultiCompiler)(compiler)) {
113
- compiler.hooks.done.tap("rsbuild:done", done);
114
- } else {
115
- compiler.hooks.done.tapPromise("rsbuild:done", done);
116
- }
112
+ const { MultiStats: MultiStatsStor } = await Promise.resolve().then(() => __toESM(require("@rspack/core")));
113
+ (0, import_shared.onCompileDone)(
114
+ compiler,
115
+ done,
116
+ // @ts-expect-error type mismatch
117
+ MultiStatsStor
118
+ );
117
119
  await context.hooks.onAfterCreateCompiler.call({ compiler });
118
120
  (0, import_shared.debug)("create compiler done");
119
121
  return compiler;
@@ -44,7 +44,7 @@ async function createContextByConfig(options, bundlerType, config = {}) {
44
44
  const context = {
45
45
  entry: (0, import_entry.getEntryObject)(config, "web"),
46
46
  targets: config.output?.targets || [],
47
- version: "0.5.4",
47
+ version: "0.5.6",
48
48
  rootPath,
49
49
  distPath,
50
50
  cachePath,
@@ -63,11 +63,23 @@ function getPluginAPI({
63
63
  {}
64
64
  );
65
65
  };
66
+ const exposed = [];
67
+ const expose = (id, api) => {
68
+ exposed.push({ id, api });
69
+ };
70
+ const useExposed = (id) => {
71
+ const matched = exposed.find((item) => item.id === id);
72
+ if (matched) {
73
+ return matched.api;
74
+ }
75
+ };
66
76
  (0, import_shared.onExitProcess)(() => {
67
77
  hooks.onExit.call();
68
78
  });
69
79
  return {
70
80
  context: publicContext,
81
+ expose,
82
+ useExposed,
71
83
  getHTMLPaths,
72
84
  getRsbuildConfig,
73
85
  getNormalizedConfig,
@@ -1,11 +1,14 @@
1
- import { type Stats, type MultiStats } from '@rsbuild/shared';
1
+ import { type Stats, type MultiStats, type StatsError } from '@rsbuild/shared';
2
2
  import type { RsbuildPlugin } from '../types';
3
3
  import { type Plugins } from '@rsbuild/shared';
4
+ import type { StatsCompilation } from '@rspack/core';
4
5
  export declare const applyDefaultPlugins: (plugins: Plugins) => import("@rsbuild/shared").AwaitableGetter<RsbuildPlugin>;
5
6
  export declare const rspackMinVersion = "0.5.0";
6
7
  export declare const isSatisfyRspackVersion: (originalVersion: string) => Promise<boolean>;
7
8
  export declare const getCompiledPath: (packageName: string) => string;
8
9
  export declare const BUILTIN_LOADER = "builtin:";
10
+ export declare const getAllStatsErrors: (statsData: StatsCompilation) => StatsError[] | undefined;
11
+ export declare const getAllStatsWarnings: (statsData: StatsCompilation) => StatsError[] | undefined;
9
12
  export declare function formatStats(stats: Stats | MultiStats): {
10
13
  message: string;
11
14
  level: string;
@@ -31,6 +31,8 @@ __export(shared_exports, {
31
31
  BUILTIN_LOADER: () => BUILTIN_LOADER,
32
32
  applyDefaultPlugins: () => applyDefaultPlugins,
33
33
  formatStats: () => formatStats,
34
+ getAllStatsErrors: () => getAllStatsErrors,
35
+ getAllStatsWarnings: () => getAllStatsWarnings,
34
36
  getCompiledPath: () => getCompiledPath,
35
37
  isSatisfyRspackVersion: () => isSatisfyRspackVersion,
36
38
  rspackMinVersion: () => rspackMinVersion
@@ -187,11 +189,33 @@ function formatErrorMessage(errors) {
187
189
  ${tip}
188
190
  ${text}`;
189
191
  }
192
+ const getAllStatsErrors = (statsData) => {
193
+ if (statsData.errorsCount && statsData.errors?.length === 0) {
194
+ return statsData.children?.reduce(
195
+ (errors, curr) => errors.concat(curr.errors || []),
196
+ []
197
+ );
198
+ }
199
+ return statsData.errors;
200
+ };
201
+ const getAllStatsWarnings = (statsData) => {
202
+ if (statsData.warningsCount && statsData.warnings?.length === 0) {
203
+ return statsData.children?.reduce(
204
+ (warnings, curr) => warnings.concat(curr.warnings || []),
205
+ []
206
+ );
207
+ }
208
+ return statsData.warnings;
209
+ };
190
210
  function formatStats(stats) {
191
211
  const statsData = stats.toJson({
192
- preset: "errors-warnings"
212
+ preset: "errors-warnings",
213
+ children: true
214
+ });
215
+ const { errors, warnings } = (0, import_formatStats.formatStatsMessages)({
216
+ errors: getAllStatsErrors(statsData),
217
+ warnings: getAllStatsWarnings(statsData)
193
218
  });
194
- const { errors, warnings } = (0, import_formatStats.formatStatsMessages)(statsData);
195
219
  if (errors.length) {
196
220
  return {
197
221
  message: formatErrorMessage(errors),
@@ -213,6 +237,8 @@ function formatStats(stats) {
213
237
  BUILTIN_LOADER,
214
238
  applyDefaultPlugins,
215
239
  formatStats,
240
+ getAllStatsErrors,
241
+ getAllStatsWarnings,
216
242
  getCompiledPath,
217
243
  isSatisfyRspackVersion,
218
244
  rspackMinVersion
@@ -39,12 +39,11 @@ module.exports = __toCommonJS(compilerDevMiddleware_exports);
39
39
  var import_socketServer = require("./socketServer");
40
40
  const noop = () => {
41
41
  };
42
- function getHMRClientPath(client) {
43
- const protocol = client?.protocol ? `&protocol=${client.protocol}` : "";
44
- const host = client?.host ? `&host=${client.host}` : "";
45
- const path = client?.path ? `&path=${client.path}` : "";
46
- const port = client?.port ? `&port=${client.port}` : "";
47
- const clientEntry = `${require.resolve("@rsbuild/core/client/hmr")}?${host}${path}${port}${protocol}`;
42
+ function getHMRClientPath(client = {}) {
43
+ const params = Object.entries(client).reduce((query, [key, value]) => {
44
+ return value ? `${query}&${key}=${value}` : `${query}`;
45
+ }, "");
46
+ const clientEntry = `${require.resolve("@rsbuild/core/client/hmr")}?${params}`;
48
47
  return clientEntry;
49
48
  }
50
49
  class CompilerDevMiddleware {
@@ -58,6 +58,7 @@ export declare const getDevOptions: ({ rsbuildConfig, getPortSilently, }: {
58
58
  port?: string | undefined;
59
59
  host?: string | undefined;
60
60
  protocol?: "ws" | "wss" | undefined;
61
+ overlay?: boolean | undefined;
61
62
  } | undefined;
62
63
  setupMiddlewares?: ((middlewares: {
63
64
  unshift: (...handlers: import("@rsbuild/shared").RequestHandler[]) => void;
@@ -38,6 +38,7 @@ __export(socketServer_exports, {
38
38
  module.exports = __toCommonJS(socketServer_exports);
39
39
  var import_ws = __toESM(require("../../compiled/ws"));
40
40
  var import_shared = require("@rsbuild/shared");
41
+ var import_shared2 = require("../provider/shared");
41
42
  class SocketServer {
42
43
  constructor(options) {
43
44
  __publicField(this, "wsServer");
@@ -136,8 +137,11 @@ class SocketServer {
136
137
  hash: true,
137
138
  assets: true,
138
139
  warnings: true,
140
+ warningsCount: true,
139
141
  errors: true,
140
- errorDetails: false
142
+ errorsCount: true,
143
+ errorDetails: false,
144
+ children: true
141
145
  };
142
146
  return curStats.toJson(defaultStats);
143
147
  }
@@ -147,16 +151,16 @@ class SocketServer {
147
151
  if (!stats) {
148
152
  return null;
149
153
  }
150
- const shouldEmit = !force && stats && (!stats.errors || stats.errors.length === 0) && stats.assets && stats.assets.every((asset) => !asset.emitted);
154
+ const shouldEmit = !force && stats && !stats.errorsCount && stats.assets && stats.assets.every((asset) => !asset.emitted);
151
155
  if (shouldEmit) {
152
156
  return this.sockWrite("still-ok");
153
157
  }
154
158
  this.sockWrite("hash", stats.hash);
155
- if (stats.errors && stats.errors.length > 0) {
156
- return this.sockWrite("errors", stats.errors);
159
+ if (stats.errorsCount) {
160
+ return this.sockWrite("errors", (0, import_shared2.getAllStatsErrors)(stats));
157
161
  }
158
- if (stats.warnings && stats.warnings.length > 0) {
159
- return this.sockWrite("warnings", stats.warnings);
162
+ if (stats.warningsCount) {
163
+ return this.sockWrite("warnings", (0, import_shared2.getAllStatsWarnings)(stats));
160
164
  }
161
165
  return this.sockWrite("ok");
162
166
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/core",
3
- "version": "0.5.4",
3
+ "version": "0.5.6",
4
4
  "description": "The Rspack-based build tool.",
5
5
  "homepage": "https://rsbuild.dev",
6
6
  "bugs": {
@@ -52,12 +52,12 @@
52
52
  "types.d.ts"
53
53
  ],
54
54
  "dependencies": {
55
- "@rspack/core": "0.5.9",
55
+ "@rspack/core": "0.5.9-canary-8778e17-20240328104834",
56
56
  "@swc/helpers": "0.5.3",
57
57
  "core-js": "~3.36.0",
58
58
  "html-webpack-plugin": "npm:html-rspack-plugin@5.6.2",
59
59
  "postcss": "^8.4.38",
60
- "@rsbuild/shared": "0.5.4"
60
+ "@rsbuild/shared": "0.5.6"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@types/node": "16.x",