@rsbuild/core 0.5.9 → 0.6.0

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 (39) hide show
  1. package/dist/cli/commands.js +1 -1
  2. package/dist/cli/prepare.js +1 -1
  3. package/dist/client/hmr/createSocketUrl.d.ts +2 -2
  4. package/dist/client/hmr/index.d.ts +6 -0
  5. package/dist/client/hmr.mjs +11 -275
  6. package/dist/client/overlay.d.ts +1 -0
  7. package/dist/client/overlay.mjs +250 -0
  8. package/dist/config.d.ts +8 -1
  9. package/dist/config.js +154 -3
  10. package/dist/createRsbuild.js +1 -1
  11. package/dist/{provider/htmlPluginUtil.js → htmlUtils.js} +3 -3
  12. package/dist/index.d.ts +1 -1
  13. package/dist/index.js +1 -1
  14. package/dist/internal.d.ts +20 -0
  15. package/dist/{provider/index.js → internal.js} +28 -18
  16. package/dist/plugins/fileSize.js +2 -0
  17. package/dist/provider/createCompiler.js +1 -1
  18. package/dist/provider/createContext.js +2 -2
  19. package/dist/provider/devMiddleware.js +19 -6
  20. package/dist/provider/initConfigs.js +1 -1
  21. package/dist/provider/plugins/css.js +11 -5
  22. package/dist/provider/rspackConfig.js +2 -2
  23. package/dist/provider/shared.d.ts +4 -3
  24. package/dist/provider/shared.js +27 -8
  25. package/dist/rspack/HtmlAppIconPlugin.js +2 -2
  26. package/dist/rspack/HtmlBasicPlugin.js +2 -2
  27. package/dist/rspack/HtmlCrossOriginPlugin.js +2 -2
  28. package/dist/rspack/HtmlNetworkPerformancePlugin.js +2 -2
  29. package/dist/rspack/HtmlNoncePlugin.js +2 -2
  30. package/dist/rspack/InlineChunkHtmlPlugin.js +2 -2
  31. package/dist/rspack/preload/HtmlPreloadOrPrefetchPlugin.js +3 -3
  32. package/dist/server/compilerDevMiddleware.d.ts +2 -2
  33. package/dist/server/compilerDevMiddleware.js +23 -15
  34. package/package.json +9 -13
  35. package/dist/client/hmr/overlay.d.ts +0 -2
  36. package/dist/provider/config.d.ts +0 -8
  37. package/dist/provider/config.js +0 -175
  38. package/dist/provider/index.d.ts +0 -14
  39. /package/dist/{provider/htmlPluginUtil.d.ts → htmlUtils.d.ts} +0 -0
@@ -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.9");
42
+ import_commander.program.name("rsbuild").usage("<command> [options]").version("0.6.0");
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.9"}`}
37
+ import_rslog.logger.greet(` ${`Rsbuild v${"0.6.0"}`}
38
38
  `);
39
39
  }
40
40
  // Annotate the CommonJS export names for ESM import in node:
@@ -1,9 +1,9 @@
1
+ import type { ClientConfig } from '@rsbuild/shared';
1
2
  /**
2
3
  * hmr socket connect path
3
4
  */
4
5
  export declare const HMR_SOCK_PATH = "/rsbuild-hmr";
5
- export declare function parseParams(resourceQuery: string): Record<string, string>;
6
- export declare function createSocketUrl(options?: Record<string, string>): string;
6
+ export declare function createSocketUrl(options?: ClientConfig): string;
7
7
  export declare function formatURL({ port, protocol, hostname, pathname, }: {
8
8
  port: string;
9
9
  protocol: string;
@@ -1 +1,7 @@
1
+ declare let createOverlay: undefined | ((err: string[]) => void);
2
+ declare let clearOverlay: undefined | (() => void);
3
+ export declare const registerOverlay: (options: {
4
+ createOverlay: (err: string[]) => void;
5
+ clearOverlay: () => void;
6
+ }) => void;
1
7
  export {};
@@ -7,12 +7,6 @@ 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
- }
16
10
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
17
11
  try {
18
12
  var info = gen[key](arg);
@@ -42,63 +36,6 @@ function _async_to_generator(fn) {
42
36
  });
43
37
  };
