@rspress/core 0.0.2 → 0.0.3

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 (53) hide show
  1. package/dist/index.d.ts +10 -1
  2. package/dist/index.js +63 -52
  3. package/dist/index.js.map +1 -1
  4. package/dist/loader.js +2 -1
  5. package/dist/loader.js.map +1 -1
  6. package/dist/theme/bundle.css +318 -318
  7. package/dist/theme/bundle.js +35 -35
  8. package/dist/theme/bundle.js.map +1 -1
  9. package/package.json +5 -5
  10. package/src/theme-default/assets/loading.svg +1 -1
  11. package/src/theme-default/components/BackDrop/index.module.scss +1 -1
  12. package/src/theme-default/components/Button/index.module.scss +9 -9
  13. package/src/theme-default/components/DocFooter/index.module.scss +5 -5
  14. package/src/theme-default/components/EditLink/index.module.scss +1 -1
  15. package/src/theme-default/components/HomeFeatures/index.module.scss +3 -3
  16. package/src/theme-default/components/HomeFeatures/index.tsx +4 -4
  17. package/src/theme-default/components/HomeHero/index.module.scss +3 -3
  18. package/src/theme-default/components/HomeHero/index.tsx +1 -1
  19. package/src/theme-default/components/Link/index.module.scss +1 -1
  20. package/src/theme-default/components/LocalSideBar/index.module.scss +5 -5
  21. package/src/theme-default/components/Nav/NavMenuGroup.tsx +3 -3
  22. package/src/theme-default/components/Nav/index.module.scss +8 -8
  23. package/src/theme-default/components/Nav/index.tsx +4 -4
  24. package/src/theme-default/components/NavHambmger/index.module.scss +1 -1
  25. package/src/theme-default/components/NavScreen/index.module.scss +4 -4
  26. package/src/theme-default/components/NavScreenMenuGroup/index.module.scss +1 -1
  27. package/src/theme-default/components/Overview/index.module.scss +7 -7
  28. package/src/theme-default/components/Search/assets/loading.svg +1 -1
  29. package/src/theme-default/components/Search/assets/search.svg +1 -1
  30. package/src/theme-default/components/Search/index.module.scss +21 -21
  31. package/src/theme-default/components/Search/index.tsx +1 -1
  32. package/src/theme-default/components/Sidebar/index.module.scss +14 -14
  33. package/src/theme-default/components/Sidebar/index.tsx +5 -5
  34. package/src/theme-default/components/SocialLinks/HiddenLinks.tsx +2 -2
  35. package/src/theme-default/components/SocialLinks/LinkContent.tsx +3 -3
  36. package/src/theme-default/components/SocialLinks/index.module.scss +2 -2
  37. package/src/theme-default/components/SwitchAppearance/index.tsx +1 -1
  38. package/src/theme-default/components/Tabs/index.module.scss +5 -5
  39. package/src/theme-default/layout/DocLayout/docComponents/code.tsx +1 -1
  40. package/src/theme-default/layout/DocLayout/docComponents/index.module.scss +7 -7
  41. package/src/theme-default/layout/DocLayout/docComponents/pre.tsx +2 -2
  42. package/src/theme-default/layout/DocLayout/index.module.scss +14 -16
  43. package/src/theme-default/layout/DocLayout/index.tsx +3 -3
  44. package/src/theme-default/layout/HomeLayout/index.css +10 -10
  45. package/src/theme-default/layout/HomeLayout/index.tsx +1 -1
  46. package/src/theme-default/layout/Layout/index.tsx +1 -1
  47. package/src/theme-default/logic/sideEffects.ts +1 -1
  48. package/src/theme-default/styles/base.css +8 -8
  49. package/src/theme-default/styles/doc/code.css +57 -54
  50. package/src/theme-default/styles/doc/container.css +49 -49
  51. package/src/theme-default/styles/doc/index.css +1 -1
  52. package/src/theme-default/styles/scrollbar.css +2 -2
  53. package/src/theme-default/styles/vars.css +48 -52
