@rsbuild/core 1.2.10 → 1.2.12

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/compiled/chokidar/index.d.ts +61 -23
  2. package/compiled/chokidar/index.js +71 -56
  3. package/compiled/css-loader/index.js +309 -195
  4. package/compiled/html-rspack-plugin/index.js +14 -14
  5. package/compiled/http-proxy-middleware/index.d.ts +1 -1
  6. package/compiled/launch-editor-middleware/index.js +9 -6
  7. package/compiled/mrmime/index.js +4 -0
  8. package/compiled/mrmime/package.json +1 -1
  9. package/compiled/postcss/index.js +194 -194
  10. package/compiled/postcss/package.json +1 -1
  11. package/compiled/postcss-load-config/index.js +11 -11
  12. package/compiled/postcss-loader/index.js +9 -9
  13. package/compiled/rsbuild-dev-middleware/index.js +25 -25
  14. package/compiled/rspack-manifest-plugin/index.js +4 -4
  15. package/compiled/sirv/index.js +8 -4
  16. package/compiled/sirv/package.json +1 -1
  17. package/compiled/style-loader/index.js +10 -10
  18. package/compiled/tinyglobby/index.d.ts +1 -0
  19. package/compiled/tinyglobby/index.js +266 -142
  20. package/compiled/tinyglobby/package.json +1 -1
  21. package/compiled/webpack-bundle-analyzer/index.js +6 -2
  22. package/compiled/ws/index.js +50 -49
  23. package/compiled/ws/package.json +1 -1
  24. package/dist/client/hmr.js +2 -2
  25. package/dist/index.cjs +95 -60
  26. package/dist/index.js +91 -56
  27. package/dist-types/helpers/index.d.ts +3 -3
  28. package/dist-types/index.d.ts +1 -1
  29. package/dist-types/loadEnv.d.ts +16 -4
  30. package/dist-types/logger.d.ts +14 -0
  31. package/dist-types/server/devServer.d.ts +2 -1
  32. package/dist-types/server/socketServer.d.ts +4 -2
  33. package/dist-types/types/config.d.ts +79 -43
  34. package/dist-types/types/rspack.d.ts +1 -1
  35. package/package.json +11 -11
  36. package/compiled/jiti/index.d.ts +0 -1
  37. package/compiled/jiti/index.js +0 -416
  38. package/compiled/jiti/license +0 -21
  39. package/compiled/jiti/package.json +0 -1
package/dist/index.cjs CHANGED
@@ -268,10 +268,6 @@ var __webpack_modules__ = {
268
268
  "use strict";
269
269
  module.exports = import("../compiled/http-proxy-middleware/index.js");
270
270
  },
271
- "../compiled/jiti/index.js": function(module) {
272
- "use strict";
273
- module.exports = import("../compiled/jiti/index.js");
274
- },
275
271
  "../../compiled/launch-editor-middleware/index.js": function(module) {
276
272
  "use strict";
277
273
  module.exports = import("../compiled/launch-editor-middleware/index.js");
@@ -316,6 +312,10 @@ var __webpack_modules__ = {
316
312
  "use strict";
317
313
  module.exports = import("../compiled/ws/index.js");
318
314
  },
315
+ jiti: function(module) {
316
+ "use strict";
317
+ module.exports = import("jiti");
318
+ },
319
319
  "node:http": function(module) {
320
320
  "use strict";
321
321
  module.exports = import("node:http");
@@ -525,7 +525,7 @@ var __webpack_exports__ = {};
525
525
  !keep.some((reg)=>reg.test(toPosixPath(fullPath))) && (entry.isDirectory() ? (await emptyDir(fullPath, keep, !1), keep.length || await external_node_fs_default().promises.rmdir(fullPath)) : await external_node_fs_default().promises.unlink(fullPath));
526
526
  }));
527
527
  } catch (err) {
528
- rslog_index_js_namespaceObject.logger.debug(`Failed to empty dir: ${dir}`), rslog_index_js_namespaceObject.logger.debug(err);
528
+ rslog_index_js_namespaceObject.logger.debug(`failed to empty dir: ${dir}`), rslog_index_js_namespaceObject.logger.debug(err);
529
529
  }
530
530
  }
531
531
  let hintNodePolyfill = (message)=>{
@@ -775,7 +775,7 @@ var __webpack_exports__ = {};
775
775
  }, isTTY = (type = 'stdout')=>('stdin' === type ? process.stdin.isTTY : process.stdout.isTTY) && !process.env.CI;
