@rsbuild/core 1.7.0 → 1.7.2

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.
package/dist/index.cjs CHANGED
@@ -2982,6 +2982,13 @@ ${section.body}` : section.body).join("\n\n"));
2982
2982
  }) : resolve(!1);
2983
2983
  });
2984
2984
  }
2985
+ function readFileAsync(fs, filename) {
2986
+ return new Promise((resolve, reject)=>{
2987
+ fs.readFile(filename, (err, data)=>{
2988
+ err ? reject(err) : void 0 === data ? reject(Error(`Failed to read file: ${filename}, data is undefined`)) : resolve(data);
2989
+ });
2990
+ });
2991
+ }
2985
2992
  async function emptyDir(dir, keep = [], checkExists = !0) {
2986
2993
  if (!checkExists || await pathExists(dir)) try {
2987
2994
  let entries = await external_node_fs_default().promises.readdir(dir, {
@@ -2989,7 +2996,11 @@ ${section.body}` : section.body).join("\n\n"));
2989
2996
  });
2990
2997
  await Promise.all(entries.map(async (entry)=>{
2991
2998
  let fullPath = external_node_path_default().join(dir, entry.name);
2992
- !keep.some((reg)=>reg.test(toPosixPath(fullPath))) && (entry.isDirectory() ? (await emptyDir(fullPath, keep, !1), keep.length || await external_node_fs_default().promises.rmdir(fullPath)) : await external_node_fs_default().promises.unlink(fullPath));
2999
+ if (keep.length) {
3000
+ let posixFullPath = toPosixPath(fullPath);
3001
+ if (keep.some((regex)=>regex.test(posixFullPath))) return;
3002
+ }
3003
+ entry.isDirectory() ? (await emptyDir(fullPath, keep, !1), keep.length || await external_node_fs_default().promises.rmdir(fullPath)) : await external_node_fs_default().promises.unlink(fullPath);
2993
3004
  }));
2994
3005
  } catch (err) {
2995
3006
  src_logger.debug(`failed to empty dir: ${dir}`), src_logger.debug(err);
@@ -3689,7 +3700,7 @@ ${section.body}` : section.body).join("\n\n"));
3689
3700
  async function createContext(options, userConfig) {
3690
3701
  let { cwd } = options, rootPath = userConfig.root ? ensureAbsolutePath(cwd, userConfig.root) : cwd, rsbuildConfig = await withDefaultConfig(rootPath, userConfig), cachePath = (0, external_node_path_.join)(rootPath, 'node_modules', '.cache'), specifiedEnvironments = options.environment && options.environment.length > 0 ? options.environment : void 0, bundlerType = userConfig.provider ? 'webpack' : 'rspack';
3691
3702
  return {
3692
- version: "1.7.0",
3703
+ version: "1.7.2",
3693
3704
  rootPath,
3694
3705
  distPath: '',
3695
3706
  cachePath,
@@ -4592,9 +4603,12 @@ ${section.body}` : section.body).join("\n\n"));
4592
4603
  }
4593
4604
  let external_node_zlib_namespaceObject = require("node:zlib");
4594
4605
  var external_node_zlib_default = __webpack_require__.n(external_node_zlib_namespaceObject);
4595
- let fileSize_gzip = (0, external_node_util_.promisify)(external_node_zlib_default().gzip);
4596
4606
  async function gzipSize(input) {
4597
- let data = await fileSize_gzip(input);
4607
+ let data = await new Promise((resolve, reject)=>{
4608
+ external_node_zlib_default().gzip(input, (err, result)=>{
4609
+ err ? reject(err) : resolve(result);
4610
+ });
4611
+ });
4598
4612
  return Buffer.byteLength(data);
4599
4613
  }
