@rsbuild/core 0.6.7 → 0.6.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.
@@ -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.6.7");
42
+ import_commander.program.name("rsbuild").usage("<command> [options]").version("0.6.8");
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.6.7"}`}
37
+ import_rslog.logger.greet(` ${`Rsbuild v${"0.6.8"}`}
38
38
  `);
39
39
  }
40
40
  // Annotate the CommonJS export names for ESM import in node:
@@ -6,7 +6,7 @@
6
6
  * https://github.com/facebook/create-react-app/blob/master/LICENSE
7
7
  */
8
8
  import type { StatsCompilation } from 'webpack';
9
- export declare function formatStatsMessages(json?: Pick<StatsCompilation, 'errors' | 'warnings'>): {
9
+ export declare function formatStatsMessages(stats: Pick<StatsCompilation, 'errors' | 'warnings'>): {
10
10
  errors: string[];
11
11
  warnings: string[];
12
12
  };
@@ -25,12 +25,24 @@ const friendlySyntaxErrorLabel = "SyntaxError:";
25
25
  function isLikelyASyntaxError(message) {
26
26
  return message.includes(friendlySyntaxErrorLabel);
27
27
  }
28
+ function resolveFileName(stats) {
29
+ const regex = /(?:\!|^)([^!]+)$/;
30
+ const fileName = stats.moduleIdentifier?.match(regex)?.at(-1) ?? "";
31
+ return fileName ? (
32
+ // add default column add lines for linking
33
+ `File: ${fileName}:1:1
34
+ `
35
+ ) : (
36
+ // fallback to moduleName if moduleIdentifier parse failed
37
+ `File: ${stats.moduleName}
38
+ `
39
+ );
40
+ }
28
41
  function formatMessage(stats) {
29
42
  let lines = [];
30
43
  let message;
31
44
  if (typeof stats === "object") {
32
- const fileName = stats.moduleName ? `File: ${stats.moduleName}
33
- ` : "";
45
+ const fileName = resolveFileName(stats);
34
46
  const mainMessage = typeof stats.formatted === "string" ? stats.formatted : stats.message;
35
47
  const details = stats.details ? `
36
48
  Details: ${stats.details}
@@ -72,13 +84,12 @@ ${stats.stack}` : "";
72
84
  message = lines.join("\n");
73
85
  return message.trim();
74
86
  }
75
- function formatStatsMessages(json) {
76
- const formattedErrors = json?.errors?.map(formatMessage);
77
- const formattedWarnings = json?.warnings?.map(formatMessage);
87
+ function formatStatsMessages(stats) {
88
+ const formattedErrors = stats.errors?.map(formatMessage);
89
+ const formattedWarnings = stats.warnings?.map(formatMessage);
78
90
  const result = {
79
91
  errors: formattedErrors || [],
80
- warnings: formattedWarnings || [],
81
- errorTips: []
92
+ warnings: formattedWarnings || []
82
93
  };
83
94
  if (result.errors?.some(isLikelyASyntaxError)) {
84
95
  result.errors = result.errors.filter(isLikelyASyntaxError);
@@ -1,4 +1 @@
1
- export declare const registerOverlay: (options: {
2
- createOverlay: (err: string[]) => void;
3
- clearOverlay: () => void;
4
- }) => void;
1
+ export declare const registerOverlay: (createFn: (err: string[]) => void, clearFn: () => void) => void;
@@ -0,0 +1,6 @@
1
+ import type { ClientConfig } from '@rsbuild/shared';
2
+ /**
3
+ * hmr socket connect path
4
+ */
5
+ export declare const HMR_SOCK_PATH = "/rsbuild-hmr";
6
+ export declare function getSocketUrl(urlParts: ClientConfig): string;
@@ -173,11 +173,20 @@ var friendlySyntaxErrorLabel = "SyntaxError:";
173
173
  function isLikelyASyntaxError(message) {
174
174
  return message.includes(friendlySyntaxErrorLabel);
175
175
  }
176
+ function resolveFileName(stats) {
177
+ var _stats_moduleIdentifier_match, _stats_moduleIdentifier;
178
+ var regex = /(?:\!|^)([^!]+)$/;
179
+ var _stats_moduleIdentifier_match_at;
180
+ var fileName = (_stats_moduleIdentifier_match_at = (_stats_moduleIdentifier = stats.moduleIdentifier) === null || _stats_moduleIdentifier === void 0 ? void 0 : (_stats_moduleIdentifier_match = _stats_moduleIdentifier.match(regex)) === null || _stats_moduleIdentifier_match === void 0 ? void 0 : _stats_moduleIdentifier_match.at(-1)) !== null && _stats_moduleIdentifier_match_at !== void 0 ? _stats_moduleIdentifier_match_at : "";
181
+ return fileName ? // add default column add lines for linking
182
+ "File: ".concat(fileName, ":1:1\n") : // fallback to moduleName if moduleIdentifier parse failed
183
+ "File: ".concat(stats.moduleName, "\n");
184
+ }
176
185
  function formatMessage(stats) {
177
186
  var lines = [];
178
187
  var message;
179
188
  if (typeof stats === "object") {
180
- var fileName = stats.moduleName ? "File: ".concat(stats.moduleName, "\n") : "";
189
+ var fileName = resolveFileName(stats);
181
190
  var mainMessage = typeof stats.formatted === "string" ? stats.formatted : stats.message;
182
191
  var details = stats.details ? "\nDetails: ".concat(stats.details, "\n") : "";
183
192
  var stack = stats.stack ? "\n".concat(stats.stack) : "";
@@ -210,14 +219,13 @@ function formatMessage(stats) {
210
219
  message = lines.join("\n");
211
220
  return message.trim();
212
221
  }
213
- function formatStatsMessages(json) {
214
- var _json_errors, _json_warnings, _result_errors;
215
- var formattedErrors = json === null || json === void 0 ? void 0 : (_json_errors = json.errors) === null || _json_errors === void 0 ? void 0 : _json_errors.map(formatMessage);
216
- var formattedWarnings = json === null || json === void 0 ? void 0 : (_json_warnings = json.warnings) === null || _json_warnings === void 0 ? void 0 : _json_warnings.map(formatMessage);
222
+ function formatStatsMessages(stats) {
223
+ var _stats_errors, _stats_warnings, _result_errors;
224
+ var formattedErrors = (_stats_errors = stats.errors) === null || _stats_errors === void 0 ? void 0 : _stats_errors.map(formatMessage);
225
+ var formattedWarnings = (_stats_warnings = stats.warnings) === null || _stats_warnings === void 0 ? void 0 : _stats_warnings.map(formatMessage);
217
226
  var result = {
218
227
  errors: formattedErrors || [],
219
- warnings: formattedWarnings || [],
220
- errorTips: []
228
+ warnings: formattedWarnings || []
221
229
  };
222
230
  if ((_result_errors = result.errors) === null || _result_errors === void 0 ? void 0 : _result_errors.some(isLikelyASyntaxError)) {
223
231
  result.errors = result.errors.filter(isLikelyASyntaxError);
@@ -227,13 +235,8 @@ function formatStatsMessages(json) {
227
235
  }
228
236
  return result;
229
237
  }
230
- // src/client/hmr/createSocketUrl.ts
238
+ // src/client/hmr/url.ts
231
239
  var HMR_SOCK_PATH = "/rsbuild-hmr";
232
- function createSocketUrl() {
233
- var options2 = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
234
- var currentLocation = self.location;
235
- return getSocketUrl(options2, currentLocation);
236
- }
237
240
  function formatURL(param) {
238
241
  var port = param.port, protocol = param.protocol, hostname = param.hostname, pathname = param.pathname;
239
242
  if (typeof URL !== "undefined") {
@@ -247,7 +250,8 @@ function formatURL(param) {
247
250
  var colon = protocol.indexOf(":") === -1 ? ":" : "";
248
251
  return "".concat(protocol).concat(colon, "//").concat(hostname, ":").concat(port).concat(pathname);
249
252
  }
250
- function getSocketUrl(urlParts, location) {
253
+ function getSocketUrl(urlParts) {
254
+ var location = self.location;
251
255
  var host = urlParts.host, port = urlParts.port, path = urlParts.path, protocol = urlParts.protocol;
252
256
  return formatURL({
253
257
  protocol: protocol || (location.protocol === "https:" ? "wss" : "ws"),
@@ -257,25 +261,19 @@ function getSocketUrl(urlParts, location) {
257
261
  });
258
262
  }
259
263
  // src/client/hmr/index.ts
260
- var options = RSBUILD_CLIENT_CONFIG;
261
- var socketUrl = createSocketUrl(options);
262
- var enableOverlay = !!options.overlay;
263
- var enableLiveReload = RSBUILD_DEV_LIVE_RELOAD;
264
264
  var isFirstCompilation = true;
265
- var mostRecentCompilationHash = null;
265
+ var lastCompilationHash = null;
266
266
  var hasCompileErrors = false;
267
267
  function clearOutdatedErrors() {
268
- if (typeof console !== "undefined" && typeof console.clear === "function") {
269
- if (hasCompileErrors) {
270
- console.clear();
271
- }
268
+ if (console.clear && hasCompileErrors) {
269
+ console.clear();
272
270
  }
273
271
  }
274
272
  var createOverlay;
275
273
  var clearOverlay;
276
- var registerOverlay = function(options2) {
277
- createOverlay = options2.createOverlay;
278
- clearOverlay = options2.clearOverlay;
274
+ var registerOverlay = function(createFn, clearFn) {
275
+ createOverlay = createFn;
276
+ clearOverlay = clearFn;
279
277
  };
280
278
  function handleSuccess() {
281
279
  clearOutdatedErrors();
@@ -291,22 +289,17 @@ function handleWarnings(warnings) {
291
289
  var isHotUpdate = !isFirstCompilation;
292
290
  isFirstCompilation = false;
293
291
  hasCompileErrors = false;
294
- function printWarnings() {
295
- var formatted = formatStatsMessages({
296
- warnings: warnings,
297
- errors: []
298
- });
299
- if (typeof console !== "undefined" && typeof console.warn === "function") {
300
- for(var i = 0; i < formatted.warnings.length; i++){
301
- if (i === 5) {
302
- console.warn("There were more warnings in other files.\nYou can find a complete log in the terminal.");
303
- break;
304
- }
305
- console.warn(formatted.warnings[i]);
306
- }
292
+ var formatted = formatStatsMessages({
293
+ warnings: warnings,
294
+ errors: []
295
+ });
296
+ for(var i = 0; i < formatted.warnings.length; i++){
297
+ if (i === 5) {
298
+ console.warn("There were more warnings in other files, you can find a complete log in the terminal.");
299
+ break;
307
300
  }
301
+ console.warn(formatted.warnings[i]);
308
302
  }
309
- printWarnings();
310
303
  if (isHotUpdate) {
311
304
  tryApplyUpdates();
312
305
  }
@@ -319,40 +312,32 @@ function handleErrors(errors) {
319
312
  errors: errors,
320
313
  warnings: []
321
314
  });
322
- if (typeof console !== "undefined" && typeof console.error === "function") {
323
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
315
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
316
+ try {
317
+ for(var _iterator = formatted.errors[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
318
+ var error = _step.value;
319
+ console.error(error);
320
+ }
321
+ } catch (err) {
322
+ _didIteratorError = true;
323
+ _iteratorError = err;
324
+ } finally{
324
325
  try {
325
- for(var _iterator = formatted.errors[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
326
- var error = _step.value;
327
- console.error(error);
326
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
327
+ _iterator.return();
328
328
  }
329
- } catch (err) {
330
- _didIteratorError = true;
331
- _iteratorError = err;
332
329
  } finally{
333
- try {
334
- if (!_iteratorNormalCompletion && _iterator.return != null) {
335
- _iterator.return();
336
- }
337
- } finally{
338
- if (_didIteratorError) {
339
- throw _iteratorError;
340
- }
330
+ if (_didIteratorError) {
331
+ throw _iteratorError;
341
332
  }
342
333
  }
343
334
  }
344
- if (enableOverlay) {
345
- createOverlay === null || createOverlay === void 0 ? void 0 : createOverlay(formatted.errors);
335
+ if (createOverlay) {
336
+ createOverlay(formatted.errors);
346
337
  }
347
338
  }
348
- function handleAvailableHash(hash) {
349
- mostRecentCompilationHash = hash;
350
- }
351
339
  function isUpdateAvailable() {
352
- return mostRecentCompilationHash !== __webpack_hash__;
353
- }
354
- function canApplyUpdates() {
355
- return import.meta.webpackHot.status() === "idle";
340
+ return lastCompilationHash !== __webpack_hash__;
356
341
  }
357
342
  function tryApplyUpdates() {
358
343
  if (!isUpdateAvailable()) {
@@ -362,13 +347,13 @@ function tryApplyUpdates() {
362
347
  reloadPage();
363
348
  return;
364
349
  }
365
- if (!canApplyUpdates()) {
350
+ if (import.meta.webpackHot.status() !== "idle") {
366
351
  return;
367
352
  }
368
353
  function handleApplyUpdates(err, updatedModules) {
369
- var wantsForcedReload = err || !updatedModules;
370
- if (wantsForcedReload) {
371
- if (err && typeof console !== "undefined" && typeof console.error === "function") {
354
+ var forcedReload = err || !updatedModules;
355
+ if (forcedReload) {
356
+ if (err) {
372
357
  console.error("[HMR] Forced reload caused by: ", err);
373
358
  }
374
359
  reloadPage();
@@ -386,28 +371,24 @@ function tryApplyUpdates() {
386
371
  }
387
372
  var MAX_RETRIES = 100;
388
373
  var connection = null;
389
- var retry_counter = 0;
374
+ var retryCount = 0;
390
375
  function onOpen() {
391
- if (typeof console !== "undefined" && typeof console.info === "function") {
392
- console.info("[HMR] connected.");
393
- }
376
+ console.info("[HMR] connected.");
394
377
  }
395
378
  function onMessage(e) {
396
379
  var message = JSON.parse(e.data);
397
380
  switch(message.type){
398
381
  case "hash":
399
- if (enableOverlay) {
400
- clearOverlay === null || clearOverlay === void 0 ? void 0 : clearOverlay();
382
+ lastCompilationHash = message.data;
383
+ if (clearOverlay && isUpdateAvailable()) {
384
+ clearOverlay();
401
385
  }
402
- handleAvailableHash(message.data);
403
386
  break;
404
387
  case "still-ok":
405
388
  case "ok":
406
389
  handleSuccess();
407
390
  break;
408
391
  case "static-changed":
409
- reloadPage();
410
- break;
411
392
  case "content-changed":
412
393
  reloadPage();
413
394
  break;
@@ -417,27 +398,13 @@ function onMessage(e) {
417
398
  case "errors":
418
399
  handleErrors(message.data);
419
400
  break;
420
- default:
421
401
  }
422
402
  }
423
403
  function sleep() {
424
- return _sleep.apply(this, arguments);
425
- }
426
- function _sleep() {
427
- _sleep = _async_to_generator(function() {
428
- var msec;
429
- var _arguments = arguments;
430
- return _ts_generator(this, function(_state) {
431
- msec = _arguments.length > 0 && _arguments[0] !== void 0 ? _arguments[0] : 1e3;
432
- return [
433
- 2,
434
- new Promise(function(resolve) {
435
- setTimeout(resolve, msec);
436
- })
437
- ];
438
- });
404
+ var msec = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 1e3;
405
+ return new Promise(function(resolve) {
406
+ setTimeout(resolve, msec);
439
407
  });
440
- return _sleep.apply(this, arguments);
441
408
  }
442
409
  function onClose() {
443
410
  return _onClose.apply(this, arguments);
@@ -447,9 +414,7 @@ function _onClose() {
447
414
  return _ts_generator(this, function(_state) {
448
415
  switch(_state.label){
449
416
  case 0:
450
- if (typeof console !== "undefined" && typeof console.info === "function") {
451
- console.info("[HMR] disconnected. Attempting to reconnect.");
452
- }
417
+ console.info("[HMR] disconnected. Attempting to reconnect.");
453
418
  removeListeners();
454
419
  return [
455
420
  4,
@@ -457,18 +422,16 @@ function _onClose() {
457
422
  ];
458
423
  case 1:
459
424
  _state.sent();
460
- retry_counter++;
425
+ retryCount++;
461
426
  if (connection && (connection.readyState === connection.CONNECTING || connection.readyState === connection.OPEN)) {
462
- retry_counter = 0;
427
+ retryCount = 0;
463
428
  return [
464
429
  2
465
430
  ];
466
431
  }
467
- if (retry_counter > MAX_RETRIES) {
468
- if (typeof console !== "undefined" && typeof console.info === "function") {
469
- console.info("[HMR] Unable to establish a connection after exceeding the maximum retry attempts.");
470
- }
471
- retry_counter = 0;
432
+ if (retryCount > MAX_RETRIES) {
433
+ console.info("[HMR] Unable to establish a connection after exceeding the maximum retry attempts.");
434
+ retryCount = 0;
472
435
  return [
473
436
  2
474
437
  ];
@@ -483,6 +446,7 @@ function _onClose() {
483
446
  return _onClose.apply(this, arguments);
484
447
  }
485
448
  function connect() {
449
+ var socketUrl = getSocketUrl(RSBUILD_CLIENT_CONFIG);
486
450
  connection = new WebSocket(socketUrl);
487
451
  connection.addEventListener("open", onOpen);
488
452
  connection.addEventListener("close", onClose);
@@ -502,7 +466,7 @@ function reconnect() {
502
466
  connect();
503
467
  }
504
468
  function reloadPage() {
505
- if (enableLiveReload) {
469
+ if (RSBUILD_DEV_LIVE_RELOAD) {
506
470
  window.location.reload();
507
471
  }
508
472
  }
@@ -227,24 +227,17 @@ var overlayId = "rsbuild-error-overlay";
227
227
  if (customElements && !customElements.get(overlayId)) {
228
228
  customElements.define(overlayId, ErrorOverlay);
229
229
  }
230
- var documentAvailable = typeof document !== "undefined";
231
230
  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
231
  clearOverlay();
237
232
  document.body.appendChild(new ErrorOverlay(err));
238
233
  }
239
234
  function clearOverlay() {
240
- if (!documentAvailable) {
241
- return;
242
- }
243
235
  document.querySelectorAll(overlayId).forEach(function(n) {
244
236
  return n.close();
245
237
  });
246
238
  }
247
- registerOverlay({
248
- createOverlay: createOverlay,
249
- clearOverlay: clearOverlay
250
- });
239
+ if (typeof document !== "undefined") {
240
+ registerOverlay(createOverlay, clearOverlay);
241
+ } else {
242
+ console.info("[Rsbuild] Failed to display error overlay as document is not available, you can disable the `dev.client.overlay` option.");
243
+ }
@@ -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.6.7",
47
+ version: "0.6.8",
48
48
  rootPath,
49
49
  distPath,
50
50
  cachePath,
package/dist/index.js CHANGED
@@ -40,7 +40,7 @@ var import_config = require("./config");
40
40
  var import_shared = require("@rsbuild/shared");
41
41
  var import_mergeConfig = require("./mergeConfig");
42
42
  var import_constants = require("./constants");
43
- const version = "0.6.7";
43
+ const version = "0.6.8";
44
44
  // Annotate the CommonJS export names for ESM import in node:
45
45
  0 && (module.exports = {
46
46
  PLUGIN_CSS_NAME,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/core",
3
- "version": "0.6.7",
3
+ "version": "0.6.8",
4
4
  "description": "The Rspack-based build tool.",
5
5
  "homepage": "https://rsbuild.dev",
6
6
  "bugs": {
@@ -51,9 +51,9 @@
51
51
  "@rspack/core": "0.6.3",
52
52
  "@swc/helpers": "0.5.3",
53
53
  "core-js": "~3.36.0",
54
- "html-webpack-plugin": "npm:html-rspack-plugin@5.6.2",
54
+ "html-webpack-plugin": "npm:html-rspack-plugin@5.7.0",
55
55
  "postcss": "^8.4.38",
56
- "@rsbuild/shared": "0.6.7"
56
+ "@rsbuild/shared": "0.6.8"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@types/node": "18.x",
@@ -1,12 +0,0 @@
1
- import type { ClientConfig } from '@rsbuild/shared';
2
- /**
3
- * hmr socket connect path
4
- */
5
- export declare const HMR_SOCK_PATH = "/rsbuild-hmr";
6
- export declare function createSocketUrl(options?: ClientConfig): string;
7
- export declare function formatURL({ port, protocol, hostname, pathname, }: {
8
- port: string;
9
- protocol: string;
10
- hostname: string;
11
- pathname: string;
12
- }): string;