@rsbuild/core 2.1.9 → 2.1.11

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.
@@ -63,13 +63,13 @@ export declare class RspackChain extends __Config.ChainedMap<void> {
63
63
  >;
64
64
  output: RspackChain.Output;
65
65
  module: RspackChain.Module;
66
- node: RspackChain.ChainedMap<this> & ((value: boolean) => this);
66
+ node: RspackChain.ChainedMap<this> & ((value: false) => this);
67
67
  optimization: RspackChain.Optimization;
68
- performance: RspackChain.Performance & ((value: boolean) => this);
68
+ performance: RspackChain.Performance & ((value: false) => this);
69
69
  plugins: RspackChain.Plugins<this, PluginInstance>;
70
70
  resolve: RspackChain.Resolve;
71
71
  resolveLoader: RspackChain.ResolveLoader;
72
- devServer: RspackChain.DevServer;
72
+ devServer: RspackChain.DevServer & ((value: false) => this);
73
73
 
74
74
  context(value: RspackConfig['context']): this;
75
75
  mode(value: RspackConfig['mode']): this;
@@ -144,7 +144,7 @@ export declare namespace RspackChain {
144
144
  : any[],
145
145
  ) => PluginType,
146
146
  ): this;
147
- use<P extends string | PluginType | PluginClass<PluginType>>(
147
+ use<P extends PluginType | PluginClass<PluginType>>(
148
148
  plugin: P,
149
149
  args?: P extends PluginClass<PluginType>
150
150
  ? ConstructorParameters<P>
@@ -272,8 +272,9 @@ export declare namespace RspackChain {
272
272
  }
273
273
 
274
274
  type RspackResolve = Required<NonNullable<Configuration['resolve']>>;
275
+ type RspackResolveAlias = Exclude<RspackResolve['alias'], false>;
275
276
  class Resolve<T = RspackChain> extends ChainedMap<T> {
276
- alias: TypedChainedMap<this, { [key: string]: string | false | string[] }>;
277
+ alias: TypedChainedMap<this, RspackResolveAlias>;
277
278
  aliasFields: TypedChainedSet<this, RspackResolve['aliasFields'][number]>;
278
279
  conditionNames: TypedChainedSet<
279
280
  this,
@@ -298,10 +299,7 @@ export declare namespace RspackChain {
298
299
  restrictions: TypedChainedSet<this, RspackResolve['restrictions'][number]>;
299
300
  roots: TypedChainedSet<this, RspackResolve['roots'][number]>;
300
301
  modules: TypedChainedSet<this, RspackResolve['modules'][number]>;
301
- fallback: TypedChainedMap<
302
- this,
303
- { [key: string]: string | false | string[] }
304
- >;
302
+ fallback: TypedChainedMap<this, RspackResolveAlias>;
305
303
  byDependency: TypedChainedMap<this, RspackResolve['byDependency']>;
306
304
  enforceExtension(value: RspackResolve['enforceExtension']): this;
307
305
  fullySpecified(value: RspackResolve['fullySpecified']): this;
@@ -400,9 +398,7 @@ export declare namespace RspackChain {
400
398
  [name: string]: any;
401
399
  }
402
400
 
403
- interface LoaderOptions {
404
- [name: string]: any;
405
- }
401
+ type LoaderOptions = NonNullable<RuleSetLoaderWithOptions['options']>;
406
402
 
407
403
  type LoaderParallelOptions = NonNullable<
408
404
  RuleSetLoaderWithOptions['parallel']
package/dist/626.js CHANGED
@@ -386,8 +386,8 @@ __webpack_require__.add({
386
386
  return (asyncHooks.AsyncResource && (res = new asyncHooks.AsyncResource(fn.name || 'bound-anonymous-fn')), res && res.runInAsyncScope) ? res.runInAsyncScope.bind(res, fn, null) : fn;
387
387
  }
388
388
  },
389
- "../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.23/node_modules/postcss-load-config/src/index.js" (module, __unused_rspack_exports, __webpack_require__) {
390
- let yaml, { resolve } = __webpack_require__("node:path?815c"), 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.23/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.23/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.23/node_modules/postcss-load-config/src/req.js");
389
+ "../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.26/node_modules/postcss-load-config/src/index.js" (module, __unused_rspack_exports, __webpack_require__) {
390
+ let yaml, { resolve } = __webpack_require__("node:path?815c"), 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.26/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.26/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.26/node_modules/postcss-load-config/src/req.js");
391
391
  async function processResult(ctx, result) {
392
392
  let obj, file = result.filepath || '', projectConfig = ((obj = result.config) && obj.__esModule ? obj : {
393
393
  default: obj
@@ -460,8 +460,8 @@ __webpack_require__.add({
460
460
  });
461
461
  };
462
462
  },
463
- "../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.23/node_modules/postcss-load-config/src/options.js" (module, __unused_rspack_exports, __webpack_require__) {
464
- let req = __webpack_require__("../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.23/node_modules/postcss-load-config/src/req.js");
463
+ "../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.26/node_modules/postcss-load-config/src/options.js" (module, __unused_rspack_exports, __webpack_require__) {
464
+ let req = __webpack_require__("../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.26/node_modules/postcss-load-config/src/req.js");
465
465
  module.exports = async function options(config, file) {
466
466
  if (config.parser && 'string' == typeof config.parser) try {
467
467
  config.parser = await req(config.parser, file);
@@ -481,8 +481,8 @@ __webpack_require__.add({
481
481
  return config;
482
482
  };
483
483
  },
484
- "../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.23/node_modules/postcss-load-config/src/plugins.js" (module, __unused_rspack_exports, __webpack_require__) {
485
- let req = __webpack_require__("../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.23/node_modules/postcss-load-config/src/req.js");
484
+ "../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.26/node_modules/postcss-load-config/src/plugins.js" (module, __unused_rspack_exports, __webpack_require__) {
485
+ let req = __webpack_require__("../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.26/node_modules/postcss-load-config/src/req.js");
486
486
  async function load(plugin, options, file) {
487
487
  try {
488
488
  if (null == options || 0 === Object.keys(options).length) return await req(plugin, file);
@@ -498,7 +498,7 @@ __webpack_require__.add({
498
498
  }), list;
499
499
  };
500
500
  },
501
- "../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.23/node_modules/postcss-load-config/src/req.js" (module, __unused_rspack_exports, __webpack_require__) {
501
+ "../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.26/node_modules/postcss-load-config/src/req.js" (module, __unused_rspack_exports, __webpack_require__) {
502
502
  let tsx, jiti, { createRequire } = __webpack_require__("node:module?f56b"), { pathToFileURL } = __webpack_require__("node:url?5295"), TS_EXT_RE = /\.[mc]?ts$/, importError = [];
503
503
  module.exports = async function req(name, rootFile = __rspack_import_meta_filename__) {
504
504
  let url = createRequire(rootFile).resolve(name);
@@ -1535,11 +1535,9 @@ function createMap(superClass) {
1535
1535
  return this.store.delete(key), this;
1536
1536
  }
1537
1537
  order() {
1538
- let entries = [
1539
- ...this.store
1540
- ].reduce((acc, [key, value])=>(acc[key] = value, acc), {}), names = Object.keys(entries), order = [
1541
- ...names
1542
- ];
1538
+ let entries = {};
1539
+ for (let [key, value] of this.store)entries[key] = value;
1540
+ let names = Object.keys(entries), order = names.slice();
1543
1541
  return names.forEach((name)=>{
1544
1542
  if (!entries[name]) return;
1545
1543
  let { __before, __after } = entries[name];
@@ -1550,12 +1548,21 @@ function createMap(superClass) {
1550
1548
  };
1551
1549
  }
1552
1550
  entries() {
1553
- let { entries, order } = this.order();
1554
- if (order.length) return entries;
1551
+ if (!this.store.size) return;
1552
+ let entries = {};
1553
+ for (let [key, value] of this.store)entries[key] = value;
1554
+ return entries;
1555
1555
  }
1556
1556
  values() {
1557
- let { entries, order } = this.order();
1558
- return order.map((name)=>entries[name]);
1557
+ let values = [];
1558
+ for (let value of this.store.values()){
1559
+ if (value?.__before || value?.__after) {
1560
+ let { entries, order } = this.order();
1561
+ return order.map((name)=>entries[name]);
1562
+ }
1563
+ values.push(value);
1564
+ }
1565
+ return values;
1559
1566
  }
1560
1567
  get(key) {
1561
1568
  return this.store.get(key);
@@ -1798,7 +1805,7 @@ let ChainedMap = createMap(createChainable(Object)), ChainedValueMap = (superCla
1798
1805
  'clean'
1799
1806
  ]);
1800
1807
  }
1801
- }, DevServer = class extends ChainedMap {
1808
+ }, DevServer = class extends ChainedValueMap {
1802
1809
  constructor(parent){
1803
1810
  super(parent), this.extend([
1804
1811
  'allowedHosts',
@@ -1825,7 +1832,8 @@ let ChainedMap = createMap(createChainable(Object)), ChainedValueMap = (superCla
1825
1832
  ]);
1826
1833
  }
1827
1834
  toConfig() {
1828
- return this.clean(this.entries() || {});
1835
+ let config = this.entries();
1836
+ return !1 !== config && this.clean(config || {});
1829
1837
  }
1830
1838
  }, Orderable = (Class)=>class extends Class {
1831
1839
  before(name) {
@@ -1857,6 +1865,7 @@ let ChainedMap = createMap(createChainable(Object)), ChainedValueMap = (superCla
1857
1865
  return this.set('args', f(this.get('args') || [])), this;
1858
1866
  }
1859
1867
  set(key, value) {
1868
+ if ('plugin' === key && 'string' == typeof value) throw TypeError('Plugin paths are not supported. Import the plugin and pass it to .use() instead.');
1860
1869
  if ('args' === key && !Array.isArray(value)) throw Error('args must be an array of arguments');
1861
1870
  return super.set(key, value);
1862
1871
  }
@@ -1868,9 +1877,8 @@ let ChainedMap = createMap(createChainable(Object)), ChainedValueMap = (superCla
1868
1877
  ]);
1869
1878
  }
1870
1879
  toConfig() {
1871
- let init = this.get('init'), plugin = this.get('plugin'), args = this.get('args'), pluginPath = null;
1880
+ let init = this.get('init'), plugin = this.get('plugin'), args = this.get('args');
1872
1881
  if (void 0 === plugin) throw Error(`Invalid ${this.type} configuration: ${this.type}('${this.name}').use(<Plugin>) was not called to specify the plugin`);
1873
- 'string' == typeof plugin && (plugin = require(pluginPath = plugin));
1874
1882
  let constructorName = plugin.__expression ? `(${plugin.__expression})` : plugin.name, config = init(plugin, args);
1875
1883
  return Object.defineProperties(config, {
1876
1884
  __pluginName: {
@@ -1884,9 +1892,6 @@ let ChainedMap = createMap(createChainable(Object)), ChainedValueMap = (superCla
1884
1892
  },
1885
1893
  __pluginConstructorName: {
1886
1894
  value: constructorName
1887
- },
1888
- __pluginPath: {
1889
- value: pluginPath
1890
1895
  }
1891
1896
  }), config;
1892
1897
  }
@@ -1930,11 +1935,12 @@ function toArray(arr) {
1930
1935
  ];
1931
1936
  }
1932
1937
  let Rule = Orderable(class extends ChainedMap {
1938
+ #resolve;
1933
1939
  constructor(parent, name, ruleType = 'rule'){
1934
1940
  super(parent), this.ruleName = name, this.names = [], this.ruleType = ruleType, this.ruleTypes = [];
1935
1941
  let rule = this;
1936
1942
  for(; rule instanceof Rule;)this.names.unshift(rule.ruleName), this.ruleTypes.unshift(rule.ruleType), rule = rule.parent;
1937
- this.uses = new ChainedMap(this), this.include = new ChainedSet(this), this.exclude = new ChainedSet(this), this.rules = new ChainedMap(this), this.oneOfs = new ChainedMap(this), this.resolve = new Resolve(this), this.extend([
1943
+ this.uses = new ChainedMap(this), this.include = new ChainedSet(this), this.exclude = new ChainedSet(this), this.rules = new ChainedMap(this), this.oneOfs = new ChainedMap(this), this.extend([
1938
1944
  'dependency',
1939
1945
  "descriptionData",
1940
1946
  'enforce',
@@ -1956,6 +1962,12 @@ let Rule = Orderable(class extends ChainedMap {
1956
1962
  'type'
1957
1963
  ]);
1958
1964
  }
1965
+ get resolve() {
1966
+ return this.#resolve ??= new Resolve(this), this.#resolve;
1967
+ }
1968
+ set resolve(value) {
1969
+ this.#resolve = value;
1970
+ }
1959
1971
  use(name) {
1960
1972
  return this.uses.getOrCompute(name, ()=>new Use(this, name));
1961
1973
  }
@@ -1978,7 +1990,7 @@ let Rule = Orderable(class extends ChainedMap {
1978
1990
  rules: this.rules.values().map((rule)=>rule.toConfig()),
1979
1991
  oneOf: this.oneOfs.values().map((oneOf)=>oneOf.toConfig()),
1980
1992
  use: this.uses.values().map((use)=>use.toConfig()),
1981
- resolve: this.resolve.toConfig()
1993
+ resolve: this.#resolve?.toConfig()
1982
1994
  }));
1983
1995
  return Object.defineProperties(config, {
1984
1996
  __ruleNames: {
@@ -2023,6 +2035,7 @@ let Rule = Orderable(class extends ChainedMap {
2023
2035
  }
2024
2036
  merge(obj, omit = []) {
2025
2037
  return !omit.includes('rule') && 'rule' in obj && Object.keys(obj.rule).forEach((name)=>this.rule(name).merge(obj.rule[name])), !omit.includes('defaultRule') && 'defaultRule' in obj && Object.keys(obj.defaultRule).forEach((name)=>this.defaultRule(name).merge(obj.defaultRule[name])), super.merge(obj, [
2038
+ ...omit,
2026
2039
  'rule',
2027
2040
  'defaultRule'
2028
2041
  ]);
@@ -2107,7 +2120,7 @@ class RspackChain extends ChainedMap {
2107
2120
  static toString(config, { verbose = !1, configPrefix = 'config' } = {}) {
2108
2121
  return (0, dist.A)(config, (value, indent, stringify)=>{
2109
2122
  if (value && value.__pluginName) {
2110
- let prefix = `/* ${configPrefix}.${value.__pluginType}('${value.__pluginName}') */\n`, constructorExpression = value.__pluginPath ? `(require(${stringify(value.__pluginPath)}))` : value.__pluginConstructorName;
2123
+ let prefix = `/* ${configPrefix}.${value.__pluginType}('${value.__pluginName}') */\n`, constructorExpression = value.__pluginConstructorName;
2111
2124
  if (constructorExpression) {
2112
2125
  let args = stringify(value.__pluginArgs).slice(1, -1);
2113
2126
  return `${prefix}new ${constructorExpression}(${args})`;
@@ -2152,6 +2165,10 @@ class RspackChain extends ChainedMap {
2152
2165
  entryImport.push(item);
2153
2166
  continue;
2154
2167
  }
2168
+ if (Array.isArray(item)) {
2169
+ entryImport.push(...item);
2170
+ continue;
2171
+ }
2155
2172
  item.import && entryImport.push(...castArray(item.import)), entryDescription ? Object.assign(entryDescription, item) : entryDescription = item;
2156
2173
  }
2157
2174
  formattedEntry[entryName] = entryDescription ? {
@@ -3363,7 +3380,7 @@ let getEnvironmentHTMLPaths = (entry, config, logger)=>'web' !== config.output.t
3363
3380
  }, {});
3364
3381
  async function updateEnvironmentContext(context, configs) {
3365
3382
  for (let [index, [name, config]] of (context.environments ||= {}, Object.entries(configs).entries())){
3366
- let browserslist = getBrowserslistByEnvironment(context.rootPath, config), { entry = {}, tsconfigPath } = config.source, htmlPaths = getEnvironmentHTMLPaths(entry, config, context.logger), webSocketToken = 'dev' === context.action ? await helpers_hash(context.rootPath + name) : '', environmentContext = {
3383
+ let browserslist = getBrowserslistByEnvironment(context.rootPath, config), { entry = {}, tsconfigPath } = config.source, htmlPaths = getEnvironmentHTMLPaths(entry, config, context.logger), webSocketToken = 'dev' === context.action ? await helpers_hash(context.rootPath + name) : '', readonlyEnvironmentContext = new Proxy({
3367
3384
  index,
3368
3385
  name,
3369
3386
  distPath: getAbsoluteDistPath(context.rootPath, config),
@@ -3373,7 +3390,7 @@ async function updateEnvironmentContext(context, configs) {
3373
3390
  tsconfigPath,
3374
3391
  config,
3375
3392
  webSocketToken
3376
- }, readonlyEnvironmentContext = new Proxy(environmentContext, {
3393
+ }, {
3377
3394
  get: (target, prop)=>target[prop],
3378
3395
  set: (target, prop, newValue)=>('manifest' === prop ? target[prop] = newValue : context.logger.error(`EnvironmentContext is readonly, you can not assign to the "environment.${prop}" prop.`), !0)
3379
3396
  });
@@ -3407,7 +3424,7 @@ function createPublicContext(context) {
3407
3424
  async function createContext(options, userConfig, logger, loadConfigResult) {
3408
3425
  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, hooks = initHooks();
3409
3426
  return {
3410
- version: "2.1.9",
3427
+ version: "2.1.11",
3411
3428
  rootPath,
3412
3429
  configFile: loadConfigResult?.filePath ?? userConfig._privateMeta?.configFilePath,
3413
3430
  configFileDependencies: loadConfigResult?.dependencies ?? userConfig._privateMeta?.configFileDependencies ?? [],
@@ -5028,7 +5045,7 @@ function parseMinifyOptions(config) {
5028
5045
  cssOptions: minify.cssOptions
5029
5046
  };
5030
5047
  }
5031
- let postcss_load_config_src = __webpack_require__("../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.23/node_modules/postcss-load-config/src/index.js");
5048
+ let postcss_load_config_src = __webpack_require__("../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.26/node_modules/postcss-load-config/src/index.js");
5032
5049
  var postcss_load_config_src_default = __webpack_require__.n(postcss_load_config_src);
5033
5050
  async function getLightningCSSLoaderOptions(config, targets, minify) {
5034
5051
  let userOptions = 'object' == typeof config.tools.lightningcssLoader ? config.tools.lightningcssLoader : {}, initialOptions = {
@@ -5316,9 +5333,9 @@ async function printFileSizes(options, stats, rootPath, distPath, environmentNam
5316
5333
  }, getAssets = async ()=>{
5317
5334
  let { exclude, include } = options, formattedAssets = [], compilationAssets = stats.compilation.assets;
5318
5335
  for (let assetName of Object.keys(compilationAssets)){
5319
- let value = compilationAssets[assetName], filePath = getFilePath(assetName);
5336
+ let filePath = getFilePath(assetName);
5320
5337
  if (!exclude && EXCLUDE_ASSET_REGEX.test(filePath)) continue;
5321
- let content = options.compressed && isCompressible(filePath) ? value.source() : void 0, size = void 0 === content ? value.size() : Buffer.byteLength(content);
5338
+ let value = compilationAssets[assetName], content = options.compressed && isCompressible(filePath) ? value.source() : void 0, size = void 0 === content ? value.size() : Buffer.byteLength(content);
5322
5339
  if (exclude || include) {
5323
5340
  let publicAsset = {
5324
5341
  name: filePath,
@@ -5467,8 +5484,8 @@ class RsbuildHtmlPlugin {
5467
5484
  }
5468
5485
  apply(compiler) {
5469
5486
  let emitFavicon = async ({ compilation, favicon, faviconDistPath, logger })=>{
5470
- let fileContent, name = node_path.basename(favicon);
5471
- if (compilation.assets[name]) return name;
5487
+ let fileContent, name = node_path.basename(favicon), outputFilename = node_path.posix.join(faviconDistPath, name);
5488
+ if (outputFilename in compilation.assets) return outputFilename;
5472
5489
  let inputFs = compilation.inputFileSystem;
5473
5490
  if (!inputFs) return addCompilationError(compilation, `${color.dim('[rsbuild:html]')} Failed to read the favicon file as ${color.yellow('compilation.inputFileSystem')} is not available.`), null;
5474
5491
  let inputFilename = node_path.isAbsolute(favicon) ? favicon : node_path.join(compilation.compiler.context, favicon);
@@ -5477,7 +5494,7 @@ class RsbuildHtmlPlugin {
5477
5494
  } catch (error) {
5478
5495
  return logger.debug(`read favicon error: ${error}`), addCompilationError(compilation, `${color.dim('[rsbuild:html]')} Failed to read the favicon file at ${color.yellow(inputFilename)}.`), null;
5479
5496
  }
5480
- let source = new core_rspack.sources.RawSource(fileContent, !1), outputFilename = node_path.posix.join(faviconDistPath, name);
5497
+ let source = new core_rspack.sources.RawSource(fileContent, !1);
5481
5498
  return compilation.emitAsset(outputFilename, source), outputFilename;
5482
5499
  }, addFavicon = async ({ headTags, favicon, faviconDistPath, compilation, publicPath, logger })=>{
5483
5500
  let href = favicon;
@@ -5713,11 +5730,12 @@ function updateSourceMappingURL({ source, compilation, publicPath, type, config
5713
5730
  }
5714
5731
  return source;
5715
5732
  }
5716
- function matchTests(name, asset, tests) {
5717
- return tests.some((test)=>isFunction(test) ? test({
5733
+ function getMatchedAsset(name, assets, tests) {
5734
+ let asset;
5735
+ if (tests.some((test)=>isFunction(test) ? !!(asset ??= assets[name]) && test({
5718
5736
  name,
5719
5737
  size: asset.size()
5720
- }) : test.exec(name));
5738
+ }) : test.exec(name))) return asset ?? assets[name];
5721
5739
  }
5722
5740
  function getInlineTests(config) {
5723
5741
  let isProd = 'production' === config.mode, { inlineStyles, inlineScripts } = config.output, scriptTests = [], styleTests = [];
@@ -5753,19 +5771,31 @@ let normalizeUrl = (url)=>url.replace(/([^:]\/)\/+/g, '$1'), formatPrefix = (inp
5753
5771
  entryName,
5754
5772
  pathname: prefix + ('index' === entryName && 'nested' !== outputStructure ? '' : entryName)
5755
5773
  })).sort((a)=>'index' === a.entryName ? -1 : 1);
5756
- };
5774
+ }, formatName = (name)=>name ? `(${name.length > 20 ? `${name.slice(0, 19)}…` : name})` : name;
5757
5775
  function getURLMessages(urls, routes, { maxRoutes = 10, showAllRoutes, cliShortcutsEnabled }) {
5758
- let routeLimit = showAllRoutes ? 1 / 0 : void 0 === maxRoutes ? 10 : maxRoutes === 1 / 0 ? maxRoutes : Math.max(0, Math.floor(maxRoutes)), printableRoutes = 0 === routeLimit ? [] : routes.slice(0, routeLimit), moreEntries = routeLimit > 0 ? routes.length - printableRoutes.length : 0;
5776
+ let prevName, routeLimit = showAllRoutes ? 1 / 0 : void 0 === maxRoutes ? 10 : 1 / 0 === maxRoutes ? maxRoutes : Math.max(0, Math.floor(maxRoutes)), printableRoutes = 0 === routeLimit ? [] : routes.slice(0, routeLimit), moreEntries = routeLimit > 0 ? routes.length - printableRoutes.length : 0, nameCount = 0;
5777
+ for (let { name } of urls)if (name && ++nameCount > 1) break;
5778
+ let showNames = nameCount > 1;
5759
5779
  if (routes.length <= 1 || 0 === printableRoutes.length) {
5760
- let pathname = printableRoutes.length ? printableRoutes[0].pathname : '', padWidth = Math.max(Math.max(...urls.map((u)=>u.label.trimEnd().length)) + 2, 10), message = urls.map(({ label, url })=>{
5761
- let normalizedPathname = normalizeUrl(`${url}${pathname}`), prefix = `➜ ${color.dim(label.trimEnd().padEnd(padWidth))}`;
5762
- return ` ${prefix}${color.cyan(normalizedPathname)}\n`;
5780
+ let pathname = printableRoutes[0]?.pathname ?? '', items = urls.map(({ label, name, url })=>({
5781
+ label,
5782
+ name: showNames ? formatName(name) : void 0,
5783
+ url: normalizeUrl(`${url}${pathname}`)
5784
+ })), labelWidth = Math.max(10, ...items.map((item)=>item.label.trimEnd().length + 2)), urlWidth = Math.max(0, ...items.map((item)=>item.name ? item.url.length : 0)), message = items.map(({ label, name, url })=>{
5785
+ let prefix = `➜ ${color.dim(label.trimEnd().padEnd(labelWidth))}`, suffix = name ? `${' '.repeat(urlWidth - url.length + 2)}${color.dim(name)}` : '';
5786
+ return ` ${prefix}${color.cyan(url)}${suffix}\n`;
5763
5787
  }).join('');
5764
5788
  return moreEntries > 0 && (message += getMoreEntriesMessage(moreEntries, cliShortcutsEnabled)), message;
5765
5789
  }
5766
- let message = '', prevLabel = '', maxNameLength = Math.max(...printableRoutes.map((r)=>r.entryName.length));
5767
- return urls.forEach(({ label, url }, index)=>{
5768
- for (let { entryName, pathname } of (prevLabel !== label && (index > 0 && (message += '\n'), message += ` ➜ ${label}\n`, prevLabel = label), printableRoutes))message += ` ${color.dim('-')} ${color.dim(entryName.padEnd(maxNameLength + 4))}${color.cyan(normalizeUrl(`${url}${pathname}`))}\n`;
5790
+ let message = '', prevLabel = '', entryWidth = Math.max(...printableRoutes.map((route)=>route.entryName.length));
5791
+ return urls.forEach(({ label, name, url }, index)=>{
5792
+ let shortName = showNames ? formatName(name) : void 0;
5793
+ if (prevLabel !== label || prevName !== shortName) {
5794
+ index > 0 && (message += '\n');
5795
+ let title = shortName ? `${label.trimEnd().slice(0, -1)} ${color.dim(shortName)}:` : label;
5796
+ message += ` ➜ ${title}\n`, prevLabel = label, prevName = shortName;
5797
+ }
5798
+ for (let { entryName, pathname } of printableRoutes)message += ` ${color.dim('-')} ${color.dim(entryName.padEnd(entryWidth + 4))}${color.cyan(normalizeUrl(`${url}${pathname}`))}\n`;
5769
5799
  }), moreEntries > 0 && (message += getMoreEntriesMessage(moreEntries, cliShortcutsEnabled)), message;
5770
5800
  }
5771
5801
  function printServerURLs({ urls: originalUrls, port, routes, protocol, printUrls, fallbackPathname, showAllRoutes, cliShortcutsEnabled, originalConfig, logger }) {
@@ -5835,12 +5865,16 @@ let getPort = async ({ host, port, strictPort, tryLimits = 20 })=>{
5835
5865
  port,
5836
5866
  portTip
5837
5867
  };
5838
- }, isLoopbackHost = (host)=>new Set([
5839
- LOCALHOST,
5840
- '127.0.0.1',
5841
- '::1',
5842
- '0000:0000:0000:0000:0000:0000:0000:0001'
5843
- ]).has(host), getHostInUrl = async (host)=>{
5868
+ }, WILDCARD_HOSTS = new Set([
5869
+ ALL_INTERFACES_IPV4,
5870
+ '::',
5871
+ '0000:0000:0000:0000:0000:0000:0000:0000'
5872
+ ]), LOOPBACK_HOSTS = new Set([
5873
+ LOCALHOST,
5874
+ '127.0.0.1',
5875
+ '::1',
5876
+ '0000:0000:0000:0000:0000:0000:0000:0001'
5877
+ ]), isLoopbackHost = (host)=>LOOPBACK_HOSTS.has(host), getHostInUrl = async (host)=>{
5844
5878
  if (host === ALL_INTERFACES_IPV4 || host === LOCALHOST) return LOCALHOST;
5845
5879
  let { isIPv6 } = await import("node:net");
5846
5880
  return isIPv6(host) ? '::' === host ? '[::1]' : `[${host}]` : host;
@@ -5865,33 +5899,27 @@ let getPort = async ({ host, port, strictPort, tryLimits = 20 })=>{
5865
5899
  }
5866
5900
  ];
5867
5901
  }
5868
- let ipv4Interfaces = (()=>{
5869
- let interfaces = node_os.networkInterfaces(), ipv4Interfaces = new Map();
5870
- for (let key of Object.keys(interfaces))for (let detail of interfaces[key]){
5871
- let familyV4Value = 'string' == typeof detail.family ? 'IPv4' : 4;
5872
- detail.family !== familyV4Value || ipv4Interfaces.has(detail.address) || ipv4Interfaces.set(detail.address, detail);
5873
- }
5874
- return Array.from(ipv4Interfaces.values());
5875
- })(), addressUrls = [], hasLocalUrl = !1;
5876
- for (let detail of ipv4Interfaces)if (isLoopbackHost(detail.address) || detail.internal) {
5877
- if (hasLocalUrl) continue;
5878
- addressUrls.push({
5902
+ let urls = [], seen = new Set(), hasLocal = !1;
5903
+ for (let [name, infos] of Object.entries(node_os.networkInterfaces()))for (let info of infos ?? []){
5904
+ let family = info.family;
5905
+ !('IPv4' !== family && 4 !== family || seen.has(info.address)) && (seen.add(info.address), isLoopbackHost(info.address) || info.internal ? hasLocal || (urls.push({
5879
5906
  label: LOCAL_LABEL,
5880
5907
  url: concatUrl({
5881
5908
  host: LOCALHOST,
5882
5909
  port,
5883
5910
  protocol
5884
5911
  })
5885
- }), hasLocalUrl = !0;
5886
- } else addressUrls.push({
5887
- label: NETWORK_LABEL,
5888
- url: concatUrl({
5889
- host: detail.address,
5890
- port,
5891
- protocol
5892
- })
5893
- });
5894
- return addressUrls;
5912
+ }), hasLocal = !0) : urls.push({
5913
+ label: NETWORK_LABEL,
5914
+ name,
5915
+ url: concatUrl({
5916
+ host: info.address,
5917
+ port,
5918
+ protocol
5919
+ })
5920
+ }));
5921
+ }
5922
+ return urls;
5895
5923
  };
5896
5924
  function getServerTerminator(server) {
5897
5925
  let listened = !1, pendingSockets = new Set(), onConnection = (socket)=>{
@@ -6512,11 +6540,7 @@ async function resolveHostname(host = LOCALHOST) {
6512
6540
  let resolvedAddress = await getLocalhostResolvedAddress();
6513
6541
  if (resolvedAddress) return resolvedAddress;
6514
6542
  }
6515
- return void 0 === host || new Set([
6516
- ALL_INTERFACES_IPV4,
6517
- '::',
6518
- '0000:0000:0000:0000:0000:0000:0000:0000'
6519
- ]).has(host) ? LOCALHOST : host;
6543
+ return void 0 === host || WILDCARD_HOSTS.has(host) ? LOCALHOST : host;
6520
6544
  }
6521
6545
  let UP_PATH_REGEXP = /(?:^|[\\/])\.\.(?:[\\/]|$)/;
6522
6546
  async function getFileFromUrl(url, outputFileSystem, context) {
@@ -6610,7 +6634,7 @@ function getValueContentRangeHeader(type, size, range) {
6610
6634
  }
6611
6635
  function parseHttpDate(date) {
6612
6636
  let timestamp = date && Date.parse(date);
6613
- return 'number' == typeof timestamp ? timestamp : NaN;
6637
+ return 'number' == typeof timestamp ? timestamp : 0 / 0;
6614
6638
  }
6615
6639
  let CACHE_CONTROL_NO_CACHE_REGEXP = /(?:^|,)\s*?no-cache\s*?(?:,|$)/;
6616
6640
  function getRequestHeader(headers, name) {
@@ -6804,7 +6828,7 @@ function createAssetsMiddleware(context, ready, outputFileSystem) {
6804
6828
  }
6805
6829
  async function setupOutputFileSystem(writeToDisk, compilers) {
6806
6830
  if (!0 !== writeToDisk) {
6807
- let { createFsFromVolume, Volume } = await import("./memfs.js").then(__webpack_require__.t.bind(__webpack_require__, "../../node_modules/.pnpm/memfs@4.64.0/node_modules/memfs/lib/index.js", 23)), outputFileSystem = createFsFromVolume(new Volume());
6831
+ let { createFsFromVolume, Volume } = await import("./memfs.js").then(__webpack_require__.t.bind(__webpack_require__, "../../node_modules/.pnpm/memfs@4.68.0/node_modules/memfs/lib/index.js", 23)), outputFileSystem = createFsFromVolume(new Volume());
6808
6832
  for (let compiler of compilers)compiler.outputFileSystem = outputFileSystem;
6809
6833
  }
6810
6834
  let compiler = compilers.find((compiler)=>!!compiler.outputFileSystem);
@@ -9025,14 +9049,14 @@ function applyDefaultPlugins(pluginManager, context) {
9025
9049
  'node'
9026
9050
  ],
9027
9051
  raw: !0
9028
- }, ({ code, emitFile, resourcePath })=>{
9052
+ }, ({ code, emitFile, environment, resourcePath })=>{
9029
9053
  let name, filename = (name = resourcePath && node_path.parse(resourcePath).name) ? `${name}.node` : null;
9030
9054
  if (null === filename) throw Error(`${color.dim('[rsbuild:nodeAddons]')} Failed to load Node.js addon: ${color.yellow(resourcePath)}`);
9031
9055
  emitFile(filename, code);
9032
- let config = api.getNormalizedConfig(), handleErrorSnippet = `throw new Error('Failed to load Node.js addon: "${filename}"', {
9056
+ let handleErrorSnippet = `throw new Error('Failed to load Node.js addon: "${filename}"', {
9033
9057
  cause: error,
9034
9058
  });`;
9035
- return config.output.module ? `
9059
+ return environment.config.output.module ? `
9036
9060
  import path from "node:path";
9037
9061
  import { createRequire } from "node:module";
9038
9062
  import { fileURLToPath } from "node:url";
@@ -9153,8 +9177,7 @@ try {
9153
9177
  emitCss
9154
9178
  });
9155
9179
  await updateRules((rule, type)=>{
9156
- let finalOptions = cssLoaderOptions;
9157
- finalOptions = 'inline' === type || 'url' === type ? {
9180
+ let finalOptions = 'inline' === type || 'url' === type ? {
9158
9181
  ...cssLoaderOptions,
9159
9182
  exportType: 'string',
9160
9183
  modules: !1,
@@ -9162,7 +9185,8 @@ try {
9162
9185
  } : {
9163
9186
  ...cssLoaderOptions,
9164
9187
  importLoaders: importLoaders.normal
9165
- }, emitCss || 'main' !== type || rule.use(CHAIN_ID.USE.IGNORE_CSS).options({
9188
+ };
9189
+ emitCss || 'main' !== type || rule.use(CHAIN_ID.USE.IGNORE_CSS).options({
9166
9190
  modules: finalOptions.modules
9167
9191
  }), rule.use(CHAIN_ID.USE.CSS).options(finalOptions), 'url' !== type && rule.sideEffects(!0), rule.resolve.preferRelative(!0);
9168
9192
  });
@@ -9355,12 +9379,16 @@ try {
9355
9379
  if (!inlinedAssets || 0 === inlinedAssets.size) return;
9356
9380
  let { devtool } = compiler.options, hasSourceMap = 'hidden-source-map' !== devtool && !1 !== devtool;
9357
9381
  for (let name of inlinedAssets){
9358
- let asset = compilation.assets[name];
9359
- asset && (hasSourceMap && compilation.updateAsset(name, asset, {
9360
- related: {
9361
- sourceMap: null
9362
- }
9363
- }), compilation.deleteAsset(name));
9382
+ if (hasSourceMap) {
9383
+ let asset = compilation.assets[name];
9384
+ if (!asset) continue;
9385
+ compilation.updateAsset(name, asset, {
9386
+ related: {
9387
+ sourceMap: null
9388
+ }
9389
+ });
9390
+ } else if (!(name in compilation.assets)) continue;
9391
+ compilation.deleteAsset(name);
9364
9392
  }
9365
9393
  inlinedAssets.clear();
9366
9394
  }), api.modifyHTMLTags(({ headTags, bodyTags }, { compiler, compilation, environment })=>{
@@ -9380,8 +9408,8 @@ try {
9380
9408
  return config = environment.config, "script" === tag.tag ? ((publicPath, tag, compilation, inlinedAssets, scriptTests, config)=>{
9381
9409
  let { assets } = compilation;
9382
9410
  if (!(tag.attrs?.src && 'string' == typeof tag.attrs.src)) return tag;
9383
- let { src, ...otherAttrs } = tag.attrs, scriptName = publicPath ? src.replace(publicPath, '') : src, asset = assets[scriptName];
9384
- if (null == asset || !matchTests(scriptName, asset, scriptTests)) return tag;
9411
+ let { src, ...otherAttrs } = tag.attrs, scriptName = publicPath ? src.replace(publicPath, '') : src, asset = getMatchedAsset(scriptName, assets, scriptTests);
9412
+ if (!asset) return tag;
9385
9413
  let ret = {
9386
9414
  tag: "script",
9387
9415
  children: updateSourceMappingURL({
@@ -9399,8 +9427,8 @@ try {
9399
9427
  })(publicPath, tag, compilation, inlinedAssets, scriptTests, config) : 'link' === tag.tag && tag.attrs && 'stylesheet' === tag.attrs.rel ? ((publicPath, tag, compilation, inlinedAssets, styleTests, config)=>{
9400
9428
  let { assets } = compilation;
9401
9429
  if (!(tag.attrs?.href && 'string' == typeof tag.attrs.href)) return tag;
9402
- let linkName = publicPath ? tag.attrs.href.replace(publicPath, '') : tag.attrs.href, asset = assets[linkName];
9403
- if (null == asset || !matchTests(linkName, asset, styleTests)) return tag;
9430
+ let linkName = publicPath ? tag.attrs.href.replace(publicPath, '') : tag.attrs.href, asset = getMatchedAsset(linkName, assets, styleTests);
9431
+ if (!asset) return tag;
9404
9432
  let ret = {
9405
9433
  tag: 'style',
9406
9434
  children: updateSourceMappingURL({
@@ -9571,7 +9599,7 @@ try {
9571
9599
  api.modifyBundlerChain(async (chain, { CHAIN_ID, environment, isDev })=>{
9572
9600
  let { output: { manifest }, dev: { writeToDisk } } = environment.config;
9573
9601
  if (!1 === manifest) return;
9574
- let manifestOptions = normalizeManifestObjectConfig(manifest), { RspackManifestPlugin } = await import("./manifest-plugin.js").then(__webpack_require__.bind(__webpack_require__, "../../node_modules/.pnpm/rspack-manifest-plugin@5.2.2_@rspack+core@2.1.7/node_modules/rspack-manifest-plugin/dist/index.js")), { htmlPaths } = environment, filter = manifestOptions.filter ?? ((file)=>!file.name.endsWith('.LICENSE.txt'));
9602
+ let manifestOptions = normalizeManifestObjectConfig(manifest), { RspackManifestPlugin } = await import("./manifest-plugin.js").then(__webpack_require__.bind(__webpack_require__, "../../node_modules/.pnpm/rspack-manifest-plugin@5.2.2_@rspack+core@2.1.9/node_modules/rspack-manifest-plugin/dist/index.js")), { htmlPaths } = environment, filter = manifestOptions.filter ?? ((file)=>!file.name.endsWith('.LICENSE.txt'));
9575
9603
  manifestFilenames.set(environment.name, manifestOptions.filename);
9576
9604
  let pluginOptions = {
9577
9605
  fileName: manifestOptions.filename,
@@ -10114,7 +10142,7 @@ let applyServerOptions = (command)=>{
10114
10142
  };
10115
10143
  function setupCommands(argv) {
10116
10144
  let cli = ((name = "")=>new CAC(name))('rsbuild');
10117
- cli.version("2.1.9"), 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)', {
10145
+ cli.version("2.1.11"), 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)', {
10118
10146
  default: 'auto'
10119
10147
  }).option('--dist-path <dir>', 'Set the root directory of output files').option('--source-map', 'Enable source map').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', {
10120
10148
  type: [
@@ -10179,7 +10207,7 @@ function setupCommands(argv) {
10179
10207
  }
10180
10208
  function showGreeting() {
10181
10209
  let { npm_execpath, npm_lifecycle_event, NODE_RUN_SCRIPT_NAME } = process.env, isBun = npm_execpath?.includes('.bun');
10182
- src_logger.greet(`${'npx' === npm_lifecycle_event || isBun || NODE_RUN_SCRIPT_NAME ? '\n' : ''}Rsbuild v2.1.9\n`);
10210
+ src_logger.greet(`${'npx' === npm_lifecycle_event || isBun || NODE_RUN_SCRIPT_NAME ? '\n' : ''}Rsbuild v2.1.11\n`);
10183
10211
  }
10184
10212
  function setupLogLevel(argv) {
10185
10213
  if (argv.length <= 3) return;
@@ -10201,5 +10229,5 @@ function runCLI({ argv = process.argv } = {}) {
10201
10229
  src_logger.error('Failed to start Rsbuild CLI.'), src_logger.error(err), process.exit(1);
10202
10230
  }
10203
10231
  }
10204
- let src_version = "2.1.9";
10232
+ let src_version = "2.1.11";
10205
10233
  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, mrmime_lookup, runCLI, src_logger as logger, src_version as version };