4600
4614
  function getSnapshotPath(dir, snapshotHash) {
@@ -4843,16 +4857,17 @@ ${section.body}` : section.body).join("\n\n"));
4843
4857
  }
4844
4858
  apply(compiler) {
4845
4859
  let emitFavicon = async ({ compilation, favicon, faviconDistPath })=>{
4846
- let buffer, name = external_node_path_default().basename(favicon);
4860
+ let fileContent, name = external_node_path_default().basename(favicon);
4847
4861
  if (compilation.assets[name]) return name;
4848
- if (!compilation.inputFileSystem) return addCompilationError(compilation, `${color.dim('[rsbuild:html]')} Failed to read the favicon file as ${color.yellow('compilation.inputFileSystem')} is not available.`), null;
4862
+ let inputFs = compilation.inputFileSystem;
4863
+ if (!inputFs) return addCompilationError(compilation, `${color.dim('[rsbuild:html]')} Failed to read the favicon file as ${color.yellow('compilation.inputFileSystem')} is not available.`), null;
4849
4864
  let inputFilename = external_node_path_default().isAbsolute(favicon) ? favicon : external_node_path_default().join(compilation.compiler.context, favicon);
4850
4865
  try {
4851
- if (!(buffer = await (0, external_node_util_.promisify)(compilation.inputFileSystem.readFile)(inputFilename))) throw Error('Buffer is undefined');
4866
+ fileContent = await readFileAsync(inputFs, inputFilename);
4852
4867
  } catch (error) {
4853
4868
  return src_logger.debug(`read favicon error: ${error}`), addCompilationError(compilation, `${color.dim('[rsbuild:html]')} Failed to read the favicon file at ${color.yellow(inputFilename)}.`), null;
4854
4869
  }
4855
- let source = new compiler.webpack.sources.RawSource(buffer, !1), outputFilename = external_node_path_default().posix.join(faviconDistPath, name);
4870
+ let source = new compiler.webpack.sources.RawSource(fileContent, !1), outputFilename = external_node_path_default().posix.join(faviconDistPath, name);
4856
4871
  return compilation.emitAsset(outputFilename, source), outputFilename;
4857
4872
  }, addFavicon = async ({ headTags, favicon, faviconDistPath, compilation, publicPath })=>{
4858
4873
  let href = favicon;
@@ -5268,7 +5283,7 @@ ${section.body}` : section.body).join("\n\n"));
5268
5283
  function escapeHtml(text) {
5269
5284
  return text ? text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#39;') : '';
5270
5285
  }
5271
- let supportedChromiumBrowsers = [
5286
+ let HttpCode_Ok = 200, HttpCode_NotModified = 304, HttpCode_BadRequest = 400, HttpCode_Forbidden = 403, HttpCode_NotFound = 404, HttpCode_PreconditionFailed = 412, HttpCode_RangeNotSatisfiable = 416, HttpCode_InternalServerError = 500, supportedChromiumBrowsers = [
5272
5287
  'Google Chrome Canary',
5273
5288
  'Google Chrome Dev',
5274
5289
  'Google Chrome Beta',
@@ -5733,11 +5748,9 @@ ${section.body}` : section.body).join("\n\n"));
5733
5748
  env: {
5734
5749
  targets: browserslist
5735
5750
  },
5736
- rspackExperiments: {
5737
- collectTypeScriptInfo: {
5738
- typeExports: !0,
5739
- exportedEnum: isProd
5740
- }
5751
+ collectTypeScriptInfo: {
5752
+ typeExports: !0,
5753
+ exportedEnum: isProd
5741
5754
  }
5742
5755
  };
5743
5756
  }
@@ -5804,15 +5817,15 @@ ${section.body}` : section.body).join("\n\n"));
5804
5817
  pathname = decodeURIComponent(pathname);
5805
5818
  } catch {
5806
5819
  return {
5807
- errorCode: 400
5820
+ errorCode: HttpCode_BadRequest
5808
5821
  };
5809
5822
  }
5810
5823
  if (!pathname) return;
5811
5824
  if (pathname.includes('\0')) return {
5812
- errorCode: 400
5825
+ errorCode: HttpCode_BadRequest
5813
5826
  };
5814
5827
  if (UP_PATH_REGEXP.test(external_node_path_default().normalize(`./${pathname}`))) return {
5815
- errorCode: 403
5828
+ errorCode: HttpCode_Forbidden
5816
5829
  };
