@rspress/core 2.0.0-beta.21 → 2.0.0-beta.22
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 +15 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +144 -0
- package/dist/index.d.ts +3 -6
- package/dist/index.js +212 -79
- package/dist/index.js.LICENSE.txt +10 -0
- package/dist/loader.d.ts +1 -6
- package/dist/processor.d.ts +1 -6
- package/dist/processor.js +17 -8
- package/dist/renderPageWorker.js +193 -0
- package/dist/runtime/ssrClientEntry.js +2 -1
- package/dist/shiki-transformers.js +1 -1
- package/meta-json-schema.json +382 -0
- package/nav-json-schema.json +118 -0
- package/package.json +19 -8
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/*! For license information please see index.js.LICENSE.txt */
|
|
1
2
|
import __rslib_shim_module__ from 'module';
|
|
2
3
|
const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(import.meta.url);
|
|
3
4
|
import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__ from "@rspress/shared";
|
|
@@ -22,7 +23,7 @@ import picocolors from "picocolors";
|
|
|
22
23
|
import { glob } from "tinyglobby";
|
|
23
24
|
import { extractTextAndId, getIconUrlPath, getNodeAttribute, loadFrontMatter, mergeDocConfig } from "@rspress/shared/node-utils";
|
|
24
25
|
import { RspackVirtualModulePlugin } from "rspack-plugin-virtual-module";
|
|
25
|
-
import { groupBy } from "lodash-es";
|
|
26
|
+
import { chunk, groupBy } from "lodash-es";
|
|
26
27
|
import { compile } from "@rspress/mdx-rs";
|
|
27
28
|
import { htmlToText } from "html-to-text";
|
|
28
29
|
import { createProcessor } from "@mdx-js/mdx";
|
|
@@ -240,10 +241,6 @@ class PluginDriver {
|
|
|
240
241
|
...current
|
|
241
242
|
}), {});
|
|
242
243
|
}
|
|
243
|
-
async addSSGRoutes() {
|
|
244
|
-
const result = await this._runParallelAsyncHook('addSSGRoutes', this.#config || {}, this.#isProd);
|
|
245
|
-
return result.flat();
|
|
246
|
-
}
|
|
247
244
|
globalUIComponents() {
|
|
248
245
|
const result = this.#plugins.map((plugin)=>plugin.globalUIComponents || []);
|
|
249
246
|
return result.flat();
|
|
@@ -340,16 +337,16 @@ async function hintThemeBreakingChange(customThemeDir) {
|
|
|
340
337
|
}
|
|
341
338
|
}
|
|
342
339
|
if (useDefaultExportFilePath) logger.warn(`[Rspress v2] Breaking Change: The "theme/index.tsx" is now using named export instead of default export, please update ${picocolors.greenBright(useDefaultExportFilePath)} (https://github.com/web-infra-dev/rspress/discussions/1891#discussioncomment-12422737).\n`, picocolors.redBright(`
|
|
343
|
-
- import Theme from '@rspress/theme
|
|
340
|
+
- import Theme from '@rspress/core/theme';
|
|
344
341
|
- export default {
|
|
345
342
|
- ...Theme,
|
|
346
343
|
- Layout,
|
|
347
344
|
- };
|
|
348
|
-
- export * from 'rspress/theme';`) + picocolors.greenBright(`
|
|
349
|
-
+ import { Layout } from '@rspress/theme
|
|
345
|
+
- export * from '@rspress/core/theme';`) + picocolors.greenBright(`
|
|
346
|
+
+ import { Layout } from '@rspress/core/theme';
|
|
350
347
|
|
|
351
348
|
+ export { Layout };
|
|
352
|
-
+ export * from 'rspress/theme';
|
|
349
|
+
+ export * from '@rspress/core/theme';
|
|
353
350
|
`));
|
|
354
351
|
}
|
|
355
352
|
function hintBuilderPluginsBreakingChange(config) {
|
|
@@ -371,7 +368,7 @@ ${picocolors.greenBright(` builderConfig: {
|
|
|
371
368
|
function hintSSGFailed() {
|
|
372
369
|
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:
|
|
373
370
|
1. Fix code to make it SSR-compatible.
|
|
374
|
-
2. Set \`ssg: false
|
|
371
|
+
2. Set \`ssg: false\` if the code in node_modules may be difficult to fix, but the SSG feature will be lost.`);
|
|
375
372
|
}
|
|
376
373
|
function hintSSGFalse() {
|
|
377
374
|
logger.info('`ssg: false` detected, SSG will be disabled.');
|
|
@@ -406,7 +403,7 @@ function slash(p) {
|
|
|
406
403
|
function normalizePath(id) {
|
|
407
404
|
return external_node_path_["default"].posix.normalize(isWindows ? slash(id) : id);
|
|
408
405
|
}
|
|
409
|
-
var package_namespaceObject = JSON.parse('{"i8":"2.0.0-beta.
|
|
406
|
+
var package_namespaceObject = JSON.parse('{"i8":"2.0.0-beta.22"}');
|
|
410
407
|
const RSPRESS_VERSION = package_namespaceObject.i8;
|
|
411
408
|
const isProduction = ()=>'production' === process.env.NODE_ENV;
|
|
412
409
|
const importStatementRegex = /import\s+(.*?)\s+from\s+(['"])(.*?)(?:"|');?/gm;
|
|
@@ -839,13 +836,18 @@ async function metaFileItemToSidebarItem(metaItemRaw, workDir, docsDir, extensio
|
|
|
839
836
|
}
|
|
840
837
|
function metaCustomLinkItemToSidebarItem(metaItem, workDir, docsDir) {
|
|
841
838
|
if ('items' in metaItem && Array.isArray(metaItem.items) && metaItem.items.length > 0) {
|
|
842
|
-
const { label, link, context, items, tag } = metaItem;
|
|
839
|
+
const { label, link, context, items, tag, collapsed, collapsible, overviewHeaders } = metaItem;
|
|
843
840
|
return {
|
|
844
841
|
text: label ?? link,
|
|
845
842
|
context,
|
|
846
843
|
tag,
|
|
847
844
|
link,
|
|
848
|
-
items: items.map((subItem)=>metaCustomLinkItemToSidebarItem(subItem,
|
|
845
|
+
items: items.map((subItem)=>metaCustomLinkItemToSidebarItem(Object.assign(subItem, {
|
|
846
|
+
type: 'custom-link'
|
|
847
|
+
}), workDir, docsDir)),
|
|
848
|
+
collapsed,
|
|
849
|
+
collapsible,
|
|
850
|
+
overviewHeaders
|
|
849
851
|
};
|
|
850
852
|
}
|
|
851
853
|
if ('link' in metaItem && 'string' == typeof metaItem.link) {
|
|
@@ -1368,7 +1370,6 @@ async function siteDataVMPlugin(context) {
|
|
|
1368
1370
|
locales: userConfig?.locales || userConfig.themeConfig?.locales || [],
|
|
1369
1371
|
logo: userConfig?.logo || '',
|
|
1370
1372
|
logoText: userConfig?.logoText || '',
|
|
1371
|
-
ssg: Boolean(userConfig?.ssg ?? true),
|
|
1372
1373
|
multiVersion: {
|
|
1373
1374
|
default: userConfig?.multiVersion?.default || '',
|
|
1374
1375
|
versions: userConfig?.multiVersion?.versions || []
|
|
@@ -1607,10 +1608,10 @@ async function pMap(iterable, mapper, { concurrency = 1 / 0, stopOnError = true,
|
|
|
1607
1608
|
});
|
|
1608
1609
|
}
|
|
1609
1610
|
const pMapSkip = Symbol('skip');
|
|
1610
|
-
async function renderConfigHead(
|
|
1611
|
+
async function renderConfigHead(head, route) {
|
|
1611
1612
|
if (!isRouteMeta(route)) return '';
|
|
1612
|
-
if (!
|
|
1613
|
-
return
|
|
1613
|
+
if (!head || 0 === head.length) return '';
|
|
1614
|
+
return head.map((head)=>{
|
|
1614
1615
|
if ('string' == typeof head) return head;
|
|
1615
1616
|
if ('function' == typeof head) {
|
|
1616
1617
|
const resultHead = head(route);
|
|
@@ -1621,6 +1622,12 @@ async function renderConfigHead(config, route) {
|
|
|
1621
1622
|
return `<${head[0]} ${renderAttrs(head[1])}>`;
|
|
1622
1623
|
}).join('');
|
|
1623
1624
|
}
|
|
1625
|
+
async function renderHtmlTemplate(htmlTemplate, head, route, appHtml = '') {
|
|
1626
|
+
const replacedHtmlTemplate = htmlTemplate.replace(APP_HTML_MARKER, ()=>appHtml).replace(META_GENERATOR, ()=>`<meta name="generator" content="Rspress v${RSPRESS_VERSION}">`).replace(HEAD_MARKER, [
|
|
1627
|
+
await renderConfigHead(head, route)
|
|
1628
|
+
].join(''));
|
|
1629
|
+
return replacedHtmlTemplate;
|
|
1630
|
+
}
|
|
1624
1631
|
function renderAttrs(attrs) {
|
|
1625
1632
|
return Object.entries(attrs).map(([key, value])=>{
|
|
1626
1633
|
if ('boolean' == typeof value) return key;
|
|
@@ -1631,9 +1638,7 @@ function renderAttrs(attrs) {
|
|
|
1631
1638
|
function isRouteMeta(route) {
|
|
1632
1639
|
return !!route && 'object' == typeof route && 'routePath' in route && 'absolutePath' in route;
|
|
1633
1640
|
}
|
|
1634
|
-
async function
|
|
1635
|
-
logger.info('Rendering pages...');
|
|
1636
|
-
const startTime = Date.now();
|
|
1641
|
+
async function renderPage(route, htmlTemplate, configHead, ssrBundlePath) {
|
|
1637
1642
|
let render;
|
|
1638
1643
|
try {
|
|
1639
1644
|
const { default: ssrExports } = await import((0, external_node_url_.pathToFileURL)(ssrBundlePath).toString());
|
|
@@ -1646,45 +1651,123 @@ async function renderPages(routeService, config, pluginDriver, ssrBundlePath, ht
|
|
|
1646
1651
|
}
|
|
1647
1652
|
throw e;
|
|
1648
1653
|
}
|
|
1654
|
+
const head = createHead();
|
|
1655
|
+
const { routePath } = route;
|
|
1656
|
+
let appHtml = '';
|
|
1657
|
+
if (render) try {
|
|
1658
|
+
({ appHtml } = await render(routePath, head));
|
|
1659
|
+
} catch (e) {
|
|
1660
|
+
if (e instanceof Error) {
|
|
1661
|
+
logger.error(`Page "${picocolors.yellow(routePath)}" SSG rendering failed.\n ${picocolors.gray(e.toString())}`);
|
|
1662
|
+
throw e;
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1665
|
+
const replacedHtmlTemplate = await renderHtmlTemplate(htmlTemplate, configHead, route, appHtml);
|
|
1666
|
+
const html = await transformHtmlTemplate(head, replacedHtmlTemplate);
|
|
1667
|
+
return html;
|
|
1668
|
+
}
|
|
1669
|
+
/**
|
|
1670
|
+
* these codes are copied from
|
|
1671
|
+
* @link https://github.com/facebook/docusaurus/blob/45065e8d2b5831117b8d69fec1be28f5520cf105/packages/docusaurus/src/ssg/ssgEnv.ts#L11
|
|
1672
|
+
* @license MIT
|
|
1673
|
+
*/ function SSGWorkerThreadTaskSize() {
|
|
1674
|
+
return process.env.RSPRESS_SSG_WORKER_THREAD_TASK_SIZE ? Number.parseInt(process.env.RSPRESS_SSG_WORKER_THREAD_TASK_SIZE, 10) : 10;
|
|
1675
|
+
}
|
|
1676
|
+
function SSGWorkerThreadRecyclerMaxMemory() {
|
|
1677
|
+
return process.env.RSPRESS_SSG_WORKER_THREAD_RECYCLER_MAX_MEMORY ? Number.parseInt(process.env.RSPRESS_SSG_WORKER_THREAD_RECYCLER_MAX_MEMORY, 10) : 1000000000;
|
|
1678
|
+
}
|
|
1679
|
+
function inferNumberOfThreads({ pageCount, cpuCount, minPagesPerCpu }) {
|
|
1680
|
+
const threadsByWorkload = Math.ceil(pageCount / minPagesPerCpu);
|
|
1681
|
+
return Math.max(1, Math.min(threadsByWorkload, cpuCount));
|
|
1682
|
+
}
|
|
1683
|
+
function SSGWorkerThreadCount() {
|
|
1684
|
+
return process.env.RSPRESS_SSG_WORKER_THREAD_COUNT ? Number.parseInt(process.env.RSPRESS_SSG_WORKER_THREAD_COUNT, 10) : void 0;
|
|
1685
|
+
}
|
|
1686
|
+
function getNumberOfThreads(pathnamesLength) {
|
|
1687
|
+
const workerCount = SSGWorkerThreadCount();
|
|
1688
|
+
if (void 0 !== workerCount) return workerCount;
|
|
1689
|
+
const cpuCount = 'function' == typeof external_node_os_["default"].availableParallelism ? external_node_os_["default"].availableParallelism() : external_node_os_["default"].cpus().length;
|
|
1690
|
+
return inferNumberOfThreads({
|
|
1691
|
+
pageCount: pathnamesLength,
|
|
1692
|
+
cpuCount,
|
|
1693
|
+
minPagesPerCpu: 100
|
|
1694
|
+
});
|
|
1695
|
+
}
|
|
1696
|
+
function SSGConcurrency() {
|
|
1697
|
+
return process.env.RSPRESS_SSG_CONCURRENCY ? Number.parseInt(process.env.RSPRESS_SSG_CONCURRENCY, 10) : 32;
|
|
1698
|
+
}
|
|
1699
|
+
const routePath2HtmlFileName = (routePath)=>{
|
|
1700
|
+
let fileName = routePath;
|
|
1701
|
+
fileName = fileName.endsWith('/') ? `${routePath}index.html` : `${routePath}.html`;
|
|
1702
|
+
return fileName.replace(/^\/+/, '');
|
|
1703
|
+
};
|
|
1704
|
+
async function renderPages(routeService, config, ssrBundlePath, htmlTemplate, emitAsset) {
|
|
1705
|
+
logger.info('Rendering pages...');
|
|
1706
|
+
const startTime = Date.now();
|
|
1707
|
+
const ssg = config.ssg || true;
|
|
1649
1708
|
try {
|
|
1650
1709
|
const routes = routeService.getRoutes();
|
|
1651
|
-
|
|
1652
|
-
routePath: route.path
|
|
1653
|
-
}));
|
|
1654
|
-
const allRoutes = [
|
|
1655
|
-
...routes,
|
|
1656
|
-
...additionalRoutes
|
|
1657
|
-
];
|
|
1658
|
-
const is404RouteInRoutes = allRoutes.some((route)=>'/404' === route.routePath);
|
|
1659
|
-
if (!is404RouteInRoutes) allRoutes.push({
|
|
1710
|
+
if (!routeService.isExistRoute('/404')) routes.push({
|
|
1660
1711
|
routePath: '/404'
|
|
1661
1712
|
});
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
const
|
|
1665
|
-
const
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1713
|
+
if ('object' == typeof ssg && Array.isArray(ssg?.experimentalExcludeRoutePaths) && ssg.experimentalExcludeRoutePaths.length > 0) {
|
|
1714
|
+
const shouldIgnoreRoutePaths = new Set();
|
|
1715
|
+
const shouldIgnoreRoutePathsRegExp = [];
|
|
1716
|
+
for (const routePath of ssg.experimentalExcludeRoutePaths)if ('string' == typeof routePath) shouldIgnoreRoutePaths.add(routePath);
|
|
1717
|
+
else if (routePath instanceof RegExp) shouldIgnoreRoutePathsRegExp.push(routePath);
|
|
1718
|
+
const promiseList = [];
|
|
1719
|
+
const csrRoutes = [];
|
|
1720
|
+
const ssgRoutes = [];
|
|
1721
|
+
for (const route of routes)if (shouldIgnoreRoutePaths.has(route.routePath) || shouldIgnoreRoutePathsRegExp.some((reg)=>reg.test(route.routePath))) {
|
|
1722
|
+
csrRoutes.push(route);
|
|
1723
|
+
promiseList.push(renderCSRPage(config.head, route, htmlTemplate, emitAsset));
|
|
1724
|
+
} else ssgRoutes.push(route);
|
|
1725
|
+
if (csrRoutes.length > 0) {
|
|
1726
|
+
logger.warn(`Some routes are ignored in SSG and fallback to CSR via \`ssg.experimentalExcludeRoutePaths\`: ${picocolors.yellow(csrRoutes.map((r)=>r.routePath).join(', '))}`);
|
|
1727
|
+
await Promise.all(promiseList);
|
|
1728
|
+
routes.length = 0;
|
|
1729
|
+
routes.push(...ssgRoutes);
|
|
1674
1730
|
}
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
const
|
|
1679
|
-
const
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1731
|
+
}
|
|
1732
|
+
if ('object' == typeof ssg && ssg?.experimentalWorker) {
|
|
1733
|
+
const numberOfThreads = getNumberOfThreads(routes.length);
|
|
1734
|
+
const Tinypool = await import("tinypool").then((m)=>m.default);
|
|
1735
|
+
const pool = new Tinypool({
|
|
1736
|
+
filename: new URL('./renderPageWorker.js', import.meta.url).href,
|
|
1737
|
+
concurrentTasksPerWorker: 1,
|
|
1738
|
+
minThreads: numberOfThreads,
|
|
1739
|
+
maxThreads: numberOfThreads,
|
|
1740
|
+
/**
|
|
1741
|
+
* https://github.com/facebook/docusaurus/blob/0306d182407bb98f140cd5ec7481fa9608fe0297/packages/docusaurus/src/ssg/ssgExecutor.ts#L123
|
|
1742
|
+
* @license MIT
|
|
1743
|
+
*/ maxMemoryLimitBeforeRecycle: SSGWorkerThreadRecyclerMaxMemory(),
|
|
1744
|
+
isolateWorkers: false,
|
|
1745
|
+
workerData: {
|
|
1746
|
+
params: {
|
|
1747
|
+
htmlTemplate,
|
|
1748
|
+
head: config.head,
|
|
1749
|
+
ssrBundlePath
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
});
|
|
1753
|
+
await Promise.all(chunk(routes, SSGWorkerThreadTaskSize()).map(async (routes)=>{
|
|
1754
|
+
const htmlList = await pool.run({
|
|
1755
|
+
routes
|
|
1756
|
+
});
|
|
1757
|
+
for(let i = 0; i < routes.length; i++){
|
|
1758
|
+
const route = routes[i];
|
|
1759
|
+
const html = htmlList[i];
|
|
1760
|
+
const fileName = routePath2HtmlFileName(route.routePath);
|
|
1761
|
+
emitAsset(fileName, html);
|
|
1762
|
+
}
|
|
1763
|
+
}));
|
|
1764
|
+
await pool.destroy();
|
|
1765
|
+
} else await pMap(routes, async (route)=>{
|
|
1766
|
+
const html = await renderPage(route, htmlTemplate, config.head, ssrBundlePath);
|
|
1767
|
+
const fileName = routePath2HtmlFileName(route.routePath);
|
|
1685
1768
|
emitAsset(fileName, html);
|
|
1686
1769
|
}, {
|
|
1687
|
-
concurrency:
|
|
1770
|
+
concurrency: SSGConcurrency()
|
|
1688
1771
|
});
|
|
1689
1772
|
const totalTime = Date.now() - startTime;
|
|
1690
1773
|
logger.success(`Pages rendered in ${picocolors.yellow(totalTime)} ms.`);
|
|
@@ -1697,7 +1780,44 @@ async function renderPages(routeService, config, pluginDriver, ssrBundlePath, ht
|
|
|
1697
1780
|
throw e;
|
|
1698
1781
|
}
|
|
1699
1782
|
}
|
|
1700
|
-
|
|
1783
|
+
async function renderCSRPage(head, route, htmlTemplate, emitAsset) {
|
|
1784
|
+
const html = await renderHtmlTemplate(htmlTemplate, head, route, '');
|
|
1785
|
+
const fileName = routePath2HtmlFileName(route.routePath);
|
|
1786
|
+
emitAsset(fileName, html);
|
|
1787
|
+
}
|
|
1788
|
+
async function renderCSRPages(routeService, config, htmlTemplate, emitAsset) {
|
|
1789
|
+
const routes = routeService.getRoutes();
|
|
1790
|
+
if (!routeService.isExistRoute('/404')) routes.push({
|
|
1791
|
+
routePath: '/404'
|
|
1792
|
+
});
|
|
1793
|
+
await Promise.all(routes.map((route)=>renderCSRPage(config.head, route, htmlTemplate, emitAsset)));
|
|
1794
|
+
}
|
|
1795
|
+
const rsbuildPluginCSR = ({ routeService, config })=>({
|
|
1796
|
+
name: 'rspress-inner-rsbuild-plugin-csr',
|
|
1797
|
+
async setup (api) {
|
|
1798
|
+
api.onBeforeBuild(()=>{
|
|
1799
|
+
api.processAssets({
|
|
1800
|
+
stage: 'report',
|
|
1801
|
+
environments: [
|
|
1802
|
+
'web'
|
|
1803
|
+
]
|
|
1804
|
+
}, async ({ assets, compilation, compiler })=>{
|
|
1805
|
+
if (compilation.errors.length > 0) return;
|
|
1806
|
+
const emitAsset = (assetName, content)=>{
|
|
1807
|
+
compilation.emitAsset(assetName, new compiler.webpack.sources.RawSource(content));
|
|
1808
|
+
};
|
|
1809
|
+
let htmlTemplate = '';
|
|
1810
|
+
for (const [assetName, assetSource] of Object.entries(assets))if ('index.html' === assetName) {
|
|
1811
|
+
htmlTemplate = assetSource.source().toString();
|
|
1812
|
+
compilation.deleteAsset(assetName);
|
|
1813
|
+
break;
|
|
1814
|
+
}
|
|
1815
|
+
await renderCSRPages(routeService, config, htmlTemplate, emitAsset);
|
|
1816
|
+
});
|
|
1817
|
+
});
|
|
1818
|
+
}
|
|
1819
|
+
});
|
|
1820
|
+
const rsbuildPluginSSG = ({ routeService, config })=>({
|
|
1701
1821
|
name: 'rspress-inner-rsbuild-plugin-ssg',
|
|
1702
1822
|
async setup (api) {
|
|
1703
1823
|
api.onBeforeBuild(()=>{
|
|
@@ -1706,11 +1826,10 @@ const rsbuildPluginSSG = ({ routeService, config, pluginDriver })=>({
|
|
|
1706
1826
|
const indexHtmlEmittedInWeb = new Promise((resolve, reject)=>{
|
|
1707
1827
|
api.processAssets({
|
|
1708
1828
|
stage: 'report',
|
|
1709
|
-
|
|
1829
|
+
environments: [
|
|
1710
1830
|
'web'
|
|
1711
1831
|
]
|
|
1712
|
-
}, ({ assets, compilation
|
|
1713
|
-
if ('web' !== environment.name) return;
|
|
1832
|
+
}, ({ assets, compilation })=>{
|
|
1714
1833
|
if (compilation.errors.length > 0) {
|
|
1715
1834
|
hasError = true;
|
|
1716
1835
|
return;
|
|
@@ -1731,16 +1850,18 @@ const rsbuildPluginSSG = ({ routeService, config, pluginDriver })=>({
|
|
|
1731
1850
|
});
|
|
1732
1851
|
api.processAssets({
|
|
1733
1852
|
stage: 'optimize-transfer',
|
|
1734
|
-
|
|
1853
|
+
environments: [
|
|
1735
1854
|
'node'
|
|
1736
1855
|
]
|
|
1737
1856
|
}, async ({ assets, compilation, environment, compiler })=>{
|
|
1738
|
-
if ('node' !== environment.name) return;
|
|
1739
1857
|
if (compilation.errors.length > 0) {
|
|
1740
1858
|
hasError = true;
|
|
1741
1859
|
return;
|
|
1742
1860
|
}
|
|
1743
1861
|
if (hasError) return;
|
|
1862
|
+
const emitAsset = (assetName, content)=>{
|
|
1863
|
+
compilation.emitAsset(assetName, new compiler.webpack.sources.RawSource(content));
|
|
1864
|
+
};
|
|
1744
1865
|
const distPath = environment.distPath;
|
|
1745
1866
|
const ssgFolderPath = (0, external_node_path_.join)(distPath, NODE_SSG_BUNDLE_FOLDER);
|
|
1746
1867
|
const mainCjsAbsolutePath = (0, external_node_path_.join)(ssgFolderPath, NODE_SSG_BUNDLE_NAME);
|
|
@@ -1754,11 +1875,8 @@ const rsbuildPluginSSG = ({ routeService, config, pluginDriver })=>({
|
|
|
1754
1875
|
compilation.deleteAsset(assetName);
|
|
1755
1876
|
}
|
|
1756
1877
|
}));
|
|
1757
|
-
const emitAsset = (assetName, content)=>{
|
|
1758
|
-
compilation.emitAsset(assetName, new compiler.webpack.sources.RawSource(content));
|
|
1759
|
-
};
|
|
1760
1878
|
await indexHtmlEmittedInWeb;
|
|
1761
|
-
await renderPages(routeService, config,
|
|
1879
|
+
await renderPages(routeService, config, mainCjsAbsolutePath, htmlTemplate, emitAsset);
|
|
1762
1880
|
if (!(0, shared_.isDebugMode)()) await rm(ssgFolderPath, {
|
|
1763
1881
|
recursive: true
|
|
1764
1882
|
});
|
|
@@ -1945,13 +2063,13 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1945
2063
|
...runtimeConfigVMPlugin(context)
|
|
1946
2064
|
}
|
|
1947
2065
|
}),
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
2066
|
+
enableSSG ? rsbuildPluginSSG({
|
|
2067
|
+
routeService,
|
|
2068
|
+
config
|
|
2069
|
+
}) : rsbuildPluginCSR({
|
|
2070
|
+
routeService,
|
|
2071
|
+
config
|
|
2072
|
+
})
|
|
1955
2073
|
],
|
|
1956
2074
|
server: {
|
|
1957
2075
|
port: !isProduction() && process.env.PORT ? Number(process.env.PORT) : void 0,
|
|
@@ -1998,7 +2116,6 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1998
2116
|
DEFAULT_THEME
|
|
1999
2117
|
],
|
|
2000
2118
|
'@theme-assets': external_node_path_["default"].join(DEFAULT_THEME, '../assets'),
|
|
2001
|
-
'@rspress/core': PACKAGE_ROOT,
|
|
2002
2119
|
'react-lazy-with-preload': require.resolve('react-lazy-with-preload')
|
|
2003
2120
|
}
|
|
2004
2121
|
},
|
|
@@ -2026,6 +2143,11 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
2026
2143
|
})) ?? {
|
|
2027
2144
|
nav: config.themeConfig?.nav,
|
|
2028
2145
|
sidebar: config.themeConfig?.sidebar
|
|
2146
|
+
}),
|
|
2147
|
+
JSON.stringify({
|
|
2148
|
+
base: config.base,
|
|
2149
|
+
ssg: config.ssg,
|
|
2150
|
+
pluginLength: config.plugins?.length ?? 0
|
|
2029
2151
|
})
|
|
2030
2152
|
]
|
|
2031
2153
|
}
|
|
@@ -2278,7 +2400,7 @@ async function build(options) {
|
|
|
2278
2400
|
const pluginDriver = new PluginDriver(config, configFilePath, true);
|
|
2279
2401
|
await pluginDriver.init();
|
|
2280
2402
|
const modifiedConfig = await pluginDriver.modifyConfig();
|
|
2281
|
-
const ssgConfig = modifiedConfig.ssg ?? true;
|
|
2403
|
+
const ssgConfig = Boolean(modifiedConfig.ssg ?? true);
|
|
2282
2404
|
await emptyDir(constants_TEMP_DIR);
|
|
2283
2405
|
await bundle(docDirectory, modifiedConfig, pluginDriver, ssgConfig);
|
|
2284
2406
|
if (!ssgConfig) hintSSGFalse();
|
|
@@ -2457,7 +2579,7 @@ function parseFileFromMeta(meta) {
|
|
|
2457
2579
|
if (!meta) return '';
|
|
2458
2580
|
const kvList = meta.split(' ').filter(Boolean);
|
|
2459
2581
|
for (const item of kvList){
|
|
2460
|
-
const [k, v] = item.split('=');
|
|
2582
|
+
const [k, v = ''] = item.split('=');
|
|
2461
2583
|
if ('file' === k && v.length > 0) return v.replace(/["'`]/g, '');
|
|
2462
2584
|
}
|
|
2463
2585
|
return '';
|
|
@@ -2465,13 +2587,14 @@ function parseFileFromMeta(meta) {
|
|
|
2465
2587
|
const remarkFileCodeBlock = ({ filepath })=>async (tree)=>{
|
|
2466
2588
|
const promiseList = [];
|
|
2467
2589
|
visit(tree, 'code', (node)=>{
|
|
2468
|
-
const { meta, value } = node;
|
|
2590
|
+
const { meta, value, lang } = node;
|
|
2469
2591
|
const file = parseFileFromMeta(meta ?? '');
|
|
2470
2592
|
if (!file) return;
|
|
2593
|
+
const originalMetaForErrorInfo = picocolors.cyan(`\`\`\`${lang} ${meta}`);
|
|
2471
2594
|
if (file.startsWith('./') || file.startsWith('../')) {
|
|
2472
2595
|
const resolvedFilePath = external_node_path_["default"].join(external_node_path_["default"].dirname(filepath), file);
|
|
2473
2596
|
if ('' !== value.trim()) {
|
|
2474
|
-
logger.error(`${ERROR_PREFIX} The content of file code block should be empty.
|
|
2597
|
+
logger.error(`${ERROR_PREFIX} ${originalMetaForErrorInfo} The content of file code block should be empty.
|
|
2475
2598
|
|
|
2476
2599
|
\`\`\`tsx file="./filename"
|
|
2477
2600
|
content
|
|
@@ -2482,26 +2605,36 @@ this usage is not allowed, please use below:
|
|
|
2482
2605
|
\`\`\`tsx file="./filename"
|
|
2483
2606
|
\`\`\`
|
|
2484
2607
|
`);
|
|
2485
|
-
throw new Error(`${ERROR_PREFIX} The content of file code block should be empty.`);
|
|
2608
|
+
throw new Error(`${ERROR_PREFIX} ${originalMetaForErrorInfo} The content of file code block should be empty.`);
|
|
2486
2609
|
}
|
|
2487
2610
|
const promise = readFile(resolvedFilePath, 'utf-8').then((fileContent)=>{
|
|
2488
2611
|
node.value = fileContent;
|
|
2489
2612
|
}).catch((e)=>{
|
|
2490
|
-
|
|
2491
|
-
|
|
2613
|
+
const message = `${ERROR_PREFIX} ${originalMetaForErrorInfo} introduces another file in "${resolvedFilePath}", but the file does not exist.`;
|
|
2614
|
+
logger.error(message);
|
|
2615
|
+
e.message = `${message}\n${e.message}`;
|
|
2492
2616
|
throw e;
|
|
2493
2617
|
});
|
|
2494
2618
|
promiseList.push(promise);
|
|
2495
2619
|
return;
|
|
2496
2620
|
}
|
|
2497
|
-
|
|
2621
|
+
logger.error(`${ERROR_PREFIX} ${originalMetaForErrorInfo} syntax error of file code block:
|
|
2622
|
+
Please use below:
|
|
2623
|
+
|
|
2624
|
+
\`\`\`tsx file="./filename"
|
|
2625
|
+
\`\`\`
|
|
2626
|
+
`);
|
|
2627
|
+
throw new Error(`${ERROR_PREFIX} ${originalMetaForErrorInfo} syntax error of file code block`);
|
|
2498
2628
|
});
|
|
2499
2629
|
await Promise.all(promiseList);
|
|
2500
2630
|
};
|
|
2631
|
+
function defineConfig(config) {
|
|
2632
|
+
return config;
|
|
2633
|
+
}
|
|
2501
2634
|
var __webpack_exports__RSPRESS_TEMP_DIR = shared_.RSPRESS_TEMP_DIR;
|
|
2502
2635
|
var __webpack_exports__getSidebarDataGroup = shared_.getSidebarDataGroup;
|
|
2503
2636
|
var __webpack_exports__normalizeHref = shared_.normalizeHref;
|
|
2504
2637
|
var __webpack_exports__normalizePosixPath = shared_.normalizePosixPath;
|
|
2505
2638
|
var __webpack_exports__removeTrailingSlash = shared_.removeTrailingSlash;
|
|
2506
2639
|
var __webpack_exports__withBase = shared_.withBase;
|
|
2507
|
-
export { build, dev, getIconUrlPath, getNodeAttribute, logger, matchPath, mergeDocConfig, remarkFileCodeBlock, remarkPluginNormalizeLink, serve, __webpack_exports__RSPRESS_TEMP_DIR as RSPRESS_TEMP_DIR, __webpack_exports__getSidebarDataGroup as getSidebarDataGroup, __webpack_exports__normalizeHref as normalizeHref, __webpack_exports__normalizePosixPath as normalizePosixPath, __webpack_exports__removeTrailingSlash as removeTrailingSlash, __webpack_exports__withBase as withBase };
|
|
2640
|
+
export { build, defineConfig, dev, getIconUrlPath, getNodeAttribute, logger, matchPath, mergeDocConfig, remarkFileCodeBlock, remarkPluginNormalizeLink, serve, __webpack_exports__RSPRESS_TEMP_DIR as RSPRESS_TEMP_DIR, __webpack_exports__getSidebarDataGroup as getSidebarDataGroup, __webpack_exports__normalizeHref as normalizeHref, __webpack_exports__normalizePosixPath as normalizePosixPath, __webpack_exports__removeTrailingSlash as removeTrailingSlash, __webpack_exports__withBase as withBase };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* https://github.com/facebook/docusaurus/blob/0306d182407bb98f140cd5ec7481fa9608fe0297/packages/docusaurus/src/ssg/ssgExecutor.ts#L123
|
|
3
|
+
* @license MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* these codes are copied from
|
|
8
|
+
* @link https://github.com/facebook/docusaurus/blob/45065e8d2b5831117b8d69fec1be28f5520cf105/packages/docusaurus/src/ssg/ssgEnv.ts#L11
|
|
9
|
+
* @license MIT
|
|
10
|
+
*/
|
package/dist/loader.d.ts
CHANGED
|
@@ -42,11 +42,6 @@ declare class PluginDriver {
|
|
|
42
42
|
routeGenerated(routes: RouteMeta[]): Promise<void[]>;
|
|
43
43
|
routeServiceGenerated(routeService: RouteService): Promise<void[]>;
|
|
44
44
|
addRuntimeModules(): Promise<Record<string, string>>;
|
|
45
|
-
addSSGRoutes(): Promise<({
|
|
46
|
-
path: string;
|
|
47
|
-
} | {
|
|
48
|
-
path: string;
|
|
49
|
-
})[]>;
|
|
50
45
|
globalUIComponents(): (string | [string, object])[];
|
|
51
46
|
globalStyles(): string[];
|
|
52
47
|
_runParallelAsyncHook<H extends RspressPluginHookKeys>(hookName: H, ...args: Parameters<Required<RspressPlugin>[H]>): Promise<Awaited<ReturnType<Required<RspressPlugin>[H]>>[]>;
|
|
@@ -88,6 +83,6 @@ declare class RouteService {
|
|
|
88
83
|
getRoutePageByRoutePath(routePath: string): RoutePage | undefined;
|
|
89
84
|
}
|
|
90
85
|
|
|
91
|
-
declare type RspressPluginHookKeys = 'beforeBuild' | 'config' | 'afterBuild' | 'addPages' | 'addRuntimeModules' | 'routeGenerated' | 'routeServiceGenerated' | '
|
|
86
|
+
declare type RspressPluginHookKeys = 'beforeBuild' | 'config' | 'afterBuild' | 'addPages' | 'addRuntimeModules' | 'routeGenerated' | 'routeServiceGenerated' | 'extendPageData' | 'modifySearchIndexData';
|
|
92
87
|
|
|
93
88
|
export { }
|
package/dist/processor.d.ts
CHANGED
|
@@ -44,11 +44,6 @@ declare class PluginDriver {
|
|
|
44
44
|
routeGenerated(routes: RouteMeta[]): Promise<void[]>;
|
|
45
45
|
routeServiceGenerated(routeService: RouteService): Promise<void[]>;
|
|
46
46
|
addRuntimeModules(): Promise<Record<string, string>>;
|
|
47
|
-
addSSGRoutes(): Promise<({
|
|
48
|
-
path: string;
|
|
49
|
-
} | {
|
|
50
|
-
path: string;
|
|
51
|
-
})[]>;
|
|
52
47
|
globalUIComponents(): (string | [string, object])[];
|
|
53
48
|
globalStyles(): string[];
|
|
54
49
|
_runParallelAsyncHook<H extends RspressPluginHookKeys>(hookName: H, ...args: Parameters<Required<RspressPlugin>[H]>): Promise<Awaited<ReturnType<Required<RspressPlugin>[H]>>[]>;
|
|
@@ -90,6 +85,6 @@ declare class RouteService {
|
|
|
90
85
|
getRoutePageByRoutePath(routePath: string): RoutePage | undefined;
|
|
91
86
|
}
|
|
92
87
|
|
|
93
|
-
declare type RspressPluginHookKeys = 'beforeBuild' | 'config' | 'afterBuild' | 'addPages' | 'addRuntimeModules' | 'routeGenerated' | 'routeServiceGenerated' | '
|
|
88
|
+
declare type RspressPluginHookKeys = 'beforeBuild' | 'config' | 'afterBuild' | 'addPages' | 'addRuntimeModules' | 'routeGenerated' | 'routeServiceGenerated' | 'extendPageData' | 'modifySearchIndexData';
|
|
94
89
|
|
|
95
90
|
export { }
|
package/dist/processor.js
CHANGED
|
@@ -319,7 +319,7 @@ function parseTitleFromMeta(meta) {
|
|
|
319
319
|
if (!meta) return '';
|
|
320
320
|
const kvList = meta.split(' ').filter(Boolean);
|
|
321
321
|
for (const item of kvList){
|
|
322
|
-
const [k, v] = item.split('=');
|
|
322
|
+
const [k, v = ''] = item.split('=').filter(Boolean);
|
|
323
323
|
if ('title' === k && v.length > 0) return v.replace(/["'`]/g, '');
|
|
324
324
|
}
|
|
325
325
|
return '';
|
|
@@ -389,6 +389,7 @@ const createContainer = (type, title, children)=>{
|
|
|
389
389
|
const titleHName = isDetails ? 'summary' : 'div';
|
|
390
390
|
return {
|
|
391
391
|
type: 'containerDirective',
|
|
392
|
+
name: type,
|
|
392
393
|
data: {
|
|
393
394
|
hName: rootHName,
|
|
394
395
|
hProperties: {
|
|
@@ -567,7 +568,7 @@ function parseFileFromMeta(meta) {
|
|
|
567
568
|
if (!meta) return '';
|
|
568
569
|
const kvList = meta.split(' ').filter(Boolean);
|
|
569
570
|
for (const item of kvList){
|
|
570
|
-
const [k, v] = item.split('=');
|
|
571
|
+
const [k, v = ''] = item.split('=');
|
|
571
572
|
if ('file' === k && v.length > 0) return v.replace(/["'`]/g, '');
|
|
572
573
|
}
|
|
573
574
|
return '';
|
|
@@ -575,13 +576,14 @@ function parseFileFromMeta(meta) {
|
|
|
575
576
|
const remarkFileCodeBlock = ({ filepath })=>async (tree)=>{
|
|
576
577
|
const promiseList = [];
|
|
577
578
|
visit(tree, 'code', (node)=>{
|
|
578
|
-
const { meta, value } = node;
|
|
579
|
+
const { meta, value, lang } = node;
|
|
579
580
|
const file = parseFileFromMeta(meta ?? '');
|
|
580
581
|
if (!file) return;
|
|
582
|
+
const originalMetaForErrorInfo = picocolors_0.cyan(`\`\`\`${lang} ${meta}`);
|
|
581
583
|
if (file.startsWith('./') || file.startsWith('../')) {
|
|
582
584
|
const resolvedFilePath = node_path.join(node_path.dirname(filepath), file);
|
|
583
585
|
if ('' !== value.trim()) {
|
|
584
|
-
logger_logger.error(`${ERROR_PREFIX} The content of file code block should be empty.
|
|
586
|
+
logger_logger.error(`${ERROR_PREFIX} ${originalMetaForErrorInfo} The content of file code block should be empty.
|
|
585
587
|
|
|
586
588
|
\`\`\`tsx file="./filename"
|
|
587
589
|
content
|
|
@@ -592,19 +594,26 @@ this usage is not allowed, please use below:
|
|
|
592
594
|
\`\`\`tsx file="./filename"
|
|
593
595
|
\`\`\`
|
|
594
596
|
`);
|
|
595
|
-
throw new Error(`${ERROR_PREFIX} The content of file code block should be empty.`);
|
|
597
|
+
throw new Error(`${ERROR_PREFIX} ${originalMetaForErrorInfo} The content of file code block should be empty.`);
|
|
596
598
|
}
|
|
597
599
|
const promise = promises_readFile(resolvedFilePath, 'utf-8').then((fileContent)=>{
|
|
598
600
|
node.value = fileContent;
|
|
599
601
|
}).catch((e)=>{
|
|
600
|
-
|
|
601
|
-
|
|
602
|
+
const message = `${ERROR_PREFIX} ${originalMetaForErrorInfo} introduces another file in "${resolvedFilePath}", but the file does not exist.`;
|
|
603
|
+
logger_logger.error(message);
|
|
604
|
+
e.message = `${message}\n${e.message}`;
|
|
602
605
|
throw e;
|
|
603
606
|
});
|
|
604
607
|
promiseList.push(promise);
|
|
605
608
|
return;
|
|
606
609
|
}
|
|
607
|
-
|
|
610
|
+
logger_logger.error(`${ERROR_PREFIX} ${originalMetaForErrorInfo} syntax error of file code block:
|
|
611
|
+
Please use below:
|
|
612
|
+
|
|
613
|
+
\`\`\`tsx file="./filename"
|
|
614
|
+
\`\`\`
|
|
615
|
+
`);
|
|
616
|
+
throw new Error(`${ERROR_PREFIX} ${originalMetaForErrorInfo} syntax error of file code block`);
|
|
608
617
|
});
|
|
609
618
|
await Promise.all(promiseList);
|
|
610
619
|
};
|