776
776
  function loadEnv({ cwd = process.cwd(), mode = getNodeEnv(), prefixes = [
777
777
  'PUBLIC_'
778
- ] } = {}) {
778
+ ], processEnv = process.env } = {}) {
779
779
  if ('local' === mode) throw Error("[rsbuild:loadEnv] 'local' cannot be used as a value for env mode, because \".env.local\" represents a temporary local file. Please use another value.");
780
780
  let filePaths = [
781
781
  '.env',
@@ -783,13 +783,14 @@ var __webpack_exports__ = {};
783
783
  `.env.${mode}`,
784
784
  `.env.${mode}.local`
785
785
  ].map((filename)=>(0, external_node_path_namespaceObject.join)(cwd, filename)).filter(isFileSync), parsed = {};
786
- for (let envPath of filePaths)Object.assign(parsed, (0, main.parse)(external_node_fs_default().readFileSync(envPath)));
787
- parsed.NODE_ENV && (process.env.NODE_ENV = parsed.NODE_ENV), (0, lib_main.expand)({
788
- parsed
786
+ for (let envPath of filePaths)Object.assign(parsed, (0, main.parse)(external_node_fs_default().readFileSync(envPath))), rslog_index_js_namespaceObject.logger.debug('loaded env file:', envPath);
787
+ parsed.NODE_ENV && (processEnv.NODE_ENV = parsed.NODE_ENV), (0, lib_main.expand)({
788
+ parsed,
789
+ processEnv
789
790
  });
790
791
  let publicVars = {}, rawPublicVars = {};
791
- for (let key of Object.keys(process.env))if (prefixes.some((prefix)=>key.startsWith(prefix))) {
792
- let val = process.env[key];
792
+ for (let key of Object.keys(processEnv))if (prefixes.some((prefix)=>key.startsWith(prefix))) {
793
+ let val = processEnv[key];
793
794
  publicVars[`import.meta.env.${key}`] = JSON.stringify(val), publicVars[`process.env.${key}`] = JSON.stringify(val), rawPublicVars[key] = val;
794
795
  }
795
796
  let cleaned = !1;
@@ -797,7 +798,7 @@ var __webpack_exports__ = {};
797
798
  parsed,
798
799
  cleanup: ()=>{
799
800
  if (!cleaned) {
800
- for (let key of Object.keys(parsed))'NODE_ENV' !== key && process.env[key] === parsed[key] && delete process.env[key];
801
+ for (let key of Object.keys(parsed))'NODE_ENV' !== key && processEnv[key] === parsed[key] && delete processEnv[key];
801
802
  cleaned = !0;
802
803
  }
803
804
  },
@@ -972,8 +973,8 @@ var __webpack_exports__ = {};
972
973
  }, beforeRestart = async ({ filePath, clear = !0, id })=>{
973
974
  if (clear && clearConsole(), filePath) {
974
975
  let filename = external_node_path_default().basename(filePath);
975
- rslog_index_js_namespaceObject.logger.info(`Restart ${id} because ${index_js_default().yellow(filename)} is changed.\n`);
976
- } else rslog_index_js_namespaceObject.logger.info(`Restarting ${id}...\n`);
976
+ rslog_index_js_namespaceObject.logger.info(`restarting ${id} because ${index_js_default().yellow(filename)} has changed\n`);
977
+ } else rslog_index_js_namespaceObject.logger.info(`restarting ${id}...\n`);
977
978
  for (let cleaner of cleaners)await cleaner();
978
979
  cleaners = [];
979
980
  }, restartDevServer = async ({ filePath, clear = !0 } = {})=>{
@@ -1080,7 +1081,8 @@ var __webpack_exports__ = {};
1080
1081
  compress: !0,
1081
1082
  printUrls: !0,
1082
1083
  strictPort: !1,
1083
- cors: !1
1084
+ cors: !1,
1085
+ middlewareMode: !1
1084
1086
  }), getDefaultSourceConfig = ()=>({
1085
1087
  alias: {},
1086
1088
  define: {},
@@ -1250,7 +1252,7 @@ var __webpack_exports__ = {};
1250
1252
  async function config_loadConfig({ cwd = process.cwd(), path, envMode, meta, loader = 'jiti' } = {}) {
1251
1253
  let configExport;
1252
1254
  let configFilePath = resolveConfigPath(cwd, path);
1253
- if (!configFilePath) return {
1255
+ if (!configFilePath) return rslog_index_js_namespaceObject.logger.debug('no config file found.'), {
1254
1256
  content: {},
1255
1257
  filePath: configFilePath
1256
1258
  };
@@ -1262,16 +1264,17 @@ var __webpack_exports__ = {};
1262
1264
  configExport = exportModule.default ? exportModule.default : exportModule;
1263
1265
  } catch (err) {
1264
1266
  if ('native' === loader) throw rslog_index_js_namespaceObject.logger.error(`Failed to load file with native loader: ${index_js_default().dim(configFilePath)}`), err;
1265
- rslog_index_js_namespaceObject.logger.debug(`Failed to load file with dynamic import: ${index_js_default().dim(configFilePath)}`);
1267
+ rslog_index_js_namespaceObject.logger.debug(`failed to load file with dynamic import: ${index_js_default().dim(configFilePath)}`);
1266
1268
  }
1267
1269
  try {
1268
1270
  if (void 0 === configExport) {
1269
- let { default: jiti } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "../compiled/jiti/index.js"));
1270
- configExport = jiti(constants_filename, {
1271
- esmResolve: !0,
1272
- requireCache: !1,
1271
+ let { createJiti } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "jiti")), jiti = createJiti(constants_filename, {
1272
+ moduleCache: !1,
1273
1273
  interopDefault: !0
1274
- })(configFilePath);
1274
+ });
1275
+ configExport = await jiti.import(configFilePath, {
1276
+ default: !0
1277
+ });
1275
1278
  }
1276
1279
  } catch (err) {
1277
1280
  throw rslog_index_js_namespaceObject.logger.error(`Failed to load file with jiti: ${index_js_default().dim(configFilePath)}`), err;
@@ -1290,7 +1293,7 @@ var __webpack_exports__ = {};
1290
1293
  };
