@rspress/core 2.0.0-beta.3 → 2.0.0-beta.30

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/335.js ADDED
@@ -0,0 +1,26 @@
1
+ export const __webpack_id__ = "335";
2
+ export const __webpack_ids__ = [
3
+ "335"
4
+ ];
5
+ export const __webpack_modules__ = {
6
+ "./src/node/medium-zoom/index.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
7
+ __webpack_require__.d(__webpack_exports__, {
8
+ pluginMediumZoom: ()=>pluginMediumZoom
9
+ });
10
+ var node_path__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("node:path");
11
+ var node_url__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("node:url");
12
+ var _rspress_shared__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("@rspress/shared");
13
+ function pluginMediumZoom(options = {}) {
14
+ const __dirname = (0, _rspress_shared__WEBPACK_IMPORTED_MODULE_2__.normalizePosixPath)(node_path__WEBPACK_IMPORTED_MODULE_0__["default"].dirname((0, node_url__WEBPACK_IMPORTED_MODULE_1__.fileURLToPath)(import.meta.url)));
15
+ return {
16
+ name: '@rspress/plugin-medium-zoom',
17
+ globalUIComponents: [
18
+ [
19
+ node_path__WEBPACK_IMPORTED_MODULE_0__["default"].join(__dirname, '../static/MediumZoom.tsx'),
20
+ options
21
+ ]
22
+ ]
23
+ };
24
+ }
25
+ }
26
+ };
package/dist/395.js ADDED
@@ -0,0 +1,74 @@
1
+ import * as __WEBPACK_EXTERNAL_MODULE_child_process__ from "child_process";
2
+ import * as __WEBPACK_EXTERNAL_MODULE_fs__ from "fs";
3
+ import * as __WEBPACK_EXTERNAL_MODULE_node_buffer_fb286294__ from "node:buffer";
4
+ import * as __WEBPACK_EXTERNAL_MODULE_node_child_process_27f17141__ from "node:child_process";
5
+ import * as __WEBPACK_EXTERNAL_MODULE_node_process_786449bf__ from "node:process";
6
+ import * as __WEBPACK_EXTERNAL_MODULE_node_timers_promises_aedbf14c__ from "node:timers/promises";
7
+ import * as __WEBPACK_EXTERNAL_MODULE_node_util_1b29d436__ from "node:util";
8
+ import * as __WEBPACK_EXTERNAL_MODULE_path__ from "path";
9
+ import * as __WEBPACK_EXTERNAL_MODULE_stream__ from "stream";
10
+ export const __webpack_id__ = "395";
11
+ export const __webpack_ids__ = [
12
+ "395"
13
+ ];
14
+ export const __webpack_modules__ = {
15
+ "./src/node/last-updated/index.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
16
+ __webpack_require__.d(__webpack_exports__, {
17
+ pluginLastUpdated: ()=>pluginLastUpdated
18
+ });
19
+ var execa__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("../../node_modules/.pnpm/execa@8.0.1/node_modules/execa/index.js");
20
+ function transform(timestamp, lang) {
21
+ return new Date(timestamp).toLocaleString(lang || 'zh');
22
+ }
23
+ async function getGitLastUpdatedTimeStamp(filePath) {
24
+ let lastUpdated;
25
+ try {
26
+ const { stdout } = await (0, execa__WEBPACK_IMPORTED_MODULE_0__.Ho)('git', [
27
+ 'log',
28
+ '-1',
29
+ '--format=%at',
30
+ filePath
31
+ ]);
32
+ lastUpdated = 1000 * Number(stdout);
33
+ } catch (_e) {}
34
+ return lastUpdated;
35
+ }
36
+ function pluginLastUpdated() {
37
+ return {
38
+ name: '@rspress/plugin-last-updated',
39
+ async extendPageData (pageData) {
40
+ const { _filepath, lang } = pageData;
41
+ const lastUpdated = await getGitLastUpdatedTimeStamp(_filepath);
42
+ if (lastUpdated) pageData.lastUpdatedTime = transform(lastUpdated, lang);
43
+ }
44
+ };
45
+ }
46
+ },
47
+ child_process: function(module) {
48
+ module.exports = __WEBPACK_EXTERNAL_MODULE_child_process__;
49
+ },
50
+ fs: function(module) {
51
+ module.exports = __WEBPACK_EXTERNAL_MODULE_fs__;
52
+ },
53
+ "node:buffer": function(module) {
54
+ module.exports = __WEBPACK_EXTERNAL_MODULE_node_buffer_fb286294__;
55
+ },
56
+ "node:child_process": function(module) {
57
+ module.exports = __WEBPACK_EXTERNAL_MODULE_node_child_process_27f17141__;
58
+ },
59
+ "node:process": function(module) {
60
+ module.exports = __WEBPACK_EXTERNAL_MODULE_node_process_786449bf__;
61
+ },
62
+ "node:timers/promises": function(module) {
63
+ module.exports = __WEBPACK_EXTERNAL_MODULE_node_timers_promises_aedbf14c__;
64
+ },
65
+ "node:util": function(module) {
66
+ module.exports = __WEBPACK_EXTERNAL_MODULE_node_util_1b29d436__;
67
+ },
68
+ path: function(module) {
69
+ module.exports = __WEBPACK_EXTERNAL_MODULE_path__;
70
+ },
71
+ stream: function(module) {
72
+ module.exports = __WEBPACK_EXTERNAL_MODULE_stream__;
73
+ }
74
+ };
package/dist/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { }
package/dist/cli.js ADDED
@@ -0,0 +1,142 @@
1
+ import node_path from "node:path";
2
+ import { logger } from "@rspress/shared/logger";
3
+ import { cac } from "cac";
4
+ import chokidar from "chokidar";
5
+ import picocolors from "picocolors";
6
+ import { build, dev, serve } from "./index.js";
7
+ import node_fs from "node:fs";
8
+ import { DEFAULT_CONFIG_EXTENSIONS, DEFAULT_CONFIG_NAME } from "@rspress/shared/constants";
9
+ var package_namespaceObject = JSON.parse('{"rE":"2.0.0-beta.30"}');
10
+ const findConfig = (basePath)=>DEFAULT_CONFIG_EXTENSIONS.map((ext)=>basePath + ext).find(node_fs.existsSync);
11
+ async function loadConfigFile(customConfigFile) {
12
+ const baseDir = process.cwd();
13
+ let configFilePath = '';
14
+ configFilePath = customConfigFile ? node_path.isAbsolute(customConfigFile) ? customConfigFile : node_path.join(baseDir, customConfigFile) : findConfig(node_path.join(baseDir, DEFAULT_CONFIG_NAME));
15
+ if (!configFilePath) {
16
+ logger.info(`No config file found in ${baseDir}`);
17
+ return {
18
+ config: {},
19
+ configFilePath: ''
20
+ };
21
+ }
22
+ const { loadConfig } = await import("@rsbuild/core");
23
+ const { content } = await loadConfig({
24
+ cwd: node_path.dirname(configFilePath),
25
+ path: configFilePath
26
+ });
27
+ return {
28
+ config: content,
29
+ configFilePath
30
+ };
31
+ }
32
+ function resolveDocRoot(cwd, cliRoot, configRoot) {
33
+ if (cliRoot) return node_path.join(cwd, cliRoot);
34
+ if (configRoot) return node_path.isAbsolute(configRoot) ? configRoot : node_path.join(cwd, configRoot);
35
+ return node_path.join(cwd, 'docs');
36
+ }
37
+ const CONFIG_FILES = [
38
+ 'rspress.config.ts',
39
+ 'rspress.config.js'
40
+ ];
41
+ const META_FILES = [
42
+ '_meta.json',
43
+ '_nav.json'
44
+ ];
45
+ const cli = cac('rspress').version(package_namespaceObject.rE).help();
46
+ const landingMessage = `\u{1F525} Rspress v${package_namespaceObject.rE}\n`;
47
+ logger.greet(landingMessage);
48
+ const setNodeEnv = (env)=>{
49
+ process.env.NODE_ENV = env;
50
+ };
51
+ cli.option('-c,--config [config]', 'Specify the path to the config file');
52
+ cli.command('[root]', 'start dev server').alias('dev').option('--port [port]', 'port number').option('--host [host]', 'hostname').action(async (root, options)=>{
53
+ setNodeEnv('development');
54
+ let isRestarting = false;
55
+ const cwd = process.cwd();
56
+ let cliWatcher;
57
+ let devServer;
58
+ const startDevServer = async ()=>{
59
+ const { port, host } = options || {};
60
+ const { config, configFilePath } = await loadConfigFile(options?.config);
61
+ config.root = resolveDocRoot(cwd, root, config.root);
62
+ const docDirectory = config.root;
63
+ devServer = await dev({
64
+ appDirectory: cwd,
65
+ docDirectory,
66
+ config,
67
+ configFilePath,
68
+ extraBuilderConfig: {
69
+ server: {
70
+ port,
71
+ host
72
+ }
73
+ }
74
+ });
75
+ cliWatcher = chokidar.watch([
76
+ `${cwd}/**/{${CONFIG_FILES.join(',')}}`,
77
+ docDirectory
78
+ ], {
79
+ ignoreInitial: true,
80
+ ignored: [
81
+ '**/node_modules/**',
82
+ '**/.git/**',
83
+ '**/.DS_Store/**'
84
+ ]
85
+ });
86
+ cliWatcher.on('all', async (eventName, filepath)=>{
87
+ const basename = node_path.basename(filepath);
88
+ if ('add' === eventName || 'unlink' === eventName || 'change' === eventName && (CONFIG_FILES.includes(basename) || META_FILES.includes(basename))) {
89
+ if (isRestarting) return;
90
+ isRestarting = true;
91
+ console.log(`
92
+ \u{2728} ${eventName} ${picocolors.green(node_path.relative(cwd, filepath))}, dev server will restart...\n`);
93
+ await devServer.close();
94
+ await cliWatcher.close();
95
+ await startDevServer();
96
+ isRestarting = false;
97
+ }
98
+ });
99
+ };
100
+ await startDevServer();
101
+ const exitProcess = async ()=>{
102
+ try {
103
+ await devServer.close();
104
+ await cliWatcher.close();
105
+ } finally{
106
+ process.exit(0);
107
+ }
108
+ };
109
+ process.on('SIGINT', exitProcess);
110
+ process.on('SIGTERM', exitProcess);
111
+ });
112
+ cli.command('build [root]').action(async (root, options)=>{
113
+ setNodeEnv('production');
114
+ const cwd = process.cwd();
115
+ const { config, configFilePath } = await loadConfigFile(options.config);
116
+ config.root = resolveDocRoot(cwd, root, config.root);
117
+ const docDirectory = config.root;
118
+ try {
119
+ await build({
120
+ docDirectory,
121
+ config,
122
+ configFilePath
123
+ });
124
+ } catch (err) {
125
+ logger.error(err);
126
+ process.exit(1);
127
+ }
128
+ });
129
+ cli.command('preview [root]').alias('serve').option('--port [port]', 'port number').option('--host [host]', 'hostname').action(async (root, options)=>{
130
+ setNodeEnv('production');
131
+ const cwd = process.cwd();
132
+ const { port, host } = options || {};
133
+ const { config, configFilePath } = await loadConfigFile(options?.config);
134
+ config.root = resolveDocRoot(cwd, root, config.root);
135
+ await serve({
136
+ config,
137
+ host,
138
+ port,
139
+ configFilePath
140
+ });
141
+ });
142
+ cli.parse();
package/dist/index.d.ts CHANGED
@@ -1,21 +1,41 @@
1
1
  import { AdditionalPage } from '@rspress/shared';
