@rsbuild/core 2.0.7 → 2.0.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.
@@ -1,11 +1,11 @@
1
- /*! LICENSE: 753.js.LICENSE.txt */
1
+ /*! LICENSE: 756.js.LICENSE.txt */
2
2
  let flagForceColor, runtimeProcessArgs, runtimeInfo, swcHelpersPath, pluginHelper_htmlPlugin;
3
3
  import { rspack as core_rspack } from "@rspack/core";
4
4
  import node_util, { stripVTControlCharacters } from "node:util";
5
5
  import node_process from "node:process";
6
6
  import node_os, { constants as external_node_os_constants } from "node:os";
7
7
  import node_tty from "node:tty";
8
- import node_path, { dirname as external_node_path_dirname, isAbsolute as external_node_path_isAbsolute, join, posix, relative, sep, win32 } from "node:path";
8
+ import node_path, { dirname as external_node_path_dirname, isAbsolute as external_node_path_isAbsolute, join, posix, relative, resolve as external_node_path_resolve, sep, win32 } from "node:path";
9
9
  import { builtinModules, createRequire, createRequire as __rspack_createRequire } from "node:module";
10
10
  import node_fs, { existsSync } from "node:fs";
11
11
  import { URL as external_node_url_URL, pathToFileURL, fileURLToPath as __rspack_fileURLToPath } from "node:url";
@@ -385,8 +385,8 @@ __webpack_require__.add({
385
385
  return (asyncHooks.AsyncResource && (res = new asyncHooks.AsyncResource(fn.name || 'bound-anonymous-fn')), res && res.runInAsyncScope) ? res.runInAsyncScope.bind(res, fn, null) : fn;
386
386
  }
387
387
  },
