@rspress/core 1.5.1 → 1.6.0

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.js CHANGED
@@ -3506,7 +3506,7 @@ var require_parse = __commonJS({
3506
3506
  var require_gray_matter = __commonJS({
3507
3507
  "../../node_modules/.pnpm/gray-matter@4.0.3/node_modules/gray-matter/index.js"(exports2, module2) {
3508
3508
  "use strict";
3509
- var fs10 = __require("fs");
3509
+ var fs11 = __require("fs");
3510
3510
  var sections = require_section_matter();
3511
3511
  var defaults = require_defaults();
3512
3512
  var stringify = require_stringify();
@@ -3591,7 +3591,7 @@ var require_gray_matter = __commonJS({
3591
3591
  return stringify(file, data, options2);
3592
3592
  };
3593
3593
  matter.read = function(filepath, options2) {
3594
- const str2 = fs10.readFileSync(filepath, "utf8");
3594
+ const str2 = fs11.readFileSync(filepath, "utf8");
3595
3595
  const file = matter(str2, options2);
3596
3596
  file.path = filepath;
3597
3597
  return file;
@@ -3624,8 +3624,8 @@ import { removeLeadingSlash as removeLeadingSlash2 } from "@rspress/shared";
3624
3624
  import { logger as logger4 } from "@rspress/shared/logger";
3625
3625
 
3626
3626
  // src/node/initRsbuild.ts
3627
- import path9 from "path";
3628
- import fs8 from "@modern-js/utils/fs-extra";
3627
+ import path10 from "path";
3628
+ import fs9 from "@modern-js/utils/fs-extra";
3629
3629
  import {
3630
3630
  MDX_REGEXP as MDX_REGEXP3,
3631
3631
  RSPRESS_TEMP_DIR as RSPRESS_TEMP_DIR2,
@@ -3748,19 +3748,18 @@ async function routeVMPlugin(context) {
3748
3748
  };
3749
3749
  }
3750
3750
 
3751
- // src/node/runtimeModule/siteData.ts
3752
- import path6 from "path";
3751
+ // src/node/runtimeModule/siteData/index.ts
3752
+ import path7 from "path";
3753
+ import { SEARCH_INDEX_NAME } from "@rspress/shared";
3754
+ import fs4 from "@modern-js/utils/fs-extra";
3755
+
3756
+ // src/node/runtimeModule/siteData/normalizeThemeConfig.ts
3753
3757
  import {
3754
3758
  withBase,
3755
- MDX_REGEXP as MDX_REGEXP2,
3756
- SEARCH_INDEX_NAME,
3757
3759
  addLeadingSlash as addLeadingSlash2,
3758
3760
  isExternalUrl,
3759
3761
  withoutBase
3760
3762
  } from "@rspress/shared";
3761
- import { htmlToText } from "html-to-text";
3762
- import fs3 from "@modern-js/utils/fs-extra";
3763
- import { compile } from "@rspress/mdx-rs";
3764
3763
 
3765
3764
  // src/node/utils/applyReplaceRules.ts
3766
3765
  function applyReplaceRules(code = "", replaceRules = []) {
@@ -3771,6 +3770,181 @@ function applyReplaceRules(code = "", replaceRules = []) {
3771
3770
  return result;
3772
3771
  }
3773
3772
 
3773
+ // src/node/runtimeModule/i18n.ts
3774
+ import { join } from "path";
3775
+ var DEFAULT_I18N_SOURCE = join(process.cwd(), "i18n.json");
3776
+ function getI18nData(docConfig) {
3777
+ const { i18nSourcePath = DEFAULT_I18N_SOURCE } = docConfig;
3778
+ try {
3779
+ const i18nSource = __require(i18nSourcePath);
3780
+ return i18nSource;
3781
+ } catch (e) {
3782
+ return {};
3783
+ }
3784
+ }
3785
+ function i18nVMPlugin(context) {
3786
+ const { config } = context;
3787
+ const i18nData = getI18nData(config);
3788
+ return {
3789
+ ["virtual-i18n-text" /* I18nText */]: `export default ${JSON.stringify(i18nData)}`
3790
+ };
3791
+ }
3792
+
3793
+ // src/node/runtimeModule/siteData/normalizeThemeConfig.ts
3794
+ function normalizeThemeConfig(docConfig, pages = []) {
3795
+ const {
3796
+ locales: siteLocales,
3797
+ base = "",
3798
+ lang,
3799
+ replaceRules = [],
3800
+ multiVersion
3801
+ } = docConfig;
3802
+ const { versions = [] } = multiVersion || {};
3803
+ const hasMultiVersion = versions.length > 0;
3804
+ docConfig.themeConfig = docConfig.themeConfig || {};
3805
+ const { themeConfig } = docConfig;
3806
+ const locales = siteLocales ?? (themeConfig?.locales || []);
3807
+ const i18nTextData = getI18nData(docConfig);
3808
+ const normalizeLinkPrefix = (link = "", currentLang = "") => {
3809
+ if (!currentLang || !link || withoutBase(link, base).startsWith(`/${currentLang}`) || isExternalUrl(link) || // In multi version case, we have got the complete link prefix in `plugin-auto-nav-sidebar` and does not need to add the lang prefix
3810
+ hasMultiVersion) {
3811
+ return link;
3812
+ }
3813
+ return lang === currentLang ? link : `/${currentLang}${addLeadingSlash2(link)}`;
3814
+ };
3815
+ const getI18nText = (key = "", currentLang = "") => {
3816
+ const text = i18nTextData[key]?.[currentLang];
3817
+ return text || key;
3818
+ };
3819
+ const normalizeSidebar = (sidebar, currentLang = "") => {
3820
+ const normalizedSidebar = {};
3821
+ if (!sidebar) {
3822
+ return {};
3823
+ }
3824
+ const normalizeSidebarItem = (item) => {
3825
+ if (typeof item === "object" && "items" in item) {
3826
+ return {
3827
+ text: applyReplaceRules(
3828
+ getI18nText(item.text, currentLang),
3829
+ replaceRules
3830
+ ),
3831
+ link: normalizeLinkPrefix(item.link),
3832
+ collapsed: item.collapsed ?? false,
3833
+ collapsible: item.collapsible ?? true,
3834
+ tag: item.tag,
3835
+ items: item.items.map((subItem) => {
3836
+ return normalizeSidebarItem(subItem);
3837
+ })
3838
+ };
3839
+ }
3840
+ if (typeof item === "object" && "dividerType" in item) {
3841
+ return item;
3842
+ }
3843
+ if (typeof item === "string") {
3844
+ const normalizedItem = normalizeLinkPrefix(item, currentLang);
3845
+ const page = pages.find(
3846
+ (page2) => page2.routePath === withBase(normalizedItem, base)
3847
+ );
3848
+ return {
3849
+ text: applyReplaceRules(page?.title || "", replaceRules),
3850
+ link: normalizedItem
3851
+ };
3852
+ }
3853
+ return {
3854
+ text: applyReplaceRules(
3855
+ getI18nText(item.text, currentLang),
3856
+ replaceRules
3857
+ ),
3858
+ link: normalizeLinkPrefix(item.link),
3859
+ tag: item.tag
3860
+ };
3861
+ };
3862
+ const normalizeSidebar2 = (sidebar2) => {
3863
+ Object.keys(sidebar2).forEach((key) => {
3864
+ const value = sidebar2[key];
3865
+ normalizedSidebar[key] = value.map(normalizeSidebarItem);
3866
+ });
3867
+ };
3868
+ normalizeSidebar2(sidebar);
3869
+ return normalizedSidebar;
3870
+ };
3871
+ const normalizeNav = (nav, currentLang) => {
3872
+ if (!nav) {
3873
+ return [];
3874
+ }
3875
+ const transformNavItem = (navItem) => {
3876
+ const text = applyReplaceRules(
3877
+ getI18nText(navItem.text, currentLang),
3878
+ replaceRules
3879
+ );
3880
+ if ("link" in navItem) {
3881
+ return {
3882
+ ...navItem,
3883
+ text,
3884
+ link: normalizeLinkPrefix(navItem.link, currentLang)
3885
+ };
3886
+ }
3887
+ if ("items" in navItem) {
3888
+ return {
3889
+ ...navItem,
3890
+ text,
3891
+ items: navItem.items.map((item) => {
3892
+ return {
3893
+ ...item,
3894
+ text: applyReplaceRules(
3895
+ getI18nText(item.text, currentLang),
3896
+ replaceRules
3897
+ ),
3898
+ link: normalizeLinkPrefix(item.link, currentLang)
3899
+ };
3900
+ })
3901
+ };
3902
+ }
3903
+ return navItem;
3904
+ };
3905
+ if (Array.isArray(nav)) {
3906
+ return nav.map(transformNavItem);
3907
+ }
3908
+ return Object.entries(nav).reduce((acc, [key, value]) => {
3909
+ acc[key] = value.map(transformNavItem);
3910
+ return acc;
3911
+ }, {});
3912
+ };
3913
+ if (locales.length) {
3914
+ themeConfig.locales = locales.map(({ lang: currentLang, label }) => {
3915
+ const localeInThemeConfig = themeConfig.locales?.find(
3916
+ (locale) => locale.lang === currentLang
3917
+ );
3918
+ return {
3919
+ lang: currentLang,
3920
+ label,
3921
+ ...localeInThemeConfig || {},
3922
+ sidebar: normalizeSidebar(
3923
+ localeInThemeConfig?.sidebar ?? themeConfig.sidebar,
3924
+ currentLang
3925
+ ),
3926
+ nav: normalizeNav(
3927
+ localeInThemeConfig?.nav ?? themeConfig.nav,
3928
+ currentLang
3929
+ )
3930
+ };
3931
+ });
3932
+ } else {
3933
+ themeConfig.sidebar = normalizeSidebar(themeConfig?.sidebar);
3934
+ themeConfig.nav = normalizeNav(themeConfig?.nav);
3935
+ }
3936
+ return themeConfig;
3937
+ }
3938
+
3939
+ // src/node/runtimeModule/siteData/extractPageData.ts
3940
+ import path6 from "path";
3941
+ import {
3942
+ MDX_REGEXP as MDX_REGEXP2
3943
+ } from "@rspress/shared";
3944
+ import { htmlToText } from "html-to-text";
3945
+ import fs3 from "@modern-js/utils/fs-extra";
3946
+ import { compile } from "@rspress/mdx-rs";
3947
+
3774
3948
  // src/node/utils/normalizePath.ts
3775
3949
  import os from "os";
3776
3950
  import path2 from "path";
@@ -3968,167 +4142,7 @@ function loadFrontMatter(source, filepath, root, outputWarning = false) {
3968
4142
  return { frontmatter, content };
3969
4143
  }
3970
4144
 
3971
- // src/node/runtimeModule/i18n.ts
3972
- import { join } from "path";
3973
- var DEFAULT_I18N_SOURCE = join(process.cwd(), "i18n.json");
3974
- function getI18nData(docConfig) {
3975
- const { i18nSourcePath = DEFAULT_I18N_SOURCE } = docConfig;
3976
- try {
3977
- const i18nSource = __require(i18nSourcePath);
3978
- return i18nSource;
3979
- } catch (e) {
3980
- return {};
3981
- }
3982
- }
3983
- function i18nVMPlugin(context) {
3984
- const { config } = context;
3985
- const i18nData = getI18nData(config);
3986
- return {
3987
- ["virtual-i18n-text" /* I18nText */]: `export default ${JSON.stringify(i18nData)}`
3988
- };
3989
- }
3990
-
3991
- // src/node/runtimeModule/siteData.ts
3992
- function deletePriviteKey(obj) {
3993
- if (typeof obj !== "object" || obj === null) {
3994
- return obj;
3995
- }
3996
- const newObj = { ...obj };
3997
- Object.keys(newObj).forEach((key) => {
3998
- if (key.startsWith("_")) {
3999
- delete newObj[key];
4000
- }
4001
- });
4002
- return newObj;
4003
- }
4004
- function normalizeThemeConfig(docConfig, pages = []) {
4005
- const {
4006
- locales: siteLocales,
4007
- base = "",
4008
- lang,
4009
- replaceRules = []
4010
- } = docConfig;
4011
- docConfig.themeConfig = docConfig.themeConfig || {};
4012
- const { themeConfig } = docConfig;
4013
- const locales = siteLocales ?? (themeConfig?.locales || []);
4014
- const i18nTextData = getI18nData(docConfig);
4015
- const normalizeLangPrefix = (link, currentLang) => {
4016
- if (!currentLang || !link || withoutBase(link, base).startsWith(`/${currentLang}`) || isExternalUrl(link)) {
4017
- return link;
4018
- }
4019
- return lang === currentLang ? link : `/${currentLang}${addLeadingSlash2(link)}`;
4020
- };
4021
- const getI18nText = (key, currentLang) => {
4022
- const text = i18nTextData[key]?.[currentLang];
4023
- return text || key;
4024
- };
4025
- const normalizeSidebar = (sidebar, currentLang) => {
4026
- const normalizedSidebar = {};
4027
- if (!sidebar) {
4028
- return {};
4029
- }
4030
- const normalizeSidebarItem = (item) => {
4031
- if (typeof item === "object" && "items" in item) {
4032
- return {
4033
- text: applyReplaceRules(
4034
- getI18nText(item.text, currentLang),
4035
- replaceRules
4036
- ),
4037
- link: normalizeLangPrefix(item.link, currentLang),
4038
- collapsed: item.collapsed ?? false,
4039
- collapsible: item.collapsible ?? true,
4040
- tag: item.tag,
4041
- items: item.items.map((subItem) => {
4042
- return normalizeSidebarItem(subItem);
4043
- })
4044
- };
4045
- }
4046
- if (typeof item === "string") {
4047
- const normalizedItem = normalizeLangPrefix(item, currentLang);
4048
- const page = pages.find(
4049
- (page2) => page2.routePath === withBase(normalizedItem, base)
4050
- );
4051
- return {
4052
- text: applyReplaceRules(page?.title || "", replaceRules),
4053
- link: normalizedItem
4054
- };
4055
- }
4056
- return {
4057
- text: applyReplaceRules(
4058
- getI18nText(item.text, currentLang),
4059
- replaceRules
4060
- ),
4061
- link: normalizeLangPrefix(item.link, currentLang),
4062
- tag: item.tag
4063
- };
4064
- };
4065
- Object.keys(sidebar).forEach((key) => {
4066
- const value = sidebar[key];
4067
- const normalizedKey = normalizeLangPrefix(key, currentLang);
4068
- normalizedSidebar[normalizedKey] = value.map(normalizeSidebarItem);
4069
- });
4070
- return normalizedSidebar;
4071
- };
4072
- const normalizeNav = (nav, currentLang) => {
4073
- if (!nav) {
4074
- return [];
4075
- }
4076
- return nav?.map((navItem) => {
4077
- const text = applyReplaceRules(
4078
- getI18nText(navItem.text, currentLang),
4079
- replaceRules
4080
- );
4081
- if ("link" in navItem) {
4082
- return {
4083
- ...navItem,
4084
- text,
4085
- link: normalizeLangPrefix(navItem.link, currentLang)
4086
- };
4087
- }
4088
- if ("items" in navItem) {
4089
- return {
4090
- ...navItem,
4091
- text,
4092
- items: navItem.items.map((item) => {
4093
- return {
4094
- ...item,
4095
- text: applyReplaceRules(
4096
- getI18nText(item.text, currentLang),
4097
- replaceRules
4098
- ),
4099
- link: normalizeLangPrefix(item.link, currentLang)
4100
- };
4101
- })
4102
- };
4103
- }
4104
- return navItem;
4105
- });
4106
- };
4107
- if (locales.length) {
4108
- themeConfig.locales = locales.map(({ lang: currentLang, label }) => {
4109
- const localeInThemeConfig = themeConfig.locales?.find(
4110
- (locale) => locale.lang === currentLang
4111
- );
4112
- return {
4113
- lang: currentLang,
4114
- label,
4115
- ...localeInThemeConfig || {},
4116
- sidebar: normalizeSidebar(
4117
- localeInThemeConfig?.sidebar ?? themeConfig.sidebar,
4118
- currentLang
4119
- ),
4120
- nav: normalizeNav(
4121
- localeInThemeConfig?.nav ?? themeConfig.nav,
4122
- currentLang
4123
- )
4124
- };
4125
- });
4126
- } else {
4127
- themeConfig.sidebar = normalizeSidebar(themeConfig?.sidebar);
4128
- themeConfig.nav = normalizeNav(themeConfig?.nav);
4129
- }
4130
- return themeConfig;
4131
- }
4145
+ // src/node/runtimeModule/siteData/extractPageData.ts
4132
4146
  async function extractPageData(replaceRules, alias, domain, root, routeService2) {
4133
4147
  return Promise.all(
4134
4148
  routeService2.getRoutes().filter((route) => MDX_REGEXP2.test(route.absolutePath)).map(async (route, index) => {
@@ -4147,7 +4161,7 @@ async function extractPageData(replaceRules, alias, domain, root, routeService2)
4147
4161
  }
4148
4162
  });
4149
4163
  const flattenContent = await flattenMdxContent(
4150
- strippedFrontMatter,
4164
+ applyReplaceRules(strippedFrontMatter, replaceRules),
4151
4165
  route.absolutePath,
4152
4166
  alias
4153
4167
  );
@@ -4232,6 +4246,20 @@ ${item.text}#
4232
4246
  })
4233
4247
  );
4234
4248
  }
4249
+
4250
+ // src/node/runtimeModule/siteData/index.ts
4251
+ function deletePriviteKey(obj) {
4252
+ if (typeof obj !== "object" || obj === null) {
4253
+ return obj;
4254
+ }
4255
+ const newObj = { ...obj };
4256
+ Object.keys(newObj).forEach((key) => {
4257
+ if (key.startsWith("_")) {
4258
+ delete newObj[key];
4259
+ }
4260
+ });
4261
+ return newObj;
4262
+ }
4235
4263
  async function siteDataVMPlugin(context) {
4236
4264
  const { config, alias, userDocRoot, routeService: routeService2, pluginDriver } = context;
4237
4265
  const userConfig = config;
@@ -4263,9 +4291,9 @@ async function siteDataVMPlugin(context) {
4263
4291
  );
4264
4292
  const indexHash = createHash(stringfiedIndex);
4265
4293
  indexHashByLang[lang] = indexHash;
4266
- await fs3.ensureDir(TEMP_DIR);
4267
- await fs3.writeFile(
4268
- path6.join(TEMP_DIR, `${SEARCH_INDEX_NAME}.${lang}.${indexHash}.json`),
4294
+ await fs4.ensureDir(TEMP_DIR);
4295
+ await fs4.writeFile(
4296
+ path7.join(TEMP_DIR, `${SEARCH_INDEX_NAME}.${lang}.${indexHash}.json`),
4269
4297
  stringfiedIndex
4270
4298
  );
4271
4299
  })
@@ -4343,15 +4371,15 @@ const Props_${index++} = ${JSON.stringify(source[1])};
4343
4371
  }
4344
4372
 
4345
4373
  // src/node/runtimeModule/globalStyles.ts
4346
- import fs4 from "@modern-js/utils/fs-extra";
4374
+ import fs5 from "@modern-js/utils/fs-extra";
4347
4375
  async function globalStylesVMPlugin(context) {
4348
4376
  const { config, pluginDriver } = context;
4349
4377
  const globalStylesByPlugins = pluginDriver.globalStyles();
4350
4378
  if (config.globalStyles) {
4351
4379
  const source = config.globalStyles;
4352
- const styleContent = await fs4.readFile(source, "utf-8");
4380
+ const styleContent = await fs5.readFile(source, "utf-8");
4353
4381
  const patchedStyleContent = styleContent.replace(/--modern-/g, "--rp-").replace(/\.modern-doc/g, ".rspress").replace(/\.modern-/g, ".rspress-");
4354
- await fs4.writeFile(source, patchedStyleContent, "utf-8");
4382
+ await fs5.writeFile(source, patchedStyleContent, "utf-8");
4355
4383
  }
4356
4384
  const moduleContent = (await Promise.all(
4357
4385
  [config?.globalStyles || "", ...globalStylesByPlugins].filter((source) => source.length > 0).map(async (source) => {
@@ -4364,12 +4392,12 @@ async function globalStylesVMPlugin(context) {
4364
4392
  }
4365
4393
 
4366
4394
  // src/node/runtimeModule/searchHooks.ts
4367
- import fs5 from "@modern-js/utils/fs-extra";
4395
+ import fs6 from "@modern-js/utils/fs-extra";
4368
4396
  async function searchHookVMPlugin(context) {
4369
4397
  const { config } = context;
4370
4398
  let content = "export const onSearch = () => {}";
4371
4399
  if (typeof config.search === "object" && typeof config.search.searchHooks === "string") {
4372
- content = await fs5.readFile(config.search.searchHooks, "utf-8");
4400
+ content = await fs6.readFile(config.search.searchHooks, "utf-8");
4373
4401
  }
4374
4402
  return {
4375
4403
  ["virtual-search-hooks" /* SearchHooks */]: content
@@ -4487,8 +4515,8 @@ function rsbuildPluginDocVM(factoryContext) {
4487
4515
  }
4488
4516
 
4489
4517
  // src/node/searchIndex.ts
4490
- import path7, { join as join2 } from "path";
4491
- import fs6 from "@modern-js/utils/fs-extra";
4518
+ import path8, { join as join2 } from "path";
4519
+ import fs7 from "@modern-js/utils/fs-extra";
4492
4520
  import chalk from "@modern-js/utils/chalk";
4493
4521
  import fetch from "node-fetch";
4494
4522
  import { isSCM, SEARCH_INDEX_NAME as SEARCH_INDEX_NAME2 } from "@rspress/shared";
@@ -4498,7 +4526,7 @@ async function writeSearchIndex(config) {
4498
4526
  return;
4499
4527
  }
4500
4528
  const cwd = process.cwd();
4501
- const searchIndexFiles = await fs6.readdir(TEMP_DIR);
4529
+ const searchIndexFiles = await fs7.readdir(TEMP_DIR);
4502
4530
  const outDir = config?.outDir ?? join2(cwd, OUTPUT_DIR);
4503
4531
  let searchIndexData = "[]";
4504
4532
  let scaning = false;
@@ -4508,12 +4536,12 @@ async function writeSearchIndex(config) {
4508
4536
  }
4509
4537
  const source = join2(TEMP_DIR, searchIndexFile);
4510
4538
  const target = join2(outDir, "static", searchIndexFile);
4511
- const searchIndex = await fs6.readFile(
4539
+ const searchIndex = await fs7.readFile(
4512
4540
  join2(TEMP_DIR, searchIndexFile),
4513
4541
  "utf-8"
4514
4542
  );
4515
4543
  searchIndexData = `${searchIndexData.slice(0, -1)}${scaning ? "," : ""}${searchIndex.slice(1)}`;
4516
- await fs6.move(source, target, { overwrite: true });
4544
+ await fs7.move(source, target, { overwrite: true });
4517
4545
  scaning = true;
4518
4546
  }
4519
4547
  if (isProduction() && isSCM() && config?.search?.mode === "remote") {
@@ -4545,8 +4573,8 @@ function serveSearchIndexMiddleware(config) {
4545
4573
  if (req.url?.includes(searchIndexRequestMatch)) {
4546
4574
  res.setHeader("Content-Type", "application/json");
4547
4575
  const searchIndexFile = req.url?.split("/").pop();
4548
- const searchIndex = fs6.readFileSync(
4549
- path7.join(
4576
+ const searchIndex = fs7.readFileSync(
4577
+ path8.join(
4550
4578
  process.cwd(),
4551
4579
  config?.outDir || OUTPUT_DIR,
4552
4580
  "static",
@@ -4562,8 +4590,8 @@ function serveSearchIndexMiddleware(config) {
4562
4590
  }
4563
4591
 
4564
4592
  // src/node/route/RouteService.ts
4565
- import path8 from "path";
4566
- import fs7 from "@modern-js/utils/fs-extra";
4593
+ import path9 from "path";
4594
+ import fs8 from "@modern-js/utils/fs-extra";
4567
4595
  import { withBase as withBase2 } from "@rspress/shared";
4568
4596
  var DEFAULT_PAGE_EXTENSIONS = ["js", "jsx", "ts", "tsx", "md", "mdx"];
4569
4597
  var addLeadingSlash3 = (str2) => {
@@ -4642,7 +4670,7 @@ var RouteService = class {
4642
4670
  }).sort();
4643
4671
  files.forEach((filePath) => {
4644
4672
  const fileRelativePath = normalizePath(
4645
- path8.relative(__privateGet(this, _scanDir), filePath)
4673
+ path9.relative(__privateGet(this, _scanDir), filePath)
4646
4674
  );
4647
4675
  const { routePath, lang, version } = normalizeRoutePath(
4648
4676
  fileRelativePath,
@@ -4650,7 +4678,7 @@ var RouteService = class {
4650
4678
  __privateGet(this, _base),
4651
4679
  __privateGet(this, _defaultVersion)
4652
4680
  );
4653
- const absolutePath = path8.join(__privateGet(this, _scanDir), fileRelativePath);
4681
+ const absolutePath = path9.join(__privateGet(this, _scanDir), fileRelativePath);
4654
4682
  const routeInfo = {
4655
4683
  routePath,
4656
4684
  absolutePath: normalizePath(absolutePath),
@@ -4683,10 +4711,10 @@ var RouteService = class {
4683
4711
  const { routePath, absolutePath } = routeInfo;
4684
4712
  if (this.routeData.has(routePath)) {
4685
4713
  const preRouteExtIndex = __privateGet(this, _extensions).indexOf(
4686
- path8.extname(this.routeData.get(routePath).absolutePath).slice(1)
4714
+ path9.extname(this.routeData.get(routePath).absolutePath).slice(1)
4687
4715
  );
4688
4716
  const currRouteExtIndex = __privateGet(this, _extensions).indexOf(
4689
- path8.extname(absolutePath).slice(1)
4717
+ path9.extname(absolutePath).slice(1)
4690
4718
  );
4691
4719
  if (currRouteExtIndex !== -1 && (currRouteExtIndex < preRouteExtIndex || preRouteExtIndex === -1)) {
4692
4720
  this.routeData.set(routePath, routeInfo);
@@ -4696,7 +4724,7 @@ var RouteService = class {
4696
4724
  }
4697
4725
  }
4698
4726
  removeRoute(filePath) {
4699
- const fileRelativePath = path8.relative(__privateGet(this, _scanDir), filePath);
4727
+ const fileRelativePath = path9.relative(__privateGet(this, _scanDir), filePath);
4700
4728
  const { routePath } = normalizeRoutePath(
4701
4729
  fileRelativePath,
4702
4730
  __privateGet(this, _defaultLang),
@@ -4754,8 +4782,8 @@ _tempDir = new WeakMap();
4754
4782
  _pluginDriver = new WeakMap();
4755
4783
  _writeTempFile = new WeakSet();
4756
4784
  writeTempFile_fn = async function(index, content) {
4757
- const tempFilePath = path8.join(__privateGet(this, _tempDir), `temp-${index}.mdx`);
4758
- await fs7.writeFile(tempFilePath, content);
4785
+ const tempFilePath = path9.join(__privateGet(this, _tempDir), `temp-${index}.mdx`);
4786
+ await fs8.writeFile(tempFilePath, content);
4759
4787
  return tempFilePath;
4760
4788
  };
4761
4789
  _generateRouteInfo = new WeakSet();
@@ -4773,7 +4801,7 @@ generateRouteInfo_fn = function(routePath, filepath) {
4773
4801
  return {
4774
4802
  routePath: normalizedPath,
4775
4803
  absolutePath: normalizePath(filepath),
4776
- relativePath: normalizePath(path8.relative(__privateGet(this, _scanDir), filepath)),
4804
+ relativePath: normalizePath(path9.relative(__privateGet(this, _scanDir), filepath)),
4777
4805
  pageName: getPageKey(routePath),
4778
4806
  lang,
4779
4807
  version
@@ -4797,15 +4825,15 @@ async function initRouteService(options2) {
4797
4825
  // src/node/initRsbuild.ts
4798
4826
  async function createInternalBuildConfig(userDocRoot, config, isSSR, routeService2, pluginDriver) {
4799
4827
  const cwd = process.cwd();
4800
- const { default: fs10 } = await import("@modern-js/utils/fs-extra");
4801
- const CUSTOM_THEME_DIR = config?.themeDir ?? path9.join(process.cwd(), "theme");
4828
+ const { default: fs11 } = await import("@modern-js/utils/fs-extra");
4829
+ const CUSTOM_THEME_DIR = config?.themeDir ?? path10.join(process.cwd(), "theme");
4802
4830
  const outDir = config?.outDir ?? OUTPUT_DIR;
4803
4831
  const DEFAULT_THEME = __require.resolve("@rspress/theme-default");
4804
- const themeDir = await fs10.pathExists(CUSTOM_THEME_DIR) ? CUSTOM_THEME_DIR : DEFAULT_THEME;
4832
+ const themeDir = await fs11.pathExists(CUSTOM_THEME_DIR) ? CUSTOM_THEME_DIR : DEFAULT_THEME;
4805
4833
  const checkDeadLinks = (config?.markdown?.checkDeadLinks && !isSSR) ?? false;
4806
4834
  const base = config?.base ?? "";
4807
- const publicDir = path9.join(userDocRoot, "public");
4808
- const isPublicDirExist = await fs10.pathExists(publicDir);
4835
+ const publicDir = path10.join(userDocRoot, "public");
4836
+ const isPublicDirExist = await fs11.pathExists(publicDir);
4809
4837
  const assetPrefix = isProduction() ? removeTrailingSlash(config?.builderConfig?.output?.assetPrefix ?? base) : "";
4810
4838
  const enableMdxRs = config?.markdown?.mdxRs ?? true;
4811
4839
  const reactVersion = await detectReactVersion();
@@ -4813,8 +4841,8 @@ async function createInternalBuildConfig(userDocRoot, config, isSSR, routeServic
4813
4841
  if (!icon) {
4814
4842
  return void 0;
4815
4843
  }
4816
- if (path9.isAbsolute(icon)) {
4817
- return path9.join(userDocRoot, PUBLIC_DIR, icon);
4844
+ if (path10.isAbsolute(icon)) {
4845
+ return path10.join(userDocRoot, PUBLIC_DIR, icon);
4818
4846
  }
4819
4847
  return icon;
4820
4848
  };
@@ -4833,13 +4861,13 @@ async function createInternalBuildConfig(userDocRoot, config, isSSR, routeServic
4833
4861
  },
4834
4862
  html: {
4835
4863
  favicon: normalizeIcon(config?.icon),
4836
- template: path9.join(PACKAGE_ROOT, "index.html"),
4864
+ template: path10.join(PACKAGE_ROOT, "index.html"),
4837
4865
  outputStructure: "nested"
4838
4866
  },
4839
4867
  output: {
4840
4868
  distPath: {
4841
4869
  // `root` must be a relative path in Rsbuild
4842
- root: path9.isAbsolute(outDir) ? path9.relative(cwd, outDir) : outDir,
4870
+ root: path10.isAbsolute(outDir) ? path10.relative(cwd, outDir) : outDir,
4843
4871
  html: "html"
4844
4872
  },
4845
4873
  // Disable production source map, it is useless for doc site
@@ -4854,14 +4882,14 @@ async function createInternalBuildConfig(userDocRoot, config, isSSR, routeServic
4854
4882
  "@/theme-default": DEFAULT_THEME,
4855
4883
  "@rspress/core": PACKAGE_ROOT,
4856
4884
  "react-lazy-with-preload": __require.resolve("react-lazy-with-preload"),
4857
- "react-syntax-highlighter": path9.dirname(
4885
+ "react-syntax-highlighter": path10.dirname(
4858
4886
  __require.resolve("react-syntax-highlighter/package.json")
4859
4887
  ),
4860
4888
  ...await resolveReactAlias(reactVersion)
4861
4889
  },
4862
4890
  include: [
4863
4891
  PACKAGE_ROOT,
4864
- path9.join(cwd, "node_modules", RSPRESS_TEMP_DIR2),
4892
+ path10.join(cwd, "node_modules", RSPRESS_TEMP_DIR2),
4865
4893
  /(.*?)\.tsx?$/
4866
4894
  ],
4867
4895
  define: {
@@ -4891,7 +4919,7 @@ async function createInternalBuildConfig(userDocRoot, config, isSSR, routeServic
4891
4919
  config: {
4892
4920
  ...tailwindConfig,
4893
4921
  content: [
4894
- path9.join(PACKAGE_ROOT, "src", "theme-default", "**/*")
4922
+ path10.join(PACKAGE_ROOT, "src", "theme-default", "**/*")
4895
4923
  ]
4896
4924
  }
4897
4925
  })
@@ -4924,11 +4952,11 @@ async function createInternalBuildConfig(userDocRoot, config, isSSR, routeServic
4924
4952
  }
4925
4953
  async function initRsbuild(rootDir, config, pluginDriver, isSSR = false, extraRsbuildConfig) {
4926
4954
  const cwd = process.cwd();
4927
- const userDocRoot = path9.resolve(rootDir || config?.root || cwd);
4955
+ const userDocRoot = path10.resolve(rootDir || config?.root || cwd);
4928
4956
  const builderPlugins = config?.builderPlugins ?? [];
4929
- const runtimeTempDir = path9.join(RSPRESS_TEMP_DIR2, "runtime");
4930
- const runtimeAbsTempDir = path9.join(cwd, "node_modules", runtimeTempDir);
4931
- await fs8.ensureDir(runtimeAbsTempDir);
4957
+ const runtimeTempDir = path10.join(RSPRESS_TEMP_DIR2, "runtime");
4958
+ const runtimeAbsTempDir = path10.join(cwd, "node_modules", runtimeTempDir);
4959
+ await fs9.ensureDir(runtimeAbsTempDir);
4932
4960
  const routeService2 = await initRouteService({
4933
4961
  config,
4934
4962
  runtimeTempDir: runtimeAbsTempDir,
@@ -5184,7 +5212,7 @@ async function dev(options2) {
5184
5212
  import { dirname as dirname2, join as join3 } from "path";
5185
5213
  import { pathToFileURL } from "url";
5186
5214
  import chalk2 from "@modern-js/utils/chalk";
5187
- import fs9 from "@modern-js/utils/fs-extra";
5215
+ import fs10 from "@modern-js/utils/fs-extra";
5188
5216
  import {
5189
5217
  APPEARANCE_KEY,
5190
5218
  normalizeSlash,
@@ -5227,8 +5255,8 @@ async function bundle(docDirectory, config, pluginDriver, enableSSG) {
5227
5255
  await clientBuilder.build();
5228
5256
  }
5229
5257
  const publicDir = join3(docDirectory, PUBLIC_DIR);
5230
- if (await fs9.pathExists(publicDir)) {
5231
- await fs9.copy(publicDir, outputDir);
5258
+ if (await fs10.pathExists(publicDir)) {
5259
+ await fs10.copy(publicDir, outputDir);
5232
5260
  }
5233
5261
  } finally {
5234
5262
  await writeSearchIndex(config);
@@ -5240,7 +5268,7 @@ async function renderPages(appDirectory, config, pluginDriver, enableSSG) {
5240
5268
  const outputPath = config?.outDir ?? join3(appDirectory, OUTPUT_DIR);
5241
5269
  const ssrBundlePath = join3(outputPath, "ssr", "bundles", "main.js");
5242
5270
  try {
5243
- const { default: fs10 } = await import("@modern-js/utils/fs-extra");
5271
+ const { default: fs11 } = await import("@modern-js/utils/fs-extra");
5244
5272
  let render = null;
5245
5273
  if (enableSSG) {
5246
5274
  try {
@@ -5256,7 +5284,7 @@ async function renderPages(appDirectory, config, pluginDriver, enableSSG) {
5256
5284
  const routes = routeService.getRoutes();
5257
5285
  const base = config?.base ?? "";
5258
5286
  const htmlTemplatePath = join3(outputPath, "html", "main", "index.html");
5259
- const htmlTemplate = await fs10.readFile(htmlTemplatePath, "utf-8");
5287
+ const htmlTemplate = await fs11.readFile(htmlTemplatePath, "utf-8");
5260
5288
  const additionalRoutes = (await pluginDriver.addSSGRoutes()).map((route) => ({
5261
5289
  routePath: withBase3(route.path, base)
5262
5290
  }));
@@ -5302,20 +5330,20 @@ async function renderPages(appDirectory, config, pluginDriver, enableSSG) {
5302
5330
  `${BODY_START_TAG} ${helmet?.bodyAttributes?.toString()}`
5303
5331
  );
5304
5332
  }
5305
- const normalizeHtmlFilePath = (path10) => {
5333
+ const normalizeHtmlFilePath = (path11) => {
5306
5334
  const normalizedBase = normalizeSlash(config?.base || "/");
5307
- if (path10.endsWith("/")) {
5308
- return `${path10}index.html`.replace(normalizedBase, "");
5335
+ if (path11.endsWith("/")) {
5336
+ return `${path11}index.html`.replace(normalizedBase, "");
5309
5337
  }
5310
- return `${path10}.html`.replace(normalizedBase, "");
5338
+ return `${path11}.html`.replace(normalizedBase, "");
5311
5339
  };
5312
5340
  const fileName = normalizeHtmlFilePath(routePath);
5313
- await fs10.ensureDir(join3(outputPath, dirname2(fileName)));
5314
- await fs10.writeFile(join3(outputPath, fileName), html);
5341
+ await fs11.ensureDir(join3(outputPath, dirname2(fileName)));
5342
+ await fs11.writeFile(join3(outputPath, fileName), html);
5315
5343
  })
5316
5344
  );
5317
- await fs10.remove(join3(outputPath, "ssr"));
5318
- await fs10.remove(join3(outputPath, "html"));
5345
+ await fs11.remove(join3(outputPath, "ssr"));
5346
+ await fs11.remove(join3(outputPath, "html"));
5319
5347
  const totalTime = Date.now() - startTime;
5320
5348
  logger5.success(`Pages rendered in ${chalk2.yellow(totalTime)} ms.`);
5321
5349
  } catch (e) {
@@ -5330,7 +5358,7 @@ async function build(options2) {
5330
5358
  await pluginDriver.init();
5331
5359
  const modifiedConfig = await pluginDriver.modifyConfig();
5332
5360
  await pluginDriver.beforeBuild();
5333
- await fs9.emptyDir(TEMP_DIR);
5361
+ await fs10.emptyDir(TEMP_DIR);
5334
5362
  await bundle(docDirectory, modifiedConfig, pluginDriver, enableSSG);
5335
5363
  await renderPages(appDirectory, modifiedConfig, pluginDriver, enableSSG);
5336
5364
  await pluginDriver.afterBuild();