@rsbuild/core 1.7.0-beta.0 → 1.7.0-beta.1

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.
package/dist/2~open.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- const __rslib_import_meta_url__ = 'undefined' == typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
2
+ const __rslib_import_meta_url__ = "u" < typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
3
3
  exports.ids = [
4
4
  "664"
5
5
  ], exports.modules = {
@@ -1,6 +1,6 @@
1
1
  /*! For license information please see 2~range-parser.cjs.LICENSE.txt */
2
2
  "use strict";
3
- const __rslib_import_meta_url__ = 'undefined' == typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
3
+ const __rslib_import_meta_url__ = "u" < typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
4
4
  exports.ids = [
5
5
  "603"
6
6
  ], exports.modules = {
@@ -8,6 +8,7 @@ const registerOverlay = (createFn, clearFn)=>{
8
8
  function init({ token, config, serverHost, serverPort, liveReload, browserLogs, logLevel }) {
9
9
  logger.level = logLevel;
10
10
  const queuedMessages = [];
11
+ const clientErrors = [];
11
12
  let lastHash;
12
13
  let hasBuildErrors = false;
13
14
  function formatURL(fallback) {
@@ -16,7 +17,7 @@ function init({ token, config, serverHost, serverPort, liveReload, browserLogs,
16
17
  const port = (fallback ? serverPort : config.port) || location.port;
17
18
  const protocol = config.protocol || ('https:' === location.protocol ? 'wss' : 'ws');
18
19
  const pathname = config.path;
19
- if ('undefined' != typeof URL) {
20
+ if ("u" > typeof URL) {
20
21
  const url = new URL('http://localhost');
21
22
  url.port = String(port);
22
23
  url.hostname = hostname;
@@ -51,7 +52,12 @@ function init({ token, config, serverHost, serverPort, liveReload, browserLogs,
51
52
  clearBuildErrors();
52
53
  hasBuildErrors = true;
53
54
  for (const error of text)logger.error(error);
54
- if (createOverlay) createOverlay(html);
55
+ if (createOverlay) createOverlay('Build failed', html);
56
+ }
57
+ function handleResolvedClientError({ id, message }) {
58
+ if (!createOverlay || hasBuildErrors) return;
59
+ for (const item of clientErrors)if (item.id === id) item.message = message;
60
+ createOverlay('Runtime errors', clientErrors.map((item)=>item.message).filter(Boolean).join('\n\n'));
55
61
  }
56
62
  const shouldUpdate = ()=>lastHash !== __webpack_hash__;
57
63
  const handleApplyUpdates = (err, updatedModules)=>{
@@ -116,6 +122,9 @@ function init({ token, config, serverHost, serverPort, liveReload, browserLogs,
116
122
  case 'errors':
117
123
  handleErrors(message.data);
118
124
  break;
125
+ case 'resolved-client-error':
126
+ handleResolvedClientError(message.data);
127
+ break;
119
128
  }
120
129
  }
121
130
  function onClose() {
@@ -138,11 +147,16 @@ function init({ token, config, serverHost, serverPort, liveReload, browserLogs,
138
147
  }
139
148
  }
140
149
  function sendError(message, stack) {
150
+ const id = `${Date.now().toString(36)}${Math.random().toString(36).slice(2)}`;
141
151
  const messageInfo = {
142
152
  type: 'client-error',
153
+ id,
143
154
  message,
144
155
  stack
145
156
  };
157
+ clientErrors.push({
158
+ id
159
+ });
146
160
  if (isSocketReady()) socketSend(messageInfo);
147
161
  else queuedMessages.push(messageInfo);
148
162
  }
@@ -181,7 +195,7 @@ function init({ token, config, serverHost, serverPort, liveReload, browserLogs,
181
195
  function reloadPage() {
182
196
  if (liveReload) window.location.reload();
183
197
  }
184
- if (browserLogs && 'undefined' != typeof window) {
198
+ if (browserLogs && "u" > typeof window) {
185
199
  window.addEventListener('error', ({ message, error })=>{
186
200
  sendError(message, error instanceof Error ? error.stack : void 0);
187
201
  });
@@ -11,7 +11,7 @@ function _define_property(obj, key, value) {
11
11
  return obj;
12
12
  }
13
13
  const { HTMLElement: HTMLElement = class {
14
- }, customElements: customElements } = 'undefined' != typeof window ? window : globalThis;
14
+ }, customElements: customElements } = "u" > typeof window ? window : globalThis;
15
15
  class ErrorOverlay extends HTMLElement {
16
16
  constructor(html){
17
17
  var _root_querySelector, _root_querySelector1;
@@ -56,14 +56,148 @@ class ErrorOverlay extends HTMLElement {
56
56
  }
57
57
  const overlayId = 'rsbuild-error-overlay';
58
58
  if (customElements && !customElements.get(overlayId)) customElements.define(overlayId, ErrorOverlay);
59
- function createOverlay(html) {
59
+ function getOverlayHtml(title, content) {
60
+ return `
61
+ <style>
62
+ .root {
63
+ position: fixed;
64
+ z-index: 9999;
65
+ top: 0;
66
+ left: 0;
67
+ width: 100%;
68
+ height: 100%;
69
+ overflow-y: scroll;
70
+ margin: 0;
71
+ background: rgba(0, 0, 0, 0.66);
72
+ cursor: pointer;
73
+ }
74
+ .container {
75
+ font-family: Menlo, Consolas, monospace;
76
+ line-height: 1.6;
77
+ width: 960px;
78
+ max-width: 85%;
79
+ color: #d8d8d8;
80
+ margin: 32px auto;
81
+ padding: 32px 40px;
82
+ position: relative;
83
+ background: #181818;
84
+ border-radius: 24px;
85
+ box-shadow: 0 19px 38px rgba(0,0,0,0.30), 0 15px 12px rgba(0,0,0,0.22);
86
+ overflow: hidden;
87
+ direction: ltr;
88
+ text-align: left;
89
+ box-sizing: border-box;
90
+ cursor: default;
91
+ }
92
+ .title {
93
+ margin: 0 0 20px;
94
+ padding-bottom: 12px;
95
+ font-size: 17px;
96
+ font-weight: 600;
97
+ color: #fb6a6a;
98
+ border-bottom: 2px solid rgba(252,94,94,.66);
99
+ }
100
+ .content {
101
+ margin: 0;
102
+ font-size: 14px;
103
+ font-family: inherit;
104
+ white-space: pre-wrap;
105
+ word-break: break-all;
106
+ scrollbar-width: none;
107
+ }
108
+ .content::-webkit-scrollbar {
109
+ display: none;
110
+ }
111
+ .file-link,
112
+ .url-link,
113
+ .config-link {
114
+ cursor: pointer;
115
+ text-decoration: underline;
116
+ text-underline-offset: 3px;
117
+ &:hover {
118
+ opacity: 0.8;
119
+ }
120
+ &:active {
121
+ opacity: 0.6;
122
+ }
123
+ }
124
+ .file-link {
125
+ color: #6eecf7;
126
+ }
127
+ .url-link {
128
+ color: #eff986;
129
+ }
130
+ .config-link {
131
+ color: inherit;
132
+ text-decoration: none;
133
+ }
134
+ .close {
135
+ position: absolute;
136
+ top: 27px;
137
+ right: 32px;
138
+ width: 32px;
139
+ height: 32px;
140
+ cursor: pointer;
141
+ }
142
+ .close:hover {
143
+ opacity: 0.8;
144
+ }
145
+ .close:active {
146
+ opacity: 0.6;
147
+ }
148
+ .close:before,
149
+ .close:after {
150
+ position: absolute;
151
+ left: 16px;
152
+ top: 8px;
153
+ content: ' ';
154
+ height: 18px;
155
+ width: 2px;
156
+ border-radius: 4px;
157
+ background-color: #b8b8b8;
158
+ }
159
+ .close:before {
160
+ transform: rotate(45deg);
161
+ }
162
+ .close:after {
163
+ transform: rotate(-45deg);
164
+ }
165
+ .footer {
166
+ font-size: 12px;
167
+ color: #7e6a92;
168
+ margin-top: 20px;
169
+ padding-top: 12px;
170
+ border-top: 2px solid rgba(126,106,146,.6);
171
+ }
172
+ .footer p {
173
+ margin: 4px 0 0;
174
+ }
175
+ .footer span {
176
+ color: #a88dc3;
177
+ }
178
+ </style>
179
+
180
+ <div class="root">
181
+ <div class="container">
182
+ <div class="close"></div>
183
+ <p class="title">${title}</p>
184
+ <pre class="content">${content}</pre>
185
+ <footer class="footer">
186
+ <p><span>Fix error</span>, click outside, or press Esc to close the overlay.</p>
187
+ <p>Disable overlay by setting Rsbuild's <span><a class="config-link" target="_blank" rel="noopener noreferrer" href="https://rsbuild.rs/config/dev/client">dev.client.overlay</a></span> config to false.<p>
188
+ </footer>
189
+ </div>
190
+ </div>
191
+ `;
192
+ }
193
+ function createOverlay(title, content) {
60
194
  clearOverlay();
61
- document.body.appendChild(new ErrorOverlay(html));
195
+ document.body.appendChild(new ErrorOverlay(getOverlayHtml(title, content)));
62
196
  }
63
197
  function clearOverlay() {
64
198
  document.querySelectorAll(overlayId).forEach((n)=>{
65
199
  n.close(true);
66
200
  });
67
201
  }
68
- if ('undefined' != typeof document) registerOverlay(createOverlay, clearOverlay);
202
+ if ("u" > typeof document) registerOverlay(createOverlay, clearOverlay);
69
203
  else logger.info('[rsbuild] Error overlay unavailable: Running in non-browser environment. To suppress this message, set `dev.client.overlay: false` in your configuration.');
@@ -1,3 +1,3 @@
1
1
  export default function(source) {
2
2
  return (this?.cacheable(!0), source.includes('___CSS_LOADER_EXPORT___')) ? '' : source;
3
- }
3
+ };