@rsbuild/core 2.0.9 → 2.0.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.
@@ -1,8 +1,8 @@
1
1
  (() => {
2
2
  var __webpack_modules__ = {
3
- 99: (module, __unused_webpack_exports, __nccwpck_require__) => {
3
+ 203: (module, __unused_webpack_exports, __nccwpck_require__) => {
4
4
  "use strict";
5
- const { HtmlWebpackChildCompiler } = __nccwpck_require__(515);
5
+ const { HtmlWebpackChildCompiler } = __nccwpck_require__(288);
6
6
  const compilerMap = new WeakMap();
7
7
  class CachedChildCompilation {
8
8
  constructor(compiler) {
@@ -311,7 +311,7 @@
311
311
  }
312
312
  module.exports = { CachedChildCompilation };
313
313
  },
314
- 515: (module) => {
314
+ 288: (module) => {
315
315
  "use strict";
316
316
  class HtmlWebpackChildCompiler {
317
317
  constructor(templates) {
@@ -480,7 +480,7 @@
480
480
  }
481
481
  module.exports = { HtmlWebpackChildCompiler };
482
482
  },
483
- 120: (module) => {
483
+ 880: (module) => {
484
484
  "use strict";
485
485
  module.exports = {};
486
486
  module.exports.none = (chunks) => chunks;
@@ -499,7 +499,7 @@
499
499
  };
500
500
  module.exports.auto = module.exports.none;
501
501
  },
502
- 783: (module) => {
502
+ 447: (module) => {
503
503
  "use strict";
504
504
  module.exports = function (err) {
505
505
  return {
@@ -523,7 +523,7 @@
523
523
  };
524
524
  };
525
525
  },
526
- 310: (module, __unused_webpack_exports, __nccwpck_require__) => {
526
+ 334: (module, __unused_webpack_exports, __nccwpck_require__) => {
527
527
  "use strict";
528
528
  const { AsyncSeriesWaterfallHook } = __nccwpck_require__(159);
529
529
  const htmlWebpackPluginHooksMap = new WeakMap();
@@ -549,7 +549,7 @@
549
549
  }
550
550
  module.exports = { getHtmlRspackPluginHooks };
551
551
  },
552
- 75: (module) => {
552
+ 619: (module) => {
553
553
  const voidTags = [
554
554
  "area",
555
555
  "base",
@@ -617,19 +617,19 @@
617
617
  htmlTagObjectToString,
618
618
  };
619
619
  },
620
- 954: (module, __unused_webpack_exports, __nccwpck_require__) => {
620
+ 914: (module, __unused_webpack_exports, __nccwpck_require__) => {
621
621
  "use strict";
622
622
  const promisify = __nccwpck_require__(23).promisify;
623
623
  const vm = __nccwpck_require__(154);
624
624
  const fs = __nccwpck_require__(896);
625
625
  const path = __nccwpck_require__(928);
626
- const { CachedChildCompilation } = __nccwpck_require__(99);
626
+ const { CachedChildCompilation } = __nccwpck_require__(203);
627
627
  const { createHtmlTagObject, htmlTagObjectToString, HtmlTagArray } =
628
- __nccwpck_require__(75);
629
- const prettyError = __nccwpck_require__(783);
630
- const chunkSorter = __nccwpck_require__(120);
628
+ __nccwpck_require__(619);
629
+ const prettyError = __nccwpck_require__(447);
630
+ const chunkSorter = __nccwpck_require__(880);
631
631
  const getHtmlRspackPluginHooks =
632
- __nccwpck_require__(310).getHtmlRspackPluginHooks;
632
+ __nccwpck_require__(334).getHtmlRspackPluginHooks;
633
633
  const WITH_PLACEHOLDER = "function __with_placeholder__";
634
634
  class HtmlRspackPlugin {
635
635
  constructor(userOptions = {}) {
@@ -2398,6 +2398,6 @@
2398
2398
  }
2399
2399
  if (typeof __nccwpck_require__ !== "undefined")
2400
2400
  __nccwpck_require__.ab = __dirname + "/";
2401
- var __webpack_exports__ = __nccwpck_require__(954);
2401
+ var __webpack_exports__ = __nccwpck_require__(914);
2402
2402
  module.exports = __webpack_exports__;
2403
2403
  })();
@@ -1 +1 @@
1
- {"name":"html-rspack-plugin","author":"Jan Nicklas <j.nicklas@me.com> (https://github.com/jantimon)","version":"6.1.8","funding":{"type":"opencollective","url":"https://opencollective.com/html-webpack-plugin"},"license":"MIT","types":"index.d.ts","type":"commonjs"}
1
+ {"name":"html-rspack-plugin","author":"Jan Nicklas <j.nicklas@me.com> (https://github.com/jantimon)","version":"6.1.9","funding":{"type":"opencollective","url":"https://opencollective.com/html-webpack-plugin"},"license":"MIT","types":"index.d.ts","type":"commonjs"}
@@ -1,15 +1,15 @@
1
1
  (() => {
2
2
  "use strict";
3
3
  var __webpack_modules__ = {
4
- 218: (module, __unused_webpack_exports, __nccwpck_require__) => {
5
- module.exports = __nccwpck_require__(448)["default"];
4
+ 501: (module, __unused_webpack_exports, __nccwpck_require__) => {
5
+ module.exports = __nccwpck_require__(495)["default"];
6
6
  },
7
- 448: (__unused_webpack_module, exports, __nccwpck_require__) => {
7
+ 495: (__unused_webpack_module, exports, __nccwpck_require__) => {
8
8
  var __webpack_unused_export__;
9
9
  __webpack_unused_export__ = { value: true };
10
10
  exports["default"] = loader;
11
11
  var _nodePath = _interopRequireDefault(__nccwpck_require__(760));
12
- var _utils = __nccwpck_require__(233);
12
+ var _utils = __nccwpck_require__(906);
13
13
  function _interopRequireDefault(e) {
14
14
  return e && e.__esModule ? e : { default: e };
15
15
  }
@@ -179,7 +179,7 @@
179
179
  callback(null, result.css, map, { ast });
180
180
  }
181
181
  },
182
- 233: (module, exports, __nccwpck_require__) => {
182
+ 906: (module, exports, __nccwpck_require__) => {
183
183
  module = __nccwpck_require__.nmd(module);
184
184
  Object.defineProperty(exports, "__esModule", { value: true });
185
185
  exports.exec = exec;
@@ -716,6 +716,6 @@
716
716
  })();
717
717
  if (typeof __nccwpck_require__ !== "undefined")
718
718
  __nccwpck_require__.ab = __dirname + "/";
719
- var __webpack_exports__ = __nccwpck_require__(218);
719
+ var __webpack_exports__ = __nccwpck_require__(501);
720
720
  module.exports = __webpack_exports__;
721
721
  })();
@@ -16,7 +16,7 @@ declare const color: {
16
16
  strikethrough: ColorFn;
17
17
  };
18
18
 
19
- declare let LOG_TYPES: {
19
+ declare const LOG_TYPES: {
20
20
  error: {
21
21
  label: string;
22
22
  level: "error";
@@ -90,9 +90,9 @@ type Logger = Record<LogMethods, LogFunction> & {
90
90
  override: (customLogger: Partial<Record<LogMethods, LogFunction>>) => void;
91
91
  };
92
92
 
93
- declare let createLogger: (options?: Options) => Logger;
93
+ declare const createLogger: (options?: Options) => Logger;
94
94
 
95
- declare let logger: Logger;
95
+ declare const logger: Logger;
96
96
 
97
97
  export { color, createLogger, logger };
98
98
  export type { LogFunction, LogLevel, LogMessage, LogType, Logger, Options };
@@ -1 +1 @@
1
- {"name":"rslog","version":"2.1.1","license":"MIT","types":"index.d.ts","type":"module"}
1
+ {"name":"rslog","version":"2.1.2","license":"MIT","types":"index.d.ts","type":"module"}
@@ -1 +1 @@
1
- {"name":"rspack-chain","version":"2.0.1","license":"MIT","types":"types/index.d.ts","type":"module"}
1
+ {"name":"rspack-chain","version":"2.0.2","license":"MIT","types":"types/index.d.ts","type":"module"}
package/dist/756.js CHANGED
@@ -755,8 +755,8 @@ let supportsColor = {
755
755
  }
756
756
  }, normalizeErrorMessage = (err)=>{
757
757
  if (err.stack) {
758
- let [name, ...rest] = err.stack.split('\n');
759
- return name.startsWith('Error: ') && (name = name.slice(7)), `${name}\n${color.gray(rest.join('\n'))}`;
758
+ let [rawName, ...rest] = err.stack.split('\n'), name = rawName.startsWith('Error: ') ? rawName.slice(7) : rawName;
759
+ return `${name}\n${color.gray(rest.join('\n'))}`;
760
760
  }
761
761
  return err.message;
762
762
  }, createLogger = (options = {})=>{
@@ -1477,14 +1477,12 @@ __nested_rspack_require_65__.m = __webpack_modules__, __nested_rspack_require_65
1477
1477
  }
1478
1478
  },
1479
1479
  "./node_modules/.pnpm/javascript-stringify@2.1.0/node_modules/javascript-stringify/dist/index.js" (__unused_rspack_module, exports, __nested_rspack_require_14714_14733__) {
1480
- Object.defineProperty(exports, "__esModule", {
1481
- value: !0
1482
- }), exports.stringify = void 0;
1480
+ exports.A = void 0;
1483
1481
  let stringify_1 = __nested_rspack_require_14714_14733__("./node_modules/.pnpm/javascript-stringify@2.1.0/node_modules/javascript-stringify/dist/stringify.js"), quote_1 = __nested_rspack_require_14714_14733__("./node_modules/.pnpm/javascript-stringify@2.1.0/node_modules/javascript-stringify/dist/quote.js"), ROOT_SENTINEL = Symbol("root");
1484
1482
  function replacerToString(replacer) {
1485
1483
  return replacer ? (value, space, next, key)=>replacer(value, space, (value)=>stringify_1.toString(value, space, next, key), key) : stringify_1.toString;
1486
1484
  }
1487
- exports.stringify = function stringify(value, replacer, indent, options = {}) {
1485
+ exports.A = function stringify(value, replacer, indent, options = {}) {
1488
1486
  let space = "string" == typeof indent ? indent : " ".repeat(indent || 0), path = [], stack = new Set(), tracking = new Map(), unpack = new Map(), valueCount = 0, { maxDepth = 100, references = !1, skipUndefinedProperties = !1, maxValues = 100000 } = options, valueToString = replacerToString(replacer), onNext = (value, key)=>{
1489
1487
  if (++valueCount > maxValues || skipUndefinedProperties && void 0 === value || path.length > maxDepth) return;
1490
1488
  if (void 0 === key) return valueToString(value, space, onNext, key);
@@ -1514,9 +1512,9 @@ __nested_rspack_require_65__.m = __webpack_modules__, __nested_rspack_require_65
1514
1512
  return result;
1515
1513
  };
1516
1514
  },
1517
- "./node_modules/.pnpm/javascript-stringify@2.1.0/node_modules/javascript-stringify/dist/object.js" (__unused_rspack_module, exports, __nested_rspack_require_18136_18155__) {
1515
+ "./node_modules/.pnpm/javascript-stringify@2.1.0/node_modules/javascript-stringify/dist/object.js" (__unused_rspack_module, exports, __nested_rspack_require_18029_18048__) {
1518
1516
  exports.objectToString = void 0;
1519
- let quote_1 = __nested_rspack_require_18136_18155__("./node_modules/.pnpm/javascript-stringify@2.1.0/node_modules/javascript-stringify/dist/quote.js"), function_1 = __nested_rspack_require_18136_18155__("./node_modules/.pnpm/javascript-stringify@2.1.0/node_modules/javascript-stringify/dist/function.js"), array_1 = __nested_rspack_require_18136_18155__("./node_modules/.pnpm/javascript-stringify@2.1.0/node_modules/javascript-stringify/dist/array.js");
1517
+ let quote_1 = __nested_rspack_require_18029_18048__("./node_modules/.pnpm/javascript-stringify@2.1.0/node_modules/javascript-stringify/dist/quote.js"), function_1 = __nested_rspack_require_18029_18048__("./node_modules/.pnpm/javascript-stringify@2.1.0/node_modules/javascript-stringify/dist/function.js"), array_1 = __nested_rspack_require_18029_18048__("./node_modules/.pnpm/javascript-stringify@2.1.0/node_modules/javascript-stringify/dist/array.js");
1520
1518
  exports.objectToString = (value, space, next, key)=>{
1521
1519
  if ("function" == typeof Buffer && Buffer.isBuffer(value)) return `Buffer.from(${next(value.toString("base64"))}, 'base64')`;
1522
1520
  if ("object" == typeof global && value === global) return globalToString(value, space, next);
@@ -1600,9 +1598,9 @@ __nested_rspack_require_65__.m = __webpack_modules__, __nested_rspack_require_65
1600
1598
  return result;
1601
1599
  };
1602
1600
  },
1603
- "./node_modules/.pnpm/javascript-stringify@2.1.0/node_modules/javascript-stringify/dist/stringify.js" (__unused_rspack_module, exports, __nested_rspack_require_23555_23574__) {
1601
+ "./node_modules/.pnpm/javascript-stringify@2.1.0/node_modules/javascript-stringify/dist/stringify.js" (__unused_rspack_module, exports, __nested_rspack_require_23448_23467__) {
1604
1602
  exports.toString = void 0;
1605
- let quote_1 = __nested_rspack_require_23555_23574__("./node_modules/.pnpm/javascript-stringify@2.1.0/node_modules/javascript-stringify/dist/quote.js"), object_1 = __nested_rspack_require_23555_23574__("./node_modules/.pnpm/javascript-stringify@2.1.0/node_modules/javascript-stringify/dist/object.js"), function_1 = __nested_rspack_require_23555_23574__("./node_modules/.pnpm/javascript-stringify@2.1.0/node_modules/javascript-stringify/dist/function.js"), PRIMITIVE_TYPES = {
1603
+ let quote_1 = __nested_rspack_require_23448_23467__("./node_modules/.pnpm/javascript-stringify@2.1.0/node_modules/javascript-stringify/dist/quote.js"), object_1 = __nested_rspack_require_23448_23467__("./node_modules/.pnpm/javascript-stringify@2.1.0/node_modules/javascript-stringify/dist/object.js"), function_1 = __nested_rspack_require_23448_23467__("./node_modules/.pnpm/javascript-stringify@2.1.0/node_modules/javascript-stringify/dist/function.js"), PRIMITIVE_TYPES = {
1606
1604
  string: quote_1.quoteString,
1607
1605
  number: (value)=>Object.is(value, -0) ? "-0" : String(value),
1608
1606
  boolean: String,
@@ -2193,7 +2191,7 @@ class RspackChain extends ChainedMap {
2193
2191
  ]);
2194
2192
  }
2195
2193
  static toString(config, { verbose = !1, configPrefix = 'config' } = {}) {
2196
- return (0, dist.stringify)(config, (value, indent, stringify)=>{
2194
+ return (0, dist.A)(config, (value, indent, stringify)=>{
2197
2195
  if (value && value.__pluginName) {
2198
2196
  let prefix = `/* ${configPrefix}.${value.__pluginType}('${value.__pluginName}') */\n`, constructorExpression = value.__pluginPath ? `(require(${stringify(value.__pluginPath)}))` : value.__pluginConstructorName;
2199
2197
  if (constructorExpression) {
@@ -3086,10 +3084,10 @@ function exitHook(onExit) {
3086
3084
  exitHook_callbacks.delete(onExit);
3087
3085
  };
3088
3086
  }
3089
- let addTrailingSlash = (s)=>s.endsWith('/') ? s : `${s}/`, isURL = (str)=>str.startsWith('http') || str.startsWith('//'), urlJoin = (base, path)=>{
3087
+ let removeTailingSlash = (s)=>s.endsWith('/') ? s.replace(/\/+$/, '') : s, addTrailingSlash = (s)=>s.endsWith('/') ? s : `${s}/`, isURL = (str)=>str.startsWith('http') || str.startsWith('//'), urlJoin = (base, path)=>{
3090
3088
  let [urlProtocol, baseUrl] = base.split('://');
3091
3089
  return `${urlProtocol}://${posix.join(baseUrl, path)}`;
3092
- }, ensureAssetPrefix = (url, assetPrefix = "/")=>url.startsWith('//') || external_node_url_URL.canParse(url) || 'auto' === assetPrefix || 'function' == typeof assetPrefix ? url : assetPrefix.startsWith('http') ? urlJoin(assetPrefix, url) : assetPrefix.startsWith('//') ? urlJoin(`https:${assetPrefix}`, url).replace('https:', '') : posix.join(assetPrefix, url), formatPublicPath = (publicPath, withSlash = !0)=>'auto' === publicPath || '' === publicPath ? publicPath : withSlash ? addTrailingSlash(publicPath) : publicPath.replace(/\/+$/, ''), getPublicPathFromChain = (chain, withSlash = !0)=>{
3090
+ }, ensureAssetPrefix = (url, assetPrefix = "/")=>url.startsWith('//') || external_node_url_URL.canParse(url) || 'auto' === assetPrefix || 'function' == typeof assetPrefix ? url : assetPrefix.startsWith('http') ? urlJoin(assetPrefix, url) : assetPrefix.startsWith('//') ? urlJoin(`https:${assetPrefix}`, url).replace('https:', '') : posix.join(assetPrefix, url), formatPublicPath = (publicPath, withSlash = !0)=>'auto' === publicPath || '' === publicPath ? publicPath : withSlash ? addTrailingSlash(publicPath) : removeTailingSlash(publicPath), getPublicPathFromChain = (chain, withSlash = !0)=>{
3093
3091
  let publicPath = chain.output.get('publicPath');
3094
3092
  return 'string' == typeof publicPath ? formatPublicPath(publicPath, withSlash) : formatPublicPath("/", withSlash);
3095
3093
  };
@@ -3485,7 +3483,7 @@ function createPublicContext(context) {
3485
3483
  async function createContext(options, userConfig, logger) {
3486
3484
  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;
3487
3485
  return {
3488
- version: "2.0.9",
3486
+ version: "2.0.11",
3489
3487
  rootPath,
3490
3488
  distPath: '',
3491
3489
  cachePath,
@@ -5173,9 +5171,14 @@ let normalizeUrl = (url)=>url.replace(/([^:]\/)\/+/g, '$1'), formatPrefix = (inp
5173
5171
  if (prefix?.startsWith('./') && (prefix = prefix.replace('./', '')), !prefix) return '/';
5174
5172
  let hasLeadingSlash = prefix.startsWith('/'), hasTailSlash = prefix.endsWith('/');
5175
5173
  return `${hasLeadingSlash ? '' : '/'}${prefix}${hasTailSlash ? '' : '/'}`;
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;
5174
+ }, joinUrlPath = (basePath, pathname)=>'' === basePath ? pathname : '' === pathname ? basePath : addTrailingSlash(basePath) + pathname.replace(/^\/+/, ''), isUrlPathUnderBase = (pathname, base)=>{
5175
+ let basePath = removeTailingSlash(base);
5176
+ return '' === basePath || pathname === basePath || pathname.startsWith(`${basePath}/`);
5177
+ }, removeBasePath = (url, base)=>{
5178
+ let basePath = removeTailingSlash(base);
5179
+ if ('' === basePath || !url.startsWith(basePath)) return url;
5180
+ let nextChar = url[basePath.length];
5181
+ return void 0 === nextChar ? '/' : '/' === nextChar ? url.slice(basePath.length) : '?' === nextChar || '#' === nextChar ? `/${url.slice(basePath.length)}` : url;
5179
5182
  }, getRoutes = (context)=>{
5180
5183
  let environmentWithHtml = context.environmentList.filter((item)=>Object.keys(item.htmlPaths).length > 0);
5181
5184
  if (0 === environmentWithHtml.length) return [];
@@ -5939,7 +5942,7 @@ async function getFileFromUrl(url, outputFileSystem, context) {
5939
5942
  }), { environmentList, publicPathnames } = context, distPaths = environmentList.map((env)=>env.distPath), possibleFilenames = new Set();
5940
5943
  for (let [index, distPath] of distPaths.entries()){
5941
5944
  let prefix = publicPathnames[index];
5942
- prefix && '/' !== prefix && pathname.startsWith(prefix) && possibleFilenames.add(node_path.join(distPath, pathname.slice(prefix.length)));
5945
+ prefix && '/' !== prefix && isUrlPathUnderBase(pathname, prefix) && possibleFilenames.add(node_path.join(distPath, pathname.slice(prefix.length)));
5943
5946
  }
5944
5947
  for (let distPath of distPaths)possibleFilenames.add(node_path.join(distPath, pathname));
5945
5948
  for (let filename of possibleFilenames){
@@ -5990,13 +5993,13 @@ function getEtag(stat) {
5990
5993
  let mtime = stat.mtime.getTime().toString(16), size = stat.size.toString(16);
5991
5994
  return `W/"${size}-${mtime}"`;
5992
5995
  }
5993
- function createReadStreamOrReadFileSync(filename, outputFileSystem, start, end) {
5996
+ function createReadStreamOrReadFileSync(filename, outputFileSystem, start, end, byteLength) {
5994
5997
  return {
5995
5998
  bufferOrStream: outputFileSystem.createReadStream(filename, {
5996
5999
  start,
5997
6000
  end
5998
6001
  }),
5999
- byteLength: 0 === end ? 0 : end - start + 1
6002
+ byteLength
6000
6003
  };
6001
6004
  }
6002
6005
  async function getContentType(str) {
@@ -6050,7 +6053,7 @@ function sendError(res, code) {
6050
6053
  let byteLength = Buffer.byteLength(document);
6051
6054
  res.setHeader('Content-Length', byteLength), res.end(document);
6052
6055
  }
6053
- function createMiddleware(context, ready, outputFileSystem) {
6056
+ function createAssetsMiddleware(context, ready, outputFileSystem) {
6054
6057
  let { logger } = context;
6055
6058
  return async function assetsMiddleware(req, res, next) {
6056
6059
  async function goNext() {
@@ -6175,7 +6178,7 @@ function createMiddleware(context, ready, outputFileSystem) {
6175
6178
  }
6176
6179
  let [start, end] = calcStartAndEnd(offset, len);
6177
6180
  try {
6178
- ({ bufferOrStream, byteLength } = createReadStreamOrReadFileSync(filename, outputFileSystem, start, end));
6181
+ ({ bufferOrStream, byteLength } = createReadStreamOrReadFileSync(filename, outputFileSystem, start, end, len));
6179
6182
  } catch {
6180
6183
  await goNext();
6181
6184
  return;
@@ -6204,7 +6207,7 @@ function createMiddleware(context, ready, outputFileSystem) {
6204
6207
  }
6205
6208
  async function setupOutputFileSystem(writeToDisk, compilers) {
6206
6209
  if (!0 !== writeToDisk) {
6207
- let { createFsFromVolume, Volume } = await import("./memfs.js").then(__webpack_require__.t.bind(__webpack_require__, "../../node_modules/.pnpm/memfs@4.57.2/node_modules/memfs/lib/index.js", 23)), outputFileSystem = createFsFromVolume(new Volume());
6210
+ let { createFsFromVolume, Volume } = await import("./memfs.js").then(__webpack_require__.t.bind(__webpack_require__, "../../node_modules/.pnpm/memfs@4.57.3/node_modules/memfs/lib/index.js", 23)), outputFileSystem = createFsFromVolume(new Volume());
6208
6211
  for (let compiler of compilers)compiler.outputFileSystem = outputFileSystem;
6209
6212
  }
6210
6213
  let compiler = compilers.find((compiler)=>!!compiler.outputFileSystem);
@@ -6340,7 +6343,7 @@ let assets_middleware_assetsMiddleware = async ({ config, compiler, context, soc
6340
6343
  return name && environments[name] && (writeToDisk = environments[name].config.dev.writeToDisk ?? writeToDisk), 'function' == typeof writeToDisk ? writeToDisk(filePath) : writeToDisk;
6341
6344
  });
6342
6345
  writeToDisk && setupWriteToDisk(compilers, writeToDisk, logger);
6343
- let instance = createMiddleware(context, (callback)=>{
6346
+ let instance = createAssetsMiddleware(context, (callback)=>{
6344
6347
  'done' === context.buildState.status ? callback() : callbacks.push(callback);
6345
6348
  }, await setupOutputFileSystem(writeToDisk, compilers));
6346
6349
  return instance.watch = ()=>{
@@ -6992,21 +6995,38 @@ let faviconFallbackMiddleware = (req, res, next)=>{
6992
6995
  next();
6993
6996
  }, middlewares_isFileExists = async (filePath, outputFileSystem)=>new Promise((resolve)=>{
6994
6997
  outputFileSystem.stat(filePath, (_error, stats)=>{
6995
- resolve(stats?.isFile());
6998
+ resolve(!!stats?.isFile());
6996
6999
  });
6997
- }), maybeHTMLRequest = (req)=>{
7000
+ }), isFileExistsInDistPaths = async (distPaths, filename, outputFileSystem)=>{
7001
+ for (let distPath of distPaths)if (await middlewares_isFileExists(node_path.join(distPath, filename), outputFileSystem)) return !0;
7002
+ return !1;
7003
+ }, maybeHTMLRequest = (req)=>{
6998
7004
  if (!req.url || !req.headers || 'GET' !== req.method && 'HEAD' !== req.method) return !1;
6999
7005
  let { accept } = req.headers;
7000
7006
  return 'string' == typeof accept && (accept.includes('text/html') || accept.includes('*/*'));
7001
- }, postfixRE = /[?#].*$/, getBaseUrlMiddleware = ({ base })=>function baseUrlMiddleware(req, res, next) {
7002
- var pathname;
7003
- let basePath, url = req.url, pathname1 = url.replace(postfixRE, '');
7004
- if (pathname = pathname1, '' === (basePath = base.replace(/\/+$/, '')) || pathname === basePath || pathname.startsWith(`${basePath}/`)) {
7007
+ }, postfixRE = /[?#].*$/, getHtmlCompletionMiddleware = ({ distPaths, assetsMiddleware, outputFileSystem })=>async function htmlCompletionMiddleware(req, res, next) {
7008
+ if (!maybeHTMLRequest(req)) return void next();
7009
+ let pathname = req.url.replace(postfixRE, ''), rewrite = (newUrl)=>{
7010
+ req.url = newUrl, assetsMiddleware(req, res, (...args)=>{
7011
+ next(...args);
7012
+ });
7013
+ };
7014
+ if (pathname.endsWith('/')) {
7015
+ let newUrl = `${pathname}index.html`;
7016
+ if (await isFileExistsInDistPaths(distPaths, newUrl, outputFileSystem)) return void rewrite(newUrl);
7017
+ } else if (!node_path.extname(pathname)) {
7018
+ let newUrl = `${pathname}.html`;
7019
+ if (await isFileExistsInDistPaths(distPaths, newUrl, outputFileSystem)) return void rewrite(newUrl);
7020
+ }
7021
+ next();
7022
+ }, getBaseUrlMiddleware = ({ base })=>function baseUrlMiddleware(req, res, next) {
7023
+ let url = req.url, pathname = url.replace(postfixRE, '');
7024
+ if (isUrlPathUnderBase(pathname, base)) {
7005
7025
  req.url = removeBasePath(url, base), next();
7006
7026
  return;
7007
7027
  }
7008
7028
  let redirectPath = addTrailingSlash(url) !== base ? joinUrlPath(base, url) : base;
7009
- if ('/' === pathname1 || '/index.html' === pathname1) {
7029
+ if ('/' === pathname || '/index.html' === pathname) {
7010
7030
  res.writeHead(302, {
7011
7031
  Location: redirectPath
7012
7032
  }), res.end();
@@ -7021,6 +7041,16 @@ let faviconFallbackMiddleware = (req, res, next)=>{
7021
7041
  res.writeHead(404, {
7022
7042
  'Content-Type': 'text/plain'
7023
7043
  }), res.end(`The server is configured with a base URL of ${base} - did you mean to visit ${redirectPath} instead?`);
7044
+ }, getHtmlFallbackMiddleware = ({ distPaths, assetsMiddleware, outputFileSystem, logger })=>async function htmlFallbackMiddleware(req, res, next) {
7045
+ if (!maybeHTMLRequest(req) || '/favicon.ico' === req.url) return void next();
7046
+ if (await isFileExistsInDistPaths(distPaths, 'index.html', outputFileSystem)) {
7047
+ let newUrl = '/index.html';
7048
+ isVerbose(logger) && logger.debug(` ${req.method} ${req.url} ${color.yellow('fallback to')} ${newUrl}`), req.url = newUrl, assetsMiddleware(req, res, (...args)=>{
7049
+ next(...args);
7050
+ });
7051
+ return;
7052
+ }
7053
+ next();
7024
7054
  };
7025
7055
  function formatProxyOptions(proxyOptions, logger) {
7026
7056
  let logPrefix = color.dim('[http-proxy-middleware]: '), defaultOptions = {
@@ -7086,7 +7116,7 @@ let applyDefaultMiddlewares = async ({ config, buildManager, context, devServer,
7086
7116
  server.base && '/' !== server.base && middlewares.use(getBaseUrlMiddleware({
7087
7117
  base: server.base
7088
7118
  }));
7089
- let { default: launchEditorMiddleware } = await import("./launch-editor-middleware.js").then(__webpack_require__.t.bind(__webpack_require__, "../../node_modules/.pnpm/launch-editor-middleware@2.13.2/node_modules/launch-editor-middleware/index.js", 23));
7119
+ let { default: launchEditorMiddleware } = await import("./launch-editor-middleware.js").then(__webpack_require__.t.bind(__webpack_require__, "../../node_modules/.pnpm/launch-editor-middleware@2.14.0/node_modules/launch-editor-middleware/index.js", 23));
7090
7120
  if (middlewares.use('/__open-in-editor', launchEditorMiddleware()), middlewares.use((({ environments, logger })=>async function viewingServedFilesMiddleware(req, res, next) {
7091
7121
  if ('/rsbuild-dev-server' !== req.url.replace(postfixRE, '')) return void next();
7092
7122
  res.writeHead(200, {
@@ -7150,24 +7180,12 @@ let applyDefaultMiddlewares = async ({ config, buildManager, context, devServer,
7150
7180
  logger
7151
7181
  })), buildManager && (middlewares.use(buildManager.assetsMiddleware), upgradeEvents.push(buildManager.socketServer.upgrade), middlewares.use(function hotUpdateJsonFallbackMiddleware(req, res, next) {
7152
7182
  req.url?.endsWith('.hot-update.json') && 'OPTIONS' !== req.method ? notFoundMiddleware(req, res, next) : next();
7153
- })), buildManager && middlewares.use((({ distPath, buildManager })=>async function htmlCompletionMiddleware(req, res, next) {
7154
- if (!maybeHTMLRequest(req)) return void next();
7155
- let pathname = req.url.replace(postfixRE, ''), rewrite = (newUrl)=>{
7156
- req.url = newUrl, buildManager.assetsMiddleware(req, res, (...args)=>{
7157
- next(...args);
7158
- });
7159
- };
7160
- if (pathname.endsWith('/')) {
7161
- let newUrl = `${pathname}index.html`, filePath = node_path.join(distPath, newUrl);
7162
- if (await middlewares_isFileExists(filePath, buildManager.outputFileSystem)) return void rewrite(newUrl);
7163
- } else if (!node_path.extname(pathname)) {
7164
- let newUrl = `${pathname}.html`, filePath = node_path.join(distPath, newUrl);
7165
- if (await middlewares_isFileExists(filePath, buildManager.outputFileSystem)) return void rewrite(newUrl);
7166
- }
7167
- next();
7168
- })({
7169
- buildManager,
7170
- distPath: context.distPath
7183
+ })), buildManager && middlewares.use(getHtmlCompletionMiddleware({
7184
+ assetsMiddleware: buildManager.assetsMiddleware,
7185
+ distPaths: [
7186
+ context.distPath
7187
+ ],
7188
+ outputFileSystem: buildManager.outputFileSystem
7171
7189
  })), server.publicDir.length) {
7172
7190
  let { default: sirv } = await import("./sirv.js");
7173
7191
  for (let { name } of server.publicDir){
@@ -7181,21 +7199,13 @@ let applyDefaultMiddlewares = async ({ config, buildManager, context, devServer,
7181
7199
  }
7182
7200
  }
7183
7201
  for (let callback of postCallbacks)await callback();
7184
- return server.historyApiFallback && (middlewares.use(historyApiFallback_historyApiFallbackMiddleware(logger, !0 === server.historyApiFallback ? {} : server.historyApiFallback)), buildManager?.assetsMiddleware && middlewares.use(buildManager.assetsMiddleware)), buildManager && server.htmlFallback && middlewares.use((({ distPath, buildManager, logger })=>async function htmlFallbackMiddleware(req, res, next) {
7185
- if (!maybeHTMLRequest(req) || '/favicon.ico' === req.url) return void next();
7186
- let filePath = node_path.join(distPath, 'index.html');
7187
- if (await middlewares_isFileExists(filePath, buildManager.outputFileSystem)) {
7188
- let newUrl = '/index.html';
7189
- isVerbose(logger) && logger.debug(` ${req.method} ${req.url} ${color.yellow('fallback to')} ${newUrl}`), req.url = newUrl, buildManager.assetsMiddleware(req, res, (...args)=>{
7190
- next(...args);
7191
- });
7192
- return;
7193
- }
7194
- next();
7195
- })({
7196
- buildManager,
7197
- distPath: context.distPath,
7198
- logger
7202
+ return server.historyApiFallback && (middlewares.use(historyApiFallback_historyApiFallbackMiddleware(logger, !0 === server.historyApiFallback ? {} : server.historyApiFallback)), buildManager?.assetsMiddleware && middlewares.use(buildManager.assetsMiddleware)), buildManager && server.htmlFallback && middlewares.use(getHtmlFallbackMiddleware({
7203
+ assetsMiddleware: buildManager.assetsMiddleware,
7204
+ distPaths: [
7205
+ context.distPath
7206
+ ],
7207
+ logger,
7208
+ outputFileSystem: buildManager.outputFileSystem
7199
7209
  })), middlewares.use(faviconFallbackMiddleware), {
7200
7210
  onUpgrade: (...args)=>{
7201
7211
  for (let cb of upgradeEvents)cb(...args);
@@ -7503,7 +7513,7 @@ let runner_run = async ({ bundlePath, ...runnerFactoryOptions })=>{
7503
7513
  }
7504
7514
  let { createServer } = await import("node:http");
7505
7515
  return createServer(middlewares);
7506
- };
7516
+ }, getPublicPathname = (publicPath)=>'auto' === publicPath || '' === publicPath ? '' : getPathnameFromUrl(publicPath.endsWith('/') ? publicPath : `${publicPath}/`), getPublicPathnames = (publicPaths, base)=>publicPaths.map(getPublicPathname).map((prefix)=>base && '/' !== base ? removeBasePath(prefix, base) : prefix);
7507
7517
  async function applyServerSetup(setup, context) {
7508
7518
  let postCallbacks = [];
7509
7519
  for (let handler of helpers_castArray(setup || [])){
@@ -7592,10 +7602,9 @@ async function devServer_createDevServer(options, createCompiler, config, { getP
7592
7602
  let startCompile = async ()=>{
7593
7603
  let compiler = await createCompiler();
7594
7604
  if (!compiler) throw Error(`${color.dim('[rsbuild:server]')} Failed to get compiler instance.`);
7595
- let publicPaths = compiler_isMultiCompiler(compiler) ? compiler.compilers.map(getPublicPathFromCompiler) : [
7605
+ context.publicPathnames = getPublicPathnames(compiler_isMultiCompiler(compiler) ? compiler.compilers.map(getPublicPathFromCompiler) : [
7596
7606
  getPublicPathFromCompiler(compiler)
7597
- ], { base } = config.server;
7598
- context.publicPathnames = publicPaths.map(getPathnameFromUrl).map((prefix)=>base && '/' !== base ? removeBasePath(prefix, base) : prefix), compiler?.hooks.watchRun.tap('rsbuild:watchRun', ()=>{
7607
+ ], config.server.base), compiler?.hooks.watchRun.tap('rsbuild:watchRun', ()=>{
7599
7608
  lastStats && (waitLastCompileDoneResolve && (waitLastCompileDoneResolve(), waitLastCompileDoneResolve = null), waitLastCompileDone = new Promise((resolve)=>{
7600
7609
  waitLastCompileDoneResolve = resolve;
7601
7610
  }));
@@ -7750,7 +7759,9 @@ async function devServer_createDevServer(options, createCompiler, config, { getP
7750
7759
  }), state.buildManager?.watch(), logger.debug('create dev server done'), devServer;
7751
7760
  }
7752
7761
  async function startPreviewServer(context, config, { getPortSilently } = {}) {
7753
- let { logger } = context, { connect } = await import("./connect-next.js"), middlewares = connect(), { port, portTip } = await resolvePort(config), serverConfig = config.server, { host, headers, proxy, historyApiFallback, compress, base, cors } = serverConfig, protocol = serverConfig.https ? 'https' : 'http', routes = getRoutes(context), urls = await getAddressUrls({
7762
+ let environmentList, { logger } = context, { connect } = await import("./connect-next.js"), middlewares = connect(), { port, portTip } = await resolvePort(config), serverConfig = config.server, { host, headers, proxy, historyApiFallback, compress, base, cors } = serverConfig, assetPrefixes = context.environmentList.map((environment)=>environment.config.output.assetPrefix);
7763
+ context.publicPathnames = getPublicPathnames(assetPrefixes, base);
7764
+ let protocol = serverConfig.https ? 'https' : 'http', routes = getRoutes(context), urls = await getAddressUrls({
7754
7765
  protocol,
7755
7766
  port,
7756
7767
  host
@@ -7791,21 +7802,14 @@ async function startPreviewServer(context, config, { getPortSilently } = {}) {
7791
7802
  server: previewServer,
7792
7803
  environments: context.environments
7793
7804
  });
7794
- let applyStaticAssetMiddleware = async ()=>{
7795
- let { default: sirv } = await import("./sirv.js"), assetsMiddleware = sirv(context.distPath, {
7796
- etag: !0,
7797
- dev: !0,
7798
- ignores: [
7799
- 'favicon.ico'
7800
- ],
7801
- single: 'index' === serverConfig.htmlFallback
7802
- }), assetPrefixes = context.environmentList.map((e)=>getPathnameFromUrl(e.config.output.assetPrefix));
7803
- middlewares.use(function staticAssetMiddleware(req, res, next) {
7804
- let { url } = req, assetPrefix = url && assetPrefixes.find((prefix)=>url.startsWith(prefix));
7805
- assetPrefix && url?.startsWith(assetPrefix) ? (req.url = url.slice(assetPrefix.length), assetsMiddleware(req, res, (...args)=>{
7806
- req.url = url, next(...args);
7807
- })) : assetsMiddleware(req, res, next);
7808
- });
7805
+ let assetContext = (environmentList = context.environmentList.filter((environment)=>isWebTarget(environment.config.output.target)), {
7806
+ ...context,
7807
+ environmentList,
7808
+ publicPathnames: environmentList.map((environment)=>context.publicPathnames[environment.index])
7809
+ }), assetsMiddleware = createAssetsMiddleware(assetContext, (callback)=>callback(), node_fs), htmlMiddlewareOptions = {
7810
+ assetsMiddleware,
7811
+ distPaths: assetContext.environmentList.map((environment)=>environment.distPath),
7812
+ outputFileSystem: node_fs
7809
7813
  };
7810
7814
  if (isVerbose(logger) && middlewares.use(getRequestLoggerMiddleware(logger)), cors) {
7811
7815
  let { default: corsMiddleware } = await import("./cors.js").then(__webpack_require__.t.bind(__webpack_require__, "../../node_modules/.pnpm/cors@2.8.6/node_modules/cors/lib/index.js", 23));
@@ -7828,8 +7832,11 @@ async function startPreviewServer(context, config, { getPortSilently } = {}) {
7828
7832
  }
7829
7833
  for (let callback of (base && '/' !== base && middlewares.use(getBaseUrlMiddleware({
7830
7834
  base
7831
- })), await applyStaticAssetMiddleware(), historyApiFallback && (middlewares.use(historyApiFallback_historyApiFallbackMiddleware(logger, !0 === historyApiFallback ? {} : historyApiFallback)), await applyStaticAssetMiddleware()), postSetupCallbacks))await callback();
7832
- return middlewares.use(faviconFallbackMiddleware), middlewares.use(optionsFallbackMiddleware), middlewares.use(notFoundMiddleware), new Promise((resolve)=>{
7835
+ })), middlewares.use(assetsMiddleware), middlewares.use(getHtmlCompletionMiddleware(htmlMiddlewareOptions)), historyApiFallback && (middlewares.use(historyApiFallback_historyApiFallbackMiddleware(logger, !0 === historyApiFallback ? {} : historyApiFallback)), middlewares.use(assetsMiddleware)), postSetupCallbacks))await callback();
7836
+ return serverConfig.htmlFallback && middlewares.use(getHtmlFallbackMiddleware({
7837
+ ...htmlMiddlewareOptions,
7838
+ logger
7839
+ })), middlewares.use(faviconFallbackMiddleware), middlewares.use(optionsFallbackMiddleware), middlewares.use(notFoundMiddleware), new Promise((resolve)=>{
7833
7840
  httpServer.listen({
7834
7841
  host,
7835
7842
  port
@@ -8949,7 +8956,7 @@ try {
8949
8956
  api.modifyBundlerChain(async (chain, { CHAIN_ID, environment, isDev })=>{
8950
8957
  let { output: { manifest }, dev: { writeToDisk } } = environment.config;
8951
8958
  if (!1 === manifest) return;
8952
- 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'));
8959
+ 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.6/node_modules/rspack-manifest-plugin/dist/index.js")), { htmlPaths } = environment, filter = manifestOptions.filter ?? ((file)=>!file.name.endsWith('.LICENSE.txt'));
8953
8960
  manifestFilenames.set(environment.name, manifestOptions.filename);
8954
8961
  let pluginOptions = {
8955
8962
  fileName: manifestOptions.filename,
@@ -9463,7 +9470,7 @@ let applyServerOptions = (command)=>{
9463
9470
  };
9464
9471
  function setupCommands() {
9465
9472
  let cli = ((name = "")=>new CAC(name))('rsbuild');
9466
- cli.version("2.0.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)', {
9473
+ cli.version("2.0.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)', {
9467
9474
  default: 'auto'
9468
9475
  }).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', {
9469
9476
  type: [
@@ -9534,7 +9541,7 @@ function initNodeEnv(command) {
9534
9541
  }
9535
9542
  function showGreeting() {
9536
9543
  let { npm_execpath, npm_lifecycle_event, NODE_RUN_SCRIPT_NAME } = process.env, isBun = npm_execpath?.includes('.bun');
9537
- src_logger.greet(`${'npx' === npm_lifecycle_event || isBun || NODE_RUN_SCRIPT_NAME ? '\n' : ''}Rsbuild v2.0.9\n`);
9544
+ src_logger.greet(`${'npx' === npm_lifecycle_event || isBun || NODE_RUN_SCRIPT_NAME ? '\n' : ''}Rsbuild v2.0.11\n`);
9538
9545
  }
9539
9546
  function setupLogLevel() {
9540
9547
  if (cli_argv.length <= 3) return;
@@ -9556,5 +9563,5 @@ function runCLI() {
9556
9563
  src_logger.error('Failed to start Rsbuild CLI.'), src_logger.error(err), process.exit(1);
9557
9564
  }
9558
9565
  }
9559
- let src_version = "2.0.9";
9566
+ let src_version = "2.0.11";
9560
9567
  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 };