@rspress/core 2.0.0-beta.14 → 2.0.0-beta.15

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
@@ -6,6 +6,13 @@ import type { Rspack as Rspack_2 } from '@rsbuild/core';
6
6
  import type { RspressPlugin } from '@rspress/shared';
7
7
  import type { UserConfig } from '@rspress/shared';
8
8
 
9
+ declare interface InitOptions {
10
+ scanDir: string;
11
+ config: UserConfig;
12
+ runtimeTempDir: string;
13
+ pluginDriver: PluginDriver;
14
+ }
15
+
9
16
  declare function mdxLoader(this: Rspack_2.LoaderContext<MdxLoaderOptions>, source: string): Promise<void>;
10
17
  export default mdxLoader;
11
18
 
@@ -45,17 +52,23 @@ declare class PluginDriver {
45
52
  _runSerialAsyncHook<H extends RspressPluginHookKeys>(hookName: H, ...args: Parameters<Required<RspressPlugin>[H]>): RspressPlugin;
46
53
  }
47
54
 
55
+ declare class RoutePage {
56
+ routeMeta: RouteMeta;
57
+ static create(routeMeta: RouteMeta): RoutePage;
58
+ constructor(routeMeta: RouteMeta);
59
+ }
60
+
48
61
  declare class RouteService {
49
62
  #private;
50
- routeData: Map<string, RouteMeta>;
63
+ routeData: Map<string, RoutePage>;
64
+ static create(options: InitOptions): Promise<RouteService>;
51
65
  constructor(scanDir: string, userConfig: UserConfig, tempDir: string, pluginDriver: PluginDriver);
52
66
  get extensions(): readonly string[];
53
- init(): Promise<void>;
54
- addRoute(routeInfo: RouteMeta): void;
67
+ addRoute(routeMeta: RouteMeta): Promise<void>;
55
68
  removeRoute(filePath: string): void;
56
69
  getRoutes(): RouteMeta[];
70
+ getRoutePages(): RoutePage[];
57
71
  isExistRoute(routePath: string): boolean;
58
- isEmpty(): boolean;
59
72
  generateRoutesCode(): string;
60
73
  generateRoutesCodeByRouteMeta(routeMeta: RouteMeta[]): string;
61
74
  getRoutePathParts(routePath: string): readonly [string, string, string];
@@ -64,6 +77,7 @@ declare class RouteService {
64
77
  lang: string;
65
78
  version: string;
66
79
  };
80
+ getRoutePageByRoutePath(routePath: string): RoutePage | undefined;
67
81
  }
68
82
 
69
83
  declare type RspressPluginHookKeys = 'beforeBuild' | 'afterBuild' | 'addPages' | 'addRuntimeModules' | 'routeGenerated' | 'routeServiceGenerated' | 'addSSGRoutes' | 'extendPageData' | 'modifySearchIndexData';