2
2
  import type { Data as Data_2 } from 'unist';
3
3
  import { DefaultThemeConfig } from '@rspress/shared';
4
+ import { getIconUrlPath } from '@rspress/shared/node-utils';
5
+ import { getNodeAttribute } from '@rspress/shared/node-utils';
6
+ import { getSidebarDataGroup } from '@rspress/shared';
7
+ import { logger } from '@rspress/shared/logger';
8
+ import { MarkdownOptions } from '@rspress/shared';
9
+ import { matchPath } from '@rspress/runtime/server';
4
10
  import { mergeDocConfig } from '@rspress/shared/node-utils';
11
+ import { Nav } from '@rspress/shared';
12
+ import { NavItemWithLink } from '@rspress/shared';
5
13
  import type { Node as Node_3 } from 'unist';
6
- import type { PageIndexInfo } from '@rspress/shared';
14
+ import { normalizeHref } from '@rspress/shared';
15
+ import { normalizePosixPath } from '@rspress/shared';
16
+ import { PageIndexInfo } from '@rspress/shared';
7
17
  import type { Plugin as Plugin_2 } from 'unified';
8
- import type { RouteMeta } from '@rspress/shared';
18
+ import { removeTrailingSlash } from '@rspress/shared';
19
+ import { RouteMeta } from '@rspress/shared';
9
20
  import type { RsbuildConfig } from '@rsbuild/core';