package/dist/index.d.ts CHANGED
@@ -4,10 +4,19 @@ export * from '@rspress/shared';
4
4
  interface ServerInstance {
5
5
  close: () => Promise<void>;
6
6
  }
7
+ interface Logger {
8
+ info: (msg: string) => void;
9
+ error: (msg: string) => void;
10
+ warn: (msg: string) => void;
11
+ success: (msg: string) => void;
12
+ debug: (msg: string) => void;
13
+ log: (msg: string) => void;
14
+ }
7
15
  interface DevOptions {
8
16
  appDirectory: string;
9
17
  docDirectory: string;
10
18
  config: UserConfig;
19
+ logger: Logger;
11
20
  }
12
21
  declare function dev(options: DevOptions): Promise<ServerInstance>;
13
22
 
@@ -25,4 +34,4 @@ interface ServeOptions {
25
34
  }
26
35
  declare function serve(options: ServeOptions): Promise<void>;
27
36
 
28
- export { build, dev, serve };
37
+ export { Logger, build, dev, serve };
package/dist/index.js CHANGED
@@ -1,13 +1,13 @@
1
1
  // src/node/dev.ts
2
2
  import { removeLeadingSlash as removeLeadingSlash2 } from "@rspress/shared";
3
- import fs9 from "@modern-js/utils/fs-extra";
3
+ import fs10 from "@modern-js/utils/fs-extra";
4
4
 
5
5
  // src/node/createBuilder.ts
6
6
  import path9 from "path";
7
7
  import { createRequire as createRequire3 } from "module";
8
8
  import { isDebugMode, removeTrailingSlash } from "@rspress/shared";
9
9
  import sirv from "sirv";
10
- import fs8 from "@modern-js/utils/fs-extra";
10
+ import fs9 from "@modern-js/utils/fs-extra";
11
11
 
12
12
  // tailwind.config.ts