@@ -19,6 +19,13 @@ declare interface CompileOptions {
19
19
 
20
20
  export declare function compileWithCrossCompilerCache(options: CompileOptions): Promise<string>;
21
21
 
22
+ declare interface InitOptions {
23
+ scanDir: string;
24
+ config: UserConfig;
25
+ runtimeTempDir: string;
26
+ pluginDriver: PluginDriver;
27
+ }
28
+
22
29
  declare class PluginDriver {
23
30
  #private;
24
31
  constructor(config: UserConfig, isProd: boolean);
@@ -47,17 +54,23 @@ declare class PluginDriver {
47
54
  _runSerialAsyncHook<H extends RspressPluginHookKeys>(hookName: H, ...args: Parameters<Required<RspressPlugin>[H]>): RspressPlugin;
48
55
  }
49
56
 
57
+ declare class RoutePage {
58
+ routeMeta: RouteMeta;
59
+ static create(routeMeta: RouteMeta): RoutePage;
60
+ constructor(routeMeta: RouteMeta);
61
+ }
62
+
50
63
  declare class RouteService {
51
64
  #private;
52
- routeData: Map<string, RouteMeta>;
65
+ routeData: Map<string, RoutePage>;
66
+ static create(options: InitOptions): Promise<RouteService>;
53
67
  constructor(scanDir: string, userConfig: UserConfig, tempDir: string, pluginDriver: PluginDriver);
54
68
  get extensions(): readonly string[];
55
- init(): Promise<void>;
56
- addRoute(routeInfo: RouteMeta): void;
69
+ addRoute(routeMeta: RouteMeta): Promise<void>;
57
70
  removeRoute(filePath: string): void;
58
71
  getRoutes(): RouteMeta[];
72
+ getRoutePages(): RoutePage[];
59
73
  isExistRoute(routePath: string): boolean;
60
- isEmpty(): boolean;
61
74
  generateRoutesCode(): string;
62
75
  generateRoutesCodeByRouteMeta(routeMeta: RouteMeta[]): string;
63
76
  getRoutePathParts(routePath: string): readonly [string, string, string];
@@ -66,6 +79,7 @@ declare class RouteService {
66
79
  lang: string;
67
80
  version: string;
68
81
  };
82
+ getRoutePageByRoutePath(routePath: string): RoutePage | undefined;
69
83
  }
70
84
 
71
85
  declare type RspressPluginHookKeys = 'beforeBuild' | 'afterBuild' | 'addPages' | 'addRuntimeModules' | 'routeGenerated' | 'routeServiceGenerated' | 'addSSGRoutes' | 'extendPageData' | 'modifySearchIndexData';
package/dist/processor.js CHANGED
@@ -1,20 +1,20 @@
1
1
  import __rslib_shim_module__ from 'module';
2
2
  /*#__PURE__*/ import.meta.url;
3
- import external_node_path_default from "node:path";
3
+ import node_path from "node:path";
4
4
  import { createProcessor, nodeTypes } from "@mdx-js/mdx";
5
5
  import { logger } from "@rspress/shared/logger";
6
6
  import { extractTextAndId, getNodeAttribute, loadFrontMatter } from "@rspress/shared/node-utils";
7
- import external_node_os_default from "node:os";
8
- import external_rehype_external_links_default from "rehype-external-links";
9
- import external_rehype_raw_default from "rehype-raw";
10
- import external_remark_gfm_default from "remark-gfm";
11
- import external_github_slugger_default from "github-slugger";
7
+ import node_os from "node:os";
8
+ import rehype_external_links from "rehype-external-links";
9
+ import rehype_raw from "rehype-raw";
10
+ import remark_gfm from "remark-gfm";
11
+ import github_slugger from "github-slugger";
12
12
  import { headingRank } from "hast-util-heading-rank";
13
13
  import { visit } from "unist-util-visit";
14
14
  import { addLeadingSlash, cleanUrl, isExternalUrl, isProduction, normalizeHref, parseUrl, slash as shared_slash } from "@rspress/shared";
15
15
  import { DEFAULT_PAGE_EXTENSIONS } from "@rspress/shared/constants";
16
16
  import { visitChildren } from "unist-util-visit-children";
17
- import rehype_default from "@shikijs/rehype";
17
+ import rehype from "@shikijs/rehype";
18
18
  import { createCssVariablesTheme } from "shiki";
19
19
  function applyReplaceRules(code = '', replaceRules = []) {
20
20
  let result = code;
@@ -25,15 +25,15 @@ function escapeMarkdownHeadingIds(content) {
25
25
  const markdownHeadingRegexp = /(?:^|\n)#{1,6}(?!#).*/g;
26
26
  return content.replace(markdownHeadingRegexp, (substring)=>substring.replace('{#', '\\{#').replace('\\\\{#', '\\{#'));
27
27
  }
28
- const isWindows = 'win32' === external_node_os_default.platform();
28
+ const isWindows = 'win32' === node_os.platform();
29
29
  function slash(p) {
30
30
  return p.replace(/\\/g, '/');
31
31
  }
32
32
  function normalizePath(id) {
33
- return external_node_path_default.posix.normalize(isWindows ? slash(id) : id);
33
+ return node_path.posix.normalize(isWindows ? slash(id) : id);
34
34
  }
35
35
  const rehypeHeaderAnchor = ()=>{
36
- const slugger = new external_github_slugger_default();
36
+ const slugger = new github_slugger();
37
37
  return (tree)=>{
38
38
  visit(tree, 'element', (node)=>{
39
39
  if (!headingRank(node)) return;
@@ -112,7 +112,7 @@ const getASTNodeImport = (name, from)=>({
112
112
  });
113
113
  const remarkBuiltin = ({ globalComponents })=>(tree)=>{
114
114
  const demos = globalComponents.map((componentPath)=>{
115
- const filename = external_node_path_default.parse(componentPath).name;
115
+ const filename = node_path.parse(componentPath).name;
116
116
  const componentName = filename[0].toUpperCase() + filename.slice(1);
117
117
  return getASTNodeImport(componentName, componentPath);
118
118
  });
@@ -122,7 +122,7 @@ const IGNORE_REGEXP = /^(https?|mailto|tel|#)/;
122
122
  function checkLinks(links, filepath, root, routeService) {
123
123
  const errorInfos = [];
124
124
  links.filter((link)=>!IGNORE_REGEXP.test(link)).map((link)=>normalizePath(link)).forEach((link)=>{
125
- const relativePath = external_node_path_default.relative(root, filepath);
125
+ const relativePath = node_path.relative(root, filepath);
126
126
  if (!routeService.isExistRoute(cleanUrl(link))) errorInfos.push(`Internal link to "${link}" is dead, check it in "${relativePath}"`);
127
127
  });
128
128
  if (errorInfos.length > 0) {
@@ -140,7 +140,7 @@ const remarkCheckDeadLinks = (checkLink)=>{
140
140
  if (!url) return;
141
141
  if (internalLinks.has(url)) return;
142
142
  if (!url.startsWith('http://') && !url.startsWith('https://')) {
143
- const { routePath: normalizeUrl } = routeService.normalizeRoutePath(url.split(external_node_path_default.sep).join('/')?.split('#')[0]);
143
+ const { routePath: normalizeUrl } = routeService.normalizeRoutePath(url.split(node_path.sep).join('/')?.split('#')[0]);
144
144
  internalLinks.add(normalizeUrl);
145
145
  }
146
146
  });
@@ -152,9 +152,9 @@ function normalizeLink(nodeUrl, routeService, relativePath, cleanUrls) {
152
152
  if (nodeUrl.startsWith('#')) return `#${nodeUrl.slice(1)}`;
153
153
  let { url, hash } = parseUrl(nodeUrl);
154
154
  if (isExternalUrl(url)) return url + (hash ? `#${hash}` : '');
155
- const extname = external_node_path_default.extname(url);
155
+ const extname = node_path.extname(url);
156
156
  if ((routeService?.extensions ?? DEFAULT_PAGE_EXTENSIONS).includes(extname)) url = url.replace(new RegExp(`\\${extname}$`), '');
157
- if (url.startsWith('.')) url = external_node_path_default.posix.join(shared_slash(external_node_path_default.dirname(relativePath)), url);
157
+ if (url.startsWith('.')) url = node_path.posix.join(shared_slash(node_path.dirname(relativePath)), url);
158
158
  else if (routeService) {
159
159
  const [pathVersion, pathLang] = routeService.getRoutePathParts(shared_slash(relativePath));
160
160
  const [urlVersion, urlLang, urlPath] = routeService.getRoutePathParts(url);
@@ -178,12 +178,12 @@ const remarkPluginNormalizeLink = ({ root, cleanUrls, routeService })=>(tree, fi
178
178
  const images = [];
179
179
  visit(tree, 'link', (node)=>{
180
180
  const { url: nodeUrl } = node;
181
- const relativePath = external_node_path_default.relative(root, file.path);
181
+ const relativePath = node_path.relative(root, file.path);
182
182
  node.url = normalizeLink(nodeUrl, routeService, relativePath, cleanUrls);
183
183
  });
184
184
  visit(tree, 'definition', (node)=>{
185
185
  const { url: nodeUrl } = node;
186
- const relativePath = external_node_path_default.relative(root, file.path);
186
+ const relativePath = node_path.relative(root, file.path);
187
187
  node.url = normalizeLink(nodeUrl, routeService, relativePath, cleanUrls);
188
188
  });
189
189
  const getMdxSrcAttribute = (tempVar)=>({
@@ -245,7 +245,7 @@ const remarkPluginNormalizeLink = ({ root, cleanUrls, routeService })=>(tree, fi
245
245
  const parseToc = (tree)=>{
246
246
  let title = '';
247
247
  const toc = [];
248
- const slugger = new external_github_slugger_default();
248
+ const slugger = new github_slugger();
249
249
  visitChildren((node)=>{
250
250
  if ('heading' !== node.type || !node.depth || !node.children) return;
251
251
  if (node.depth >= 1 && node.depth < 5) {
@@ -362,7 +362,7 @@ function createRehypeShikiOptions(showLineNumbers, options) {
362
362
  }
363
363
  async function createMDXOptions(options) {
364
364
  const { docDirectory, config, checkDeadLinks, routeService, filepath, pluginDriver } = options;
365
- const format = external_node_path_default.extname(filepath).slice(1);
365
+ const format = node_path.extname(filepath).slice(1);
366
366
  const cleanUrls = config?.route?.cleanUrls ?? false;
367
367
  const { remarkPlugins: remarkPluginsFromConfig = [], rehypePlugins: rehypePluginsFromConfig = [], globalComponents: globalComponentsFromConfig = [], showLineNumbers = false, shiki } = config?.markdown || {};
368
368
  const rspressPlugins = pluginDriver?.getPlugins() ?? [];
@@ -376,7 +376,7 @@ async function createMDXOptions(options) {
376
376
  providerImportSource: '@mdx-js/react',
377
377
  format,
378
378
  remarkPlugins: [
379
- external_remark_gfm_default,
379
+ remark_gfm,
380
380
  remarkPluginToc,
381
381
  [
382
382
  remarkPluginNormalizeLink,
@@ -408,18 +408,18 @@ async function createMDXOptions(options) {
408
408
  ...'md' === format ? [
409
409
  rehypeCodeMeta,
410
410
  [
411
- external_rehype_raw_default,
411
+ rehype_raw,
412
412
  {
413
413
  passThrough: nodeTypes
414
414
  }
415
415
  ]
416
416
  ] : [],
417
417
  [
418
- rehype_default,
418
+ rehype,
419
419
  createRehypeShikiOptions(showLineNumbers, shiki)
420
420
  ],
421
421
  [
422
- external_rehype_external_links_default,
422
+ rehype_external_links,
423
423
  {
424
424
  target: '_blank',
425
425
  rel: 'noopener noreferrer'
@@ -473,7 +473,7 @@ async function compile(options) {
473
473
  ${compileResult}
474
474
  MDXContent.__RSPRESS_PAGE_META = {};
475
475
 
476
- MDXContent.__RSPRESS_PAGE_META["${encodeURIComponent(normalizePath(external_node_path_default.relative(docDirectory, filepath)))}"] = ${JSON.stringify(pageMeta)};
476
+ MDXContent.__RSPRESS_PAGE_META["${encodeURIComponent(normalizePath(node_path.relative(docDirectory, filepath)))}"] = ${JSON.stringify(pageMeta)};
477
477
  `;
478
478
  return result;
479
479
  } catch (e) {
@@ -1,8 +1,8 @@
1
1
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
2
  import { DataContext, useLocation } from "@rspress/runtime";
3
3
  import { Layout } from "@theme";
4
- import external_react_default, { useContext, useLayoutEffect } from "react";
5
- import external_virtual_global_components_default from "virtual-global-components";
4
+ import react, { useContext, useLayoutEffect } from "react";
5
+ import virtual_global_components from "virtual-global-components";
6
6
  import { initPageData } from "./initPageData.js";
7
7
  function App() {
8
8
  const { setData: setPageData, data } = useContext(DataContext);
@@ -29,15 +29,15 @@ function App() {
29
29
  return /*#__PURE__*/ jsxs(Fragment, {
30
30
  children: [
31
31
  /*#__PURE__*/ jsx(Layout, {}),
32
- !hideGlobalUIComponents && external_virtual_global_components_default.map((componentInfo, index)=>{
32
+ !hideGlobalUIComponents && virtual_global_components.map((componentInfo, index)=>{
33
33
  if (Array.isArray(componentInfo)) {
34
34
  const [component, props] = componentInfo;
35
- return /*#__PURE__*/ external_react_default.createElement(component, {
35
+ return /*#__PURE__*/ react.createElement(component, {
36
36
  key: index,
37
37
  ...props
38
38
  });
39
39
  }
40
- return /*#__PURE__*/ external_react_default.createElement(componentInfo, {
40
+ return /*#__PURE__*/ react.createElement(componentInfo, {
41
41
  key: index
42
42
  });
43
43
  })
@@ -1,18 +1,18 @@
1
1
  import { isEqualPath, pathnameToRouteService } from "@rspress/runtime";
2
2
  import { MDX_OR_MD_REGEXP, cleanUrl } from "@rspress/shared";
3
- import external_virtual_site_data_default from "virtual-site-data";
3
+ import virtual_site_data from "virtual-site-data";
4
4
  async function initPageData(routePath) {
5
5
  const matchedRoute = pathnameToRouteService(routePath);
6
6
  if (matchedRoute) {
7
7
  const mod = await matchedRoute.preload();
8
8
  const pagePath = cleanUrl(matchedRoute.filePath);
9
9
  const normalize = (p)=>p.replace(/\/$/, '').toLowerCase();
10
- const extractPageInfo = external_virtual_site_data_default.pages.find((page)=>isEqualPath(normalize(page.routePath), normalize(matchedRoute.path)));
10
+ const extractPageInfo = virtual_site_data.pages.find((page)=>isEqualPath(normalize(page.routePath), normalize(matchedRoute.path)));
11
11
  const encodedPagePath = encodeURIComponent(pagePath);
12
12
  const meta = mod.default.__RSPRESS_PAGE_META?.[encodedPagePath] || {};
13
13
  const { toc = [], title = '', frontmatter = {}, ...rest } = MDX_OR_MD_REGEXP.test(matchedRoute.filePath) ? meta : mod;
14
14
  return {
15
- siteData: external_virtual_site_data_default,
15
+ siteData: virtual_site_data,
16
16
  page: {
17
17
  ...rest,
18
18
  pagePath,
@@ -24,21 +24,21 @@ async function initPageData(routePath) {
24
24
  }
25
25
  };
26
26
  }
27
- let lang = external_virtual_site_data_default.lang || '';
28
- let version = external_virtual_site_data_default.multiVersion?.default || '';
29
- if (external_virtual_site_data_default.lang && 'undefined' != typeof window) {
30
- const path = location.pathname.replace(external_virtual_site_data_default.base, '').split('/').slice(0, 2);
31
- if (external_virtual_site_data_default.locales.length) {
32
- const result = external_virtual_site_data_default.locales.find(({ lang })=>path.includes(lang));
27
+ let lang = virtual_site_data.lang || '';
28
+ let version = virtual_site_data.multiVersion?.default || '';
29
+ if (virtual_site_data.lang && 'undefined' != typeof window) {
30
+ const path = location.pathname.replace(virtual_site_data.base, '').split('/').slice(0, 2);
31
+ if (virtual_site_data.locales.length) {
32
+ const result = virtual_site_data.locales.find(({ lang })=>path.includes(lang));
33
33
  if (result) lang = result.lang;
34
34
  }
35
- if (external_virtual_site_data_default.multiVersion.versions) {
36
- const result = external_virtual_site_data_default.multiVersion.versions.find((version)=>path.includes(version));
35
+ if (virtual_site_data.multiVersion.versions) {
36
+ const result = virtual_site_data.multiVersion.versions.find((version)=>path.includes(version));
37
37
  if (result) version = result;
38
38
  }
39
39
  }
40
40
  return {
41
- siteData: external_virtual_site_data_default,
41
+ siteData: virtual_site_data,
42
42
  page: {
43
43
  pagePath: '',
44
44
  pageType: '404',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspress/core",
3
- "version": "2.0.0-beta.14",
3
+ "version": "2.0.0-beta.15",
4
4
  "description": "The Rspress Documentation Framework",
5
5
  "bugs": "https://github.com/web-infra-dev/rspress/issues",
6
6
  "repository": {
@@ -29,7 +29,7 @@
29
29
  "default": "./theme.ts"
30
30
  },
31
31
  "./shiki-transformers": {
32
- "types": "./dist/index.d.ts",
32
+ "types": "./dist/shiki-transformers.d.ts",
33
33
  "default": "./dist/shiki-transformers.js"
34
34
  },
35
35
  "./runtime": {
@@ -77,17 +77,17 @@
77
77
  "unified": "^11.0.5",
78
78
  "unist-util-visit": "^5.0.0",
79
79
  "unist-util-visit-children": "^3.0.0",
80
- "@rspress/plugin-last-updated": "2.0.0-beta.14",
81
- "@rspress/plugin-medium-zoom": "2.0.0-beta.14",
82
- "@rspress/plugin-auto-nav-sidebar": "2.0.0-beta.14",
83
- "@rspress/runtime": "2.0.0-beta.14",
84
- "@rspress/plugin-container-syntax": "2.0.0-beta.14",
85
- "@rspress/shared": "2.0.0-beta.14",
86
- "@rspress/theme-default": "2.0.0-beta.14"
80
+ "@rspress/plugin-auto-nav-sidebar": "2.0.0-beta.15",
81
+ "@rspress/plugin-medium-zoom": "2.0.0-beta.15",
82
+ "@rspress/plugin-container-syntax": "2.0.0-beta.15",
83
+ "@rspress/plugin-last-updated": "2.0.0-beta.15",
84
+ "@rspress/runtime": "2.0.0-beta.15",
85
+ "@rspress/shared": "2.0.0-beta.15",
86
+ "@rspress/theme-default": "2.0.0-beta.15"
87
87
  },
88
88
  "devDependencies": {
89
89
  "@microsoft/api-extractor": "^7.52.8",
90
- "@rslib/core": "0.9.2",
90
+ "@rslib/core": "0.10.0",
91
91
  "@rspress-dev/plugin-preview": "link:../plugin-preview",
92
92
  "@types/hast": "^3.0.4",
93
93
  "@types/html-to-text": "^9.0.4",
@@ -95,11 +95,11 @@
95
95
  "@types/lodash-es": "^4.17.12",
96
96
  "@types/mdast": "^4.0.4",
97
97
  "@types/node": "^22.8.1",
98
- "@types/react": "^19.1.6",
98
+ "@types/react": "^19.1.8",
99
99
  "@types/react-dom": "^19.1.6",
100
100
  "memfs": "^4.17.2",
101
101
  "p-map": "^7.0.3",
102
- "postcss": "8.5.4",
102
+ "postcss": "8.5.5",
103
103
  "rehype-stringify": "^10.0.1",
104
104
  "remark-mdx": "^3.1.0",
105
105
  "remark-parse": "^11.0.0",