10
21
  import { RsbuildInstance } from '@rsbuild/core';
11
- import type { RspressPlugin } from '@rspress/shared';
12
- import type { UserConfig } from '@rspress/shared';
22
+ import type { Rspack as Rspack_2 } from '@rsbuild/core';
23
+ import { RSPRESS_TEMP_DIR } from '@rspress/shared';
24
+ import { RspressPlugin } from '@rspress/shared';
25
+ import { Sidebar } from '@rspress/shared';
26
+ import { SidebarDivider } from '@rspress/shared';
27
+ import { SidebarGroup } from '@rspress/shared';
28
+ import { SidebarItem } from '@rspress/shared';
29
+ import { SidebarSectionHeader } from '@rspress/shared';
30
+ import { UserConfig } from '@rspress/shared';
31
+ import { withBase } from '@rspress/shared';
13
32
 
14
33
  export declare function build(options: BuildOptions): Promise<void>;
15
34
 
16
35
  declare interface BuildOptions {
17
36
  docDirectory: string;
18
37
  config: UserConfig;
38
+ configFilePath: string;
19
39
  }
20
40
 
21
41
  /**
@@ -38,17 +58,41 @@ declare interface BuildOptions {
38
58
  */
39
59
  declare interface Data extends Data_2 {}
40
60
 