388
- "../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.14/node_modules/postcss-load-config/src/index.js" (module, __unused_rspack_exports, __webpack_require__) {
389
- let yaml, { resolve } = __webpack_require__("node:path?435f"), config = __webpack_require__("../../node_modules/.pnpm/lilconfig@3.1.3/node_modules/lilconfig/src/index.js"), loadOptions = __webpack_require__("../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.14/node_modules/postcss-load-config/src/options.js"), loadPlugins = __webpack_require__("../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.14/node_modules/postcss-load-config/src/plugins.js"), req = __webpack_require__("../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.14/node_modules/postcss-load-config/src/req.js");
388
+ "../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.15/node_modules/postcss-load-config/src/index.js" (module, __unused_rspack_exports, __webpack_require__) {
389
+ let yaml, { resolve } = __webpack_require__("node:path?435f"), config = __webpack_require__("../../node_modules/.pnpm/lilconfig@3.1.3/node_modules/lilconfig/src/index.js"), loadOptions = __webpack_require__("../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.15/node_modules/postcss-load-config/src/options.js"), loadPlugins = __webpack_require__("../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.15/node_modules/postcss-load-config/src/plugins.js"), req = __webpack_require__("../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.15/node_modules/postcss-load-config/src/req.js");
390
390
  async function processResult(ctx, result) {
391
391
  let obj, file = result.filepath || '', projectConfig = ((obj = result.config) && obj.__esModule ? obj : {
392
392
  default: obj
@@ -459,8 +459,8 @@ __webpack_require__.add({
459
459
  });
460
460
  };
461
461
  },
462
- "../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.14/node_modules/postcss-load-config/src/options.js" (module, __unused_rspack_exports, __webpack_require__) {
463
- let req = __webpack_require__("../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.14/node_modules/postcss-load-config/src/req.js");
462
+ "../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.15/node_modules/postcss-load-config/src/options.js" (module, __unused_rspack_exports, __webpack_require__) {
463
+ let req = __webpack_require__("../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.15/node_modules/postcss-load-config/src/req.js");
464
464
  module.exports = async function options(config, file) {
465
465
  if (config.parser && 'string' == typeof config.parser) try {
466
466
  config.parser = await req(config.parser, file);
@@ -480,8 +480,8 @@ __webpack_require__.add({
480
480
  return config;
481
481
  };
482
482
  },
483
- "../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.14/node_modules/postcss-load-config/src/plugins.js" (module, __unused_rspack_exports, __webpack_require__) {
484
- let req = __webpack_require__("../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.14/node_modules/postcss-load-config/src/req.js");
483
+ "../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.15/node_modules/postcss-load-config/src/plugins.js" (module, __unused_rspack_exports, __webpack_require__) {
484
+ let req = __webpack_require__("../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.15/node_modules/postcss-load-config/src/req.js");
485
485
  async function load(plugin, options, file) {
486
486
  try {
487
487
  if (null == options || 0 === Object.keys(options).length) return await req(plugin, file);
@@ -497,7 +497,7 @@ __webpack_require__.add({
497
497
  }), list;
498
498
  };
499
499
  },
500
- "../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.14/node_modules/postcss-load-config/src/req.js" (module, __unused_rspack_exports, __webpack_require__) {
500
+ "../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.15/node_modules/postcss-load-config/src/req.js" (module, __unused_rspack_exports, __webpack_require__) {
501
501
  let tsx, jiti;
502
502
  var __filename = __rspack_fileURLToPath(import.meta.url);
503
503
  let { createRequire } = __webpack_require__("node:module?1bcb"), { pathToFileURL } = __webpack_require__("node:url?b4ec"), TS_EXT_RE = /\.[mc]?ts$/, importError = [];
@@ -602,6 +602,9 @@ __webpack_require__.add({
602
602
  },
603
603
  events (module) {
604
604
  module.exports = __rspack_createRequire_require("node:events");
605
+ },
606
+ "supports-color" (module) {
607
+ module.exports = __rspack_createRequire_require("supports-color");
605
608
  }
606
609
  }), function checkNodeVersion() {
607
610
  let { versions } = process;
@@ -3482,7 +3485,7 @@ function createPublicContext(context) {
3482
3485
  async function createContext(options, userConfig, logger) {
3483
3486
  let { cwd } = options, rootPath = userConfig.root ? ensureAbsolutePath(cwd, userConfig.root) : cwd, rsbuildConfig = await withDefaultConfig(rootPath, userConfig), cachePath = join(rootPath, 'node_modules', '.cache'), specifiedEnvironments = options.environment && options.environment.length > 0 ? options.environment : void 0;
3484
3487
  return {
3485
- version: "2.0.7",
3488
+ version: "2.0.8",
3486
3489
  rootPath,
3487
3490
  distPath: '',
3488
3491
  cachePath,
@@ -3597,28 +3600,28 @@ async function inspectConfig_inspectConfig({ context, pluginManager, bundlerConf
3597
3600
  };
3598
3601
  }
3599
3602
  let dist_isPlainObject = (obj)=>null !== obj && 'object' == typeof obj && '[object Object]' === Object.prototype.toString.call(obj);
3600
- function reduceConfigs({ initial, config, mergeFn = Object.assign }) {
3601
- return null == config ? initial : dist_isPlainObject(config) ? dist_isPlainObject(initial) ? mergeFn(initial, config) : config : 'function' == typeof config ? config(initial) ?? initial : Array.isArray(config) ? config.reduce((initial, config)=>reduceConfigs({
3602
- initial,
3603
- config,
3604
- mergeFn
3605
- }), initial) : config ?? initial;
3606
- }
3607
- function reduceConfigsWithContext({ initial, config, ctx, mergeFn = Object.assign }) {
3608
- return null == config ? initial : dist_isPlainObject(config) ? dist_isPlainObject(initial) ? mergeFn(initial, config) : config : 'function' == typeof config ? config(initial, ctx) ?? initial : Array.isArray(config) ? config.reduce((initial, config)=>reduceConfigsWithContext({
3609
- initial,
3610
- config,
3611
- ctx,
3603
+ async function reduceConfigs({ initial, config, mergeFn = Object.assign }) {
3604
+ if (null == config) return initial;
3605
+ if (dist_isPlainObject(config)) return dist_isPlainObject(initial) ? mergeFn(initial, config) : config;
3606
+ if ('function' == typeof config) return await config(initial) ?? initial;
3607
+ if (Array.isArray(config)) {
3608
+ let result = initial;
3609
+ for (let item of config)result = await reduceConfigs({
3610
+ initial: result,
3611
+ config: item,
3612
3612
  mergeFn
3613
- }), initial) : config ?? initial;
3613
+ });
3614
+ return result;
3615
+ }
3616
+ return config ?? initial;
3614
3617
  }
3615
- async function reduceConfigsAsyncWithContext({ initial, config, ctx, mergeFn = Object.assign }) {
3618
+ async function reduceConfigsWithContext({ initial, config, ctx, mergeFn = Object.assign }) {
3616
3619
  if (null == config) return initial;
3617
3620
  if (dist_isPlainObject(config)) return dist_isPlainObject(initial) ? mergeFn(initial, config) : config;
3618
3621
  if ('function' == typeof config) return await config(initial, ctx) ?? initial;
3619
3622
  if (Array.isArray(config)) {
3620
3623
  let result = initial;
3621
- for (let item of config)result = await reduceConfigsAsyncWithContext({
3624
+ for (let item of config)result = await reduceConfigsWithContext({
3622
3625
  initial: result,
3623
3626
  config: item,
3624
3627
  ctx,
@@ -3628,16 +3631,24 @@ async function reduceConfigsAsyncWithContext({ initial, config, ctx, mergeFn = O
3628
3631
  }
3629
3632
  return config ?? initial;
3630
3633
  }
3631
- function reduceConfigsMergeContext({ initial, config, ctx, mergeFn = Object.assign }) {
3632
- return null == config ? initial : dist_isPlainObject(config) ? dist_isPlainObject(initial) ? mergeFn(initial, config) : config : 'function' == typeof config ? config({
3634
+ async function reduceConfigsWithMergedContext({ initial, config, ctx, mergeFn = Object.assign }) {
3635
+ if (null == config) return initial;
3636
+ if (dist_isPlainObject(config)) return dist_isPlainObject(initial) ? mergeFn(initial, config) : config;
3637
+ if ('function' == typeof config) return await config({
3633
3638
  value: initial,
3634
3639
  ...ctx
3635
- }) ?? initial : Array.isArray(config) ? config.reduce((initial, config)=>reduceConfigsMergeContext({
3636
- initial,
3637
- config,
3640
+ }) ?? initial;
3641
+ if (Array.isArray(config)) {
3642
+ let result = initial;
3643
+ for (let item of config)result = await reduceConfigsWithMergedContext({
3644
+ initial: result,
3645
+ config: item,
3638
3646
  ctx,
3639
3647
  mergeFn
3640
- }), initial) : config ?? initial;
3648
+ });
3649
+ return result;
3650
+ }
3651
+ return config ?? initial;
3641
3652
  }
3642
3653
  function mergeTo(a, b, customizer) {
3643
3654
  let ret = {};
@@ -3822,7 +3833,7 @@ async function modifyRspackConfig(context, rspackConfig, chainUtils) {
3822
3833
  }
3823
3834
  }), utils.environment.config.tools?.rspack) {
3824
3835
  let toolsRspackConfig = utils.environment.config.tools.rspack;
3825
- currentConfig = await reduceConfigsAsyncWithContext({
3836
+ currentConfig = await reduceConfigsWithContext({
3826
3837
  initial: currentConfig,
3827
3838
  config: toolsRspackConfig,
3828
3839
  ctx: utils,
@@ -4465,9 +4476,9 @@ function parseMinifyOptions(config) {
4465
4476
  cssOptions: minify.cssOptions
4466
4477
  };
4467
4478
  }
4468
- let postcss_load_config_src = __webpack_require__("../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.14/node_modules/postcss-load-config/src/index.js");
4479
+ let postcss_load_config_src = __webpack_require__("../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.15/node_modules/postcss-load-config/src/index.js");
4469
4480
  var postcss_load_config_src_default = __webpack_require__.n(postcss_load_config_src);
4470
- function getLightningCSSLoaderOptions(config, targets, minify) {
4481
+ async function getLightningCSSLoaderOptions(config, targets, minify) {
4471
4482
  let userOptions = 'object' == typeof config.tools.lightningcssLoader ? config.tools.lightningcssLoader : {}, initialOptions = {
4472
4483
  targets,
4473
4484
  errorRecovery: !0
@@ -4498,12 +4509,12 @@ async function loadUserPostcssrc(root, postcssrcCache) {
4498
4509
  let getPostcssLoaderOptions = async ({ config, root, postcssrcCache })=>{
4499
4510
  let extraPlugins = [], userOptions = await loadUserPostcssrc(root, postcssrcCache);
4500
4511
  userOptions.plugins ||= [];
4501
- let finalOptions = reduceConfigsWithContext({
4502
- initial: {
4503
- implementation: join(COMPILED_PATH, 'postcss', 'index.js'),
4504
- postcssOptions: userOptions,
4505
- sourceMap: getCSSSourceMap(config)
4506
- },
4512
+ let defaultOptions = {
4513
+ implementation: join(COMPILED_PATH, 'postcss', 'index.js'),
4514
+ postcssOptions: userOptions,
4515
+ sourceMap: getCSSSourceMap(config)
4516
+ }, finalOptions = await reduceConfigsWithContext({
4517
+ initial: defaultOptions,
4507
4518
  config: config.tools.postcss,
4508
4519
  ctx: {
4509
4520
  addPlugins (plugins, options = {}) {
@@ -4533,6 +4544,36 @@ let getPostcssLoaderOptions = async ({ config, root, postcssrcCache })=>{
4533
4544
  };
4534
4545
  }
4535
4546
  return finalOptions.postcssOptions = updatePostcssOptions(postcssOptions), finalOptions;
4547
+ }, getCSSLoaderOptions = async ({ config, localIdentName, emitCss })=>{
4548
+ let { cssModules } = config.output, defaultOptions = {
4549
+ modules: {
4550
+ ...cssModules,
4551
+ localIdentName
4552
+ },
4553
+ sourceMap: getCSSSourceMap(config)
4554
+ };
4555
+ return ((options, exportOnlyLocals)=>{
4556
+ if (options.modules && exportOnlyLocals) {
4557
+ let { modules } = options;
4558
+ return modules = !0 === modules ? {
4559
+ exportOnlyLocals: !0
4560
+ } : 'string' == typeof modules ? {
4561
+ mode: modules,
4562
+ exportOnlyLocals: !0
4563
+ } : {
4564
+ ...modules,
4565
+ exportOnlyLocals: !0
4566
+ }, {
4567
+ ...options,
4568
+ modules
4569
+ };
4570
+ }
4571
+ return options;
4572
+ })(await reduceConfigs({
4573
+ initial: defaultOptions,
4574
+ config: config.tools.cssLoader,
4575
+ mergeFn: cjs_0_default()
4576
+ }), !emitCss);
4536
4577
  };
4537
4578
  function checkProcessEnvSecurity(define, logger) {
4538
4579
  let value = define['process.env'];
@@ -4546,8 +4587,7 @@ function checkProcessEnvSecurity(define, logger) {
4546
4587
  check(JSON.parse(value));
4547
4588
  } catch {}
4548
4589
  }
4549
- let readPackageJson = async (rootPath)=>{
4550
- let pkgJsonPath = join(rootPath, 'package.json');
4590
+ let readPackageJsonByPath = async (pkgJsonPath)=>{
4551
4591
  if (await isFileExists(pkgJsonPath)) try {
4552
4592
  return JSON.parse(await readFile(pkgJsonPath, 'utf8'));
4553
4593
  } catch {
@@ -4570,29 +4610,42 @@ let readPackageJson = async (rootPath)=>{
4570
4610
  ...!0 === autoExternal ? {} : autoExternal
4571
4611
  };
4572
4612
  return dependencyTypes.some((type)=>externalOptions[type]) ? externalOptions : void 0;
4613
+ }, readPackageJsonList = async (paths, cache)=>{
4614
+ var packageJsonList = (await Promise.all(paths.map(async (path)=>(cache.has(path) || cache.set(path, await readPackageJsonByPath(path)), cache.get(path))))).filter((pkgJson)=>!!pkgJson);
4615
+ return packageJsonList.length ? dependencyTypes.reduce((merged, type)=>{
4616
+ for (let pkgJson of packageJsonList){
4617
+ let deps = pkgJson[type];
4618
+ isPlainObject(deps) && (merged[type] = {
4619
+ ...merged[type],
4620
+ ...deps
4621
+ });
4622
+ }
4623
+ return merged;
4624
+ }, {}) : void 0;
4573
4625
  };
4574
4626
  function pluginExternals() {
4575
4627
  return {
4576
4628
  name: 'rsbuild:externals',
4577
4629
  setup (api) {
4578
- let pkgJson, hasReadPackageJson = !1, hasWarnedReadPackageJsonFailed = !1;
4630
+ let packageJsonCache = new Map(), hasWarnedReadPackageJsonFailed = !1;
4579
4631
  api.modifyBundlerChain(async (chain, { environment })=>{
4580
- let { autoExternal, externals } = environment.config.output, externalOptions = resolveAutoExternalOptions(autoExternal);
4581
- externalOptions && !hasReadPackageJson && (pkgJson = await readPackageJson(api.context.rootPath), hasReadPackageJson = !0), !externalOptions || pkgJson || hasWarnedReadPackageJsonFailed || (api.logger.warn('The `output.autoExternal` configuration will not be applied because reading package.json failed.'), hasWarnedReadPackageJsonFailed = !0);
4632
+ let pkgJson, { autoExternal, externals } = environment.config.output, externalOptions = resolveAutoExternalOptions(autoExternal);
4633
+ if (externalOptions) {
4634
+ let rootPath, packageJsonPaths = (rootPath = api.context.rootPath, helpers_castArray(externalOptions.packageJson ?? 'package.json').map((path)=>external_node_path_resolve(rootPath, path)));
4635
+ pkgJson = await readPackageJsonList(packageJsonPaths, packageJsonCache);
4636
+ }
4637
+ !externalOptions || pkgJson || hasWarnedReadPackageJsonFailed || (api.logger.warn('The `output.autoExternal` configuration will not be applied because reading package.json failed.'), hasWarnedReadPackageJsonFailed = !0);
4582
4638
  let autoExternalRules = ((options)=>{
4583
4639
  let { autoExternal, pkgJson, userExternals } = options, externalOptions = resolveAutoExternalOptions(autoExternal);
4584
4640
  if (!externalOptions || !pkgJson) return;
4585
- let userExternalKeys = isPlainObject(userExternals) ? Object.keys(userExternals) : [], uniqueExternals = Array.from(new Set(dependencyTypes.reduce((prev, type)=>{
4641
+ let userExternalKeys = isPlainObject(userExternals) ? Object.keys(userExternals) : [], excludeConditions = externalOptions.exclude ? helpers_castArray(externalOptions.exclude) : void 0, uniqueExternals = Array.from(new Set(dependencyTypes.reduce((prev, type)=>{
4586
4642
  if (externalOptions[type]) {
4587
4643
  let deps = pkgJson[type];
4588
4644
  return isPlainObject(deps) ? prev.concat(Object.keys(deps)) : prev;
4589
4645
  }
4590
4646
  return prev;
4591
- }, []).filter((name)=>!userExternalKeys.includes(name))));
4592
- return uniqueExternals.length ? [
4593
- ...uniqueExternals.map((dep)=>RegExp(`^${dep.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&')}($|\/|\\\\)`)),
4594
- ...uniqueExternals
4595
- ] : void 0;
4647
+ }, []).filter((name)=>!userExternalKeys.includes(name) && (!excludeConditions || !excludeConditions.some((condition)=>'string' == typeof condition ? condition === name : condition instanceof RegExp && (condition.global || condition.sticky ? new RegExp(condition) : condition).test(name))))));
4648
+ if (uniqueExternals.length) return uniqueExternals.map((dep)=>RegExp(`^${dep.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&')}(?:$|[/\\\\])`));
4596
4649
  })({
4597
4650
  autoExternal,
4598
4651
  pkgJson,
@@ -4997,7 +5050,7 @@ class RsbuildHtmlPlugin {
4997
5050
  }
4998
5051
  }
4999
5052
  function getTitle(entryName, config) {
5000
- return reduceConfigsMergeContext({
5053
+ return reduceConfigsWithMergedContext({
5001
5054
  initial: '',
5002
5055
  config: config.html.title,
5003
5056
  ctx: {
@@ -5006,7 +5059,7 @@ function getTitle(entryName, config) {
5006
5059
  });
5007
5060
  }
5008
5061
  function getInject(entryName, config) {
5009
- return reduceConfigsMergeContext({
5062
+ return reduceConfigsWithMergedContext({
5010
5063
  initial: 'head',
5011
5064
  config: config.html.inject,
5012
5065
  ctx: {
@@ -5016,7 +5069,7 @@ function getInject(entryName, config) {
5016
5069
  }
5017
5070
  let existTemplatePath = new Set();
5018
5071
  async function getTemplate(entryName, config, rootPath) {
5019
- let templatePath = reduceConfigsMergeContext({
5072
+ let templatePath = await reduceConfigsWithMergedContext({
5020
5073
  initial: '',
5021
5074
  config: config.html.template,
5022
5075
  ctx: {
@@ -5042,7 +5095,7 @@ async function getTemplate(entryName, config, rootPath) {
5042
5095
  };
5043
5096
  }
5044
5097
  function getFavicon(entryName, config) {
5045
- return reduceConfigsMergeContext({
5098
+ return reduceConfigsWithMergedContext({
5046
5099
  initial: '',
5047
5100
  config: config.html.favicon,
5048
5101
  ctx: {
@@ -5050,8 +5103,8 @@ function getFavicon(entryName, config) {
5050
5103
  }
5051
5104
  });
5052
5105
  }
5053
- function getMetaTags(entryName, config, templateContent) {
5054
- let metaTags = reduceConfigsMergeContext({
5106
+ async function getMetaTags(entryName, config, templateContent) {
5107
+ let metaTags = await reduceConfigsWithMergedContext({
5055
5108
  initial: {},
5056
5109
  config: config.html.meta,
5057
5110
  ctx: {
@@ -5061,7 +5114,7 @@ function getMetaTags(entryName, config, templateContent) {
5061
5114
  return templateContent && metaTags.charset && /<meta[^>]+charset=["'][^>]*>/i.test(templateContent) && delete metaTags.charset, metaTags;
5062
5115
  }
5063
5116
  function getTemplateParameters(entryName, config, assetPrefix) {
5064
- return (compilation, assets, assetTags, pluginOptions)=>{
5117
+ return async (compilation, assets, assetTags, pluginOptions)=>{
5065
5118
  let { mountId, templateParameters } = config.html, rspackConfig = compilation.options;
5066
5119
  return reduceConfigsWithContext({
5067
5120
  initial: {
@@ -5120,10 +5173,9 @@ let normalizeUrl = (url)=>url.replace(/([^:]\/)\/+/g, '$1'), formatPrefix = (inp
5120
5173
  if (prefix?.startsWith('./') && (prefix = prefix.replace('./', '')), !prefix) return '/';
5121
5174
  let hasLeadingSlash = prefix.startsWith('/'), hasTailSlash = prefix.endsWith('/');
5122
5175
  return `${hasLeadingSlash ? '' : '/'}${prefix}${hasTailSlash ? '' : '/'}`;
5123
- }, joinUrlSegments = (s1, s2)=>s1 && s2 ? addTrailingSlash(s1) + s2.replace(/^\/+/, '') : s1 || s2 || '', stripBase = (path, base)=>{
5124
- if (path === base) return '/';
5125
- let trailingSlashBase = addTrailingSlash(base);
5126
- return path.startsWith(trailingSlashBase) ? path.slice(trailingSlashBase.length - 1) : path;
5176
+ }, joinUrlPath = (basePath, pathname)=>'' === basePath ? pathname : '' === pathname ? basePath : addTrailingSlash(basePath) + pathname.replace(/^\/+/, ''), removeBasePath = (url, base)=>{
5177
+ let basePath = base.replace(/\/+$/, '');
5178
+ return '' === basePath ? url : url === basePath ? '/' : url.startsWith(`${basePath}/`) ? url.slice(basePath.length) : url;
5127
5179
  }, getRoutes = (context)=>{
5128
5180
  let environmentWithHtml = context.environmentList.filter((item)=>Object.keys(item.htmlPaths).length > 0);
5129
5181
  if (0 === environmentWithHtml.length) return [];
@@ -5133,7 +5185,7 @@ let normalizeUrl = (url)=>url.replace(/([^:]\/)\/+/g, '$1'), formatPrefix = (inp
5133
5185
  return prev.concat(...routes);
5134
5186
  }, []);
5135
5187
  }, formatRoutes = (entry, base, distPathPrefix, outputStructure)=>{
5136
- let prefix = joinUrlSegments(base, formatPrefix(distPathPrefix));
5188
+ let prefix = joinUrlPath(base, formatPrefix(distPathPrefix));
5137
5189
  return Object.keys(entry).map((entryName)=>({
5138
5190
  entryName,
5139
5191
  pathname: prefix + ('index' === entryName && 'nested' !== outputStructure ? '' : entryName)
@@ -5436,8 +5488,8 @@ function getPublicPath({ isDev, config, context }) {
5436
5488
  let defaultPort = server.port ?? 3000;
5437
5489
  return formatPublicPath(replacePortPlaceholder(publicPath, isDev ? context.devServer?.port ?? defaultPort : defaultPort));
5438
5490
  }
5439
- function applyAlias({ chain, config, rootPath, logger }) {
5440
- let mergedAlias = reduceConfigs({
5491
+ async function applyAlias({ chain, config, rootPath, logger }) {
5492
+ let mergedAlias = await reduceConfigs({
5441
5493
  initial: {},
5442
5494
  config: config.resolve.alias
5443
5495
  });
@@ -6941,13 +6993,14 @@ let faviconFallbackMiddleware = (req, res, next)=>{
6941
6993
  let { accept } = req.headers;
6942
6994
  return 'string' == typeof accept && (accept.includes('text/html') || accept.includes('*/*'));
6943
6995
  }, postfixRE = /[?#].*$/, getBaseUrlMiddleware = ({ base })=>function baseUrlMiddleware(req, res, next) {
6944
- let url = req.url, pathname = url.replace(postfixRE, '');
6945
- if (pathname.startsWith(base)) {
6946
- req.url = stripBase(url, base), next();
6996
+ var pathname;
6997
+ let basePath, url = req.url, pathname1 = url.replace(postfixRE, '');
6998
+ if (pathname = pathname1, '' === (basePath = base.replace(/\/+$/, '')) || pathname === basePath || pathname.startsWith(`${basePath}/`)) {
6999
+ req.url = removeBasePath(url, base), next();
6947
7000
  return;
6948
7001
  }
6949
- let redirectPath = addTrailingSlash(url) !== base ? joinUrlSegments(base, url) : base;
6950
- if ('/' === pathname || '/index.html' === pathname) {
7002
+ let redirectPath = addTrailingSlash(url) !== base ? joinUrlPath(base, url) : base;
7003
+ if ('/' === pathname1 || '/index.html' === pathname1) {
6951
7004
  res.writeHead(302, {
6952
7005
  Location: redirectPath
6953
7006
  }), res.end();
@@ -7536,7 +7589,7 @@ async function devServer_createDevServer(options, createCompiler, config, { getP
7536
7589
  let publicPaths = compiler_isMultiCompiler(compiler) ? compiler.compilers.map(getPublicPathFromCompiler) : [
7537
7590
  getPublicPathFromCompiler(compiler)
7538
7591
  ], { base } = config.server;
7539
- context.publicPathnames = publicPaths.map(getPathnameFromUrl).map((prefix)=>base && '/' !== base ? stripBase(prefix, base) : prefix), compiler?.hooks.watchRun.tap('rsbuild:watchRun', ()=>{
7592
+ context.publicPathnames = publicPaths.map(getPathnameFromUrl).map((prefix)=>base && '/' !== base ? removeBasePath(prefix, base) : prefix), compiler?.hooks.watchRun.tap('rsbuild:watchRun', ()=>{
7540
7593
  lastStats && (waitLastCompileDoneResolve && (waitLastCompileDoneResolve(), waitLastCompileDoneResolve = null), waitLastCompileDone = new Promise((resolve)=>{
7541
7594
  waitLastCompileDoneResolve = resolve;
7542
7595
  }));
@@ -7998,7 +8051,7 @@ function applyDefaultPlugins(pluginManager, context) {
7998
8051
  setup (api) {
7999
8052
  api.modifyBundlerChain({
8000
8053
  order: 'pre',
8001
- handler: (chain, { environment, CHAIN_ID })=>{
8054
+ handler: async (chain, { environment, CHAIN_ID })=>{
8002
8055
  let { config, tsconfigPath } = environment, { extensions, conditionNames, mainFields } = config.resolve;
8003
8056
  chain.resolve.extensions.merge([
8004
8057
  ...extensions
@@ -8013,7 +8066,7 @@ function applyDefaultPlugins(pluginManager, context) {
8013
8066
  ]).set('.jsx', [
8014
8067
  '.jsx',
8015
8068
  '.tsx'
8016
- ]), applyAlias({
8069
+ ]), await applyAlias({
8017
8070
  chain,
8018
8071
  config,
8019
8072
  rootPath: api.context.rootPath,
@@ -8155,8 +8208,8 @@ function applyDefaultPlugins(pluginManager, context) {
8155
8208
  let { config, htmlPaths } = environment;
8156
8209
  if (0 === Object.keys(htmlPaths).length) return;
8157
8210
  let assetPrefix = getPublicPathFromChain(chain, !1), entries = chain.entryPoints.entries() || {}, entryNames = Object.keys(entries).filter((entryName)=>!!htmlPaths[entryName]), extraDataMap = new Map(), finalOptions = await Promise.all(entryNames.map(async (entryName)=>{
8158
- let entryValue = entries[entryName].values(), chunks = getChunks(entryName, entryValue), inject = getInject(entryName, config), filename = htmlPaths[entryName], { templatePath, templateContent } = await getTemplate(entryName, config, api.context.rootPath), templateParameters = getTemplateParameters(entryName, config, assetPrefix), pluginOptions = {
8159
- meta: getMetaTags(entryName, config, templateContent),
8211
+ let entryValue = entries[entryName].values(), chunks = getChunks(entryName, entryValue), inject = await getInject(entryName, config), filename = htmlPaths[entryName], { templatePath, templateContent } = await getTemplate(entryName, config, api.context.rootPath), templateParameters = getTemplateParameters(entryName, config, assetPrefix), pluginOptions = {
8212
+ meta: await getMetaTags(entryName, config, templateContent),
8160
8213
  chunks,
8161
8214
  inject,
8162
8215
  filename,
@@ -8181,8 +8234,8 @@ function applyDefaultPlugins(pluginManager, context) {
8181
8234
  tags
8182
8235
  };
8183
8236
  })(environment.config);
8184
- tagConfig && (extraData.tagConfig = tagConfig), pluginOptions.title = getTitle(entryName, config);
8185
- let favicon = getFavicon(entryName, config) || (()=>{
8237
+ tagConfig && (extraData.tagConfig = tagConfig), pluginOptions.title = await getTitle(entryName, config);
8238
+ let favicon = await getFavicon(entryName, config) || (()=>{
8186
8239
  if (defaultFavicon) return defaultFavicon;
8187
8240
  let { publicDir } = api.getNormalizedConfig().server, extensions = [
8188
8241
  'ico',
@@ -8194,7 +8247,7 @@ function applyDefaultPlugins(pluginManager, context) {
8194
8247
  return faviconPath && (defaultFavicon = faviconPath), defaultFavicon;
8195
8248
  })();
8196
8249
  favicon && (extraData.favicon = favicon);
8197
- let finalOptions = reduceConfigsWithContext({
8250
+ let finalOptions = await reduceConfigsWithContext({
8198
8251
  initial: pluginOptions,
8199
8252
  config: 'boolean' == typeof config.tools.htmlPlugin ? {} : config.tools.htmlPlugin,
8200
8253
  ctx: {
@@ -8431,7 +8484,7 @@ try {
8431
8484
  cssRule.oneOf(CHAIN_ID.ONE_OF.CSS_RAW).type('asset/source').resourceQuery(RAW_QUERY_REGEX);
8432
8485
  let mainRule = cssRule.oneOf(CHAIN_ID.ONE_OF.CSS_MAIN), emitCss = config.output.emitCss ?? 'web' === target;
8433
8486
  if (emitCss) if (config.output.injectStyles) {
8434
- let styleLoaderOptions = reduceConfigs({
8487
+ let styleLoaderOptions = await reduceConfigs({
8435
8488
  initial: {},
8436
8489
  config: config.tools.styleLoader
8437
8490
  });
@@ -8441,10 +8494,10 @@ try {
8441
8494
  let importLoaders = {
8442
8495
  normal: 0,
8443
8496
  inline: 0
8444
- }, updateRules = (callback, options = {})=>{
8445
- options.skipMain || callback(mainRule, 'main'), callback(inlineRule, 'inline'), callback(urlRule, 'url');
8497
+ }, updateRules = async (callback, options = {})=>{
8498
+ options.skipMain || await callback(mainRule, 'main'), await callback(inlineRule, 'inline'), await callback(urlRule, 'url');
8446
8499
  }, cssLoaderPath = join(COMPILED_PATH, 'css-loader', 'index.js');
8447
- if (updateRules((rule)=>{
8500
+ if (await updateRules((rule)=>{
8448
8501
  rule.use(CHAIN_ID.USE.CSS).loader(cssLoaderPath);
8449
8502
  }), !1 !== config.tools.lightningcssLoader) {
8450
8503
  emitCss && importLoaders.normal++, importLoaders.inline++;
@@ -8453,8 +8506,8 @@ try {
8453
8506
  let webEnvironment = Object.values(environments).find((env)=>'web' === env.config.output.target);
8454
8507
  webEnvironment && (browserslist = webEnvironment.browserslist, minifyCss = parseMinifyOptions(webEnvironment.config).minifyCss);
8455
8508
  }
8456
- updateRules((rule, type)=>{
8457
- let minify = ('inline' === type || 'url' === type || config.output.injectStyles) && minifyCss, lightningcssOptions = getLightningCSSLoaderOptions(config, browserslist, minify);
8509
+ await updateRules(async (rule, type)=>{
8510
+ let minify = ('inline' === type || 'url' === type || config.output.injectStyles) && minifyCss, lightningcssOptions = await getLightningCSSLoaderOptions(config, browserslist, minify);
8458
8511
  rule.use(CHAIN_ID.USE.LIGHTNINGCSS).loader('builtin:lightningcss-loader').options(lightningcssOptions);
8459
8512
  }, {
8460
8513
  skipMain: !emitCss
@@ -8468,48 +8521,18 @@ try {
8468
8521
  if ('function' == typeof postcssLoaderOptions.postcssOptions || postcssLoaderOptions.postcssOptions?.plugins?.length) {
8469
8522
  emitCss && importLoaders.normal++, importLoaders.inline++;
8470
8523
  let postcssLoaderPath = join(COMPILED_PATH, 'postcss-loader', 'index.js');
8471
- updateRules((rule)=>{
8524
+ await updateRules((rule)=>{
8472
8525
  rule.use(CHAIN_ID.USE.POSTCSS).loader(postcssLoaderPath).options(postcssLoaderOptions);
8473
8526
  }, {
8474
8527
  skipMain: !emitCss
8475
8528
  });
8476
8529
  }
8477
- let localIdentName = config.output.cssModules.localIdentName || (isProd ? '[local]-[hash:base64:6]' : '[path][name]__[local]-[hash:base64:6]'), cssLoaderOptions = (({ config, localIdentName, emitCss })=>{
8478
- let { cssModules } = config.output;
8479
- return ((options, exportOnlyLocals)=>{
8480
- if (options.modules && exportOnlyLocals) {
8481
- let { modules } = options;
8482
- return modules = !0 === modules ? {
8483
- exportOnlyLocals: !0
8484
- } : 'string' == typeof modules ? {
8485
- mode: modules,
8486
- exportOnlyLocals: !0
8487
- } : {
8488
- ...modules,
8489
- exportOnlyLocals: !0
8490
- }, {
8491
- ...options,
8492
- modules
8493
- };
8494
- }
8495
- return options;
8496
- })(reduceConfigs({
8497
- initial: {
8498
- modules: {
8499
- ...cssModules,
8500
- localIdentName
8501
- },
8502
- sourceMap: getCSSSourceMap(config)
8503
- },
8504
- config: config.tools.cssLoader,
8505
- mergeFn: cjs_0_default()
8506
- }), !emitCss);
8507
- })({
8530
+ let localIdentName = config.output.cssModules.localIdentName || (isProd ? '[local]-[hash:base64:6]' : '[path][name]__[local]-[hash:base64:6]'), cssLoaderOptions = await getCSSLoaderOptions({
8508
8531
  config,
8509
8532
  localIdentName,
8510
8533
  emitCss
8511
8534
  });
8512
- updateRules((rule, type)=>{
8535
+ await updateRules((rule, type)=>{
8513
8536
  let finalOptions = cssLoaderOptions;
8514
8537
  finalOptions = 'inline' === type || 'url' === type ? {
8515
8538
  ...cssLoaderOptions,
@@ -8550,12 +8573,12 @@ try {
8550
8573
  {
8551
8574
  name: 'rsbuild:minimize',
8552
8575
  setup (api) {
8553
- api.modifyBundlerChain((chain, { environment, CHAIN_ID, rspack })=>{
8576
+ api.modifyBundlerChain(async (chain, { environment, CHAIN_ID, rspack })=>{
8554
8577
  let { config } = environment, { minifyJs, minifyCss, jsOptions, cssOptions } = parseMinifyOptions(config);
8555
8578
  if (chain.optimization.minimize(minifyJs || minifyCss), minifyJs && chain.optimization.minimizer(CHAIN_ID.MINIMIZER.JS).use(rspack.SwcJsMinimizerRspackPlugin, [
8556
8579
  getSwcMinimizerOptions(config, jsOptions)
8557
8580
  ]).end(), minifyCss) {
8558
- let loaderOptions = getLightningCSSLoaderOptions(config, environment.browserslist, !0), defaultOptions = {
8581
+ let loaderOptions = await getLightningCSSLoaderOptions(config, environment.browserslist, !0), defaultOptions = {
8559
8582
  minimizerOptions: {
8560
8583
  targets: isPlainObject(loaderOptions.targets) ? environment.browserslist : loaderOptions.targets,
8561
8584
  ...pick(loaderOptions, [
@@ -8608,7 +8631,7 @@ try {
8608
8631
  setup (api) {
8609
8632
  api.modifyBundlerChain({
8610
8633
  order: 'pre',
8611
- handler: (chain, { CHAIN_ID, isDev, isProd, target, environment })=>{
8634
+ handler: async (chain, { CHAIN_ID, isDev, isProd, target, environment })=>{
8612
8635
  let { config, browserslist } = environment, cacheRoot = node_path.join(api.context.cachePath, '.swc'), rule = chain.module.rule(CHAIN_ID.RULE.JS).test(SCRIPT_REGEX).dependency({
8613
8636
  not: 'url'
8614
8637
  });
@@ -8642,7 +8665,7 @@ try {
8642
8665
  ])item.resolve.alias.set('core-js', coreJsDir);
8643
8666
  }
8644
8667
  }
8645
- let mergedConfig = reduceConfigs({
8668
+ let mergedConfig = await reduceConfigs({
8646
8669
  initial: swcConfig,
8647
8670
  config: config.tools.swc,
8648
8671
  mergeFn: cjs_0_default()
@@ -8920,7 +8943,7 @@ try {
8920
8943
  api.modifyBundlerChain(async (chain, { CHAIN_ID, environment, isDev })=>{
8921
8944
  let { output: { manifest }, dev: { writeToDisk } } = environment.config;
8922
8945
  if (!1 === manifest) return;
8923
- let manifestOptions = normalizeManifestObjectConfig(manifest), { RspackManifestPlugin } = await import("./manifest-plugin.js").then(__webpack_require__.bind(__webpack_require__, "../../node_modules/.pnpm/rspack-manifest-plugin@5.2.1_@rspack+core@2.0.4/node_modules/rspack-manifest-plugin/dist/index.js")), { htmlPaths } = environment, filter = manifestOptions.filter ?? ((file)=>!file.name.endsWith('.LICENSE.txt'));
8946
+ let manifestOptions = normalizeManifestObjectConfig(manifest), { RspackManifestPlugin } = await import("./manifest-plugin.js").then(__webpack_require__.bind(__webpack_require__, "../../node_modules/.pnpm/rspack-manifest-plugin@5.2.1_@rspack+core@2.0.5/node_modules/rspack-manifest-plugin/dist/index.js")), { htmlPaths } = environment, filter = manifestOptions.filter ?? ((file)=>!file.name.endsWith('.LICENSE.txt'));
8924
8947
  manifestFilenames.set(environment.name, manifestOptions.filename);
8925
8948
  let pluginOptions = {
8926
8949
  fileName: manifestOptions.filename,
@@ -9434,7 +9457,7 @@ let applyServerOptions = (command)=>{
9434
9457
  };
9435
9458
  function setupCommands() {
9436
9459
  let cli = ((name = "")=>new CAC(name))('rsbuild');
9437
- cli.version("2.0.7"), cli.option('--base <base>', 'Set the base path of the server').option('-c, --config <config>', 'Set the configuration file (relative or absolute path)').option('--config-loader <loader>', 'Set the config file loader (auto | jiti | native)', {
9460
+ cli.version("2.0.8"), cli.option('--base <base>', 'Set the base path of the server').option('-c, --config <config>', 'Set the configuration file (relative or absolute path)').option('--config-loader <loader>', 'Set the config file loader (auto | jiti | native)', {
9438
9461
  default: 'auto'
9439
9462
  }).option('--env-dir <dir>', 'Set the directory for loading `.env` files').option('--env-mode <mode>', 'Set the env mode to load the `.env.[mode]` file').option('--environment <name>', 'Set the environment name(s) to build', {
9440
9463
  type: [
@@ -9505,7 +9528,7 @@ function initNodeEnv(command) {
9505
9528
  }
9506
9529
  function showGreeting() {
9507
9530
  let { npm_execpath, npm_lifecycle_event, NODE_RUN_SCRIPT_NAME } = process.env, isBun = npm_execpath?.includes('.bun');
9508
- src_logger.greet(`${'npx' === npm_lifecycle_event || isBun || NODE_RUN_SCRIPT_NAME ? '\n' : ''}Rsbuild v2.0.7\n`);
9531
+ src_logger.greet(`${'npx' === npm_lifecycle_event || isBun || NODE_RUN_SCRIPT_NAME ? '\n' : ''}Rsbuild v2.0.8\n`);
9509
9532
  }
9510
9533
  function setupLogLevel() {
9511
9534
  if (cli_argv.length <= 3) return;
@@ -9527,5 +9550,5 @@ function runCLI() {
9527
9550
  src_logger.error('Failed to start Rsbuild CLI.'), src_logger.error(err), process.exit(1);
9528
9551
  }
9529
9552
  }
9530
- let src_version = "2.0.7";
9553
+ let src_version = "2.0.8";
9531
9554
  export { PLUGIN_CSS_NAME, PLUGIN_SWC_NAME, core_rspack as rspack, createRsbuild, defaultAllowedOrigins, defineConfig, ensureAssetPrefix, loadConfig_loadConfig as loadConfig, loadEnv, logger_createLogger as createLogger, mergeRsbuildConfig, runCLI, src_logger as logger, src_version as version };
@@ -1,4 +1,4 @@
1
- import { logger } from "./797.js";
1
+ import { logger } from "./60.js";
2
2
  let createOverlay;
3
3
  let clearOverlay;
4
4
  const getErrorField = (error, field)=>{
@@ -1,5 +1,5 @@
1
1
  import { registerOverlay } from "./hmr.js";
2
- import { logger } from "./797.js";
2
+ import { logger } from "./60.js";
3
3
  function _define_property(obj, key, value) {
4
4
  if (key in obj) Object.defineProperty(obj, key, {
5
5
  value: value,