@rspress/core 0.2.0 → 1.0.0-beta.1

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.
Files changed (38) hide show
  1. package/dist/index.js +29 -27
  2. package/dist/index.js.map +1 -1
  3. package/dist/loader.d.ts +0 -1
  4. package/dist/loader.js +14 -11
  5. package/dist/loader.js.map +1 -1
  6. package/dist/runtime/App.js +3 -4
  7. package/dist/runtime/Content.js +15 -8
  8. package/dist/runtime/hooks.d.ts +10 -0
  9. package/dist/runtime/hooks.js +6 -2
  10. package/dist/runtime/index.d.ts +1 -1
  11. package/dist/runtime/index.js +1 -1
  12. package/dist/runtime/utils.d.ts +3 -2
  13. package/dist/runtime/utils.js +6 -2
  14. package/dist/theme/bundle.css +5 -3
  15. package/dist/theme/bundle.js +45 -22
  16. package/dist/theme/bundle.js.map +1 -1
  17. package/package.json +6 -6
  18. package/src/runtime/App.tsx +4 -6
  19. package/src/runtime/Content.tsx +24 -11
  20. package/src/runtime/global.d.ts +4 -5
  21. package/src/runtime/hooks.ts +22 -2
  22. package/src/runtime/index.ts +1 -1
  23. package/src/runtime/utils.ts +9 -8
  24. package/src/theme-default/components/DocFooter/index.tsx +1 -1
  25. package/src/theme-default/components/HomeHero/index.tsx +1 -1
  26. package/src/theme-default/components/Link/index.module.scss +0 -1
  27. package/src/theme-default/components/Link/index.tsx +21 -2
  28. package/src/theme-default/components/Nav/NavMenuSingleItem.tsx +1 -1
  29. package/src/theme-default/components/Overview/index.tsx +1 -1
  30. package/src/theme-default/components/Search/logic/search.ts +1 -1
  31. package/src/theme-default/components/Sidebar/SidebarGroup.tsx +1 -1
  32. package/src/theme-default/components/Sidebar/SidebarItem.tsx +1 -1
  33. package/src/theme-default/layout/DocLayout/docComponents/index.module.scss +4 -0
  34. package/src/theme-default/layout/DocLayout/docComponents/link.tsx +14 -8
  35. package/src/theme-default/layout/DocLayout/docComponents/pre.tsx +1 -1
  36. package/src/theme-default/layout/HomeLayout/index.tsx +1 -0
  37. package/src/theme-default/logic/sideEffects.ts +7 -0
  38. package/src/theme-default/logic/usePathUtils.ts +2 -1
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import { logger as logger3 } from "@rspress/shared/logger";
4
4
 
5
5
  // src/node/createBuilder.ts
6
6
  import path8 from "path";
7
- import { createRequire as createRequire3 } from "module";
7
+ import { createRequire as createRequire2 } from "module";
8
8
  import fs8 from "@modern-js/utils/fs-extra";
9
9
  import { RSPRESS_TEMP_DIR as RSPRESS_TEMP_DIR2, isDebugMode, removeTrailingSlash } from "@rspress/shared";
10
10
  import sirv from "sirv";
@@ -150,15 +150,10 @@ function createHash(str) {
150
150
  return createHashFunc("sha256").update(str).digest("hex").slice(0, 8);
151
151
  }
152
152
 
153
- // src/node/utils/logger.ts
154
- import { createRequire } from "module";
155
- var require2 = createRequire(import.meta.url);
156
- var { logger } = require2("@modern-js/utils/logger");
157
-
158
153
  // src/node/utils/detectReactVersion.ts
159
154
  import path3 from "path";
160
155
  import fs from "@modern-js/utils/fs-extra";
161
- import { logger as logger2 } from "@rspress/shared/logger";
156
+ import { logger } from "@rspress/shared/logger";
162
157
  import enhancedResolve from "enhanced-resolve";
163
158
  var { CachedInputFileSystem, ResolverFactory } = enhancedResolve;
164
159
  var DEFAULT_REACT_VERSION = 18;
@@ -207,7 +202,7 @@ async function resolveReactAlias(reactVersion) {
207
202
  });
208
203
  } catch (e) {
209
204
  console.log(e);
210
- logger2.warn(`${lib} not found`);
205
+ logger.warn(`${lib} not found`);
211
206
  }
212
207
  }));
213
208
  return alias;