5817
5830
  let stat = async (filename)=>new Promise((resolve, reject)=>{
5818
5831
  outputFileSystem.stat(filename, (err, stats)=>{
@@ -5908,14 +5921,14 @@ ${section.body}` : section.body).join("\n\n"));
5908
5921
  'HEAD'
5909
5922
  ];
5910
5923
  function sendError(res, code) {
5911
- let message = `${code} ${{
5912
- 400: 'Bad Request',
5913
- 403: 'Forbidden',
5914
- 404: 'Not Found',
5915
- 412: 'Precondition Failed',
5916
- 416: 'Range Not Satisfiable',
5917
- 500: 'Internal Server Error'
5918
- }[code]}`, document1 = Buffer.from(`<!DOCTYPE html>
5924
+ let content = {
5925
+ [HttpCode_BadRequest]: 'Bad Request',
5926
+ [HttpCode_Forbidden]: 'Forbidden',
5927
+ [HttpCode_NotFound]: 'Not Found',
5928
+ [HttpCode_PreconditionFailed]: 'Precondition Failed',
5929
+ [HttpCode_RangeNotSatisfiable]: 'Range Not Satisfiable',
5930
+ [HttpCode_InternalServerError]: 'Internal Server Error'
5931
+ }[code], message = `${code} ${content}`, document1 = Buffer.from(`<!DOCTYPE html>
5919
5932
  <html lang="en">
5920
5933
  <head>
5921
5934
  <meta charset="utf-8">
@@ -5961,7 +5974,7 @@ ${section.body}` : section.body).join("\n\n"));
5961
5974
  return !1;
5962
5975
  }
5963
5976
  function isCachable() {
5964
- return res.statusCode >= 200 && res.statusCode < 300 || 304 === res.statusCode;
5977
+ return res.statusCode >= 200 && res.statusCode < 300 || res.statusCode === HttpCode_NotModified;
5965
5978
  }
5966
5979
  function isFresh(resHeaders) {
5967
5980
  let cacheControl = req.headers['cache-control'];
@@ -6021,7 +6034,7 @@ ${section.body}` : section.body).join("\n\n"));
6021
6034
  let resolved = await getFileFromUrl(req.url, outputFileSystem, context);
6022
6035
  if (!resolved) return void await goNext();
6023
6036
  if ('errorCode' in resolved) {
6024
- 403 === resolved.errorCode ? src_logger.error(`[rsbuild:middleware] Malicious path "${req.url}".`) : 400 === resolved.errorCode && src_logger.error(`[rsbuild:middleware] Invalid pathname "${req.url}".`), sendError(res, resolved.errorCode);
6037
+ resolved.errorCode === HttpCode_Forbidden ? src_logger.error(`[rsbuild:middleware] Malicious path "${req.url}".`) : resolved.errorCode === HttpCode_BadRequest && src_logger.error(`[rsbuild:middleware] Invalid pathname "${req.url}".`), sendError(res, resolved.errorCode);
6025
6038
  return;
6026
6039
  }
6027
6040
  let { fsStats, filename } = resolved, { size } = fsStats, len = size, offset = 0;
@@ -6036,19 +6049,19 @@ ${section.body}` : section.body).join("\n\n"));
6036
6049
  res.setHeader('ETag', hash);
6037
6050
  }