61
+ export declare function defineConfig(config: UserConfig): UserConfig;
62
+
41
63
  export declare function dev(options: DevOptions): Promise<ServerInstance>;
42
64
 
43
65
  declare interface DevOptions {
44
66
  appDirectory: string;
45
67
  docDirectory: string;
46
68
  config: UserConfig;
69
+ configFilePath: string;
47
70
  extraBuilderConfig?: RsbuildConfig;
48
71
  }
49
72
 
73
+ export { getIconUrlPath }
74
+
75
+ export { getNodeAttribute }
76
+
77
+ export { getSidebarDataGroup }
78
+
79
+ declare interface InitOptions {
80
+ scanDir: string;
81
+ config: UserConfig;
82
+ runtimeTempDir: string;
83
+ pluginDriver: PluginDriver;
84
+ }
85
+
86
+ export { logger }
87
+
88
+ export { matchPath }
89
+
50
90
  export { mergeDocConfig }
51
91
 
92
+ export { Nav }
93
+
94
+ export { NavItemWithLink }
95
+
52
96
  /**
53
97
  * Abstract mdast node.
54
98
  *
@@ -69,6 +113,12 @@ declare interface Node_2 extends Node_3 {
69
113
  data?: Data | undefined;
70
114
  }
71
115
 
116
+ export { normalizeHref }
117
+
118
+ export { normalizePosixPath }
119
+
120
+ export { PageIndexInfo }
121
+
72
122
  /**
73
123
  * Abstract mdast node that contains other mdast nodes (*children*).
74
124
  *
@@ -85,7 +135,8 @@ declare interface Parent extends Node_2 {
85
135
 
86
136
  declare class PluginDriver {
87
137
  #private;
88
- constructor(config: UserConfig, isProd: boolean);
138
+ constructor(config: UserConfig, configFilePath: string, isProd: boolean);
139
+ getConfigFilePath(): string;
89
140
  init(): Promise<void>;
90
141
  addPlugin(plugin: RspressPlugin): void;
91
142
  getPlugins(): RspressPlugin[];
@@ -100,28 +151,35 @@ declare class PluginDriver {
100
151
  routeGenerated(routes: RouteMeta[]): Promise<void[]>;
101
152
  routeServiceGenerated(routeService: RouteService): Promise<void[]>;
102
153
  addRuntimeModules(): Promise<Record<string, string>>;
103
- addSSGRoutes(): Promise<({
104
- path: string;
105
- } | {
106
- path: string;
107
- })[]>;
108
154
  globalUIComponents(): (string | [string, object])[];
109
155
  globalStyles(): string[];
110
156
  _runParallelAsyncHook<H extends RspressPluginHookKeys>(hookName: H, ...args: Parameters<Required<RspressPlugin>[H]>): Promise<Awaited<ReturnType<Required<RspressPlugin>[H]>>[]>;
111
157
  _runSerialAsyncHook<H extends RspressPluginHookKeys>(hookName: H, ...args: Parameters<Required<RspressPlugin>[H]>): RspressPlugin;
112
158
  }
113
159
 
160
+ export declare const remarkFileCodeBlock: Plugin_2<[
161
+ {
162
+ filepath: string;
163
+ addDependency?: Rspack_2.LoaderContext['addDependency'];
164
+ }
165
+ ], Root>;
166
+
114
167
  /**
115
168
  * Remark plugin to normalize a link href
169
+ * 1. add version and lang prefix to the link
170
+ * 2. checkDeadLinks
116
171
  */
