@rspress/core 2.0.0-rc.1 → 2.0.0-rc.2
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/bin/rspress.js +1 -1
- package/dist/0~7675.989ee664.js +1791 -0
- package/dist/1218.3869bad6.js +2 -0
- package/dist/4669.12208c6a.js +2 -0
- package/dist/5313.6594aba0.js +63 -0
- package/dist/5485.2a0273cf.js +98 -0
- package/dist/6289.c67fe0d5.js +5 -0
- package/dist/7805.cadab34e.js +4 -0
- package/dist/8813.9da1f210.js +2 -0
- package/dist/cli/config/index.js +4 -0
- package/dist/cli/config/loadConfigFile.js +30 -0
- package/dist/cli/index.cb89dbd1.js +3 -0
- package/dist/cli/index.js +122 -0
- package/dist/eject-theme/components/Banner/index.tsx +3 -4
- package/dist/eject-theme/components/Callout/index.scss +0 -2
- package/dist/eject-theme/components/CodeBlock/index.scss +4 -12
- package/dist/eject-theme/components/CodeBlock/index.tsx +6 -1
- package/dist/eject-theme/components/CodeButtonGroup/CopyCodeButton.tsx +1 -3
- package/dist/eject-theme/components/CodeButtonGroup/index.scss +5 -1
- package/dist/eject-theme/components/CodeButtonGroup/index.tsx +1 -3
- package/dist/eject-theme/components/DocContent/doc.scss +27 -7
- package/dist/eject-theme/components/DocContent/docComponents/table.tsx +10 -4
- package/dist/eject-theme/components/DocContent/index.tsx +3 -3
- package/dist/eject-theme/components/{DocContent/FallbackHeading.tsx → FallbackHeading/index.tsx} +20 -11
- package/dist/eject-theme/components/Link/index.tsx +13 -4
- package/dist/eject-theme/components/Nav/NavMenu.tsx +2 -3
- package/dist/eject-theme/components/NavHamburger/index.tsx +3 -4
- package/dist/eject-theme/components/NavScreen/NavScreenMenuItem.tsx +2 -3
- package/dist/eject-theme/components/Overview/OverviewGroup.tsx +1 -2
- package/dist/eject-theme/components/Overview/index.tsx +6 -2
- package/dist/eject-theme/components/PackageManagerTabs/index.tsx +12 -0
- package/dist/eject-theme/components/PrevNextPage/index.tsx +6 -3
- package/dist/eject-theme/components/Root/index.tsx +58 -0
- package/dist/eject-theme/components/Search/NoSearchResult.tsx +2 -3
- package/dist/eject-theme/components/Search/SearchButton.tsx +3 -4
- package/dist/eject-theme/components/Search/SearchPanel.tsx +12 -7
- package/dist/eject-theme/components/Search/SuggestItem.tsx +15 -12
- package/dist/eject-theme/components/Sidebar/SidebarGroup.tsx +2 -3
- package/dist/eject-theme/components/Sidebar/SidebarItem.tsx +1 -0
- package/dist/eject-theme/components/SidebarMenu/index.tsx +4 -4
- package/dist/eject-theme/components/SocialLinks/index.tsx +2 -3
- package/dist/eject-theme/components/SourceCode/index.tsx +6 -4
- package/dist/eject-theme/components/SwitchAppearance/index.tsx +3 -5
- package/dist/eject-theme/components/Tabs/index.scss +19 -22
- package/dist/eject-theme/components/Toc/TocItem.scss +3 -3
- package/dist/eject-theme/components/Toc/TocItem.tsx +1 -0
- package/dist/index.d.ts +6 -6
- package/dist/index.js +16 -3134
- package/dist/node/PluginDriver.d.ts +1 -1
- package/dist/node/PluginDriver.js +143 -0
- package/dist/node/auto-nav-sidebar/index.js +44 -0
- package/dist/node/auto-nav-sidebar/locales.js +26 -0
- package/dist/node/auto-nav-sidebar/normalize.js +228 -0
- package/dist/node/auto-nav-sidebar/utils.js +68 -0
- package/dist/node/auto-nav-sidebar/walk.js +67 -0
- package/dist/node/build.js +31 -0
- package/dist/node/constants.d.ts +1 -0
- package/dist/node/constants.js +33 -0
- package/dist/node/dev.js +32 -0
- package/dist/node/eject.js +111 -0
- package/dist/node/index.d.ts +5 -5
- package/dist/node/initRsbuild.d.ts +2 -2
- package/dist/node/initRsbuild.js +338 -0
- package/dist/node/last-updated/index.js +28 -0
- package/dist/node/logger/hint.d.ts +1 -1
- package/dist/node/logger/hint.js +85 -0
- package/dist/node/mdx/loader.d.ts +1 -1
- package/dist/node/mdx/loader.e1578c62.js +13 -0
- package/dist/{loader.js → node/mdx/loader.js} +2 -2
- package/dist/node/mdx/options.d.ts +2 -2
- package/dist/node/mdx/options.js +100 -0
- package/dist/node/mdx/processor.d.ts +2 -2
- package/dist/node/mdx/processor.js +71 -0
- package/dist/node/mdx/rehypePlugins/codeMeta.js +10 -0
- package/dist/node/mdx/rehypePlugins/headerAnchor.js +53 -0
- package/dist/node/mdx/rehypePlugins/shiki.js +34 -0
- package/dist/node/mdx/rehypePlugins/transformers/add-lang.js +15 -0
- package/dist/node/mdx/rehypePlugins/transformers/add-line-numbers.js +22 -0
- package/dist/node/mdx/rehypePlugins/transformers/add-title.js +24 -0
- package/dist/node/mdx/rehypePlugins/transformers/add-wrap-code.js +22 -0
- package/dist/node/mdx/rehypePlugins/transformers/index.d.ts +5 -5
- package/dist/node/mdx/rehypePlugins/transformers/index.js +5 -0
- package/dist/node/mdx/rehypePlugins/transformers/meta-highlight.js +41 -0
- package/dist/node/mdx/remarkPlugins/builtin.js +11 -0
- package/dist/node/mdx/remarkPlugins/containerSyntax.js +190 -0
- package/dist/node/mdx/remarkPlugins/fileCodeBlock.js +66 -0
- package/dist/node/mdx/remarkPlugins/image.js +67 -0
- package/dist/node/mdx/remarkPlugins/link.d.ts +1 -1
- package/dist/node/mdx/remarkPlugins/link.js +99 -0
- package/dist/node/mdx/remarkPlugins/toc.js +50 -0
- package/dist/node/mdx/types.d.ts +3 -3
- package/dist/node/medium-zoom/index.d.ts +1 -1
- package/dist/node/medium-zoom/index.js +14 -0
- package/dist/node/route/RoutePage.d.ts +1 -1
- package/dist/node/route/RoutePage.js +61 -0
- package/dist/node/route/RouteService.d.ts +1 -1
- package/dist/node/route/RouteService.js +177 -0
- package/dist/node/route/extractPageData.d.ts +1 -1
- package/dist/node/route/extractPageData.js +112 -0
- package/dist/node/route/normalizeRoutePath.js +54 -0
- package/dist/node/runtimeModule/DEFAULT_I18N_TEXT.d.ts +21 -0
- package/dist/node/runtimeModule/DEFAULT_I18N_TEXT.js +150 -0
- package/dist/node/runtimeModule/globalStyles.d.ts +1 -1
- package/dist/node/runtimeModule/globalStyles.js +12 -0
- package/dist/node/runtimeModule/globalUIComponents.d.ts +1 -1
- package/dist/node/runtimeModule/globalUIComponents.js +25 -0
- package/dist/node/runtimeModule/i18n.d.ts +2 -2
- package/dist/node/runtimeModule/i18n.js +83 -0
- package/dist/node/runtimeModule/pageData/createPageData.d.ts +1 -1
- package/dist/node/runtimeModule/pageData/createPageData.js +64 -0
- package/dist/node/runtimeModule/pageData/rsbuildPlugin.d.ts +1 -1
- package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +51 -0
- package/dist/node/runtimeModule/routeList.d.ts +1 -1
- package/dist/node/runtimeModule/routeList.js +7 -0
- package/dist/node/runtimeModule/searchHooks.d.ts +1 -1
- package/dist/node/runtimeModule/searchHooks.js +11 -0
- package/dist/node/runtimeModule/siteData/createSiteData.js +34 -0
- package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +94 -0
- package/dist/node/runtimeModule/siteData/rsbuildPlugin.d.ts +1 -1
- package/dist/node/runtimeModule/siteData/rsbuildPlugin.js +24 -0
- package/dist/node/runtimeModule/socialLinks.d.ts +1 -1
- package/dist/node/runtimeModule/socialLinks.js +8 -0
- package/dist/node/runtimeModule/types.d.ts +2 -2
- package/dist/node/serve.js +23 -0
- package/dist/node/ssg/renderHtmlTemplate.js +33 -0
- package/dist/node/ssg/renderPage.js +34 -0
- package/dist/node/ssg/renderPageWorker.474f9f73.js +2 -0
- package/dist/node/ssg/renderPageWorker.js +15 -0
- package/dist/node/ssg/renderPages.d.ts +1 -1
- package/dist/node/ssg/renderPages.js +105 -0
- package/dist/node/ssg/renderPages.js.LICENSE.txt +4 -0
- package/dist/node/ssg/rsbuildPluginCSR.d.ts +1 -1
- package/dist/node/ssg/rsbuildPluginCSR.js +27 -0
- package/dist/node/ssg/rsbuildPluginSSG.d.ts +1 -1
- package/dist/node/ssg/rsbuildPluginSSG.js +72 -0
- package/dist/node/ssg/ssgEnv.js +33 -0
- package/dist/node/ssg/ssgEnv.js.LICENSE.txt +5 -0
- package/dist/node/ssg-md/llms/emitLlmsTxt.d.ts +1 -1
- package/dist/node/ssg-md/llms/emitLlmsTxt.js +80 -0
- package/dist/node/ssg-md/llms/llmsTxt.d.ts +1 -1
- package/dist/node/ssg-md/llms/llmsTxt.js +66 -0
- package/dist/node/ssg-md/react/index.d.ts +1 -1
- package/dist/node/ssg-md/remarkSplitMdx.js +202 -0
- package/dist/node/ssg-md/renderPage.js +31 -0
- package/dist/node/ssg-md/renderPages.d.ts +1 -1
- package/dist/node/ssg-md/renderPages.js +27 -0
- package/dist/node/ssg-md/rsbuildPluginSSGMD.d.ts +1 -1
- package/dist/node/ssg-md/rsbuildPluginSSGMD.js +47 -0
- package/dist/node/utils/applyReplaceRules.js +6 -0
- package/dist/node/utils/checkLanguageParity.js +77 -0
- package/dist/node/utils/createHash.js +5 -0
- package/dist/node/utils/error.d.ts +9 -0
- package/dist/node/utils/error.js +9 -0
- package/dist/node/utils/escapeHeadingIds.js +5 -0
- package/dist/node/utils/flattenMdxContent.js +74 -0
- package/dist/node/utils/fs.js +14 -0
- package/dist/node/utils/getImportAstNode.js +63 -0
- package/dist/node/utils/getPageKey.js +6 -0
- package/dist/node/utils/getSocialIcons.js +32 -0
- package/dist/node/utils/index.d.ts +10 -9
- package/dist/node/utils/normalizePath.js +10 -0
- package/dist/node/utils/reactAlias.d.ts +2 -0
- package/dist/node/utils/reactAlias.js +83 -0
- package/dist/rslib-runtime.99091bf6.js +18 -0
- package/dist/runtime/App.js +2 -2
- package/dist/runtime/ClientApp.d.ts +1 -1
- package/dist/runtime/ClientApp.js +0 -4
- package/dist/runtime/ssrMdServerEntry.js +1 -1
- package/dist/runtime/ssrServerEntry.js +2 -1
- package/dist/runtime.72d450ac.js +1 -0
- package/dist/runtime.js +3 -2
- package/dist/shiki-transformers.d.ts +1 -1
- package/dist/shiki-transformers.js +6 -120
- package/dist/theme/components/Banner/index.d.ts +1 -1
- package/dist/theme/components/Banner/index.js +2 -3
- package/dist/theme/components/Callout/index.css +0 -2
- package/dist/theme/components/CodeBlock/index.css +4 -15
- package/dist/theme/components/CodeBlock/index.js +1 -0
- package/dist/theme/components/CodeButtonGroup/CopyCodeButton.js +3 -5
- package/dist/theme/components/CodeButtonGroup/index.css +5 -1
- package/dist/theme/components/CodeButtonGroup/index.js +3 -5
- package/dist/theme/components/DocContent/doc.css +28 -7
- package/dist/theme/components/DocContent/docComponents/index.d.ts +3 -3
- package/dist/theme/components/DocContent/docComponents/table.d.ts +2 -2
- package/dist/theme/components/DocContent/docComponents/table.js +8 -3
- package/dist/theme/components/DocContent/index.js +2 -3
- package/dist/theme/components/{DocContent/FallbackHeading.js → FallbackHeading/index.js} +19 -11
- package/dist/theme/components/HoverGroup/useHoverGroup.d.ts +1 -1
- package/dist/theme/components/Link/index.js +9 -5
- package/dist/theme/components/Nav/NavMenu.js +2 -3
- package/dist/theme/components/NavHamburger/index.js +3 -4
- package/dist/theme/components/NavScreen/NavScreenMenuItem.js +2 -3
- package/dist/theme/components/Overview/OverviewGroup.js +1 -2
- package/dist/theme/components/Overview/index.js +1 -2
- package/dist/theme/components/PackageManagerTabs/index.d.ts +1 -1
- package/dist/theme/components/PackageManagerTabs/index.js +4 -0
- package/dist/theme/components/PrevNextPage/index.js +3 -4
- package/dist/theme/components/Root/index.d.ts +54 -0
- package/dist/theme/components/Root/index.js +7 -0
- package/dist/theme/components/Search/NoSearchResult.js +2 -3
- package/dist/theme/components/Search/SearchButton.js +3 -4
- package/dist/theme/components/Search/SearchPanel.js +12 -15
- package/dist/theme/components/Search/SuggestItem.d.ts +1 -1
- package/dist/theme/components/Search/SuggestItem.js +7 -11
- package/dist/theme/components/Search/logic/Provider.d.ts +1 -1
- package/dist/theme/components/Search/logic/providers/LocalProvider.d.ts +2 -2
- package/dist/theme/components/Search/logic/search.d.ts +1 -1
- package/dist/theme/components/Sidebar/SidebarGroup.js +2 -3
- package/dist/theme/components/Sidebar/SidebarItem.js +1 -0
- package/dist/theme/components/SidebarMenu/index.js +3 -5
- package/dist/theme/components/SocialLinks/index.js +2 -3
- package/dist/theme/components/SourceCode/index.js +2 -4
- package/dist/theme/components/SwitchAppearance/index.js +3 -5
- package/dist/theme/components/Tabs/index.css +13 -22
- package/dist/theme/components/Toc/TocItem.css +2 -3
- package/dist/theme/components/Toc/TocItem.js +1 -0
- package/dist/theme/icons.d.ts +25 -0
- package/dist/theme/icons.js +47 -0
- package/dist/theme/index.d.ts +62 -59
- package/dist/theme/index.js +4 -1
- package/dist/theme/layout/DocLayout/index.css +2 -2
- package/dist/theme/logic/useFullTextSearch.d.ts +1 -1
- package/dist/theme/styles/scrollbar.css +1 -0
- package/dist/theme/styles/vars/base-vars.css +5 -3
- package/dist/theme/styles/vars/home-vars.css +2 -1
- package/package.json +17 -18
- package/dist/3~128.js +0 -74
- package/dist/3~517.js +0 -1786
- package/dist/3~894.js +0 -26
- package/dist/cli.js +0 -259
- package/dist/index.js.LICENSE.txt +0 -10
- package/dist/node/auto-nav-sidebar/fixtures/docs/guide/c.d.ts +0 -2
- package/dist/node/auto-nav-sidebar/fixtures/docs-locales/en/guide/c.d.ts +0 -2
- package/dist/node/auto-nav-sidebar/fixtures/docs-locales/zh/guide/c.d.ts +0 -2
- package/dist/node/auto-nav-sidebar/locales.test.d.ts +0 -1
- package/dist/node/auto-nav-sidebar/walk.test.d.ts +0 -1
- package/dist/node/mdx/rehypePlugins/headerAnchor.test.d.ts +0 -1
- package/dist/node/mdx/remarkPlugins/containerSyntax.test.d.ts +0 -1
- package/dist/node/mdx/remarkPlugins/fileCodeBlock.test.d.ts +0 -1
- package/dist/node/mdx/remarkPlugins/image.test.d.ts +0 -1
- package/dist/node/mdx/remarkPlugins/link.test.d.ts +0 -1
- package/dist/node/route/RouteService.test.d.ts +0 -1
- package/dist/node/route/extractPageData.test.d.ts +0 -1
- package/dist/node/route/fixtures/basic/guide/c.d.ts +0 -2
- package/dist/node/route/normalizeRoutePath.test.d.ts +0 -1
- package/dist/node/runtimeModule/i18n.test.d.ts +0 -1
- package/dist/node/ssg-md/remarkSplitMdx.test.d.ts +0 -4
- package/dist/node/utils/checkLanguageParity.test.d.ts +0 -1
- package/dist/node/utils/detectCustomIcon.d.ts +0 -1
- package/dist/node/utils/detectReactVersion.d.ts +0 -3
- package/dist/processor.js +0 -4539
- package/dist/renderPageWorker.js +0 -196
- package/dist/theme/components/Search/logic/util.test.d.ts +0 -1
- /package/dist/cli/{config.d.ts → config/index.d.ts} +0 -0
- /package/dist/{shiki-transformers.js.LICENSE.txt → node/mdx/rehypePlugins/transformers/meta-highlight.js.LICENSE.txt} +0 -0
- /package/dist/theme/components/{DocContent/FallbackHeading.d.ts → FallbackHeading/index.d.ts} +0 -0
package/dist/node/dev.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { PluginDriver } from "./PluginDriver.js";
|
|
2
|
+
import { RouteService } from "./route/RouteService.js";
|
|
3
|
+
import { initRsbuild } from "./initRsbuild.js";
|
|
4
|
+
import { checkLanguageParity } from "./utils/checkLanguageParity.js";
|
|
5
|
+
async function dev(options) {
|
|
6
|
+
const { docDirectory, config, extraBuilderConfig, configFilePath } = options;
|
|
7
|
+
const isProd = false;
|
|
8
|
+
const pluginDriver = await PluginDriver.create(config, configFilePath, isProd);
|
|
9
|
+
const modifiedConfig = await pluginDriver.modifyConfig();
|
|
10
|
+
try {
|
|
11
|
+
const additionalPages = await pluginDriver.addPages();
|
|
12
|
+
const routeService = await RouteService.create({
|
|
13
|
+
config: modifiedConfig,
|
|
14
|
+
scanDir: docDirectory,
|
|
15
|
+
externalPages: additionalPages
|
|
16
|
+
});
|
|
17
|
+
await pluginDriver.routeGenerated(routeService.getRoutes());
|
|
18
|
+
await pluginDriver.routeServiceGenerated(routeService);
|
|
19
|
+
await pluginDriver.beforeBuild();
|
|
20
|
+
const rsbuild = await initRsbuild(docDirectory, modifiedConfig, pluginDriver, routeService, false, extraBuilderConfig);
|
|
21
|
+
rsbuild.onAfterDevCompile(async ()=>{
|
|
22
|
+
await pluginDriver.afterBuild();
|
|
23
|
+
});
|
|
24
|
+
const { server } = await rsbuild.startDevServer({
|
|
25
|
+
getPortSilently: true
|
|
26
|
+
});
|
|
27
|
+
return server;
|
|
28
|
+
} finally{
|
|
29
|
+
await checkLanguageParity(modifiedConfig);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export { dev };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { node_path, logger, promises, picocolors } from "../6289.c67fe0d5.js";
|
|
2
|
+
import { fileURLToPath } from "../5485.2a0273cf.js";
|
|
3
|
+
const eject_filename = fileURLToPath(import.meta.url);
|
|
4
|
+
const eject_dirname = node_path.dirname(eject_filename);
|
|
5
|
+
let _themeComponentsPathOverride;
|
|
6
|
+
function __setThemeComponentsPathForTesting(themePath) {
|
|
7
|
+
_themeComponentsPathOverride = themePath;
|
|
8
|
+
}
|
|
9
|
+
function getThemeComponentsPath() {
|
|
10
|
+
if (_themeComponentsPathOverride) return _themeComponentsPathOverride;
|
|
11
|
+
return node_path.join(eject_dirname, 'eject-theme/components');
|
|
12
|
+
}
|
|
13
|
+
async function getAvailableComponents() {
|
|
14
|
+
return [
|
|
15
|
+
'Banner',
|
|
16
|
+
'Badge',
|
|
17
|
+
'Callout',
|
|
18
|
+
'DocFooter',
|
|
19
|
+
'FallbackHeading',
|
|
20
|
+
'HomeFeature',
|
|
21
|
+
'HomeHero',
|
|
22
|
+
'HomeBackground',
|
|
23
|
+
'HomeFooter',
|
|
24
|
+
'Toc',
|
|
25
|
+
'Tabs',
|
|
26
|
+
'PackageManagerTabs',
|
|
27
|
+
'PrevNextPage',
|
|
28
|
+
'Overview',
|
|
29
|
+
'Root',
|
|
30
|
+
'SocialLinks',
|
|
31
|
+
'Steps'
|
|
32
|
+
];
|
|
33
|
+
}
|
|
34
|
+
async function componentExists(componentName) {
|
|
35
|
+
const themePath = getThemeComponentsPath();
|
|
36
|
+
const componentPath = node_path.join(themePath, componentName);
|
|
37
|
+
try {
|
|
38
|
+
const stat = await promises.stat(componentPath);
|
|
39
|
+
return stat.isDirectory();
|
|
40
|
+
} catch {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async function copyDir(src, dest) {
|
|
45
|
+
await promises.mkdir(dest, {
|
|
46
|
+
recursive: true
|
|
47
|
+
});
|
|
48
|
+
const entries = await promises.readdir(src, {
|
|
49
|
+
withFileTypes: true
|
|
50
|
+
});
|
|
51
|
+
for (const entry of entries){
|
|
52
|
+
const srcPath = node_path.join(src, entry.name);
|
|
53
|
+
const destPath = node_path.join(dest, entry.name);
|
|
54
|
+
if (entry.isDirectory()) await copyDir(srcPath, destPath);
|
|
55
|
+
else await promises.copyFile(srcPath, destPath);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async function transformImports(filePath) {
|
|
59
|
+
const content = await promises.readFile(filePath, 'utf-8');
|
|
60
|
+
const transformed = content;
|
|
61
|
+
if (transformed !== content) await promises.writeFile(filePath, transformed, 'utf-8');
|
|
62
|
+
}
|
|
63
|
+
async function transformDirectory(dir) {
|
|
64
|
+
const entries = await promises.readdir(dir, {
|
|
65
|
+
withFileTypes: true
|
|
66
|
+
});
|
|
67
|
+
for (const entry of entries){
|
|
68
|
+
const fullPath = node_path.join(dir, entry.name);
|
|
69
|
+
if (entry.isDirectory()) await transformDirectory(fullPath);
|
|
70
|
+
else if (entry.name.endsWith('.ts') || entry.name.endsWith('.tsx')) await transformImports(fullPath);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async function ejectComponent(componentName, cwd = process.cwd()) {
|
|
74
|
+
const exists = await componentExists(componentName);
|
|
75
|
+
if (!exists) {
|
|
76
|
+
logger.error(`Component ${picocolors.cyan(componentName)} not found in theme.`);
|
|
77
|
+
const available = await getAvailableComponents();
|
|
78
|
+
logger.info(`\nAvailable components:\n${available.map((c)=>` - ${c}`).join('\n')}`);
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
const themePath = getThemeComponentsPath();
|
|
82
|
+
const sourceComponentPath = node_path.join(themePath, componentName);
|
|
83
|
+
const destThemePath = node_path.join(cwd, 'theme', 'components');
|
|
84
|
+
const destComponentPath = node_path.join(destThemePath, componentName);
|
|
85
|
+
try {
|
|
86
|
+
await promises.access(destComponentPath);
|
|
87
|
+
logger.warn(`Component ${picocolors.cyan(componentName)} already exists in ${picocolors.yellow(node_path.relative(cwd, destComponentPath))}`);
|
|
88
|
+
logger.info('Overwriting existing component...');
|
|
89
|
+
} catch {}
|
|
90
|
+
try {
|
|
91
|
+
await promises.mkdir(destThemePath, {
|
|
92
|
+
recursive: true
|
|
93
|
+
});
|
|
94
|
+
await copyDir(sourceComponentPath, destComponentPath);
|
|
95
|
+
await transformDirectory(destComponentPath);
|
|
96
|
+
logger.success(`✨ Component ${picocolors.cyan(componentName)} ejected successfully!`);
|
|
97
|
+
logger.info(`Component files copied to: ${picocolors.green(node_path.relative(cwd, destComponentPath))}\nYou can now customize the component. To use it in your theme, you'll need to:\n 1. Re-export it in your custom \`theme/index.tsx\` file\n 2. Edit it by yourself`);
|
|
98
|
+
} catch (error) {
|
|
99
|
+
logger.error(`Failed to eject component: ${error}`);
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
async function listComponents() {
|
|
104
|
+
const components = await getAvailableComponents();
|
|
105
|
+
logger.info(`📦 Available components to eject:\n`);
|
|
106
|
+
components.forEach((component)=>{
|
|
107
|
+
logger.info(` ${picocolors.cyan('•')} ${component}`);
|
|
108
|
+
});
|
|
109
|
+
logger.info(`💡 Usage: ${picocolors.dim('rspress eject <ComponentName>')}\n`);
|
|
110
|
+
}
|
|
111
|
+
export { __setThemeComponentsPathForTesting, ejectComponent, getAvailableComponents, listComponents };
|
package/dist/node/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { build } from './build';
|
|
2
|
-
export { dev } from './dev';
|
|
3
|
-
export { remarkFileCodeBlock } from './mdx/remarkPlugins/fileCodeBlock';
|
|
4
|
-
export { remarkLink } from './mdx/remarkPlugins/link';
|
|
5
|
-
export { serve } from './serve';
|
|
1
|
+
export { build } from './build.js';
|
|
2
|
+
export { dev } from './dev.js';
|
|
3
|
+
export { remarkFileCodeBlock } from './mdx/remarkPlugins/fileCodeBlock.js';
|
|
4
|
+
export { remarkLink } from './mdx/remarkPlugins/link.js';
|
|
5
|
+
export { serve } from './serve.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { RsbuildConfig, RsbuildInstance } from '@rsbuild/core';
|
|
2
2
|
import { type UserConfig } from '@rspress/shared';
|
|
3
|
-
import type { PluginDriver } from './PluginDriver';
|
|
4
|
-
import type { RouteService } from './route/RouteService';
|
|
3
|
+
import type { PluginDriver } from './PluginDriver.js';
|
|
4
|
+
import type { RouteService } from './route/RouteService.js';
|
|
5
5
|
export declare function initRsbuild(rootDir: string, config: UserConfig, pluginDriver: PluginDriver, routeService: RouteService, enableSSG: boolean, extraRsbuildConfig?: RsbuildConfig): Promise<RsbuildInstance>;
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
import { createRequire, fileURLToPath, package_namespaceObject } from "../5485.2a0273cf.js";
|
|
2
|
+
import { node_path } from "../6289.c67fe0d5.js";
|
|
3
|
+
import { PLUGIN_REACT_NAME, pluginReact, pluginVirtualModule } from "../5313.6594aba0.js";
|
|
4
|
+
import { removeTrailingSlash, MDX_OR_MD_REGEXP } from "../4669.12208c6a.js";
|
|
5
|
+
import { createError } from "./utils/error.js";
|
|
6
|
+
import { PUBLIC_DIR, CSR_CLIENT_ENTRY, SSR_CLIENT_ENTRY, OUTPUT_DIR, SSG_MD_SERVER_ENTRY, inlineThemeScript, NODE_SSG_BUNDLE_FOLDER, isProduction, PACKAGE_ROOT, SSR_SERVER_ENTRY, TEMPLATE_PATH, NODE_SSG_MD_BUNDLE_FOLDER, DEFAULT_THEME, NODE_SSG_MD_BUNDLE_NAME, DEFAULT_TITLE, NODE_SSG_BUNDLE_NAME } from "./constants.js";
|
|
7
|
+
import { hintBuilderPluginsBreakingChange, hintThemeBreakingChange } from "./logger/hint.js";
|
|
8
|
+
import { resolveReactRouterDomAlias, resolveReactAlias } from "./utils/reactAlias.js";
|
|
9
|
+
import { rsbuildPluginDocVM } from "./runtimeModule/pageData/rsbuildPlugin.js";
|
|
10
|
+
import { socialLinksVMPlugin } from "./runtimeModule/socialLinks.js";
|
|
11
|
+
import { i18nVMPlugin } from "./runtimeModule/i18n.js";
|
|
12
|
+
import { globalUIComponentsVMPlugin } from "./runtimeModule/globalUIComponents.js";
|
|
13
|
+
import { globalStylesVMPlugin } from "./runtimeModule/globalStyles.js";
|
|
14
|
+
import { searchHookVMPlugin } from "./runtimeModule/searchHooks.js";
|
|
15
|
+
import { routeListVMPlugin } from "./runtimeModule/routeList.js";
|
|
16
|
+
import { siteDataVMPlugin } from "./runtimeModule/siteData/rsbuildPlugin.js";
|
|
17
|
+
import { rsbuildPluginSSG } from "./ssg/rsbuildPluginSSG.js";
|
|
18
|
+
import { rsbuildPluginCSR } from "./ssg/rsbuildPluginCSR.js";
|
|
19
|
+
import { rsbuildPluginSSGMD } from "./ssg-md/rsbuildPluginSSGMD.js";
|
|
20
|
+
function isPluginIncluded(config, pluginName) {
|
|
21
|
+
return Boolean(config.builderConfig?.plugins?.some((plugin)=>plugin && plugin.name === pluginName));
|
|
22
|
+
}
|
|
23
|
+
const initRsbuild_require = createRequire(import.meta.url);
|
|
24
|
+
async function getVirtualModulesFromPlugins(pluginDriver) {
|
|
25
|
+
const runtimeModule = {};
|
|
26
|
+
const modulesByPlugin = await pluginDriver.addRuntimeModules();
|
|
27
|
+
Object.keys(modulesByPlugin).forEach((key)=>{
|
|
28
|
+
if (runtimeModule[key]) throw createError(`The runtime module ${key} is duplicated, please check your plugin`);
|
|
29
|
+
runtimeModule[key] = ()=>modulesByPlugin[key];
|
|
30
|
+
});
|
|
31
|
+
return runtimeModule;
|
|
32
|
+
}
|
|
33
|
+
async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeService, pluginDriver) {
|
|
34
|
+
const CUSTOM_THEME_DIR = config.themeDir;
|
|
35
|
+
const outDir = config?.outDir ?? OUTPUT_DIR;
|
|
36
|
+
const base = config?.base ?? '';
|
|
37
|
+
const assetPrefix = isProduction() ? removeTrailingSlash(config?.builderConfig?.output?.assetPrefix ?? base) : '';
|
|
38
|
+
const normalizeIcon = (icon)=>{
|
|
39
|
+
if (!icon) return;
|
|
40
|
+
icon = icon.toString();
|
|
41
|
+
if (icon.startsWith('file://')) icon = fileURLToPath(icon);
|
|
42
|
+
else if (node_path.isAbsolute(icon)) return node_path.join(userDocRoot, PUBLIC_DIR, icon);
|
|
43
|
+
return icon;
|
|
44
|
+
};
|
|
45
|
+
await hintThemeBreakingChange(CUSTOM_THEME_DIR);
|
|
46
|
+
const [reactCSRAlias, reactSSRAlias, reactRouterDomAlias] = await Promise.all([
|
|
47
|
+
resolveReactAlias(false),
|
|
48
|
+
enableSSG ? resolveReactAlias(true) : Promise.resolve({}),
|
|
49
|
+
resolveReactRouterDomAlias()
|
|
50
|
+
]);
|
|
51
|
+
const context = {
|
|
52
|
+
userDocRoot,
|
|
53
|
+
config,
|
|
54
|
+
routeService,
|
|
55
|
+
pluginDriver
|
|
56
|
+
};
|
|
57
|
+
return {
|
|
58
|
+
plugins: [
|
|
59
|
+
...isPluginIncluded(config, PLUGIN_REACT_NAME) ? [] : [
|
|
60
|
+
pluginReact()
|
|
61
|
+
],
|
|
62
|
+
rsbuildPluginDocVM({
|
|
63
|
+
config,
|
|
64
|
+
pluginDriver,
|
|
65
|
+
routeService,
|
|
66
|
+
userDocRoot
|
|
67
|
+
}),
|
|
68
|
+
pluginVirtualModule({
|
|
69
|
+
tempDir: '.rspress/runtime',
|
|
70
|
+
virtualModules: {
|
|
71
|
+
...socialLinksVMPlugin(context),
|
|
72
|
+
...i18nVMPlugin(context),
|
|
73
|
+
...globalUIComponentsVMPlugin(context),
|
|
74
|
+
...globalStylesVMPlugin(context),
|
|
75
|
+
...searchHookVMPlugin(context),
|
|
76
|
+
...routeListVMPlugin(context),
|
|
77
|
+
...await getVirtualModulesFromPlugins(pluginDriver),
|
|
78
|
+
...siteDataVMPlugin(context)
|
|
79
|
+
}
|
|
80
|
+
}),
|
|
81
|
+
enableSSG && config.ssg ? rsbuildPluginSSG({
|
|
82
|
+
routeService,
|
|
83
|
+
config
|
|
84
|
+
}) : rsbuildPluginCSR({
|
|
85
|
+
routeService,
|
|
86
|
+
config
|
|
87
|
+
}),
|
|
88
|
+
enableSSG && config.llms ? rsbuildPluginSSGMD({
|
|
89
|
+
routeService,
|
|
90
|
+
config
|
|
91
|
+
}) : null
|
|
92
|
+
],
|
|
93
|
+
server: {
|
|
94
|
+
port: !isProduction() && process.env.PORT ? Number(process.env.PORT) : void 0,
|
|
95
|
+
publicDir: {
|
|
96
|
+
name: node_path.join(userDocRoot, PUBLIC_DIR)
|
|
97
|
+
},
|
|
98
|
+
...base.length > 0 ? {
|
|
99
|
+
base: removeTrailingSlash(base)
|
|
100
|
+
} : {}
|
|
101
|
+
},
|
|
102
|
+
dev: {
|
|
103
|
+
lazyCompilation: 'false' !== process.env.RSPRESS_LAZY_COMPILATION,
|
|
104
|
+
cliShortcuts: {
|
|
105
|
+
custom: (shortcuts)=>shortcuts.filter(({ key })=>'r' !== key)
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
html: {
|
|
109
|
+
title: config?.title ?? DEFAULT_TITLE,
|
|
110
|
+
favicon: normalizeIcon(config?.icon),
|
|
111
|
+
template: TEMPLATE_PATH,
|
|
112
|
+
tags: [
|
|
113
|
+
config.themeConfig?.darkMode !== false ? {
|
|
114
|
+
tag: "script",
|
|
115
|
+
children: inlineThemeScript,
|
|
116
|
+
append: false
|
|
117
|
+
} : null
|
|
118
|
+
].filter(Boolean)
|
|
119
|
+
},
|
|
120
|
+
output: {
|
|
121
|
+
assetPrefix,
|
|
122
|
+
distPath: {
|
|
123
|
+
root: outDir
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
resolve: {
|
|
127
|
+
alias: {
|
|
128
|
+
'@mdx-js/react': initRsbuild_require.resolve('@mdx-js/react'),
|
|
129
|
+
'react-lazy-with-preload': initRsbuild_require.resolve('react-lazy-with-preload'),
|
|
130
|
+
'@theme': [
|
|
131
|
+
CUSTOM_THEME_DIR,
|
|
132
|
+
DEFAULT_THEME
|
|
133
|
+
],
|
|
134
|
+
'@rspress/core/theme': [
|
|
135
|
+
CUSTOM_THEME_DIR,
|
|
136
|
+
DEFAULT_THEME
|
|
137
|
+
],
|
|
138
|
+
'@theme-original': DEFAULT_THEME,
|
|
139
|
+
'@rspress/core/theme-original': DEFAULT_THEME,
|
|
140
|
+
'@rspress/core/runtime': node_path.join(PACKAGE_ROOT, 'dist/runtime.js'),
|
|
141
|
+
'@rspress/core/shiki-transformers': node_path.join(PACKAGE_ROOT, 'dist/shiki-transformers.js')
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
source: {
|
|
145
|
+
preEntry: [
|
|
146
|
+
node_path.join(DEFAULT_THEME, './styles/index.js'),
|
|
147
|
+
'virtual-global-styles',
|
|
148
|
+
'@theme'
|
|
149
|
+
],
|
|
150
|
+
include: [
|
|
151
|
+
PACKAGE_ROOT
|
|
152
|
+
],
|
|
153
|
+
define: {
|
|
154
|
+
'process.env.TEST': JSON.stringify(process.env.TEST)
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
performance: {
|
|
158
|
+
...'false' !== process.env.RSPRESS_PERSISTENT_CACHE ? {
|
|
159
|
+
buildCache: {
|
|
160
|
+
buildDependencies: [
|
|
161
|
+
new URL(import.meta.url).href,
|
|
162
|
+
pluginDriver.getConfigFilePath()
|
|
163
|
+
],
|
|
164
|
+
cacheDigest: [
|
|
165
|
+
routeService.generateRoutesCode(),
|
|
166
|
+
JSON.stringify(config.themeConfig?.locales?.map((i)=>({
|
|
167
|
+
nav: i.nav,
|
|
168
|
+
sidebar: i.sidebar
|
|
169
|
+
})) ?? {
|
|
170
|
+
nav: config.themeConfig?.nav,
|
|
171
|
+
sidebar: config.themeConfig?.sidebar
|
|
172
|
+
}),
|
|
173
|
+
package_namespaceObject.rE
|
|
174
|
+
]
|
|
175
|
+
}
|
|
176
|
+
} : {},
|
|
177
|
+
chunkSplit: {
|
|
178
|
+
override: {
|
|
179
|
+
cacheGroups: {
|
|
180
|
+
styles: {
|
|
181
|
+
name: 'styles',
|
|
182
|
+
minSize: 0,
|
|
183
|
+
chunks: 'all',
|
|
184
|
+
test: /\.(?:css|less|sass|scss)$/,
|
|
185
|
+
priority: 99
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
tools: {
|
|
192
|
+
bundlerChain (chain, { CHAIN_ID, environment }) {
|
|
193
|
+
const isSsg = 'node' === environment.name;
|
|
194
|
+
const isSsgMd = 'node_md' === environment.name;
|
|
195
|
+
const jsModuleRule = chain.module.rule(CHAIN_ID.RULE.JS);
|
|
196
|
+
const swcLoaderOptions = jsModuleRule.use(CHAIN_ID.USE.SWC).get('options');
|
|
197
|
+
chain.module.rule('MDX').type("javascript/auto").test(MDX_OR_MD_REGEXP).resolve.merge({
|
|
198
|
+
conditionNames: jsModuleRule.resolve.conditionNames.values(),
|
|
199
|
+
mainFields: jsModuleRule.resolve.mainFields.values()
|
|
200
|
+
}).end().oneOf('MDXCompile').use('builtin:swc-loader').loader('builtin:swc-loader').options(swcLoaderOptions).end().use('mdx-loader').loader(fileURLToPath(new URL('./mdx/loader.js', import.meta.url))).options({
|
|
201
|
+
config,
|
|
202
|
+
docDirectory: userDocRoot,
|
|
203
|
+
routeService,
|
|
204
|
+
pluginDriver,
|
|
205
|
+
isSsgMd
|
|
206
|
+
}).end();
|
|
207
|
+
if (chain.plugins.has(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH)) chain.plugin(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH).tap((options)=>{
|
|
208
|
+
options[0] ??= {};
|
|
209
|
+
options[0].test = [
|
|
210
|
+
/\.([cm]js|[jt]sx?|flow)$/i,
|
|
211
|
+
MDX_OR_MD_REGEXP
|
|
212
|
+
];
|
|
213
|
+
options[0].include = [
|
|
214
|
+
/\.([cm]js|[jt]sx?|flow)$/i,
|
|
215
|
+
MDX_OR_MD_REGEXP
|
|
216
|
+
];
|
|
217
|
+
return options;
|
|
218
|
+
});
|
|
219
|
+
chain.resolve.extensions.prepend('.md').prepend('.mdx').prepend('.mjs');
|
|
220
|
+
chain.module.rule('css-virtual-module').test(/\.rspress[\\/]runtime[\\/]virtual-global-styles/).merge({
|
|
221
|
+
sideEffects: true
|
|
222
|
+
});
|
|
223
|
+
if (isSsg || isSsgMd) chain.optimization.splitChunks({});
|
|
224
|
+
if (isSsg) {
|
|
225
|
+
chain.output.filename(`${NODE_SSG_BUNDLE_FOLDER}/${NODE_SSG_BUNDLE_NAME}`);
|
|
226
|
+
chain.output.chunkFilename(`${NODE_SSG_BUNDLE_FOLDER}/[name].cjs`);
|
|
227
|
+
} else if (isSsgMd) {
|
|
228
|
+
chain.output.filename(`${NODE_SSG_MD_BUNDLE_FOLDER}/${NODE_SSG_MD_BUNDLE_NAME}`);
|
|
229
|
+
chain.output.chunkFilename(`${NODE_SSG_MD_BUNDLE_FOLDER}/[name].cjs`);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
},
|
|
233
|
+
environments: {
|
|
234
|
+
web: {
|
|
235
|
+
resolve: {
|
|
236
|
+
alias: {
|
|
237
|
+
...reactCSRAlias,
|
|
238
|
+
...reactRouterDomAlias
|
|
239
|
+
}
|
|
240
|
+
},
|
|
241
|
+
source: {
|
|
242
|
+
entry: {
|
|
243
|
+
index: enableSSG && isProduction() ? SSR_CLIENT_ENTRY : CSR_CLIENT_ENTRY
|
|
244
|
+
},
|
|
245
|
+
define: {
|
|
246
|
+
'process.env.__SSR__': JSON.stringify(false),
|
|
247
|
+
'process.env.__SSR_MD__': JSON.stringify(false)
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
output: {
|
|
251
|
+
target: 'web',
|
|
252
|
+
distPath: {
|
|
253
|
+
root: outDir
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
},
|
|
257
|
+
...enableSSG && config.ssg ? {
|
|
258
|
+
node: {
|
|
259
|
+
resolve: {
|
|
260
|
+
alias: {
|
|
261
|
+
...reactSSRAlias,
|
|
262
|
+
...reactRouterDomAlias
|
|
263
|
+
}
|
|
264
|
+
},
|
|
265
|
+
source: {
|
|
266
|
+
entry: {
|
|
267
|
+
index: SSR_SERVER_ENTRY
|
|
268
|
+
},
|
|
269
|
+
define: {
|
|
270
|
+
'process.env.__SSR__': JSON.stringify(true),
|
|
271
|
+
'process.env.__SSR_MD__': JSON.stringify(false)
|
|
272
|
+
}
|
|
273
|
+
},
|
|
274
|
+
performance: {
|
|
275
|
+
printFileSize: {
|
|
276
|
+
compressed: true
|
|
277
|
+
}
|
|
278
|
+
},
|
|
279
|
+
output: {
|
|
280
|
+
emitAssets: false,
|
|
281
|
+
target: 'node',
|
|
282
|
+
minify: false
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
} : {},
|
|
286
|
+
...enableSSG && config.llms ? {
|
|
287
|
+
node_md: {
|
|
288
|
+
resolve: {
|
|
289
|
+
alias: {
|
|
290
|
+
...reactSSRAlias,
|
|
291
|
+
...reactRouterDomAlias
|
|
292
|
+
}
|
|
293
|
+
},
|
|
294
|
+
tools: {
|
|
295
|
+
rspack: {
|
|
296
|
+
optimization: {
|
|
297
|
+
moduleIds: 'named',
|
|
298
|
+
chunkIds: 'named'
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
},
|
|
302
|
+
source: {
|
|
303
|
+
entry: {
|
|
304
|
+
index: SSG_MD_SERVER_ENTRY
|
|
305
|
+
},
|
|
306
|
+
define: {
|
|
307
|
+
'process.env.__SSR__': JSON.stringify(true),
|
|
308
|
+
'process.env.__SSR_MD__': JSON.stringify(true)
|
|
309
|
+
}
|
|
310
|
+
},
|
|
311
|
+
performance: {
|
|
312
|
+
printFileSize: {
|
|
313
|
+
compressed: true
|
|
314
|
+
}
|
|
315
|
+
},
|
|
316
|
+
output: {
|
|
317
|
+
emitAssets: false,
|
|
318
|
+
target: 'node',
|
|
319
|
+
minify: false
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
} : {}
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
async function initRsbuild(rootDir, config, pluginDriver, routeService, enableSSG, extraRsbuildConfig) {
|
|
327
|
+
const cwd = process.cwd();
|
|
328
|
+
const userDocRoot = node_path.resolve(rootDir || config?.root || cwd);
|
|
329
|
+
hintBuilderPluginsBreakingChange(config);
|
|
330
|
+
const { createRsbuild, mergeRsbuildConfig } = await import("@rsbuild/core");
|
|
331
|
+
const internalRsbuildConfig = await createInternalBuildConfig(userDocRoot, config, enableSSG, routeService, pluginDriver);
|
|
332
|
+
const rsbuild = await createRsbuild({
|
|
333
|
+
callerName: 'rspress',
|
|
334
|
+
rsbuildConfig: mergeRsbuildConfig(internalRsbuildConfig, ...pluginDriver.getPlugins()?.map((plugin)=>plugin.builderConfig ?? {}) || [], config.builderConfig || {}, extraRsbuildConfig || {})
|
|
335
|
+
});
|
|
336
|
+
return rsbuild;
|
|
337
|
+
}
|
|
338
|
+
export { initRsbuild };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { execa } from "../../0~7675.989ee664.js";
|
|
2
|
+
function transform(timestamp, lang) {
|
|
3
|
+
return new Date(timestamp).toLocaleString(lang || 'zh');
|
|
4
|
+
}
|
|
5
|
+
async function getGitLastUpdatedTimeStamp(filePath) {
|
|
6
|
+
let lastUpdated;
|
|
7
|
+
try {
|
|
8
|
+
const { stdout } = await execa('git', [
|
|
9
|
+
'log',
|
|
10
|
+
'-1',
|
|
11
|
+
'--format=%at',
|
|
12
|
+
filePath
|
|
13
|
+
]);
|
|
14
|
+
lastUpdated = 1000 * Number(stdout);
|
|
15
|
+
} catch (_e) {}
|
|
16
|
+
return lastUpdated;
|
|
17
|
+
}
|
|
18
|
+
function pluginLastUpdated() {
|
|
19
|
+
return {
|
|
20
|
+
name: '@rspress/plugin-last-updated',
|
|
21
|
+
async extendPageData (pageData) {
|
|
22
|
+
const { _filepath, lang } = pageData;
|
|
23
|
+
const lastUpdated = await getGitLastUpdatedTimeStamp(_filepath);
|
|
24
|
+
if (lastUpdated) pageData.lastUpdatedTime = transform(lastUpdated, lang);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export { pluginLastUpdated };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { UserConfig } from '@rspress/shared';
|
|
2
|
-
import type { NavJson } from '../auto-nav-sidebar/type';
|
|
2
|
+
import type { NavJson } from '../auto-nav-sidebar/type.js';
|
|
3
3
|
/**
|
|
4
4
|
* breaking change hint of theme
|
|
5
5
|
* @see https://github.com/web-infra-dev/rspress/discussions/1891#discussioncomment-12422737
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { picocolors, relative, logger, join, readFile } from "../../6289.c67fe0d5.js";
|
|
2
|
+
import { pathExists } from "../utils/fs.js";
|
|
3
|
+
const THEME_DEFAULT_EXPORT_PATTERN = /export\s+default\s+\{/;
|
|
4
|
+
const THEME_OLD_IMPORT_0 = /from\s+['"]rspress\/theme['"]/;
|
|
5
|
+
const THEME_OLD_IMPORT_1 = /from\s+['"]@rspress\/core\/theme['"]/;
|
|
6
|
+
async function hintThemeBreakingChange(customThemeDir) {
|
|
7
|
+
const fileList = [
|
|
8
|
+
'index.ts',
|
|
9
|
+
'index.tsx',
|
|
10
|
+
'index.js',
|
|
11
|
+
'index.mjs'
|
|
12
|
+
];
|
|
13
|
+
let useDefaultExportFilePath = null;
|
|
14
|
+
for (const file of fileList){
|
|
15
|
+
const filePath = join(customThemeDir, file);
|
|
16
|
+
if (await pathExists(filePath)) {
|
|
17
|
+
const content = await readFile(filePath, {
|
|
18
|
+
encoding: 'utf-8'
|
|
19
|
+
});
|
|
20
|
+
if (THEME_DEFAULT_EXPORT_PATTERN.test(content)) {
|
|
21
|
+
useDefaultExportFilePath = filePath;
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
if (THEME_OLD_IMPORT_0.test(content) || THEME_OLD_IMPORT_1.test(content)) {
|
|
25
|
+
useDefaultExportFilePath = filePath;
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (useDefaultExportFilePath) logger.warn(`[Rspress v2] Breaking Change: The "theme/index.tsx" is now using named export from '@rspress/core/theme-original' instead of default export from 'rspress/theme', please update ${picocolors.greenBright(useDefaultExportFilePath)} (https://github.com/web-infra-dev/rspress/discussions/1891#discussioncomment-12422737).\n`, picocolors.redBright(`
|
|
31
|
+
- import Theme from 'rspress/theme';
|
|
32
|
+
- export default {
|
|
33
|
+
- ...Theme,
|
|
34
|
+
- Layout,
|
|
35
|
+
- };
|
|
36
|
+
- export * from 'rspress/theme';`) + picocolors.greenBright(`
|
|
37
|
+
+ import { Layout } from '@rspress/core/theme-original';
|
|
38
|
+
|
|
39
|
+
+ export { Layout };
|
|
40
|
+
+ export * from '@rspress/core/theme-original';
|
|
41
|
+
`));
|
|
42
|
+
}
|
|
43
|
+
function hintBuilderPluginsBreakingChange(config) {
|
|
44
|
+
if ('builderPlugins' in config && Array.isArray(config.builderPlugins) && config.builderPlugins.length > 0) {
|
|
45
|
+
logger.error(`[Rspress v2] The "builderPlugins" option has been renamed to "builderConfig.plugins", please update your config accordingly (https://rspress.rs/api/config/config-build#builderconfigplugins).\n`, `
|
|
46
|
+
export default defineConfig({
|
|
47
|
+
${picocolors.redBright(` builderPlugins: [
|
|
48
|
+
pluginFoo()
|
|
49
|
+
],`)}
|
|
50
|
+
${picocolors.greenBright(` builderConfig: {
|
|
51
|
+
plugins: [
|
|
52
|
+
pluginFoo()
|
|
53
|
+
],
|
|
54
|
+
},`)}
|
|
55
|
+
});`);
|
|
56
|
+
process.exit(1);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function hintSSGFailed() {
|
|
60
|
+
logger.info(`[Rspress v2] \`ssg: true\` requires the source code to support SSR. If the code is not compatible to SSR, the build process will fail. You can try:
|
|
61
|
+
1. Fix code to make it SSR-compatible.
|
|
62
|
+
2. Set \`ssg: false\` if the code in node_modules may be difficult to fix, but the SSG feature will be lost.`);
|
|
63
|
+
}
|
|
64
|
+
function hintSSGFalse() {
|
|
65
|
+
logger.info('`ssg: false` detected, SSG will be disabled.');
|
|
66
|
+
}
|
|
67
|
+
function hintReactVersion() {
|
|
68
|
+
logger.info('[Rspress v2] Rspress support React 18 and 19, please confirm that both react and react-dom are installed in package.json with the same version. ');
|
|
69
|
+
}
|
|
70
|
+
function hintNavJsonChangeThenPanic(metaJson, metaJsonDir, docsDir) {
|
|
71
|
+
if (metaJson.some((i)=>'object' == typeof i && ('activeMatch' in i || 'text' in i || 'link' in i || 'items' in i || 'icon' in i || 'ariaLabel' in i || 'target' in i))) {
|
|
72
|
+
const error = new Error('[Rspress v2] Detected that you are still using top level `_meta.json` to configure the nav, but it has been changed to `_nav.json` in Rspress v2. Please rename the top level `_meta.json` to `_nav.json` accordingly.');
|
|
73
|
+
logger.error(error);
|
|
74
|
+
const dir = relative(docsDir, metaJsonDir);
|
|
75
|
+
logger.info(`Please rename "${picocolors.greenBright(join(dir, '_meta.json'))}" to "${picocolors.greenBright(join(dir, '_nav.json'))}".`);
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
let isLogged = false;
|
|
80
|
+
function hintRelativeMarkdownLink() {
|
|
81
|
+
if (isLogged) return;
|
|
82
|
+
isLogged = true;
|
|
83
|
+
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)');
|
|
84
|
+
}
|
|
85
|
+
export { hintBuilderPluginsBreakingChange, hintNavJsonChangeThenPanic, hintReactVersion, hintRelativeMarkdownLink, hintSSGFailed, hintSSGFalse, hintThemeBreakingChange };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import rehype from "@shikijs/rehype";
|
|
2
|
+
import rehype_external_links from "rehype-external-links";
|
|
3
|
+
import rehype_raw from "rehype-raw";
|
|
4
|
+
import remark_gfm from "remark-gfm";
|
|
5
|
+
import remark_mdx from "remark-mdx";
|
|
6
|
+
import remark_stringify from "remark-stringify";
|
|
7
|
+
import { unified } from "unified";
|
|
8
|
+
import github_slugger from "github-slugger";
|
|
9
|
+
import { headingRank } from "hast-util-heading-rank";
|
|
10
|
+
import { transformerAddLang, transformerAddLineNumbers, transformerAddTitle, transformerAddWrapCode } from "@rspress/core/shiki-transformers";
|
|
11
|
+
import { createCssVariablesTheme } from "shiki";
|
|
12
|
+
import { visitChildren } from "unist-util-visit-children";
|
|
13
|
+
export { createCssVariablesTheme, github_slugger, headingRank, rehype, rehype_external_links, rehype_raw, remark_gfm, remark_mdx, remark_stringify, transformerAddLang, transformerAddLineNumbers, transformerAddTitle, transformerAddWrapCode, unified, visitChildren };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { compileWithCrossCompilerCache, compile } from "./processor.js";
|
|
2
2
|
async function mdxLoader(source) {
|
|
3
3
|
this.cacheable(true);
|
|
4
4
|
const callback = this.async();
|
|
@@ -49,4 +49,4 @@ async function mdxLoader(source) {
|
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
-
export
|
|
52
|
+
export default mdxLoader;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type ProcessorOptions } from '@mdx-js/mdx';
|
|
2
2
|
import type { Rspack } from '@rsbuild/core';
|
|
3
3
|
import type { UserConfig } from '@rspress/shared';
|
|
4
|
-
import type { PluginDriver } from '../PluginDriver';
|
|
5
|
-
import type { RouteService } from '../route/RouteService';
|
|
4
|
+
import type { PluginDriver } from '../PluginDriver.js';
|
|
5
|
+
import type { RouteService } from '../route/RouteService.js';
|
|
6
6
|
export declare function createMDXOptions(options: {
|
|
7
7
|
docDirectory: string;
|
|
8
8
|
filepath: string;
|