@rspress/core 2.0.0-beta.31 → 2.0.0-beta.32
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/101.js +16 -16
- package/dist/cli.js +3 -2
- package/dist/index.d.ts +2 -29
- package/dist/index.js +182 -163
- package/dist/loader.d.ts +5 -3
- package/dist/processor.d.ts +5 -3
- package/dist/renderPageWorker.js +2 -3
- package/package.json +8 -9
package/dist/101.js
CHANGED
|
@@ -542,21 +542,6 @@ export const __webpack_modules__ = {
|
|
|
542
542
|
};
|
|
543
543
|
const node_modules_onetime = onetime_onetime;
|
|
544
544
|
var external_node_os_ = __webpack_require__("node:os");
|
|
545
|
-
const getRealtimeSignals = ()=>{
|
|
546
|
-
const length = SIGRTMAX - SIGRTMIN + 1;
|
|
547
|
-
return Array.from({
|
|
548
|
-
length
|
|
549
|
-
}, getRealtimeSignal);
|
|
550
|
-
};
|
|
551
|
-
const getRealtimeSignal = (value, index)=>({
|
|
552
|
-
name: `SIGRT${index + 1}`,
|
|
553
|
-
number: SIGRTMIN + index,
|
|
554
|
-
action: "terminate",
|
|
555
|
-
description: "Application-specific signal (realtime)",
|
|
556
|
-
standard: "posix"
|
|
557
|
-
});
|
|
558
|
-
const SIGRTMIN = 34;
|
|
559
|
-
const SIGRTMAX = 64;
|
|
560
545
|
const SIGNALS = [
|
|
561
546
|
{
|
|
562
547
|
name: "SIGHUP",
|
|
@@ -828,6 +813,21 @@ export const __webpack_modules__ = {
|
|
|
828
813
|
standard: "other"
|
|
829
814
|
}
|
|
830
815
|
];
|
|
816
|
+
const getRealtimeSignals = ()=>{
|
|
817
|
+
const length = SIGRTMAX - SIGRTMIN + 1;
|
|
818
|
+
return Array.from({
|
|
819
|
+
length
|
|
820
|
+
}, getRealtimeSignal);
|
|
821
|
+
};
|
|
822
|
+
const getRealtimeSignal = (value, index)=>({
|
|
823
|
+
name: `SIGRT${index + 1}`,
|
|
824
|
+
number: SIGRTMIN + index,
|
|
825
|
+
action: "terminate",
|
|
826
|
+
description: "Application-specific signal (realtime)",
|
|
827
|
+
standard: "posix"
|
|
828
|
+
});
|
|
829
|
+
const SIGRTMIN = 34;
|
|
830
|
+
const SIGRTMAX = 64;
|
|
831
831
|
const getSignals = ()=>{
|
|
832
832
|
const realtimeSignals = getRealtimeSignals();
|
|
833
833
|
const signals = [
|
|
@@ -869,7 +869,7 @@ export const __webpack_modules__ = {
|
|
|
869
869
|
const signalsByName = getSignalsByName();
|
|
870
870
|
const getSignalsByNumber = ()=>{
|
|
871
871
|
const signals = getSignals();
|
|
872
|
-
const length =
|
|
872
|
+
const length = 65;
|
|
873
873
|
const signalsA = Array.from({
|
|
874
874
|
length
|
|
875
875
|
}, (value, number)=>getSignalByNumber(number, signals));
|
package/dist/cli.js
CHANGED
|
@@ -6,7 +6,7 @@ import picocolors from "picocolors";
|
|
|
6
6
|
import { build, dev, serve } from "./index.js";
|
|
7
7
|
import node_fs from "node:fs";
|
|
8
8
|
import { DEFAULT_CONFIG_EXTENSIONS, DEFAULT_CONFIG_NAME } from "@rspress/shared/constants";
|
|
9
|
-
var package_namespaceObject = JSON.parse('{"rE":"2.0.0-beta.
|
|
9
|
+
var package_namespaceObject = JSON.parse('{"rE":"2.0.0-beta.32"}');
|
|
10
10
|
const findConfig = (basePath)=>DEFAULT_CONFIG_EXTENSIONS.map((ext)=>basePath + ext).find(node_fs.existsSync);
|
|
11
11
|
async function loadConfigFile(customConfigFile) {
|
|
12
12
|
const baseDir = process.cwd();
|
|
@@ -85,7 +85,8 @@ cli.command('[root]', 'start dev server').alias('dev').option('--port [port]', '
|
|
|
85
85
|
});
|
|
86
86
|
cliWatcher.on('all', async (eventName, filepath)=>{
|
|
87
87
|
const basename = node_path.basename(filepath);
|
|
88
|
-
if ('
|
|
88
|
+
if ('change' === eventName && META_FILES.includes(basename)) return;
|
|
89
|
+
if ('add' === eventName || 'unlink' === eventName || 'change' === eventName && CONFIG_FILES.includes(basename)) {
|
|
89
90
|
if (isRestarting) return;
|
|
90
91
|
isRestarting = true;
|
|
91
92
|
console.log(`
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { AdditionalPage } from '@rspress/shared';
|
|
2
2
|
import type { Data as Data_2 } from 'unist';
|
|
3
|
-
import { DefaultThemeConfig } from '@rspress/shared';
|
|
4
3
|
import { getIconUrlPath } from '@rspress/shared/node-utils';
|
|
5
4
|
import { getNodeAttribute } from '@rspress/shared/node-utils';
|
|
6
5
|
import { getSidebarDataGroup } from '@rspress/shared';
|
|
@@ -79,8 +78,7 @@ export { getSidebarDataGroup }
|
|
|
79
78
|
declare interface InitOptions {
|
|
80
79
|
scanDir: string;
|
|
81
80
|
config: UserConfig;
|
|
82
|
-
|
|
83
|
-
pluginDriver: PluginDriver;
|
|
81
|
+
externalPages: AdditionalPage[];
|
|
84
82
|
}
|
|
85
83
|
|
|
86
84
|
export { logger }
|
|
@@ -133,30 +131,6 @@ declare interface Parent extends Node_2 {
|
|
|
133
131
|
children: RootContent[];
|
|
134
132
|
}
|
|
135
133
|
|
|
136
|
-
declare class PluginDriver {
|
|
137
|
-
#private;
|
|
138
|
-
constructor(config: UserConfig, configFilePath: string, isProd: boolean);
|
|
139
|
-
getConfigFilePath(): string;
|
|
140
|
-
init(): Promise<void>;
|
|
141
|
-
addPlugin(plugin: RspressPlugin): void;
|
|
142
|
-
getPlugins(): RspressPlugin[];
|
|
143
|
-
clearPlugins(): void;
|
|
144
|
-
removePlugin(pluginName: string): void;
|
|
145
|
-
modifyConfig(): Promise<UserConfig<DefaultThemeConfig>>;
|
|
146
|
-
beforeBuild(): Promise<void[]>;
|
|
147
|
-
afterBuild(): Promise<void[]>;
|
|
148
|
-
modifySearchIndexData(pages: PageIndexInfo[]): Promise<void[]>;
|
|
149
|
-
extendPageData(pageData: PageIndexInfo): Promise<void[]>;
|
|
150
|
-
addPages(): Promise<AdditionalPage[]>;
|
|
151
|
-
routeGenerated(routes: RouteMeta[]): Promise<void[]>;
|
|
152
|
-
routeServiceGenerated(routeService: RouteService): Promise<void[]>;
|
|
153
|
-
addRuntimeModules(): Promise<Record<string, string>>;
|
|
154
|
-
globalUIComponents(): (string | [string, object])[];
|
|
155
|
-
globalStyles(): string[];
|
|
156
|
-
_runParallelAsyncHook<H extends RspressPluginHookKeys>(hookName: H, ...args: Parameters<Required<RspressPlugin>[H]>): Promise<Awaited<ReturnType<Required<RspressPlugin>[H]>>[]>;
|
|
157
|
-
_runSerialAsyncHook<H extends RspressPluginHookKeys>(hookName: H, ...args: Parameters<Required<RspressPlugin>[H]>): RspressPlugin;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
134
|
export declare const remarkFileCodeBlock: Plugin_2<[
|
|
161
135
|
{
|
|
162
136
|
filepath: string;
|
|
@@ -226,6 +200,7 @@ export declare class RouteService {
|
|
|
226
200
|
static __instance__: RouteService | null;
|
|
227
201
|
static getInstance(): RouteService;
|
|
228
202
|
static create(options: InitOptions): Promise<RouteService>;
|
|
203
|
+
static createSimple(): Promise<RouteService>;
|
|
229
204
|
private constructor();
|
|
230
205
|
get extensions(): readonly string[];
|
|
231
206
|
addRoute(routePage: RoutePage): Promise<void>;
|
|
@@ -252,8 +227,6 @@ export { RSPRESS_TEMP_DIR }
|
|
|
252
227
|
|
|
253
228
|
export { RspressPlugin }
|
|
254
229
|
|
|
255
|
-
declare type RspressPluginHookKeys = 'beforeBuild' | 'config' | 'afterBuild' | 'addPages' | 'addRuntimeModules' | 'routeGenerated' | 'routeServiceGenerated' | 'extendPageData' | 'modifySearchIndexData';
|
|
256
|
-
|
|
257
230
|
export declare function serve(options: ServeOptions): Promise<ReturnType<RsbuildInstance['preview']>>;
|
|
258
231
|
|
|
259
232
|
declare interface ServeOptions {
|
package/dist/index.js
CHANGED
|
@@ -7,12 +7,12 @@ import * as __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__ from "node:url";
|
|
|
7
7
|
import { matchPath } from "@rspress/runtime/server";
|
|
8
8
|
import { logger } from "@rspress/shared/logger";
|
|
9
9
|
import { extractTextAndId, getIconUrlPath, getNodeAttribute, loadFrontMatter, mergeDocConfig } from "@rspress/shared/node-utils";
|
|
10
|
-
import node_fs_promises, { mkdir, readFile, readdir, rm, stat as promises_stat, writeFile } from "node:fs/promises";
|
|
11
|
-
import { createRequire } from "node:module";
|
|
12
|
-
import { PLUGIN_REACT_NAME, pluginReact } from "@rsbuild/plugin-react";
|
|
13
10
|
import { DEFAULT_PAGE_EXTENSIONS } from "@rspress/shared/constants";
|
|
11
|
+
import node_fs_promises, { mkdir, readFile, readdir, rm, stat as promises_stat, writeFile } from "node:fs/promises";
|
|
14
12
|
import picocolors from "picocolors";
|
|
15
13
|
import { glob } from "tinyglobby";
|
|
14
|
+
import { createRequire } from "node:module";
|
|
15
|
+
import { PLUGIN_REACT_NAME, pluginReact } from "@rsbuild/plugin-react";
|
|
16
16
|
import { chunk, groupBy } from "lodash-es";
|
|
17
17
|
import { compile } from "@rspress/mdx-rs";
|
|
18
18
|
import { htmlToText } from "html-to-text";
|
|
@@ -113,75 +113,6 @@ function defineConfig(config) {
|
|
|
113
113
|
return config;
|
|
114
114
|
}
|
|
115
115
|
var external_node_path_ = __webpack_require__("node:path");
|
|
116
|
-
var external_node_url_ = __webpack_require__("node:url");
|
|
117
|
-
var package_namespaceObject = JSON.parse('{"rE":"2.0.0-beta.31"}');
|
|
118
|
-
const RSPRESS_VERSION = package_namespaceObject.rE;
|
|
119
|
-
const isProduction = ()=>'production' === process.env.NODE_ENV;
|
|
120
|
-
const importStatementRegex = /import\s+(.*?)\s+from\s+(['"])(.*?)(?:"|');?/gm;
|
|
121
|
-
const inlineThemeScript = `{
|
|
122
|
-
const saved = localStorage.getItem('${shared_.APPEARANCE_KEY}')
|
|
123
|
-
const preferDark = window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
124
|
-
const isDark = !saved || saved === 'auto' ? preferDark : saved === 'dark'
|
|
125
|
-
document.documentElement.classList.toggle('dark', isDark)
|
|
126
|
-
document.documentElement.classList.toggle('rp-dark', isDark)
|
|
127
|
-
document.documentElement.style.colorScheme = isDark ? 'dark' : 'light'
|
|
128
|
-
}`.replace(/\n/g, ';').replace(/\s{2,}/g, '');
|
|
129
|
-
const dirname = external_node_path_["default"].dirname((0, external_node_url_.fileURLToPath)(new URL(import.meta.url)));
|
|
130
|
-
const PACKAGE_ROOT = external_node_path_["default"].join(dirname, '..');
|
|
131
|
-
const TEMPLATE_PATH = external_node_path_["default"].join(PACKAGE_ROOT, 'index.html');
|
|
132
|
-
const CSR_CLIENT_ENTRY = external_node_path_["default"].join(PACKAGE_ROOT, 'dist', 'runtime', 'csrClientEntry.js');
|
|
133
|
-
const SSR_CLIENT_ENTRY = external_node_path_["default"].join(PACKAGE_ROOT, 'dist', 'runtime', 'ssrClientEntry.js');
|
|
134
|
-
const SSR_SERVER_ENTRY = external_node_path_["default"].join(PACKAGE_ROOT, 'dist', 'runtime', 'ssrServerEntry.js');
|
|
135
|
-
const OUTPUT_DIR = 'doc_build';
|
|
136
|
-
const APP_HTML_MARKER = '<!--<?- DOC_CONTENT ?>-->';
|
|
137
|
-
const HEAD_MARKER = '<!--<?- HEAD ?>-->';
|
|
138
|
-
const META_GENERATOR = '<!--<?- GENERATOR ?>-->';
|
|
139
|
-
const DEFAULT_TITLE = 'Rspress';
|
|
140
|
-
const PUBLIC_DIR = 'public';
|
|
141
|
-
const constants_TEMP_DIR = external_node_path_["default"].join(process.cwd(), 'node_modules', shared_.RSPRESS_TEMP_DIR);
|
|
142
|
-
const NODE_SSG_BUNDLE_FOLDER = '__ssg__';
|
|
143
|
-
const NODE_SSG_BUNDLE_NAME = 'rspress-ssg-entry.cjs';
|
|
144
|
-
const PLUGIN_VIRTUAL_MODULE_NAME = 'rsbuild:virtual-module';
|
|
145
|
-
const pluginVirtualModule = (pluginOptions = {})=>({
|
|
146
|
-
name: PLUGIN_VIRTUAL_MODULE_NAME,
|
|
147
|
-
async setup (api) {
|
|
148
|
-
const { virtualModules = {}, tempDir: virtualFolderName = '.rsbuild-virtual-module' } = pluginOptions;
|
|
149
|
-
const TEMP_DIR = (0, external_node_path_.join)(api.context.rootPath, 'node_modules', virtualFolderName);
|
|
150
|
-
const virtualFileAbsolutePaths = Object.keys(virtualModules).map((i)=>{
|
|
151
|
-
let absolutePath = (0, external_node_path_.join)(TEMP_DIR, i);
|
|
152
|
-
if (!(0, external_node_path_.extname)(absolutePath)) absolutePath = `${absolutePath}.js`;
|
|
153
|
-
return [
|
|
154
|
-
i,
|
|
155
|
-
absolutePath
|
|
156
|
-
];
|
|
157
|
-
});
|
|
158
|
-
api.modifyRsbuildConfig((config)=>{
|
|
159
|
-
if (!config.source) config.source = {};
|
|
160
|
-
config.source.include = [
|
|
161
|
-
...config.source.include || [],
|
|
162
|
-
TEMP_DIR
|
|
163
|
-
];
|
|
164
|
-
});
|
|
165
|
-
api.onBeforeCreateCompiler(async ()=>{
|
|
166
|
-
await Promise.all(virtualFileAbsolutePaths.map(async ([_, absolutePath])=>{
|
|
167
|
-
const dir = (0, external_node_path_.dirname)(absolutePath);
|
|
168
|
-
await mkdir(dir, {
|
|
169
|
-
recursive: true
|
|
170
|
-
});
|
|
171
|
-
return writeFile(absolutePath, '', 'utf-8');
|
|
172
|
-
}));
|
|
173
|
-
});
|
|
174
|
-
api.modifyBundlerChain((chain)=>{
|
|
175
|
-
chain.resolve.alias.merge(Object.fromEntries(virtualFileAbsolutePaths));
|
|
176
|
-
});
|
|
177
|
-
for (const [moduleName, absolutePath] of virtualFileAbsolutePaths){
|
|
178
|
-
const handler = virtualModules[moduleName];
|
|
179
|
-
if (handler) api.transform({
|
|
180
|
-
test: absolutePath
|
|
181
|
-
}, handler);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
116
|
async function pathExists(path) {
|
|
186
117
|
try {
|
|
187
118
|
await node_fs_promises.access(path);
|
|
@@ -280,6 +211,33 @@ function slash(p) {
|
|
|
280
211
|
function normalizePath(id) {
|
|
281
212
|
return external_node_path_["default"].posix.normalize(isWindows ? slash(id) : id);
|
|
282
213
|
}
|
|
214
|
+
var external_node_url_ = __webpack_require__("node:url");
|
|
215
|
+
var package_namespaceObject = JSON.parse('{"rE":"2.0.0-beta.32"}');
|
|
216
|
+
const RSPRESS_VERSION = package_namespaceObject.rE;
|
|
217
|
+
const isProduction = ()=>'production' === process.env.NODE_ENV;
|
|
218
|
+
const importStatementRegex = /import\s+(.*?)\s+from\s+(['"])(.*?)(?:"|');?/gm;
|
|
219
|
+
const inlineThemeScript = `{
|
|
220
|
+
const saved = localStorage.getItem('${shared_.APPEARANCE_KEY}')
|
|
221
|
+
const preferDark = window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
222
|
+
const isDark = !saved || saved === 'auto' ? preferDark : saved === 'dark'
|
|
223
|
+
document.documentElement.classList.toggle('dark', isDark)
|
|
224
|
+
document.documentElement.classList.toggle('rp-dark', isDark)
|
|
225
|
+
document.documentElement.style.colorScheme = isDark ? 'dark' : 'light'
|
|
226
|
+
}`.replace(/\n/g, ';').replace(/\s{2,}/g, '');
|
|
227
|
+
const dirname = external_node_path_["default"].dirname((0, external_node_url_.fileURLToPath)(new URL(import.meta.url)));
|
|
228
|
+
const PACKAGE_ROOT = external_node_path_["default"].join(dirname, '..');
|
|
229
|
+
const TEMPLATE_PATH = external_node_path_["default"].join(PACKAGE_ROOT, 'index.html');
|
|
230
|
+
const CSR_CLIENT_ENTRY = external_node_path_["default"].join(PACKAGE_ROOT, 'dist', 'runtime', 'csrClientEntry.js');
|
|
231
|
+
const SSR_CLIENT_ENTRY = external_node_path_["default"].join(PACKAGE_ROOT, 'dist', 'runtime', 'ssrClientEntry.js');
|
|
232
|
+
const SSR_SERVER_ENTRY = external_node_path_["default"].join(PACKAGE_ROOT, 'dist', 'runtime', 'ssrServerEntry.js');
|
|
233
|
+
const OUTPUT_DIR = 'doc_build';
|
|
234
|
+
const APP_HTML_MARKER = '<!--<?- DOC_CONTENT ?>-->';
|
|
235
|
+
const HEAD_MARKER = '<!--<?- HEAD ?>-->';
|
|
236
|
+
const META_GENERATOR = '<!--<?- GENERATOR ?>-->';
|
|
237
|
+
const DEFAULT_TITLE = 'Rspress';
|
|
238
|
+
const PUBLIC_DIR = 'public';
|
|
239
|
+
const NODE_SSG_BUNDLE_FOLDER = '__ssg__';
|
|
240
|
+
const NODE_SSG_BUNDLE_NAME = 'rspress-ssg-entry.cjs';
|
|
283
241
|
const getRoutePathParts = (relativePath, lang, version, langs, versions)=>{
|
|
284
242
|
const [versionPart, langPart, purePath] = splitRoutePathParts(relativePath, lang, version, langs, versions);
|
|
285
243
|
return [
|
|
@@ -343,20 +301,26 @@ class RouteService {
|
|
|
343
301
|
#exclude;
|
|
344
302
|
#excludeConvention;
|
|
345
303
|
#tempDir;
|
|
346
|
-
#
|
|
304
|
+
#externalPages;
|
|
347
305
|
static __instance__ = null;
|
|
348
306
|
static getInstance() {
|
|
349
307
|
return RouteService.__instance__;
|
|
350
308
|
}
|
|
351
309
|
static async create(options) {
|
|
352
|
-
const { scanDir, config,
|
|
353
|
-
const
|
|
310
|
+
const { scanDir, config, externalPages } = options;
|
|
311
|
+
const runtimeAbsTempDir = external_node_path_["default"].join(process.cwd(), 'node_modules', shared_.RSPRESS_TEMP_DIR, 'runtime');
|
|
312
|
+
await node_fs_promises.mkdir(runtimeAbsTempDir, {
|
|
313
|
+
recursive: true
|
|
314
|
+
});
|
|
315
|
+
const routeService = new RouteService(scanDir, config, externalPages || [], runtimeAbsTempDir);
|
|
354
316
|
RouteService.__instance__ = routeService;
|
|
355
317
|
await routeService.#init();
|
|
356
|
-
await pluginDriver.routeServiceGenerated(routeService);
|
|
357
318
|
return routeService;
|
|
358
319
|
}
|
|
359
|
-
|
|
320
|
+
static async createSimple() {
|
|
321
|
+
return new RouteService('', {}, [], '');
|
|
322
|
+
}
|
|
323
|
+
constructor(scanDir, userConfig, externalPages, runtimeAbsTempDir){
|
|
360
324
|
const routeOptions = userConfig?.route || {};
|
|
361
325
|
this.#scanDir = scanDir;
|
|
362
326
|
this.#extensions = routeOptions.extensions || DEFAULT_PAGE_EXTENSIONS;
|
|
@@ -367,8 +331,8 @@ class RouteService {
|
|
|
367
331
|
];
|
|
368
332
|
this.#defaultLang = userConfig?.lang || '';
|
|
369
333
|
this.#langs = (userConfig?.locales ?? userConfig?.themeConfig?.locales ?? []).map((item)=>item.lang);
|
|
370
|
-
this.#tempDir =
|
|
371
|
-
this.#
|
|
334
|
+
this.#tempDir = runtimeAbsTempDir;
|
|
335
|
+
this.#externalPages = externalPages;
|
|
372
336
|
if (userConfig.multiVersion) {
|
|
373
337
|
this.#defaultVersion = userConfig.multiVersion.default || '';
|
|
374
338
|
this.#versions = userConfig.multiVersion.versions || [];
|
|
@@ -403,7 +367,7 @@ class RouteService {
|
|
|
403
367
|
const routePage = RoutePage.create(filePath, this.#scanDir);
|
|
404
368
|
this.addRoute(routePage);
|
|
405
369
|
});
|
|
406
|
-
const externalPages =
|
|
370
|
+
const externalPages = this.#externalPages;
|
|
407
371
|
await Promise.all(externalPages.map(async (route, index)=>{
|
|
408
372
|
const { routePath, content, filepath } = route;
|
|
409
373
|
if (filepath) {
|
|
@@ -417,7 +381,6 @@ class RouteService {
|
|
|
417
381
|
this.addRoute(routePage);
|
|
418
382
|
}
|
|
419
383
|
}));
|
|
420
|
-
await this.#pluginDriver.routeGenerated(this.getRoutes());
|
|
421
384
|
}
|
|
422
385
|
async addRoute(routePage) {
|
|
423
386
|
const { routeMeta: { routePath } } = routePage;
|
|
@@ -596,7 +559,7 @@ async function fsDirToMetaItems(workDir, extensions) {
|
|
|
596
559
|
}))).filter(Boolean);
|
|
597
560
|
return sideMeta;
|
|
598
561
|
}
|
|
599
|
-
async function metaItemToSidebarItem(metaItem, workDir, docsDir, extensions, isFirstDir = false) {
|
|
562
|
+
async function metaItemToSidebarItem(metaItem, workDir, docsDir, extensions, metaFileSet, isFirstDir = false) {
|
|
600
563
|
if ('string' == typeof metaItem) return metaFileItemToSidebarItem(metaItem, workDir, docsDir, extensions);
|
|
601
564
|
const { type } = metaItem;
|
|
602
565
|
if ('file' === type) return metaFileItemToSidebarItem(metaItem, workDir, docsDir, extensions);
|
|
@@ -606,7 +569,10 @@ async function metaItemToSidebarItem(metaItem, workDir, docsDir, extensions, isF
|
|
|
606
569
|
const dirMetaJsonPath = (0, external_node_path_.join)(dirAbsolutePath, '_meta.json');
|
|
607
570
|
const isMetaJsonExist = await utils_pathExists(dirMetaJsonPath);
|
|
608
571
|
let dirMetaJson = [];
|
|
609
|
-
|
|
572
|
+
if (isMetaJsonExist) {
|
|
573
|
+
metaFileSet.add(dirMetaJsonPath);
|
|
574
|
+
dirMetaJson = await utils_readJson(dirMetaJsonPath);
|
|
575
|
+
} else dirMetaJson = await fsDirToMetaItems(dirAbsolutePath, extensions);
|
|
610
576
|
async function getItems(withoutIndex = false) {
|
|
611
577
|
const items = await Promise.all((withoutIndex ? dirMetaJson.filter((i)=>{
|
|
612
578
|
let name;
|
|
@@ -616,7 +582,7 @@ async function metaItemToSidebarItem(metaItem, workDir, docsDir, extensions, isF
|
|
|
616
582
|
name = i;
|
|
617
583
|
}
|
|
618
584
|
return 'index.md' !== name && 'index.mdx' !== i && 'index' !== i;
|
|
619
|
-
}) : dirMetaJson).map((item)=>metaItemToSidebarItem(item, dirAbsolutePath, docsDir, extensions)));
|
|
585
|
+
}) : dirMetaJson).map((item)=>metaItemToSidebarItem(item, dirAbsolutePath, docsDir, extensions, metaFileSet)));
|
|
620
586
|
return items;
|
|
621
587
|
}
|
|
622
588
|
try {
|
|
@@ -756,18 +722,19 @@ function metaDividerToSidebarItem(metaItem) {
|
|
|
756
722
|
tag
|
|
757
723
|
};
|
|
758
724
|
}
|
|
759
|
-
async function scanSideMeta(workDir, docsDir, extensions) {
|
|
725
|
+
async function scanSideMeta(workDir, docsDir, extensions, metaFileSet) {
|
|
760
726
|
const dir = await metaItemToSidebarItem({
|
|
761
727
|
type: 'dir',
|
|
762
728
|
name: ''
|
|
763
|
-
}, workDir, docsDir, extensions, true);
|
|
729
|
+
}, workDir, docsDir, extensions, metaFileSet, true);
|
|
764
730
|
return dir.items;
|
|
765
731
|
}
|
|
766
|
-
async function scanNav(workDir, docsDir) {
|
|
732
|
+
async function scanNav(workDir, docsDir, metaFileSet) {
|
|
767
733
|
let navConfig;
|
|
768
734
|
const rootNavJson = external_node_path_["default"].resolve(workDir, '_nav.json');
|
|
769
735
|
try {
|
|
770
736
|
navConfig = await utils_readJson(rootNavJson);
|
|
737
|
+
metaFileSet.add(rootNavJson);
|
|
771
738
|
} catch (_e) {
|
|
772
739
|
logger.error('[auto-nav-sidebar]', `Generate nav meta error: ${rootNavJson} failed`);
|
|
773
740
|
navConfig = [];
|
|
@@ -780,7 +747,7 @@ async function scanNav(workDir, docsDir) {
|
|
|
780
747
|
});
|
|
781
748
|
return navConfig;
|
|
782
749
|
}
|
|
783
|
-
async function walk(workDir, docsDir, extensions) {
|
|
750
|
+
async function walk(workDir, docsDir, extensions, metaFileSet) {
|
|
784
751
|
const rootNavJson = external_node_path_["default"].resolve(workDir, '_nav.json');
|
|
785
752
|
const rootMetaJson = external_node_path_["default"].resolve(workDir, '_meta.json');
|
|
786
753
|
const isRootNavJsonExist = await pathExists(rootNavJson);
|
|
@@ -790,16 +757,16 @@ async function walk(workDir, docsDir, extensions) {
|
|
|
790
757
|
hintNavJsonChangeThenPanic(metaConfig, workDir, docsDir);
|
|
791
758
|
}
|
|
792
759
|
if (isRootMetaJsonExist && isRootNavJsonExist) {
|
|
793
|
-
const navConfig = await scanNav(workDir, docsDir);
|
|
760
|
+
const navConfig = await scanNav(workDir, docsDir, metaFileSet);
|
|
794
761
|
return {
|
|
795
762
|
nav: navConfig,
|
|
796
763
|
sidebar: {
|
|
797
|
-
'/': await scanSideMeta(workDir, docsDir, extensions)
|
|
764
|
+
'/': await scanSideMeta(workDir, docsDir, extensions, metaFileSet)
|
|
798
765
|
}
|
|
799
766
|
};
|
|
800
767
|
}
|
|
801
768
|
if (isRootNavJsonExist) {
|
|
802
|
-
const navConfig = await scanNav(workDir, docsDir);
|
|
769
|
+
const navConfig = await scanNav(workDir, docsDir, metaFileSet);
|
|
803
770
|
const subDirs = (await Promise.all((await node_fs_promises.readdir(workDir)).map((v)=>node_fs_promises.stat(external_node_path_["default"].join(workDir, v)).then((s)=>{
|
|
804
771
|
if (s.isDirectory() && 'node_modules' !== v) return v;
|
|
805
772
|
return false;
|
|
@@ -807,7 +774,7 @@ async function walk(workDir, docsDir, extensions) {
|
|
|
807
774
|
const sidebarConfig = {};
|
|
808
775
|
await Promise.all(subDirs.map(async (subDir)=>{
|
|
809
776
|
const sidebarGroupKey = addRoutePrefix(workDir, docsDir, subDir);
|
|
810
|
-
sidebarConfig[sidebarGroupKey] = await scanSideMeta(external_node_path_["default"].join(workDir, subDir), docsDir, extensions);
|
|
777
|
+
sidebarConfig[sidebarGroupKey] = await scanSideMeta(external_node_path_["default"].join(workDir, subDir), docsDir, extensions, metaFileSet);
|
|
811
778
|
}));
|
|
812
779
|
return {
|
|
813
780
|
nav: navConfig,
|
|
@@ -817,7 +784,7 @@ async function walk(workDir, docsDir, extensions) {
|
|
|
817
784
|
return {
|
|
818
785
|
nav: [],
|
|
819
786
|
sidebar: {
|
|
820
|
-
'/': await scanSideMeta(workDir, docsDir, extensions)
|
|
787
|
+
'/': await scanSideMeta(workDir, docsDir, extensions, metaFileSet)
|
|
821
788
|
}
|
|
822
789
|
};
|
|
823
790
|
}
|
|
@@ -836,47 +803,94 @@ function combineWalkResult(walks, versions) {
|
|
|
836
803
|
sidebar: {}
|
|
837
804
|
});
|
|
838
805
|
}
|
|
839
|
-
function processLocales(langs, versions, root, extensions) {
|
|
806
|
+
function processLocales(langs, versions, root, extensions, metaFileSet) {
|
|
840
807
|
return Promise.all(langs.map(async (lang)=>{
|
|
841
|
-
const walks = versions.length ? await Promise.all(versions.map((version)=>walk(external_node_path_["default"].join(root, version, lang), root, extensions))) : [
|
|
842
|
-
await walk(external_node_path_["default"].join(root, lang), root, extensions)
|
|
808
|
+
const walks = versions.length ? await Promise.all(versions.map((version)=>walk(external_node_path_["default"].join(root, version, lang), root, extensions, metaFileSet))) : [
|
|
809
|
+
await walk(external_node_path_["default"].join(root, lang), root, extensions, metaFileSet)
|
|
843
810
|
];
|
|
844
811
|
return combineWalkResult(walks, versions);
|
|
845
812
|
}));
|
|
846
813
|
}
|
|
847
|
-
async function
|
|
848
|
-
const themeConfig = config.themeConfig || {};
|
|
849
|
-
const haveNavSidebarConfig = themeConfig.nav || themeConfig.sidebar || themeConfig.locales?.[0]?.nav || themeConfig.locales?.[0]?.sidebar;
|
|
850
|
-
if (haveNavSidebarConfig) return config;
|
|
814
|
+
async function runAutoNavSide(config, metaFileSet) {
|
|
851
815
|
config.themeConfig = config.themeConfig || {};
|
|
852
816
|
config.themeConfig.locales = config.themeConfig.locales || config.locales || [];
|
|
853
817
|
const langs = config.themeConfig.locales.map((locale)=>locale.lang);
|
|
854
818
|
const hasLocales = langs.length > 0;
|
|
855
|
-
const hasLang = Boolean(config.lang);
|
|
856
819
|
const versions = config.multiVersion?.versions || [];
|
|
857
820
|
const { extensions = DEFAULT_PAGE_EXTENSIONS } = config?.route || {};
|
|
858
821
|
if (hasLocales) {
|
|
859
|
-
const metaInfo = await processLocales(langs, versions, config.root, extensions);
|
|
822
|
+
const metaInfo = await processLocales(langs, versions, config.root, extensions, metaFileSet);
|
|
823
|
+
return metaInfo;
|
|
824
|
+
}
|
|
825
|
+
const walks = versions.length ? await Promise.all(versions.map((version)=>walk(external_node_path_["default"].join(config.root, version), config.root, extensions, metaFileSet))) : [
|
|
826
|
+
await walk(config.root, config.root, extensions, metaFileSet)
|
|
827
|
+
];
|
|
828
|
+
const combined = combineWalkResult(walks, versions);
|
|
829
|
+
return combined;
|
|
830
|
+
}
|
|
831
|
+
function auto_nav_sidebar_haveNavSidebarConfig(config) {
|
|
832
|
+
const themeConfig = config.themeConfig || {};
|
|
833
|
+
const haveNavSidebarConfig = themeConfig.nav || themeConfig.sidebar || themeConfig.locales?.[0]?.nav || themeConfig.locales?.[0]?.sidebar;
|
|
834
|
+
return Boolean(haveNavSidebarConfig);
|
|
835
|
+
}
|
|
836
|
+
async function modifyConfigWithAutoNavSide(config, metaFileSet = new Set(), force = false) {
|
|
837
|
+
if (auto_nav_sidebar_haveNavSidebarConfig(config) && !force) return;
|
|
838
|
+
const autoNavSide = await runAutoNavSide(config, metaFileSet);
|
|
839
|
+
if (null === autoNavSide) return;
|
|
840
|
+
if (Array.isArray(autoNavSide)) {
|
|
841
|
+
config.themeConfig = config.themeConfig || {};
|
|
842
|
+
config.themeConfig.locales = config.themeConfig.locales || [];
|
|
860
843
|
config.themeConfig.locales = config.themeConfig.locales.map((item, index)=>({
|
|
861
844
|
...item,
|
|
862
|
-
...
|
|
845
|
+
...autoNavSide[index]
|
|
863
846
|
}));
|
|
864
|
-
|
|
865
|
-
if (hasLang) {
|
|
866
|
-
logger.error("`lang` is configured but `locales` not, thus `auto-nav-sidebar` can not auto generate navbar level config correctly!\nplease check your config file");
|
|
867
|
-
return config;
|
|
868
|
-
}
|
|
869
|
-
const walks = versions.length ? await Promise.all(versions.map((version)=>walk(external_node_path_["default"].join(config.root, version), config.root, extensions))) : [
|
|
870
|
-
await walk(config.root, config.root, extensions)
|
|
871
|
-
];
|
|
872
|
-
const combined = combineWalkResult(walks, versions);
|
|
873
|
-
config.themeConfig = {
|
|
874
|
-
...config.themeConfig,
|
|
875
|
-
...combined
|
|
876
|
-
};
|
|
847
|
+
return;
|
|
877
848
|
}
|
|
878
|
-
|
|
849
|
+
config.themeConfig = config.themeConfig || {};
|
|
850
|
+
config.themeConfig.nav = autoNavSide.nav;
|
|
851
|
+
config.themeConfig.sidebar = autoNavSide.sidebar;
|
|
879
852
|
}
|
|
853
|
+
const PLUGIN_VIRTUAL_MODULE_NAME = 'rsbuild:virtual-module';
|
|
854
|
+
const pluginVirtualModule = (pluginOptions = {})=>({
|
|
855
|
+
name: PLUGIN_VIRTUAL_MODULE_NAME,
|
|
856
|
+
async setup (api) {
|
|
857
|
+
const { virtualModules = {}, tempDir: virtualFolderName = '.rsbuild-virtual-module' } = pluginOptions;
|
|
858
|
+
const TEMP_DIR = (0, external_node_path_.join)(api.context.rootPath, 'node_modules', virtualFolderName);
|
|
859
|
+
const virtualFileAbsolutePaths = Object.keys(virtualModules).map((i)=>{
|
|
860
|
+
let absolutePath = (0, external_node_path_.join)(TEMP_DIR, i);
|
|
861
|
+
if (!(0, external_node_path_.extname)(absolutePath)) absolutePath = `${absolutePath}.js`;
|
|
862
|
+
return [
|
|
863
|
+
i,
|
|
864
|
+
absolutePath
|
|
865
|
+
];
|
|
866
|
+
});
|
|
867
|
+
api.modifyRsbuildConfig((config)=>{
|
|
868
|
+
if (!config.source) config.source = {};
|
|
869
|
+
config.source.include = [
|
|
870
|
+
...config.source.include || [],
|
|
871
|
+
TEMP_DIR
|
|
872
|
+
];
|
|
873
|
+
});
|
|
874
|
+
api.onBeforeCreateCompiler(async ()=>{
|
|
875
|
+
await Promise.all(virtualFileAbsolutePaths.map(async ([_, absolutePath])=>{
|
|
876
|
+
const dir = (0, external_node_path_.dirname)(absolutePath);
|
|
877
|
+
await mkdir(dir, {
|
|
878
|
+
recursive: true
|
|
879
|
+
});
|
|
880
|
+
return writeFile(absolutePath, '', 'utf-8');
|
|
881
|
+
}));
|
|
882
|
+
});
|
|
883
|
+
api.modifyBundlerChain((chain)=>{
|
|
884
|
+
chain.resolve.alias.merge(Object.fromEntries(virtualFileAbsolutePaths));
|
|
885
|
+
});
|
|
886
|
+
for (const [moduleName, absolutePath] of virtualFileAbsolutePaths){
|
|
887
|
+
const handler = virtualModules[moduleName];
|
|
888
|
+
if (handler) api.transform({
|
|
889
|
+
test: absolutePath
|
|
890
|
+
}, handler);
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
});
|
|
880
894
|
const globalStylesVMPlugin = (context)=>({
|
|
881
895
|
["virtual-global-styles"]: ()=>{
|
|
882
896
|
const { config, pluginDriver } = context;
|
|
@@ -1374,9 +1388,16 @@ async function createSiteData(userConfig) {
|
|
|
1374
1388
|
};
|
|
1375
1389
|
}
|
|
1376
1390
|
const siteDataVMPlugin = (context)=>{
|
|
1377
|
-
const { config } = context;
|
|
1391
|
+
const { config, pluginDriver } = context;
|
|
1378
1392
|
return {
|
|
1379
|
-
["virtual-site-data"]: async ()=>{
|
|
1393
|
+
["virtual-site-data"]: async ({ addDependency })=>{
|
|
1394
|
+
const force = !pluginDriver.haveNavSidebarConfig;
|
|
1395
|
+
const metaFileSet = new Set();
|
|
1396
|
+
try {
|
|
1397
|
+
await modifyConfigWithAutoNavSide(config, metaFileSet, force);
|
|
1398
|
+
} finally{
|
|
1399
|
+
if (metaFileSet) for (const metaFile of metaFileSet)addDependency(metaFile);
|
|
1400
|
+
}
|
|
1380
1401
|
const { siteData } = await createSiteData(config);
|
|
1381
1402
|
return `export default ${JSON.stringify(siteData, null, 2)}`;
|
|
1382
1403
|
}
|
|
@@ -1902,7 +1923,6 @@ async function getVirtualModulesFromPlugins(pluginDriver) {
|
|
|
1902
1923
|
return runtimeModule;
|
|
1903
1924
|
}
|
|
1904
1925
|
async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeService, pluginDriver) {
|
|
1905
|
-
const cwd = process.cwd();
|
|
1906
1926
|
const CUSTOM_THEME_DIR = config?.themeDir ?? external_node_path_["default"].join(process.cwd(), 'theme');
|
|
1907
1927
|
const outDir = config?.outDir ?? OUTPUT_DIR;
|
|
1908
1928
|
const DEFAULT_THEME = initRsbuild_require.resolve('@rspress/theme-default');
|
|
@@ -2011,8 +2031,7 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
2011
2031
|
},
|
|
2012
2032
|
source: {
|
|
2013
2033
|
include: [
|
|
2014
|
-
PACKAGE_ROOT
|
|
2015
|
-
external_node_path_["default"].join(cwd, 'node_modules', shared_.RSPRESS_TEMP_DIR)
|
|
2034
|
+
PACKAGE_ROOT
|
|
2016
2035
|
],
|
|
2017
2036
|
define: {
|
|
2018
2037
|
'process.env.TEST': JSON.stringify(process.env.TEST)
|
|
@@ -2033,7 +2052,8 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
2033
2052
|
})) ?? {
|
|
2034
2053
|
nav: config.themeConfig?.nav,
|
|
2035
2054
|
sidebar: config.themeConfig?.sidebar
|
|
2036
|
-
})
|
|
2055
|
+
}),
|
|
2056
|
+
package_namespaceObject.rE
|
|
2037
2057
|
]
|
|
2038
2058
|
}
|
|
2039
2059
|
} : {},
|
|
@@ -2150,27 +2170,15 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
2150
2170
|
}
|
|
2151
2171
|
};
|
|
2152
2172
|
}
|
|
2153
|
-
async function initRsbuild(rootDir, config, pluginDriver, enableSSG, extraRsbuildConfig) {
|
|
2173
|
+
async function initRsbuild(rootDir, config, pluginDriver, routeService, enableSSG, extraRsbuildConfig) {
|
|
2154
2174
|
const cwd = process.cwd();
|
|
2155
2175
|
const userDocRoot = external_node_path_["default"].resolve(rootDir || config?.root || cwd);
|
|
2156
|
-
|
|
2157
|
-
const runtimeAbsTempDir = external_node_path_["default"].join(cwd, 'node_modules', runtimeTempDir);
|
|
2158
|
-
await node_fs_promises.mkdir(runtimeAbsTempDir, {
|
|
2159
|
-
recursive: true
|
|
2160
|
-
});
|
|
2161
|
-
const routeService = await RouteService.create({
|
|
2162
|
-
config: config,
|
|
2163
|
-
runtimeTempDir: runtimeAbsTempDir,
|
|
2164
|
-
scanDir: userDocRoot,
|
|
2165
|
-
pluginDriver
|
|
2166
|
-
});
|
|
2167
|
-
const mergedConfig = await modifyConfigWithAutoNavSide(config);
|
|
2168
|
-
hintBuilderPluginsBreakingChange(mergedConfig);
|
|
2176
|
+
hintBuilderPluginsBreakingChange(config);
|
|
2169
2177
|
const { createRsbuild, mergeRsbuildConfig } = await import("@rsbuild/core");
|
|
2170
|
-
const internalRsbuildConfig = await createInternalBuildConfig(userDocRoot,
|
|
2178
|
+
const internalRsbuildConfig = await createInternalBuildConfig(userDocRoot, config, enableSSG, routeService, pluginDriver);
|
|
2171
2179
|
const rsbuild = await createRsbuild({
|
|
2172
2180
|
callerName: 'rspress',
|
|
2173
|
-
rsbuildConfig: mergeRsbuildConfig(internalRsbuildConfig, ...pluginDriver.getPlugins()?.map((plugin)=>plugin.builderConfig ?? {}) || [],
|
|
2181
|
+
rsbuildConfig: mergeRsbuildConfig(internalRsbuildConfig, ...pluginDriver.getPlugins()?.map((plugin)=>plugin.builderConfig ?? {}) || [], config.builderConfig || {}, extraRsbuildConfig || {})
|
|
2174
2182
|
});
|
|
2175
2183
|
return rsbuild;
|
|
2176
2184
|
}
|
|
@@ -2179,6 +2187,12 @@ class PluginDriver {
|
|
|
2179
2187
|
#configFilePath;
|
|
2180
2188
|
#plugins;
|
|
2181
2189
|
#isProd;
|
|
2190
|
+
haveNavSidebarConfig = false;
|
|
2191
|
+
static async create(config, configFilePath, isProd) {
|
|
2192
|
+
const pluginDriver = new PluginDriver(config, configFilePath, isProd);
|
|
2193
|
+
await pluginDriver.init();
|
|
2194
|
+
return pluginDriver;
|
|
2195
|
+
}
|
|
2182
2196
|
constructor(config, configFilePath, isProd){
|
|
2183
2197
|
this.#config = config;
|
|
2184
2198
|
this.#configFilePath = configFilePath;
|
|
@@ -2238,6 +2252,7 @@ class PluginDriver {
|
|
|
2238
2252
|
}, this.#isProd);
|
|
2239
2253
|
}
|
|
2240
2254
|
this.#config = config;
|
|
2255
|
+
this.haveNavSidebarConfig = auto_nav_sidebar_haveNavSidebarConfig(config);
|
|
2241
2256
|
return this.#config;
|
|
2242
2257
|
}
|
|
2243
2258
|
async beforeBuild() {
|
|
@@ -2363,42 +2378,47 @@ async function checkLanguageParity(config) {
|
|
|
2363
2378
|
throw err;
|
|
2364
2379
|
}
|
|
2365
2380
|
}
|
|
2366
|
-
async function
|
|
2381
|
+
async function build(options) {
|
|
2382
|
+
const { docDirectory, config, configFilePath } = options;
|
|
2383
|
+
const pluginDriver = await PluginDriver.create(config, configFilePath, true);
|
|
2384
|
+
const modifiedConfig = await pluginDriver.modifyConfig();
|
|
2385
|
+
const ssgConfig = Boolean(modifiedConfig.ssg ?? true);
|
|
2386
|
+
const additionalPages = await pluginDriver.addPages();
|
|
2387
|
+
const routeService = await RouteService.create({
|
|
2388
|
+
config: modifiedConfig,
|
|
2389
|
+
scanDir: docDirectory,
|
|
2390
|
+
externalPages: additionalPages
|
|
2391
|
+
});
|
|
2392
|
+
await pluginDriver.routeGenerated(routeService.getRoutes());
|
|
2393
|
+
await pluginDriver.routeServiceGenerated(routeService);
|
|
2394
|
+
await modifyConfigWithAutoNavSide(modifiedConfig);
|
|
2367
2395
|
try {
|
|
2368
|
-
const rsbuild = await initRsbuild(docDirectory, config, pluginDriver, enableSSG);
|
|
2369
2396
|
await pluginDriver.beforeBuild();
|
|
2397
|
+
const rsbuild = await initRsbuild(docDirectory, modifiedConfig, pluginDriver, routeService, ssgConfig);
|
|
2370
2398
|
await rsbuild.build();
|
|
2371
2399
|
} finally{
|
|
2372
2400
|
await checkLanguageParity(config);
|
|
2373
2401
|
}
|
|
2374
2402
|
await pluginDriver.afterBuild();
|
|
2375
|
-
}
|
|
2376
|
-
function emptyDir(path) {
|
|
2377
|
-
return node_fs_promises.rm(path, {
|
|
2378
|
-
force: true,
|
|
2379
|
-
recursive: true
|
|
2380
|
-
});
|
|
2381
|
-
}
|
|
2382
|
-
async function build(options) {
|
|
2383
|
-
const { docDirectory, config, configFilePath } = options;
|
|
2384
|
-
const pluginDriver = new PluginDriver(config, configFilePath, true);
|
|
2385
|
-
await pluginDriver.init();
|
|
2386
|
-
const modifiedConfig = await pluginDriver.modifyConfig();
|
|
2387
|
-
const ssgConfig = Boolean(modifiedConfig.ssg ?? true);
|
|
2388
|
-
await emptyDir(constants_TEMP_DIR);
|
|
2389
|
-
await bundle(docDirectory, modifiedConfig, pluginDriver, ssgConfig);
|
|
2390
2403
|
if (!ssgConfig) hintSSGFalse();
|
|
2391
2404
|
}
|
|
2392
2405
|
async function dev(options) {
|
|
2393
2406
|
const { docDirectory, config, extraBuilderConfig, configFilePath } = options;
|
|
2394
2407
|
const isProd = false;
|
|
2395
|
-
const pluginDriver =
|
|
2396
|
-
await pluginDriver.init();
|
|
2408
|
+
const pluginDriver = await PluginDriver.create(config, configFilePath, isProd);
|
|
2397
2409
|
const modifiedConfig = await pluginDriver.modifyConfig();
|
|
2398
2410
|
try {
|
|
2399
|
-
const
|
|
2411
|
+
const additionalPages = await pluginDriver.addPages();
|
|
2412
|
+
const routeService = await RouteService.create({
|
|
2413
|
+
config: modifiedConfig,
|
|
2414
|
+
scanDir: docDirectory,
|
|
2415
|
+
externalPages: additionalPages
|
|
2416
|
+
});
|
|
2417
|
+
await pluginDriver.routeGenerated(routeService.getRoutes());
|
|
2418
|
+
await pluginDriver.routeServiceGenerated(routeService);
|
|
2400
2419
|
await pluginDriver.beforeBuild();
|
|
2401
|
-
rsbuild
|
|
2420
|
+
const rsbuild = await initRsbuild(docDirectory, modifiedConfig, pluginDriver, routeService, false, extraBuilderConfig);
|
|
2421
|
+
rsbuild.onAfterDevCompile(async ()=>{
|
|
2402
2422
|
await pluginDriver.afterBuild();
|
|
2403
2423
|
});
|
|
2404
2424
|
const { server } = await rsbuild.startDevServer({
|
|
@@ -2560,10 +2580,9 @@ async function serve(options) {
|
|
|
2560
2580
|
host
|
|
2561
2581
|
}
|
|
2562
2582
|
});
|
|
2563
|
-
const pluginDriver =
|
|
2564
|
-
await pluginDriver.init();
|
|
2583
|
+
const pluginDriver = await PluginDriver.create(config, configFilePath, true);
|
|
2565
2584
|
const modifiedConfig = await pluginDriver.modifyConfig();
|
|
2566
|
-
const rsbuild = await initRsbuild(config.root, modifiedConfig, pluginDriver, false);
|
|
2585
|
+
const rsbuild = await initRsbuild(config.root, modifiedConfig, pluginDriver, await RouteService.createSimple(), false);
|
|
2567
2586
|
return rsbuild.preview();
|
|
2568
2587
|
}
|
|
2569
2588
|
var __webpack_exports__RSPRESS_TEMP_DIR = shared_.RSPRESS_TEMP_DIR;
|
package/dist/loader.d.ts
CHANGED
|
@@ -9,8 +9,7 @@ import { UserConfig } from '@rspress/shared';
|
|
|
9
9
|
declare interface InitOptions {
|
|
10
10
|
scanDir: string;
|
|
11
11
|
config: UserConfig;
|
|
12
|
-
|
|
13
|
-
pluginDriver: PluginDriver;
|
|
12
|
+
externalPages: AdditionalPage[];
|
|
14
13
|
}
|
|
15
14
|
|
|
16
15
|
declare function mdxLoader(this: Rspack_2.LoaderContext<MdxLoaderOptions>, source: string): Promise<void>;
|
|
@@ -26,7 +25,9 @@ declare interface MdxLoaderOptions {
|
|
|
26
25
|
|
|
27
26
|
declare class PluginDriver {
|
|
28
27
|
#private;
|
|
29
|
-
|
|
28
|
+
haveNavSidebarConfig: boolean;
|
|
29
|
+
static create(config: UserConfig, configFilePath: string, isProd: boolean): Promise<PluginDriver>;
|
|
30
|
+
private constructor();
|
|
30
31
|
getConfigFilePath(): string;
|
|
31
32
|
init(): Promise<void>;
|
|
32
33
|
addPlugin(plugin: RspressPlugin): void;
|
|
@@ -63,6 +64,7 @@ declare class RouteService {
|
|
|
63
64
|
static __instance__: RouteService | null;
|
|
64
65
|
static getInstance(): RouteService;
|
|
65
66
|
static create(options: InitOptions): Promise<RouteService>;
|
|
67
|
+
static createSimple(): Promise<RouteService>;
|
|
66
68
|
private constructor();
|
|
67
69
|
get extensions(): readonly string[];
|
|
68
70
|
addRoute(routePage: RoutePage): Promise<void>;
|
package/dist/processor.d.ts
CHANGED
|
@@ -23,13 +23,14 @@ export declare function compileWithCrossCompilerCache(options: CompileOptions):
|
|
|
23
23
|
declare interface InitOptions {
|
|
24
24
|
scanDir: string;
|
|
25
25
|
config: UserConfig;
|
|
26
|
-
|
|
27
|
-
pluginDriver: PluginDriver;
|
|
26
|
+
externalPages: AdditionalPage[];
|
|
28
27
|
}
|
|
29
28
|
|
|
30
29
|
declare class PluginDriver {
|
|
31
30
|
#private;
|
|
32
|
-
|
|
31
|
+
haveNavSidebarConfig: boolean;
|
|
32
|
+
static create(config: UserConfig, configFilePath: string, isProd: boolean): Promise<PluginDriver>;
|
|
33
|
+
private constructor();
|
|
33
34
|
getConfigFilePath(): string;
|
|
34
35
|
init(): Promise<void>;
|
|
35
36
|
addPlugin(plugin: RspressPlugin): void;
|
|
@@ -66,6 +67,7 @@ declare class RouteService {
|
|
|
66
67
|
static __instance__: RouteService | null;
|
|
67
68
|
static getInstance(): RouteService;
|
|
68
69
|
static create(options: InitOptions): Promise<RouteService>;
|
|
70
|
+
static createSimple(): Promise<RouteService>;
|
|
69
71
|
private constructor();
|
|
70
72
|
get extensions(): readonly string[];
|
|
71
73
|
addRoute(routePage: RoutePage): Promise<void>;
|
package/dist/renderPageWorker.js
CHANGED
|
@@ -5,7 +5,7 @@ import { createHead, transformHtmlTemplate } from "@unhead/react/server";
|
|
|
5
5
|
import picocolors_0 from "picocolors";
|
|
6
6
|
import "node:fs/promises";
|
|
7
7
|
import node_path from "node:path";
|
|
8
|
-
import { APPEARANCE_KEY
|
|
8
|
+
import { APPEARANCE_KEY } from "@rspress/shared";
|
|
9
9
|
async function pMap(iterable, mapper, { concurrency = 1 / 0, stopOnError = true, signal } = {}) {
|
|
10
10
|
return new Promise((resolve_, reject_)=>{
|
|
11
11
|
if (void 0 === iterable[Symbol.iterator] && void 0 === iterable[Symbol.asyncIterator]) throw new TypeError(`Expected \`input\` to be either an \`Iterable\` or \`AsyncIterable\`, got (${typeof iterable})`);
|
|
@@ -102,7 +102,7 @@ function hintSSGFailed() {
|
|
|
102
102
|
1. Fix code to make it SSR-compatible.
|
|
103
103
|
2. Set \`ssg: false\` if the code in node_modules may be difficult to fix, but the SSG feature will be lost.`);
|
|
104
104
|
}
|
|
105
|
-
var package_namespaceObject = JSON.parse('{"rE":"2.0.0-beta.
|
|
105
|
+
var package_namespaceObject = JSON.parse('{"rE":"2.0.0-beta.32"}');
|
|
106
106
|
const RSPRESS_VERSION = package_namespaceObject.rE;
|
|
107
107
|
`{
|
|
108
108
|
const saved = localStorage.getItem('${APPEARANCE_KEY}')
|
|
@@ -121,7 +121,6 @@ node_path.join(PACKAGE_ROOT, 'dist', 'runtime', 'ssrServerEntry.js');
|
|
|
121
121
|
const APP_HTML_MARKER = '<!--<?- DOC_CONTENT ?>-->';
|
|
122
122
|
const HEAD_MARKER = '<!--<?- HEAD ?>-->';
|
|
123
123
|
const META_GENERATOR = '<!--<?- GENERATOR ?>-->';
|
|
124
|
-
node_path.join(process.cwd(), 'node_modules', RSPRESS_TEMP_DIR);
|
|
125
124
|
async function renderConfigHead(head, route) {
|
|
126
125
|
if (!isRouteMeta(route)) return '';
|
|
127
126
|
if (!head || 0 === head.length) return '';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspress/core",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.32",
|
|
4
4
|
"description": "The Rspress Documentation Framework",
|
|
5
5
|
"bugs": "https://github.com/web-infra-dev/rspress/issues",
|
|
6
6
|
"repository": {
|
|
@@ -53,10 +53,10 @@
|
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@mdx-js/mdx": "^3.1.1",
|
|
55
55
|
"@mdx-js/react": "^3.1.1",
|
|
56
|
-
"@rsbuild/core": "~1.5.
|
|
56
|
+
"@rsbuild/core": "~1.5.4",
|
|
57
57
|
"@rsbuild/plugin-react": "~1.4.0",
|
|
58
58
|
"@rspress/mdx-rs": "0.6.6",
|
|
59
|
-
"@shikijs/rehype": "^3.12.
|
|
59
|
+
"@shikijs/rehype": "^3.12.2",
|
|
60
60
|
"@types/unist": "^3.0.3",
|
|
61
61
|
"@unhead/react": "^2.0.14",
|
|
62
62
|
"cac": "^6.7.14",
|
|
@@ -76,22 +76,21 @@
|
|
|
76
76
|
"rehype-external-links": "^3.0.0",
|
|
77
77
|
"rehype-raw": "^7.0.0",
|
|
78
78
|
"remark-gfm": "^4.0.1",
|
|
79
|
-
"shiki": "^3.12.
|
|
80
|
-
"tinyglobby": "^0.2.
|
|
79
|
+
"shiki": "^3.12.2",
|
|
80
|
+
"tinyglobby": "^0.2.15",
|
|
81
81
|
"tinypool": "^1.1.1",
|
|
82
82
|
"unified": "^11.0.5",
|
|
83
83
|
"unist-util-visit": "^5.0.0",
|
|
84
84
|
"unist-util-visit-children": "^3.0.0",
|
|
85
|
-
"@rspress/runtime": "2.0.0-beta.
|
|
86
|
-
"@rspress/shared": "2.0.0-beta.
|
|
87
|
-
"@rspress/theme-default": "2.0.0-beta.
|
|
85
|
+
"@rspress/runtime": "2.0.0-beta.32",
|
|
86
|
+
"@rspress/shared": "2.0.0-beta.32",
|
|
87
|
+
"@rspress/theme-default": "2.0.0-beta.32"
|
|
88
88
|
},
|
|
89
89
|
"devDependencies": {
|
|
90
90
|
"@microsoft/api-extractor": "^7.52.11",
|
|
91
91
|
"@rslib/core": "0.12.4",
|
|
92
92
|
"@types/hast": "^3.0.4",
|
|
93
93
|
"@types/html-to-text": "^9.0.4",
|
|
94
|
-
"@types/jest": "~29.5.14",
|
|
95
94
|
"@types/lodash-es": "^4.17.12",
|
|
96
95
|
"@types/mdast": "^4.0.4",
|
|
97
96
|
"@types/node": "^22.8.1",
|