@rsbuild/core 0.3.7 → 0.3.9

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.
@@ -0,0 +1,13 @@
1
+ /// <reference types="node" />
2
+ import { IncomingMessage, OutgoingMessage } from 'http';
3
+
4
+ export = onFinished;
5
+
6
+ declare function onFinished<T extends IncomingMessage | OutgoingMessage>(
7
+ msg: T,
8
+ listener: (err: Error | null, msg: T) => void,
9
+ ): T;
10
+
11
+ declare namespace onFinished {
12
+ function isFinished(msg: IncomingMessage | OutgoingMessage): boolean;
13
+ }
@@ -0,0 +1,14 @@
1
+ (()=>{"use strict";var e={261:e=>{
2
+ /*!
3
+ * ee-first
4
+ * Copyright(c) 2014 Jonathan Ong
5
+ * MIT Licensed
6
+ */
7
+ e.exports=first;function first(e,n){if(!Array.isArray(e))throw new TypeError("arg must be an array of [ee, events...] arrays");var r=[];for(var t=0;t<e.length;t++){var i=e[t];if(!Array.isArray(i)||i.length<2)throw new TypeError("each array member must be [ee, events...]");var o=i[0];for(var a=1;a<i.length;a++){var s=i[a];var u=listener(s,callback);o.on(s,u);r.push({ee:o,event:s,fn:u})}}function callback(){cleanup();n.apply(null,arguments)}function cleanup(){var e;for(var n=0;n<r.length;n++){e=r[n];e.ee.removeListener(e.event,e.fn)}}function thunk(e){n=e}thunk.cancel=cleanup;return thunk}function listener(e,n){return function onevent(r){var t=new Array(arguments.length);var i=this;var o=e==="error"?r:null;for(var a=0;a<t.length;a++){t[a]=arguments[a]}n(o,i,e,t)}}},772:(e,n,r)=>{
8
+ /*!
9
+ * on-finished
10
+ * Copyright(c) 2013 Jonathan Ong
11
+ * Copyright(c) 2014 Douglas Christopher Wilson
12
+ * MIT Licensed
13
+ */
14
+ e.exports=onFinished;e.exports.isFinished=isFinished;var t=tryRequireAsyncHooks();var i=r(261);var o=typeof setImmediate==="function"?setImmediate:function(e){process.nextTick(e.bind.apply(e,arguments))};function onFinished(e,n){if(isFinished(e)!==false){o(n,null,e);return e}attachListener(e,wrap(n));return e}function isFinished(e){var n=e.socket;if(typeof e.finished==="boolean"){return Boolean(e.finished||n&&!n.writable)}if(typeof e.complete==="boolean"){return Boolean(e.upgrade||!n||!n.readable||e.complete&&!e.readable)}return undefined}function attachFinishedListener(e,n){var r;var t;var o=false;function onFinish(e){r.cancel();t.cancel();o=true;n(e)}r=t=i([[e,"end","finish"]],onFinish);function onSocket(n){e.removeListener("socket",onSocket);if(o)return;if(r!==t)return;t=i([[n,"error","close"]],onFinish)}if(e.socket){onSocket(e.socket);return}e.on("socket",onSocket);if(e.socket===undefined){patchAssignSocket(e,onSocket)}}function attachListener(e,n){var r=e.__onFinished;if(!r||!r.queue){r=e.__onFinished=createListener(e);attachFinishedListener(e,r)}r.queue.push(n)}function createListener(e){function listener(n){if(e.__onFinished===listener)e.__onFinished=null;if(!listener.queue)return;var r=listener.queue;listener.queue=null;for(var t=0;t<r.length;t++){r[t](n,e)}}listener.queue=[];return listener}function patchAssignSocket(e,n){var r=e.assignSocket;if(typeof r!=="function")return;e.assignSocket=function _assignSocket(e){r.call(this,e);n(e)}}function tryRequireAsyncHooks(){try{return r(852)}catch(e){return{}}}function wrap(e){var n;if(t.AsyncResource){n=new t.AsyncResource(e.name||"bound-anonymous-fn")}if(!n||!n.runInAsyncScope){return e}return n.runInAsyncScope.bind(n,e,null)}},852:e=>{e.exports=require("async_hooks")}};var n={};function __nccwpck_require__(r){var t=n[r];if(t!==undefined){return t.exports}var i=n[r]={exports:{}};var o=true;try{e[r](i,i.exports,__nccwpck_require__);o=false}finally{if(o)delete n[r]}return i.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var r=__nccwpck_require__(772);module.exports=r})();
@@ -0,0 +1,23 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2013 Jonathan Ong <me@jongleberry.com>
4
+ Copyright (c) 2014 Douglas Christopher Wilson <doug@somethingdoug.com>
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining
7
+ a copy of this software and associated documentation files (the
8
+ 'Software'), to deal in the Software without restriction, including
9
+ without limitation the rights to use, copy, modify, merge, publish,
10
+ distribute, sublicense, and/or sell copies of the Software, and to
11
+ permit persons to whom the Software is furnished to do so, subject to
12
+ the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be
15
+ included in all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
18
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1 @@
1
+ {"name":"on-finished","version":"2.4.1","license":"MIT","type":"commonjs"}
@@ -58,7 +58,8 @@ async function init({
58
58
  }
59
59
  const { content: config, filePath: configFilePath } = await (0, import_config.loadConfigV2)({
60
60
  cwd: root,
61
- path: commonOpts.config
61
+ path: commonOpts.config,
62
+ envMode: commonOpts.envMode
62
63
  });
63
64
  const command = process.argv[2];
64
65
  if (command === "dev") {
@@ -111,7 +112,7 @@ const applyServerOptions = (command) => {
111
112
  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");
112
113
  };
113
114
  function runCli() {
114
- import_commander.program.name("rsbuild").usage("<command> [options]").version("0.3.7");
115
+ import_commander.program.name("rsbuild").usage("<command> [options]").version("0.3.9");
115
116
  const devCommand = import_commander.program.command("dev");
116
117
  const buildCommand = import_commander.program.command("build");
117
118
  const previewCommand = import_commander.program.command("preview");
@@ -2,6 +2,7 @@ import { type RsbuildConfig } from '@rsbuild/shared';
2
2
  export type ConfigParams = {
3
3
  env: string;
4
4
  command: string;
5
+ envMode?: string;
5
6
  };
6
7
  export type RsbuildConfigAsyncFn = (env: ConfigParams) => Promise<RsbuildConfig>;
7
8
  export type RsbuildConfigSyncFn = (env: ConfigParams) => RsbuildConfig;
@@ -15,14 +16,15 @@ export declare function defineConfig(config: RsbuildConfigSyncFn): RsbuildConfig
15
16
  export declare function defineConfig(config: RsbuildConfigAsyncFn): RsbuildConfigAsyncFn;
16
17
  export declare function defineConfig(config: RsbuildConfigExport): RsbuildConfigExport;
17
18
  export declare function watchFiles(files: string[]): Promise<void>;
18
- export declare function loadConfigByPath(configFile: string): Promise<RsbuildConfig>;
19
+ export declare function loadConfigByPath(configFile: string, envMode?: string): Promise<RsbuildConfig>;
19
20
  export declare function loadConfig({ cwd, path, }: {
20
21
  cwd: string;
21
22
  path?: string;
22
23
  }): Promise<RsbuildConfig>;
23
- export declare function loadConfigV2({ cwd, path, }: {
24
+ export declare function loadConfigV2({ cwd, path, envMode, }: {
24
25
  cwd: string;
25
26
  path?: string;
27
+ envMode?: string;
26
28
  }): Promise<{
27
29
  content: RsbuildConfig;
28
30
  filePath: string | null;
@@ -90,7 +90,7 @@ async function watchFiles(files) {
90
90
  watcher.on("change", callback);
91
91
  watcher.on("unlink", callback);
92
92
  }
93
- async function loadConfigByPath(configFile) {
93
+ async function loadConfigByPath(configFile, envMode) {
94
94
  try {
95
95
  const { default: jiti } = await Promise.resolve().then(() => __toESM(require("@rsbuild/shared/jiti")));
96
96
  const loadConfig2 = jiti(__filename, {
@@ -104,7 +104,8 @@ async function loadConfigByPath(configFile) {
104
104
  const command = process.argv[2];
105
105
  const params = {
106
106
  env: (0, import_shared.getNodeEnv)(),
107
- command
107
+ command,
108
+ envMode: envMode || (0, import_shared.getNodeEnv)()
108
109
  };
109
110
  const result = await configExport(params);
110
111
  if (result === void 0) {
@@ -137,7 +138,8 @@ async function loadConfig({
137
138
  }
138
139
  async function loadConfigV2({
139
140
  cwd,
140
- path
141
+ path,
142
+ envMode
141
143
  }) {
142
144
  const configFile = resolveConfigPath(cwd, path);
143
145
  if (!configFile) {
@@ -147,7 +149,7 @@ async function loadConfigV2({
147
149
  };
148
150
  }
149
151
  return {
150
- content: await loadConfigByPath(configFile),
152
+ content: await loadConfigByPath(configFile, envMode),
151
153
  filePath: configFile
152
154
  };
153
155
  }
@@ -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.7"}`}
37
+ import_rslog.logger.greet(` ${`Rsbuild v${"0.3.9"}`}
38
38
  `);
39
39
  }
40
40
  // Annotate the CommonJS export names for ESM import in node:
package/dist/index.js CHANGED
@@ -38,7 +38,7 @@ var import_createRsbuild = require("./createRsbuild");
38
38
  var import_config = require("./cli/config");
39
39
  var import_shared = require("@rsbuild/shared");
40
40
  var import_constants = require("./constants");
41
- const version = "0.3.7";
41
+ const version = "0.3.9";
42
42
  // Annotate the CommonJS export names for ESM import in node:
43
43
  0 && (module.exports = {
44
44
  PLUGIN_BABEL_NAME,
@@ -21,19 +21,40 @@ __export(cleanOutput_exports, {
21
21
  pluginCleanOutput: () => pluginCleanOutput
22
22
  });
23
23
  module.exports = __toCommonJS(cleanOutput_exports);
24
+ var import_node_path = require("node:path");
24
25
  var import_shared = require("@rsbuild/shared");
25
26
  const emptyDir = async (dir) => {
26
27
  if (await import_shared.fse.pathExists(dir)) {
27
28
  await import_shared.fse.emptyDir(dir);
28
29
  }
29
30
  };
31
+ const addTrailingSep = (dir) => dir.endsWith(import_node_path.sep) ? dir : dir + import_node_path.sep;
32
+ const isStrictSubdir = (parent, child) => {
33
+ const parentDir = addTrailingSep(parent);
34
+ const childDir = addTrailingSep(child);
35
+ return parentDir !== childDir && childDir.startsWith(parentDir);
36
+ };
30
37
  const pluginCleanOutput = () => ({
31
38
  name: "rsbuild:clean-output",
32
39
  setup(api) {
33
40
  const clean = async () => {
41
+ const { distPath, rootPath } = api.context;
34
42
  const config = api.getNormalizedConfig();
35
- if (config.output.cleanDistPath) {
36
- const { distPath } = api.context;
43
+ let { cleanDistPath } = config.output;
44
+ if (cleanDistPath === void 0) {
45
+ cleanDistPath = isStrictSubdir(rootPath, distPath);
46
+ if (!cleanDistPath) {
47
+ import_shared.logger.warn(
48
+ "The dist path is not a subdir of root path, Rsbuild will not empty it."
49
+ );
50
+ import_shared.logger.warn(
51
+ `Please set ${import_shared.color.yellow("`output.cleanDistPath`")} config manually.`
52
+ );
53
+ import_shared.logger.warn(`Current root path: ${import_shared.color.dim(rootPath)}`);
54
+ import_shared.logger.warn(`Current dist path: ${import_shared.color.dim(distPath)}`);
55
+ }
56
+ }
57
+ if (cleanDistPath) {
37
58
  await emptyDir(distPath);
38
59
  }
39
60
  };
@@ -43,6 +43,7 @@ const plugins = {
43
43
  splitChunks: () => Promise.resolve().then(() => __toESM(require("./splitChunks"))).then((m) => m.pluginSplitChunks()),
44
44
  inlineChunk: () => Promise.resolve().then(() => __toESM(require("./inlineChunk"))).then((m) => m.pluginInlineChunk()),
45
45
  bundleAnalyzer: () => Promise.resolve().then(() => __toESM(require("./bundleAnalyzer"))).then((m) => m.pluginBundleAnalyzer()),
46
+ rsdoctor: () => Promise.resolve().then(() => __toESM(require("./rsdoctor"))).then((m) => m.pluginRsdoctor()),
46
47
  asset: () => Promise.resolve().then(() => __toESM(require("./asset"))).then((m) => m.pluginAsset()),
47
48
  wasm: () => Promise.resolve().then(() => __toESM(require("./wasm"))).then((m) => m.pluginWasm()),
48
49
  moment: () => Promise.resolve().then(() => __toESM(require("./moment"))).then((m) => m.pluginMoment()),
@@ -35,9 +35,9 @@ var import_shared = require("@rsbuild/shared");
35
35
  const pluginInlineChunk = () => ({
36
36
  name: "rsbuild:inline-chunk",
37
37
  setup(api) {
38
- api.modifyBundlerChain(async (chain, { target, CHAIN_ID, isProd }) => {
38
+ api.modifyBundlerChain(async (chain, { target, CHAIN_ID, isDev }) => {
39
39
  const config = api.getNormalizedConfig();
40
- if ((0, import_shared.isHtmlDisabled)(config, target) || !isProd) {
40
+ if ((0, import_shared.isHtmlDisabled)(config, target) || isDev) {
41
41
  return;
42
42
  }
43
43
  const { InlineChunkHtmlPlugin } = await Promise.resolve().then(() => __toESM(require("../rspack/InlineChunkHtmlPlugin")));
@@ -0,0 +1,2 @@
1
+ import type { RsbuildPlugin } from '../types';
2
+ export declare const pluginRsdoctor: () => RsbuildPlugin;
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
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
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var rsdoctor_exports = {};
30
+ __export(rsdoctor_exports, {
31
+ pluginRsdoctor: () => pluginRsdoctor
32
+ });
33
+ module.exports = __toCommonJS(rsdoctor_exports);
34
+ var import_shared = require("@rsbuild/shared");
35
+ const pluginRsdoctor = () => ({
36
+ name: "rsbuild:rsdoctor",
37
+ setup(api) {
38
+ api.onBeforeCreateCompiler(async ({ bundlerConfigs }) => {
39
+ if (process.env.RSDOCTOR !== "true") {
40
+ return;
41
+ }
42
+ const isRspack = api.context.bundlerType === "rspack";
43
+ const packageName = isRspack ? "@rsdoctor/rspack-plugin" : "@rsdoctor/webpack-plugin";
44
+ let module2;
45
+ try {
46
+ const path = require.resolve(packageName, {
47
+ paths: [api.context.rootPath]
48
+ });
49
+ module2 = await Promise.resolve().then(() => __toESM(require(path)));
50
+ } catch (err) {
51
+ import_shared.logger.warn(
52
+ `\`process.env.RSDOCTOR\` enabled, please install ${import_shared.color.bold(import_shared.color.yellow(packageName))} package.`
53
+ );
54
+ return;
55
+ }
56
+ const pluginName = isRspack ? "RsdoctorRspackPlugin" : "RsdoctorWebpackPlugin";
57
+ if (!module2 || !module2[pluginName]) {
58
+ return;
59
+ }
60
+ let isAutoRegister = false;
61
+ bundlerConfigs.forEach((config) => {
62
+ const registered = config.plugins?.some(
63
+ (plugin) => plugin?.constructor?.name === pluginName
64
+ );
65
+ if (registered) {
66
+ return;
67
+ }
68
+ config.plugins || (config.plugins = []);
69
+ config.plugins.push(new module2[pluginName]());
70
+ isAutoRegister = true;
71
+ });
72
+ if (isAutoRegister) {
73
+ import_shared.logger.info(`${import_shared.color.bold(import_shared.color.yellow(packageName))} enabled.`);
74
+ }
75
+ });
76
+ }
77
+ });
78
+ // Annotate the CommonJS export names for ESM import in node:
79
+ 0 && (module.exports = {
80
+ pluginRsdoctor
81
+ });
@@ -43,7 +43,7 @@ async function createContextByConfig(options, bundlerType, config = {}) {
43
43
  const context = {
44
44
  entry: config.source?.entry || {},
45
45
  targets: config.output?.targets || [],
46
- version: "0.3.7",
46
+ version: "0.3.9",
47
47
  rootPath,
48
48
  distPath,
49
49
  cachePath,
@@ -1,5 +1,6 @@
1
- import { type RspackConfig, type RsbuildTarget } from '@rsbuild/shared';
1
+ import { type RspackConfig, type RsbuildTarget, type ModifyChainUtils } from '@rsbuild/shared';
2
2
  import type { InternalContext } from '../../types';
3
+ export declare function getChainUtils(target: RsbuildTarget): ModifyChainUtils;
3
4
  export declare function generateRspackConfig({ target, context, }: {
4
5
  target: RsbuildTarget;
5
6
  context: InternalContext;
@@ -28,7 +28,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var rspackConfig_exports = {};
30
30
  __export(rspackConfig_exports, {
31
- generateRspackConfig: () => generateRspackConfig
31
+ generateRspackConfig: () => generateRspackConfig,
32
+ getChainUtils: () => getChainUtils
32
33
  });
33
34
  module.exports = __toCommonJS(rspackConfig_exports);
34
35
  var import_shared = require("@rsbuild/shared");
@@ -91,15 +92,16 @@ async function getConfigUtils(config, chainUtils) {
91
92
  }
92
93
  };
93
94
  }
94
- async function getChainUtils(target) {
95
+ function getChainUtils(target) {
95
96
  const nodeEnv = (0, import_shared.getNodeEnv)();
96
97
  return {
97
98
  env: nodeEnv,
98
99
  target,
100
+ isDev: nodeEnv === "development",
99
101
  isProd: nodeEnv === "production",
100
102
  isServer: target === "node",
101
- isServiceWorker: target === "service-worker",
102
103
  isWebWorker: target === "web-worker",
104
+ isServiceWorker: target === "service-worker",
103
105
  getCompiledPath: import_shared2.getCompiledPath,
104
106
  CHAIN_ID: import_shared.CHAIN_ID,
105
107
  HtmlPlugin: (0, import_htmlPluginUtil.getHTMLPlugin)()
@@ -109,7 +111,7 @@ async function generateRspackConfig({
109
111
  target,
110
112
  context
111
113
  }) {
112
- const chainUtils = await getChainUtils(target);
114
+ const chainUtils = getChainUtils(target);
113
115
  const {
114
116
  BannerPlugin,
115
117
  DefinePlugin,
@@ -135,5 +137,6 @@ async function generateRspackConfig({
135
137
  }
136
138
  // Annotate the CommonJS export names for ESM import in node:
137
139
  0 && (module.exports = {
138
- generateRspackConfig
140
+ generateRspackConfig,
141
+ getChainUtils
139
142
  });
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * This file is used to provide/set a global html-plugin singleton
3
3
  */
4
- import HtmlWebpackPlugin from 'html-webpack-plugin';
4
+ import type HtmlWebpackPlugin from 'html-webpack-plugin';
5
5
  /**
6
6
  * This method is used to override the Rsbuild default html-plugin (html-rspack-plugin).
7
7
  */
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
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
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
  var htmlPluginUtil_exports = {};
30
20
  __export(htmlPluginUtil_exports, {
@@ -32,13 +22,17 @@ __export(htmlPluginUtil_exports, {
32
22
  setHTMLPlugin: () => setHTMLPlugin
33
23
  });
34
24
  module.exports = __toCommonJS(htmlPluginUtil_exports);
35
- var import_html_webpack_plugin = __toESM(require("html-webpack-plugin"));
36
25
  let htmlPlugin;
37
26
  const setHTMLPlugin = (plugin) => {
38
- htmlPlugin = plugin;
27
+ if (plugin) {
28
+ htmlPlugin = plugin;
29
+ }
39
30
  };
40
31
  const getHTMLPlugin = () => {
41
- return htmlPlugin || import_html_webpack_plugin.default;
32
+ if (!htmlPlugin) {
33
+ htmlPlugin = require("html-webpack-plugin");
34
+ }
35
+ return htmlPlugin;
42
36
  };
43
37
  // Annotate the CommonJS export names for ESM import in node:
44
38
  0 && (module.exports = {
@@ -9,3 +9,4 @@ export { applyBaseCSSRule, applyCSSModuleRule } from './plugins/css';
9
9
  export type { InternalContext } from '../types';
10
10
  export { setHTMLPlugin, getHTMLPlugin } from './htmlPluginUtil';
11
11
  export { formatStats } from './shared';
12
+ export { getChainUtils } from './core/rspackConfig';
@@ -23,6 +23,7 @@ __export(provider_exports, {
23
23
  createContext: () => import_createContext.createContext,
24
24
  createPublicContext: () => import_createContext.createPublicContext,
25
25
  formatStats: () => import_shared2.formatStats,
26
+ getChainUtils: () => import_rspackConfig.getChainUtils,
26
27
  getHTMLPlugin: () => import_htmlPluginUtil.getHTMLPlugin,
27
28
  getPluginAPI: () => import_initPlugins.getPluginAPI,
28
29
  initHooks: () => import_initHooks.initHooks,
@@ -41,6 +42,7 @@ var import_initPlugins = require("./core/initPlugins");
41
42
  var import_css = require("./plugins/css");
42
43
  var import_htmlPluginUtil = require("./htmlPluginUtil");
43
44
  var import_shared2 = require("./shared");
45
+ var import_rspackConfig = require("./core/rspackConfig");
44
46
  // Annotate the CommonJS export names for ESM import in node:
45
47
  0 && (module.exports = {
46
48
  applyBaseCSSRule,
@@ -48,6 +50,7 @@ var import_shared2 = require("./shared");
48
50
  createContext,
49
51
  createPublicContext,
50
52
  formatStats,
53
+ getChainUtils,
51
54
  getHTMLPlugin,
52
55
  getPluginAPI,
53
56
  initHooks,
@@ -24,7 +24,9 @@ module.exports = __toCommonJS(transition_exports);
24
24
  const pluginTransition = () => ({
25
25
  name: "rsbuild:transition",
26
26
  setup() {
27
+ var _a;
27
28
  process.env.RSPACK_CONFIG_VALIDATE = "loose-silent";
29
+ (_a = process.env).WATCHPACK_WATCHER_LIMIT || (_a.WATCHPACK_WATCHER_LIMIT = "20");
28
30
  }
29
31
  });
30
32
  // Annotate the CommonJS export names for ESM import in node:
@@ -69,6 +69,7 @@ const applyDefaultPlugins = (plugins) => (0, import_shared3.awaitableGetter)([
69
69
  plugins.startUrl(),
70
70
  plugins.inlineChunk(),
71
71
  plugins.bundleAnalyzer(),
72
+ plugins.rsdoctor(),
72
73
  plugins.networkPerformance(),
73
74
  plugins.preloadOrPrefetch(),
74
75
  plugins.performance(),
@@ -32,6 +32,7 @@ __export(getDevMiddlewares_exports, {
32
32
  });
33
33
  module.exports = __toCommonJS(getDevMiddlewares_exports);
34
34
  var import_node_url = __toESM(require("node:url"));
35
+ var import_shared = require("@rsbuild/shared");
35
36
  var import_middlewares = require("./middlewares");
36
37
  var import_node_path = require("node:path");
37
38
  const applySetupMiddlewares = (dev, compileMiddlewareAPI) => {
@@ -137,6 +138,9 @@ const applyDefaultMiddlewares = async ({
137
138
  const getMiddlewares = async (options) => {
138
139
  const middlewares = [];
139
140
  const { compileMiddlewareAPI } = options;
141
+ if ((0, import_shared.isDebug)()) {
142
+ middlewares.push(await (0, import_middlewares.getRequestLoggerMiddleware)());
143
+ }
140
144
  const { before, after } = applySetupMiddlewares(
141
145
  options.dev,
142
146
  compileMiddlewareAPI
@@ -1,5 +1,7 @@
1
1
  import { type HtmlFallback, type RequestHandler as Middleware } from '@rsbuild/shared';
2
+ import type { NextHandleFunction } from '@rsbuild/shared/connect';
2
3
  export declare const faviconFallbackMiddleware: Middleware;
4
+ export declare const getRequestLoggerMiddleware: () => Promise<NextHandleFunction>;
3
5
  export declare const notFoundMiddleware: Middleware;
4
6
  export declare const getHtmlFallbackMiddleware: (params: {
5
7
  distPath: string;
@@ -30,6 +30,7 @@ var middlewares_exports = {};
30
30
  __export(middlewares_exports, {
31
31
  faviconFallbackMiddleware: () => faviconFallbackMiddleware,
32
32
  getHtmlFallbackMiddleware: () => getHtmlFallbackMiddleware,
33
+ getRequestLoggerMiddleware: () => getRequestLoggerMiddleware,
33
34
  notFoundMiddleware: () => notFoundMiddleware
34
35
  });
35
36
  module.exports = __toCommonJS(middlewares_exports);
@@ -45,6 +46,42 @@ const faviconFallbackMiddleware = (req, res, next) => {
45
46
  next();
46
47
  }
47
48
  };
49
+ const getStatusCodeColor = (status) => {
50
+ if (status >= 500) {
51
+ return import_shared.color.red;
52
+ }
53
+ if (status >= 400) {
54
+ return import_shared.color.yellow;
55
+ }
56
+ if (status >= 300) {
57
+ return import_shared.color.cyan;
58
+ }
59
+ if (status >= 200) {
60
+ return import_shared.color.green;
61
+ }
62
+ return (res) => res;
63
+ };
64
+ const getRequestLoggerMiddleware = async () => {
65
+ const { default: onFinished } = await Promise.resolve().then(() => __toESM(require("../../compiled/on-finished")));
66
+ return (req, res, next) => {
67
+ const _startAt = process.hrtime();
68
+ const logRequest = () => {
69
+ const method = req.method;
70
+ const url = req.originalUrl || req.url;
71
+ const status = Number(res.statusCode);
72
+ const statusColor = getStatusCodeColor(status);
73
+ const endAt = process.hrtime();
74
+ const totalTime = (endAt[0] - _startAt[0]) * 1e3 + (endAt[1] - _startAt[1]) * 1e-6;
75
+ (0, import_shared.debug)(
76
+ `${statusColor(status)} ${method} ${import_shared.color.gray(url)} ${import_shared.color.gray(
77
+ `${totalTime.toFixed(3)} ms`
78
+ )}`
79
+ );
80
+ };
81
+ onFinished(res, logRequest);
82
+ next();
83
+ };
84
+ };
48
85
  const notFoundMiddleware = (_req, res, _next) => {
49
86
  res.statusCode = 404;
50
87
  res.end();
@@ -75,8 +112,14 @@ const getHtmlFallbackMiddleware = ({ htmlFallback, distPath, callback }) => {
75
112
  const { devMiddleware } = res.locals.webpack;
76
113
  outputFileSystem = devMiddleware.outputFileSystem;
77
114
  }
78
- const rewrite = (newUrl) => {
79
- (0, import_shared.debug)?.(`Rewriting ${req.method} ${req.url} to ${newUrl}`);
115
+ const rewrite = (newUrl, isFallback = false) => {
116
+ if (isFallback && (0, import_shared.isDebug)()) {
117
+ (0, import_shared.debug)(
118
+ `${req.method} ${import_shared.color.gray(
119
+ `${req.url} ${import_shared.color.yellow("fallback")} to ${newUrl}`
120
+ )}`
121
+ );
122
+ }
80
123
  req.url = newUrl;
81
124
  if (callback) {
82
125
  return callback(req, res, (...args) => {
@@ -103,7 +146,7 @@ const getHtmlFallbackMiddleware = ({ htmlFallback, distPath, callback }) => {
103
146
  }
104
147
  if (htmlFallback === "index") {
105
148
  if (outputFileSystem.existsSync(import_node_path.default.join(distPath, "index.html"))) {
106
- return rewrite("/index.html");
149
+ return rewrite("/index.html", true);
107
150
  }
108
151
  }
109
152
  next();
@@ -113,5 +156,6 @@ const getHtmlFallbackMiddleware = ({ htmlFallback, distPath, callback }) => {
113
156
  0 && (module.exports = {
114
157
  faviconFallbackMiddleware,
115
158
  getHtmlFallbackMiddleware,
159
+ getRequestLoggerMiddleware,
116
160
  notFoundMiddleware
117
161
  });
@@ -58,6 +58,9 @@ class RsbuildProdServer {
58
58
  }
59
59
  async applyDefaultMiddlewares() {
60
60
  const { headers, proxy, historyApiFallback, compress } = this.options.serverConfig;
61
+ if ((0, import_shared.isDebug)()) {
62
+ this.middlewares.use(await (0, import_middlewares.getRequestLoggerMiddleware)());
63
+ }
61
64
  if (compress) {
62
65
  const { default: compression } = await Promise.resolve().then(() => __toESM(require("../../compiled/http-compression")));
63
66
  this.middlewares.use((req, res, next) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/core",
3
- "version": "0.3.7",
3
+ "version": "0.3.9",
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.0",
55
+ "@rspack/core": "0.5.2",
56
56
  "@swc/helpers": "0.5.3",
57
57
  "core-js": "~3.32.2",
58
58
  "html-webpack-plugin": "npm:html-rspack-plugin@5.5.7",
59
59
  "postcss": "^8.4.33",
60
- "@rsbuild/shared": "0.3.7"
60
+ "@rsbuild/shared": "0.3.9"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@types/node": "16.x",