1291
1294
  }
1292
1295
  if (!isObject(configExport)) throw Error(`[rsbuild:loadConfig] The config must be an object or a function that returns an object, get ${index_js_default().yellow(configExport)}`);
1293
- return {
1296
+ return rslog_index_js_namespaceObject.logger.debug('loaded config file:', configFilePath), {
1294
1297
  content: applyMetaInfo(configExport),
1295
1298
  filePath: configFilePath
1296
1299
  };
@@ -1330,13 +1333,13 @@ var __webpack_exports__ = {};
1330
1333
  ...rawEnvironmentConfigs.map(({ name, content })=>{
1331
1334
  if (1 === rawEnvironmentConfigs.length) return {
1332
1335
  path: (0, external_node_path_namespaceObject.join)(outputPath, 'rsbuild.config.mjs'),
1333
- label: 'Rsbuild Config',
1336
+ label: 'Rsbuild config',
1334
1337
  content
1335
1338
  };
1336
1339
  let outputFile = `rsbuild.config.${name}.mjs`;
1337
1340
  return {
1338
1341
  path: (0, external_node_path_namespaceObject.join)(outputPath, outputFile),
1339
- label: `Rsbuild Config (${name})`,
1342
+ label: `Rsbuild config (${name})`,
1340
1343
  content
1341
1344
  };
1342
1345
  }),
@@ -1353,7 +1356,7 @@ var __webpack_exports__ = {};
1353
1356
  recursive: !0
1354
1357
  }), await Promise.all(files.map(async (item)=>external_node_fs_default().promises.writeFile(item.path, `export default ${item.content}`)));
1355
1358
  let fileInfos = files.map((item)=>` - ${index_js_default().bold(index_js_default().yellow(item.label))}: ${index_js_default().underline(item.path)}`).join('\n');
1356
- rslog_index_js_namespaceObject.logger.success(`Inspect config succeed, open following files to view the content: \n\n${fileInfos}\n`);
1359
+ rslog_index_js_namespaceObject.logger.success(`config inspection completed, generated files: \n\n${fileInfos}\n`);
1357
1360
  }