@@ -293,13 +288,13 @@ async function flattenMdxContent(content, basePath, alias) {
293
288
 
294
289
  // src/node/runtimeModule/i18n.ts
295
290
  import { join } from "path";
296
- import { createRequire as createRequire2 } from "module";
297
- var require3 = createRequire2(import.meta.url);
291
+ import { createRequire } from "module";
292
+ var require2 = createRequire(import.meta.url);
298
293
  var DEFAULT_I18N_SOURCE = join(process.cwd(), "i18n.json");
299
294
  function getI18nData(docConfig) {
300
295
  const { i18nSourcePath = DEFAULT_I18N_SOURCE } = docConfig;
301
296
  try {
302
- const i18nSource = require3(i18nSourcePath);
297
+ const i18nSource = require2(i18nSourcePath);
303
298
  return i18nSource;
304
299
  } catch (e) {
305
300
  return {};
@@ -555,6 +550,7 @@ async function siteDataVMPlugin(context) {
555
550
  title: userConfig?.title || "",
556
551
  description: userConfig?.description || "",
557
552
  icon: userConfig?.icon || "",
553
+ route: userConfig?.route,
558
554
  themeConfig: normalizeThemeConfig(userConfig, pages),
559
555
  base: userConfig?.base || "/",
560
556
  lang: userConfig?.lang || "",
@@ -646,7 +642,7 @@ async function searchHookVMPlugin(context) {
646
642
  content = await fs5.readFile(config.search.searchHooks, "utf-8");
647
643
  }
648
644
  return {
649
- [`${RuntimeModuleID.SearchHooks}.ts`]: content
645
+ [RuntimeModuleID.SearchHooks]: content
650
646
  };
651
647
  }
652
648
 
@@ -724,6 +720,7 @@ import fs6 from "@modern-js/utils/fs-extra";
724
720
  import chalk from "@modern-js/utils/chalk";
725
721
  import fetch from "node-fetch";
726
722
  import { isSCM, SEARCH_INDEX_NAME as SEARCH_INDEX_NAME2 } from "@rspress/shared";
723
+ import { logger as logger2 } from "@rspress/shared/logger";
727
724
  async function writeSearchIndex(config) {
728
725
  if (config?.search === false) {
729
726
  return;
@@ -756,9 +753,9 @@ async function writeSearchIndex(config) {
756
753
  "Content-Type": "application/json"
757
754
  }
758
755
  });
759
- logger.info(chalk.green(`[doc-tools] Search index uploaded to ${apiUrl}, indexName: ${indexName}`));
756
+ logger2.info(chalk.green(`[doc-tools] Search index uploaded to ${apiUrl}, indexName: ${indexName}`));
760
757
  } catch (e) {
761
- logger.info(chalk.red(`[doc-tools] Upload search index \`${indexName}\` failed:
758
+ logger2.info(chalk.red(`[doc-tools] Upload search index \`${indexName}\` failed:
762
759
  ${e}`));
763
760
  }
764
761
  }
@@ -856,6 +853,7 @@ var addLeadingSlash3 = (str) => {
856
853
  return str.startsWith("/") ? str : `/${str}`;
857
854
  };
858
855
  var normalizeRoutePath = (routePath, lang, base, version) => {
856
+ const hasTrailSlash = routePath.endsWith("/");
859
857
  let versionPart = "";
860
858
  let langPart = "";
861
859
  let purePathPart = "";
@@ -873,11 +871,14 @@ var normalizeRoutePath = (routePath, lang, base, version) => {
873
871
  }
874
872
  }
875
873
  purePathPart = parts.join("/");
876
- const normalizedRoutePath = addLeadingSlash3([
874
+ let normalizedRoutePath = addLeadingSlash3([
877
875
  versionPart,
878
876
  langPart,
879
877
  purePathPart
880
878
  ].filter(Boolean).join("/")).replace(/\.[^.]+$/, "").replace(/\/index$/, "/");
879
+ if (hasTrailSlash && !normalizedRoutePath.endsWith("/")) {
880
+ normalizedRoutePath = `${normalizedRoutePath}/`;
881
+ }
881
882
  return {
882
883
  routePath: withBase2(normalizedRoutePath, base),
883
884
  lang: langPart || lang,
@@ -1071,7 +1072,7 @@ async function initRouteService(options) {
1071
1072
  }
1072
1073
 
1073
1074
  // src/node/createBuilder.ts
1074
- var require4 = createRequire3(import.meta.url);
1075
+ var require3 = createRequire2(import.meta.url);
1075
1076
  async function createInternalBuildConfig(userDocRoot, config, isSSR, routeService2, pluginDriver) {
1076
1077
  const cwd = process.cwd();
1077
1078
  const { default: fs10 } = await import("@modern-js/utils/fs-extra");
@@ -1136,12 +1137,12 @@ async function createInternalBuildConfig(userDocRoot, config, isSSR, routeServic
1136
1137
  },
1137
1138
  source: {
1138
1139
  alias: {
1139
- "@mdx-js/react": require4.resolve("@mdx-js/react"),
1140
+ "@mdx-js/react": require3.resolve("@mdx-js/react"),
1140
1141
  "@/runtime": path8.join(PACKAGE_ROOT, "dist", "runtime"),
1141
1142
  "@theme": themeDir,
1142
1143
  "@/theme-default": DEFAULT_THEME_DIR,
1143
1144
  "@rspress/core": PACKAGE_ROOT,
1144
- "react-lazy-with-preload": require4.resolve("react-lazy-with-preload"),
1145
+ "react-lazy-with-preload": require3.resolve("react-lazy-with-preload"),
1145
1146
  ...await resolveReactAlias(reactVersion)
1146
1147
  },
1147
1148
  include: [
@@ -1171,7 +1172,7 @@ async function createInternalBuildConfig(userDocRoot, config, isSSR, routeServic
1171
1172
  },
1172
1173
  postcss(config2) {
1173
1174
  if (isDebugMode()) {
1174
- config2.postcssOptions.plugins.push(require4("tailwindcss")({
1175
+ config2.postcssOptions.plugins.push(require3("tailwindcss")({
1175
1176
  config: {
1176
1177
  ...tailwindConfig,
1177
1178
  content: [
@@ -1189,14 +1190,14 @@ async function createInternalBuildConfig(userDocRoot, config, isSSR, routeServic
1189
1190
  }
1190
1191
  },
1191
1192
  bundlerChain(chain) {
1192
- chain.module.rule("MDX").type("jsx").test(/\.mdx?$/).oneOf("MDXCompile").use("mdx-loader").loader(require4.resolve("../loader.cjs")).options({
1193
+ chain.module.rule("MDX").type("jsx").test(/\.mdx?$/).oneOf("MDXCompile").use("mdx-loader").loader(require3.resolve("../loader.cjs")).options({
1193
1194
  config,
1194
1195
  docDirectory: userDocRoot,
1195
1196
  checkDeadLinks,
1196
1197
  enableMdxRs,
1197
1198
  routeService: routeService2,
1198
1199
  pluginDriver
1199
- }).end().use("string-replace-loader").loader(require4.resolve("string-replace-loader")).options({
1200
+ }).end().use("string-replace-loader").loader(require3.resolve("string-replace-loader")).options({
1200
1201
  multiple: config?.replaceRules || []
1201
1202
  });
1202
1203
  chain.resolve.extensions.prepend(".md").prepend(".mdx").prepend(".mjs");
@@ -1441,6 +1442,7 @@ import { pathToFileURL } from "url";
1441
1442
  import chalk2 from "@modern-js/utils/chalk";
1442
1443
  import fs9 from "@modern-js/utils/fs-extra";
1443
1444
  import { APPEARANCE_KEY, normalizeSlash, withBase as withBase3 } from "@rspress/shared";
1445
+ import { logger as logger4 } from "@rspress/shared/logger";
1444
1446
  var CHECK_DARK_LIGHT_SCRIPT = `
1445
1447
  <script id="check-dark-light">
1446
1448
  ;(() => {
@@ -1478,7 +1480,7 @@ async function bundle(appDirectory, docDirectory, config, pluginDriver) {
1478
1480
  }
1479
1481
  }
1480
1482
  async function renderPages(appDirectory, config, pluginDriver) {
1481
- logger.info("Rendering pages...");
1483
+ logger4.info("Rendering pages...");
1482
1484
  const startTime = Date.now();
1483
1485
  const outputPath = config?.outDir ?? join3(appDirectory, OUTPUT_DIR);
1484
1486
  const ssrBundlePath = join3(outputPath, "ssr", "bundles", "main.js");
@@ -1489,8 +1491,8 @@ async function renderPages(appDirectory, config, pluginDriver) {
1489
1491
  const { default: ssrExports } = await import(pathToFileURL(ssrBundlePath).toString());
1490
1492
  ({ render } = ssrExports);
1491
1493
  } catch (e) {
1492
- logger.error(e);
1493
- logger.warn(`Failed to load SSR bundle: ${ssrBundlePath}, fallback to CSR.`);
1494
+ logger4.error(e);
1495
+ logger4.warn(`Failed to load SSR bundle: ${ssrBundlePath}, fallback to CSR.`);
1494
1496
  }
1495
1497
  const routes = routeService.getRoutes();
1496
1498
  const base = config?.base ?? "";
@@ -1514,7 +1516,7 @@ async function renderPages(appDirectory, config, pluginDriver) {
1514
1516
  try {
1515
1517
  ({ appHtml } = await render(routePath, helmetContext.context));
1516
1518
  } catch (e) {
1517
- logger.warn(`page "${routePath}" render error: ${e.message}, fallback to CSR.`);
1519
+ logger4.warn(`page "${routePath}" render error: ${e.message}, fallback to CSR.`);
1518
1520
  }
1519
1521
  }
1520
1522
  const { helmet } = helmetContext.context;
@@ -1546,9 +1548,9 @@ async function renderPages(appDirectory, config, pluginDriver) {
1546
1548
  await fs10.remove(join3(outputPath, "ssr"));
1547
1549
  await fs10.remove(join3(outputPath, "html"));
1548
1550
  const totalTime = Date.now() - startTime;
1549
- logger.success(`Pages rendered in ${chalk2.yellow(totalTime)} ms.`);
1551
+ logger4.success(`Pages rendered in ${chalk2.yellow(totalTime)} ms.`);
1550
1552
  } catch (e) {
1551
- logger.error(`Pages render error: ${e.stack}`);
1553
+ logger4.error(`Pages render error: ${e.stack}`);
1552
1554
  throw e;
1553
1555
  }
1554
1556
  }