6038
6051
  if (isConditionalGET()) {
6039
- if (isPreconditionFailure()) return void sendError(res, 412);
6040
- if (404 === res.statusCode && (res.statusCode = 200), isCachable() && isFresh({
6052
+ if (isPreconditionFailure()) return void sendError(res, HttpCode_PreconditionFailed);
6053
+ if (res.statusCode === HttpCode_NotFound && (res.statusCode = HttpCode_Ok), isCachable() && isFresh({
6041
6054
  etag: res.getHeader('ETag'),
6042
6055
  'last-modified': res.getHeader('Last-Modified')
6043
6056
  })) {
6044
- res.statusCode = 304, res.removeHeader('Content-Encoding'), res.removeHeader('Content-Language'), res.removeHeader('Content-Length'), res.removeHeader('Content-Range'), res.removeHeader('Content-Type'), res.end();
6057
+ res.statusCode = HttpCode_NotModified, res.removeHeader('Content-Encoding'), res.removeHeader('Content-Language'), res.removeHeader('Content-Length'), res.removeHeader('Content-Range'), res.removeHeader('Content-Type'), res.end();
6045
6058
  return;
6046
6059
  }
6047
6060
  }
6048
6061
  if (rangeHeader) {
6049
6062
  let parsedRanges = await parseRangeHeaders(`${size}|${rangeHeader}`);
6050
6063
  if (isRangeFresh() || (parsedRanges = []), -1 === parsedRanges) {
6051
- src_logger.error("[rsbuild:middleware] Unsatisfiable range for 'Range' header."), res.setHeader('Content-Range', getValueContentRangeHeader('bytes', size)), sendError(res, 416);
6064
+ src_logger.error("[rsbuild:middleware] Unsatisfiable range for 'Range' header."), res.setHeader('Content-Range', getValueContentRangeHeader('bytes', size)), sendError(res, HttpCode_RangeNotSatisfiable);
6052
6065
  return;
6053
6066
  }
6054
6067
  -2 === parsedRanges ? src_logger.error("[rsbuild:middleware] A malformed 'Range' header was provided. A regular response will be sent for this request.") : parsedRanges.length > 1 && src_logger.error("[rsbuild:middleware] A 'Range' header with multiple ranges was provided. Multiple ranges are not supported, so a regular response will be sent for this request."), -2 !== parsedRanges && 1 === parsedRanges.length && (res.statusCode = 206, res.setHeader('Content-Range', getValueContentRangeHeader('bytes', size, parsedRanges[0])), [offset, len] = getOffsetAndLenFromRange(parsedRanges[0]));
@@ -6061,7 +6074,7 @@ ${section.body}` : section.body).join("\n\n"));
6061
6074
  return;
6062
6075
  }
6063
6076
  if (res.setHeader('Content-Length', byteLength), 'HEAD' === req.method) {
6064
- 404 === res.statusCode && (res.statusCode = 200), res.end();
6077
+ res.statusCode === HttpCode_NotFound && (res.statusCode = HttpCode_Ok), res.end();
6065
6078
  return;
6066
6079
  }
6067
6080
  if ('function' != typeof bufferOrStream.pipe) return void res.end(bufferOrStream);
@@ -6073,10 +6086,10 @@ ${section.body}` : section.body).join("\n\n"));
6073
6086
  case 'ENAMETOOLONG':
6074
6087
  case 'ENOENT':
6075
6088
  case 'ENOTDIR':
6076
- sendError(res, 404);
6089
+ sendError(res, HttpCode_NotFound);
6077
6090
  break;
6078
6091
  default:
6079
- sendError(res, 500);
6092
+ sendError(res, HttpCode_InternalServerError);
6080
6093
  }
6081
6094
  }), bufferOrStream.pipe(res), on_finished_default()(res, cleanup);
6082
6095
  });