117
- export declare const remarkPluginNormalizeLink: Plugin_2<[
172
+ export declare const remarkLink: Plugin_2<[
118
173
  {
119
- root: string;
120
174
  cleanUrls: boolean | string;
121
- routeService?: RouteService;
175
+ routeService: RouteService | null;
176
+ remarkLinkOptions?: MarkdownOptions['link'];
177
+ __base?: string;
122
178
  }
123
179
  ], Root>;
124
180
 
181
+ export { removeTrailingSlash }
182
+
125
183
  /**
126
184
  * Document fragment or a whole document.
127
185
  *
@@ -151,33 +209,56 @@ declare type RootContent = RootContentMap[keyof RootContentMap];
151
209
  */
152
210
  declare interface RootData extends Data {}
153
211
 
212
+ export { RouteMeta }
213
+
214
+ declare class RoutePage {
215
+ #private;
216
+ routeMeta: RouteMeta;
217
+ static create(absolutePath: string, docsDir: string): RoutePage;
218
+ static createFromExternal(routePath: string, filepath: string, docDir: string): RoutePage;
219
+ private constructor();
220
+ static generateRouteMeta(routePath: string, filepath: string, docDir: string): RouteMeta;
221
+ }
222
+
154
223
  export declare class RouteService {
155
224
  #private;
156
- routeData: Map<string, RouteMeta>;
157
- constructor(scanDir: string, userConfig: UserConfig, tempDir: string, pluginDriver: PluginDriver);
225
+ routeData: Map<string, RoutePage>;
226
+ static __instance__: RouteService | null;
227
+ static getInstance(): RouteService;
228
+ static create(options: InitOptions): Promise<RouteService>;
229
+ private constructor();
158
230
  get extensions(): readonly string[];
159
- init(): Promise<void>;
160
- addRoute(routeInfo: RouteMeta): void;
161
- removeRoute(filePath: string): void;
231
+ addRoute(routePage: RoutePage): Promise<void>;
162
232
  getRoutes(): RouteMeta[];
163
- isExistRoute(routePath: string): boolean;
164
- isEmpty(): boolean;
165
- generateRoutesCode(isStaticImport?: boolean): string;
166
- generateRoutesCodeByRouteMeta(routeMeta: RouteMeta[], isStaticImport: boolean): string;
167
- getRoutePathParts(routePath: string): readonly [string, string, string];
168
- normalizeRoutePath(routePath: string): {
233
+ getRoutePages(): RoutePage[];
234
+ isExistRoute(link: string): boolean;
235
+ generateRoutesCode(): string;
236
+ private generateRoutesCodeByRouteMeta;
237
+ getRoutePathParts(relativePath: string): string[];
238
+ splitRoutePathParts(relativePath: string): readonly [string, string, string];
239
+ normalizeRoutePath(relativePath: string): {
240
+ pureRoutePath: string;
169
241
  routePath: string;
170
242
  lang: string;
171
243
  version: string;
172
244
  };
245
+ absolutePathToRoutePath(absolutePath: string): string;
246
+ isInDocsDir(absolutePath: string): boolean;
247
+ absolutePathToRelativePath(absolutePath: string): string;
248
+ getRoutePageByRoutePath(routePath: string): RoutePage | undefined;
173
249
  }
174
250
 
175
- declare type RspressPluginHookKeys = 'beforeBuild' | 'afterBuild' | 'addPages' | 'addRuntimeModules' | 'routeGenerated' | 'routeServiceGenerated' | 'addSSGRoutes' | 'extendPageData' | 'modifySearchIndexData';
251
+ export { RSPRESS_TEMP_DIR }
252
+
253
+ export { RspressPlugin }
254
+
255
+ declare type RspressPluginHookKeys = 'beforeBuild' | 'config' | 'afterBuild' | 'addPages' | 'addRuntimeModules' | 'routeGenerated' | 'routeServiceGenerated' | 'extendPageData' | 'modifySearchIndexData';
176
256
 
177
257
  export declare function serve(options: ServeOptions): Promise<ReturnType<RsbuildInstance['preview']>>;
178
258
 
179
259
  declare interface ServeOptions {
180
260
  config: UserConfig;
261
+ configFilePath: string;
181
262
  port?: number;
182
263
  host?: string;
183
264
  }
@@ -186,7 +267,18 @@ declare interface ServerInstance {
186
267
  close: () => Promise<void>;
187
268
  }
188
269
 
270
+ export { Sidebar }
271
+
272
+ export { SidebarDivider }
273
+
274
+ export { SidebarGroup }
275
+
276
+ export { SidebarItem }
277
+
278
+ export { SidebarSectionHeader }
279
+
280
+ export { UserConfig }
189
281
 
190
- export * from "@rspress/shared";
282
+ export { withBase }
191
283
 
192
284
  export { }