@rsbuild/core 2.3.4 → 2.3.5

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 +1 @@
1
- {"name":"rspack-chain","version":"2.3.3","license":"MIT","types":"types/index.d.ts","type":"module"}
1
+ {"name":"rspack-chain","version":"2.4.0","license":"MIT","types":"types/index.d.ts","type":"module"}
@@ -429,6 +429,7 @@ export declare namespace RspackChain {
429
429
  ): Use<this, Options>;
430
430
  rule(name: string): Rule<Rule>;
431
431
  oneOf(name: string): Rule<Rule>;
432
+ cloneFrom<SourceParent>(source: Rule<SourceParent>): this;
432
433
  pre(): this;
433
434
  post(): this;
434
435
  before(name: string): this;
@@ -497,6 +498,8 @@ export declare namespace RspackChain {
497
498
 
498
499
  tap(f: (options: Options) => Options): this;
499
500
 
501
+ cloneFrom<SourceParent>(source: Use<SourceParent, Options>): this;
502
+
500
503
  // Orderable
501
504
  before(name: string): this;
502
505
  after(name: string): this;
package/dist/m.js CHANGED
@@ -1474,7 +1474,38 @@ let ChainedMap = createMap(createChainable(Object)), ChainedValueMap = (superCla
1474
1474
  when(condition, whenTruthy = Function.prototype, whenFalsy = Function.prototype) {
1475
1475
  return condition ? whenTruthy(this) : whenFalsy(this), this;
1476
1476
  }
1477
- }), childMaps = [
1477
+ });
1478
+ function cloneValue(value, context) {
1479
+ if (null === value || 'object' != typeof value) return value;
1480
+ let seen = context.seen ??= new WeakMap();
1481
+ if (seen.has(value)) return seen.get(value);
1482
+ if (value instanceof RegExp) {
1483
+ let cloned = new RegExp(value.source, value.flags);
1484
+ return cloned.lastIndex = value.lastIndex, seen.set(value, cloned), cloned;
1485
+ }
1486
+ let prototype = Object.getPrototypeOf(value);
1487
+ if (!Array.isArray(value) && prototype !== Object.prototype && null !== prototype) return value;
1488
+ let cloned = Array.isArray(value) ? Array(value.length) : Object.create(prototype);
1489
+ for (let key of (seen.set(value, cloned), Object.keys(value))){
1490
+ let clonedValue = cloneValue(value[key], context);
1491
+ '__proto__' === key ? Object.defineProperty(cloned, key, {
1492
+ value: clonedValue,
1493
+ enumerable: !0,
1494
+ configurable: !0,
1495
+ writable: !0
1496
+ }) : cloned[key] = clonedValue;
1497
+ }
1498
+ return cloned;
1499
+ }
1500
+ function cloneMap(source, context, cloned = new Map()) {
1501
+ for (let [key, value] of (cloned.clear(), source))cloned.set(key, cloneValue(value, context));
1502
+ return cloned;
1503
+ }
1504
+ function cloneSet(source, context, cloned = new Set()) {
1505
+ for (let value of (cloned.clear(), source))cloned.add(cloneValue(value, context));
1506
+ return cloned;
1507
+ }
1508
+ let childMaps = [
1478
1509
  'alias',
1479
1510
  'fallback',
1480
1511
  'byDependency',
@@ -1491,7 +1522,8 @@ let ChainedMap = createMap(createChainable(Object)), ChainedValueMap = (superCla
1491
1522
  'restrictions',
1492
1523
  'roots',
1493
1524
  'modules'
1494
- ], Resolve = class extends ChainedMap {
1525
+ ];
1526
+ class Resolve extends ChainedMap {
1495
1527
  constructor(parent){
1496
1528
  super(parent), childMaps.forEach((key)=>{
1497
1529
  this[key] = new ChainedMap(this);
@@ -1530,7 +1562,14 @@ let ChainedMap = createMap(createChainable(Object)), ChainedValueMap = (superCla
1530
1562
  ...omissions
1531
1563
  ]);
1532
1564
  }
1533
- }, ResolveLoader = class extends Resolve {
1565
+ }
1566
+ function cloneResolve(source, parent, context) {
1567
+ let cloned = new Resolve(parent);
1568
+ for (let key of (cloneMap(source.store, context, cloned.store), childMaps))cloneMap(source[key].store, context, cloned[key].store);
1569
+ for (let key of childSets)cloneSet(source[key].store, context, cloned[key].store);
1570
+ return cloned;
1571
+ }
1572
+ let ResolveLoader = class extends Resolve {
1534
1573
  constructor(parent){
1535
1574
  super(parent), this.modules = new ChainedSet(this), this.moduleExtensions = new ChainedSet(this), this.packageMains = new ChainedSet(this);
1536
1575
  }
@@ -1710,6 +1749,9 @@ let ChainedMap = createMap(createChainable(Object)), ChainedValueMap = (superCla
1710
1749
  tap(f) {
1711
1750
  return this.options(f(this.get('options'))), this;
1712
1751
  }
1752
+ cloneFrom(source) {
1753
+ return source === this || (this.store = cloneMap(source.store, {})), this;
1754
+ }
1713
1755
  merge(obj, omit = []) {
1714
1756
  return !omit.includes('loader') && 'loader' in obj && this.loader(obj.loader), !omit.includes('options') && 'options' in obj && this.options(cjs(this.store.get('options') || {}, obj.options)), super.merge(obj, [
1715
1757
  ...omit,
@@ -1786,6 +1828,26 @@ let Rule = Orderable(class extends ChainedMap {
1786
1828
  post() {
1787
1829
  return this.enforce('post');
1788
1830
  }
1831
+ cloneFrom(source) {
1832
+ return source === this ? this : this.#cloneFrom(source, {});
1833
+ }
1834
+ #cloneFrom(source, context) {
1835
+ let children = {};
1836
+ for (let key of [
1837
+ 'uses',
1838
+ 'rules',
1839
+ 'oneOfs'
1840
+ ]){
1841
+ let entries = new Map();
1842
+ for (let [name, child] of source[key].store){
1843
+ let cloned;
1844
+ 'uses' === key ? (cloned = new Use(this, name), cloneMap(child.store, context, cloned.store)) : (cloned = new Rule(this, name, 'rules' === key ? 'rule' : 'oneOf')).#cloneFrom(child, context), cloned.__before = child.__before, cloned.__after = child.__after, entries.set(name, cloned);
1845
+ }
1846
+ children[key] = entries;
1847
+ }
1848
+ let resolve = source.#resolve ? cloneResolve(source.#resolve, this, context) : void 0;
1849
+ return cloneMap(source.store, context, this.store), cloneSet(source.include.store, context, this.include.store), cloneSet(source.exclude.store, context, this.exclude.store), this.uses.store = children.uses, this.rules.store = children.rules, this.oneOfs.store = children.oneOfs, this.#resolve = resolve, this;
1850
+ }
1789
1851
  toConfig() {
1790
1852
  let config = this.clean(Object.assign(this.entries() || {}, {
1791
1853
  include: this.include.values(),
@@ -2179,7 +2241,7 @@ function formatStatsError(stats, root, level = 'error', logger) {
2179
2241
  let innerError = '-- inner error --';
2180
2242
  !verbose && message.includes(innerError) && (message = message.split(innerError)[0]);
2181
2243
  let lines = (message = ((message)=>{
2182
- if (!message.includes('produce different content for the same output file') && !message.includes('Multiple assets emit different content to the same filename')) return message;
2244
+ if (!message.includes('produce different content for the same output file')) return message;
2183
2245
  let extraMessage = `You may need to adjust ${color.yellow('output.filename')} configuration to prevent name conflicts. (See ${color.yellow('https://rsbuild.rs/config/output/filename')})`;
2184
2246
  return `${message}\n${extraMessage}`;
2185
2247
  })(message = ((message)=>{
@@ -3303,7 +3365,7 @@ async function createContext(options, userConfig, logger, loadConfigResult) {
3303
3365
  return config;
3304
3366
  })(rootPath, userConfig), cachePath = join(rootPath, 'node_modules', '.cache'), specifiedEnvironments = options.environment && options.environment.length > 0 ? options.environment : void 0, hooks = initHooks();
3305
3367
  return {
3306
- version: "2.3.4",
3368
+ version: "2.3.5",
3307
3369
  rootPath,
3308
3370
  configFile: loadConfigResult?.filePath ?? userConfig._privateMeta?.configFilePath,
3309
3371
  configFileDependencies: loadConfigResult?.dependencies ?? userConfig._privateMeta?.configFileDependencies ?? [],
@@ -6359,7 +6421,6 @@ function getSplitChunksByPreset(config, preset) {
6359
6421
  throw Error(`[rsbuild] Unknown splitChunks preset: ${String(preset)}`);
6360
6422
  }
6361
6423
  }
6362
- let builtinSwcLoaderName = 'builtin:swc-loader';
6363
6424
  function applyScriptCondition({ rule, isDev, config, rsbuildTarget }) {
6364
6425
  for (let condition of (rule.include.add({
6365
6426
  not: NODE_MODULES_REGEX
@@ -6761,16 +6822,20 @@ function setupMemoryFileSystemCleanup(fileSystem, compilers) {
6761
6822
  if (compilers.some((compiler)=>compiler.options.output.clean)) return;
6762
6823
  let lastSeenByCompiler = compilers.map(()=>new Map());
6763
6824
  for (let [index, compiler] of compilers.entries()){
6764
- let lastHash, lastSeen = lastSeenByCompiler[index], generation = 0;
6825
+ let lastHash, lastSeen = lastSeenByCompiler[index], expiresAt = new Map(), generation = 0;
6765
6826
  compiler.hooks.afterEmit.tap('rsbuild:clean-memory-filesystem', (compilation)=>{
6766
6827
  if (compilation.errors.length) return;
6767
- compilation.hash !== lastHash && (generation++, lastHash = compilation.hash);
6828
+ let now = performance.now();
6829
+ for (let [retiredGeneration, deadline] of (compilation.hash !== lastHash && (generation > 0 && expiresAt.set(generation, now + 30000), generation++, lastHash = compilation.hash), expiresAt)){
6830
+ if (deadline > now) break;
6831
+ expiresAt.delete(retiredGeneration);
6832
+ }
6768
6833
  let outputPath = compilation.getPath(compiler.outputPath);
6769
6834
  for (let name of getAssetNames(compilation)){
6770
6835
  let queryIndex = name.indexOf('?'), filename = -1 === queryIndex ? name : name.slice(0, queryIndex), filePath = join(outputPath, filename);
6771
6836
  lastSeen.set(filePath, generation);
6772
6837
  }
6773
- for (let [filePath, seen] of lastSeen)if (!(seen >= generation - 1) && (lastSeen.delete(filePath), !lastSeenByCompiler.some((assets)=>assets.has(filePath)))) try {
6838
+ for (let [filePath, seen] of lastSeen)if (!(seen >= generation - 1 || expiresAt.has(seen)) && (lastSeen.delete(filePath), !lastSeenByCompiler.some((assets)=>assets.has(filePath)))) try {
6774
6839
  fileSystem.unlinkSync(filePath);
6775
6840
  } catch (error) {
6776
6841
  if ('ENOENT' !== error.code) throw error;
@@ -7517,7 +7582,15 @@ let createDeferred = ()=>{
7517
7582
  return deferred.promise = new Promise((resolve)=>{
7518
7583
  deferred.resolve = resolve;
7519
7584
  }), deferred;
7520
- }, ENCODING_REGEX = /\bgzip\b/, CONTENT_TYPE_REGEX = /text|javascript|\/json|xml/i;
7585
+ }, ENCODING_REGEX = /\bgzip\b/, TEXT_LIKE_MIME_TYPE = /text|javascript|\/json|xml|\+(?:json|yaml)$/, COMPRESSIBLE_ASSET_TYPES = new Set([
7586
+ 'application/toml',
7587
+ 'application/wasm',
7588
+ 'application/yaml',
7589
+ 'font/collection',
7590
+ 'font/otf',
7591
+ 'font/ttf',
7592
+ 'image/bmp'
7593
+ ]);
7521
7594
  function gzipMiddleware_gzipMiddleware({ filter, level = node_zlib.constants.Z_BEST_SPEED } = {}) {
7522
7595
  return function gzipMiddleware(req, res, next) {
7523
7596
  let gzip, writeHeadStatus, writeHeadMessage;
@@ -7531,12 +7604,13 @@ function gzipMiddleware_gzipMiddleware({ filter, level = node_zlib.constants.Z_B
7531
7604
  let start = ()=>{
7532
7605
  if (started) return;
7533
7606
  if (started = !0, ((res)=>{
7607
+ var contentType;
7534
7608
  let index;
7535
7609
  if (res.getHeader('Content-Encoding')) return !1;
7536
- let contentType = res.getHeader('Content-Type');
7537
- if (!contentType) return !1;
7538
- let contentTypeValue = String(contentType);
7539
- if (!CONTENT_TYPE_REGEX.test(contentTypeValue) || 'text/event-stream' === (-1 === (index = contentTypeValue.indexOf(';')) ? contentTypeValue : contentTypeValue.slice(0, index)).trim().toLowerCase()) return !1;
7610
+ let contentType1 = res.getHeader('Content-Type');
7611
+ if (!contentType1) return !1;
7612
+ let mimeType = (-1 === (index = (contentType = String(contentType1)).indexOf(';')) ? contentType : contentType.slice(0, index)).trim().toLowerCase();
7613
+ if ('text/event-stream' === mimeType || !TEXT_LIKE_MIME_TYPE.test(mimeType) && !COMPRESSIBLE_ASSET_TYPES.has(mimeType)) return !1;
7540
7614
  let size = res.getHeader('Content-Length');
7541
7615
  return void 0 === size || Number(size) > 1024;
7542
7616
  })(res)) {
@@ -8764,7 +8838,7 @@ function applyDefaultPlugins(pluginManager, context) {
8764
8838
  ...chain.get('experiments'),
8765
8839
  newCache: !0
8766
8840
  }), cacheEnabled = !0;
8767
- let { context } = api, cacheConfig = 'boolean' == typeof buildCache ? {} : buildCache, cacheDirectory = getCacheDirectory(cacheConfig, context), buildDependencies = await getBuildDependencies(context, environment, cacheConfig.buildDependencies), useDigest = Array.isArray(cacheConfig.cacheDigest) && cacheConfig.cacheDigest.length, cacheVersion = `rsbuild-2.3.4-${environment.name}-${env}`;
8841
+ let { context } = api, cacheConfig = 'boolean' == typeof buildCache ? {} : buildCache, cacheDirectory = getCacheDirectory(cacheConfig, context), buildDependencies = await getBuildDependencies(context, environment, cacheConfig.buildDependencies), useDigest = Array.isArray(cacheConfig.cacheDigest) && cacheConfig.cacheDigest.length, cacheVersion = `rsbuild-2.3.5-${environment.name}-${env}`;
8768
8842
  chain.cache({
8769
8843
  type: 'persistent',
8770
8844
  version: useDigest ? `${cacheVersion}-${await helpers_hash(JSON.stringify(cacheConfig.cacheDigest))}` : cacheVersion,
@@ -9585,7 +9659,7 @@ try {
9585
9659
  config: config.tools.swc,
9586
9660
  mergeFn: cjs_0_default()
9587
9661
  });
9588
- mergedConfig.jsc?.target !== void 0 && mergedConfig.env?.targets !== void 0 && 1 === Object.keys(mergedConfig.env).length && delete mergedConfig.env, mainRule.use(CHAIN_ID.USE.SWC).loader(builtinSwcLoaderName).options(mergedConfig), dataUriRule.resolve.set('fullySpecified', !1).end().use(CHAIN_ID.USE.SWC).loader(builtinSwcLoaderName).options(cloneDeep(mergedConfig));
9662
+ mergedConfig.jsc?.target !== void 0 && mergedConfig.env?.targets !== void 0 && 1 === Object.keys(mergedConfig.env).length && delete mergedConfig.env, mainRule.use(CHAIN_ID.USE.SWC).loader('builtin:swc-loader').options(mergedConfig), dataUriRule.resolve.set('fullySpecified', !1).end().use(CHAIN_ID.USE.SWC).cloneFrom(mainRule.use(CHAIN_ID.USE.SWC));
9589
9663
  }
9590
9664
  });
9591
9665
  }
@@ -10517,7 +10591,7 @@ let applyServerOptions = (command)=>{
10517
10591
  };
10518
10592
  function setupCommands(argv) {
10519
10593
  let cli = ((name = "")=>new CAC(name))('rsbuild');
10520
- cli.version("2.3.4"), 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)', {
10594
+ cli.version("2.3.5"), 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)', {
10521
10595
  default: 'auto'
10522
10596
  }).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', {
10523
10597
  type: [
@@ -10582,7 +10656,7 @@ function setupCommands(argv) {
10582
10656
  }
10583
10657
  function showGreeting() {
10584
10658
  let { npm_execpath, npm_lifecycle_event, NODE_RUN_SCRIPT_NAME } = process.env, isBun = npm_execpath?.includes('.bun');
10585
- src_logger.greet(`${'npx' === npm_lifecycle_event || isBun || NODE_RUN_SCRIPT_NAME ? '\n' : ''}Rsbuild v2.3.4\n`);
10659
+ src_logger.greet(`${'npx' === npm_lifecycle_event || isBun || NODE_RUN_SCRIPT_NAME ? '\n' : ''}Rsbuild v2.3.5\n`);
10586
10660
  }
10587
10661
  function setupLogLevel(argv) {
10588
10662
  if (argv.length <= 3) return;
@@ -10604,5 +10678,5 @@ function runCLI({ argv = process.argv } = {}) {
10604
10678
  src_logger.error('Failed to start Rsbuild CLI.'), src_logger.error(err), process.exit(1);
10605
10679
  }
10606
10680
  }
10607
- let src_version = "2.3.4";
10681
+ let src_version = "2.3.5";
10608
10682
  export { 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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/core",
3
- "version": "2.3.4",
3
+ "version": "2.3.5",
4
4
  "description": "The Rspack-based build tool.",
5
5
  "homepage": "https://rsbuild.rs",
6
6
  "bugs": {
@@ -71,7 +71,7 @@
71
71
  "range-parser": "^2.0.0",
72
72
  "reduce-configs": "^2.0.1",
73
73
  "rslog": "^2.3.0",
74
- "rspack-chain": "^2.3.3",
74
+ "rspack-chain": "^2.4.0",
75
75
  "rspack-manifest-plugin": "5.2.2",
76
76
  "rspack-merge": "1.0.1",
77
77
  "sirv": "^3.0.2",