44
38
  }
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
- }
102
39
  function _iterable_to_array_limit(arr, i) {
103
40
  var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
104
41
  if (_i == null) return;
@@ -126,26 +63,9 @@ function _iterable_to_array_limit(arr, i) {
126
63
  function _non_iterable_rest() {
127
64
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
128
65
  }
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
- }
142
66
  function _sliced_to_array(arr, i) {
143
67
  return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
144
68
  }
145
- function _type_of(obj) {
146
- "@swc/helpers - typeof";
147
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
148
- }
149
69
  function _unsupported_iterable_to_array(o, minLen) {
150
70
  if (!o) return;
151
71
  if (typeof o === "string") return _array_like_to_array(o, minLen);
@@ -154,56 +74,6 @@ function _unsupported_iterable_to_array(o, minLen) {
154
74
  if (n === "Map" || n === "Set") return Array.from(n);
155
75
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
156
76
  }
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
- }
207
77
  function _ts_generator(thisArg, body) {
208
78
  var f, y, t, g, _ = {
209
79
  label: 0,
@@ -359,32 +229,6 @@ function formatStatsMessages(json) {
359
229
  }
360
230
  // src/client/hmr/createSocketUrl.ts
361
231
  var HMR_SOCK_PATH = "/rsbuild-hmr";
362
- function parseParams(resourceQuery) {
363
- var searchParams = resourceQuery.substr(1).split("&");
364
- var options2 = {};
365
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
366
- try {
367
- for(var _iterator = searchParams[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
368
- var pair = _step.value;
369
- var ary = pair.split("=");
370
- options2[ary[0]] = decodeURIComponent(ary[1]);
371
- }
372
- } catch (err) {
373
- _didIteratorError = true;
374
- _iteratorError = err;
375
- } finally{
376
- try {
377
- if (!_iteratorNormalCompletion && _iterator.return != null) {
378
- _iterator.return();
379
- }
380
- } finally{
381
- if (_didIteratorError) {
382
- throw _iteratorError;
383
- }
384
- }
385
- }
386
- return options2;
387
- }
388
232
  function createSocketUrl() {
389
233
  var options2 = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
390
234
  var currentLocation = self.location;
@@ -412,125 +256,10 @@ function getSocketUrl(urlParts, location) {
412
256
  pathname: path || HMR_SOCK_PATH
413
257
  });
414
258
  }
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
- }
530
259
  // src/client/hmr/index.ts
531
- var options = parseParams(__resourceQuery);
260
+ var options = RSBUILD_CLIENT_CONFIG;
532
261
  var socketUrl = createSocketUrl(options);
533
- var enableOverlay = options.overlay === "true";
262
+ var enableOverlay = !!options.overlay;
534
263
  var isFirstCompilation = true;
535
264
  var mostRecentCompilationHash = null;
536
265
  var hasCompileErrors = false;
@@ -541,6 +270,12 @@ function clearOutdatedErrors() {
541
270
  }
542
271
  }
543
272
  }
273
+ var createOverlay;
274
+ var clearOverlay;
275
+ var registerOverlay = function(options2) {
276
+ createOverlay = options2.createOverlay;
277
+ clearOverlay = options2.clearOverlay;
278
+ };
544
279
  function handleSuccess() {
545
280
  clearOutdatedErrors();
546
281
  var isHotUpdate = !isFirstCompilation;
@@ -606,7 +341,7 @@ function handleErrors(errors) {
606
341
  }
607
342
  }
608
343
  if (enableOverlay) {
609
- createOverlay(formatted.errors);
344
+ createOverlay === null || createOverlay === void 0 ? void 0 : createOverlay(formatted.errors);
610
345
  }
611
346
  }
