@rspress/core 2.0.0-beta.22 → 2.0.0-beta.23
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/cli.js +1 -1
- package/dist/index.d.ts +14 -5
- package/dist/index.js +307 -354
- package/dist/loader.d.ts +3 -1
- package/dist/loader.js +3 -4
- package/dist/processor.d.ts +5 -2
- package/dist/processor.js +270 -236
- package/dist/renderPageWorker.js +2 -2
- package/dist/runtime/ssrServerEntry.js +2 -2
- package/dist/shiki-transformers.js +13 -13
- package/package.json +7 -8
package/dist/index.js
CHANGED
|
@@ -15,13 +15,14 @@ import * as __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__ from "node:url";
|
|
|
15
15
|
import * as __WEBPACK_EXTERNAL_MODULE_node_util_1b29d436__ from "node:util";
|
|
16
16
|
import * as __WEBPACK_EXTERNAL_MODULE_path__ from "path";
|
|
17
17
|
import * as __WEBPACK_EXTERNAL_MODULE_stream__ from "stream";
|
|
18
|
+
import { matchPath } from "@rspress/runtime/server";
|
|
19
|
+
import { logger } from "@rspress/shared/logger";
|
|
20
|
+
import { extractTextAndId, getIconUrlPath, getNodeAttribute, loadFrontMatter, mergeDocConfig } from "@rspress/shared/node-utils";
|
|
18
21
|
import node_fs_promises, { mkdir, readFile, readdir, rm, stat as promises_stat, writeFile } from "node:fs/promises";
|
|
19
22
|
import { PLUGIN_REACT_NAME, pluginReact } from "@rsbuild/plugin-react";
|
|
20
23
|
import { DEFAULT_PAGE_EXTENSIONS } from "@rspress/shared/constants";
|
|
21
|
-
import { logger } from "@rspress/shared/logger";
|
|
22
24
|
import picocolors from "picocolors";
|
|
23
25
|
import { glob } from "tinyglobby";
|
|
24
|
-
import { extractTextAndId, getIconUrlPath, getNodeAttribute, loadFrontMatter, mergeDocConfig } from "@rspress/shared/node-utils";
|
|
25
26
|
import { RspackVirtualModulePlugin } from "rspack-plugin-virtual-module";
|
|
26
27
|
import { chunk, groupBy } from "lodash-es";
|
|
27
28
|
import { compile } from "@rspress/mdx-rs";
|
|
@@ -30,9 +31,8 @@ import { createProcessor } from "@mdx-js/mdx";
|
|
|
30
31
|
import enhanced_resolve from "enhanced-resolve";
|
|
31
32
|
import { createHash } from "node:crypto";
|
|
32
33
|
import { createHead, transformHtmlTemplate } from "@unhead/react/server";
|
|
33
|
-
import { mergeRsbuildConfig as core_mergeRsbuildConfig } from "@rsbuild/core";
|
|
34
34
|
import { visit } from "unist-util-visit";
|
|
35
|
-
import {
|
|
35
|
+
import { mergeRsbuildConfig as core_mergeRsbuildConfig } from "@rsbuild/core";
|
|
36
36
|
var __webpack_modules__ = {
|
|
37
37
|
"@rspress/shared": function(module) {
|
|
38
38
|
module.exports = __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__;
|
|
@@ -146,124 +146,39 @@ __webpack_require__.m = __webpack_modules__;
|
|
|
146
146
|
}
|
|
147
147
|
};
|
|
148
148
|
})();
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
#plugins;
|
|
153
|
-
#isProd;
|
|
154
|
-
constructor(config, configFilePath, isProd){
|
|
155
|
-
this.#config = config;
|
|
156
|
-
this.#configFilePath = configFilePath;
|
|
157
|
-
this.#isProd = isProd;
|
|
158
|
-
this.#plugins = [];
|
|
159
|
-
}
|
|
160
|
-
getConfigFilePath() {
|
|
161
|
-
return this.#configFilePath;
|
|
162
|
-
}
|
|
163
|
-
async init() {
|
|
164
|
-
this.clearPlugins();
|
|
165
|
-
const config = this.#config;
|
|
166
|
-
const themeConfig = config?.themeConfig || {};
|
|
167
|
-
const enableLastUpdated = themeConfig?.lastUpdated || themeConfig?.locales?.some((locale)=>locale.lastUpdated);
|
|
168
|
-
const mediumZoomConfig = config?.mediumZoom ?? true;
|
|
169
|
-
if (enableLastUpdated) {
|
|
170
|
-
const { pluginLastUpdated } = await Promise.all([
|
|
171
|
-
__webpack_require__.e("94"),
|
|
172
|
-
__webpack_require__.e("208")
|
|
173
|
-
]).then(__webpack_require__.bind(__webpack_require__, "./src/node/last-updated/index.ts"));
|
|
174
|
-
this.addPlugin(pluginLastUpdated());
|
|
175
|
-
}
|
|
176
|
-
if (mediumZoomConfig) {
|
|
177
|
-
const { pluginMediumZoom } = await __webpack_require__.e("309").then(__webpack_require__.bind(__webpack_require__, "./src/node/medium-zoom/index.ts"));
|
|
178
|
-
this.addPlugin(pluginMediumZoom('object' == typeof mediumZoomConfig ? mediumZoomConfig : void 0));
|
|
179
|
-
}
|
|
180
|
-
(config.plugins || []).forEach((plugin)=>{
|
|
181
|
-
this.addPlugin(plugin);
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
addPlugin(plugin) {
|
|
185
|
-
const existedIndex = this.#plugins.findIndex((item)=>item.name === plugin.name);
|
|
186
|
-
if (-1 !== existedIndex) throw new Error(`The plugin "${plugin.name}" has been registered`);
|
|
187
|
-
this.#plugins.push(plugin);
|
|
188
|
-
}
|
|
189
|
-
getPlugins() {
|
|
190
|
-
return this.#plugins;
|
|
191
|
-
}
|
|
192
|
-
clearPlugins() {
|
|
193
|
-
this.#plugins = [];
|
|
194
|
-
}
|
|
195
|
-
removePlugin(pluginName) {
|
|
196
|
-
const index = this.#plugins.findIndex((item)=>item.name === pluginName);
|
|
197
|
-
if (-1 !== index) this.#plugins.splice(index, 1);
|
|
198
|
-
}
|
|
199
|
-
async modifyConfig() {
|
|
200
|
-
let config = this.#config;
|
|
201
|
-
for(let i = 0; i < this.#plugins.length; i++){
|
|
202
|
-
const plugin = this.#plugins[i];
|
|
203
|
-
if ('function' == typeof plugin.config) config = await plugin.config(config || {}, {
|
|
204
|
-
addPlugin: this.addPlugin.bind(this),
|
|
205
|
-
removePlugin: (pluginName)=>{
|
|
206
|
-
const index = this.#plugins.findIndex((item)=>item.name === pluginName);
|
|
207
|
-
this.removePlugin(pluginName);
|
|
208
|
-
if (index <= i && index > 0) i--;
|
|
209
|
-
}
|
|
210
|
-
}, this.#isProd);
|
|
211
|
-
}
|
|
212
|
-
this.#config = config;
|
|
213
|
-
return this.#config;
|
|
214
|
-
}
|
|
215
|
-
async beforeBuild() {
|
|
216
|
-
return this._runParallelAsyncHook('beforeBuild', this.#config || {}, this.#isProd);
|
|
217
|
-
}
|
|
218
|
-
async afterBuild() {
|
|
219
|
-
return this._runParallelAsyncHook('afterBuild', this.#config || {}, this.#isProd);
|
|
220
|
-
}
|
|
221
|
-
async modifySearchIndexData(pages) {
|
|
222
|
-
return this._runParallelAsyncHook('modifySearchIndexData', pages, this.#isProd);
|
|
223
|
-
}
|
|
224
|
-
async extendPageData(pageData) {
|
|
225
|
-
return this._runParallelAsyncHook('extendPageData', pageData, this.#isProd);
|
|
226
|
-
}
|
|
227
|
-
async addPages() {
|
|
228
|
-
const result = await this._runParallelAsyncHook('addPages', this.#config || {}, this.#isProd);
|
|
229
|
-
return result.flat();
|
|
230
|
-
}
|
|
231
|
-
async routeGenerated(routes) {
|
|
232
|
-
return this._runParallelAsyncHook('routeGenerated', routes, this.#isProd);
|
|
233
|
-
}
|
|
234
|
-
async routeServiceGenerated(routeService) {
|
|
235
|
-
return this._runParallelAsyncHook('routeServiceGenerated', routeService, this.#isProd);
|
|
236
|
-
}
|
|
237
|
-
async addRuntimeModules() {
|
|
238
|
-
const result = await this._runParallelAsyncHook('addRuntimeModules', this.#config || {}, this.#isProd);
|
|
239
|
-
return result.reduce((prev, current)=>({
|
|
240
|
-
...prev,
|
|
241
|
-
...current
|
|
242
|
-
}), {});
|
|
243
|
-
}
|
|
244
|
-
globalUIComponents() {
|
|
245
|
-
const result = this.#plugins.map((plugin)=>plugin.globalUIComponents || []);
|
|
246
|
-
return result.flat();
|
|
247
|
-
}
|
|
248
|
-
globalStyles() {
|
|
249
|
-
return this.#plugins.filter((plugin)=>'string' == typeof plugin.globalStyles).map((plugin)=>plugin.globalStyles);
|
|
250
|
-
}
|
|
251
|
-
_runParallelAsyncHook(hookName, ...args) {
|
|
252
|
-
return Promise.all(this.#plugins.filter((plugin)=>'function' == typeof plugin[hookName]).map((plugin)=>plugin[hookName](...args)));
|
|
253
|
-
}
|
|
254
|
-
_runSerialAsyncHook(hookName, ...args) {
|
|
255
|
-
return this.#plugins.reduce(async (prev, plugin)=>{
|
|
256
|
-
if ('function' == typeof plugin[hookName]) {
|
|
257
|
-
await prev;
|
|
258
|
-
return plugin[hookName](...args);
|
|
259
|
-
}
|
|
260
|
-
return prev;
|
|
261
|
-
}, Promise.resolve());
|
|
262
|
-
}
|
|
149
|
+
var shared_ = __webpack_require__("@rspress/shared");
|
|
150
|
+
function defineConfig(config) {
|
|
151
|
+
return config;
|
|
263
152
|
}
|
|
264
153
|
var external_node_path_ = __webpack_require__("node:path");
|
|
265
154
|
var external_node_url_ = __webpack_require__("node:url");
|
|
266
|
-
var
|
|
155
|
+
var package_namespaceObject = JSON.parse('{"i8":"2.0.0-beta.23"}');
|
|
156
|
+
const RSPRESS_VERSION = package_namespaceObject.i8;
|
|
157
|
+
const isProduction = ()=>'production' === process.env.NODE_ENV;
|
|
158
|
+
const importStatementRegex = /import\s+(.*?)\s+from\s+(['"])(.*?)(?:"|');?/gm;
|
|
159
|
+
const inlineThemeScript = `{
|
|
160
|
+
const saved = localStorage.getItem('${shared_.APPEARANCE_KEY}')
|
|
161
|
+
const preferDark = window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
162
|
+
const isDark = !saved || saved === 'auto' ? preferDark : saved === 'dark'
|
|
163
|
+
document.documentElement.classList.toggle('dark', isDark)
|
|
164
|
+
document.documentElement.classList.toggle('rp-dark', isDark)
|
|
165
|
+
document.documentElement.style.colorScheme = isDark ? 'dark' : 'light'
|
|
166
|
+
}`.replace(/\n/g, ';').replace(/\s{2,}/g, '');
|
|
167
|
+
const dirname = external_node_path_["default"].dirname((0, external_node_url_.fileURLToPath)(new URL(import.meta.url)));
|
|
168
|
+
const PACKAGE_ROOT = external_node_path_["default"].join(dirname, '..');
|
|
169
|
+
const TEMPLATE_PATH = external_node_path_["default"].join(PACKAGE_ROOT, 'index.html');
|
|
170
|
+
const CSR_CLIENT_ENTRY = external_node_path_["default"].join(PACKAGE_ROOT, 'dist', 'runtime', 'csrClientEntry.js');
|
|
171
|
+
const SSR_CLIENT_ENTRY = external_node_path_["default"].join(PACKAGE_ROOT, 'dist', 'runtime', 'ssrClientEntry.js');
|
|
172
|
+
const SSR_SERVER_ENTRY = external_node_path_["default"].join(PACKAGE_ROOT, 'dist', 'runtime', 'ssrServerEntry.js');
|
|
173
|
+
const OUTPUT_DIR = 'doc_build';
|
|
174
|
+
const APP_HTML_MARKER = '<!--<?- DOC_CONTENT ?>-->';
|
|
175
|
+
const HEAD_MARKER = '<!--<?- HEAD ?>-->';
|
|
176
|
+
const META_GENERATOR = '<!--<?- GENERATOR ?>-->';
|
|
177
|
+
const DEFAULT_TITLE = 'Rspress';
|
|
178
|
+
const PUBLIC_DIR = 'public';
|
|
179
|
+
const constants_TEMP_DIR = external_node_path_["default"].join(process.cwd(), 'node_modules', shared_.RSPRESS_TEMP_DIR);
|
|
180
|
+
const NODE_SSG_BUNDLE_FOLDER = '__ssg__';
|
|
181
|
+
const NODE_SSG_BUNDLE_NAME = 'rspress-ssg-entry.cjs';
|
|
267
182
|
const PLUGIN_VIRTUAL_MODULE_NAME = 'rsbuild:virtual-module';
|
|
268
183
|
const pluginVirtualModule = (pluginOptions = {})=>({
|
|
269
184
|
name: PLUGIN_VIRTUAL_MODULE_NAME,
|
|
@@ -403,34 +318,15 @@ function slash(p) {
|
|
|
403
318
|
function normalizePath(id) {
|
|
404
319
|
return external_node_path_["default"].posix.normalize(isWindows ? slash(id) : id);
|
|
405
320
|
}
|
|
406
|
-
var package_namespaceObject = JSON.parse('{"i8":"2.0.0-beta.22"}');
|
|
407
|
-
const RSPRESS_VERSION = package_namespaceObject.i8;
|
|
408
|
-
const isProduction = ()=>'production' === process.env.NODE_ENV;
|
|
409
|
-
const importStatementRegex = /import\s+(.*?)\s+from\s+(['"])(.*?)(?:"|');?/gm;
|
|
410
|
-
const inlineThemeScript = `{
|
|
411
|
-
const saved = localStorage.getItem('${shared_.APPEARANCE_KEY}')
|
|
412
|
-
const preferDark = window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
413
|
-
const isDark = !saved || saved === 'auto' ? preferDark : saved === 'dark'
|
|
414
|
-
document.documentElement.classList.toggle('dark', isDark)
|
|
415
|
-
document.documentElement.classList.toggle('rp-dark', isDark)
|
|
416
|
-
document.documentElement.style.colorScheme = isDark ? 'dark' : 'light'
|
|
417
|
-
}`.replace(/\n/g, ';').replace(/\s{2,}/g, '');
|
|
418
|
-
const dirname = external_node_path_["default"].dirname((0, external_node_url_.fileURLToPath)(new URL(import.meta.url)));
|
|
419
|
-
const PACKAGE_ROOT = external_node_path_["default"].join(dirname, '..');
|
|
420
|
-
const TEMPLATE_PATH = external_node_path_["default"].join(PACKAGE_ROOT, 'index.html');
|
|
421
|
-
const CSR_CLIENT_ENTRY = external_node_path_["default"].join(PACKAGE_ROOT, 'dist', 'runtime', 'csrClientEntry.js');
|
|
422
|
-
const SSR_CLIENT_ENTRY = external_node_path_["default"].join(PACKAGE_ROOT, 'dist', 'runtime', 'ssrClientEntry.js');
|
|
423
|
-
const SSR_SERVER_ENTRY = external_node_path_["default"].join(PACKAGE_ROOT, 'dist', 'runtime', 'ssrServerEntry.js');
|
|
424
|
-
const OUTPUT_DIR = 'doc_build';
|
|
425
|
-
const APP_HTML_MARKER = '<!--<?- DOC_CONTENT ?>-->';
|
|
426
|
-
const HEAD_MARKER = '<!--<?- HEAD ?>-->';
|
|
427
|
-
const META_GENERATOR = '<!--<?- GENERATOR ?>-->';
|
|
428
|
-
const DEFAULT_TITLE = 'Rspress';
|
|
429
|
-
const PUBLIC_DIR = 'public';
|
|
430
|
-
const constants_TEMP_DIR = external_node_path_["default"].join(process.cwd(), 'node_modules', shared_.RSPRESS_TEMP_DIR);
|
|
431
|
-
const NODE_SSG_BUNDLE_FOLDER = '__ssg__';
|
|
432
|
-
const NODE_SSG_BUNDLE_NAME = 'rspress-ssg-entry.cjs';
|
|
433
321
|
const getRoutePathParts = (relativePath, lang, version, langs, versions)=>{
|
|
322
|
+
const [versionPart, langPart, purePath] = splitRoutePathParts(relativePath, lang, version, langs, versions);
|
|
323
|
+
return [
|
|
324
|
+
versionPart === version ? '' : versionPart,
|
|
325
|
+
langPart === lang ? '' : langPart,
|
|
326
|
+
purePath
|
|
327
|
+
];
|
|
328
|
+
};
|
|
329
|
+
const splitRoutePathParts = (relativePath, lang, version, langs, versions)=>{
|
|
434
330
|
const hasTrailSlash = relativePath.endsWith('/');
|
|
435
331
|
let versionPart = '';
|
|
436
332
|
let langPart = '';
|
|
@@ -438,17 +334,11 @@ const getRoutePathParts = (relativePath, lang, version, langs, versions)=>{
|
|
|
438
334
|
const parts = relativePath.split('/').filter(Boolean);
|
|
439
335
|
if (version) {
|
|
440
336
|
const versionToMatch = parts[0];
|
|
441
|
-
if (versions.includes(versionToMatch))
|
|
442
|
-
if (versionToMatch !== version) versionPart = versionToMatch;
|
|
443
|
-
parts.shift();
|
|
444
|
-
}
|
|
337
|
+
if (versions.includes(versionToMatch)) versionPart = parts.shift() ?? '';
|
|
445
338
|
}
|
|
446
339
|
if (lang) {
|
|
447
340
|
const langToMatch = parts[0];
|
|
448
|
-
if (langs.includes(langToMatch))
|
|
449
|
-
if (langToMatch !== lang) langPart = langToMatch;
|
|
450
|
-
parts.shift();
|
|
451
|
-
}
|
|
341
|
+
if (langs.includes(langToMatch)) langPart = parts.shift() ?? '';
|
|
452
342
|
}
|
|
453
343
|
purePathPart = parts.join('/');
|
|
454
344
|
return [
|
|
@@ -461,6 +351,7 @@ const normalizeRoutePath = (relativePath, lang, version, langs, versions, extens
|
|
|
461
351
|
const extensionsWithoutDot = extensions.map((i)=>i.slice(1));
|
|
462
352
|
const cleanExtensionPattern = new RegExp(`\\.(${extensionsWithoutDot.join('|')})$`, 'i');
|
|
463
353
|
let routePath = relativePath.replace(cleanExtensionPattern, '').replace(/\.html$/, '');
|
|
354
|
+
if (routePath.endsWith('/')) routePath = `${routePath}index`;
|
|
464
355
|
const [versionPart, langPart, purePathPart] = getRoutePathParts(routePath, lang, version, langs, versions);
|
|
465
356
|
routePath = purePathPart.replace(/\/index$/, '/');
|
|
466
357
|
if ('index' === routePath) routePath = '';
|
|
@@ -482,13 +373,14 @@ class RouteService {
|
|
|
482
373
|
routeData = new Map();
|
|
483
374
|
#scanDir;
|
|
484
375
|
#defaultLang;
|
|
485
|
-
#defaultVersion
|
|
486
|
-
#extensions
|
|
487
|
-
#langs
|
|
488
|
-
#versions
|
|
489
|
-
#include
|
|
490
|
-
#exclude
|
|
491
|
-
#
|
|
376
|
+
#defaultVersion;
|
|
377
|
+
#extensions;
|
|
378
|
+
#langs;
|
|
379
|
+
#versions;
|
|
380
|
+
#include;
|
|
381
|
+
#exclude;
|
|
382
|
+
#excludeConvention;
|
|
383
|
+
#tempDir;
|
|
492
384
|
#pluginDriver;
|
|
493
385
|
static __instance__ = null;
|
|
494
386
|
static getInstance() {
|
|
@@ -508,6 +400,9 @@ class RouteService {
|
|
|
508
400
|
this.#extensions = routeOptions.extensions || DEFAULT_PAGE_EXTENSIONS;
|
|
509
401
|
this.#include = routeOptions.include || [];
|
|
510
402
|
this.#exclude = routeOptions.exclude || [];
|
|
403
|
+
this.#excludeConvention = routeOptions.excludeConvention || [
|
|
404
|
+
'**/_[^_]*'
|
|
405
|
+
];
|
|
511
406
|
this.#defaultLang = userConfig?.lang || '';
|
|
512
407
|
this.#langs = (userConfig?.locales ?? userConfig?.themeConfig?.locales ?? []).map((item)=>item.lang);
|
|
513
408
|
this.#tempDir = tempDir;
|
|
@@ -515,6 +410,9 @@ class RouteService {
|
|
|
515
410
|
if (userConfig.multiVersion) {
|
|
516
411
|
this.#defaultVersion = userConfig.multiVersion.default || '';
|
|
517
412
|
this.#versions = userConfig.multiVersion.versions || [];
|
|
413
|
+
} else {
|
|
414
|
+
this.#defaultVersion = '';
|
|
415
|
+
this.#versions = [];
|
|
518
416
|
}
|
|
519
417
|
}
|
|
520
418
|
get extensions() {
|
|
@@ -531,10 +429,12 @@ class RouteService {
|
|
|
531
429
|
onlyFiles: true,
|
|
532
430
|
ignore: [
|
|
533
431
|
...this.#exclude,
|
|
432
|
+
...this.#excludeConvention,
|
|
534
433
|
'**/node_modules/**',
|
|
535
434
|
'**/.eslintrc.js',
|
|
536
435
|
'**/.nx/**',
|
|
537
|
-
`./${PUBLIC_DIR}
|
|
436
|
+
`./${PUBLIC_DIR}/**`,
|
|
437
|
+
'**/*.d.ts'
|
|
538
438
|
]
|
|
539
439
|
})).sort();
|
|
540
440
|
files.forEach((filePath)=>{
|
|
@@ -594,12 +494,19 @@ ${routeMeta.map((route, index)=>{
|
|
|
594
494
|
getRoutePathParts(relativePath) {
|
|
595
495
|
return getRoutePathParts(relativePath, this.#defaultLang, this.#defaultVersion, this.#langs, this.#versions);
|
|
596
496
|
}
|
|
497
|
+
splitRoutePathParts(relativePath) {
|
|
498
|
+
return splitRoutePathParts(relativePath, this.#defaultLang, this.#defaultVersion, this.#langs, this.#versions);
|
|
499
|
+
}
|
|
597
500
|
normalizeRoutePath(relativePath) {
|
|
598
501
|
return normalizeRoutePath(relativePath, this.#defaultLang, this.#defaultVersion, this.#langs, this.#versions, this.#extensions);
|
|
599
502
|
}
|
|
600
503
|
absolutePathToRoutePath(absolutePath) {
|
|
601
504
|
return absolutePathToRoutePath(absolutePath, this.#scanDir, this);
|
|
602
505
|
}
|
|
506
|
+
isInDocsDir(absolutePath) {
|
|
507
|
+
const relativePath = external_node_path_["default"].relative(this.#scanDir, absolutePath);
|
|
508
|
+
return !relativePath.startsWith('..') && !external_node_path_["default"].isAbsolute(relativePath);
|
|
509
|
+
}
|
|
603
510
|
absolutePathToRelativePath(absolutePath) {
|
|
604
511
|
return absolutePathToRelativePath(absolutePath, this.#scanDir);
|
|
605
512
|
}
|
|
@@ -894,7 +801,7 @@ async function scanNav(workDir, docsDir) {
|
|
|
894
801
|
const rootNavJson = external_node_path_["default"].resolve(workDir, '_nav.json');
|
|
895
802
|
try {
|
|
896
803
|
navConfig = await utils_readJson(rootNavJson);
|
|
897
|
-
} catch (
|
|
804
|
+
} catch (_e) {
|
|
898
805
|
logger.error('[auto-nav-sidebar]', `Generate nav meta error: ${rootNavJson} failed`);
|
|
899
806
|
navConfig = [];
|
|
900
807
|
}
|
|
@@ -1378,7 +1285,7 @@ async function siteDataVMPlugin(context) {
|
|
|
1378
1285
|
mode: 'local'
|
|
1379
1286
|
},
|
|
1380
1287
|
pages: pages.map((page)=>{
|
|
1381
|
-
const { content, _filepath, _html, _flattenContent, ...rest } = page;
|
|
1288
|
+
const { content: _content, _filepath, _html, _flattenContent, ...rest } = page;
|
|
1382
1289
|
return isProduction() ? rest : {
|
|
1383
1290
|
...rest,
|
|
1384
1291
|
_filepath
|
|
@@ -2171,14 +2078,12 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
2171
2078
|
const isServer = 'node' === target;
|
|
2172
2079
|
const jsModuleRule = chain.module.rule(CHAIN_ID.RULE.JS);
|
|
2173
2080
|
const swcLoaderOptions = jsModuleRule.use(CHAIN_ID.USE.SWC).get('options');
|
|
2174
|
-
const checkDeadLinks = (config?.markdown?.checkDeadLinks && !isServer) ?? false;
|
|
2175
2081
|
chain.module.rule('MDX').type("javascript/auto").test(shared_.MDX_OR_MD_REGEXP).resolve.merge({
|
|
2176
2082
|
conditionNames: jsModuleRule.resolve.conditionNames.values(),
|
|
2177
2083
|
mainFields: jsModuleRule.resolve.mainFields.values()
|
|
2178
2084
|
}).end().oneOf('MDXCompile').use('builtin:swc-loader').loader('builtin:swc-loader').options(swcLoaderOptions).end().use('mdx-loader').loader(require.resolve('./loader.js')).options({
|
|
2179
2085
|
config,
|
|
2180
2086
|
docDirectory: userDocRoot,
|
|
2181
|
-
checkDeadLinks,
|
|
2182
2087
|
routeService,
|
|
2183
2088
|
pluginDriver
|
|
2184
2089
|
}).end();
|
|
@@ -2283,6 +2188,121 @@ async function initRsbuild(rootDir, config, pluginDriver, enableSSG, extraRsbuil
|
|
|
2283
2188
|
});
|
|
2284
2189
|
return rsbuild;
|
|
2285
2190
|
}
|
|
2191
|
+
class PluginDriver {
|
|
2192
|
+
#config;
|
|
2193
|
+
#configFilePath;
|
|
2194
|
+
#plugins;
|
|
2195
|
+
#isProd;
|
|
2196
|
+
constructor(config, configFilePath, isProd){
|
|
2197
|
+
this.#config = config;
|
|
2198
|
+
this.#configFilePath = configFilePath;
|
|
2199
|
+
this.#isProd = isProd;
|
|
2200
|
+
this.#plugins = [];
|
|
2201
|
+
}
|
|
2202
|
+
getConfigFilePath() {
|
|
2203
|
+
return this.#configFilePath;
|
|
2204
|
+
}
|
|
2205
|
+
async init() {
|
|
2206
|
+
this.clearPlugins();
|
|
2207
|
+
const config = this.#config;
|
|
2208
|
+
const themeConfig = config?.themeConfig || {};
|
|
2209
|
+
const enableLastUpdated = themeConfig?.lastUpdated || themeConfig?.locales?.some((locale)=>locale.lastUpdated);
|
|
2210
|
+
const mediumZoomConfig = config?.mediumZoom ?? true;
|
|
2211
|
+
if (enableLastUpdated) {
|
|
2212
|
+
const { pluginLastUpdated } = await Promise.all([
|
|
2213
|
+
__webpack_require__.e("94"),
|
|
2214
|
+
__webpack_require__.e("208")
|
|
2215
|
+
]).then(__webpack_require__.bind(__webpack_require__, "./src/node/last-updated/index.ts"));
|
|
2216
|
+
this.addPlugin(pluginLastUpdated());
|
|
2217
|
+
}
|
|
2218
|
+
if (mediumZoomConfig) {
|
|
2219
|
+
const { pluginMediumZoom } = await __webpack_require__.e("309").then(__webpack_require__.bind(__webpack_require__, "./src/node/medium-zoom/index.ts"));
|
|
2220
|
+
this.addPlugin(pluginMediumZoom('object' == typeof mediumZoomConfig ? mediumZoomConfig : void 0));
|
|
2221
|
+
}
|
|
2222
|
+
(config.plugins || []).forEach((plugin)=>{
|
|
2223
|
+
this.addPlugin(plugin);
|
|
2224
|
+
});
|
|
2225
|
+
}
|
|
2226
|
+
addPlugin(plugin) {
|
|
2227
|
+
const existedIndex = this.#plugins.findIndex((item)=>item.name === plugin.name);
|
|
2228
|
+
if (-1 !== existedIndex) throw new Error(`The plugin "${plugin.name}" has been registered`);
|
|
2229
|
+
this.#plugins.push(plugin);
|
|
2230
|
+
}
|
|
2231
|
+
getPlugins() {
|
|
2232
|
+
return this.#plugins;
|
|
2233
|
+
}
|
|
2234
|
+
clearPlugins() {
|
|
2235
|
+
this.#plugins = [];
|
|
2236
|
+
}
|
|
2237
|
+
removePlugin(pluginName) {
|
|
2238
|
+
const index = this.#plugins.findIndex((item)=>item.name === pluginName);
|
|
2239
|
+
if (-1 !== index) this.#plugins.splice(index, 1);
|
|
2240
|
+
}
|
|
2241
|
+
async modifyConfig() {
|
|
2242
|
+
let config = this.#config;
|
|
2243
|
+
for(let i = 0; i < this.#plugins.length; i++){
|
|
2244
|
+
const plugin = this.#plugins[i];
|
|
2245
|
+
if ('function' == typeof plugin.config) config = await plugin.config(config || {}, {
|
|
2246
|
+
addPlugin: this.addPlugin.bind(this),
|
|
2247
|
+
removePlugin: (pluginName)=>{
|
|
2248
|
+
const index = this.#plugins.findIndex((item)=>item.name === pluginName);
|
|
2249
|
+
this.removePlugin(pluginName);
|
|
2250
|
+
if (index <= i && index > 0) i--;
|
|
2251
|
+
}
|
|
2252
|
+
}, this.#isProd);
|
|
2253
|
+
}
|
|
2254
|
+
this.#config = config;
|
|
2255
|
+
return this.#config;
|
|
2256
|
+
}
|
|
2257
|
+
async beforeBuild() {
|
|
2258
|
+
return this._runParallelAsyncHook('beforeBuild', this.#config || {}, this.#isProd);
|
|
2259
|
+
}
|
|
2260
|
+
async afterBuild() {
|
|
2261
|
+
return this._runParallelAsyncHook('afterBuild', this.#config || {}, this.#isProd);
|
|
2262
|
+
}
|
|
2263
|
+
async modifySearchIndexData(pages) {
|
|
2264
|
+
return this._runParallelAsyncHook('modifySearchIndexData', pages, this.#isProd);
|
|
2265
|
+
}
|
|
2266
|
+
async extendPageData(pageData) {
|
|
2267
|
+
return this._runParallelAsyncHook('extendPageData', pageData, this.#isProd);
|
|
2268
|
+
}
|
|
2269
|
+
async addPages() {
|
|
2270
|
+
const result = await this._runParallelAsyncHook('addPages', this.#config || {}, this.#isProd);
|
|
2271
|
+
return result.flat();
|
|
2272
|
+
}
|
|
2273
|
+
async routeGenerated(routes) {
|
|
2274
|
+
return this._runParallelAsyncHook('routeGenerated', routes, this.#isProd);
|
|
2275
|
+
}
|
|
2276
|
+
async routeServiceGenerated(routeService) {
|
|
2277
|
+
return this._runParallelAsyncHook('routeServiceGenerated', routeService, this.#isProd);
|
|
2278
|
+
}
|
|
2279
|
+
async addRuntimeModules() {
|
|
2280
|
+
const result = await this._runParallelAsyncHook('addRuntimeModules', this.#config || {}, this.#isProd);
|
|
2281
|
+
return result.reduce((prev, current)=>({
|
|
2282
|
+
...prev,
|
|
2283
|
+
...current
|
|
2284
|
+
}), {});
|
|
2285
|
+
}
|
|
2286
|
+
globalUIComponents() {
|
|
2287
|
+
const result = this.#plugins.map((plugin)=>plugin.globalUIComponents || []);
|
|
2288
|
+
return result.flat();
|
|
2289
|
+
}
|
|
2290
|
+
globalStyles() {
|
|
2291
|
+
return this.#plugins.filter((plugin)=>'string' == typeof plugin.globalStyles).map((plugin)=>plugin.globalStyles);
|
|
2292
|
+
}
|
|
2293
|
+
_runParallelAsyncHook(hookName, ...args) {
|
|
2294
|
+
return Promise.all(this.#plugins.filter((plugin)=>'function' == typeof plugin[hookName]).map((plugin)=>plugin[hookName](...args)));
|
|
2295
|
+
}
|
|
2296
|
+
_runSerialAsyncHook(hookName, ...args) {
|
|
2297
|
+
return this.#plugins.reduce(async (prev, plugin)=>{
|
|
2298
|
+
if ('function' == typeof plugin[hookName]) {
|
|
2299
|
+
await prev;
|
|
2300
|
+
return plugin[hookName](...args);
|
|
2301
|
+
}
|
|
2302
|
+
return prev;
|
|
2303
|
+
}, Promise.resolve());
|
|
2304
|
+
}
|
|
2305
|
+
}
|
|
2286
2306
|
function checkLanguageParity_normalizePath(filePath) {
|
|
2287
2307
|
return filePath.split(external_node_path_["default"].sep).join('/');
|
|
2288
2308
|
}
|
|
@@ -2357,27 +2377,6 @@ async function checkLanguageParity(config) {
|
|
|
2357
2377
|
throw err;
|
|
2358
2378
|
}
|
|
2359
2379
|
}
|
|
2360
|
-
async function dev(options) {
|
|
2361
|
-
const { docDirectory, config, extraBuilderConfig, configFilePath } = options;
|
|
2362
|
-
const isProd = false;
|
|
2363
|
-
const pluginDriver = new PluginDriver(config, configFilePath, isProd);
|
|
2364
|
-
await pluginDriver.init();
|
|
2365
|
-
const modifiedConfig = await pluginDriver.modifyConfig();
|
|
2366
|
-
try {
|
|
2367
|
-
const rsbuild = await initRsbuild(docDirectory, modifiedConfig, pluginDriver, false, extraBuilderConfig);
|
|
2368
|
-
await pluginDriver.beforeBuild();
|
|
2369
|
-
rsbuild.onDevCompileDone(async ()=>{
|
|
2370
|
-
await pluginDriver.afterBuild();
|
|
2371
|
-
});
|
|
2372
|
-
const { server } = await rsbuild.startDevServer({
|
|
2373
|
-
getPortSilently: true
|
|
2374
|
-
});
|
|
2375
|
-
return server;
|
|
2376
|
-
} finally{
|
|
2377
|
-
await writeSearchIndex(modifiedConfig);
|
|
2378
|
-
await checkLanguageParity(modifiedConfig);
|
|
2379
|
-
}
|
|
2380
|
-
}
|
|
2381
2380
|
async function bundle(docDirectory, config, pluginDriver, enableSSG) {
|
|
2382
2381
|
try {
|
|
2383
2382
|
const rsbuild = await initRsbuild(docDirectory, config, pluginDriver, enableSSG);
|
|
@@ -2405,60 +2404,93 @@ async function build(options) {
|
|
|
2405
2404
|
await bundle(docDirectory, modifiedConfig, pluginDriver, ssgConfig);
|
|
2406
2405
|
if (!ssgConfig) hintSSGFalse();
|
|
2407
2406
|
}
|
|
2408
|
-
async function
|
|
2409
|
-
const {
|
|
2410
|
-
const
|
|
2411
|
-
const
|
|
2412
|
-
const { builderConfig } = config;
|
|
2413
|
-
const port = Number(envPort || userPort || builderConfig?.server?.port || 4173);
|
|
2414
|
-
const host = envHost || userHost || builderConfig?.server?.host || 'localhost';
|
|
2415
|
-
config.builderConfig = core_mergeRsbuildConfig(builderConfig, {
|
|
2416
|
-
server: {
|
|
2417
|
-
port,
|
|
2418
|
-
host
|
|
2419
|
-
}
|
|
2420
|
-
});
|
|
2421
|
-
const pluginDriver = new PluginDriver(config, configFilePath, true);
|
|
2407
|
+
async function dev(options) {
|
|
2408
|
+
const { docDirectory, config, extraBuilderConfig, configFilePath } = options;
|
|
2409
|
+
const isProd = false;
|
|
2410
|
+
const pluginDriver = new PluginDriver(config, configFilePath, isProd);
|
|
2422
2411
|
await pluginDriver.init();
|
|
2423
2412
|
const modifiedConfig = await pluginDriver.modifyConfig();
|
|
2424
|
-
|
|
2425
|
-
|
|
2413
|
+
try {
|
|
2414
|
+
const rsbuild = await initRsbuild(docDirectory, modifiedConfig, pluginDriver, false, extraBuilderConfig);
|
|
2415
|
+
await pluginDriver.beforeBuild();
|
|
2416
|
+
rsbuild.onDevCompileDone(async ()=>{
|
|
2417
|
+
await pluginDriver.afterBuild();
|
|
2418
|
+
});
|
|
2419
|
+
const { server } = await rsbuild.startDevServer({
|
|
2420
|
+
getPortSilently: true
|
|
2421
|
+
});
|
|
2422
|
+
return server;
|
|
2423
|
+
} finally{
|
|
2424
|
+
await writeSearchIndex(modifiedConfig);
|
|
2425
|
+
await checkLanguageParity(modifiedConfig);
|
|
2426
|
+
}
|
|
2426
2427
|
}
|
|
2427
|
-
const
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2428
|
+
const ERROR_PREFIX = '[remarkFileCodeBlock]';
|
|
2429
|
+
function parseFileFromMeta(meta) {
|
|
2430
|
+
if (!meta) return '';
|
|
2431
|
+
const kvList = meta.split(' ').filter(Boolean);
|
|
2432
|
+
for (const item of kvList){
|
|
2433
|
+
const [k, v = ''] = item.split('=');
|
|
2434
|
+
if ('file' === k && v.length > 0) return v.replace(/["'`]/g, '');
|
|
2435
|
+
}
|
|
2436
|
+
return '';
|
|
2437
|
+
}
|
|
2438
|
+
const remarkFileCodeBlock = ({ filepath, addDependency })=>async (tree)=>{
|
|
2439
|
+
const promiseList = [];
|
|
2440
|
+
visit(tree, 'code', (node)=>{
|
|
2441
|
+
const { meta, value, lang } = node;
|
|
2442
|
+
const file = parseFileFromMeta(meta ?? '');
|
|
2443
|
+
if (!file) return;
|
|
2444
|
+
const originalMetaForErrorInfo = picocolors.cyan(`\`\`\`${lang} ${meta}`);
|
|
2445
|
+
if (file.startsWith('./') || file.startsWith('../')) {
|
|
2446
|
+
const resolvedFilePath = external_node_path_["default"].join(external_node_path_["default"].dirname(filepath), file);
|
|
2447
|
+
if ('' !== value.trim()) {
|
|
2448
|
+
logger.error(`${ERROR_PREFIX} ${originalMetaForErrorInfo} The content of file code block should be empty.
|
|
2449
|
+
|
|
2450
|
+
\`\`\`tsx file="./filename"
|
|
2451
|
+
content
|
|
2452
|
+
\`\`\`
|
|
2453
|
+
|
|
2454
|
+
this usage is not allowed, please use below:
|
|
2455
|
+
|
|
2456
|
+
\`\`\`tsx file="./filename"
|
|
2457
|
+
\`\`\`
|
|
2458
|
+
`);
|
|
2459
|
+
throw new Error(`${ERROR_PREFIX} ${originalMetaForErrorInfo} The content of file code block should be empty.`);
|
|
2460
|
+
}
|
|
2461
|
+
const promise = readFile(resolvedFilePath, 'utf-8').then((fileContent)=>{
|
|
2462
|
+
addDependency?.(resolvedFilePath);
|
|
2463
|
+
node.value = fileContent;
|
|
2464
|
+
}).catch((e)=>{
|
|
2465
|
+
const message = `${ERROR_PREFIX} ${originalMetaForErrorInfo} introduces another file in "${resolvedFilePath}", but the file does not exist.`;
|
|
2466
|
+
logger.error(message);
|
|
2467
|
+
e.message = `${message}\n${e.message}`;
|
|
2468
|
+
throw e;
|
|
2469
|
+
});
|
|
2470
|
+
promiseList.push(promise);
|
|
2471
|
+
return;
|
|
2453
2472
|
}
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2473
|
+
logger.error(`${ERROR_PREFIX} ${originalMetaForErrorInfo} syntax error of file code block:
|
|
2474
|
+
Please use below:
|
|
2475
|
+
|
|
2476
|
+
\`\`\`tsx file="./filename"
|
|
2477
|
+
\`\`\`
|
|
2478
|
+
`);
|
|
2479
|
+
throw new Error(`${ERROR_PREFIX} ${originalMetaForErrorInfo} syntax error of file code block`);
|
|
2480
|
+
});
|
|
2481
|
+
await Promise.all(promiseList);
|
|
2482
|
+
};
|
|
2483
|
+
function link_checkDeadLinks(checkDeadLinks, internalLinks, filePath, routeService) {
|
|
2457
2484
|
const errorInfos = [];
|
|
2485
|
+
const excludes = 'object' == typeof checkDeadLinks ? checkDeadLinks.excludes : void 0;
|
|
2486
|
+
const excludesUrl = Array.isArray(excludes) ? new Set(excludes) : void 0;
|
|
2487
|
+
const excludesFn = 'function' == typeof excludes ? excludes : void 0;
|
|
2458
2488
|
let possibleBreakingChange = false;
|
|
2459
2489
|
[
|
|
2460
2490
|
...internalLinks.entries()
|
|
2461
2491
|
].forEach(([nodeUrl, link])=>{
|
|
2492
|
+
if (excludesUrl?.has(nodeUrl)) return;
|
|
2493
|
+
if (excludesFn?.(nodeUrl)) return;
|
|
2462
2494
|
const cleanLinkPath = linkToRoutePath(link);
|
|
2463
2495
|
if (!cleanLinkPath) return;
|
|
2464
2496
|
if (!nodeUrl.startsWith('/') && /^\w/.test(nodeUrl)) possibleBreakingChange = true;
|
|
@@ -2474,13 +2506,31 @@ ${errorInfos.map(([nodeUrl, link])=>` ${picocolors.green(`"[..](${nodeUrl})"`)}
|
|
|
2474
2506
|
if ((0, shared_.isProduction)()) throw new Error('Dead link found');
|
|
2475
2507
|
}
|
|
2476
2508
|
}
|
|
2477
|
-
function
|
|
2509
|
+
function looseMarkdownLink(url, routeService, filePath) {
|
|
2510
|
+
if (!routeService.isInDocsDir(filePath)) return url;
|
|
2511
|
+
const [versionPart, langPart, pureRoute] = routeService.splitRoutePathParts(url);
|
|
2512
|
+
const relativePath = routeService.absolutePathToRelativePath(filePath);
|
|
2513
|
+
const [versionPartCurrFile, langPartCurrFile] = routeService.getRoutePathParts(relativePath);
|
|
2514
|
+
if ('' === versionPart) {
|
|
2515
|
+
if ('' === langPart) return (0, shared_.addLeadingSlash)(`${[
|
|
2516
|
+
versionPartCurrFile,
|
|
2517
|
+
langPartCurrFile
|
|
2518
|
+
].filter(Boolean).join('/')}${(0, shared_.addLeadingSlash)(pureRoute.replace(/^\/*/, ''))}`);
|
|
2519
|
+
return (0, shared_.addLeadingSlash)(`${[
|
|
2520
|
+
versionPartCurrFile,
|
|
2521
|
+
langPart
|
|
2522
|
+
].filter(Boolean).join('/')}${(0, shared_.addLeadingSlash)(pureRoute.replace(/^\/*/, ''))}`);
|
|
2523
|
+
}
|
|
2524
|
+
return url;
|
|
2525
|
+
}
|
|
2526
|
+
function normalizeLink(nodeUrl, routeService, filePath, cleanUrls, autoPrefix, internalLinks, __base) {
|
|
2478
2527
|
if (!nodeUrl) return '';
|
|
2479
2528
|
if (nodeUrl.startsWith('#')) return nodeUrl;
|
|
2480
2529
|
let { url, hash } = (0, shared_.parseUrl)(nodeUrl);
|
|
2481
2530
|
if ((0, shared_.isExternalUrl)(url)) return url + (hash ? `#${hash}` : '');
|
|
2482
2531
|
if (!routeService) return nodeUrl;
|
|
2483
2532
|
if (url.startsWith('/')) {
|
|
2533
|
+
if (autoPrefix) url = looseMarkdownLink(url, routeService, filePath);
|
|
2484
2534
|
const { routePath } = routeService.normalizeRoutePath(url);
|
|
2485
2535
|
url = routePath;
|
|
2486
2536
|
} else {
|
|
@@ -2500,136 +2550,39 @@ function normalizeLink(nodeUrl, routeService, filePath, cleanUrls, internalLinks
|
|
|
2500
2550
|
function linkToRoutePath(routePath) {
|
|
2501
2551
|
return decodeURIComponent(routePath.split('#')[0]).replace(/\.html$/, '').replace(/\/index$/, '/');
|
|
2502
2552
|
}
|
|
2503
|
-
const
|
|
2504
|
-
|
|
2505
|
-
return imageUrl;
|
|
2506
|
-
};
|
|
2507
|
-
const remarkPluginNormalizeLink = ({ cleanUrls, routeService, checkDeadLinks: shouldCheckDeadLinks = false, __base })=>(tree, file)=>{
|
|
2553
|
+
const remarkLink = ({ cleanUrls, routeService, remarkLinkOptions, __base })=>(tree, file)=>{
|
|
2554
|
+
const { checkDeadLinks: shouldCheckDeadLinks = true, autoPrefix = true } = remarkLinkOptions ?? {};
|
|
2508
2555
|
const internalLinks = new Map();
|
|
2509
2556
|
visit(tree, 'link', (node)=>{
|
|
2510
2557
|
const { url: nodeUrl } = node;
|
|
2511
|
-
const link = normalizeLink(nodeUrl, routeService, file.path, cleanUrls, internalLinks, __base);
|
|
2558
|
+
const link = normalizeLink(nodeUrl, routeService, file.path, cleanUrls, autoPrefix, internalLinks, __base);
|
|
2512
2559
|
node.url = link;
|
|
2513
2560
|
});
|
|
2514
2561
|
visit(tree, 'definition', (node)=>{
|
|
2515
2562
|
const { url: nodeUrl } = node;
|
|
2516
|
-
const link = normalizeLink(nodeUrl, routeService, file.path, cleanUrls, internalLinks, __base);
|
|
2563
|
+
const link = normalizeLink(nodeUrl, routeService, file.path, cleanUrls, autoPrefix, internalLinks, __base);
|
|
2517
2564
|
node.url = link;
|
|
2518
2565
|
});
|
|
2519
|
-
if (shouldCheckDeadLinks && routeService)
|
|
2520
|
-
const images = [];
|
|
2521
|
-
const getMdxSrcAttribute = (tempVar)=>({
|
|
2522
|
-
type: 'mdxJsxAttribute',
|
|
2523
|
-
name: 'src',
|
|
2524
|
-
value: {
|
|
2525
|
-
type: 'mdxJsxAttributeValueExpression',
|
|
2526
|
-
value: tempVar,
|
|
2527
|
-
data: {
|
|
2528
|
-
estree: {
|
|
2529
|
-
type: 'Program',
|
|
2530
|
-
sourceType: 'module',
|
|
2531
|
-
body: [
|
|
2532
|
-
{
|
|
2533
|
-
type: 'ExpressionStatement',
|
|
2534
|
-
expression: {
|
|
2535
|
-
type: 'Identifier',
|
|
2536
|
-
name: tempVar
|
|
2537
|
-
}
|
|
2538
|
-
}
|
|
2539
|
-
]
|
|
2540
|
-
}
|
|
2541
|
-
}
|
|
2542
|
-
}
|
|
2543
|
-
});
|
|
2544
|
-
visit(tree, 'image', (node)=>{
|
|
2545
|
-
const { alt, url } = node;
|
|
2546
|
-
if (!url) return;
|
|
2547
|
-
const imagePath = normalizeImageUrl(url);
|
|
2548
|
-
if (!imagePath) return;
|
|
2549
|
-
const tempVariableName = `image${images.length}`;
|
|
2550
|
-
Object.assign(node, {
|
|
2551
|
-
type: 'mdxJsxFlowElement',
|
|
2552
|
-
name: 'img',
|
|
2553
|
-
children: [],
|
|
2554
|
-
attributes: [
|
|
2555
|
-
alt && {
|
|
2556
|
-
type: 'mdxJsxAttribute',
|
|
2557
|
-
name: 'alt',
|
|
2558
|
-
value: alt
|
|
2559
|
-
},
|
|
2560
|
-
getMdxSrcAttribute(tempVariableName)
|
|
2561
|
-
].filter(Boolean)
|
|
2562
|
-
});
|
|
2563
|
-
images.push(getASTNodeImport(tempVariableName, imagePath));
|
|
2564
|
-
});
|
|
2565
|
-
visit(tree, (node)=>{
|
|
2566
|
-
if ('mdxJsxFlowElement' !== node.type && 'mdxJsxTextElement' !== node.type || 'img' !== node.name) return;
|
|
2567
|
-
const srcAttr = getNodeAttribute(node, 'src', true);
|
|
2568
|
-
if ('string' != typeof srcAttr?.value) return;
|
|
2569
|
-
const imagePath = normalizeImageUrl(srcAttr.value);
|
|
2570
|
-
if (!imagePath) return;
|
|
2571
|
-
const tempVariableName = `image${images.length}`;
|
|
2572
|
-
Object.assign(srcAttr, getMdxSrcAttribute(tempVariableName));
|
|
2573
|
-
images.push(getASTNodeImport(tempVariableName, imagePath));
|
|
2574
|
-
});
|
|
2575
|
-
tree.children.unshift(...images);
|
|
2576
|
-
};
|
|
2577
|
-
const ERROR_PREFIX = '[remarkFileCodeBlock]';
|
|
2578
|
-
function parseFileFromMeta(meta) {
|
|
2579
|
-
if (!meta) return '';
|
|
2580
|
-
const kvList = meta.split(' ').filter(Boolean);
|
|
2581
|
-
for (const item of kvList){
|
|
2582
|
-
const [k, v = ''] = item.split('=');
|
|
2583
|
-
if ('file' === k && v.length > 0) return v.replace(/["'`]/g, '');
|
|
2584
|
-
}
|
|
2585
|
-
return '';
|
|
2586
|
-
}
|
|
2587
|
-
const remarkFileCodeBlock = ({ filepath })=>async (tree)=>{
|
|
2588
|
-
const promiseList = [];
|
|
2589
|
-
visit(tree, 'code', (node)=>{
|
|
2590
|
-
const { meta, value, lang } = node;
|
|
2591
|
-
const file = parseFileFromMeta(meta ?? '');
|
|
2592
|
-
if (!file) return;
|
|
2593
|
-
const originalMetaForErrorInfo = picocolors.cyan(`\`\`\`${lang} ${meta}`);
|
|
2594
|
-
if (file.startsWith('./') || file.startsWith('../')) {
|
|
2595
|
-
const resolvedFilePath = external_node_path_["default"].join(external_node_path_["default"].dirname(filepath), file);
|
|
2596
|
-
if ('' !== value.trim()) {
|
|
2597
|
-
logger.error(`${ERROR_PREFIX} ${originalMetaForErrorInfo} The content of file code block should be empty.
|
|
2598
|
-
|
|
2599
|
-
\`\`\`tsx file="./filename"
|
|
2600
|
-
content
|
|
2601
|
-
\`\`\`
|
|
2602
|
-
|
|
2603
|
-
this usage is not allowed, please use below:
|
|
2604
|
-
|
|
2605
|
-
\`\`\`tsx file="./filename"
|
|
2606
|
-
\`\`\`
|
|
2607
|
-
`);
|
|
2608
|
-
throw new Error(`${ERROR_PREFIX} ${originalMetaForErrorInfo} The content of file code block should be empty.`);
|
|
2609
|
-
}
|
|
2610
|
-
const promise = readFile(resolvedFilePath, 'utf-8').then((fileContent)=>{
|
|
2611
|
-
node.value = fileContent;
|
|
2612
|
-
}).catch((e)=>{
|
|
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}`;
|
|
2616
|
-
throw e;
|
|
2617
|
-
});
|
|
2618
|
-
promiseList.push(promise);
|
|
2619
|
-
return;
|
|
2620
|
-
}
|
|
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`);
|
|
2628
|
-
});
|
|
2629
|
-
await Promise.all(promiseList);
|
|
2566
|
+
if (shouldCheckDeadLinks && routeService) link_checkDeadLinks(shouldCheckDeadLinks, internalLinks, file.path, routeService);
|
|
2630
2567
|
};
|
|
2631
|
-
function
|
|
2632
|
-
|
|
2568
|
+
async function serve(options) {
|
|
2569
|
+
const { config, port: userPort, host: userHost, configFilePath } = options;
|
|
2570
|
+
const envPort = process.env.PORT;
|
|
2571
|
+
const envHost = process.env.HOST;
|
|
2572
|
+
const { builderConfig } = config;
|
|
2573
|
+
const port = Number(envPort || userPort || builderConfig?.server?.port || 4173);
|
|
2574
|
+
const host = envHost || userHost || builderConfig?.server?.host || 'localhost';
|
|
2575
|
+
config.builderConfig = core_mergeRsbuildConfig(builderConfig, {
|
|
2576
|
+
server: {
|
|
2577
|
+
port,
|
|
2578
|
+
host
|
|
2579
|
+
}
|
|
2580
|
+
});
|
|
2581
|
+
const pluginDriver = new PluginDriver(config, configFilePath, true);
|
|
2582
|
+
await pluginDriver.init();
|
|
2583
|
+
const modifiedConfig = await pluginDriver.modifyConfig();
|
|
2584
|
+
const rsbuild = await initRsbuild(config.root, modifiedConfig, pluginDriver, false);
|
|
2585
|
+
return rsbuild.preview();
|
|
2633
2586
|
}
|
|
2634
2587
|
var __webpack_exports__RSPRESS_TEMP_DIR = shared_.RSPRESS_TEMP_DIR;
|
|
2635
2588
|
var __webpack_exports__getSidebarDataGroup = shared_.getSidebarDataGroup;
|
|
@@ -2637,4 +2590,4 @@ var __webpack_exports__normalizeHref = shared_.normalizeHref;
|
|
|
2637
2590
|
var __webpack_exports__normalizePosixPath = shared_.normalizePosixPath;
|
|
2638
2591
|
var __webpack_exports__removeTrailingSlash = shared_.removeTrailingSlash;
|
|
2639
2592
|
var __webpack_exports__withBase = shared_.withBase;
|
|
2640
|
-
export { build, defineConfig, dev, getIconUrlPath, getNodeAttribute, logger, matchPath, mergeDocConfig, remarkFileCodeBlock,
|
|
2593
|
+
export { build, defineConfig, dev, getIconUrlPath, getNodeAttribute, logger, matchPath, mergeDocConfig, remarkFileCodeBlock, remarkLink, 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 };
|