@rspress/core 2.0.0-beta.27 → 2.0.0-beta.29

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/loader.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { AdditionalPage } from '@rspress/shared';
2
2
  import { DefaultThemeConfig } from '@rspress/shared';
3
3
  import type { PageIndexInfo } from '@rspress/shared';
4
- import type { RouteMeta } from '@rspress/shared';
4
+ import { RouteMeta } from '@rspress/shared';
5
5
  import { Rspack as Rspack_2 } from '@rsbuild/core';
6
6
  import type { RspressPlugin } from '@rspress/shared';
7
- import type { UserConfig } from '@rspress/shared';
7
+ import { UserConfig } from '@rspress/shared';
8
8
 
9
9
  declare interface InitOptions {
10
10
  scanDir: string;
@@ -68,7 +68,7 @@ declare class RouteService {
68
68
  addRoute(routePage: RoutePage): Promise<void>;
69
69
  getRoutes(): RouteMeta[];
70
70
  getRoutePages(): RoutePage[];
71
- isExistRoute(routePath: string): boolean;
71
+ isExistRoute(link: string): boolean;
72
72
  generateRoutesCode(): string;
73
73
  private generateRoutesCodeByRouteMeta;
74
74
  getRoutePathParts(relativePath: string): string[];
@@ -1,10 +1,10 @@
1
1
  import { AdditionalPage } from '@rspress/shared';
2
2
  import { DefaultThemeConfig } from '@rspress/shared';
3
3
  import type { PageIndexInfo } from '@rspress/shared';
4
- import type { RouteMeta } from '@rspress/shared';
4
+ import { RouteMeta } from '@rspress/shared';
5
5
  import type { Rspack as Rspack_2 } from '@rsbuild/core';
6
6
  import type { RspressPlugin } from '@rspress/shared';
7
- import type { UserConfig } from '@rspress/shared';
7
+ import { UserConfig } from '@rspress/shared';
8
8
 
9
9
  export declare function compile(options: CompileOptions): Promise<string>;
10
10
 
@@ -71,7 +71,7 @@ declare class RouteService {
71
71
  addRoute(routePage: RoutePage): Promise<void>;
72
72
  getRoutes(): RouteMeta[];
73
73
  getRoutePages(): RoutePage[];
74
- isExistRoute(routePath: string): boolean;
74
+ isExistRoute(link: string): boolean;
75
75
  generateRoutesCode(): string;
76
76
  private generateRoutesCodeByRouteMeta;
77
77
  getRoutePathParts(relativePath: string): string[];
package/dist/processor.js CHANGED
@@ -13,7 +13,7 @@ import { createCssVariablesTheme } from "shiki";
13
13
  import { readFile as promises_readFile } from "node:fs/promises";
14
14
  import { logger as logger_logger } from "@rspress/shared/logger";
15
15
  import picocolors_0 from "picocolors";
16
- import { addLeadingSlash, addTrailingSlash, isExternalUrl, isProduction, normalizeHref, parseUrl, removeTrailingSlash, withBase } from "@rspress/shared";
16
+ import { addLeadingSlash, isExternalUrl, isProduction, normalizeHref, parseUrl, withBase } from "@rspress/shared";
17
17
  import { visitChildren } from "unist-util-visit-children";
18
18
  function applyReplaceRules(code = '', replaceRules = []) {
19
19
  let result = code;
@@ -510,7 +510,7 @@ function hintRelativeMarkdownLink() {
510
510
  isLogged = true;
511
511
  logger_logger.info('[Rspress v2] Markdown links without "./" prefix are now relative links, e.g: [](guide/getting-started) is equal to [](./guide/getting-started). You can rewrite it to [](/guide/getting-started) to always use absolute links, or use [](./getting-started.md)');
512
512
  }
513
- function link_checkDeadLinks(checkDeadLinks, internalLinks, filePath, routeService) {
513
+ function link_checkDeadLinks(checkDeadLinks, internalLinks, filePath) {
514
514
  const errorInfos = [];
515
515
  const excludes = 'object' == typeof checkDeadLinks ? checkDeadLinks.excludes : void 0;
516
516
  const excludesUrl = Array.isArray(excludes) ? new Set(excludes) : void 0;
@@ -521,10 +521,8 @@ function link_checkDeadLinks(checkDeadLinks, internalLinks, filePath, routeServi
521
521
  ].forEach(([nodeUrl, link])=>{
522
522
  if (excludesUrl?.has(nodeUrl)) return;
523
523
  if (excludesFn?.(nodeUrl)) return;
524
- const cleanLinkPath = linkToRoutePath(link);
525
- if (!cleanLinkPath) return;
526
524
  if (!nodeUrl.startsWith('/') && /^\w/.test(nodeUrl)) possibleBreakingChange = true;
527
- if (!routeService.isExistRoute(removeTrailingSlash(cleanLinkPath)) && !routeService.isExistRoute(addTrailingSlash(cleanLinkPath))) errorInfos.push([
525
+ errorInfos.push([
528
526
  nodeUrl,
529
527
  link
530
528
  ]);
@@ -553,7 +551,7 @@ function looseMarkdownLink(url, routeService, filePath) {
553
551
  }
554
552
  return url;
555
553
  }
556
- function normalizeLink(nodeUrl, routeService, filePath, cleanUrls, autoPrefix, internalLinks, __base) {
554
+ function normalizeLink(nodeUrl, routeService, filePath, cleanUrls, autoPrefix, deadLinks, __base) {
557
555
  if (!nodeUrl) return '';
558
556
  if (nodeUrl.startsWith('#')) return nodeUrl;
559
557
  let { url, hash } = parseUrl(nodeUrl);
@@ -572,28 +570,28 @@ function normalizeLink(nodeUrl, routeService, filePath, cleanUrls, autoPrefix, i
572
570
  url = normalizeHref(url, false);
573
571
  url = url.replace(/\.html$/, cleanUrls);
574
572
  }
575
- internalLinks.set(nodeUrl, url);
573
+ if (!routeService.isExistRoute(url)) {
574
+ deadLinks.set(nodeUrl, url);
575
+ return nodeUrl;
576
+ }
576
577
  if (hash) url += `#${hash}`;
577
578
  if (__base) url = withBase(url, __base);
578
579
  return url;
579
580
  }
580
- function linkToRoutePath(routePath) {
581
- return decodeURIComponent(routePath.split('#')[0]).replace(/\.html$/, '').replace(/\/index$/, '/');
582
- }
583
581
  const remarkLink = ({ cleanUrls, routeService, remarkLinkOptions, __base })=>(tree, file)=>{
584
582
  const { checkDeadLinks: shouldCheckDeadLinks = true, autoPrefix = true } = remarkLinkOptions ?? {};
585
- const internalLinks = new Map();
583
+ const deadLinks = new Map();
586
584
  visit(tree, 'link', (node)=>{
587
585
  const { url: nodeUrl } = node;
588
- const link = normalizeLink(nodeUrl, routeService, file.path, cleanUrls, autoPrefix, internalLinks, __base);
586
+ const link = normalizeLink(nodeUrl, routeService, file.path, cleanUrls, autoPrefix, deadLinks, __base);
589
587
  node.url = link;
590
588
  });
591
589
  visit(tree, 'definition', (node)=>{
592
590
  const { url: nodeUrl } = node;
593
- const link = normalizeLink(nodeUrl, routeService, file.path, cleanUrls, autoPrefix, internalLinks, __base);
591
+ const link = normalizeLink(nodeUrl, routeService, file.path, cleanUrls, autoPrefix, deadLinks, __base);
594
592
  node.url = link;
595
593
  });
596
- if (shouldCheckDeadLinks && routeService) link_checkDeadLinks(shouldCheckDeadLinks, internalLinks, file.path, routeService);
594
+ if (shouldCheckDeadLinks && routeService) link_checkDeadLinks(shouldCheckDeadLinks, deadLinks, file.path);
597
595
  };
598
596
  const parseToc = (tree)=>{
599
597
  let title = '';
@@ -646,7 +644,6 @@ async function createMDXOptions(options) {
646
644
  const { docDirectory, config, routeService, filepath, pluginDriver, addDependency } = options;
647
645
  const remarkLinkOptions = config?.markdown?.link;
648
646
  const format = node_path.extname(filepath).slice(1);
649
- const cleanUrls = config?.route?.cleanUrls ?? false;
650
647
  const { remarkPlugins: remarkPluginsFromConfig = [], rehypePlugins: rehypePluginsFromConfig = [], globalComponents: globalComponentsFromConfig = [], showLineNumbers = false, shiki } = config?.markdown || {};
651
648
  const rspressPlugins = pluginDriver?.getPlugins() ?? [];
652
649
  const remarkPluginsFromPlugins = rspressPlugins.flatMap((plugin)=>plugin.markdown?.remarkPlugins || []);
@@ -672,7 +669,7 @@ async function createMDXOptions(options) {
672
669
  [
673
670
  remarkLink,
674
671
  {
675
- cleanUrls,
672
+ cleanUrls: false,
676
673
  root: docDirectory,
677
674
  routeService,
678
675
  remarkLinkOptions
@@ -102,8 +102,8 @@ function hintSSGFailed() {
102
102
  1. Fix code to make it SSR-compatible.
103
103
  2. Set \`ssg: false\` if the code in node_modules may be difficult to fix, but the SSG feature will be lost.`);
104
104
  }
105
- var package_namespaceObject = JSON.parse('{"i8":"2.0.0-beta.27"}');
106
- const RSPRESS_VERSION = package_namespaceObject.i8;
105
+ var package_namespaceObject = JSON.parse('{"rE":"2.0.0-beta.29"}');
106
+ const RSPRESS_VERSION = package_namespaceObject.rE;
107
107
  `{
108
108
  const saved = localStorage.getItem('${APPEARANCE_KEY}')
109
109
  const preferDark = window.matchMedia('(prefers-color-scheme: dark)').matches
@@ -1,11 +1,11 @@
1
1
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
- import { DataContext, useLocation } from "@rspress/runtime";
2
+ import { PageContext, useLocation } from "@rspress/runtime";
3
3
  import { Layout } from "@theme";
4
4
  import react, { useContext, useLayoutEffect } from "react";
5
5
  import virtual_global_components from "virtual-global-components";
6
6
  import { initPageData } from "./initPageData.js";
7
7
  function App() {
8
- const { setData: setPageData, data } = useContext(DataContext);
8
+ const { setData: setPageData, data } = useContext(PageContext);
9
9
  const { pathname, search } = useLocation();
10
10
  useLayoutEffect(()=>{
11
11
  async function refetchData() {
@@ -22,7 +22,7 @@ function App() {
22
22
  setPageData
23
23
  ]);
24
24
  if (!data) return /*#__PURE__*/ jsx(Fragment, {});
25
- const frontmatter = data.page.frontmatter || {};
25
+ const frontmatter = data.frontmatter || {};
26
26
  const GLOBAL_COMPONENTS_KEY = 'globalUIComponents';
27
27
  const query = new URLSearchParams(search);
28
28
  const hideGlobalUIComponents = false === frontmatter[GLOBAL_COMPONENTS_KEY] || "0" === query.get(GLOBAL_COMPONENTS_KEY);
@@ -1,4 +1,4 @@
1
- import type { PageData } from '@rspress/shared';
1
+ import type { Page } from './initPageData';
2
2
  export declare function ClientApp({ initialPageData, }: {
3
- initialPageData?: PageData;
3
+ initialPageData?: Page;
4
4
  }): import("react/jsx-runtime").JSX.Element;
@@ -1,9 +1,9 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import { BrowserRouter, DataContext, ThemeContext } from "@rspress/runtime";
2
+ import { BrowserRouter, PageContext, ThemeContext } from "@rspress/runtime";
3
3
  import { useThemeState } from "@theme";
4
4
  import { UnheadProvider, createHead } from "@unhead/react/client";
5
5
  import { useMemo, useState } from "react";
6
- import { base } from "virtual-runtime-config";
6
+ import virtual_site_data from "virtual-site-data";
7
7
  import { App } from "./App.js";
8
8
  const head = createHead();
9
9
  function ClientApp({ initialPageData = null }) {
@@ -17,7 +17,7 @@ function ClientApp({ initialPageData = null }) {
17
17
  theme,
18
18
  setTheme
19
19
  ]),
20
- children: /*#__PURE__*/ jsx(DataContext.Provider, {
20
+ children: /*#__PURE__*/ jsx(PageContext.Provider, {
21
21
  value: useMemo(()=>({
22
22
  data,
23
23
  setData
@@ -30,7 +30,7 @@ function ClientApp({ initialPageData = null }) {
30
30
  v7_relativeSplatPath: true,
31
31
  v7_startTransition: true
32
32
  },
33
- basename: base,
33
+ basename: virtual_site_data.base,
34
34
  children: /*#__PURE__*/ jsx(UnheadProvider, {
35
35
  head: head,
36
36
  children: /*#__PURE__*/ jsx(App, {})
@@ -1,2 +1,3 @@
1
- import { type PageData } from '@rspress/shared';
2
- export declare function initPageData(routePath: string): Promise<PageData>;
1
+ import { type PageDataLegacy } from '@rspress/shared';
2
+ export type Page = PageDataLegacy['page'];
3
+ export declare function initPageData(routePath: string): Promise<Page>;
@@ -1,6 +1,6 @@
1
1
  import { isEqualPath, pathnameToRouteService } from "@rspress/runtime";
2
2
  import { MDX_OR_MD_REGEXP, cleanUrl } from "@rspress/shared";
3
- import { base } from "virtual-runtime-config";
3
+ import { pageData } from "virtual-page-data";
4
4
  import virtual_site_data from "virtual-site-data";
5
5
  async function initPageData(routePath) {
6
6
  const matchedRoute = pathnameToRouteService(routePath);
@@ -8,27 +8,24 @@ async function initPageData(routePath) {
8
8
  const mod = await matchedRoute.preload();
9
9
  const pagePath = cleanUrl(matchedRoute.filePath);
10
10
  const normalize = (p)=>p.replace(/\/$/, '').toLowerCase();
11
- const extractPageInfo = virtual_site_data.pages.find((page)=>isEqualPath(normalize(page.routePath), normalize(matchedRoute.path)));
11
+ const extractPageInfo = pageData.pages.find((page)=>isEqualPath(normalize(page.routePath), normalize(matchedRoute.path)));
12
12
  const encodedPagePath = encodeURIComponent(pagePath);
13
13
  const meta = mod.default.__RSPRESS_PAGE_META?.[encodedPagePath] || {};
14
14
  const { toc = [], title = '', frontmatter = {}, ...rest } = MDX_OR_MD_REGEXP.test(matchedRoute.filePath) ? meta : mod;
15
15
  return {
16
- siteData: virtual_site_data,
17
- page: {
18
- ...rest,
19
- pagePath,
20
- ...extractPageInfo,
21
- pageType: frontmatter?.pageType || 'doc',
22
- title,
23
- frontmatter,
24
- toc
25
- }
16
+ ...rest,
17
+ pagePath,
18
+ ...extractPageInfo,
19
+ pageType: frontmatter?.pageType || 'doc',
20
+ title,
21
+ frontmatter,
22
+ toc
26
23
  };
27
24
  }
28
25
  let lang = virtual_site_data.lang || '';
29
26
  let version = virtual_site_data.multiVersion?.default || '';
30
27
  if (virtual_site_data.lang && 'undefined' != typeof window) {
31
- const path = location.pathname.replace(base, '').split('/').slice(0, 2);
28
+ const path = location.pathname.replace(virtual_site_data.base, '').split('/').slice(0, 2);
32
29
  if (virtual_site_data.locales.length) {
33
30
  const result = virtual_site_data.locales.find(({ lang })=>path.includes(lang));
34
31
  if (result) lang = result.lang;
@@ -39,19 +36,16 @@ async function initPageData(routePath) {
39
36
  }
40
37
  }
41
38
  return {
42
- siteData: virtual_site_data,
43
- page: {
44
- pagePath: '',
45
- pageType: '404',
46
- routePath: '/404',
47
- lang,
48
- frontmatter: {},
49
- title: '404',
50
- toc: [],
51
- version,
52
- _filepath: '',
53
- _relativePath: ''
54
- }
39
+ pagePath: '',
40
+ pageType: '404',
41
+ routePath: '/404',
42
+ lang,
43
+ frontmatter: {},
44
+ title: '404',
45
+ toc: [],
46
+ version,
47
+ _filepath: '',
48
+ _relativePath: ''
55
49
  };
56
50
  }
57
51
  export { initPageData };
@@ -1,7 +1,5 @@
1
- import type { PageData } from '@rspress/shared';
2
1
  import { type Unhead } from '@unhead/react/server';
3
2
  export declare function render(routePath: string, head: Unhead): Promise<{
4
3
  appHtml: string;
5
- pageData: PageData;
6
4
  }>;
7
5
  export { routes } from 'virtual-routes';
@@ -1,11 +1,11 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import { PassThrough } from "node:stream";
3
3
  import { text as consumers_text } from "node:stream/consumers";
4
- import { DataContext, ThemeContext, pathnameToRouteService, withBase } from "@rspress/runtime";
4
+ import { PageContext, ThemeContext, pathnameToRouteService, withBase } from "@rspress/runtime";
5
5
  import { StaticRouter } from "@rspress/runtime/server";
6
6
  import { UnheadProvider } from "@unhead/react/server";
7
7
  import { renderToPipeableStream } from "react-dom/server";
8
- import { base } from "virtual-runtime-config";
8
+ import virtual_site_data from "virtual-site-data";
9
9
  import { App } from "./App.js";
10
10
  import { initPageData } from "./initPageData.js";
11
11
  import { routes } from "virtual-routes";
@@ -35,13 +35,13 @@ async function render(routePath, head) {
35
35
  value: {
36
36
  theme: DEFAULT_THEME
37
37
  },
38
- children: /*#__PURE__*/ jsx(DataContext.Provider, {
38
+ children: /*#__PURE__*/ jsx(PageContext.Provider, {
39
39
  value: {
40
40
  data: initialPageData
41
41
  },
42
42
  children: /*#__PURE__*/ jsx(StaticRouter, {
43
43
  location: withBase(routePath),
44
- basename: base,
44
+ basename: virtual_site_data.base,
45
45
  children: /*#__PURE__*/ jsx(UnheadProvider, {
46
46
  value: head,
47
47
  children: /*#__PURE__*/ jsx(App, {})
@@ -50,8 +50,7 @@ async function render(routePath, head) {
50
50
  })
51
51
  }));
52
52
  return {
53
- appHtml,
54
- pageData: initialPageData
53
+ appHtml
55
54
  };
56
55
  }
57
56
  export { render, routes };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspress/core",
3
- "version": "2.0.0-beta.27",
3
+ "version": "2.0.0-beta.29",
4
4
  "description": "The Rspress Documentation Framework",
5
5
  "bugs": "https://github.com/web-infra-dev/rspress/issues",
6
6
  "repository": {
@@ -51,20 +51,18 @@
51
51
  "index.html"
52
52
  ],
53
53
  "dependencies": {
54
- "@mdx-js/loader": "^3.1.0",
55
54
  "@mdx-js/mdx": "^3.1.0",
56
55
  "@mdx-js/react": "^3.1.0",
57
- "@rsbuild/core": "~1.4.15",
56
+ "@rsbuild/core": "~1.4.16",
58
57
  "@rsbuild/plugin-react": "~1.3.5",
59
58
  "@rspress/mdx-rs": "0.6.6",
60
- "@shikijs/rehype": "^3.9.2",
59
+ "@shikijs/rehype": "^3.11.0",
61
60
  "@types/unist": "^3.0.3",
62
61
  "@unhead/react": "^2.0.14",
63
62
  "cac": "^6.7.14",
64
63
  "chokidar": "^3.6.0",
65
64
  "enhanced-resolve": "5.18.3",
66
65
  "github-slugger": "^2.0.0",
67
- "hast-util-from-html": "^2.0.3",
68
66
  "hast-util-heading-rank": "^3.0.0",
69
67
  "html-to-text": "^9.0.5",
70
68
  "lodash-es": "^4.17.21",
@@ -77,34 +75,32 @@
77
75
  "react-router-dom": "^6.30.1",
78
76
  "rehype-external-links": "^3.0.0",
79
77
  "rehype-raw": "^7.0.0",
80
- "remark": "^15.0.1",
81
78
  "remark-gfm": "^4.0.1",
82
- "rspack-plugin-virtual-module": "1.0.1",
83
- "shiki": "^3.9.2",
79
+ "shiki": "^3.11.0",
84
80
  "tinyglobby": "^0.2.14",
85
81
  "tinypool": "^1.1.1",
86
82
  "unified": "^11.0.5",
87
83
  "unist-util-visit": "^5.0.0",
88
84
  "unist-util-visit-children": "^3.0.0",
89
- "@rspress/runtime": "2.0.0-beta.27",
90
- "@rspress/shared": "2.0.0-beta.27",
91
- "@rspress/theme-default": "2.0.0-beta.27"
85
+ "@rspress/runtime": "2.0.0-beta.29",
86
+ "@rspress/theme-default": "2.0.0-beta.29",
87
+ "@rspress/shared": "2.0.0-beta.29"
92
88
  },
93
89
  "devDependencies": {
94
- "@microsoft/api-extractor": "^7.52.10",
95
- "@rslib/core": "0.11.2",
90
+ "@microsoft/api-extractor": "^7.52.11",
91
+ "@rslib/core": "0.12.2",
96
92
  "@types/hast": "^3.0.4",
97
93
  "@types/html-to-text": "^9.0.4",
98
94
  "@types/jest": "~29.5.14",
99
95
  "@types/lodash-es": "^4.17.12",
100
96
  "@types/mdast": "^4.0.4",
101
97
  "@types/node": "^22.8.1",
102
- "@types/react": "^19.1.9",
98
+ "@types/react": "^19.1.11",
103
99
  "@types/react-dom": "^19.1.7",
104
100
  "execa": "8.0.1",
105
101
  "mdast-util-directive": "^3.1.0",
106
102
  "mdast-util-mdx-expression": "^2.0.1",
107
- "memfs": "^4.36.0",
103
+ "memfs": "^4.38.1",
108
104
  "p-map": "^7.0.3",
109
105
  "postcss": "8.5.6",
110
106
  "rehype-stringify": "^10.0.1",