@@ -6300,8 +6313,7 @@ init(
6300
6313
  try {
6301
6314
  let tracer = cachedTraceMap.get(sourceMapPath);
6302
6315
  if (!tracer) {
6303
- let readFile = (0, external_node_util_.promisify)(fs.readFile), sourceMap = await readFile(sourceMapPath);
6304
- if (!sourceMap) return;
6316
+ let sourceMap = await readFileAsync(fs, sourceMapPath);
6305
6317
  tracer = new TraceMap(sourceMap.toString()), cachedTraceMap.set(sourceMapPath, tracer);
6306
6318
  }
6307
6319
  let originalPosition = originalPositionFor(tracer, {
@@ -6807,7 +6819,7 @@ init(
6807
6819
  }), next();
6808
6820
  };
6809
6821
  }, notFoundMiddleware = (_req, res, _next)=>{
6810
- res.statusCode = 404, res.end();
6822
+ res.statusCode = HttpCode_NotFound, res.setHeader('Content-Type', 'text/plain; charset=utf-8'), res.end('This page could not be found');
6811
6823
  }, optionsFallbackMiddleware = (req, res, next)=>{
6812
6824
  if ('OPTIONS' === req.method) {
6813
6825
  res.statusCode = 204, res.setHeader('Content-Length', '0'), res.end();
@@ -6836,12 +6848,12 @@ init(
6836
6848
  return;
6837
6849
  }
6838
6850
  if (req.headers.accept?.includes('text/html')) {
6839
- res.writeHead(404, {
6851
+ res.writeHead(HttpCode_NotFound, {
6840
6852
  'Content-Type': 'text/html'
6841
6853
  }), res.end(`The server is configured with a base URL of ${base} - did you mean to visit <a href="${redirectPath}">${redirectPath}</a> instead?`);
6842
6854
  return;
6843
6855
  }
6844
- res.writeHead(404, {
6856
+ res.writeHead(HttpCode_NotFound, {
6845
6857
  'Content-Type': 'text/plain'
6846
6858
  }), res.end(`The server is configured with a base URL of ${base} - did you mean to visit ${redirectPath} instead?`);
6847
6859
  };
@@ -6871,7 +6883,7 @@ init(
6871
6883
  };
6872
6884
  let proxyMiddleware = baseMiddleware(opts.context, opts), middleware = async (req, res, next)=>{
6873
6885
  let bypassUrl = 'function' == typeof opts.bypass ? await opts.bypass(req, res, opts) : null;
6874
- !1 === bypassUrl ? (res.statusCode = 404, next()) : 'string' == typeof bypassUrl ? (req.url = bypassUrl, next()) : !0 === bypassUrl ? next() : proxyMiddleware(req, res, next);
6886
+ !1 === bypassUrl ? (res.statusCode = HttpCode_NotFound, next()) : 'string' == typeof bypassUrl ? (req.url = bypassUrl, next()) : !0 === bypassUrl ? next() : proxyMiddleware(req, res, next);
6875
6887
  };
6876
6888
  middlewares.push(middleware), opts.ws && proxyMiddlewares.push(proxyMiddleware);
6877
6889
  }
@@ -7420,7 +7432,7 @@ init(
7420
7432
  launchEditorMiddleware()
7421
7433
  ]), middlewares.push((({ environments })=>async function viewingServedFilesMiddleware(req, res, next) {
7422
7434
  if ('/rsbuild-dev-server' !== req.url.replace(postfixRE, '')) return void next();
7423
- res.writeHead(200, {
7435
+ res.writeHead(HttpCode_Ok, {
7424
7436
  'Content-Type': 'text/html; charset=utf-8'
7425
7437
  }), res.write(`<!DOCTYPE html>
7426
7438
  <html>
@@ -7479,7 +7491,7 @@ init(
7479
7491
  })({
7480
7492
  environments: devServerAPI.environments
7481
7493
  })), buildManager && (middlewares.push(buildManager.assetsMiddleware), upgradeEvents.push(buildManager.socketServer.upgrade), middlewares.push(function hotUpdateJsonFallbackMiddleware(req, res, next) {
7482
- req.url?.endsWith('.hot-update.json') && 'OPTIONS' !== req.method ? (res.statusCode = 404, res.end()) : next();
7494
+ req.url?.endsWith('.hot-update.json') && 'OPTIONS' !== req.method ? notFoundMiddleware(req, res, next) : next();
7483
7495
  })), buildManager && middlewares.push((({ distPath, buildManager })=>async function htmlCompletionMiddleware(req, res, next) {
7484
7496
  if (!maybeHTMLRequest(req)) return void next();
7485
7497
  let pathname = req.url.replace(postfixRE, ''), rewrite = (newUrl)=>{
@@ -8188,11 +8200,7 @@ init(
8188
8200
  addCompilationError(compilation, `${color.dim('[rsbuild:app-icon]')} Failed to find the icon file at ${color.yellow(icon.absolutePath)}.`);
8189
8201
  continue;
8190
8202
  }
8191
- let source = await (0, external_node_util_.promisify)(compilation.inputFileSystem.readFile)(icon.absolutePath);
8192
- if (!source) {
8193
- addCompilationError(compilation, `${color.dim('[rsbuild:app-icon]')} Failed to read the icon file at ${color.yellow(icon.absolutePath)}.`);
8194
- continue;
8195
- }
8203
+ let source = await readFileAsync(compilation.inputFileSystem, icon.absolutePath);
8196
8204
  compilation.emitAsset(icon.relativePath, new sources.RawSource(source));
8197
8205
  }
8198
8206
  ('apple-touch-icon' === icon.target || !icon.target && icon.size < 200) && tags.push({
@@ -8568,23 +8576,22 @@ try {
8568
8576
  isProd
8569
8577
  });
8570
8578
  if (applyTransformImport(swcConfig, config.source.transformImport), applySwcDecoratorConfig(swcConfig, config), isWebTarget(target)) {
8571
- let polyfillMode = config.output.polyfill;
8572
- if ('off' === polyfillMode) swcConfig.env.mode = void 0;
8573
- else {
8574
- swcConfig.env.mode = polyfillMode;
8575
- let coreJsDir = applyCoreJs(swcConfig, polyfillMode);
8579
+ let { polyfill } = config.output;
8580
+ if ('off' !== polyfill) {
8581
+ swcConfig.env.mode = polyfill;
8582
+ let coreJsDir = applyCoreJs(swcConfig, polyfill);
8576
8583
  for (let item of [
8577
8584
  rule,
8578
8585
  dataUriRule
8579
8586
  ])item.resolve.alias.set('core-js', coreJsDir);
8580
8587
  }
8581
8588
  }
8582
- let mergedSwcConfig = reduceConfigs({
8589
+ let mergedConfig = reduceConfigs({
8583
8590
  initial: swcConfig,
8584
8591
  config: config.tools.swc,
8585
8592
  mergeFn: cjs_default()
8586
8593
  });
8587
- rule.use(CHAIN_ID.USE.SWC).loader(builtinSwcLoaderName).options(mergedSwcConfig), dataUriRule.resolve.set('fullySpecified', !1).end().use(CHAIN_ID.USE.SWC).loader(builtinSwcLoaderName).options(cloneDeep(mergedSwcConfig));
8594
+ mergedConfig.jsc?.target !== void 0 && mergedConfig.env?.targets !== void 0 && 1 === Object.keys(mergedConfig.env).length && delete mergedConfig.env, rule.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));
8588
8595
  }
8589
8596
  });
8590
8597
  }
@@ -8642,32 +8649,37 @@ try {
8642
8649
  {
8643
8650
  name: 'rsbuild:inline-chunk',
8644
8651
  setup (api) {
8645
- let inlinedAssets = new Set();
8652
+ let inlineAssetsByEnvironment = new Map();
8646
8653
  api.processAssets({
8647
8654
  stage: 'summarize'
8648
- }, ({ compiler, compilation })=>{
8649
- if (0 === inlinedAssets.size) return;
8655
+ }, ({ compiler, compilation, environment })=>{
8656
+ let inlinedAssets = inlineAssetsByEnvironment.get(environment.name);
8657
+ if (!inlinedAssets || 0 === inlinedAssets.size) return;
8650
8658
  let { devtool } = compiler.options, hasSourceMap = 'hidden-source-map' !== devtool && !1 !== devtool;
8651
- for (let name of inlinedAssets)hasSourceMap && compilation.updateAsset(name, compilation.assets[name], {
8652
- related: {
8653
- sourceMap: null
8654
- }
8655
- }), compilation.deleteAsset(name);
8659
+ for (let name of inlinedAssets){
8660
+ let asset = compilation.assets[name];
8661
+ asset && (hasSourceMap && compilation.updateAsset(name, asset, {
8662
+ related: {
8663
+ sourceMap: null
8664
+ }
8665
+ }), compilation.deleteAsset(name));
8666
+ }
8656
8667
  inlinedAssets.clear();
8657
8668
  }), api.modifyHTMLTags(({ headTags, bodyTags }, { compiler, compilation, environment })=>{
8658
- let { htmlPaths, config } = environment;
8669
+ var name;
8670
+ let set, { htmlPaths, config } = environment;
8659
8671
  if (0 === Object.keys(htmlPaths).length) return {
8660
8672
  headTags,
8661
8673
  bodyTags
8662
8674
  };
8663
- let { scriptTests, styleTests } = getInlineTests(config);
8675
+ let inlinedAssets = (name = environment.name, (set = inlineAssetsByEnvironment.get(name)) || (set = new Set(), inlineAssetsByEnvironment.set(name, set)), set), { scriptTests, styleTests } = getInlineTests(config);
8664
8676
  if (!scriptTests.length && !styleTests.length) return {
8665
8677
  headTags,
8666
8678
  bodyTags
8667
8679
  };
8668
8680
  let publicPath = getPublicPathFromCompiler(compiler), updateTag = (tag)=>{
8669
- var publicPath1, tag1, compilation1, scriptTests1, styleTests1, config;
8670
- return publicPath1 = publicPath, tag1 = tag, compilation1 = compilation, scriptTests1 = scriptTests, styleTests1 = styleTests, config = environment.config, "script" === tag1.tag ? ((publicPath, tag, compilation, scriptTests, config)=>{
8681
+ var publicPath1, tag1, compilation1, inlinedAssets1, scriptTests1, styleTests1, config;
8682
+ return publicPath1 = publicPath, tag1 = tag, compilation1 = compilation, inlinedAssets1 = inlinedAssets, scriptTests1 = scriptTests, styleTests1 = styleTests, config = environment.config, "script" === tag1.tag ? ((publicPath, tag, compilation, inlinedAssets, scriptTests, config)=>{
8671
8683
  let { assets } = compilation;
8672
8684
  if (!(tag.attrs?.src && 'string' == typeof tag.attrs.src)) return tag;
8673
8685
  let { src, ...otherAttrs } = tag.attrs, scriptName = publicPath ? src.replace(publicPath, '') : src, asset = assets[scriptName];
@@ -8686,7 +8698,7 @@ try {
8686
8698
  }
8687
8699
  };
8688
8700
  return inlinedAssets.add(scriptName), ret;
8689
- })(publicPath1, tag1, compilation1, scriptTests1, config) : 'link' === tag1.tag && tag1.attrs && 'stylesheet' === tag1.attrs.rel ? ((publicPath, tag, compilation, styleTests, config)=>{
8701
+ })(publicPath1, tag1, compilation1, inlinedAssets1, scriptTests1, config) : 'link' === tag1.tag && tag1.attrs && 'stylesheet' === tag1.attrs.rel ? ((publicPath, tag, compilation, inlinedAssets, styleTests, config)=>{
8690
8702
  let { assets } = compilation;
8691
8703
  if (!(tag.attrs?.href && 'string' == typeof tag.attrs.href)) return tag;
8692
8704
  let linkName = publicPath ? tag.attrs.href.replace(publicPath, '') : tag.attrs.href, asset = assets[linkName];
@@ -8702,7 +8714,7 @@ try {
8702
8714
  })
8703
8715
  };
8704
8716
  return inlinedAssets.add(linkName), ret;
8705
- })(publicPath1, tag1, compilation1, styleTests1, config) : tag1;
8717
+ })(publicPath1, tag1, compilation1, inlinedAssets1, styleTests1, config) : tag1;
8706
8718
  };
8707
8719
  return {
8708
8720
  headTags: headTags.map(updateTag),
@@ -9333,7 +9345,7 @@ try {
9333
9345
  };
9334
9346
  function setupCommands() {
9335
9347
  let cli = ((name = "")=>new CAC(name))('rsbuild');
9336
- cli.version("1.7.0"), 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)', {
9348
+ cli.version("1.7.2"), 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)', {
9337
9349
  default: 'auto'
9338
9350
  }).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', {
9339
9351
  type: [
@@ -9402,7 +9414,7 @@ try {
9402
9414
  }
9403
9415
  function showGreeting() {
9404
9416
  let { npm_execpath, npm_lifecycle_event, NODE_RUN_SCRIPT_NAME } = process.env, isBun = npm_execpath?.includes('.bun');
9405
- src_logger.greet(`${'npx' === npm_lifecycle_event || isBun || NODE_RUN_SCRIPT_NAME ? '\n' : ''}Rsbuild v1.7.0\n`);
9417
+ src_logger.greet(`${'npx' === npm_lifecycle_event || isBun || NODE_RUN_SCRIPT_NAME ? '\n' : ''}Rsbuild v1.7.2\n`);
9406
9418
  }
9407
9419
  function setupLogLevel() {
9408
9420
  let logLevelIndex = process.argv.findIndex((item)=>'--log-level' === item || '--logLevel' === item);
@@ -9423,7 +9435,7 @@ try {
9423
9435
  src_logger.error('Failed to start Rsbuild CLI.'), src_logger.error(err);
9424
9436
  }
9425
9437
  }
9426
- let src_version = "1.7.0";
9438
+ let src_version = "1.7.2";
9427
9439
  })(), exports.PLUGIN_CSS_NAME = __webpack_exports__.PLUGIN_CSS_NAME, exports.PLUGIN_SWC_NAME = __webpack_exports__.PLUGIN_SWC_NAME, exports.createRsbuild = __webpack_exports__.createRsbuild, exports.defaultAllowedOrigins = __webpack_exports__.defaultAllowedOrigins, exports.defineConfig = __webpack_exports__.defineConfig, exports.ensureAssetPrefix = __webpack_exports__.ensureAssetPrefix, exports.loadConfig = __webpack_exports__.loadConfig, exports.loadEnv = __webpack_exports__.loadEnv, exports.logger = __webpack_exports__.logger, exports.mergeRsbuildConfig = __webpack_exports__.mergeRsbuildConfig, exports.rspack = __webpack_exports__.rspack, exports.runCLI = __webpack_exports__.runCLI, exports.version = __webpack_exports__.version, __webpack_exports__)-1 === [
9428
9440
  "PLUGIN_CSS_NAME",
9429
9441
  "PLUGIN_SWC_NAME",
@@ -10,4 +10,8 @@ export declare const findExists: (files: string[]) => string | false;
10
10
  export declare function pathExists(path: string): Promise<boolean>;
11
11
  export declare function isFileExists(file: string): Promise<boolean>;
12
12
  export declare function fileExistsByCompilation({ inputFileSystem }: Rspack.Compilation, filePath: string): Promise<boolean>;
13
+ /**
14
+ * Read file asynchronously using Rspack compiler's filesystem.
15
+ */
16
+ export declare function readFileAsync(fs: NonNullable<Rspack.Compilation['inputFileSystem'] | Rspack.OutputFileSystem>, filename: string): Promise<Buffer | string>;
13
17
  export declare function emptyDir(dir: string, keep?: RegExp[], checkExists?: boolean): Promise<void>;
@@ -1,6 +1,5 @@
1
1
  import type { Stats as FSStats } from 'node:fs';
2
2
  import type { InternalContext, Rspack } from '../../types';
3
- import { HttpCode } from '../helper';
4
3
  /**
5
4
  * Resolves URL to file path with security checks and retrieves file from
6
5
  * the build output directories.
@@ -9,5 +8,5 @@ export declare function getFileFromUrl(url: string, outputFileSystem: Rspack.Out
9
8
  filename: string;
10
9
  fsStats: FSStats;
11
10
  } | {
12
- errorCode: HttpCode;
11
+ errorCode: number;
13
12
  } | undefined>;
@@ -78,12 +78,14 @@ export declare function getServerTerminator(server: Server | Http2SecureServer):
78
78
  * escapeHtml('<div>Hello</div>') // '&lt;div&gt;Hello&lt;/div&gt;'
79
79
  */
80
80
  export declare function escapeHtml(text: string | null | undefined): string;
81
- export declare enum HttpCode {
82
- BadRequest = 400,
83
- Forbidden = 403,
84
- NotFound = 404,
85
- PreconditionFailed = 412,
86
- RangeNotSatisfiable = 416,
87
- InternalServerError = 500
88
- }
81
+ export declare const HttpCode: {
82
+ readonly Ok: 200;
83
+ readonly NotModified: 304;
84
+ readonly BadRequest: 400;
85
+ readonly Forbidden: 403;
86
+ readonly NotFound: 404;
87
+ readonly PreconditionFailed: 412;
88
+ readonly RangeNotSatisfiable: 416;
89
+ readonly InternalServerError: 500;
90
+ };
89
91
  export {};
@@ -1,5 +1,5 @@
1
1
  import type { RequestHandler as Middleware, ProxyConfig } from '../types';
2
- import type { UpgradeEvent } from './helper';
2
+ import { type UpgradeEvent } from './helper';
3
3
  export declare const createProxyMiddleware: (proxyOptions: ProxyConfig) => {
4
4
  middlewares: Middleware[];
5
5
  upgrade: UpgradeEvent;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/core",
3
- "version": "1.7.0",
3
+ "version": "1.7.2",
4
4
  "description": "The Rspack-based build tool.",
5
5
  "homepage": "https://rsbuild.rs",
6
6
  "bugs": {
@@ -46,7 +46,7 @@
46
46
  "types.d.ts"
47
47
  ],
48
48
  "dependencies": {
49
- "@rspack/core": "1.7.0",
49
+ "@rspack/core": "~1.7.1",
50
50
  "@rspack/lite-tapable": "~1.1.0",
51
51
  "@swc/helpers": "^0.5.18",
52
52
  "core-js": "~3.47.0",
@@ -55,7 +55,7 @@
55
55
  "devDependencies": {
56
56
  "@jridgewell/remapping": "^2.3.5",
57
57
  "@jridgewell/trace-mapping": "^0.3.31",
58
- "@rslib/core": "0.19.0",
58
+ "@rslib/core": "0.19.1",
59
59
  "@types/connect": "3.4.38",
60
60
  "@types/cors": "^2.8.19",
61
61
  "@types/node": "^24.10.4",