@rspress/core 2.0.0-beta.21 → 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/bin/rspress.js +15 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +144 -0
- package/dist/index.d.ts +17 -11
- package/dist/index.js +517 -431
- package/dist/index.js.LICENSE.txt +10 -0
- package/dist/loader.d.ts +4 -7
- package/dist/loader.js +3 -4
- package/dist/processor.d.ts +6 -8
- package/dist/processor.js +287 -244
- package/dist/renderPageWorker.js +193 -0
- package/dist/runtime/ssrClientEntry.js +2 -1
- package/dist/runtime/ssrServerEntry.js +2 -2
- package/dist/shiki-transformers.js +14 -14
- package/meta-json-schema.json +382 -0
- package/nav-json-schema.json +118 -0
- package/package.json +20 -10
package/bin/rspress.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import nodeModule from 'node:module';
|
|
3
|
+
|
|
4
|
+
// enable on-disk code caching of all modules loaded by Node.js
|
|
5
|
+
// requires Nodejs >= 22.8.0
|
|
6
|
+
const { enableCompileCache } = nodeModule;
|
|
7
|
+
if (enableCompileCache) {
|
|
8
|
+
try {
|
|
9
|
+
enableCompileCache();
|
|
10
|
+
} catch {
|
|
11
|
+
// ignore errors
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
import('../dist/cli.js');
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { }
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import 'module';
|
|
2
|
+
/*#__PURE__*/ import.meta.url;
|
|
3
|
+
import node_path from "node:path";
|
|
4
|
+
import { logger } from "@rspress/shared/logger";
|
|
5
|
+
import { cac } from "cac";
|
|
6
|
+
import chokidar from "chokidar";
|
|
7
|
+
import picocolors from "picocolors";
|
|
8
|
+
import { build, dev, serve } from "./index.js";
|
|
9
|
+
import node_fs from "node:fs";
|
|
10
|
+
import { DEFAULT_CONFIG_EXTENSIONS, DEFAULT_CONFIG_NAME } from "@rspress/shared/constants";
|
|
11
|
+
var package_namespaceObject = JSON.parse('{"i8":"2.0.0-beta.23"}');
|
|
12
|
+
const findConfig = (basePath)=>DEFAULT_CONFIG_EXTENSIONS.map((ext)=>basePath + ext).find(node_fs.existsSync);
|
|
13
|
+
async function loadConfigFile(customConfigFile) {
|
|
14
|
+
const baseDir = process.cwd();
|
|
15
|
+
let configFilePath = '';
|
|
16
|
+
configFilePath = customConfigFile ? node_path.isAbsolute(customConfigFile) ? customConfigFile : node_path.join(baseDir, customConfigFile) : findConfig(node_path.join(baseDir, DEFAULT_CONFIG_NAME));
|
|
17
|
+
if (!configFilePath) {
|
|
18
|
+
logger.info(`No config file found in ${baseDir}`);
|
|
19
|
+
return {
|
|
20
|
+
config: {},
|
|
21
|
+
configFilePath: ''
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
const { loadConfig } = await import("@rsbuild/core");
|
|
25
|
+
const { content } = await loadConfig({
|
|
26
|
+
cwd: node_path.dirname(configFilePath),
|
|
27
|
+
path: configFilePath
|
|
28
|
+
});
|
|
29
|
+
return {
|
|
30
|
+
config: content,
|
|
31
|
+
configFilePath
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function resolveDocRoot(cwd, cliRoot, configRoot) {
|
|
35
|
+
if (cliRoot) return node_path.join(cwd, cliRoot);
|
|
36
|
+
if (configRoot) return node_path.isAbsolute(configRoot) ? configRoot : node_path.join(cwd, configRoot);
|
|
37
|
+
return node_path.join(cwd, 'docs');
|
|
38
|
+
}
|
|
39
|
+
const CONFIG_FILES = [
|
|
40
|
+
'rspress.config.ts',
|
|
41
|
+
'rspress.config.js'
|
|
42
|
+
];
|
|
43
|
+
const META_FILES = [
|
|
44
|
+
'_meta.json',
|
|
45
|
+
'_nav.json'
|
|
46
|
+
];
|
|
47
|
+
const cli = cac('rspress').version(package_namespaceObject.i8).help();
|
|
48
|
+
const landingMessage = `\u{1F525} Rspress v${package_namespaceObject.i8}\n`;
|
|
49
|
+
logger.greet(landingMessage);
|
|
50
|
+
const setNodeEnv = (env)=>{
|
|
51
|
+
process.env.NODE_ENV = env;
|
|
52
|
+
};
|
|
53
|
+
cli.option('-c,--config [config]', 'Specify the path to the config file');
|
|
54
|
+
cli.command('[root]', 'start dev server').alias('dev').option('--port [port]', 'port number').option('--host [host]', 'hostname').action(async (root, options)=>{
|
|
55
|
+
setNodeEnv('development');
|
|
56
|
+
let isRestarting = false;
|
|
57
|
+
const cwd = process.cwd();
|
|
58
|
+
let cliWatcher;
|
|
59
|
+
let devServer;
|
|
60
|
+
const startDevServer = async ()=>{
|
|
61
|
+
const { port, host } = options || {};
|
|
62
|
+
const { config, configFilePath } = await loadConfigFile(options?.config);
|
|
63
|
+
config.root = resolveDocRoot(cwd, root, config.root);
|
|
64
|
+
const docDirectory = config.root;
|
|
65
|
+
devServer = await dev({
|
|
66
|
+
appDirectory: cwd,
|
|
67
|
+
docDirectory,
|
|
68
|
+
config,
|
|
69
|
+
configFilePath,
|
|
70
|
+
extraBuilderConfig: {
|
|
71
|
+
server: {
|
|
72
|
+
port,
|
|
73
|
+
host
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
cliWatcher = chokidar.watch([
|
|
78
|
+
`${cwd}/**/{${CONFIG_FILES.join(',')}}`,
|
|
79
|
+
docDirectory
|
|
80
|
+
], {
|
|
81
|
+
ignoreInitial: true,
|
|
82
|
+
ignored: [
|
|
83
|
+
'**/node_modules/**',
|
|
84
|
+
'**/.git/**',
|
|
85
|
+
'**/.DS_Store/**'
|
|
86
|
+
]
|
|
87
|
+
});
|
|
88
|
+
cliWatcher.on('all', async (eventName, filepath)=>{
|
|
89
|
+
const basename = node_path.basename(filepath);
|
|
90
|
+
if ('add' === eventName || 'unlink' === eventName || 'change' === eventName && (CONFIG_FILES.includes(basename) || META_FILES.includes(basename))) {
|
|
91
|
+
if (isRestarting) return;
|
|
92
|
+
isRestarting = true;
|
|
93
|
+
console.log(`
|
|
94
|
+
\u{2728} ${eventName} ${picocolors.green(node_path.relative(cwd, filepath))}, dev server will restart...\n`);
|
|
95
|
+
await devServer.close();
|
|
96
|
+
await cliWatcher.close();
|
|
97
|
+
await startDevServer();
|
|
98
|
+
isRestarting = false;
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
await startDevServer();
|
|
103
|
+
const exitProcess = async ()=>{
|
|
104
|
+
try {
|
|
105
|
+
await devServer.close();
|
|
106
|
+
await cliWatcher.close();
|
|
107
|
+
} finally{
|
|
108
|
+
process.exit(0);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
process.on('SIGINT', exitProcess);
|
|
112
|
+
process.on('SIGTERM', exitProcess);
|
|
113
|
+
});
|
|
114
|
+
cli.command('build [root]').action(async (root, options)=>{
|
|
115
|
+
setNodeEnv('production');
|
|
116
|
+
const cwd = process.cwd();
|
|
117
|
+
const { config, configFilePath } = await loadConfigFile(options.config);
|
|
118
|
+
config.root = resolveDocRoot(cwd, root, config.root);
|
|
119
|
+
const docDirectory = config.root;
|
|
120
|
+
try {
|
|
121
|
+
await build({
|
|
122
|
+
docDirectory,
|
|
123
|
+
config,
|
|
124
|
+
configFilePath
|
|
125
|
+
});
|
|
126
|
+
} catch (err) {
|
|
127
|
+
logger.error(err);
|
|
128
|
+
process.exit(1);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
cli.command('preview [root]').alias('serve').option('--port [port]', 'port number').option('--host [host]', 'hostname').action(async (root, options)=>{
|
|
132
|
+
setNodeEnv('production');
|
|
133
|
+
const cwd = process.cwd();
|
|
134
|
+
const { port, host } = options || {};
|
|
135
|
+
const { config, configFilePath } = await loadConfigFile(options?.config);
|
|
136
|
+
config.root = resolveDocRoot(cwd, root, config.root);
|
|
137
|
+
await serve({
|
|
138
|
+
config,
|
|
139
|
+
host,
|
|
140
|
+
port,
|
|
141
|
+
configFilePath
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
cli.parse();
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { getIconUrlPath } from '@rspress/shared/node-utils';
|
|
|
5
5
|
import { getNodeAttribute } from '@rspress/shared/node-utils';
|
|
6
6
|
import { getSidebarDataGroup } from '@rspress/shared';
|
|
7
7
|
import { logger } from '@rspress/shared/logger';
|
|
8
|
+
import { MarkdownOptions } from '@rspress/shared';
|
|
8
9
|
import { matchPath } from '@rspress/runtime/server';
|
|
9
10
|
import { mergeDocConfig } from '@rspress/shared/node-utils';
|
|
10
11
|
import { Nav } from '@rspress/shared';
|
|
@@ -18,6 +19,7 @@ import { removeTrailingSlash } from '@rspress/shared';
|
|
|
18
19
|
import { RouteMeta } from '@rspress/shared';
|
|
19
20
|
import type { RsbuildConfig } from '@rsbuild/core';
|
|
20
21
|
import { RsbuildInstance } from '@rsbuild/core';
|
|
22
|
+
import type { Rspack as Rspack_2 } from '@rsbuild/core';
|
|
21
23
|
import { RSPRESS_TEMP_DIR } from '@rspress/shared';
|
|
22
24
|
import { RspressPlugin } from '@rspress/shared';
|
|
23
25
|
import { Sidebar } from '@rspress/shared';
|
|
@@ -56,6 +58,8 @@ declare interface BuildOptions {
|
|
|
56
58
|
*/
|
|
57
59
|
declare interface Data extends Data_2 {}
|
|
58
60
|
|
|
61
|
+
export declare function defineConfig(config: UserConfig): UserConfig;
|
|
62
|
+
|
|
59
63
|
export declare function dev(options: DevOptions): Promise<ServerInstance>;
|
|
60
64
|
|
|
61
65
|
declare interface DevOptions {
|
|
@@ -147,29 +151,29 @@ declare class PluginDriver {
|
|
|
147
151
|
routeGenerated(routes: RouteMeta[]): Promise<void[]>;
|
|
148
152
|
routeServiceGenerated(routeService: RouteService): Promise<void[]>;
|
|
149
153
|
addRuntimeModules(): Promise<Record<string, string>>;
|
|
150
|
-
addSSGRoutes(): Promise<({
|
|
151
|
-
path: string;
|
|
152
|
-
} | {
|
|
153
|
-
path: string;
|
|
154
|
-
})[]>;
|
|
155
154
|
globalUIComponents(): (string | [string, object])[];
|
|
156
155
|
globalStyles(): string[];
|
|
157
156
|
_runParallelAsyncHook<H extends RspressPluginHookKeys>(hookName: H, ...args: Parameters<Required<RspressPlugin>[H]>): Promise<Awaited<ReturnType<Required<RspressPlugin>[H]>>[]>;
|
|
158
157
|
_runSerialAsyncHook<H extends RspressPluginHookKeys>(hookName: H, ...args: Parameters<Required<RspressPlugin>[H]>): RspressPlugin;
|
|
159
158
|
}
|
|
160
159
|
|
|
161
|
-
export declare const remarkFileCodeBlock: Plugin_2<[
|
|
160
|
+
export declare const remarkFileCodeBlock: Plugin_2<[
|
|
161
|
+
{
|
|
162
162
|
filepath: string;
|
|
163
|
-
|
|
163
|
+
addDependency?: Rspack_2.LoaderContext['addDependency'];
|
|
164
|
+
}
|
|
165
|
+
], Root>;
|
|
164
166
|
|
|
165
167
|
/**
|
|
166
168
|
* Remark plugin to normalize a link href
|
|
169
|
+
* 1. add version and lang prefix to the link
|
|
170
|
+
* 2. checkDeadLinks
|
|
167
171
|
*/
|
|
168
|
-
export declare const
|
|
172
|
+
export declare const remarkLink: Plugin_2<[
|
|
169
173
|
{
|
|
170
174
|
cleanUrls: boolean | string;
|
|
171
175
|
routeService: RouteService | null;
|
|
172
|
-
|
|
176
|
+
remarkLinkOptions?: MarkdownOptions['link'];
|
|
173
177
|
__base?: string;
|
|
174
178
|
}
|
|
175
179
|
], Root>;
|
|
@@ -230,7 +234,8 @@ export declare class RouteService {
|
|
|
230
234
|
isExistRoute(routePath: string): boolean;
|
|
231
235
|
generateRoutesCode(): string;
|
|
232
236
|
private generateRoutesCodeByRouteMeta;
|
|
233
|
-
getRoutePathParts(relativePath: string):
|
|
237
|
+
getRoutePathParts(relativePath: string): string[];
|
|
238
|
+
splitRoutePathParts(relativePath: string): readonly [string, string, string];
|
|
234
239
|
normalizeRoutePath(relativePath: string): {
|
|
235
240
|
pureRoutePath: string;
|
|
236
241
|
routePath: string;
|
|
@@ -238,6 +243,7 @@ export declare class RouteService {
|
|
|
238
243
|
version: string;
|
|
239
244
|
};
|
|
240
245
|
absolutePathToRoutePath(absolutePath: string): string;
|
|
246
|
+
isInDocsDir(absolutePath: string): boolean;
|
|
241
247
|
absolutePathToRelativePath(absolutePath: string): string;
|
|
242
248
|
getRoutePageByRoutePath(routePath: string): RoutePage | undefined;
|
|
243
249
|
}
|
|
@@ -246,7 +252,7 @@ export { RSPRESS_TEMP_DIR }
|
|
|
246
252
|
|
|
247
253
|
export { RspressPlugin }
|
|
248
254
|
|
|
249
|
-
declare type RspressPluginHookKeys = 'beforeBuild' | 'config' | 'afterBuild' | 'addPages' | 'addRuntimeModules' | 'routeGenerated' | 'routeServiceGenerated' | '
|
|
255
|
+
declare type RspressPluginHookKeys = 'beforeBuild' | 'config' | 'afterBuild' | 'addPages' | 'addRuntimeModules' | 'routeGenerated' | 'routeServiceGenerated' | 'extendPageData' | 'modifySearchIndexData';
|
|
250
256
|
|
|
251
257
|
export declare function serve(options: ServeOptions): Promise<ReturnType<RsbuildInstance['preview']>>;
|
|
252
258
|
|