1358
1361
  function stringifyConfig(config, verbose) {
1359
1362
  return (0, rspack_chain_index_js_default().toString)(config, {
@@ -1739,7 +1742,7 @@ var __webpack_exports__ = {};
1739
1742
  async function createContext(options, userConfig, bundlerType) {
1740
1743
  let { cwd } = options, rootPath = userConfig.root ? getAbsolutePath(cwd, userConfig.root) : cwd, rsbuildConfig = await withDefaultConfig(rootPath, userConfig), cachePath = (0, external_node_path_namespaceObject.join)(rootPath, 'node_modules', '.cache'), specifiedEnvironments = options.environment && options.environment.length > 0 ? options.environment : void 0;
1741
1744
  return {
1742
- version: "1.2.10",
1745
+ version: "1.2.12",
1743
1746
  rootPath,
1744
1747
  distPath: '',
1745
1748
  cachePath,
@@ -1970,7 +1973,10 @@ var __webpack_exports__ = {};
1970
1973
  api.modifyBundlerChain((chain, { isProd, environment })=>{
1971
1974
  let { config } = environment, getMergedFilename = (assetType)=>{
1972
1975
  let distDir = config.output.distPath[assetType], filename = getFilename(config, assetType, isProd);
1973
- return external_node_path_default().posix.join(distDir, filename);
1976
+ return 'function' == typeof filename ? (...args)=>{
1977
+ let name = filename(...args);
1978
+ return external_node_path_default().posix.join(distDir, name);
1979
+ } : external_node_path_default().posix.join(distDir, filename);
1974
1980
  }, createAssetRule = (assetType, exts, emit)=>{
1975
1981
  let regExp = function(exts) {
1976
1982
  let matcher = exts.map((ext)=>ext.trim()).map((ext)=>ext.startsWith('.') ? ext.slice(1) : ext).join('|');
@@ -2055,7 +2061,7 @@ var __webpack_exports__ = {};
2055
2061
  try {
2056
2062
  prevBuildDependencies = JSON.parse(rawConfigFile);
2057
2063
  } catch (e) {
2058
- rslog_index_js_namespaceObject.logger.debug('Failed to parse the previous buildDependencies.json', e);
2064
+ rslog_index_js_namespaceObject.logger.debug('failed to parse the previous buildDependencies.json', e);
2059
2065
  }
2060
2066
  if (JSON.stringify(prevBuildDependencies) === JSON.stringify(buildDependencies)) return;
2061
2067
  await external_node_fs_default().promises.rm(cacheDirectory, {
@@ -2240,7 +2246,7 @@ var __webpack_exports__ = {};
2240
2246
  };
2241
2247
  }
2242
2248
  return options;
2243
- }, userPostcssrcCache = new Map(), clonePostCSSConfig = (config)=>({
2249
+ }, clonePostCSSConfig = (config)=>({
2244
2250
  ...config,
2245
2251
  plugins: config.plugins ? [
2246
2252
  ...config.plugins
@@ -2249,18 +2255,18 @@ var __webpack_exports__ = {};
2249
2255
  let { sourceMap } = config.output;
2250
2256
  return 'boolean' == typeof sourceMap ? sourceMap : sourceMap.css;
2251
2257
  };
2252
- async function loadUserPostcssrc(root) {
2253
- let cached = userPostcssrcCache.get(root);
2258
+ async function loadUserPostcssrc(root, postcssrcCache) {
2259
+ let cached = postcssrcCache.get(root);
2254
2260
  if (cached) return clonePostCSSConfig(await cached);
2255
2261
  let { default: postcssrc } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "../../compiled/postcss-load-config/index.js")), promise = postcssrc({}, root).catch((err)=>{
2256
2262
  var _err_message;
2257
2263
  if (null === (_err_message = err.message) || void 0 === _err_message ? void 0 : _err_message.includes('No PostCSS Config found')) return {};
2258
2264
  throw err;
2259
2265
  });
2260
- return userPostcssrcCache.set(root, promise), promise.then((config)=>(userPostcssrcCache.set(root, config), clonePostCSSConfig(config)));
2266
+ return postcssrcCache.set(root, promise), promise.then((config)=>(postcssrcCache.set(root, config), clonePostCSSConfig(config)));
2261
2267
  }
2262
- let isPostcssPluginCreator = (plugin)=>'function' == typeof plugin && !0 === plugin.postcss, getPostcssLoaderOptions = async ({ config, root })=>{
2263
- let extraPlugins = [], userOptions = await loadUserPostcssrc(root);
2268
+ let isPostcssPluginCreator = (plugin)=>'function' == typeof plugin && !0 === plugin.postcss, getPostcssLoaderOptions = async ({ config, root, postcssrcCache })=>{
2269
+ let extraPlugins = [], userOptions = await loadUserPostcssrc(root, postcssrcCache);
2264
2270
  userOptions.plugins ||= [];
2265
2271
  let finalOptions = reduceConfigsWithContext({
2266
2272
  initial: {
@@ -2313,6 +2319,7 @@ var __webpack_exports__ = {};
2313
2319
  }, pluginCss = ()=>({
2314
2320
  name: 'rsbuild:css',
2315
2321
  setup (api) {
2322
+ let postcssrcCache = new Map();
2316
2323
  api.modifyBundlerChain({
2317
2324
  order: 'pre',
2318
2325
  handler: async (chain, { target, isProd, CHAIN_ID, environment })=>{
@@ -2340,7 +2347,8 @@ var __webpack_exports__ = {};
2340
2347
  }
2341
2348
  let postcssLoaderOptions = await getPostcssLoaderOptions({
2342
2349
  config,
2343
- root: api.context.rootPath
2350
+ root: api.context.rootPath,
2351
+ postcssrcCache
2344
2352
  });
2345
2353
  ('function' == typeof postcssLoaderOptions.postcssOptions || (null === (_postcssLoaderOptions_postcssOptions = postcssLoaderOptions.postcssOptions) || void 0 === _postcssLoaderOptions_postcssOptions ? void 0 : null === (_postcssLoaderOptions_postcssOptions_plugins = _postcssLoaderOptions_postcssOptions.plugins) || void 0 === _postcssLoaderOptions_postcssOptions_plugins ? void 0 : _postcssLoaderOptions_postcssOptions_plugins.length)) && (importLoaders++, rule.use(CHAIN_ID.USE.POSTCSS).loader(getCompiledPath('postcss-loader')).options(postcssLoaderOptions));
2346
2354
  }
@@ -3263,7 +3271,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
3263
3271
  host,
3264
3272
  port: originalPort,
3265
3273
  strictPort: config.server.strictPort || !1
3266
- }), https = !!config.server.https, portTip = port !== originalPort ? `Port ${originalPort} is in use, ${index_js_default().yellow(`using port ${port}.`)}` : void 0;
3274
+ }), https = !!config.server.https, portTip = port !== originalPort ? `port ${originalPort} is in use, ${index_js_default().yellow(`using port ${port}.`)}` : void 0;
3267
3275
  return {
3268
3276
  port,
3269
3277
  host,
@@ -3364,9 +3372,9 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
3364
3372
  if (targetBrowser) return await execAsync(`osascript openChrome.applescript "${encodeURI(url)}" "${targetBrowser}"`, {
3365
3373
  cwd: STATIC_PATH
3366
3374
  }), !0;
3367
- rslog_index_js_namespaceObject.logger.debug('Failed to find the target browser.');
3375
+ rslog_index_js_namespaceObject.logger.debug('failed to find the target browser.');
3368
3376
  } catch (err) {
3369
- rslog_index_js_namespaceObject.logger.debug("Failed to open start URL with apple script."), rslog_index_js_namespaceObject.logger.debug(err);
3377
+ rslog_index_js_namespaceObject.logger.debug("failed to open start URL with apple script."), rslog_index_js_namespaceObject.logger.debug(err);
3370
3378
  }
3371
3379
  try {
3372
3380
  let { default: open } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "../../compiled/open/index.js"));
@@ -3651,7 +3659,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
3651
3659
  }({
3652
3660
  href,
3653
3661
  file
3654
- }), 'font' === attributes.as && (attributes.crossorigin = ''), ("script" === attributes.as || 'style' === attributes.as) && crossOriginLoading && !('use-credentials' !== crossOriginLoading && '/' === publicPath) && (attributes.crossorigin = 'anonymous' === crossOriginLoading ? '' : crossOriginLoading)), links.push({
3662
+ }), 'font' === attributes.as && (attributes.crossorigin = ''), ("script" === attributes.as || 'style' === attributes.as) && crossOriginLoading && ('use-credentials' === crossOriginLoading || '/' !== publicPath) && (attributes.crossorigin = 'anonymous' === crossOriginLoading ? '' : crossOriginLoading)), links.push({
3655
3663
  tagName: 'link',
3656
3664
  attributes,
3657
3665
  voidTag: !0,
@@ -3797,7 +3805,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
3797
3805
  }), api.onExit(()=>{
3798
3806
  enableProfileTrace && core_default().experiments.globalTrace.cleanup();
3799
3807
  let profileDir = external_node_path_default().join(api.context.distPath, profileDirName);
3800
- stopProfiler(external_node_path_default().join(profileDir, 'jscpuprofile.json'), profileSession), rslog_index_js_namespaceObject.logger.info(`Saved Rspack profile file to ${profileDir}`);
3808
+ stopProfiler(external_node_path_default().join(profileDir, 'jscpuprofile.json'), profileSession), rslog_index_js_namespaceObject.logger.info(`saved Rspack profile file to ${profileDir}`);
3801
3809
  });
3802
3810
  }
3803
3811
  }), pluginServer = ()=>({
@@ -4621,17 +4629,19 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
4621
4629
  this.wsServer.emit('connection', connection, req);
4622
4630
  });
4623
4631
  }
4632
+ clearHeartbeatTimer() {
4633
+ this.heartbeatTimer && (clearInterval(this.heartbeatTimer), this.heartbeatTimer = null);
4634
+ }
4624
4635
  async prepare() {
4625
4636
  var _this_options_client;
4637
+ this.clearHeartbeatTimer();
4626
4638
  let { default: ws } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "../../compiled/ws/index.js"));
4627
4639
  this.wsServer = new ws.Server({
4628
4640
  noServer: !0,
4629
4641
  path: null === (_this_options_client = this.options.client) || void 0 === _this_options_client ? void 0 : _this_options_client.path
4630
4642
  }), this.wsServer.on('error', (err)=>{
4631
4643
  rslog_index_js_namespaceObject.logger.error(err);
4632
- }), this.timer = setInterval(()=>{
4633
- for (let socket of this.wsServer.clients)socket.isAlive ? (socket.isAlive = !1, socket.ping(()=>{})) : socket.terminate();
4634
- }, 30000), this.wsServer.on('connection', (socket, req)=>{
4644
+ }), this.heartbeatTimer = setTimeout(this.checkSockets, 30000), this.wsServer.on('connection', (socket, req)=>{
4635
4645
  let queryStr = req.url ? req.url.split('?')[1] : '';
4636
4646
  this.onConnect(socket, queryStr ? (0, external_node_querystring_namespaceObject.parse)(queryStr) : {});
4637
4647
  });
@@ -4656,23 +4666,28 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
4656
4666
  compilationId
4657
4667
  }));
4658
4668
  }
4659
- close() {
4669
+ async close() {
4670
+ for (let socket of (this.clearHeartbeatTimer(), this.wsServer.removeAllListeners(), this.wsServer.clients))socket.terminate();
4660
4671
  for (let socket of this.sockets)socket.close();
4661
- this.timer && (clearInterval(this.timer), this.timer = null);
4672
+ return this.stats = {}, this.initialChunks = {}, this.sockets.length = 0, new Promise((resolve, reject)=>{
4673
+ this.wsServer.close((err)=>{
4674
+ err ? reject(err) : resolve();
4675
+ });
4676
+ });
4662
4677
  }
4663
4678
  onConnect(socket, params) {
4664
4679
  socket.isAlive = !0, socket.on('pong', ()=>{
4665
4680
  socket.isAlive = !0;
4666
- }), socket && (this.sockets.push(socket), socket.on('close', ()=>{
4667
- let idx = this.sockets.indexOf(socket);
4668
- idx >= 0 && this.sockets.splice(idx, 1);
4681
+ }), this.sockets.push(socket), socket.on('close', ()=>{
4682
+ let index = this.sockets.indexOf(socket);
4683
+ index >= 0 && this.sockets.splice(index, 1);
4669
4684
  }), (this.options.hmr || this.options.liveReload) && this.singleWrite(socket, {
4670
4685
  type: 'hot',
4671
4686
  compilationId: params.compilationId
4672
4687
  }), this.stats && this.sendStats({
4673
4688
  force: !0,
4674
4689
  compilationId: params.compilationId
4675
- }));
4690
+ });
4676
4691
  }
