@rspress/core 2.0.0-beta.0 → 2.0.0-beta.1

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/index.d.ts CHANGED
@@ -1,6 +1,14 @@
1
+ import { AdditionalPage } from '@rspress/shared';
2
+ import type { Data as Data_2 } from 'unist';
3
+ import { DefaultThemeConfig } from '@rspress/shared';
1
4
  import { mergeDocConfig } from '@rspress/shared/node-utils';
5
+ import type { Node as Node_3 } from 'unist';
6
+ import type { PageIndexInfo } from '@rspress/shared';
7
+ import type { Plugin as Plugin_2 } from 'unified';
8
+ import type { RouteMeta } from '@rspress/shared';
2
9
  import type { RsbuildConfig } from '@rsbuild/core';
3
10
  import { RsbuildInstance } from '@rsbuild/core';
11
+ import type { RspressPlugin } from '@rspress/shared';
4
12
  import type { UserConfig } from '@rspress/shared';
5
13
 
6
14
  export declare function build(options: BuildOptions): Promise<void>;
@@ -10,6 +18,26 @@ declare interface BuildOptions {
10
18
  config: UserConfig;
11
19
  }
12
20
 
21
+ /**
22
+ * Info associated with mdast nodes by the ecosystem.
23
+ *
24
+ * This space is guaranteed to never be specified by unist or mdast.
25
+ * But you can use it in utilities and plugins to store data.
26
+ *
27
+ * This type can be augmented to register custom data.
28
+ * For example:
29
+ *
30
+ * ```ts
31
+ * declare module 'mdast' {
32
+ * interface Data {
33
+ * // `someNode.data.myId` is typed as `number | undefined`
34
+ * myId?: number | undefined
35
+ * }
36
+ * }
37
+ * ```
38
+ */
39
+ declare interface Data extends Data_2 {}
40
+
13
41
  export declare function dev(options: DevOptions): Promise<ServerInstance>;
14
42
 
15
43
  declare interface DevOptions {
@@ -21,6 +49,131 @@ declare interface DevOptions {
21
49
 
22
50
  export { mergeDocConfig }
23
51
 
52
+ /**
53
+ * Abstract mdast node.
54
+ *
55
+ * This interface is supposed to be extended.
56
+ * If you can use {@link Literal} or {@link Parent}, you should.
57
+ * But for example in markdown, a thematic break (`***`) is neither literal nor
58
+ * parent, but still a node.
59
+ *
60
+ * To register custom mdast nodes, add them to {@link RootContentMap} and other
61
+ * places where relevant (such as {@link ElementContentMap}).
62
+ *
63
+ * For a union of all registered mdast nodes, see {@link Nodes}.
64
+ */
65
+ declare interface Node_2 extends Node_3 {
66
+ /**
67
+ * Info from the ecosystem.
68
+ */
69
+ data?: Data | undefined;
70
+ }
71
+
72
+ /**
73
+ * Abstract mdast node that contains other mdast nodes (*children*).
74
+ *
75
+ * This interface is supposed to be extended if you make custom mdast nodes.
76
+ *
77
+ * For a union of all registered mdast parents, see {@link Parents}.
78
+ */
79
+ declare interface Parent extends Node_2 {
80
+ /**
81
+ * List of children.
82
+ */
83
+ children: RootContent[];
84
+ }
85
+
86
+ declare class PluginDriver {
87
+ #private;
88
+ constructor(config: UserConfig, isProd: boolean);
89
+ init(): Promise<void>;
90
+ addPlugin(plugin: RspressPlugin): void;
91
+ getPlugins(): RspressPlugin[];
92
+ clearPlugins(): void;
93
+ removePlugin(pluginName: string): void;
94
+ modifyConfig(): Promise<UserConfig<DefaultThemeConfig>>;
95
+ beforeBuild(): Promise<void[]>;
96
+ afterBuild(): Promise<void[]>;
97
+ modifySearchIndexData(pages: PageIndexInfo[]): Promise<void[]>;
98
+ extendPageData(pageData: PageIndexInfo): Promise<void[]>;
99
+ addPages(): Promise<AdditionalPage[]>;
100
+ routeGenerated(routes: RouteMeta[]): Promise<void[]>;
101
+ routeServiceGenerated(routeService: RouteService): Promise<void[]>;
102
+ addRuntimeModules(): Promise<Record<string, string>>;
103
+ addSSGRoutes(): Promise<({
104
+ path: string;
105
+ } | {
106
+ path: string;
107
+ })[]>;
108
+ globalUIComponents(): (string | [string, object])[];
109
+ globalStyles(): string[];
110
+ _runParallelAsyncHook<H extends RspressPluginHookKeys>(hookName: H, ...args: Parameters<Required<RspressPlugin>[H]>): Promise<Awaited<ReturnType<Required<RspressPlugin>[H]>>[]>;
111
+ _runSerialAsyncHook<H extends RspressPluginHookKeys>(hookName: H, ...args: Parameters<Required<RspressPlugin>[H]>): RspressPlugin;
112
+ }
113
+
114
+ /**
115
+ * Remark plugin to normalize a link href
116
+ */
117
+ export declare const remarkPluginNormalizeLink: Plugin_2<[
118
+ {
119
+ root: string;
120
+ cleanUrls: boolean | string;
121
+ routeService?: RouteService;
122
+ }
123
+ ], Root>;
124
+
125
+ /**
126
+ * Document fragment or a whole document.
127
+ *
128
+ * Should be used as the root of a tree and must not be used as a child.
129
+ */
130
+ declare interface Root extends Parent {
131
+ /**
132
+ * Node type of mdast root.
133
+ */
134
+ type: "root";
135
+ /**
136
+ * Data associated with the mdast root.
137
+ */
138
+ data?: RootData | undefined;
139
+ }
140
+
141
+ /**
142
+ * Union of registered mdast nodes that can occur in {@link Root}.
143
+ *
144
+ * To register custom mdast nodes, add them to {@link RootContentMap}.
145
+ * They will be automatically added here.
146
+ */
147
+ declare type RootContent = RootContentMap[keyof RootContentMap];
148
+
149
+ /**
150
+ * Info associated with mdast root nodes by the ecosystem.
151
+ */
152
+ declare interface RootData extends Data {}
153
+
154
+ export declare class RouteService {
155
+ #private;
156
+ routeData: Map<string, RouteMeta>;
157
+ constructor(scanDir: string, userConfig: UserConfig, tempDir: string, pluginDriver: PluginDriver);
158
+ get extensions(): readonly string[];
159
+ init(): Promise<void>;
160
+ addRoute(routeInfo: RouteMeta): void;
161
+ removeRoute(filePath: string): void;
162
+ 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): {
169
+ routePath: string;
170
+ lang: string;
171
+ version: string;
172
+ };
173
+ }
174
+
175
+ declare type RspressPluginHookKeys = 'beforeBuild' | 'afterBuild' | 'addPages' | 'addRuntimeModules' | 'routeGenerated' | 'routeServiceGenerated' | 'addSSGRoutes' | 'extendPageData' | 'modifySearchIndexData';
176
+
24
177
  export declare function serve(options: ServeOptions): Promise<ReturnType<RsbuildInstance['preview']>>;
25
178
 
26
179
  declare interface ServeOptions {