@rspress/core 2.0.0-beta.14 → 2.0.0-beta.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +18 -4
- package/dist/index.js +240 -230
- package/dist/loader.d.ts +18 -4
- package/dist/processor.d.ts +18 -4
- package/dist/processor.js +24 -24
- package/dist/runtime/App.js +5 -5
- package/dist/runtime/initPageData.js +12 -12
- package/package.json +12 -12
package/dist/index.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
import __rslib_shim_module__ from 'module';
|
|
2
2
|
const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(import.meta.url);
|
|
3
3
|
import { pluginContainerSyntax } from "@rspress/plugin-container-syntax";
|
|
4
|
-
import
|
|
5
|
-
import
|
|
4
|
+
import node_fs_promises, { mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
5
|
+
import node_path, { extname as external_node_path_extname, join } from "node:path";
|
|
6
6
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
7
7
|
import { PLUGIN_REACT_NAME, pluginReact } from "@rsbuild/plugin-react";
|
|
8
8
|
import { APPEARANCE_KEY, MDX_OR_MD_REGEXP, RSPRESS_TEMP_DIR, SEARCH_INDEX_NAME, addLeadingSlash, addTrailingSlash, isDebugMode, isExternalUrl, isSCM, normalizeHref, normalizeSlash, parseUrl, removeLeadingSlash, removeTrailingSlash, slash, withBase, withoutBase } from "@rspress/shared";
|
|
9
9
|
import { logger } from "@rspress/shared/logger";
|
|
10
|
-
import
|
|
10
|
+
import picocolors from "picocolors";
|
|
11
11
|
import { DEFAULT_PAGE_EXTENSIONS } from "@rspress/shared/constants";
|
|
12
12
|
import { glob } from "tinyglobby";
|
|
13
|
-
import
|
|
13
|
+
import node_os from "node:os";
|
|
14
14
|
import { RspackVirtualModulePlugin } from "rspack-plugin-virtual-module";
|
|
15
15
|
import { getIconUrlPath, getNodeAttribute, loadFrontMatter, mergeDocConfig } from "@rspress/shared/node-utils";
|
|
16
16
|
import { groupBy } from "lodash-es";
|
|
17
|
-
import { createHash } from "node:crypto";
|
|
18
17
|
import { compile } from "@rspress/mdx-rs";
|
|
19
18
|
import { htmlToText } from "html-to-text";
|
|
20
|
-
import
|
|
19
|
+
import node_fs, { createReadStream, existsSync } from "node:fs";
|
|
21
20
|
import { createProcessor } from "@mdx-js/mdx";
|
|
22
|
-
import
|
|
21
|
+
import enhanced_resolve from "enhanced-resolve";
|
|
22
|
+
import { createHash } from "node:crypto";
|
|
23
23
|
import { createHead, transformHtmlTemplate } from "@unhead/react/server";
|
|
24
24
|
import { mergeRsbuildConfig as core_mergeRsbuildConfig } from "@rsbuild/core";
|
|
25
25
|
import { visit } from "unist-util-visit";
|
|
@@ -179,7 +179,7 @@ const pluginVirtualModule = (pluginOptions = {})=>({
|
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
181
|
});
|
|
182
|
-
var package_namespaceObject = JSON.parse('{"i8":"2.0.0-beta.
|
|
182
|
+
var package_namespaceObject = JSON.parse('{"i8":"2.0.0-beta.15"}');
|
|
183
183
|
const RSPRESS_VERSION = package_namespaceObject.i8;
|
|
184
184
|
const isProduction = ()=>'production' === process.env.NODE_ENV;
|
|
185
185
|
const importStatementRegex = /import\s+(.*?)\s+from\s+(['"])(.*?)(?:"|');?/gm;
|
|
@@ -191,29 +191,29 @@ const inlineThemeScript = `{
|
|
|
191
191
|
document.documentElement.classList.toggle('rp-dark', isDark)
|
|
192
192
|
document.documentElement.style.colorScheme = isDark ? 'dark' : 'light'
|
|
193
193
|
}`.replace(/\n/g, ';').replace(/\s{2,}/g, '');
|
|
194
|
-
const dirname =
|
|
195
|
-
const PACKAGE_ROOT =
|
|
196
|
-
const TEMPLATE_PATH =
|
|
197
|
-
const CSR_CLIENT_ENTRY =
|
|
198
|
-
const SSR_CLIENT_ENTRY =
|
|
199
|
-
const SSR_SERVER_ENTRY =
|
|
194
|
+
const dirname = node_path.dirname(fileURLToPath(new URL(import.meta.url)));
|
|
195
|
+
const PACKAGE_ROOT = node_path.join(dirname, '..');
|
|
196
|
+
const TEMPLATE_PATH = node_path.join(PACKAGE_ROOT, 'index.html');
|
|
197
|
+
const CSR_CLIENT_ENTRY = node_path.join(PACKAGE_ROOT, 'dist', 'runtime', 'csrClientEntry.js');
|
|
198
|
+
const SSR_CLIENT_ENTRY = node_path.join(PACKAGE_ROOT, 'dist', 'runtime', 'ssrClientEntry.js');
|
|
199
|
+
const SSR_SERVER_ENTRY = node_path.join(PACKAGE_ROOT, 'dist', 'runtime', 'ssrServerEntry.js');
|
|
200
200
|
const OUTPUT_DIR = 'doc_build';
|
|
201
201
|
const APP_HTML_MARKER = '<!--<?- DOC_CONTENT ?>-->';
|
|
202
202
|
const HEAD_MARKER = '<!--<?- HEAD ?>-->';
|
|
203
203
|
const META_GENERATOR = '<!--<?- GENERATOR ?>-->';
|
|
204
204
|
const DEFAULT_TITLE = 'Rspress';
|
|
205
205
|
const PUBLIC_DIR = 'public';
|
|
206
|
-
const constants_TEMP_DIR =
|
|
206
|
+
const constants_TEMP_DIR = node_path.join(process.cwd(), 'node_modules', RSPRESS_TEMP_DIR);
|
|
207
207
|
async function pathExists(path) {
|
|
208
208
|
try {
|
|
209
|
-
await
|
|
209
|
+
await node_fs_promises.access(path);
|
|
210
210
|
return true;
|
|
211
211
|
} catch {
|
|
212
212
|
return false;
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
215
|
async function readJson(path) {
|
|
216
|
-
const raw = await
|
|
216
|
+
const raw = await node_fs_promises.readFile(path, 'utf8');
|
|
217
217
|
return JSON.parse(raw);
|
|
218
218
|
}
|
|
219
219
|
const THEME_DEFAULT_EXPORT_PATTERN = /export\s+default\s+\{/;
|
|
@@ -235,13 +235,13 @@ async function hintThemeBreakingChange(customThemeDir) {
|
|
|
235
235
|
break;
|
|
236
236
|
}
|
|
237
237
|
}
|
|
238
|
-
if (useDefaultExportFilePath) logger.warn(`[Rspress v2] Breaking Change: The "theme/index.tsx" is now using named export instead of default export, please update ${
|
|
238
|
+
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(`
|
|
239
239
|
- import Theme from '@rspress/theme-default';
|
|
240
240
|
- export default {
|
|
241
241
|
- ...Theme,
|
|
242
242
|
- Layout,
|
|
243
243
|
- };
|
|
244
|
-
- export * from 'rspress/theme';`) +
|
|
244
|
+
- export * from 'rspress/theme';`) + picocolors.greenBright(`
|
|
245
245
|
+ import { Layout } from '@rspress/theme-default';
|
|
246
246
|
|
|
247
247
|
+ export { Layout };
|
|
@@ -259,17 +259,26 @@ function hintSSGFalse() {
|
|
|
259
259
|
function hintReactVersion() {
|
|
260
260
|
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. ');
|
|
261
261
|
}
|
|
262
|
-
const isWindows = 'win32' ===
|
|
262
|
+
const isWindows = 'win32' === node_os.platform();
|
|
263
263
|
function normalizePath_slash(p) {
|
|
264
264
|
return p.replace(/\\/g, '/');
|
|
265
265
|
}
|
|
266
266
|
function normalizePath(id) {
|
|
267
|
-
return
|
|
267
|
+
return node_path.posix.normalize(isWindows ? normalizePath_slash(id) : id);
|
|
268
268
|
}
|
|
269
269
|
function getPageKey(route) {
|
|
270
270
|
const cleanRoute = removeLeadingSlash(route);
|
|
271
271
|
return cleanRoute.replace(/\//g, '_').replace(/\.[^.]+$/, '') || 'index';
|
|
272
272
|
}
|
|
273
|
+
class RoutePage {
|
|
274
|
+
routeMeta;
|
|
275
|
+
static create(routeMeta) {
|
|
276
|
+
return new RoutePage(routeMeta);
|
|
277
|
+
}
|
|
278
|
+
constructor(routeMeta){
|
|
279
|
+
this.routeMeta = routeMeta;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
273
282
|
const getRoutePathParts = (routePath, lang, version, langs, versions)=>{
|
|
274
283
|
const hasTrailSlash = routePath.endsWith('/');
|
|
275
284
|
let versionPart = '';
|
|
@@ -324,6 +333,13 @@ class RouteService {
|
|
|
324
333
|
#base = '';
|
|
325
334
|
#tempDir = '';
|
|
326
335
|
#pluginDriver;
|
|
336
|
+
static async create(options) {
|
|
337
|
+
const { scanDir, config, runtimeTempDir, pluginDriver } = options;
|
|
338
|
+
const routeService = new RouteService(scanDir, config, runtimeTempDir, pluginDriver);
|
|
339
|
+
await routeService.#init();
|
|
340
|
+
await pluginDriver.routeServiceGenerated(routeService);
|
|
341
|
+
return routeService;
|
|
342
|
+
}
|
|
327
343
|
constructor(scanDir, userConfig, tempDir, pluginDriver){
|
|
328
344
|
const routeOptions = userConfig?.route || {};
|
|
329
345
|
this.#scanDir = scanDir;
|
|
@@ -343,7 +359,7 @@ class RouteService {
|
|
|
343
359
|
get extensions() {
|
|
344
360
|
return this.#extensions;
|
|
345
361
|
}
|
|
346
|
-
async init() {
|
|
362
|
+
async #init() {
|
|
347
363
|
const extensions = this.#extensions.map((i)=>i.slice(1));
|
|
348
364
|
const files = (await glob([
|
|
349
365
|
`**/*.{${extensions.join(',')}}`,
|
|
@@ -361,10 +377,10 @@ class RouteService {
|
|
|
361
377
|
]
|
|
362
378
|
})).sort();
|
|
363
379
|
files.forEach((filePath)=>{
|
|
364
|
-
const fileRelativePath = normalizePath(
|
|
380
|
+
const fileRelativePath = normalizePath(node_path.relative(this.#scanDir, filePath));
|
|
365
381
|
const { routePath, lang, version } = this.normalizeRoutePath(fileRelativePath);
|
|
366
|
-
const absolutePath =
|
|
367
|
-
const
|
|
382
|
+
const absolutePath = node_path.join(this.#scanDir, fileRelativePath);
|
|
383
|
+
const routeMeta = {
|
|
368
384
|
routePath,
|
|
369
385
|
absolutePath: normalizePath(absolutePath),
|
|
370
386
|
relativePath: fileRelativePath,
|
|
@@ -372,47 +388,45 @@ class RouteService {
|
|
|
372
388
|
lang,
|
|
373
389
|
version
|
|
374
390
|
};
|
|
375
|
-
this.addRoute(
|
|
391
|
+
this.addRoute(routeMeta);
|
|
376
392
|
});
|
|
377
393
|
const externalPages = await this.#pluginDriver.addPages();
|
|
378
394
|
await Promise.all(externalPages.map(async (route, index)=>{
|
|
379
395
|
const { routePath, content, filepath } = route;
|
|
380
396
|
if (filepath) {
|
|
381
|
-
const
|
|
382
|
-
this.addRoute(
|
|
397
|
+
const routeMeta = this.#generateRouteMeta(routePath, filepath);
|
|
398
|
+
this.addRoute(routeMeta);
|
|
383
399
|
return;
|
|
384
400
|
}
|
|
385
401
|
if (content) {
|
|
386
402
|
const filepath = await this.#writeTempFile(index, content);
|
|
387
|
-
const
|
|
388
|
-
this.addRoute(
|
|
403
|
+
const routeMeta = this.#generateRouteMeta(routePath, filepath);
|
|
404
|
+
this.addRoute(routeMeta);
|
|
389
405
|
}
|
|
390
406
|
}));
|
|
391
407
|
await this.#pluginDriver.routeGenerated(this.getRoutes());
|
|
392
408
|
}
|
|
393
|
-
addRoute(
|
|
394
|
-
const { routePath
|
|
395
|
-
if (this.routeData.has(routePath)) {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
if (-1 !== currRouteExtIndex && (currRouteExtIndex < preRouteExtIndex || -1 === preRouteExtIndex)) this.routeData.set(routePath, routeInfo);
|
|
399
|
-
} else this.routeData.set(routePath, routeInfo);
|
|
409
|
+
async addRoute(routeMeta) {
|
|
410
|
+
const { routePath } = routeMeta;
|
|
411
|
+
if (this.routeData.has(routePath)) throw new Error(`routePath ${routePath} has already been added`);
|
|
412
|
+
const routePage = RoutePage.create(routeMeta);
|
|
413
|
+
this.routeData.set(routePath, routePage);
|
|
400
414
|
}
|
|
401
415
|
removeRoute(filePath) {
|
|
402
|
-
const fileRelativePath =
|
|
416
|
+
const fileRelativePath = node_path.relative(this.#scanDir, filePath);
|
|
403
417
|
const { routePath } = this.normalizeRoutePath(fileRelativePath);
|
|
404
418
|
this.routeData.delete(routePath);
|
|
405
419
|
}
|
|
406
420
|
getRoutes() {
|
|
421
|
+
return Array.from(this.routeData.values()).map((i)=>i.routeMeta);
|
|
422
|
+
}
|
|
423
|
+
getRoutePages() {
|
|
407
424
|
return Array.from(this.routeData.values());
|
|
408
425
|
}
|
|
409
426
|
isExistRoute(routePath) {
|
|
410
427
|
const { routePath: normalizedRoute } = this.normalizeRoutePath(routePath);
|
|
411
428
|
return Boolean(this.routeData.get(normalizedRoute));
|
|
412
429
|
}
|
|
413
|
-
isEmpty() {
|
|
414
|
-
return 0 === this.routeData.size;
|
|
415
|
-
}
|
|
416
430
|
generateRoutesCode() {
|
|
417
431
|
return this.generateRoutesCodeByRouteMeta(this.getRoutes());
|
|
418
432
|
}
|
|
@@ -440,48 +454,30 @@ ${routeMeta.map((route, index)=>{
|
|
|
440
454
|
return normalizeRoutePath(routePath, this.#base, this.#defaultLang, this.#defaultVersion, this.#langs, this.#versions, this.#extensions);
|
|
441
455
|
}
|
|
442
456
|
async #writeTempFile(index, content) {
|
|
443
|
-
const tempFilePath =
|
|
444
|
-
await
|
|
457
|
+
const tempFilePath = node_path.join(this.#tempDir, `temp-${index}.mdx`);
|
|
458
|
+
await node_fs_promises.writeFile(tempFilePath, content);
|
|
445
459
|
return tempFilePath;
|
|
446
460
|
}
|
|
447
|
-
#
|
|
461
|
+
#generateRouteMeta(routePath, filepath) {
|
|
448
462
|
const { routePath: normalizedPath, lang, version } = this.normalizeRoutePath(routePath);
|
|
449
463
|
return {
|
|
450
464
|
routePath: normalizedPath,
|
|
451
465
|
absolutePath: normalizePath(filepath),
|
|
452
|
-
relativePath: normalizePath(
|
|
466
|
+
relativePath: normalizePath(node_path.relative(this.#scanDir, filepath)),
|
|
453
467
|
pageName: getPageKey(routePath),
|
|
454
468
|
lang,
|
|
455
469
|
version
|
|
456
470
|
};
|
|
457
471
|
}
|
|
472
|
+
getRoutePageByRoutePath(routePath) {
|
|
473
|
+
return this.routeData.get(routePath);
|
|
474
|
+
}
|
|
458
475
|
}
|
|
459
|
-
let init_routeService = null;
|
|
460
|
-
async function initRouteService(options) {
|
|
461
|
-
const { scanDir, config, runtimeTempDir, pluginDriver } = options;
|
|
462
|
-
init_routeService = new RouteService(scanDir, config, runtimeTempDir, pluginDriver);
|
|
463
|
-
await init_routeService.init();
|
|
464
|
-
await pluginDriver.routeServiceGenerated(init_routeService);
|
|
465
|
-
return init_routeService;
|
|
466
|
-
}
|
|
467
|
-
function createHash_createHash(str) {
|
|
468
|
-
return createHash('sha256').update(str).digest('hex').slice(0, 8);
|
|
469
|
-
}
|
|
470
|
-
var types_RuntimeModuleID = /*#__PURE__*/ function(RuntimeModuleID) {
|
|
471
|
-
RuntimeModuleID["GlobalStyles"] = "virtual-global-styles";
|
|
472
|
-
RuntimeModuleID["GlobalComponents"] = "virtual-global-components";
|
|
473
|
-
RuntimeModuleID["Routes"] = "virtual-routes";
|
|
474
|
-
RuntimeModuleID["SiteData"] = "virtual-site-data";
|
|
475
|
-
RuntimeModuleID["SearchIndexHash"] = "virtual-search-index-hash";
|
|
476
|
-
RuntimeModuleID["I18nText"] = "virtual-i18n-text";
|
|
477
|
-
RuntimeModuleID["SearchHooks"] = "virtual-search-hooks";
|
|
478
|
-
return RuntimeModuleID;
|
|
479
|
-
}({});
|
|
480
476
|
let flattenMdxContent_resolver;
|
|
481
477
|
let startFlatten = false;
|
|
482
478
|
const processor = createProcessor();
|
|
483
|
-
const { CachedInputFileSystem, ResolverFactory } =
|
|
484
|
-
const fileSystem =
|
|
479
|
+
const { CachedInputFileSystem, ResolverFactory } = enhanced_resolve;
|
|
480
|
+
const fileSystem = node_fs;
|
|
485
481
|
async function resolveDepPath(importPath, importer, alias) {
|
|
486
482
|
if (!flattenMdxContent_resolver) flattenMdxContent_resolver = ResolverFactory.createResolver({
|
|
487
483
|
fileSystem: new CachedInputFileSystem(fileSystem, 0),
|
|
@@ -538,12 +534,12 @@ async function flattenMdxContent(content, basePath, alias) {
|
|
|
538
534
|
const importPath = importNode.source.value;
|
|
539
535
|
let absoluteImportPath;
|
|
540
536
|
try {
|
|
541
|
-
absoluteImportPath = await resolveDepPath(importPath,
|
|
537
|
+
absoluteImportPath = await resolveDepPath(importPath, node_path.dirname(basePath), alias);
|
|
542
538
|
} catch (_e) {
|
|
543
539
|
continue;
|
|
544
540
|
}
|
|
545
541
|
if (MDX_OR_MD_REGEXP.test(absoluteImportPath)) {
|
|
546
|
-
const importedContent =
|
|
542
|
+
const importedContent = node_fs.readFileSync(absoluteImportPath, 'utf-8');
|
|
547
543
|
const { flattenContent: replacedValue, deps: subDeps } = await flattenMdxContent(importedContent, absoluteImportPath, alias);
|
|
548
544
|
result = result.replace(new RegExp(`import\\s+${id}\\s+from\\s+['"](${importPath})['"];?`), '').replace(new RegExp(`<${id}\\s*/>`, 'g'), ()=>replacedValue);
|
|
549
545
|
deps.push(...subDeps, absoluteImportPath);
|
|
@@ -564,105 +560,119 @@ function applyReplaceRulesToNestedObject(obj, replaceRules) {
|
|
|
564
560
|
else if ('object' == typeof obj[key] && null !== obj[key]) obj[key] = applyReplaceRulesToNestedObject(obj[key], replaceRules);
|
|
565
561
|
return obj;
|
|
566
562
|
}
|
|
567
|
-
async function
|
|
568
|
-
const
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
563
|
+
async function getPageIndexInfoByRoute(route, options) {
|
|
564
|
+
const { alias, domain, replaceRules, root, searchCodeBlocks } = options;
|
|
565
|
+
const defaultIndexInfo = {
|
|
566
|
+
title: '',
|
|
567
|
+
content: '',
|
|
568
|
+
_html: '',
|
|
569
|
+
_flattenContent: '',
|
|
570
|
+
routePath: route.routePath,
|
|
571
|
+
lang: route.lang,
|
|
572
|
+
toc: [],
|
|
573
|
+
domain,
|
|
574
|
+
frontmatter: {},
|
|
575
|
+
version: route.version,
|
|
576
|
+
_filepath: route.absolutePath,
|
|
577
|
+
_relativePath: node_path.relative(root, route.absolutePath).split(node_path.sep).join('/')
|
|
578
|
+
};
|
|
579
|
+
if (!MDX_OR_MD_REGEXP.test(route.absolutePath)) return defaultIndexInfo;
|
|
580
|
+
let content = await node_fs_promises.readFile(route.absolutePath, 'utf8');
|
|
581
|
+
const { frontmatter, content: contentWithoutFrontMatter } = loadFrontMatter(content, route.absolutePath, root);
|
|
582
|
+
applyReplaceRulesToNestedObject(frontmatter, replaceRules);
|
|
583
|
+
const { flattenContent } = await flattenMdxContent(applyReplaceRules(contentWithoutFrontMatter, replaceRules), route.absolutePath, alias);
|
|
584
|
+
content = flattenContent.replace(importStatementRegex, '');
|
|
585
|
+
const { html: rawHtml, title, toc: rawToc } = await compile({
|
|
586
|
+
value: content,
|
|
587
|
+
filepath: route.absolutePath,
|
|
588
|
+
development: 'production' !== process.env.NODE_ENV,
|
|
589
|
+
root
|
|
590
|
+
});
|
|
591
|
+
function encodeHtml(html) {
|
|
592
|
+
return html.replace(/<code>([\s\S]*?)<\/\s?code>/gm, function(_match, innerContent) {
|
|
593
|
+
return `<code>${innerContent.replace(/&/g, '&').replace(/"/g, '"').replace(/'/g, ''').replace(/</g, '<').replace(/>/g, '>')}</code>`;
|
|
595
594
|
});
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
595
|
+
}
|
|
596
|
+
const html = encodeHtml(String(rawHtml));
|
|
597
|
+
content = htmlToText(html, {
|
|
598
|
+
wordwrap: 80,
|
|
599
|
+
selectors: [
|
|
600
|
+
{
|
|
601
|
+
selector: 'a',
|
|
602
|
+
options: {
|
|
603
|
+
ignoreHref: true
|
|
604
|
+
}
|
|
605
|
+
},
|
|
606
|
+
{
|
|
607
|
+
selector: 'img',
|
|
608
|
+
format: 'skip'
|
|
609
|
+
},
|
|
610
|
+
{
|
|
611
|
+
selector: 'pre > code',
|
|
612
|
+
format: searchCodeBlocks ? 'block' : 'skip'
|
|
613
|
+
},
|
|
614
|
+
...[
|
|
615
|
+
'h1',
|
|
616
|
+
'h2',
|
|
617
|
+
'h3',
|
|
618
|
+
'h4',
|
|
619
|
+
'h5',
|
|
620
|
+
'h6'
|
|
621
|
+
].map((tag)=>({
|
|
622
|
+
selector: tag,
|
|
607
623
|
options: {
|
|
608
|
-
|
|
624
|
+
uppercase: false
|
|
609
625
|
}
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
'h6'
|
|
626
|
-
].map((tag)=>({
|
|
627
|
-
selector: tag,
|
|
628
|
-
options: {
|
|
629
|
-
uppercase: false
|
|
630
|
-
}
|
|
631
|
-
}))
|
|
632
|
-
],
|
|
633
|
-
tables: true,
|
|
634
|
-
longWordSplit: {
|
|
635
|
-
forceWrapOnLimit: true
|
|
636
|
-
}
|
|
637
|
-
});
|
|
638
|
-
if (content.startsWith(title)) content = content.slice(title.length);
|
|
639
|
-
const toc = rawToc.map((item)=>{
|
|
640
|
-
const match = item.id.match(/-(\d+)$/);
|
|
641
|
-
let position = -1;
|
|
642
|
-
if (match) for(let i = 0; i < Number(match[1]); i++){
|
|
643
|
-
position = content.indexOf(`\n${item.text}#\n\n`, position + 1);
|
|
644
|
-
if (-1 === position) break;
|
|
645
|
-
}
|
|
646
|
-
return {
|
|
647
|
-
...item,
|
|
648
|
-
charIndex: content.indexOf(`\n${item.text}#\n\n`, position + 1)
|
|
649
|
-
};
|
|
650
|
-
});
|
|
626
|
+
}))
|
|
627
|
+
],
|
|
628
|
+
tables: true,
|
|
629
|
+
longWordSplit: {
|
|
630
|
+
forceWrapOnLimit: true
|
|
631
|
+
}
|
|
632
|
+
});
|
|
633
|
+
if (content.startsWith(title)) content = content.slice(title.length);
|
|
634
|
+
const toc = rawToc.map((item)=>{
|
|
635
|
+
const match = item.id.match(/-(\d+)$/);
|
|
636
|
+
let position = -1;
|
|
637
|
+
if (match) for(let i = 0; i < Number(match[1]); i++){
|
|
638
|
+
position = content.indexOf(`\n${item.text}#\n\n`, position + 1);
|
|
639
|
+
if (-1 === position) break;
|
|
640
|
+
}
|
|
651
641
|
return {
|
|
652
|
-
...
|
|
653
|
-
|
|
654
|
-
toc,
|
|
655
|
-
content,
|
|
656
|
-
_flattenContent: flattenContent,
|
|
657
|
-
_html: html,
|
|
658
|
-
frontmatter: {
|
|
659
|
-
...frontmatter,
|
|
660
|
-
__content: void 0
|
|
661
|
-
}
|
|
642
|
+
...item,
|
|
643
|
+
charIndex: content.indexOf(`\n${item.text}#\n\n`, position + 1)
|
|
662
644
|
};
|
|
663
|
-
})
|
|
664
|
-
return
|
|
645
|
+
});
|
|
646
|
+
return {
|
|
647
|
+
...defaultIndexInfo,
|
|
648
|
+
title: frontmatter.title || title,
|
|
649
|
+
toc,
|
|
650
|
+
content,
|
|
651
|
+
_html: html,
|
|
652
|
+
_flattenContent: flattenContent,
|
|
653
|
+
frontmatter: {
|
|
654
|
+
...frontmatter,
|
|
655
|
+
__content: void 0
|
|
656
|
+
}
|
|
657
|
+
};
|
|
658
|
+
}
|
|
659
|
+
async function extractPageData(routeService, options) {
|
|
660
|
+
const pageData = await Promise.all(routeService.getRoutes().map((routeMeta)=>getPageIndexInfoByRoute(routeMeta, options)));
|
|
661
|
+
return pageData;
|
|
665
662
|
}
|
|
663
|
+
function createHash_createHash(str) {
|
|
664
|
+
return createHash('sha256').update(str).digest('hex').slice(0, 8);
|
|
665
|
+
}
|
|
666
|
+
var types_RuntimeModuleID = /*#__PURE__*/ function(RuntimeModuleID) {
|
|
667
|
+
RuntimeModuleID["GlobalStyles"] = "virtual-global-styles";
|
|
668
|
+
RuntimeModuleID["GlobalComponents"] = "virtual-global-components";
|
|
669
|
+
RuntimeModuleID["Routes"] = "virtual-routes";
|
|
670
|
+
RuntimeModuleID["SiteData"] = "virtual-site-data";
|
|
671
|
+
RuntimeModuleID["SearchIndexHash"] = "virtual-search-index-hash";
|
|
672
|
+
RuntimeModuleID["I18nText"] = "virtual-i18n-text";
|
|
673
|
+
RuntimeModuleID["SearchHooks"] = "virtual-search-hooks";
|
|
674
|
+
return RuntimeModuleID;
|
|
675
|
+
}({});
|
|
666
676
|
const DEFAULT_I18N_SOURCE = join(process.cwd(), 'i18n.json');
|
|
667
677
|
function getI18nData(docConfig) {
|
|
668
678
|
const { i18nSourcePath = DEFAULT_I18N_SOURCE } = docConfig;
|
|
@@ -727,7 +737,7 @@ function normalizeThemeConfig(docConfig, pages = []) {
|
|
|
727
737
|
return {
|
|
728
738
|
text: applyReplaceRules(page?.title || '', replaceRules),
|
|
729
739
|
link: normalizedItem,
|
|
730
|
-
_fileKey: page?._relativePath.replace(
|
|
740
|
+
_fileKey: page?._relativePath.replace(node_path.extname(page._relativePath), '')
|
|
731
741
|
};
|
|
732
742
|
}
|
|
733
743
|
return {
|
|
@@ -805,7 +815,13 @@ async function siteDataVMPlugin(context) {
|
|
|
805
815
|
const searchConfig = userConfig?.search || {};
|
|
806
816
|
const domain = searchConfig?.mode === 'remote' ? searchConfig.domain ?? '' : '';
|
|
807
817
|
const searchCodeBlocks = 'codeBlocks' in searchConfig ? Boolean(searchConfig.codeBlocks) : true;
|
|
808
|
-
const pages = await extractPageData(
|
|
818
|
+
const pages = await extractPageData(routeService, {
|
|
819
|
+
replaceRules,
|
|
820
|
+
alias,
|
|
821
|
+
domain,
|
|
822
|
+
root: userDocRoot,
|
|
823
|
+
searchCodeBlocks
|
|
824
|
+
});
|
|
809
825
|
await pluginDriver.modifySearchIndexData(pages);
|
|
810
826
|
const versioned = userConfig.search && 'remote' !== userConfig.search.mode && userConfig.search.versioned;
|
|
811
827
|
const groupedPages = groupBy(pages, (page)=>{
|
|
@@ -823,10 +839,10 @@ async function siteDataVMPlugin(context) {
|
|
|
823
839
|
const [version, lang] = group.split('###');
|
|
824
840
|
const indexVersion = version ? `.${version.replace('.', '_')}` : '';
|
|
825
841
|
const indexLang = lang ? `.${lang}` : '';
|
|
826
|
-
await
|
|
842
|
+
await node_fs_promises.mkdir(constants_TEMP_DIR, {
|
|
827
843
|
recursive: true
|
|
828
844
|
});
|
|
829
|
-
await
|
|
845
|
+
await node_fs_promises.writeFile(node_path.join(constants_TEMP_DIR, `${SEARCH_INDEX_NAME}${indexVersion}${indexLang}.${indexHash}.json`), stringifiedIndex);
|
|
830
846
|
}));
|
|
831
847
|
await Promise.all(pages.map(async (pageData)=>pluginDriver.extendPageData(pageData)));
|
|
832
848
|
const siteData = {
|
|
@@ -849,7 +865,7 @@ async function siteDataVMPlugin(context) {
|
|
|
849
865
|
mode: 'local'
|
|
850
866
|
},
|
|
851
867
|
pages: pages.map((page)=>{
|
|
852
|
-
const { content,
|
|
868
|
+
const { content, domain, _filepath, _html, _flattenContent, ...rest } = page;
|
|
853
869
|
return isProduction() ? rest : {
|
|
854
870
|
...rest,
|
|
855
871
|
_filepath
|
|
@@ -870,7 +886,6 @@ const runtimeModuleFactory = [
|
|
|
870
886
|
siteDataVMPlugin
|
|
871
887
|
];
|
|
872
888
|
function rsbuildPluginDocVM(factoryContext) {
|
|
873
|
-
const { pluginDriver } = factoryContext;
|
|
874
889
|
return {
|
|
875
890
|
name: 'rsbuild-plugin-doc-vm',
|
|
876
891
|
setup (api) {
|
|
@@ -884,16 +899,20 @@ function rsbuildPluginDocVM(factoryContext) {
|
|
|
884
899
|
});
|
|
885
900
|
Object.assign(runtimeModule, moduleResult);
|
|
886
901
|
}
|
|
887
|
-
const modulesByPlugin = await pluginDriver.addRuntimeModules();
|
|
888
|
-
Object.keys(modulesByPlugin).forEach((key)=>{
|
|
889
|
-
if (runtimeModule[key]) throw new Error(`The runtime module ${key} is duplicated, please check your plugin`);
|
|
890
|
-
runtimeModule[key] = modulesByPlugin[key];
|
|
891
|
-
});
|
|
892
902
|
bundlerChain.plugin('rspress-runtime-module').use(new RspackVirtualModulePlugin(runtimeModule));
|
|
893
903
|
});
|
|
894
904
|
}
|
|
895
905
|
};
|
|
896
906
|
}
|
|
907
|
+
async function getVirtualModulesFromPlugins(pluginDriver) {
|
|
908
|
+
const runtimeModule = {};
|
|
909
|
+
const modulesByPlugin = await pluginDriver.addRuntimeModules();
|
|
910
|
+
Object.keys(modulesByPlugin).forEach((key)=>{
|
|
911
|
+
if (runtimeModule[key]) throw new Error(`The runtime module ${key} is duplicated, please check your plugin`);
|
|
912
|
+
runtimeModule[key] = ()=>modulesByPlugin[key];
|
|
913
|
+
});
|
|
914
|
+
return runtimeModule;
|
|
915
|
+
}
|
|
897
916
|
const globalStylesVMPlugin = (context)=>({
|
|
898
917
|
[types_RuntimeModuleID.GlobalStyles]: ()=>{
|
|
899
918
|
const { config, pluginDriver } = context;
|
|
@@ -946,10 +965,10 @@ const searchHookVMPlugin = (context)=>({
|
|
|
946
965
|
async function writeSearchIndex(config) {
|
|
947
966
|
if (config?.search === false) return;
|
|
948
967
|
const cwd = process.cwd();
|
|
949
|
-
const searchIndexFiles = await
|
|
968
|
+
const searchIndexFiles = await node_fs_promises.readdir(constants_TEMP_DIR);
|
|
950
969
|
const outDir = config?.outDir ?? join(cwd, OUTPUT_DIR);
|
|
951
970
|
const targetDir = join(outDir, 'static');
|
|
952
|
-
await
|
|
971
|
+
await node_fs_promises.mkdir(targetDir, {
|
|
953
972
|
recursive: true
|
|
954
973
|
});
|
|
955
974
|
let searchIndexData = '[]';
|
|
@@ -958,9 +977,9 @@ async function writeSearchIndex(config) {
|
|
|
958
977
|
if (!searchIndexFile.includes(SEARCH_INDEX_NAME) || !searchIndexFile.endsWith('.json')) continue;
|
|
959
978
|
const source = join(constants_TEMP_DIR, searchIndexFile);
|
|
960
979
|
const target = join(targetDir, searchIndexFile);
|
|
961
|
-
const searchIndex = await
|
|
980
|
+
const searchIndex = await node_fs_promises.readFile(join(constants_TEMP_DIR, searchIndexFile), 'utf-8');
|
|
962
981
|
searchIndexData = `${searchIndexData.slice(0, -1)}${scanning ? ',' : ''}${searchIndex.slice(1)}`;
|
|
963
|
-
await
|
|
982
|
+
await node_fs_promises.rename(source, target);
|
|
964
983
|
scanning = true;
|
|
965
984
|
}
|
|
966
985
|
if (isProduction() && isSCM() && config?.search?.mode === 'remote') {
|
|
@@ -973,9 +992,9 @@ async function writeSearchIndex(config) {
|
|
|
973
992
|
'Content-Type': 'application/json'
|
|
974
993
|
}
|
|
975
994
|
});
|
|
976
|
-
logger.info(
|
|
995
|
+
logger.info(picocolors.green(`[doc-tools] Search index uploaded to ${apiUrl}, indexName: ${indexName}`));
|
|
977
996
|
} catch (e) {
|
|
978
|
-
logger.info(
|
|
997
|
+
logger.info(picocolors.red(`[doc-tools] Upload search index \`${indexName}\` failed:\n ${e}`));
|
|
979
998
|
}
|
|
980
999
|
}
|
|
981
1000
|
}
|
|
@@ -1083,15 +1102,6 @@ async function pMap(iterable, mapper, { concurrency = Number.POSITIVE_INFINITY,
|
|
|
1083
1102
|
});
|
|
1084
1103
|
}
|
|
1085
1104
|
const pMapSkip = Symbol('skip');
|
|
1086
|
-
async function renderFrontmatterHead(route) {
|
|
1087
|
-
if (!isRouteMeta(route)) return '';
|
|
1088
|
-
const content = await promises_default.readFile(route.absolutePath, {
|
|
1089
|
-
encoding: 'utf-8'
|
|
1090
|
-
});
|
|
1091
|
-
const { frontmatter: { head } } = loadFrontMatter(content, route.absolutePath, '', true);
|
|
1092
|
-
if (!head || 0 === head.length) return '';
|
|
1093
|
-
return head.map(([tag, attrs])=>`<${tag} ${renderAttrs(attrs)}>`).join('');
|
|
1094
|
-
}
|
|
1095
1105
|
async function renderConfigHead(config, route) {
|
|
1096
1106
|
if (!isRouteMeta(route)) return '';
|
|
1097
1107
|
if (!config.head || 0 === config.head.length) return '';
|
|
@@ -1125,7 +1135,7 @@ async function renderPages(routeService, config, pluginDriver, ssrBundlePath, ht
|
|
|
1125
1135
|
render = await ssrExports.render;
|
|
1126
1136
|
} catch (e) {
|
|
1127
1137
|
if (e instanceof Error) {
|
|
1128
|
-
logger.error(`Failed to load SSG bundle: ${
|
|
1138
|
+
logger.error(`Failed to load SSG bundle: ${picocolors.yellow(ssrBundlePath)}: ${e.message}`);
|
|
1129
1139
|
logger.debug(e);
|
|
1130
1140
|
hintSSGFailed();
|
|
1131
1141
|
}
|
|
@@ -1154,13 +1164,12 @@ async function renderPages(routeService, config, pluginDriver, ssrBundlePath, ht
|
|
|
1154
1164
|
({ appHtml } = await render(routePath, head));
|
|
1155
1165
|
} catch (e) {
|
|
1156
1166
|
if (e instanceof Error) {
|
|
1157
|
-
logger.error(`Page "${
|
|
1167
|
+
logger.error(`Page "${picocolors.yellow(routePath)}" SSG rendering failed.\n ${picocolors.gray(e.toString())}`);
|
|
1158
1168
|
throw e;
|
|
1159
1169
|
}
|
|
1160
1170
|
}
|
|
1161
1171
|
const replacedHtmlTemplate = htmlTemplate.replace(/<title>(.*?)<\/title>/gi, '').replace(APP_HTML_MARKER, ()=>appHtml).replace(META_GENERATOR, ()=>`<meta name="generator" content="Rspress v${RSPRESS_VERSION}">`).replace(HEAD_MARKER, [
|
|
1162
|
-
await renderConfigHead(config, route)
|
|
1163
|
-
await renderFrontmatterHead(route)
|
|
1172
|
+
await renderConfigHead(config, route)
|
|
1164
1173
|
].join(''));
|
|
1165
1174
|
const html = await transformHtmlTemplate(head, replacedHtmlTemplate);
|
|
1166
1175
|
const normalizeHtmlFilePath = (path)=>{
|
|
@@ -1174,7 +1183,7 @@ async function renderPages(routeService, config, pluginDriver, ssrBundlePath, ht
|
|
|
1174
1183
|
concurrency: process.env.RSPRESS_SSG_CONCURRENCY ? Number.parseInt(process.env.RSPRESS_SSG_CONCURRENCY, 10) : 32
|
|
1175
1184
|
});
|
|
1176
1185
|
const totalTime = Date.now() - startTime;
|
|
1177
|
-
logger.success(`Pages rendered in ${
|
|
1186
|
+
logger.success(`Pages rendered in ${picocolors.yellow(totalTime)} ms.`);
|
|
1178
1187
|
} catch (e) {
|
|
1179
1188
|
if (e instanceof Error) {
|
|
1180
1189
|
logger.error(`Pages render error: ${e.message}`);
|
|
@@ -1238,12 +1247,12 @@ const rsbuildPluginSSG = ({ routeService, config, pluginDriver })=>({
|
|
|
1238
1247
|
});
|
|
1239
1248
|
}
|
|
1240
1249
|
});
|
|
1241
|
-
const { CachedInputFileSystem: detectReactVersion_CachedInputFileSystem, ResolverFactory: detectReactVersion_ResolverFactory } =
|
|
1250
|
+
const { CachedInputFileSystem: detectReactVersion_CachedInputFileSystem, ResolverFactory: detectReactVersion_ResolverFactory } = enhanced_resolve;
|
|
1242
1251
|
async function detectPackageMajorVersion(name) {
|
|
1243
1252
|
const cwd = process.cwd();
|
|
1244
|
-
const pkgPath =
|
|
1253
|
+
const pkgPath = node_path.join(cwd, 'node_modules', name);
|
|
1245
1254
|
if (await pathExists(pkgPath)) {
|
|
1246
|
-
const pkgJson = await readJson(
|
|
1255
|
+
const pkgJson = await readJson(node_path.join(pkgPath, 'package.json'));
|
|
1247
1256
|
const version = Number(pkgJson.version?.split('.')[0]);
|
|
1248
1257
|
return version;
|
|
1249
1258
|
}
|
|
@@ -1255,7 +1264,7 @@ async function detectReactVersion() {
|
|
|
1255
1264
|
async function resolveReactRouterDomAlias() {
|
|
1256
1265
|
const alias = {};
|
|
1257
1266
|
const resolver = detectReactVersion_ResolverFactory.createResolver({
|
|
1258
|
-
fileSystem: new detectReactVersion_CachedInputFileSystem(
|
|
1267
|
+
fileSystem: new detectReactVersion_CachedInputFileSystem(node_fs, 0),
|
|
1259
1268
|
mainFields: [
|
|
1260
1269
|
'browser',
|
|
1261
1270
|
'module',
|
|
@@ -1295,7 +1304,7 @@ async function resolveReactAlias(reactVersion, isSSR) {
|
|
|
1295
1304
|
];
|
|
1296
1305
|
const alias = {};
|
|
1297
1306
|
const resolver = detectReactVersion_ResolverFactory.createResolver({
|
|
1298
|
-
fileSystem: new detectReactVersion_CachedInputFileSystem(
|
|
1307
|
+
fileSystem: new detectReactVersion_CachedInputFileSystem(node_fs, 0),
|
|
1299
1308
|
extensions: [
|
|
1300
1309
|
'.js'
|
|
1301
1310
|
],
|
|
@@ -1319,7 +1328,7 @@ async function resolveReactAlias(reactVersion, isSSR) {
|
|
|
1319
1328
|
});
|
|
1320
1329
|
} catch (e) {
|
|
1321
1330
|
if (e instanceof Error) {
|
|
1322
|
-
logger.warn(`${lib} not found: \n ${
|
|
1331
|
+
logger.warn(`${lib} not found: \n ${picocolors.gray(e.toString())}`);
|
|
1323
1332
|
hintReactVersion();
|
|
1324
1333
|
}
|
|
1325
1334
|
}
|
|
@@ -1327,15 +1336,15 @@ async function resolveReactAlias(reactVersion, isSSR) {
|
|
|
1327
1336
|
return alias;
|
|
1328
1337
|
}
|
|
1329
1338
|
const detectCustomIcon = async (customThemeDir)=>{
|
|
1330
|
-
const assetsDir =
|
|
1339
|
+
const assetsDir = node_path.join(customThemeDir, 'assets');
|
|
1331
1340
|
const alias = {};
|
|
1332
1341
|
if (!existsSync(assetsDir)) return alias;
|
|
1333
1342
|
const files = await glob('*.svg', {
|
|
1334
1343
|
cwd: assetsDir
|
|
1335
1344
|
});
|
|
1336
1345
|
files.forEach((file)=>{
|
|
1337
|
-
const name =
|
|
1338
|
-
alias[`@theme-assets/${name}`] =
|
|
1346
|
+
const name = node_path.basename(file, '.svg');
|
|
1347
|
+
alias[`@theme-assets/${name}`] = node_path.join(assetsDir, file);
|
|
1339
1348
|
});
|
|
1340
1349
|
return alias;
|
|
1341
1350
|
};
|
|
@@ -1373,7 +1382,7 @@ function isPluginIncluded(config, pluginName) {
|
|
|
1373
1382
|
}
|
|
1374
1383
|
async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeService, pluginDriver) {
|
|
1375
1384
|
const cwd = process.cwd();
|
|
1376
|
-
const CUSTOM_THEME_DIR = config?.themeDir ??
|
|
1385
|
+
const CUSTOM_THEME_DIR = config?.themeDir ?? node_path.join(process.cwd(), 'theme');
|
|
1377
1386
|
const outDir = config?.outDir ?? OUTPUT_DIR;
|
|
1378
1387
|
const DEFAULT_THEME = require.resolve('@rspress/theme-default');
|
|
1379
1388
|
const base = config?.base ?? '';
|
|
@@ -1383,7 +1392,7 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1383
1392
|
if (!icon) return;
|
|
1384
1393
|
icon = icon.toString();
|
|
1385
1394
|
if (icon.startsWith('file://')) icon = fileURLToPath(icon);
|
|
1386
|
-
else if (
|
|
1395
|
+
else if (node_path.isAbsolute(icon)) return node_path.join(userDocRoot, PUBLIC_DIR, icon);
|
|
1387
1396
|
return icon;
|
|
1388
1397
|
};
|
|
1389
1398
|
await hintThemeBreakingChange(CUSTOM_THEME_DIR);
|
|
@@ -1412,7 +1421,8 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1412
1421
|
...globalUIComponentsVMPlugin(context),
|
|
1413
1422
|
...globalStylesVMPlugin(context),
|
|
1414
1423
|
...searchHookVMPlugin(context),
|
|
1415
|
-
...routeListVMPlugin(context)
|
|
1424
|
+
...routeListVMPlugin(context),
|
|
1425
|
+
...await getVirtualModulesFromPlugins(pluginDriver)
|
|
1416
1426
|
}
|
|
1417
1427
|
}),
|
|
1418
1428
|
...enableSSG ? [
|
|
@@ -1427,7 +1437,7 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1427
1437
|
port: !isProduction() && process.env.PORT ? Number(process.env.PORT) : void 0,
|
|
1428
1438
|
printUrls: ({ urls })=>urls.map((url)=>`${url}/${removeLeadingSlash(base)}`),
|
|
1429
1439
|
publicDir: {
|
|
1430
|
-
name:
|
|
1440
|
+
name: node_path.join(userDocRoot, PUBLIC_DIR)
|
|
1431
1441
|
}
|
|
1432
1442
|
},
|
|
1433
1443
|
dev: {
|
|
@@ -1468,7 +1478,7 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1468
1478
|
CUSTOM_THEME_DIR,
|
|
1469
1479
|
DEFAULT_THEME
|
|
1470
1480
|
],
|
|
1471
|
-
'@theme-assets':
|
|
1481
|
+
'@theme-assets': node_path.join(DEFAULT_THEME, '../assets'),
|
|
1472
1482
|
'@rspress/core': PACKAGE_ROOT,
|
|
1473
1483
|
'react-lazy-with-preload': require.resolve('react-lazy-with-preload')
|
|
1474
1484
|
}
|
|
@@ -1476,7 +1486,7 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1476
1486
|
source: {
|
|
1477
1487
|
include: [
|
|
1478
1488
|
PACKAGE_ROOT,
|
|
1479
|
-
|
|
1489
|
+
node_path.join(cwd, 'node_modules', RSPRESS_TEMP_DIR)
|
|
1480
1490
|
],
|
|
1481
1491
|
define: {
|
|
1482
1492
|
'process.env.TEST': JSON.stringify(process.env.TEST),
|
|
@@ -1542,7 +1552,7 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1542
1552
|
index: enableSSG && isProduction() ? SSR_CLIENT_ENTRY : CSR_CLIENT_ENTRY
|
|
1543
1553
|
},
|
|
1544
1554
|
preEntry: [
|
|
1545
|
-
|
|
1555
|
+
node_path.join(DEFAULT_THEME, '../styles/index.js'),
|
|
1546
1556
|
'virtual-global-styles'
|
|
1547
1557
|
],
|
|
1548
1558
|
define: {
|
|
@@ -1596,14 +1606,14 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1596
1606
|
}
|
|
1597
1607
|
async function initRsbuild(rootDir, config, pluginDriver, enableSSG, extraRsbuildConfig) {
|
|
1598
1608
|
const cwd = process.cwd();
|
|
1599
|
-
const userDocRoot =
|
|
1609
|
+
const userDocRoot = node_path.resolve(rootDir || config?.root || cwd);
|
|
1600
1610
|
const builderPlugins = config?.builderPlugins ?? [];
|
|
1601
|
-
const runtimeTempDir =
|
|
1602
|
-
const runtimeAbsTempDir =
|
|
1603
|
-
await
|
|
1611
|
+
const runtimeTempDir = node_path.join(RSPRESS_TEMP_DIR, 'runtime');
|
|
1612
|
+
const runtimeAbsTempDir = node_path.join(cwd, 'node_modules', runtimeTempDir);
|
|
1613
|
+
await node_fs_promises.mkdir(runtimeAbsTempDir, {
|
|
1604
1614
|
recursive: true
|
|
1605
1615
|
});
|
|
1606
|
-
const routeService = await
|
|
1616
|
+
const routeService = await RouteService.create({
|
|
1607
1617
|
config,
|
|
1608
1618
|
runtimeTempDir: runtimeAbsTempDir,
|
|
1609
1619
|
scanDir: userDocRoot,
|
|
@@ -1619,34 +1629,34 @@ async function initRsbuild(rootDir, config, pluginDriver, enableSSG, extraRsbuil
|
|
|
1619
1629
|
return rsbuild;
|
|
1620
1630
|
}
|
|
1621
1631
|
function checkLanguageParity_normalizePath(filePath) {
|
|
1622
|
-
return filePath.split(
|
|
1632
|
+
return filePath.split(node_path.sep).join('/');
|
|
1623
1633
|
}
|
|
1624
1634
|
async function getAllMarkdownFilesFrom(dirPath) {
|
|
1625
|
-
const files = await
|
|
1635
|
+
const files = await node_fs_promises.readdir(dirPath, {
|
|
1626
1636
|
withFileTypes: true
|
|
1627
1637
|
});
|
|
1628
1638
|
const allFiles = [];
|
|
1629
1639
|
for (const file of files){
|
|
1630
|
-
const fullPath =
|
|
1640
|
+
const fullPath = node_path.join(dirPath, file.name);
|
|
1631
1641
|
if (file.isDirectory()) {
|
|
1632
1642
|
const nestedFiles = await getAllMarkdownFilesFrom(fullPath);
|
|
1633
1643
|
allFiles.push(...nestedFiles);
|
|
1634
1644
|
} else if ([
|
|
1635
1645
|
'.md',
|
|
1636
1646
|
'.mdx'
|
|
1637
|
-
].includes(
|
|
1647
|
+
].includes(node_path.extname(file.name))) allFiles.push(fullPath);
|
|
1638
1648
|
}
|
|
1639
1649
|
return allFiles;
|
|
1640
1650
|
}
|
|
1641
1651
|
async function collectModuleFiles(contentPath, lang, includedDir, excludedDirs, fileLangMap) {
|
|
1642
|
-
const langDirPath =
|
|
1643
|
-
const langModuleDir =
|
|
1652
|
+
const langDirPath = node_path.join(contentPath, lang);
|
|
1653
|
+
const langModuleDir = node_path.join(langDirPath, includedDir);
|
|
1644
1654
|
try {
|
|
1645
|
-
const moduleDirStats = await
|
|
1655
|
+
const moduleDirStats = await node_fs_promises.stat(langModuleDir);
|
|
1646
1656
|
if (!moduleDirStats.isDirectory()) return fileLangMap;
|
|
1647
1657
|
const files = await getAllMarkdownFilesFrom(langModuleDir);
|
|
1648
1658
|
for (const file of files){
|
|
1649
|
-
const relativePath = checkLanguageParity_normalizePath(
|
|
1659
|
+
const relativePath = checkLanguageParity_normalizePath(node_path.relative(langDirPath, file));
|
|
1650
1660
|
if (excludedDirs.some((excludedDir)=>{
|
|
1651
1661
|
const isFilePath = /\.(md|mdx)$/.test(excludedDir);
|
|
1652
1662
|
return relativePath.includes(excludedDir + (isFilePath ? '' : '/'));
|
|
@@ -1664,7 +1674,7 @@ async function collectModuleFiles(contentPath, lang, includedDir, excludedDirs,
|
|
|
1664
1674
|
async function checkLanguageParity(config) {
|
|
1665
1675
|
if (!config?.languageParity || false === config.languageParity.enabled) return;
|
|
1666
1676
|
logger.info('Checking language parity...');
|
|
1667
|
-
const contentPath =
|
|
1677
|
+
const contentPath = node_path.resolve(config.root);
|
|
1668
1678
|
const includedDirs = config.languageParity.include?.length ? config.languageParity.include : [
|
|
1669
1679
|
''
|
|
1670
1680
|
];
|
|
@@ -1680,7 +1690,7 @@ async function checkLanguageParity(config) {
|
|
|
1680
1690
|
for (const [baseName, langs] of Object.entries(curFileLangMap)){
|
|
1681
1691
|
const missingLangs = supportedLanguages.filter((lang)=>!langs.has(lang));
|
|
1682
1692
|
missingLangs.forEach((lang)=>{
|
|
1683
|
-
const missingPath =
|
|
1693
|
+
const missingPath = node_path.join(lang, baseName);
|
|
1684
1694
|
missingLanguagesFile.push(missingPath);
|
|
1685
1695
|
});
|
|
1686
1696
|
}
|
|
@@ -1723,7 +1733,7 @@ async function bundle(docDirectory, config, pluginDriver, enableSSG) {
|
|
|
1723
1733
|
}
|
|
1724
1734
|
}
|
|
1725
1735
|
function emptyDir(path) {
|
|
1726
|
-
return
|
|
1736
|
+
return node_fs_promises.rm(path, {
|
|
1727
1737
|
force: true,
|
|
1728
1738
|
recursive: true
|
|
1729
1739
|
});
|
|
@@ -1793,9 +1803,9 @@ function normalizeLink(nodeUrl, routeService, relativePath, cleanUrls) {
|
|
|
1793
1803
|
if (nodeUrl.startsWith('#')) return `#${nodeUrl.slice(1)}`;
|
|
1794
1804
|
let { url, hash } = parseUrl(nodeUrl);
|
|
1795
1805
|
if (isExternalUrl(url)) return url + (hash ? `#${hash}` : '');
|
|
1796
|
-
const extname =
|
|
1806
|
+
const extname = node_path.extname(url);
|
|
1797
1807
|
if ((routeService?.extensions ?? DEFAULT_PAGE_EXTENSIONS).includes(extname)) url = url.replace(new RegExp(`\\${extname}$`), '');
|
|
1798
|
-
if (url.startsWith('.')) url =
|
|
1808
|
+
if (url.startsWith('.')) url = node_path.posix.join(slash(node_path.dirname(relativePath)), url);
|
|
1799
1809
|
else if (routeService) {
|
|
1800
1810
|
const [pathVersion, pathLang] = routeService.getRoutePathParts(slash(relativePath));
|
|
1801
1811
|
const [urlVersion, urlLang, urlPath] = routeService.getRoutePathParts(url);
|
|
@@ -1819,12 +1829,12 @@ const remarkPluginNormalizeLink = ({ root, cleanUrls, routeService })=>(tree, fi
|
|
|
1819
1829
|
const images = [];
|
|
1820
1830
|
visit(tree, 'link', (node)=>{
|
|
1821
1831
|
const { url: nodeUrl } = node;
|
|
1822
|
-
const relativePath =
|
|
1832
|
+
const relativePath = node_path.relative(root, file.path);
|
|
1823
1833
|
node.url = normalizeLink(nodeUrl, routeService, relativePath, cleanUrls);
|
|
1824
1834
|
});
|
|
1825
1835
|
visit(tree, 'definition', (node)=>{
|
|
1826
1836
|
const { url: nodeUrl } = node;
|
|
1827
|
-
const relativePath =
|
|
1837
|
+
const relativePath = node_path.relative(root, file.path);
|
|
1828
1838
|
node.url = normalizeLink(nodeUrl, routeService, relativePath, cleanUrls);
|
|
1829
1839
|
});
|
|
1830
1840
|
const getMdxSrcAttribute = (tempVar)=>({
|