4677
4692
  getStats(name) {
4678
4693
  let curStats = this.stats[name];
@@ -4877,7 +4892,10 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
4877
4892
  1 === connection.readyState && connection.send(message);
4878
4893
  }
4879
4894
  constructor(options){
4880
- socketServer_define_property(this, "wsServer", void 0), socketServer_define_property(this, "sockets", []), socketServer_define_property(this, "options", void 0), socketServer_define_property(this, "stats", void 0), socketServer_define_property(this, "initialChunks", void 0), socketServer_define_property(this, "timer", null), this.options = options, this.stats = {}, this.initialChunks = {};
4895
+ socketServer_define_property(this, "wsServer", void 0), socketServer_define_property(this, "sockets", []), socketServer_define_property(this, "options", void 0), socketServer_define_property(this, "stats", void 0), socketServer_define_property(this, "initialChunks", void 0), socketServer_define_property(this, "heartbeatTimer", null), socketServer_define_property(this, "checkSockets", ()=>{
4896
+ for (let socket of this.wsServer.clients)socket.isAlive ? (socket.isAlive = !1, socket.ping(()=>{})) : socket.terminate();
4897
+ null !== this.heartbeatTimer && (this.heartbeatTimer = setTimeout(this.checkSockets, 30000));
4898
+ }), this.options = options, this.stats = {}, this.initialChunks = {};
4881
4899
  }