612
347
  function handleAvailableHash(hash) {
@@ -658,7 +393,7 @@ function onMessage(e) {
658
393
  switch(message.type){
659
394
  case "hash":
660
395
  if (enableOverlay) {
661
- clearOverlay();
396
+ clearOverlay === null || clearOverlay === void 0 ? void 0 : clearOverlay();
662
397
  }
663
398
  handleAvailableHash(message.data);
664
399
  break;
@@ -761,3 +496,4 @@ function reconnect() {
761
496
  connect();
762
497
  }
763
498
  connect();
499
+ export { registerOverlay };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,250 @@
1
+ // src/client/overlay.ts
2
+ function _assert_this_initialized(self) {
3
+ if (self === void 0) {
4
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
5
+ }
6
+ return self;
7
+ }
8
+ function _class_call_check(instance, Constructor) {
9
+ if (!(instance instanceof Constructor)) {
10
+ throw new TypeError("Cannot call a class as a function");
11
+ }
12
+ }
13
+ function _construct(Parent, args, Class) {
14
+ if (_is_native_reflect_construct()) {
15
+ _construct = Reflect.construct;
16
+ } else {
17
+ _construct = function construct(Parent, args, Class) {
18
+ var a = [
19
+ null
20
+ ];
21
+ a.push.apply(a, args);
22
+ var Constructor = Function.bind.apply(Parent, a);
23
+ var instance = new Constructor();
24
+ if (Class) _set_prototype_of(instance, Class.prototype);
25
+ return instance;
26
+ };
27
+ }
28
+ return _construct.apply(null, arguments);
29
+ }
30
+ function _define_property(obj, key, value) {
31
+ if (key in obj) {
32
+ Object.defineProperty(obj, key, {
33
+ value: value,
34
+ enumerable: true,
35
+ configurable: true,
36
+ writable: true
37
+ });
38
+ } else {
39
+ obj[key] = value;
40
+ }
41
+ return obj;
42
+ }
43
+ function _get_prototype_of(o) {
44
+ _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
45
+ return o.__proto__ || Object.getPrototypeOf(o);
46
+ };
47
+ return _get_prototype_of(o);
48
+ }
49
+ function _inherits(subClass, superClass) {
50
+ if (typeof superClass !== "function" && superClass !== null) {
51
+ throw new TypeError("Super expression must either be null or a function");
52
+ }
53
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
54
+ constructor: {
55
+ value: subClass,
56
+ writable: true,
57
+ configurable: true
58
+ }
59
+ });
60
+ if (superClass) _set_prototype_of(subClass, superClass);
61
+ }
62
+ function _is_native_function(fn) {
63
+ return Function.toString.call(fn).indexOf("[native code]") !== -1;
64
+ }
65
+ function _possible_constructor_return(self, call) {
66
+ if (call && (_type_of(call) === "object" || typeof call === "function")) {
67
+ return call;
68
+ }
69
+ return _assert_this_initialized(self);
70
+ }
71
+ function _set_prototype_of(o, p) {
72
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
73
+ o.__proto__ = p;
74
+ return o;
75
+ };
76
+ return _set_prototype_of(o, p);
77
+ }
78
+ function _type_of(obj) {
79
+ "@swc/helpers - typeof";
80
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
81
+ }
82
+ function _wrap_native_super(Class) {
83
+ var _cache = typeof Map === "function" ? new Map() : undefined;
84
+ _wrap_native_super = function wrapNativeSuper(Class) {
85
+ if (Class === null || !_is_native_function(Class)) return Class;
86
+ if (typeof Class !== "function") {
87
+ throw new TypeError("Super expression must either be null or a function");
88
+ }
89
+ if (typeof _cache !== "undefined") {
90
+ if (_cache.has(Class)) return _cache.get(Class);
91
+ _cache.set(Class, Wrapper);
92
+ }
93
+ function Wrapper() {
94
+ return _construct(Class, arguments, _get_prototype_of(this).constructor);
95
+ }
96
+ Wrapper.prototype = Object.create(Class.prototype, {
97
+ constructor: {
98
+ value: Wrapper,
99
+ enumerable: false,
100
+ writable: true,
101
+ configurable: true
102
+ }
103
+ });
104
+ return _set_prototype_of(Wrapper, Class);
105
+ };
106
+ return _wrap_native_super(Class);
107
+ }
108
+ function _is_native_reflect_construct() {
109
+ if (typeof Reflect === "undefined" || !Reflect.construct) return false;
110
+ if (Reflect.construct.sham) return false;
111
+ if (typeof Proxy === "function") return true;
112
+ try {
113
+ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
114
+ return true;
115
+ } catch (e) {
116
+ return false;
117
+ }
118
+ }
119
+ function _create_super(Derived) {
120
+ var hasNativeReflectConstruct = _is_native_reflect_construct();
121
+ return function _createSuperInternal() {
122
+ var Super = _get_prototype_of(Derived), result;
123
+ if (hasNativeReflectConstruct) {
124
+ var NewTarget = _get_prototype_of(this).constructor;
125
+ result = Reflect.construct(Super, arguments, NewTarget);
126
+ } else {
127
+ result = Super.apply(this, arguments);
128
+ }
129
+ return _possible_constructor_return(this, result);
130
+ };
131
+ }
132
+ import { registerOverlay } from "./hmr";
133
+ function stripAnsi(content) {
134
+ var pattern = [
135
+ "[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
136
+ "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))"
137
+ ].join("|");
138
+ var regex = new RegExp(pattern, "g");
139
+ return content.replace(regex, "");
140
+ }
141
+ function linkedText(root, selector, text) {
142
+ var _loop = function() {
143
+ var file = match[0], index = match.index;
144
+ if (index != null) {
145
+ var frag2 = text.slice(curIndex, index);
146
+ el.appendChild(document.createTextNode(frag2));
147
+ var link = document.createElement("a");
148
+ link.textContent = file;
149
+ link.className = "file-link";
150
+ link.onclick = function() {
151
+ fetch("/__open-in-editor?file=".concat(encodeURIComponent(file)));
152
+ };
153
+ el.appendChild(link);
154
+ curIndex += frag2.length + file.length;
155
+ }
156
+ match = fileRegex.exec(text);
157
+ };
158
+ var el = root.querySelector(selector);
159
+ var fileRegex = /(?:[a-zA-Z]:\\|\/).*?:\d+:\d+/g;
160
+ var curIndex = 0;
161
+ var match = fileRegex.exec(text);
162
+ while(match !== null)_loop();
163
+ var frag = text.slice(curIndex);
164
+ el.appendChild(document.createTextNode(frag));
165
+ }
166
+ 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';
167
+ var _globalThis_HTMLElement = globalThis.HTMLElement, HTMLElement = _globalThis_HTMLElement === void 0 ? function HTMLElement() {
168
+ "use strict";
169
+ _class_call_check(this, HTMLElement);
170
+ } : _globalThis_HTMLElement, customElements = globalThis.customElements;
171
+ var ErrorOverlay = /*#__PURE__*/ function(HTMLElement) {
172
+ "use strict";
173
+ _inherits(ErrorOverlay, HTMLElement);
174
+ var _super = _create_super(ErrorOverlay);
175
+ function ErrorOverlay(message) {
176
+ _class_call_check(this, ErrorOverlay);
177
+ var _this;
178
+ var _root_querySelector;
179
+ _this = _super.call(this);
180
+ _define_property(_assert_this_initialized(_this), "close", function() {
181
+ var remove = function() {
182
+ var _this_parentNode;
183
+ return (_this_parentNode = _this.parentNode) === null || _this_parentNode === void 0 ? void 0 : _this_parentNode.removeChild(_assert_this_initialized(_this));
184
+ };
185
+ if (_this.animate) {
186
+ _this.animate([
187
+ {
188
+ opacity: 1
189
+ },
190
+ {
191
+ opacity: 0
192
+ }
193
+ ], {
194
+ duration: 300,
195
+ easing: "ease-out"
196
+ }).addEventListener("finish", remove);
197
+ } else {
198
+ remove();
199
+ }
200
+ });
201
+ if (!_this.attachShadow) {
202
+ console.warn("[Rsbuild] Current browser version does not support displaying error overlay");
203
+ return _possible_constructor_return(_this);
204
+ }
205
+ var root = _this.attachShadow({
206
+ mode: "open"
207
+ });
208
+ root.innerHTML = overlayTemplate;
209
+ linkedText(root, ".content", stripAnsi(message.join("/n")).trim());
210
+ (_root_querySelector = root.querySelector(".close")) === null || _root_querySelector === void 0 ? void 0 : _root_querySelector.addEventListener("click", _this.close);
211
+ _this.addEventListener("click", _this.close);
212
+ root.querySelector(".container").addEventListener("click", function(e) {
213
+ e.stopPropagation();
214
+ });
215
+ var onEscKeydown = function(e) {
216
+ if (e.key === "Escape" || e.code === "Escape") {
217
+ _this.close();
218
+ }
219
+ document.removeEventListener("keydown", onEscKeydown);
220
+ };
221
+ document.addEventListener("keydown", onEscKeydown);
222
+ return _this;
223
+ }
224
+ return ErrorOverlay;
225
+ }(_wrap_native_super(HTMLElement));
226
+ var overlayId = "rsbuild-error-overlay";
227
+ if (customElements && !customElements.get(overlayId)) {
228
+ customElements.define(overlayId, ErrorOverlay);
229
+ }
230
+ var documentAvailable = typeof document !== "undefined";
231
+ function createOverlay(err) {
232
+ if (!documentAvailable) {
233
+ console.info("[Rsbuild] Failed to display error overlay as document is not available, you can disable the `dev.client.overlay` option.");
234
+ return;
235
+ }
236
+ clearOverlay();
237
+ document.body.appendChild(new ErrorOverlay(err));
238
+ }
239
+ function clearOverlay() {
240
+ if (!documentAvailable) {
241
+ return;
242
+ }
243
+ document.querySelectorAll(overlayId).forEach(function(n) {
244
+ return n.close();
245
+ });
246
+ }
247
+ registerOverlay({
248
+ createOverlay: createOverlay,
249
+ clearOverlay: clearOverlay
250
+ });
package/dist/config.d.ts CHANGED
@@ -1,4 +1,11 @@
1
- import { type RsbuildConfig } from '@rsbuild/shared';
1
+ import type { RsbuildConfig, NormalizedConfig } from '@rsbuild/shared';
2
+ export declare const withDefaultConfig: (rootPath: string, config: RsbuildConfig) => Promise<RsbuildConfig>;
3
+ /** #__PURE__
4
+ * 1. May used by multiple plugins.
5
+ * 2. Object value that should not be empty.
6
+ * 3. Meaningful and can be filled by constant value.
7
+ */
8
+ export declare const normalizeConfig: (config: RsbuildConfig) => NormalizedConfig;
2
9
  export type ConfigParams = {
3
10
  env: string;
4
11
  command: string;