@rsbuild/core 0.3.1 → 0.3.2

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.
@@ -86,7 +86,7 @@ async function init({
86
86
  }
87
87
  }
88
88
  function runCli() {
89
- import_commander.program.name("rsbuild").usage("<command> [options]").version("0.3.1");
89
+ import_commander.program.name("rsbuild").usage("<command> [options]").version("0.3.2");
90
90
  import_commander.program.command("dev").option("-o --open [url]", "open the page in browser on startup").option(
91
91
  "--port <port>",
92
92
  "specify a port number for Rsbuild Server to listen"
@@ -34,7 +34,7 @@ function prepareCli() {
34
34
  if (!npm_execpath || npm_execpath.includes("npx-cli.js")) {
35
35
  console.log();
36
36
  }
37
- import_rslog.logger.greet(` ${`Rsbuild v${"0.3.1"}`}
37
+ import_rslog.logger.greet(` ${`Rsbuild v${"0.3.2"}`}
38
38
  `);
39
39
  }
40
40
  // Annotate the CommonJS export names for ESM import in node:
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Copyright (c) 2015-present, Facebook, Inc.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file at
6
+ * https://github.com/facebook/create-react-app/blob/master/LICENSE
7
+ */
8
+ import type { StatsCompilation } from 'webpack';
9
+ export declare function formatStatsMessages(json?: Pick<StatsCompilation, 'errors' | 'warnings'>): {
10
+ errors: string[];
11
+ warnings: string[];
12
+ };
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var formatStats_exports = {};
20
+ __export(formatStats_exports, {
21
+ formatStatsMessages: () => formatStatsMessages
22
+ });
23
+ module.exports = __toCommonJS(formatStats_exports);
24
+ const friendlySyntaxErrorLabel = "SyntaxError:";
25
+ function isLikelyASyntaxError(message) {
26
+ return message.includes(friendlySyntaxErrorLabel);
27
+ }
28
+ function formatMessage(stats) {
29
+ let lines = [];
30
+ let message;
31
+ if (typeof stats === "object") {
32
+ const fileName = stats.moduleName ? `File: ${stats.moduleName}
33
+ ` : "";
34
+ const mainMessage = typeof stats.formatted === "string" ? stats.formatted : stats.message;
35
+ const details = stats.details ? `
36
+ Details: ${stats.details}
37
+ ` : "";
38
+ const stack = stats.stack ? `
39
+ ${stats.stack}` : "";
40
+ message = `${fileName}${mainMessage}${details}${stack}`;
41
+ } else {
42
+ message = stats;
43
+ }
44
+ lines = message.split("\n");
45
+ lines = lines.map((line) => {
46
+ const parsingError = /Line (\d+):(?:(\d+):)?\s*Parsing error: (.+)$/.exec(
47
+ line
48
+ );
49
+ if (!parsingError) {
50
+ return line;
51
+ }
52
+ const [, errorLine, errorColumn, errorMessage] = parsingError;
53
+ return `${friendlySyntaxErrorLabel} ${errorMessage} (${errorLine}:${errorColumn})`;
54
+ });
55
+ message = lines.join("\n");
56
+ message = message.replace(
57
+ /SyntaxError\s+\((\d+):(\d+)\)\s*(.+?)\n/g,
58
+ `${friendlySyntaxErrorLabel} $3 ($1:$2)
59
+ `
60
+ );
61
+ lines = message.split("\n");
62
+ if (lines.length > 2 && lines[1].trim() === "") {
63
+ lines.splice(1, 1);
64
+ }
65
+ lines[0] = lines[0].replace(/^(.*) \d+:\d+-\d+$/, "$1");
66
+ if (lines[1] && lines[1].indexOf("Module not found:") !== -1) {
67
+ lines[1] = lines[1].replace("Error: ", "");
68
+ }
69
+ lines = lines.filter(
70
+ (line, index, arr) => index === 0 || line.trim() !== "" || line.trim() !== arr[index - 1].trim()
71
+ );
72
+ message = lines.join("\n");
73
+ return message.trim();
74
+ }
75
+ function formatStatsMessages(json) {
76
+ const formattedErrors = json?.errors?.map(formatMessage);
77
+ const formattedWarnings = json?.warnings?.map(formatMessage);
78
+ const result = {
79
+ errors: formattedErrors || [],
80
+ warnings: formattedWarnings || [],
81
+ errorTips: []
82
+ };
83
+ if (result.errors?.some(isLikelyASyntaxError)) {
84
+ result.errors = result.errors.filter(isLikelyASyntaxError);
85
+ }
86
+ if (result.errors.length > 1) {
87
+ result.errors.length = 1;
88
+ }
89
+ return result;
90
+ }
91
+ // Annotate the CommonJS export names for ESM import in node:
92
+ 0 && (module.exports = {
93
+ formatStatsMessages
94
+ });
@@ -169,179 +169,65 @@ function _ts_generator(thisArg, body) {
169
169
  };
170
170
  }
171
171
  }
172
- var __create = Object.create;
173
- var __defProp = Object.defineProperty;
174
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
175
- var __getOwnPropNames = Object.getOwnPropertyNames;
176
- var __getProtoOf = Object.getPrototypeOf;
177
- var __hasOwnProp = Object.prototype.hasOwnProperty;
178
- var __commonJS = function(cb, mod) {
179
- return function __require() {
180
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = {
181
- exports: {}
182
- }).exports, mod), mod.exports;
183
- };
184
- };
185
- var __copyProps = function(to, from, except, desc) {
186
- if (from && typeof from === "object" || typeof from === "function") {
187
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
188
- try {
189
- var _loop = function() {
190
- var key = _step.value;
191
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
192
- get: function() {
193
- return from[key];
194
- },
195
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
196
- });
197
- };
198
- for(var _iterator = __getOwnPropNames(from)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
199
- } catch (err) {
200
- _didIteratorError = true;
201
- _iteratorError = err;
202
- } finally{
203
- try {
204
- if (!_iteratorNormalCompletion && _iterator.return != null) {
205
- _iterator.return();
206
- }
207
- } finally{
208
- if (_didIteratorError) {
209
- throw _iteratorError;
210
- }
211
- }
212
- }
172
+ // src/client/formatStats.ts
173
+ var friendlySyntaxErrorLabel = "SyntaxError:";
174
+ function isLikelyASyntaxError(message) {
175
+ return message.includes(friendlySyntaxErrorLabel);
176
+ }
177
+ function formatMessage(stats) {
178
+ var lines = [];
179
+ var message;
180
+ if (typeof stats === "object") {
181
+ var fileName = stats.moduleName ? "File: ".concat(stats.moduleName, "\n") : "";
182
+ var mainMessage = typeof stats.formatted === "string" ? stats.formatted : stats.message;
183
+ var details = stats.details ? "\nDetails: ".concat(stats.details, "\n") : "";
184
+ var stack = stats.stack ? "\n".concat(stats.stack) : "";
185
+ message = "".concat(fileName).concat(mainMessage).concat(details).concat(stack);
186
+ } else {
187
+ message = stats;
213
188
  }
214
- return to;
215
- };
216
- var __toESM = function(mod, isNodeMode, target) {
217
- return target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(// If the importer is in node compatibility mode or this is not an ESM
218
- // file that has been converted to a CommonJS file using a Babel-
219
- // compatible transform (i.e. "__esModule" has not been set), then set
220
- // "default" to the CommonJS "module.exports" for node compatibility.
221
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
222
- value: mod,
223
- enumerable: true
224
- }) : target, mod);
225
- };
226
- // ../shared/dist/formatStats.js
227
- var require_formatStats = __commonJS({
228
- "../shared/dist/formatStats.js": function(exports2, module2) {
229
- "use strict";
230
- var __defProp2 = Object.defineProperty;
231
- var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
232
- var __getOwnPropNames2 = Object.getOwnPropertyNames;
233
- var __hasOwnProp2 = Object.prototype.hasOwnProperty;
234
- var __export = function(target, all) {
235
- for(var name in all)__defProp2(target, name, {
236
- get: all[name],
237
- enumerable: true
238
- });
239
- };
240
- var __copyProps2 = function(to, from, except, desc) {
241
- if (from && typeof from === "object" || typeof from === "function") {
242
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
243
- try {
244
- var _loop = function() {
245
- var key = _step.value;
246
- if (!__hasOwnProp2.call(to, key) && key !== except) __defProp2(to, key, {
247
- get: function() {
248
- return from[key];
249
- },
250
- enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable
251
- });
252
- };
253
- for(var _iterator = __getOwnPropNames2(from)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
254
- } catch (err) {
255
- _didIteratorError = true;
256
- _iteratorError = err;
257
- } finally{
258
- try {
259
- if (!_iteratorNormalCompletion && _iterator.return != null) {
260
- _iterator.return();
261
- }
262
- } finally{
263
- if (_didIteratorError) {
264
- throw _iteratorError;
265
- }
266
- }
267
- }
268
- }
269
- return to;
270
- };
271
- var __toCommonJS = function(mod) {
272
- return __copyProps2(__defProp2({}, "__esModule", {
273
- value: true
274
- }), mod);
275
- };
276
- var formatStats_exports = {};
277
- __export(formatStats_exports, {
278
- formatStatsMessages: function() {
279
- return formatStatsMessages2;
280
- }
281
- });
282
- module2.exports = __toCommonJS(formatStats_exports);
283
- var friendlySyntaxErrorLabel = "SyntaxError:";
284
- function isLikelyASyntaxError(message) {
285
- return message.includes(friendlySyntaxErrorLabel);
286
- }
287
- function formatMessage(stats) {
288
- var lines = [];
289
- var message;
290
- if (typeof stats === "object") {
291
- var fileName = stats.moduleName ? "File: ".concat(stats.moduleName, "\n") : "";
292
- var mainMessage = typeof stats.formatted === "string" ? stats.formatted : stats.message;
293
- var details = stats.details ? "\nDetails: ".concat(stats.details, "\n") : "";
294
- var stack = stats.stack ? "\n".concat(stats.stack) : "";
295
- message = "".concat(fileName).concat(mainMessage).concat(details).concat(stack);
296
- } else {
297
- message = stats;
298
- }
299
- lines = message.split("\n");
300
- lines = lines.map(function(line) {
301
- var parsingError = /Line (\d+):(?:(\d+):)?\s*Parsing error: (.+)$/.exec(line);
302
- if (!parsingError) {
303
- return line;
304
- }
305
- var _parsingError = _sliced_to_array(parsingError, 4), errorLine = _parsingError[1], errorColumn = _parsingError[2], errorMessage = _parsingError[3];
306
- return "".concat(friendlySyntaxErrorLabel, " ").concat(errorMessage, " (").concat(errorLine, ":").concat(errorColumn, ")");
307
- });
308
- message = lines.join("\n");
309
- message = message.replace(/SyntaxError\s+\((\d+):(\d+)\)\s*(.+?)\n/g, "".concat(friendlySyntaxErrorLabel, " $3 ($1:$2)\n"));
310
- lines = message.split("\n");
311
- if (lines.length > 2 && lines[1].trim() === "") {
312
- lines.splice(1, 1);
313
- }
314
- lines[0] = lines[0].replace(/^(.*) \d+:\d+-\d+$/, "$1");
315
- if (lines[1] && lines[1].indexOf("Module not found:") !== -1) {
316
- lines[1] = lines[1].replace("Error: ", "");
317
- }
318
- lines = lines.filter(function(line, index, arr) {
319
- return index === 0 || line.trim() !== "" || line.trim() !== arr[index - 1].trim();
320
- });
321
- message = lines.join("\n");
322
- return message.trim();
323
- }
324
- function formatStatsMessages2(json) {
325
- var _json_errors, _json_warnings, _result_errors;
326
- var formattedErrors = json === null || json === void 0 ? void 0 : (_json_errors = json.errors) === null || _json_errors === void 0 ? void 0 : _json_errors.map(formatMessage);
327
- var formattedWarnings = json === null || json === void 0 ? void 0 : (_json_warnings = json.warnings) === null || _json_warnings === void 0 ? void 0 : _json_warnings.map(formatMessage);
328
- var result = {
329
- errors: formattedErrors || [],
330
- warnings: formattedWarnings || [],
331
- errorTips: []
332
- };
333
- if ((_result_errors = result.errors) === null || _result_errors === void 0 ? void 0 : _result_errors.some(isLikelyASyntaxError)) {
334
- result.errors = result.errors.filter(isLikelyASyntaxError);
335
- }
336
- if (result.errors.length > 1) {
337
- result.errors.length = 1;
338
- }
339
- return result;
189
+ lines = message.split("\n");
190
+ lines = lines.map(function(line) {
191
+ var parsingError = /Line (\d+):(?:(\d+):)?\s*Parsing error: (.+)$/.exec(line);
192
+ if (!parsingError) {
193
+ return line;
340
194
  }
195
+ var _parsingError = _sliced_to_array(parsingError, 4), errorLine = _parsingError[1], errorColumn = _parsingError[2], errorMessage = _parsingError[3];
196
+ return "".concat(friendlySyntaxErrorLabel, " ").concat(errorMessage, " (").concat(errorLine, ":").concat(errorColumn, ")");
197
+ });
198
+ message = lines.join("\n");
199
+ message = message.replace(/SyntaxError\s+\((\d+):(\d+)\)\s*(.+?)\n/g, "".concat(friendlySyntaxErrorLabel, " $3 ($1:$2)\n"));
200
+ lines = message.split("\n");
201
+ if (lines.length > 2 && lines[1].trim() === "") {
202
+ lines.splice(1, 1);
341
203
  }
342
- });
343
- // src/client/hmr/index.ts
344
- var import_format_stats = __toESM(require_formatStats());
204
+ lines[0] = lines[0].replace(/^(.*) \d+:\d+-\d+$/, "$1");
205
+ if (lines[1] && lines[1].indexOf("Module not found:") !== -1) {
206
+ lines[1] = lines[1].replace("Error: ", "");
207
+ }
208
+ lines = lines.filter(function(line, index, arr) {
209
+ return index === 0 || line.trim() !== "" || line.trim() !== arr[index - 1].trim();
210
+ });
211
+ message = lines.join("\n");
212
+ return message.trim();
213
+ }
214
+ function formatStatsMessages(json) {
215
+ var _json_errors, _json_warnings, _result_errors;
216
+ var formattedErrors = json === null || json === void 0 ? void 0 : (_json_errors = json.errors) === null || _json_errors === void 0 ? void 0 : _json_errors.map(formatMessage);
217
+ var formattedWarnings = json === null || json === void 0 ? void 0 : (_json_warnings = json.warnings) === null || _json_warnings === void 0 ? void 0 : _json_warnings.map(formatMessage);
218
+ var result = {
219
+ errors: formattedErrors || [],
220
+ warnings: formattedWarnings || [],
221
+ errorTips: []
222
+ };
223
+ if ((_result_errors = result.errors) === null || _result_errors === void 0 ? void 0 : _result_errors.some(isLikelyASyntaxError)) {
224
+ result.errors = result.errors.filter(isLikelyASyntaxError);
225
+ }
226
+ if (result.errors.length > 1) {
227
+ result.errors.length = 1;
228
+ }
229
+ return result;
230
+ }
345
231
  // src/client/hmr/createSocketUrl.ts
346
232
  var HMR_SOCK_PATH = "/rsbuild-hmr";
347
233
  function createSocketUrl(resourceQuery) {
@@ -420,7 +306,7 @@ function handleWarnings(warnings) {
420
306
  isFirstCompilation = false;
421
307
  hasCompileErrors = false;
422
308
  function printWarnings() {
423
- var formatted = (0, import_format_stats.formatStatsMessages)({
309
+ var formatted = formatStatsMessages({
424
310
  warnings: warnings,
425
311
  errors: []
426
312
  });
@@ -443,7 +329,7 @@ function handleErrors(errors) {
443
329
  clearOutdatedErrors();
444
330
  isFirstCompilation = false;
445
331
  hasCompileErrors = true;
446
- var formatted = (0, import_format_stats.formatStatsMessages)({
332
+ var formatted = formatStatsMessages({
447
333
  errors: errors,
448
334
  warnings: []
449
335
  });
@@ -0,0 +1,6 @@
1
+ export declare const PLUGIN_SWC_NAME = "rsbuild:swc";
2
+ export declare const PLUGIN_CSS_NAME = "rsbuild:css";
3
+ export declare const PLUGIN_LESS_NAME = "rsbuild:less";
4
+ export declare const PLUGIN_SASS_NAME = "rsbuild:sass";
5
+ export declare const PLUGIN_BABEL_NAME = "rsbuild:babel";
6
+ export declare const PLUGIN_STYLUS_NAME = "rsbuild:stylus";
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var constants_exports = {};
20
+ __export(constants_exports, {
21
+ PLUGIN_BABEL_NAME: () => PLUGIN_BABEL_NAME,
22
+ PLUGIN_CSS_NAME: () => PLUGIN_CSS_NAME,
23
+ PLUGIN_LESS_NAME: () => PLUGIN_LESS_NAME,
24
+ PLUGIN_SASS_NAME: () => PLUGIN_SASS_NAME,
25
+ PLUGIN_STYLUS_NAME: () => PLUGIN_STYLUS_NAME,
26
+ PLUGIN_SWC_NAME: () => PLUGIN_SWC_NAME
27
+ });
28
+ module.exports = __toCommonJS(constants_exports);
29
+ const PLUGIN_SWC_NAME = "rsbuild:swc";
30
+ const PLUGIN_CSS_NAME = "rsbuild:css";
31
+ const PLUGIN_LESS_NAME = "rsbuild:less";
32
+ const PLUGIN_SASS_NAME = "rsbuild:sass";
33
+ const PLUGIN_BABEL_NAME = "rsbuild:babel";
34
+ const PLUGIN_STYLUS_NAME = "rsbuild:stylus";
35
+ // Annotate the CommonJS export names for ESM import in node:
36
+ 0 && (module.exports = {
37
+ PLUGIN_BABEL_NAME,
38
+ PLUGIN_CSS_NAME,
39
+ PLUGIN_LESS_NAME,
40
+ PLUGIN_SASS_NAME,
41
+ PLUGIN_STYLUS_NAME,
42
+ PLUGIN_SWC_NAME
43
+ });
package/dist/index.d.ts CHANGED
@@ -7,6 +7,7 @@ export { createRsbuild } from './createRsbuild';
7
7
  export { loadConfig, defineConfig } from './cli/config';
8
8
  export declare const version: any;
9
9
  export { logger, mergeRsbuildConfig } from '@rsbuild/shared';
10
+ export { PLUGIN_SWC_NAME, PLUGIN_CSS_NAME, PLUGIN_SASS_NAME, PLUGIN_LESS_NAME, PLUGIN_BABEL_NAME, PLUGIN_STYLUS_NAME, } from './constants';
10
11
  export type { Rspack } from './provider';
11
- export type { RsbuildConfig, NormalizedConfig, RsbuildPlugin, RsbuildPlugins, RsbuildPluginAPI, } from './types';
12
+ export type { RsbuildConfig, DevConfig, HtmlConfig, ToolsConfig, SourceConfig, OutputConfig, SecurityConfig, PerformanceConfig, NormalizedConfig, NormalizedDevConfig, NormalizedHtmlConfig, NormalizedToolsConfig, NormalizedSourceConfig, NormalizedOutputConfig, NormalizedSecurityConfig, NormalizedPerformanceConfig, RsbuildPlugin, RsbuildPlugins, RsbuildPluginAPI, } from './types';
12
13
  export type { RsbuildMode, RsbuildEntry, RsbuildTarget, RsbuildContext, RsbuildInstance, CreateRsbuildOptions, InspectConfigOptions, OnExitFn, OnAfterBuildFn, OnAfterCreateCompilerFn, OnAfterStartDevServerFn, OnAfterStartProdServerFn, OnBeforeBuildFn, OnBeforeStartDevServerFn, OnBeforeStartProdServerFn, OnBeforeCreateCompilerFn, OnDevCompileDoneFn, ModifyRsbuildConfigFn, } from '@rsbuild/shared';
package/dist/index.js CHANGED
@@ -18,6 +18,12 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var src_exports = {};
20
20
  __export(src_exports, {
21
+ PLUGIN_BABEL_NAME: () => import_constants.PLUGIN_BABEL_NAME,
22
+ PLUGIN_CSS_NAME: () => import_constants.PLUGIN_CSS_NAME,
23
+ PLUGIN_LESS_NAME: () => import_constants.PLUGIN_LESS_NAME,
24
+ PLUGIN_SASS_NAME: () => import_constants.PLUGIN_SASS_NAME,
25
+ PLUGIN_STYLUS_NAME: () => import_constants.PLUGIN_STYLUS_NAME,
26
+ PLUGIN_SWC_NAME: () => import_constants.PLUGIN_SWC_NAME,
21
27
  createRsbuild: () => import_createRsbuild.createRsbuild,
22
28
  defineConfig: () => import_config.defineConfig,
23
29
  loadConfig: () => import_config.loadConfig,
@@ -31,9 +37,16 @@ var import_loadEnv = require("./loadEnv");
31
37
  var import_createRsbuild = require("./createRsbuild");
32
38
  var import_config = require("./cli/config");
33
39
  var import_shared = require("@rsbuild/shared");
34
- const version = "0.3.1";
40
+ var import_constants = require("./constants");
41
+ const version = "0.3.2";
35
42
  // Annotate the CommonJS export names for ESM import in node:
36
43
  0 && (module.exports = {
44
+ PLUGIN_BABEL_NAME,
45
+ PLUGIN_CSS_NAME,
46
+ PLUGIN_LESS_NAME,
47
+ PLUGIN_SASS_NAME,
48
+ PLUGIN_STYLUS_NAME,
49
+ PLUGIN_SWC_NAME,
37
50
  createRsbuild,
38
51
  defineConfig,
39
52
  loadConfig,
@@ -93,7 +93,7 @@ async function createCompiler({
93
93
  printTime(obj, 0);
94
94
  }
95
95
  }
96
- const { message, level } = (0, import_shared.formatStats)(stats);
96
+ const { message, level } = (0, import_shared2.formatStats)(stats);
97
97
  if (level === "error") {
98
98
  import_shared.logger.error(message);
99
99
  }
@@ -59,7 +59,7 @@ function createContextByConfig(options, bundlerType, config = {}) {
59
59
  const context = {
60
60
  entry: config.source?.entry || getDefaultEntry(rootPath),
61
61
  targets: config.output?.targets || [],
62
- version: "0.3.1",
62
+ version: "0.3.2",
63
63
  rootPath,
64
64
  distPath,
65
65
  cachePath,
@@ -9,3 +9,4 @@ export { getPluginAPI } from './core/initPlugins';
9
9
  export { applyBaseCSSRule, applyCSSModuleRule } from './plugins/css';
10
10
  export type { InternalContext } from '../types';
11
11
  export { setHTMLPlugin, getHTMLPlugin } from './htmlPluginUtil';
12
+ export { formatStats } from './shared';
@@ -22,6 +22,7 @@ __export(provider_exports, {
22
22
  applyCSSModuleRule: () => import_css.applyCSSModuleRule,
23
23
  createContext: () => import_createContext.createContext,
24
24
  createPublicContext: () => import_createContext.createPublicContext,
25
+ formatStats: () => import_shared2.formatStats,
25
26
  getHTMLPlugin: () => import_htmlPluginUtil.getHTMLPlugin,
26
27
  getPluginAPI: () => import_initPlugins.getPluginAPI,
27
28
  initHooks: () => import_initHooks.initHooks,
@@ -41,12 +42,14 @@ var import_initConfigs = require("./core/initConfigs");
41
42
  var import_initPlugins = require("./core/initPlugins");
42
43
  var import_css = require("./plugins/css");
43
44
  var import_htmlPluginUtil = require("./htmlPluginUtil");
45
+ var import_shared2 = require("./shared");
44
46
  // Annotate the CommonJS export names for ESM import in node:
45
47
  0 && (module.exports = {
46
48
  applyBaseCSSRule,
47
49
  applyCSSModuleRule,
48
50
  createContext,
49
51
  createPublicContext,
52
+ formatStats,
50
53
  getHTMLPlugin,
51
54
  getPluginAPI,
52
55
  initHooks,
@@ -34,6 +34,7 @@ __export(swc_exports, {
34
34
  module.exports = __toCommonJS(swc_exports);
35
35
  var import_shared = require("@rsbuild/shared");
36
36
  var import_path = __toESM(require("path"));
37
+ var import_constants = require("../../constants");
37
38
  const builtinSwcLoaderName = "builtin:swc-loader";
38
39
  async function getDefaultSwcConfig(config, rootPath, target) {
39
40
  return {
@@ -56,7 +57,7 @@ async function getDefaultSwcConfig(config, rootPath, target) {
56
57
  };
57
58
  }
58
59
  const pluginSwc = () => ({
59
- name: "rsbuild:swc",
60
+ name: import_constants.PLUGIN_SWC_NAME,
60
61
  setup(api) {
61
62
  api.modifyBundlerChain(async (chain, { CHAIN_ID, target }) => {
62
63
  const config = api.getNormalizedConfig();
@@ -1,3 +1,4 @@
1
+ import { type Stats, type MultiStats } from '@rsbuild/shared';
1
2
  import type { RsbuildPlugin } from '../types';
2
3
  import { type Plugins } from '@rsbuild/shared';
3
4
  export declare const applyDefaultPlugins: (plugins: Plugins) => import("@rsbuild/shared").AwaitableGetter<RsbuildPlugin>;
@@ -5,3 +6,10 @@ export declare const rspackMinVersion = "0.5.0";
5
6
  export declare const isSatisfyRspackVersion: (originalVersion: string) => Promise<boolean>;
6
7
  export declare const getCompiledPath: (packageName: string) => string;
7
8
  export declare const BUILTIN_LOADER = "builtin:";
9
+ export declare function formatStats(stats: Stats | MultiStats, showWarnings?: boolean): {
10
+ message: string;
11
+ level: string;
12
+ } | {
13
+ message?: undefined;
14
+ level?: undefined;
15
+ };
@@ -30,6 +30,7 @@ var shared_exports = {};
30
30
  __export(shared_exports, {
31
31
  BUILTIN_LOADER: () => BUILTIN_LOADER,
32
32
  applyDefaultPlugins: () => applyDefaultPlugins,
33
+ formatStats: () => formatStats,
33
34
  getCompiledPath: () => getCompiledPath,
34
35
  isSatisfyRspackVersion: () => isSatisfyRspackVersion,
35
36
  rspackMinVersion: () => rspackMinVersion
@@ -39,6 +40,7 @@ var import_path = require("path");
39
40
  var import_shared = require("@rsbuild/shared");
40
41
  var import_shared2 = require("@rsbuild/shared");
41
42
  var import_shared3 = require("@rsbuild/shared");
43
+ var import_formatStats = require("../client/formatStats");
42
44
  const applyDefaultPlugins = (plugins) => (0, import_shared3.awaitableGetter)([
43
45
  Promise.resolve().then(() => __toESM(require("./plugins/transition"))).then((m) => m.pluginTransition()),
44
46
  plugins.basic(),
@@ -108,10 +110,43 @@ const getCompiledPath = (packageName) => {
108
110
  return (0, import_shared.getSharedPkgCompiledPath)(packageName);
109
111
  };
110
112
  const BUILTIN_LOADER = "builtin:";
113
+ function formatStats(stats, showWarnings = true) {
114
+ const statsData = stats.toJson({
115
+ preset: "errors-warnings"
116
+ });
117
+ const { errors, warnings } = (0, import_formatStats.formatStatsMessages)(statsData);
118
+ if (errors.length) {
119
+ const errorMsgs = `${errors.join("\n\n")}
120
+ `;
121
+ const isTerserError = errorMsgs.includes("from Terser");
122
+ const title = import_shared.color.bold(
123
+ import_shared.color.red(isTerserError ? "Minify error: " : "Compile error: ")
124
+ );
125
+ const tip = import_shared.color.yellow(
126
+ isTerserError ? "Failed to minify with terser, check for syntax errors." : "Failed to compile, check the errors for troubleshooting."
127
+ );
128
+ return {
129
+ message: `${title}
130
+ ${tip}
131
+ ${errorMsgs}`,
132
+ level: "error"
133
+ };
134
+ }
135
+ if (warnings.length && (showWarnings || process.stdout.isTTY)) {
136
+ const title = import_shared.color.bold(import_shared.color.yellow("Compile Warning: \n"));
137
+ return {
138
+ message: `${title}${`${warnings.join("\n\n")}
139
+ `}`,
140
+ level: "warning"
141
+ };
142
+ }
143
+ return {};
144
+ }
111
145
  // Annotate the CommonJS export names for ESM import in node:
112
146
  0 && (module.exports = {
113
147
  BUILTIN_LOADER,
114
148
  applyDefaultPlugins,
149
+ formatStats,
115
150
  getCompiledPath,
116
151
  isSatisfyRspackVersion,
117
152
  rspackMinVersion
@@ -34,6 +34,7 @@ __export(middlewares_exports, {
34
34
  });
35
35
  module.exports = __toCommonJS(middlewares_exports);
36
36
  var import_shared = require("@rsbuild/shared");
37
+ var import_url = require("url");
37
38
  var import_path = __toESM(require("path"));
38
39
  var import_fs = __toESM(require("fs"));
39
40
  const faviconFallbackMiddleware = (req, res, next) => {
@@ -62,7 +63,7 @@ const getHtmlFallbackMiddleware = ({ htmlFallback, distPath, callback }) => {
62
63
  const { url } = req;
63
64
  let pathname = url;
64
65
  try {
65
- pathname = decodeURIComponent(url);
66
+ pathname = (0, import_url.parse)(url, false, true).pathname;
66
67
  } catch (err) {
67
68
  import_shared.logger.error(
68
69
  new Error(`Invalid URL: ${import_shared.color.yellow(url)}`, { cause: err })
@@ -85,7 +86,7 @@ const getHtmlFallbackMiddleware = ({ htmlFallback, distPath, callback }) => {
85
86
  return next();
86
87
  };
87
88
  if (pathname.endsWith("/")) {
88
- const newUrl = `${url}index.html`;
89
+ const newUrl = `${pathname}index.html`;
89
90
  const filePath = import_path.default.join(distPath, pathname, "index.html");
90
91
  if (outputFileSystem.existsSync(filePath)) {
91
92
  return rewrite(newUrl);
@@ -94,7 +95,7 @@ const getHtmlFallbackMiddleware = ({ htmlFallback, distPath, callback }) => {
94
95
  // '/main' => '/main.html'
95
96
  !pathname.endsWith(".html")
96
97
  ) {
97
- const newUrl = `${url}.html`;
98
+ const newUrl = `${pathname}.html`;
98
99
  const filePath = import_path.default.join(distPath, `${pathname}.html`);
99
100
  if (outputFileSystem.existsSync(filePath)) {
100
101
  return rewrite(newUrl);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/core",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "The Rspack-based build tool.",
5
5
  "homepage": "https://rsbuild.dev",
6
6
  "bugs": {
@@ -61,7 +61,7 @@
61
61
  "core-js": "~3.32.2",
62
62
  "html-webpack-plugin": "npm:html-rspack-plugin@5.5.7",
63
63
  "postcss": "8.4.31",
64
- "@rsbuild/shared": "0.3.1"
64
+ "@rsbuild/shared": "0.3.2"
65
65
  },
66
66
  "devDependencies": {
67
67
  "@types/node": "16.x",