4882
4900
  }
4883
4901
  function compilerDevMiddleware_define_property(obj, key, value) {
@@ -4910,7 +4928,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
4910
4928
  this.socketServer.upgrade(req, sock, head);
4911
4929
  }
4912
4930
  async close() {
4913
- this.socketServer.close(), this.middleware && await new Promise((resolve)=>{
4931
+ await this.socketServer.close(), this.middleware && await new Promise((resolve)=>{
4914
4932
  this.middleware.close(()=>{
4915
4933
  resolve();
4916
4934
  });
@@ -5605,7 +5623,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
5605
5623
  environment
5606
5624
  }))
5607
5625
  }
5608
- ])), { default: connect } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "../../compiled/connect/index.js")), middlewares = connect(), httpServer = await createHttpServer({
5626
+ ])), { default: connect } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "../../compiled/connect/index.js")), middlewares = connect(), httpServer = config.server.middlewareMode ? null : await createHttpServer({
5609
5627
  serverConfig: config.server,
5610
5628
  middlewares
5611
5629
  }), devServerAPI = {
@@ -5614,6 +5632,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
5614
5632
  environments: environmentAPI,
5615
5633
  httpServer,
5616
5634
  listen: async ()=>{
5635
+ if (!httpServer) throw Error('[rsbuild:server] Can not listen dev server as `server.middlewareMode` is enabled.');
5617
5636
  let serverTerminator = getServerTerminator(httpServer);
5618
5637
  return rslog_index_js_namespaceObject.logger.debug('listen dev server'), options.context.hooks.onCloseDevServer.tap(serverTerminator), new Promise((resolve)=>{
5619
5638
  httpServer.listen({
@@ -5669,6 +5688,12 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
5669
5688
  })).middlewares))Array.isArray(item) ? middlewares.use(...item) : middlewares.use(item);
5670
5689
  return rslog_index_js_namespaceObject.logger.debug('create dev server done'), devServerAPI;
5671
5690
  }