13
13
  var tailwindConfig = {
@@ -16,9 +16,9 @@ var tailwindConfig = {
16
16
  theme: {
17
17
  backgroundColor: (ctx) => ({
18
18
  ...ctx.theme("colors"),
19
- white: "var(--modern-c-bg)",
20
- soft: "var(--modern-c-bg-soft)",
21
- mute: "var(--modern-c-bg-mute)"
19
+ white: "var(--rp-c-bg)",
20
+ soft: "var(--rp-c-bg-soft)",
21
+ mute: "var(--rp-c-bg-mute)"
22
22
  }),
23
23
  extend: {
24
24
  borderRadius: {
@@ -38,30 +38,30 @@ var tailwindConfig = {
38
38
  },
39
39
  colors: {
40
40
  brand: {
41
- DEFAULT: "var(--modern-c-brand)",
42
- light: "var(--modern-c-brand-light)",
43
- dark: "var(--modern-c-brand-dark)",
44
- lighter: "var(--modern-c-brand-lighter)",
45
- darker: "var(--modern-c-brand-darker)"
41
+ DEFAULT: "var(--rp-c-brand)",
42
+ light: "var(--rp-c-brand-light)",
43
+ dark: "var(--rp-c-brand-dark)",
44
+ lighter: "var(--rp-c-brand-lighter)",
45
+ darker: "var(--rp-c-brand-darker)"
46
46
  },
47
47
  text: {
48
- 1: "var(--modern-c-text-1)",
49
- 2: "var(--modern-c-text-2)",
50
- 3: "var(--modern-c-text-3)",
51
- 4: "var(--modern-c-text-4)"
48
+ 1: "var(--rp-c-text-1)",
49
+ 2: "var(--rp-c-text-2)",
50
+ 3: "var(--rp-c-text-3)",
51
+ 4: "var(--rp-c-text-4)"
52
52
  },
53
53
  divider: {
54
- DEFAULT: "var(--modern-c-divider)",
55
- light: "var(--modern-c-divider-light)",
56
- dark: "var(--modern-c-divider-dark)"
54
+ DEFAULT: "var(--rp-c-divider)",
55
+ light: "var(--rp-c-divider-light)",
56
+ dark: "var(--rp-c-divider-dark)"
57
57
  },
58
58
  gray: {
59
59
  light: {
60
- 1: "var(--modern-c-gray-light-1)",
61
- 2: "var(--modern-c-gray-light-2)",
62
- 3: "var(--modern-c-gray-light-3)",
63
- 4: "var(--modern-c-gray-light-4)",
64
- 5: "var(--modern-c-gray-light-5)"
60
+ 1: "var(--rp-c-gray-light-1)",
61
+ 2: "var(--rp-c-gray-light-2)",
62
+ 3: "var(--rp-c-gray-light-3)",
63
+ 4: "var(--rp-c-gray-light-4)",
64
+ 5: "var(--rp-c-gray-light-5)"
65
65
  }
66
66
  }
67
67
  }
@@ -72,6 +72,7 @@ var tailwindConfig = {
72
72
  // src/node/constants.ts
73
73
  import path from "path";
74
74
  import { fileURLToPath } from "url";
75
+ import { RSPRESS_TEMP_DIR } from "@rspress/shared";
75
76
  var isProduction = () => process.env.NODE_ENV === "production";
76
77
  var importStatementRegex = /import\s+(.*?)\s+from\s+['"](.*?)['"];?/gm;
77
78
  var dirname = path.dirname(fileURLToPath(new URL(import.meta.url)));
@@ -84,7 +85,7 @@ var HEAD_MARKER = "<!--<?- HEAD ?>-->";
84
85
  var HTML_START_TAG = "<html";
85
86
  var BODY_START_TAG = "<body";
86
87
  var PUBLIC_DIR = "public";
87
- var TEMP_DIR = path.join(process.cwd(), "node_modules", ".modern-doc");
88
+ var TEMP_DIR = path.join(process.cwd(), "node_modules", RSPRESS_TEMP_DIR);
88
89
 
89
90
  // src/node/runtimeModule/routeData.ts
90
91
  import { join } from "path";
@@ -560,15 +561,12 @@ ${item.text}#
560
561
  }));
561
562
  }
562
563
  async function siteDataVMPlugin(context) {
563
- const { runtimeTempDir, config, isSSR, alias, userRoot, routeService: routeService2, pluginDriver } = context;
564
+ const { runtimeTempDir, config, alias, userRoot, routeService: routeService2, pluginDriver } = context;
564
565
  const entryPath = join3(runtimeTempDir, `${RuntimeModuleID.SiteData}.mjs`);
565
566
  const searchIndexHashPath = join3(runtimeTempDir, `${RuntimeModuleID.SearchIndexHash}.js`);
566
567
  const userConfig = config;
567
568
  const replaceRules = userConfig?.replaceRules || [];
568
569
  if (!pages) {
569
- if (!isSSR) {
570
- logger.info("Extracting site data...");
571
- }
572
570
  const domain = userConfig?.search && userConfig?.search?.mode === "remote" ? userConfig?.search.domain ?? "" : "";
573
571
  pages = (await extractPageData(replaceRules, alias, domain, userRoot, routeService2)).filter(Boolean);
574
572
  await pluginDriver.modifySearchIndexData(pages);
@@ -638,14 +636,21 @@ async function globalUIComponentsVMPlugin(context) {
638
636
 
639
637
  // src/node/runtimeModule/globalStyles.ts
640
638
  import { join as join5 } from "path";
639
+ import fs5 from "@modern-js/utils/fs-extra";
641
640
  async function globalStylesVMPlugin(context) {
642
641
  const { runtimeTempDir, config, pluginDriver } = context;
643
642
  const modulePath = join5(runtimeTempDir, `${RuntimeModuleID.GlobalStyles}.js`);
644
643
  const globalStylesByPlugins = pluginDriver.globalStyles();
645
- const moduleContent = [
644
+ const moduleContent = (await Promise.all([
646
645
  config?.globalStyles || "",
647
646
  ...globalStylesByPlugins
648
- ].filter((source) => source.length > 0).map((source) => `import ${JSON.stringify(source)};`).join("");
647
+ ].filter((source) => source.length > 0).map(async (source) => {
648
+ const styleContent = await fs5.readFile(source, "utf-8");
649
+ const patchedStyleContent = styleContent.replace(/--modern-/g, "--rp-").replace(/\.modern-doc/g, ".rspress").replace(/\.modern-/g, ".rspress-");
650
+ await fs5.writeFile(source, patchedStyleContent, "utf-8");
651
+ console.log(`[globalStylesVMPlugin] patched ${source}`);
652
+ return `import ${JSON.stringify(source)};`;
653
+ }))).join("");
649
654
  return new RuntimeModulesPlugin({
650
655
  [modulePath]: moduleContent
651
656
  });
@@ -653,12 +658,12 @@ async function globalStylesVMPlugin(context) {
653
658
 
654
659
  // src/node/runtimeModule/searchHooks.ts
655
660
  import { join as join6 } from "path";
656
- import fs5 from "@modern-js/utils/fs-extra";
661
+ import fs6 from "@modern-js/utils/fs-extra";
657
662
  async function searchHookVMPlugin(context) {
658
663
  const { config } = context;
659
664
  let content = "export const onSearch = () => {}";
660
665
  if (typeof config.search === "object" && typeof config.search.searchHooks === "string") {
661
- content = await fs5.readFile(config.search.searchHooks, "utf-8");
666
+ content = await fs6.readFile(config.search.searchHooks, "utf-8");
662
667
  }
663
668
  const modulePath = join6(context.runtimeTempDir, `${RuntimeModuleID.SearchHooks}.ts`);
664
669
  return new RuntimeModulesPlugin({
@@ -734,7 +739,7 @@ var runtimeModuleIDs = [
734
739
 
735
740
  // src/node/searchIndex.ts
736
741
  import path7, { join as join7 } from "path";
737
- import fs6 from "@modern-js/utils/fs-extra";
742
+ import fs7 from "@modern-js/utils/fs-extra";
738
743
  import chalk from "@modern-js/utils/chalk";
739
744
  import fetch from "node-fetch";
740
745
  import { isSCM, SEARCH_INDEX_NAME as SEARCH_INDEX_NAME2 } from "@rspress/shared";
@@ -743,7 +748,7 @@ async function writeSearchIndex(config) {
743
748
  return;
744
749
  }
745
750
  const cwd = process.cwd();
746
- const searchIndexFiles = await fs6.readdir(TEMP_DIR);
751
+ const searchIndexFiles = await fs7.readdir(TEMP_DIR);
747
752
  const outDir = config?.outDir ?? join7(cwd, OUTPUT_DIR);
748
753
  let searchIndexData = "[]";
749
754
  let scaning = false;
@@ -753,9 +758,9 @@ async function writeSearchIndex(config) {
753
758
  }
754
759
  const source = join7(TEMP_DIR, searchIndexFile);
755
760
  const target = join7(outDir, "static", searchIndexFile);
756
- const searchIndex = await fs6.readFile(join7(TEMP_DIR, searchIndexFile), "utf-8");
761
+ const searchIndex = await fs7.readFile(join7(TEMP_DIR, searchIndexFile), "utf-8");
757
762
  searchIndexData = `${searchIndexData.slice(0, -1)}${scaning ? "," : ""}${searchIndex.slice(1)}`;
758
- await fs6.move(source, target, {
763
+ await fs7.move(source, target, {
759
764
  overwrite: true
760
765
  });
761
766
  scaning = true;
@@ -783,7 +788,7 @@ function serveSearchIndexMiddleware(config) {
783
788
  if (req.url?.includes(searchIndexRequestMatch)) {
784
789
  res.setHeader("Content-Type", "application/json");
785
790
  const searchIndexFile = req.url?.split("/").pop();
786
- const searchIndex = fs6.readFileSync(path7.join(process.cwd(), config?.outDir || OUTPUT_DIR, "static", searchIndexFile), "utf-8");
791
+ const searchIndex = fs7.readFileSync(path7.join(process.cwd(), config?.outDir || OUTPUT_DIR, "static", searchIndexFile), "utf-8");
787
792
  res.end(searchIndex);
788
793
  } else {
789
794
  next?.();
@@ -793,7 +798,7 @@ function serveSearchIndexMiddleware(config) {
793
798
 
794
799
  // src/node/route/RouteService.ts
795
800
  import path8 from "path";
796
- import fs7 from "@modern-js/utils/fs-extra";
801
+ import fs8 from "@modern-js/utils/fs-extra";
797
802
  import { withBase as withBase2 } from "@rspress/shared";
798
803
  function _check_private_redeclaration2(obj, privateCollection) {
799
804
  if (privateCollection.has(obj)) {
@@ -1033,7 +1038,7 @@ ${this.getRoutes().map((route, index) => {
1033
1038
  };
1034
1039
  async function writeTempFile(index, content) {
1035
1040
  const tempFilePath = path8.join(_class_private_field_get(this, _tempDir), `temp-${index}.mdx`);
1036
- await fs7.writeFile(tempFilePath, content);
1041
+ await fs8.writeFile(tempFilePath, content);
1037
1042
  return tempFilePath;
1038
1043
  }
1039
1044
  function getLang(filepath) {
@@ -1092,7 +1097,8 @@ async function createInternalBuildConfig(userRoot, config, isSSR, runtimeTempDir
1092
1097
  };
1093
1098
  return {
1094
1099
  dev: {
1095
- port: process.env.PORT ? Number(process.env.PORT) : void 0
1100
+ port: process.env.PORT ? Number(process.env.PORT) : void 0,
1101
+ progressBar: false
1096
1102
  },
1097
1103
  html: {
1098
1104
  favicon: config?.icon,
@@ -1179,7 +1185,7 @@ async function createModernBuilder(rootDir, config, pluginDriver, isSSR = false,
1179
1185
  const userRoot = path9.resolve(rootDir || config?.root || cwd);
1180
1186
  const builderPlugins = config?.builderPlugins ?? [];
1181
1187
  const runtimeTempDir = path9.join(TEMP_DIR, "runtime");
1182
- await fs8.ensureDir(runtimeTempDir);
1188
+ await fs9.ensureDir(runtimeTempDir);
1183
1189
  const routeService2 = await initRouteService({
1184
1190
  config,
1185
1191
  runtimeTempDir,
@@ -1196,7 +1202,8 @@ async function createModernBuilder(rootDir, config, pluginDriver, isSSR = false,
1196
1202
  target: isSSR ? "node" : "web",
1197
1203
  entry: {
1198
1204
  main: isSSR ? SSR_ENTRY : CLIENT_ENTRY
1199
- }
1205
+ },
1206
+ framework: "Rspress"
1200
1207
  });
1201
1208
  builder.addPlugins([
1202
1209
  builderDocVMPlugin({
@@ -1378,7 +1385,7 @@ async function dev(options) {
1378
1385
  try {
1379
1386
  const modifiedConfig = await pluginDriver.modifyConfig();
1380
1387
  await pluginDriver.beforeBuild();
1381
- await fs9.emptyDir(TEMP_DIR);
1388
+ await fs10.emptyDir(TEMP_DIR);
1382
1389
  const builder = await createModernBuilder(docDirectory, modifiedConfig, pluginDriver, false, {});
1383
1390
  const { server } = await builder.startDevServer({
1384
1391
  printURLs: (urls) => {
@@ -1386,7 +1393,11 @@ async function dev(options) {
1386
1393
  label,
1387
1394
  url: `${url}/${removeLeadingSlash2(base)}`
1388
1395
  }));
1389
- }
1396
+ },
1397
+ // We will support the following options in the future
1398
+ // @ts-expect-error
1399
+ getPortSilently: true,
1400
+ logger: options.logger
1390
1401
  });
1391
1402
  await pluginDriver.afterBuild();
1392
1403
  return server;
@@ -1399,7 +1410,7 @@ async function dev(options) {
1399
1410
  import { dirname as dirname2, isAbsolute, join as join8 } from "path";
1400
1411
  import { pathToFileURL } from "url";
1401
1412
  import chalk2 from "@modern-js/utils/chalk";
1402
- import fs10 from "@modern-js/utils/fs-extra";
1413
+ import fs11 from "@modern-js/utils/fs-extra";
1403
1414
  import { APPEARANCE_KEY, normalizeSlash, withBase as withBase3 } from "@rspress/shared";
1404
1415
  var CHECK_DARK_LIGHT_SCRIPT = `
1405
1416
  <script id="check-dark-light">
@@ -1441,7 +1452,7 @@ async function bundle(appDirectory, docDirectory, config, pluginDriver) {
1441
1452
  const normalize = (rawPath) => isAbsolute(rawPath) ? rawPath : join8(appDirectory, rawPath);
1442
1453
  const logoPath = join8(normalize(docDirectory || config.root), PUBLIC_DIR, p);
1443
1454
  const outputLogoPath = join8(normalize(outputDir), p);
1444
- fs10.copyFileSync(logoPath, outputLogoPath);
1455
+ fs11.copyFileSync(logoPath, outputLogoPath);
1445
1456
  });
1446
1457
  } finally {
1447
1458
  await writeSearchIndex(config);
@@ -1453,7 +1464,7 @@ async function renderPages(appDirectory, config, pluginDriver) {
1453
1464
  const outputPath = config?.outDir ?? join8(appDirectory, OUTPUT_DIR);
1454
1465
  const ssrBundlePath = join8(outputPath, "ssr", "bundles", "main.js");
1455
1466
  try {
1456
- const { default: fs11 } = await import("@modern-js/utils/fs-extra");
1467
+ const { default: fs12 } = await import("@modern-js/utils/fs-extra");
1457
1468
  let render = null;
1458
1469
  try {
1459
1470
  const { default: ssrExports } = await import(pathToFileURL(ssrBundlePath).toString());
@@ -1464,7 +1475,7 @@ async function renderPages(appDirectory, config, pluginDriver) {
1464
1475
  const routes = routeService.getRoutes();
1465
1476
  const base = config?.base ?? "";
1466
1477
  const htmlTemplatePath = join8(outputPath, "html", "main", "index.html");
1467
- const htmlTemplate = await fs11.readFile(htmlTemplatePath, "utf-8");
1478
+ const htmlTemplate = await fs12.readFile(htmlTemplatePath, "utf-8");
1468
1479
  const additionalRoutes = (await pluginDriver.addSSGRoutes()).map((route) => ({
1469
1480
  routePath: withBase3(route.path, base)
1470
1481
  }));
@@ -1509,11 +1520,11 @@ async function renderPages(appDirectory, config, pluginDriver) {
1509
1520
  return `${path10}.html`.replace(normalizedBase, "");
1510
1521
  };
1511
1522
  const fileName = normalizeHtmlFilePath(routePath);
1512
- await fs11.ensureDir(join8(outputPath, dirname2(fileName)));
1513
- await fs11.writeFile(join8(outputPath, fileName), html);
1523
+ await fs12.ensureDir(join8(outputPath, dirname2(fileName)));
1524
+ await fs12.writeFile(join8(outputPath, fileName), html);
1514
1525
  }));
1515
- await fs11.remove(join8(outputPath, "ssr"));
1516
- await fs11.remove(join8(outputPath, "html"));
1526
+ await fs12.remove(join8(outputPath, "ssr"));
1527
+ await fs12.remove(join8(outputPath, "html"));
1517
1528
  const totalTime = Date.now() - startTime;
1518
1529
  logger.success(`Pages rendered in ${chalk2.yellow(totalTime)} ms.`);
1519
1530
  } catch (e) {
@@ -1527,7 +1538,7 @@ async function build(options) {
1527
1538
  await pluginDriver.init();
1528
1539
  const modifiedConfig = await pluginDriver.modifyConfig();
1529
1540
  await pluginDriver.beforeBuild();
1530
- await fs10.emptyDir(TEMP_DIR);
1541
+ await fs11.emptyDir(TEMP_DIR);
1531
1542
  await bundle(appDirectory, docDirectory, modifiedConfig, pluginDriver);
1532
1543
  await renderPages(appDirectory, modifiedConfig, pluginDriver);
1533
1544
  await pluginDriver.afterBuild();