@rspress/core 2.0.23 → 2.1.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 (104) hide show
  1. package/dist/b~0.js +1 -3
  2. package/dist/cli/index.js +1 -1
  3. package/dist/{common-Qw-RoVFD.js → common-Bo3KCGim.js} +4 -1
  4. package/dist/config/loadConfigFile.js +1 -1
  5. package/dist/eject-theme/components/Link/getHref.ts +1 -0
  6. package/dist/eject-theme/components/Link/index.tsx +0 -3
  7. package/dist/eject-theme/components/Link/useLinkNavigate.ts +29 -54
  8. package/dist/eject-theme/components/Search/logic/providers/LocalProvider.ts +4 -1
  9. package/dist/eject-theme/components/Search/useSearchPanel.ts +103 -36
  10. package/dist/eject-theme/components/SocialLinks/GithubStars.test.tsx +4 -1
  11. package/dist/eject-theme/components/SocialLinks/GithubStars.tsx +1 -1
  12. package/dist/entry/worker.js +1 -1
  13. package/dist/{a~0.js → h~0.js} +18 -15
  14. package/dist/index.d.ts +1 -1
  15. package/dist/node/PluginDriver.js +8 -2
  16. package/dist/node/auto-nav-sidebar/index.js +1 -1
  17. package/dist/node/auto-nav-sidebar/locales.js +1 -1
  18. package/dist/node/auto-nav-sidebar/normalize.js +1 -1
  19. package/dist/node/auto-nav-sidebar/utils.js +1 -1
  20. package/dist/node/auto-nav-sidebar/walk.js +1 -1
  21. package/dist/node/eject.js +1 -1
  22. package/dist/node/initRsbuild.js +8 -4
  23. package/dist/node/llms.d.ts +1 -1
  24. package/dist/node/llms.js +2 -2
  25. package/dist/node/logger/hint.d.ts +1 -0
  26. package/dist/node/logger/hint.js +8 -2
  27. package/dist/node/route/RoutePage.js +1 -1
  28. package/dist/node/route/RouteService.js +1 -1
  29. package/dist/node/route/extractPageData.js +1 -1
  30. package/dist/node/route/normalizeRoutePath.js +1 -1
  31. package/dist/node/runtimeModule/DEFAULT_I18N_TEXT.d.ts +28 -0
  32. package/dist/node/runtimeModule/DEFAULT_I18N_TEXT.js +28 -0
  33. package/dist/node/runtimeModule/i18n.js +1 -1
  34. package/dist/node/runtimeModule/pageData/createPageData.js +1 -1
  35. package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +1 -1
  36. package/dist/node/runtimeModule/searchHooks.js +2 -2
  37. package/dist/node/runtimeModule/siteData/createSiteData.js +1 -1
  38. package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +1 -1
  39. package/dist/node/runtimeModule/siteData/rsbuildPlugin.js +1 -1
  40. package/dist/node/serve.js +1 -1
  41. package/dist/node/sitemap.d.ts +2 -0
  42. package/dist/node/sitemap.js +103 -0
  43. package/dist/node/ssg/alternateLinks.js +1 -1
  44. package/dist/node/ssg/renderPages.js +1 -1
  45. package/dist/node/ssg/rsbuildPluginSSG.js +1 -1
  46. package/dist/node/ssg/ssgEnv.js +1 -1
  47. package/dist/node/ssg-md/llms/emitLlmsTxt.js +1 -1
  48. package/dist/node/ssg-md/llms/llmsTxt.js +1 -1
  49. package/dist/node/ssg-md/renderPage.js +5 -4
  50. package/dist/node/ssg-md/renderPages.js +1 -1
  51. package/dist/node/ssg-md/rsbuildPluginSSGMD.js +1 -1
  52. package/dist/node/utils/checkLanguageParity.js +1 -1
  53. package/dist/node/utils/createHash.js +1 -1
  54. package/dist/node/utils/flattenMdxContent.js +1 -1
  55. package/dist/node/utils/getPageKey.js +1 -1
  56. package/dist/node/utils/reactAlias.js +5 -2
  57. package/dist/runtime/App.js +12 -25
  58. package/dist/runtime/ClientApp.d.ts +3 -2
  59. package/dist/runtime/ClientApp.js +27 -21
  60. package/dist/runtime/ErrorRoute.d.ts +1 -0
  61. package/dist/runtime/ErrorRoute.js +30 -0
  62. package/dist/runtime/PageRoute.d.ts +2 -0
  63. package/dist/runtime/PageRoute.js +58 -0
  64. package/dist/runtime/createServerRouter.d.ts +4 -0
  65. package/dist/runtime/createServerRouter.js +17 -0
  66. package/dist/runtime/csrClientEntry.js +5 -2
  67. package/dist/runtime/hooks/useWebMcp.d.ts +36 -0
  68. package/dist/runtime/hooks/useWebMcp.js +80 -0
  69. package/dist/runtime/index.d.ts +3 -1
  70. package/dist/runtime/index.js +3 -1
  71. package/dist/runtime/initPageData.d.ts +0 -3
  72. package/dist/runtime/initPageData.js +9 -45
  73. package/dist/runtime/pageDataLoader.d.ts +11 -0
  74. package/dist/runtime/pageDataLoader.js +7 -0
  75. package/dist/runtime/ssrClientEntry.js +14 -6
  76. package/dist/runtime/ssrMdServerEntry.js +10 -21
  77. package/dist/runtime/ssrServerEntry.js +10 -21
  78. package/dist/static/assets/package.json +58 -0
  79. package/dist/theme/components/Link/index.js +0 -4
  80. package/dist/theme/components/Link/useLinkNavigate.d.ts +2 -2
  81. package/dist/theme/components/Link/useLinkNavigate.js +13 -35
  82. package/dist/theme/components/Search/logic/providers/LocalProvider.js +4 -1
  83. package/dist/theme/components/Search/useSearchPanel.js +74 -26
  84. package/dist/theme/components/SocialLinks/GithubStars.js +1 -1
  85. package/dist/theme/hooks/useWebMcpNavigation.d.ts +6 -0
  86. package/dist/theme/hooks/useWebMcpNavigation.js +123 -0
  87. package/dist/theme/hooks/useWebMcpPageList.d.ts +6 -0
  88. package/dist/theme/hooks/useWebMcpPageList.js +25 -0
  89. package/dist/theme/hooks/useWebMcpPageReading.d.ts +7 -0
  90. package/dist/theme/hooks/useWebMcpPageReading.js +23 -0
  91. package/dist/theme/hooks/useWebMcpSiteInfo.d.ts +6 -0
  92. package/dist/theme/hooks/useWebMcpSiteInfo.js +22 -0
  93. package/dist/theme/index.d.ts +5 -0
  94. package/dist/theme/index.js +5 -0
  95. package/dist/theme/layout/ErrorLayout/index.css +52 -0
  96. package/dist/theme/layout/ErrorLayout/index.d.ts +8 -0
  97. package/dist/theme/layout/ErrorLayout/index.js +76 -0
  98. package/dist/theme/webMcp/tools.d.ts +56 -0
  99. package/dist/theme/webMcp/tools.js +122 -0
  100. package/dist/theme/webMcp/types.d.ts +35 -0
  101. package/dist/theme/webMcp/types.js +0 -0
  102. package/dist/tinypool~0.js +19 -49
  103. package/dist/tu~0.js +3 -0
  104. package/package.json +12 -12