5691
+ function cutPath(filePath, root) {
5692
+ let prefix = root.endsWith(external_node_path_namespaceObject.sep) ? root : root + external_node_path_namespaceObject.sep;
5693
+ if (filePath.startsWith(prefix)) return filePath.slice(prefix.length);
5694
+ let parts = filePath.split(external_node_path_namespaceObject.sep).filter(Boolean);
5695
+ return parts.length > 3 ? parts.slice(-3).join(external_node_path_namespaceObject.sep) : parts.join(external_node_path_namespaceObject.sep);
5696
+ }
5672
5697
  async function createCompiler_createCompiler(options) {
5673
5698
  rslog_index_js_namespaceObject.logger.debug('create compiler');
5674
5699
  let { context } = options, { rspackConfigs } = await initConfigs(options);
@@ -5677,10 +5702,20 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
5677
5702
  environments: context.environments
5678
5703
  }), !await isSatisfyRspackVersion(core_namespaceObject.rspack.rspackVersion)) throw Error(`[rsbuild] The current Rspack version does not meet the requirements, the minimum supported version of Rspack is ${index_js_default().green(rspackMinVersion)}`);
5679
5704
  let compiler = 1 === rspackConfigs.length ? (0, core_namespaceObject.rspack)(rspackConfigs[0]) : (0, core_namespaceObject.rspack)(rspackConfigs), isVersionLogged = !1, isCompiling = !1, logRspackVersion = ()=>{
5680
- isVersionLogged || (rslog_index_js_namespaceObject.logger.debug(`Use Rspack v${core_namespaceObject.rspack.rspackVersion}`), isVersionLogged = !0);
5705
+ isVersionLogged || (rslog_index_js_namespaceObject.logger.debug(`use Rspack v${core_namespaceObject.rspack.rspackVersion}`), isVersionLogged = !0);
5681
5706
  };
