@rspress/core 2.0.0-beta.21 → 2.0.0-beta.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/rspress.js +15 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +144 -0
- package/dist/index.d.ts +3 -6
- package/dist/index.js +212 -79
- package/dist/index.js.LICENSE.txt +10 -0
- package/dist/loader.d.ts +1 -6
- package/dist/processor.d.ts +1 -6
- package/dist/processor.js +17 -8
- package/dist/renderPageWorker.js +193 -0
- package/dist/runtime/ssrClientEntry.js +2 -1
- package/dist/shiki-transformers.js +1 -1
- package/meta-json-schema.json +382 -0
- package/nav-json-schema.json +118 -0
- package/package.json +19 -8
package/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.22"}');
|
|
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
|
@@ -56,6 +56,8 @@ declare interface BuildOptions {
|
|
|
56
56
|
*/
|
|
57
57
|
declare interface Data extends Data_2 {}
|
|
58
58
|
|
|
59
|
+
export declare function defineConfig(config: UserConfig): UserConfig;
|
|
60
|
+
|
|
59
61
|
export declare function dev(options: DevOptions): Promise<ServerInstance>;
|
|
60
62
|
|
|
61
63
|
declare interface DevOptions {
|
|
@@ -147,11 +149,6 @@ declare class PluginDriver {
|
|
|
147
149
|
routeGenerated(routes: RouteMeta[]): Promise<void[]>;
|
|
148
150
|
routeServiceGenerated(routeService: RouteService): Promise<void[]>;
|
|
149
151
|
addRuntimeModules(): Promise<Record<string, string>>;
|
|
150
|
-
addSSGRoutes(): Promise<({
|
|
151
|
-
path: string;
|
|
152
|
-
} | {
|
|
153
|
-
path: string;
|
|
154
|
-
})[]>;
|
|
155
152
|
globalUIComponents(): (string | [string, object])[];
|
|
156
153
|
globalStyles(): string[];
|
|
157
154
|
_runParallelAsyncHook<H extends RspressPluginHookKeys>(hookName: H, ...args: Parameters<Required<RspressPlugin>[H]>): Promise<Awaited<ReturnType<Required<RspressPlugin>[H]>>[]>;
|
|
@@ -246,7 +243,7 @@ export { RSPRESS_TEMP_DIR }
|
|
|
246
243
|
|
|
247
244
|
export { RspressPlugin }
|
|
248
245
|
|
|
249
|
-
declare type RspressPluginHookKeys = 'beforeBuild' | 'config' | 'afterBuild' | 'addPages' | 'addRuntimeModules' | 'routeGenerated' | 'routeServiceGenerated' | '
|
|
246
|
+
declare type RspressPluginHookKeys = 'beforeBuild' | 'config' | 'afterBuild' | 'addPages' | 'addRuntimeModules' | 'routeGenerated' | 'routeServiceGenerated' | 'extendPageData' | 'modifySearchIndexData';
|
|
250
247
|
|
|
251
248
|
export declare function serve(options: ServeOptions): Promise<ReturnType<RsbuildInstance['preview']>>;
|
|
252
249
|
|