package/dist/b~0.js CHANGED
@@ -1,6 +1,4 @@
1
- var package_namespaceObject = {
2
- rE: "2.0.23"
3
- };
1
+ var package_namespaceObject = /*#__PURE__*/ JSON.parse('{"rE":"2.1.0-beta.1"}');
4
2
  async function pMap(iterable, mapper, { concurrency = 1 / 0, stopOnError = true, signal } = {}) {
5
3
  return new Promise((resolve_, reject_)=>{
6
4
  if (void 0 === iterable[Symbol.iterator] && void 0 === iterable[Symbol.asyncIterator]) throw new TypeError(`Expected \`input\` to be either an \`Iterable\` or \`AsyncIterable\`, got (${typeof iterable})`);
package/dist/cli/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { logger, cac } from "../a~0.js";
1
+ import { logger, cac } from "../h~0.js";
2
2
  import { package_namespaceObject } from "../b~0.js";
3
3
  import { loadConfigFile, resolveDocRoot } from "../config/loadConfigFile.js";
4
4
  import { dev } from "../node/dev.js";
@@ -16,10 +16,13 @@ function markMovable(value) {
16
16
  value: true
17
17
  });
18
18
  }
19
+ function withNullPrototype(source) {
20
+ return Object.assign(Object.create(null), source);
21
+ }
19
22
  function isTaskQueue(value) {
20
23
  return "object" == typeof value && null !== value && "size" in value && "function" == typeof value.shift && "function" == typeof value.remove && "function" == typeof value.push;
21
24
  }
22
25
  const kRequestCountField = 0;
23
26
  const kResponseCountField = 1;
24
27
  const kFieldCount = 2;
25
- export { isMovable, isTaskQueue, isTransferable, kFieldCount, kQueueOptions, kRequestCountField, kResponseCountField, kTransferable, kValue, markMovable };
28
+ export { isMovable, isTaskQueue, isTransferable, kFieldCount, kQueueOptions, kRequestCountField, kResponseCountField, kTransferable, kValue, markMovable, withNullPrototype };
@@ -1,4 +1,4 @@
1
- import { node_path, logger, DEFAULT_CONFIG_NAME, DEFAULT_CONFIG_EXTENSIONS } from "../a~0.js";
1
+ import { node_path, logger, DEFAULT_CONFIG_NAME, DEFAULT_CONFIG_EXTENSIONS } from "../h~0.js";
2
2
  async function loadConfigFile(customConfigFile) {
3
3
  const { loadConfig } = await import("@rsbuild/core");
4
4
  const result = await loadConfig({
@@ -1,4 +1,5 @@
1
1
  import { cleanUrl, isExternalUrl } from '@rspress/shared';
2
+ // eslint-disable-next-line no-restricted-imports -- Existing cross-directory dependency; retained until this component is eject-safe.
2
3
  import { cleanUrlByConfig, removeBase, withBase } from '../../../runtime/utils';
3
4
 
4
5
  type LinkType = 'external' | 'hashOnly' | 'relative' | 'internal';
@@ -1,6 +1,5 @@
1
1
  import { preloadLink } from '@rspress/core/runtime';
2
2
  import clsx from 'clsx';
3
- import nprogress from 'nprogress';
4
3
  import type React from 'react';
5
4
  import type { ComponentProps, TransitionStartFunction } from 'react';
6
5
  import { forwardRef } from 'react';
@@ -35,8 +34,6 @@ export interface LinkProps extends ComponentProps<'a'> {
35
34
  startTransition?: TransitionStartFunction;
36
35
  }
37
36
 
38
- nprogress.configure({ showSpinner: false });
39
-
40
37
  /**
41
38
  * What's the difference between <Link> and <a>?
42
39
  * Link can tell whether it's in current site or external site.
@@ -1,35 +1,24 @@
1
1
  import {
2
- initPageData,
3
2
  isActive,
4
3
  pathnameToRouteService,
5
4
  useLocation,
6
- useNavigate as useNavigateInner,
5
+ useNavigate,
7
6
  useSite,
8
- warmPageData,
9
7
  } from '@rspress/core/runtime';
10
- import nprogress from 'nprogress';
11
- import {
12
- startTransition as reactStartTransition,
13
- type TransitionStartFunction,
14
- useCallback,
15
- } from 'react';
8
+ import { type TransitionStartFunction, useCallback } from 'react';
16
9
  import { getHref } from './getHref';
17
10
 
18
- nprogress.configure({ showSpinner: false });
19
-
20
11
  /**
21
- * For import { Link } from '@rspress/core/theme';
22
- * useNavigate with preload logic
12
+ * Navigate with Rspress link normalization. The router loader handles page
13
+ * loading for both this helper and the native useNavigate hook.
23
14
  */
24
- export function useLinkNavigate(
25
- {
26
- startTransition = reactStartTransition,
27
- }: { startTransition?: TransitionStartFunction } = {
28
- startTransition: reactStartTransition,
29
- },
30
- ): (href: string) => Promise<void> {
31
- const { pathname: currPagePathname } = useLocation();
32
- const navigate = useNavigateInner();
15
+ export function useLinkNavigate({
16
+ startTransition,
17
+ }: { startTransition?: TransitionStartFunction } = {}): (
18
+ href: string,
19
+ ) => Promise<void> {
20
+ const { pathname } = useLocation();
21
+ const navigate = useNavigate();
33
22
  const { site } = useSite();
34
23
  const useTransitions = site?.route?.useTransitions;
35
24
 
@@ -41,41 +30,27 @@ export function useLinkNavigate(
41
30
  window.location.assign(href);
42
31
  return;
43
32
  }
33
+ // Keep same-page links client-side, including on a 404 page, so clicking
34
+ // a parent menu link does not reload the document and close its submenu.
35
+ if (
36
+ !isActive(removeBaseHref, pathname) &&
37
+ !pathnameToRouteService(routePath)
38
+ ) {
39
+ window.location.assign(withBaseHref);
40
+ return;
41
+ }
44
42
 
45
- const isTransitionable = !!(useTransitions && startTransition);
46
- const preloadChunkThenNavigate = async () => {
47
- const inCurrPage = isActive(removeBaseHref, currPagePathname);
48
-
49
- if (!import.meta.env.SSR && !inCurrPage) {
50
- const matchedRoute = pathnameToRouteService(routePath);
51
- if (matchedRoute) {
52
- const timer = setTimeout(() => {
53
- nprogress.start();
54
- }, 200);
55
- const data = await initPageData(routePath);
56
- warmPageData(routePath, data);
57
- clearTimeout(timer);
58
- nprogress.done();
59
- } else {
60
- window.location.assign(withBaseHref);
61
- return;
62
- }
63
- }
64
- if (isTransitionable) {
65
- startTransition(() => {
66
- return navigate(removeBaseHref, { replace: false });
67
- });
68
- } else {
69
- navigate(removeBaseHref, { replace: false });
70
- }
71
- };
72
-
73
- if (isTransitionable) {
74
- startTransition(preloadChunkThenNavigate);
43
+ if (useTransitions && startTransition) {
44
+ let navigation: void | Promise<void> = undefined;
45
+ startTransition(() => {
46
+ navigation = navigate(removeBaseHref);
47
+ return navigation;
48
+ });
49
+ await navigation;
75
50
  } else {
76
- preloadChunkThenNavigate();
51
+ await navigate(removeBaseHref);
77
52
  }
78
53
  },
79
- [useTransitions, currPagePathname, navigate, startTransition],
54
+ [useTransitions, pathname, navigate, startTransition],
80
55
  );
81
56
  }
@@ -124,7 +124,10 @@ export class LocalProvider implements Provider {
124
124
  this.#fetchPromise = this.#getPages(
125
125
  currentLang,
126
126
  versioned ? currentVersion : '',
127
- );
127
+ ).catch(error => {
128
+ this.#fetchPromise = undefined;
129
+ throw error;
130
+ });
128
131
 
129
132
  return this.#fetchPromise;
130
133
  }
@@ -1,4 +1,4 @@
1
- import { usePageData, useSearchHooks } from '@rspress/core/runtime';
1
+ import { usePageData, useSearchHooks, useWebMcp } from '@rspress/core/runtime';
2
2
  import type { LocalSearchOptions } from '@rspress/core';
3
3
  import { debounce } from '@rspress/shared/lodash-es';
4
4
  import {
@@ -18,6 +18,12 @@ import type {
18
18
  PageSearcherConfig,
19
19
  } from './logic/types';
20
20
  import { RenderType } from './logic/types';
21
+ // eslint-disable-next-line no-restricted-imports -- Existing cross-directory dependency; retained until this component is eject-safe.
22
+ import {
23
+ defineTool,
24
+ queryField,
25
+ toWebMcpSearchResults,
26
+ } from '../../webMcp/tools';
21
27
 
22
28
  const useDebounce = <T extends (...args: any[]) => any>(cb: T) => {
23
29
  const cbRef = useRef(cb);
@@ -55,6 +61,10 @@ export function useSearchPanel({
55
61
  const [searchError, setSearchError] = useState<string>();
56
62
  const pageSearcherRef = useRef<PageSearcher | null>(null);
57
63
  const pageSearcherConfigRef = useRef<PageSearcherConfig | null>(null);
64
+ const pageSearcherURLRef = useRef<string | undefined>(undefined);
65
+ const initializationRef = useRef<
66
+ { searcher: PageSearcher; promise: Promise<void> } | undefined
67
+ >(undefined);
58
68
  const searchEnabled = search !== false;
59
69
  const searchOptions: LocalSearchOptions = search === false ? {} : search;
60
70
  const versionedSearch = searchEnabled && (search?.versioned ?? true);
@@ -66,7 +76,13 @@ export function useSearchPanel({
66
76
  ];
67
77
 
68
78
  const createSearcher = () => {
69
- if (pageSearcherRef.current) {
79
+ const previous = pageSearcherConfigRef.current;
80
+ if (
81
+ pageSearcherRef.current &&
82
+ previous?.currentLang === lang &&
83
+ (!versionedSearch || previous.currentVersion === version) &&
84
+ pageSearcherURLRef.current === searchIndexURL
85
+ ) {
70
86
  return pageSearcherRef.current;
71
87
  }
72
88
  const pageSearcherConfig = { currentLang: lang, currentVersion: version };
@@ -77,9 +93,75 @@ export function useSearchPanel({
77
93
  });
78
94
  pageSearcherRef.current = pageSearcher;
79
95
  pageSearcherConfigRef.current = pageSearcherConfig;
96
+ pageSearcherURLRef.current = searchIndexURL;
80
97
  return pageSearcher;
81
98
  };
82
99
 
100
+ // UI searches and agent calls initialize the same provider once, on demand.
101
+ const initializeSearcher = (searcher: PageSearcher) => {
102
+ if (initializationRef.current?.searcher === searcher)
103
+ return initializationRef.current.promise;
104
+ const promise = searcher.init().catch(error => {
105
+ if (initializationRef.current?.searcher === searcher)
106
+ initializationRef.current = undefined;
107
+ throw error;
108
+ });
109
+ initializationRef.current = { searcher, promise };
110
+ return promise;
111
+ };
112
+
113
+ const searchDocs = async (value: string, limit?: number) => {
114
+ const searcher = createSearcher();
115
+ let newQuery = value;
116
+ const result: MatchResult = [];
117
+ if (userSearchHooks.beforeSearch) {
118
+ const transformedQuery = await userSearchHooks.beforeSearch(newQuery);
119
+ if (transformedQuery) newQuery = transformedQuery;
120
+ }
121
+ await initializeSearcher(searcher);
122
+ const defaultSearchResult = await searcher.match(newQuery, limit);
123
+ result.push(...defaultSearchResult);
124
+ if (userSearchHooks.onSearch) {
125
+ const customSearchResult = await userSearchHooks.onSearch(
126
+ newQuery,
127
+ result as DefaultMatchResult[],
128
+ );
129
+ if (customSearchResult)
130
+ result.push(
131
+ ...customSearchResult.map(
132
+ item =>
133
+ ({ renderType: RenderType.Custom, ...item }) as CustomMatchResult,
134
+ ),
135
+ );
136
+ }
137
+ await userSearchHooks.afterSearch?.(newQuery, result);
138
+ return result;
139
+ };
140
+
141
+ // Build-time gating keeps tool code out of sites that do not enable WebMCP.
142
+ if (import.meta.env.ENABLE_WEBMCP) {
143
+ useWebMcp({
144
+ ...defineTool(
145
+ 'search_docs',
146
+ 'Search documentation through the active local search component.',
147
+ {
148
+ query: queryField,
149
+ limit: { type: 'integer', minimum: 1, maximum: 20 },
150
+ },
151
+ ['query'],
152
+ async args =>
153
+ toWebMcpSearchResults(
154
+ await searchDocs(
155
+ args.query as string,
156
+ (args.limit as number | undefined) ?? 10,
157
+ ),
158
+ ),
159
+ ),
160
+ enabled:
161
+ searchEnabled && Boolean(searchIndexURL || userSearchHooks.onSearch),
162
+ });
163
+ }
164
+
83
165
  const initSearch = async () => {
84
166
  if (initStatus !== 'initial') {
85
167
  return;
@@ -88,7 +170,7 @@ export function useSearchPanel({
88
170
  setSearchError(undefined);
89
171
  setInitStatus('initing');
90
172
  try {
91
- await searcher.init();
173
+ await initializeSearcher(searcher);
92
174
  } catch (error) {
93
175
  if (pageSearcherRef.current !== searcher) {
94
176
  return;
@@ -135,52 +217,37 @@ export function useSearchPanel({
135
217
  const { currentLang, currentVersion } = pageSearcherConfigRef.current ?? {};
136
218
  const isLangChanged = lang !== currentLang;
137
219
  const isVersionChanged = versionedSearch && version !== currentVersion;
138
- if (isLangChanged || isVersionChanged) {
220
+ const isIndexChanged = pageSearcherURLRef.current !== searchIndexURL;
221
+ if (isLangChanged || isVersionChanged || isIndexChanged) {
139
222
  setInitStatus('initial');
140
223
  setSearchError(undefined);
141
224
  setIsSearching(false);
142
225
  pageSearcherRef.current = null;
143
- createSearcher()
144
- .fetchSearchIndex()
145
- .catch(() => {});
146
226
  }
147
- }, [lang, version, versionedSearch, searchEnabled]);
227
+ }, [lang, version, versionedSearch, searchEnabled, searchIndexURL]);
148
228
 
149
229
  const handleQueryChangedImpl = async (value: string) => {
150
- let newQuery = value;
230
+ const newQuery = value;
151
231
  setQuery(newQuery);
152
232
  if (!newQuery) {
153
233
  setIsSearching(false);
154
234
  return;
155
235
  }
156
- const result: MatchResult = [];
157
- if (userSearchHooks.beforeSearch) {
158
- const transformedQuery = await userSearchHooks.beforeSearch(newQuery);
159
- if (transformedQuery) newQuery = transformedQuery;
160
- }
161
- const defaultSearchResult = await pageSearcherRef.current?.match(newQuery);
162
- if (defaultSearchResult) result.push(...defaultSearchResult);
163
- if (userSearchHooks.onSearch) {
164
- const customSearchResult = await userSearchHooks.onSearch(
165
- newQuery,
166
- result as DefaultMatchResult[],
167
- );
168
- if (customSearchResult) {
169
- result.push(
170
- ...customSearchResult.map(
171
- item =>
172
- ({ renderType: RenderType.Custom, ...item }) as CustomMatchResult,
173
- ),
174
- );
236
+ try {
237
+ const result = await searchDocs(value);
238
+ if (searchInputRef.current?.value === newQuery) {
239
+ setSearchError(undefined);
240
+ setInitStatus('inited');
241
+ setCurrentSuggestionIndex(0);
242
+ setSearchResult(result || DEFAULT_RESULT);
243
+ setIsSearching(false);
244
+ }
245
+ } catch (error) {
246
+ if (searchInputRef.current?.value === newQuery) {
247
+ setSearchError(error instanceof Error ? error.message : String(error));
248
+ setInitStatus('error');
249
+ setIsSearching(false);
175
250
  }
176
- }
177
- if (userSearchHooks.afterSearch) {
178
- await userSearchHooks.afterSearch(newQuery, result);
179
- }
180
- if (searchInputRef.current?.value === newQuery) {
181
- setCurrentSuggestionIndex(0);
182
- setSearchResult(result || DEFAULT_RESULT);
183
- setIsSearching(false);
184
251
  }
185
252
  };
186
253
 
@@ -1,7 +1,10 @@
1
- import { afterEach, describe, expect, it } from '@rstest/core';
1
+ import { afterEach, describe, expect, it, rs } from '@rstest/core';
2
2
  import { renderToStaticMarkup } from 'react-dom/server';
3
+ import { useStorageValue } from '../../logic/useStorageValue';
3
4
  import { GithubStars } from './GithubStars';
4
5
 
6
+ rs.mock('@rspress/core/theme', () => ({ useStorageValue }));
7
+
5
8
  const originalLocalStorage = Object.getOwnPropertyDescriptor(
6
9
  globalThis,
7
10
  'localStorage',
@@ -1,5 +1,5 @@
1
+ import { useStorageValue } from '@rspress/core/theme';
1
2
  import { type ReactNode, useEffect, useState } from 'react';
2
- import { useStorageValue } from '../../logic/useStorageValue';
3
3
 
4
4
  const TTL_MS = 60 * 60 * 1000;
5
5
 
@@ -1,4 +1,4 @@
1
- import { isMovable, kRequestCountField, kResponseCountField, kTransferable, kValue } from "../common-Qw-RoVFD.js";
1
+ import { isMovable, kRequestCountField, kResponseCountField, kTransferable, kValue } from "../common-Bo3KCGim.js";
2
2
  import { stderr, stdout } from "../utils-De75vAgL.js";
3
3
  import { getHandler, throwInNextTick } from "../utils-B--2TaWv.js";
4
4
  import { parentPort, receiveMessageOnPort, workerData } from "node:worker_threads";
@@ -1769,7 +1769,7 @@ function findAllBrackets(v) {
1769
1769
  }
1770
1770
  function getMriOptions(options) {
1771
1771
  const result = {
1772
- alias: {},
1772
+ alias: Object.create(null),
1773
1773
  boolean: []
1774
1774
  };
1775
1775
  for (const [index, option] of options.entries()){
@@ -1781,7 +1781,7 @@ function getMriOptions(options) {
1781
1781
  return result;
1782
1782
  }
1783
1783
  function findLongest(arr) {
1784
- return arr.sort((a, b)=>a.length > b.length ? -1 : 1)[0];
1784
+ return arr.sort((a, b)=>b.length - a.length)[0];
1785
1785
  }
1786
1786
  function padRight(str, length) {
1787
1787
  return str.length >= length ? str : `${str}${" ".repeat(length - str.length)}`;
@@ -1789,7 +1789,13 @@ function padRight(str, length) {
1789
1789
  function camelcase(input) {
1790
1790
  return input.replaceAll(/([a-z])-([a-z])/g, (_, p1, p2)=>p1 + p2.toUpperCase());
1791
1791
  }
1792
+ const UNSAFE_KEYS = /* @__PURE__ */ new Set([
1793
+ "__proto__",
1794
+ "constructor",
1795
+ "prototype"
1796
+ ]);
1792
1797
  function setDotProp(obj, keys, val) {
1798
+ if (keys.some((key)=>UNSAFE_KEYS.has(key))) return;
1793
1799
  let current = obj;
1794
1800
  for(let i = 0; i < keys.length; i++){
1795
1801
  const key = keys[i];
@@ -1805,14 +1811,11 @@ function setDotProp(obj, keys, val) {
1805
1811
  }
1806
1812
  }
1807
1813
  function setByType(obj, transforms) {
1808
- for (const key of Object.keys(transforms)){
1809
- const transform = transforms[key];
1810
- if (transform.shouldTransform) {
1811
- obj[key] = [
1812
- obj[key]
1813
- ].flat();
1814
- if ("function" == typeof transform.transformFunction) obj[key] = obj[key].map(transform.transformFunction);
1815
- }
1814
+ for (const [key, transform] of Object.entries(transforms))if (transform.shouldTransform) {
1815
+ obj[key] = [
1816
+ obj[key]
1817
+ ].flat();
1818
+ if ("function" == typeof transform.transformFunction) obj[key] = obj[key].map(transform.transformFunction);
1816
1819
  }
1817
1820
  }
1818
1821
  function getFileName(input) {
@@ -1851,7 +1854,7 @@ var Option = class {
1851
1854
  name = name.replace(/^no-/, "");
1852
1855
  }
1853
1856
  return camelcaseOptionName(name);
1854
- }).sort((a, b)=>a.length > b.length ? 1 : -1);
1857
+ }).sort((a, b)=>a.length - b.length);
1855
1858
  this.name = this.names.at(-1);
1856
1859
  if (this.negated && null == this.config.default) this.config.default = true;
1857
1860
  if (rawName.includes("<")) this.required = true;
@@ -1937,7 +1940,7 @@ var Command = class {
1937
1940
  return this instanceof GlobalCommand;
1938
1941
  }
1939
1942
  hasOption(name) {
1940
- name = name.split(".")[0];
1943
+ name = name.split(".", 1)[0];
1941
1944
  return this.options.find((option)=>option.names.includes(name));
1942
1945
  }
1943
1946
  outputHelp() {
@@ -2006,7 +2009,7 @@ var Command = class {
2006
2009
  ...this.options
2007
2010
  ];
2008
2011
  for (const option of options){
2009
- const value = parsedOptions[option.name.split(".")[0]];
2012
+ const value = parsedOptions[option.name.split(".", 1)[0]];
2010
2013
  if (option.required) {
2011
2014
  const hasNegated = options.some((o)=>o.negated && o.names.includes(option.name));
2012
2015
  if (true === value || false === value && !hasNegated) throw new CACError(`option \`${option.rawName}\` value is missing`);
@@ -2181,8 +2184,8 @@ var CAC = class extends EventTarget {
2181
2184
  transforms[cliOption.name].transformFunction = cliOption.config.type[0];
2182
2185
  }
2183
2186
  }
2184
- for (const key of Object.keys(parsed))if ("_" !== key) {
2185
- setDotProp(options, key.split("."), parsed[key]);
2187
+ for (const [key, value] of Object.entries(parsed))if ("_" !== key) {
2188
+ setDotProp(options, key.split("."), value);
2186
2189
  setByType(options, transforms);
2187
2190
  }
2188
2191
  return {
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type { DarkMode, EditLink, Feature, FrontMatterMeta, Header, Hero, I18nText, LlmsTxtContext, LlmsTxtPage, LlmsTxtRenderer, LlmsTxtSection, LocalSearchOptions, Nav, NavItem, NavItemWithChildren, NavItemWithLink, NavItemWithLinkAndChildren, NormalizedSidebarGroup, PageIndexInfo, RemotePageInfo, RouteMeta, RspressPlugin, Sidebar, SidebarData, SidebarDivider, SidebarGroup, SidebarItem, SidebarSectionHeader, SocialLink, UserConfig, } from '@rspress/shared';
1
+ export type { DarkMode, EditLink, Feature, FrontMatterMeta, Header, Hero, I18nText, LlmsTxtContext, LlmsTxtPage, LlmsTxtRenderer, LlmsTxtSection, LocalSearchOptions, Nav, NavItem, NavItemWithChildren, NavItemWithLink, NavItemWithLinkAndChildren, NormalizedSidebarGroup, PageIndexInfo, RemotePageInfo, RouteMeta, RspressPlugin, Sidebar, SidebarData, SidebarDivider, SidebarGroup, SidebarItem, SidebarSectionHeader, SitemapOptions, SocialLink, UserConfig, } from '@rspress/shared';
2
2
  export { getSidebarDataGroup, normalizeHref, normalizePosixPath, RSPRESS_TEMP_DIR, removeTrailingSlash, withBase, withSiteOrigin, } from '@rspress/shared';
3
3
  export { logger } from '@rspress/shared/logger';
4
4
  export { getIconUrlPath, getNodeAttribute, mergeDocConfig, } from '@rspress/shared/node-utils';
@@ -1,4 +1,4 @@
1
- import { addTrailingSlash, node_path, addLeadingSlash } from "../a~0.js";
1
+ import { addTrailingSlash, node_path, addLeadingSlash } from "../h~0.js";
2
2
  import { createError } from "./utils/error.js";
3
3
  import { haveNavSidebarConfig as auto_nav_sidebar_haveNavSidebarConfig } from "./auto-nav-sidebar/index.js";
4
4
  class PluginDriver {
@@ -31,6 +31,10 @@ class PluginDriver {
31
31
  const { pluginMediumZoom } = await import("./medium-zoom/index.js");
32
32
  this.addPlugin(pluginMediumZoom('object' == typeof mediumZoomConfig ? mediumZoomConfig : void 0));
33
33
  }
34
+ if (this.#isProd) {
35
+ const { pluginSitemap } = await import("./sitemap.js");
36
+ this.addPlugin(pluginSitemap());
37
+ }
34
38
  (config.plugins || []).forEach((plugin)=>{
35
39
  this.addPlugin(plugin);
36
40
  });
@@ -53,7 +57,9 @@ class PluginDriver {
53
57
  async normalizeConfig() {
54
58
  this.#config.root ??= 'docs';
55
59
  this.#config.ssg ??= true;
56
- this.#config.llms ??= false;
60
+ this.#config.llms ??= true;
61
+ this.#config.webMcp ??= true;
62
+ this.#config.sitemap ??= true;
57
63
  this.#config.base = addTrailingSlash(addLeadingSlash(this.#config.base ?? '/'));
58
64
  this.#config.lang ??= 'en';
59
65
  this.#config.themeDir ??= node_path.join(process.cwd(), 'theme');
@@ -1,4 +1,4 @@
1
- import { DEFAULT_PAGE_EXTENSIONS, node_path } from "../../a~0.js";
1
+ import { DEFAULT_PAGE_EXTENSIONS, node_path } from "../../h~0.js";
2
2
  import { processLocales, combineWalkResult } from "./locales.js";
3
3
  import { walk } from "./walk.js";
4
4
  async function runAutoNavSide(config, metaFileSet, mdFileSet) {
@@ -1,4 +1,4 @@
1
- import { node_path } from "../../a~0.js";
1
+ import { node_path } from "../../h~0.js";
2
2
  import { walk } from "./walk.js";
3
3
  function combineWalkResult(walks, versions) {
4
4
  return walks.reduce((acc, cur, curIndex)=>({
@@ -1,6 +1,6 @@
1
1
  import { rspackRequire, compatGetDefaultExport } from "../../rslib-runtime~0.js";
2
2
  import "../../t~0.js";
3
- import { extname, logger, promises_readdir, external_node_path_relative, isExternalUrl, slash, promises_stat, join } from "../../a~0.js";
3
+ import { extname, logger, promises_readdir, external_node_path_relative, isExternalUrl, slash, promises_stat, join } from "../../h~0.js";
4
4
  import { createError } from "../utils/error.js";
5
5
  import { pathExists, extractInfoFromFrontmatterWithAbsolutePath, readJson } from "./utils.js";
6
6
  import { absolutePathToRoutePath, addRoutePrefix } from "../route/RoutePage.js";
@@ -1,4 +1,4 @@
1
- import { node_path, extractTextAndId, promises, loadFrontMatter } from "../../a~0.js";
1
+ import { node_path, extractTextAndId, promises, loadFrontMatter } from "../../h~0.js";
2
2
  import { createError } from "../utils/error.js";
3
3
  async function pathExists(path) {
4
4
  try {
@@ -1,4 +1,4 @@
1
- import { isExternalUrl, node_path, promises } from "../../a~0.js";
1
+ import { isExternalUrl, node_path, promises } from "../../h~0.js";
2
2
  import { pathExists } from "../utils/fs.js";
3
3
  import { readJson } from "./utils.js";
4
4
  import { addRoutePrefix } from "../route/RoutePage.js";
@@ -1,6 +1,6 @@
1
1
  import { rspackRequire, compatGetDefaultExport } from "../rslib-runtime~0.js";
2
2
  import "../t~0.js";
3
- import { node_path, logger, promises } from "../a~0.js";
3
+ import { node_path, logger, promises } from "../h~0.js";
4
4
  import { EJECTED_THEME } from "./constants.js";
5
5
  const picocolors = rspackRequire("../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js");
6
6
  var picocolors_default = /*#__PURE__*/ compatGetDefaultExport(picocolors);
@@ -1,4 +1,4 @@
1
- import { external_node_process_cwd, node_path, fileURLToPath, addTrailingSlash, PLUGIN_REACT_NAME, removeTrailingSlash, normalizeDarkMode, pluginVirtualModule, pluginReact, createRequire, MDX_OR_MD_REGEXP } from "../a~0.js";
1
+ import { external_node_process_cwd, node_path, fileURLToPath, addTrailingSlash, PLUGIN_REACT_NAME, removeTrailingSlash, normalizeDarkMode, pluginVirtualModule, pluginReact, createRequire, MDX_OR_MD_REGEXP } from "../h~0.js";
2
2
  import { createError } from "./utils/error.js";
3
3
  import { CSR_CLIENT_ENTRY, SSR_CLIENT_ENTRY, OUTPUT_DIR, SSG_MD_SERVER_ENTRY, NODE_SSG_BUNDLE_FOLDER, getInlineLocaleRedirectScript, isProduction, PACKAGE_ROOT, SSR_SERVER_ENTRY, TEMPLATE_PATH, NODE_SSG_MD_BUNDLE_FOLDER, DEFAULT_THEME, NODE_SSG_MD_BUNDLE_NAME, getInlineThemeScript, DEFAULT_TITLE, NODE_SSG_BUNDLE_NAME } from "./constants.js";
4
4
  import { isLlmsUIEnabled, isLlmsHintEnabled } from "./llms.js";
@@ -186,8 +186,11 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
186
186
  PACKAGE_ROOT
187
187
  ],
188
188
  define: {
189
+ 'import.meta.env.ENABLE_WEBMCP': JSON.stringify(false !== config.webMcp),
190
+ 'import.meta.env.WEBMCP_EXPOSED_TO': JSON.stringify('object' == typeof config.webMcp ? config.webMcp.exposedTo ?? [] : []),
189
191
  'import.meta.env.ENABLE_LLMS_UI': JSON.stringify(enableLlmsUI),
190
- 'import.meta.env.ENABLE_LLMS_HINT': JSON.stringify(enableLlmsHint)
192
+ 'import.meta.env.ENABLE_LLMS_HINT': JSON.stringify(enableLlmsHint),
193
+ 'import.meta.env.ENABLE_SSG_MD': JSON.stringify(Boolean(enableSSG && config.llms))
191
194
  }
192
195
  },
193
196
  performance: {
@@ -283,7 +286,7 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
283
286
  },
284
287
  source: {
285
288
  entry: {
286
- index: enableSSG && isProduction() ? SSR_CLIENT_ENTRY : CSR_CLIENT_ENTRY
289
+ index: enableSSG && config.ssg && isProduction() ? SSR_CLIENT_ENTRY : CSR_CLIENT_ENTRY
287
290
  },
288
291
  define: {
289
292
  'process.env.__SSR__': JSON.stringify(false),
@@ -361,7 +364,8 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
361
364
  define: {
362
365
  'process.env.__SSR__': JSON.stringify(true),
363
366
  'process.env.__SSR_MD__': JSON.stringify(true),
364
- 'import.meta.env.SSG_MD': JSON.stringify(true)
367
+ 'import.meta.env.SSG_MD': JSON.stringify(true),
368
+ 'import.meta.env.ENABLE_LLMS_HINT': JSON.stringify(isLlmsHintEnabled(config, enableSSG, 'markdown'))
365
369
  }
366
370
  },
367
371
  output: {
@@ -1,3 +1,3 @@
1
1
  import type { UserConfig } from '@rspress/shared';
2
2
  export declare function isLlmsUIEnabled(config: UserConfig): boolean;
3
- export declare function isLlmsHintEnabled(config: UserConfig, enableSSG: boolean): boolean;
3
+ export declare function isLlmsHintEnabled(config: UserConfig, enableSSG: boolean, output?: 'html' | 'markdown'): boolean;
package/dist/node/llms.js CHANGED
@@ -1,8 +1,8 @@
1
1
  function isLlmsUIEnabled(config) {
2
2
  return Boolean(config.themeConfig?.llmsUI ?? config.llms);
3
3
  }
4
- function isLlmsHintEnabled(config, enableSSG) {
4
+ function isLlmsHintEnabled(config, enableSSG, output = 'html') {
5
5
  const llmsUI = config.themeConfig?.llmsUI;
6
- return enableSSG && false !== config.ssg && isLlmsUIEnabled(config) && ('object' != typeof llmsUI || false !== llmsUI.injectLlmsHint);
6
+ return enableSSG && ('markdown' === output ? Boolean(config.llms) : false !== config.ssg) && isLlmsUIEnabled(config) && ('object' != typeof llmsUI || false !== llmsUI.injectLlmsHint);
7
7
  }
8
8
  export { isLlmsHintEnabled, isLlmsUIEnabled };
@@ -7,6 +7,7 @@ import type { NavJson } from '../auto-nav-sidebar/type.js';
7
7
  export declare function hintThemeBreakingChange(customThemeDir: string): Promise<void>;
8
8
  export declare function hintBuilderPluginsBreakingChange(config: UserConfig): void;
9
9
  export declare function hintSSGFailed(): void;
10
+ export declare function hintSSGMDFailed(): void;
10
11
  /**
11
12
  * Print "ssg: false" explicitly to give users a clear perception.
12
13
  */