5682
- compiler.hooks.watchRun.tap('rsbuild:compiling', ()=>{
5683
- logRspackVersion(), isCompiling || rslog_index_js_namespaceObject.logger.start('Building...'), isCompiling = !0;
5707
+ compiler.hooks.watchRun.tap('rsbuild:compiling', (compiler)=>{
5708
+ if (logRspackVersion(), !isCompiling) {
5709
+ let changedFiles = compiler.modifiedFiles ? Array.from(compiler.modifiedFiles) : [], removedFiles = compiler.removedFiles ? Array.from(compiler.removedFiles) : [];
5710
+ if (changedFiles.length) {
5711
+ let fileInfo = index_js_default().dim(changedFiles.map((file)=>cutPath(file, context.rootPath)).join(', '));
5712
+ rslog_index_js_namespaceObject.logger.start(`building ${fileInfo}`);
5713
+ } else if (removedFiles.length) {
5714
+ let fileInfo = removedFiles.map((file)=>cutPath(file, context.rootPath)).join(', ');
5715
+ rslog_index_js_namespaceObject.logger.start(`building ${index_js_default().dim(`removed ${fileInfo}`)}`);
5716
+ } else rslog_index_js_namespaceObject.logger.start('build started...');
5717
+ }
5718
+ isCompiling = !0;
5684
5719
  }), 'build' === context.command && compiler.hooks.run.tap('rsbuild:run', logRspackVersion);
5685
5720
  let done = (stats)=>{
5686
5721
  let statsOptions = getStatsOptions(compiler), statsJson = stats.toJson({
@@ -5692,7 +5727,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
5692
5727
  }), printTime = (c, index)=>{
5693
5728
  if (c.time) {
5694
5729
  let time = prettyTime(c.time / 1000), { name } = rspackConfigs[index], suffix = name ? index_js_default().gray(` (${name})`) : '';
5695
- rslog_index_js_namespaceObject.logger.ready(`Built in ${time}${suffix}`);
5730
+ rslog_index_js_namespaceObject.logger.ready(`built in ${time}${suffix}`);
5696
5731
  }
5697
5732
  }, hasErrors = stats.hasErrors();
5698
5733
  if (!hasErrors) {
@@ -6688,12 +6723,12 @@ ${section.body}` : section.body).join("\n\n"));
6688
6723
  }
6689
6724
  }(), process.title = 'rsbuild-node';
6690
6725
  let { npm_execpath } = process.env;
6691
- (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) && console.log(), rslog_index_js_namespaceObject.logger.greet(` Rsbuild v1.2.10\n`);
6726
+ (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) && console.log(), rslog_index_js_namespaceObject.logger.greet(` Rsbuild v1.2.12\n`);
6692
6727
  }();
6693
6728
  try {
6694
6729
  !function() {
6695
6730
  let cli = dist('rsbuild');
6696
- cli.help(), cli.version("1.2.10"), applyCommonOptions(cli);
6731
+ cli.help(), cli.version("1.2.12"), applyCommonOptions(cli);
6697
6732
  let devCommand = cli.command('dev', 'starting the dev server'), buildCommand = cli.command('build', 'build the app for production'), previewCommand = cli.command('preview', 'preview the production build locally'), inspectCommand = cli.command('inspect', 'inspect the Rspack and Rsbuild configs');
6698
6733
  applyServerOptions(devCommand), applyServerOptions(previewCommand), devCommand.action(async (options)=>{
6699
6734
  try {
@@ -6744,7 +6779,7 @@ ${section.body}` : section.body).join("\n\n"));
6744
6779
  rslog_index_js_namespaceObject.logger.error('Failed to start Rsbuild CLI.'), rslog_index_js_namespaceObject.logger.error(err);
6745
6780
  }
6746
6781
  }
6747
- let src_rslib_entry_version = "1.2.10";
6782
+ let src_rslib_entry_version = "1.2.12";
6748
6783
  })();
6749
6784
  var __webpack_export_target__ = exports;
6750
6785
  for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];