@vuepress/core 2.0.0-rc.3 → 2.0.0-rc.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/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { MarkdownLink, MarkdownSfcBlocks, MarkdownOptions, Markdown, MarkdownHeader } from '@vuepress/markdown';
2
- import { PageBase, PageData, PageFrontmatter, SiteData } from '@vuepress/shared';
3
- export { HeadAttrsConfig, HeadConfig, HeadTag, HeadTagEmpty, HeadTagNonEmpty, LocaleConfig, LocaleData, PageData, PageFrontmatter, PageHeader, SiteData, SiteLocaleConfig } from '@vuepress/shared';
4
- import { TemplateRenderer } from '@vuepress/utils';
1
+ import { HeadAttrsConfig, HeadConfig, HeadTag, HeadTagEmpty, HeadTagNonEmpty, LocaleConfig, LocaleData, PageBase, PageData, PageData as PageData$1, PageFrontmatter, PageFrontmatter as PageFrontmatter$1, PageHeader, PageHeader as PageHeader$1, SiteData, SiteData as SiteData$1, SiteLocaleConfig } from "@vuepress/shared";
2
+ import { TemplateRenderer } from "@vuepress/utils";
3
+ import { Markdown, MarkdownLink, MarkdownOptions, MarkdownSfcBlocks } from "@vuepress/markdown";
5
4
 
5
+ //#region src/types/bundler.d.ts
6
6
  /**
7
7
  * Vuepress bundler
8
8
  *
@@ -11,179 +11,188 @@ import { TemplateRenderer } from '@vuepress/utils';
11
11
  * - build: bundle assets for deployment
12
12
  */
13
13
  interface Bundler {
14
- name: string;
15
- dev: (app: App) => Promise<() => Promise<void>>;
16
- build: (app: App) => Promise<void>;
14
+ /**
15
+ * Name of the bundler
16
+ */
17
+ name: string;
18
+ /**
19
+ * Method to run vuepress app in dev mode, starting dev server
20
+ */
21
+ dev: (app: App) => Promise<() => Promise<void>>;
22
+ /**
23
+ * Method to run vuepress app in build mode, generating static pages and assets
24
+ */
25
+ build: (app: App) => Promise<void>;
17
26
  }
18
-
27
+ type BundlerOptions = Record<string, unknown>;
28
+ //#endregion
29
+ //#region src/types/page.d.ts
19
30
  /**
20
31
  * Vuepress Page
21
32
  */
22
- type Page<ExtraPageData extends Record<any, any> = Record<never, never>, ExtraPageFrontmatter extends Record<any, any> = Record<string, unknown>, ExtraPageFields extends Record<any, any> = Record<never, never>> = PageBase<ExtraPageFrontmatter> & ExtraPageFields & {
23
- /**
24
- * Data of the page, which will be available in client code
25
- */
26
- data: PageData<ExtraPageData, ExtraPageFrontmatter>;
27
- /**
28
- * Raw Content of the page
29
- */
30
- content: string;
31
- /**
32
- * Rendered content of the page
33
- */
34
- contentRendered: string;
35
- /**
36
- * Date of the page, in 'yyyy-MM-dd' format
37
- *
38
- * @example '2020-09-09'
39
- */
40
- date: string;
41
- /**
42
- * Dependencies of the page
43
- */
44
- deps: string[];
45
- /**
46
- * Links of the page
47
- */
48
- links: MarkdownLink[];
49
- /**
50
- * Markdown env object of the page
51
- */
52
- markdownEnv: Record<string, unknown>;
53
- /**
54
- * Path of the page that inferred from file path
55
- *
56
- * If the page does not come from a file, it would be `null`
57
- *
58
- * @example '/guide/index.html'
59
- */
60
- pathInferred: string | null;
61
- /**
62
- * Locale path prefix of the page
63
- *
64
- * @example '/getting-started.html' -> '/'
65
- * @example '/en/getting-started.html' -> '/en/'
66
- * @example '/zh/getting-started.html' -> '/zh/'
67
- */
68
- pathLocale: string;
69
- /**
70
- * Permalink of the page
71
- *
72
- * If the page does not have a permalink, it would be `null`
73
- */
74
- permalink: string | null;
75
- /**
76
- * Custom data to be attached to route record
77
- */
78
- routeMeta: Record<string, unknown>;
79
- /**
80
- * Extracted sfc blocks of the page
81
- */
82
- sfcBlocks: MarkdownSfcBlocks;
83
- /**
84
- * Slug of the page
85
- */
86
- slug: string;
87
- /**
88
- * Source file path
89
- *
90
- * If the page does not come from a file, it would be `null`
91
- */
92
- filePath: string | null;
93
- /**
94
- * Source file path relative to source directory
95
- *
96
- * If the page does not come from a file, it would be `null`
97
- */
98
- filePathRelative: string | null;
99
- /**
100
- * Component file path
101
- */
102
- componentFilePath: string;
103
- /**
104
- * Component file path relative to temp directory
105
- */
106
- componentFilePathRelative: string;
107
- /**
108
- * Chunk file path
109
- */
110
- chunkFilePath: string;
111
- /**
112
- * Chunk file path relative to temp directory
113
- */
114
- chunkFilePathRelative: string;
115
- /**
116
- * Chunk name
117
- *
118
- * This will only take effect in webpack
119
- */
120
- chunkName: string;
121
- /**
122
- * Rendered html file path
123
- */
124
- htmlFilePath: string;
125
- /**
126
- * Rendered html file path relative to dest directory
127
- */
128
- htmlFilePathRelative: string;
33
+ type Page<ExtraPageData extends Record<string, unknown> = Record<string, unknown>, ExtraPageFrontmatter extends Record<string, unknown> = Record<string, unknown>, ExtraPageFields extends Record<string, unknown> = Record<string, unknown>> = ExtraPageFields & PageBase<ExtraPageFrontmatter> & {
34
+ /**
35
+ * Data of the page, which will be available in client code
36
+ */
37
+ data: PageData$1<ExtraPageData, ExtraPageFrontmatter>;
38
+ /**
39
+ * Raw Content of the page
40
+ */
41
+ content: string;
42
+ /**
43
+ * Rendered content of the page
44
+ */
45
+ contentRendered: string;
46
+ /**
47
+ * Date of the page, in 'yyyy-MM-dd' format
48
+ *
49
+ * @example '2020-09-09'
50
+ */
51
+ date: string;
52
+ /**
53
+ * Dependencies of the page
54
+ */
55
+ deps: string[];
56
+ /**
57
+ * Headers of the page
58
+ */
59
+ headers: PageHeader$1[];
60
+ /**
61
+ * Links of the page
62
+ */
63
+ links: MarkdownLink[];
64
+ /**
65
+ * Markdown env object of the page
66
+ */
67
+ markdownEnv: Record<string, unknown>;
68
+ /**
69
+ * Path of the page that inferred from file path
70
+ *
71
+ * If the page does not come from a file, it would be `null`
72
+ *
73
+ * @example '/guide/index.html'
74
+ */
75
+ pathInferred: string | null;
76
+ /**
77
+ * Locale path prefix of the page
78
+ *
79
+ * @example '/getting-started.html' -> '/'
80
+ * @example '/en/getting-started.html' -> '/en/'
81
+ * @example '/zh/getting-started.html' -> '/zh/'
82
+ */
83
+ pathLocale: string;
84
+ /**
85
+ * Permalink of the page
86
+ *
87
+ * If the page does not have a permalink, it would be `null`
88
+ */
89
+ permalink: string | null;
90
+ /**
91
+ * Custom data to be attached to route record
92
+ */
93
+ routeMeta: Record<string, unknown>;
94
+ /**
95
+ * Extracted sfc blocks of the page
96
+ */
97
+ sfcBlocks: MarkdownSfcBlocks;
98
+ /**
99
+ * Slug of the page
100
+ */
101
+ slug: string;
102
+ /**
103
+ * Source file path
104
+ *
105
+ * If the page does not come from a file, it would be `null`
106
+ */
107
+ filePath: string | null;
108
+ /**
109
+ * Source file path relative to source directory
110
+ *
111
+ * If the page does not come from a file, it would be `null`
112
+ */
113
+ filePathRelative: string | null;
114
+ /**
115
+ * Chunk file path
116
+ */
117
+ chunkFilePath: string;
118
+ /**
119
+ * Chunk file path relative to temp directory
120
+ */
121
+ chunkFilePathRelative: string;
122
+ /**
123
+ * Chunk name
124
+ *
125
+ * This will only take effect in webpack
126
+ */
127
+ chunkName: string;
128
+ /**
129
+ * Rendered html file path
130
+ */
131
+ htmlFilePath: string;
132
+ /**
133
+ * Rendered html file path relative to dest directory
134
+ */
135
+ htmlFilePathRelative: string;
129
136
  };
130
137
  /**
131
138
  * Options to create vuepress page
132
139
  */
133
140
  interface PageOptions {
134
- /**
135
- * If `filePath` is not set, this option will be used as the raw
136
- * markdown content of the page.
137
- *
138
- * If `filePath` is set, this option will be ignored, while the
139
- * content of the file will be used.
140
- */
141
- content?: string;
142
- /**
143
- * Absolute file path of the markdown source file.
144
- */
145
- filePath?: string;
146
- /**
147
- * Default frontmatter of the page, which could be overridden by
148
- * the frontmatter of the markdown content.
149
- */
150
- frontmatter?: PageFrontmatter;
151
- /**
152
- * If this option is set, it will be used as the final route path
153
- * of the page, ignoring the relative path and permalink.
154
- */
155
- path?: string;
141
+ /**
142
+ * The raw markdown content of the page.
143
+ *
144
+ * If `content` is not provided, the file content of the `filePath`
145
+ * will be used.
146
+ */
147
+ content?: string;
148
+ /**
149
+ * Absolute file path of the markdown source file.
150
+ */
151
+ filePath?: string;
152
+ /**
153
+ * Default frontmatter of the page, which could be overridden by
154
+ * the frontmatter of the markdown content.
155
+ */
156
+ frontmatter?: PageFrontmatter$1;
157
+ /**
158
+ * If this option is set, it will be used as the final route path
159
+ * of the page, ignoring the relative path and permalink.
160
+ */
161
+ path?: string;
156
162
  }
157
-
163
+ //#endregion
164
+ //#region src/types/pluginApi/hooks.d.ts
158
165
  type PromiseOrNot<T> = Promise<T> | T;
159
166
  interface Closable {
160
- close(): void;
167
+ close(): void;
161
168
  }
162
- interface Hook<Exposed, Normalized = Exposed, Result = Normalized extends (...args: any) => infer U ? U extends Promise<infer V> ? V : U : void> {
163
- exposed: Exposed;
164
- normalized: Normalized;
165
- result: Result;
169
+ interface Hook<Exposed, Normalized = Exposed, Result = (Normalized extends ((...args: any) => infer U) ? U extends Promise<infer V> ? V : U : never)> {
170
+ exposed: Exposed;
171
+ normalized: Normalized;
172
+ result: Result;
166
173
  }
167
174
  type LifeCycleHook<T extends unknown[] = []> = Hook<(app: App, ...args: T) => PromiseOrNot<void>>;
168
175
  type ExtendsHook<T> = Hook<(extendable: T, app: App) => PromiseOrNot<void>>;
169
176
  type ClientConfigFileHook = Hook<string | ((app: App) => PromiseOrNot<string>), (app: App) => Promise<string>>;
170
- type AliasDefineHook = Hook<Record<string, any> | ((app: App, isServer: boolean) => PromiseOrNot<Record<string, any>>), (app: App, isServer: boolean) => Promise<Record<string, any>>>;
177
+ type AliasHook = Hook<Record<string, string> | ((app: App, isServer: boolean) => PromiseOrNot<Record<string, string>>), (app: App, isServer: boolean) => Promise<Record<string, string>>>;
178
+ type DefineHook = Hook<Record<string, unknown> | ((app: App, isServer: boolean) => PromiseOrNot<Record<string, unknown>>), (app: App, isServer: boolean) => Promise<Record<string, unknown>>>;
171
179
  /**
172
180
  * List of hooks
173
181
  */
174
182
  interface Hooks {
175
- onInitialized: LifeCycleHook;
176
- onPrepared: LifeCycleHook;
177
- onWatched: LifeCycleHook<[watchers: Closable[], restart: () => Promise<void>]>;
178
- onGenerated: LifeCycleHook;
179
- extendsMarkdownOptions: ExtendsHook<MarkdownOptions>;
180
- extendsMarkdown: ExtendsHook<Markdown>;
181
- extendsPageOptions: ExtendsHook<PageOptions>;
182
- extendsPage: ExtendsHook<Page>;
183
- extendsBundlerOptions: ExtendsHook<any>;
184
- clientConfigFile: ClientConfigFileHook;
185
- alias: AliasDefineHook;
186
- define: AliasDefineHook;
183
+ onInitialized: LifeCycleHook;
184
+ onPrepared: LifeCycleHook;
185
+ onWatched: LifeCycleHook<[watchers: Closable[], restart: () => Promise<void>]>;
186
+ onPageUpdated: LifeCycleHook<[type: 'create', newPage: Page, oldPage: null] | [type: 'delete', newPage: null, oldPage: Page] | [type: 'update', newPage: Page, oldPage: Page]>;
187
+ onGenerated: LifeCycleHook;
188
+ extendsMarkdownOptions: ExtendsHook<MarkdownOptions>;
189
+ extendsMarkdown: ExtendsHook<Markdown>;
190
+ extendsPageOptions: ExtendsHook<PageOptions>;
191
+ extendsPage: ExtendsHook<Page>;
192
+ extendsBundlerOptions: ExtendsHook<BundlerOptions>;
193
+ clientConfigFile: ClientConfigFileHook;
194
+ alias: AliasHook;
195
+ define: DefineHook;
187
196
  }
188
197
  /**
189
198
  * Name of hooks
@@ -192,60 +201,54 @@ type HooksName = keyof Hooks;
192
201
  /**
193
202
  * Exposed hooks API that can be accessed by a plugin
194
203
  */
195
- type HooksExposed = {
196
- [K in HooksName]: Hooks[K]['exposed'];
197
- };
204
+ type HooksExposed = { [K in HooksName]: Hooks[K]['exposed'] };
198
205
  /**
199
206
  * Normalized hooks
200
207
  */
201
- type HooksNormalized = {
202
- [K in HooksName]: Hooks[K]['normalized'];
203
- };
208
+ type HooksNormalized = { [K in HooksName]: Hooks[K]['normalized'] };
204
209
  /**
205
210
  * Result of hooks
206
211
  */
207
- type HooksResult = {
208
- [K in HooksName]: Hooks[K]['result'];
209
- };
212
+ type HooksResult = { [K in HooksName]: Hooks[K]['result'] };
210
213
  /**
211
214
  * Hook item
212
215
  */
213
216
  interface HookItem<T extends HooksName> {
214
- pluginName: string;
215
- hook: HooksNormalized[T];
217
+ pluginName: string;
218
+ hook: HooksNormalized[T];
216
219
  }
217
220
  /**
218
221
  * Hook items queue
219
222
  */
220
223
  interface HookQueue<T extends HooksName> {
221
- name: T;
222
- items: HookItem<T>[];
223
- add: (item: HookItem<T>) => void;
224
- process: (...args: Parameters<HooksNormalized[T]>) => Promise<HooksResult[T][]>;
224
+ name: T;
225
+ items: HookItem<T>[];
226
+ add: (item: HookItem<T>) => void;
227
+ process: (...args: Parameters<HooksNormalized[T]>) => Promise<HooksResult[T][]>;
225
228
  }
226
-
229
+ //#endregion
230
+ //#region src/types/pluginApi/pluginApi.d.ts
227
231
  /**
228
232
  * Vuepress plugin system
229
233
  */
230
234
  interface PluginApi {
231
- /**
232
- * Plugins that have been used
233
- */
234
- plugins: PluginObject[];
235
- /**
236
- * All available hooks
237
- */
238
- hooks: {
239
- [K in HooksName]: HookQueue<K>;
240
- };
241
- /**
242
- * Register hooks of plugins
243
- *
244
- * Should be invoked before applying a hook
245
- */
246
- registerHooks: () => void;
235
+ /**
236
+ * Plugins that have been used
237
+ */
238
+ plugins: PluginObject[];
239
+ /**
240
+ * All available hooks
241
+ */
242
+ hooks: { [K in HooksName]: HookQueue<K> };
243
+ /**
244
+ * Register hooks of plugins
245
+ *
246
+ * Should be invoked before applying a hook
247
+ */
248
+ registerHooks: () => void;
247
249
  }
248
-
250
+ //#endregion
251
+ //#region src/types/plugin.d.ts
249
252
  /**
250
253
  * Vuepress plugin
251
254
  *
@@ -255,7 +258,7 @@ interface PluginApi {
255
258
  *
256
259
  * A plugin package should have a `Plugin` as the default export
257
260
  */
258
- type Plugin<T extends PluginObject = PluginObject> = T | PluginFunction<T>;
261
+ type Plugin<T extends PluginObject = PluginObject> = PluginFunction<T> | T;
259
262
  /**
260
263
  * Vuepress plugin function
261
264
  *
@@ -266,14 +269,21 @@ type PluginFunction<T extends PluginObject = PluginObject> = (app: App) => T;
266
269
  * Vuepress plugin object
267
270
  */
268
271
  interface PluginObject extends Partial<HooksExposed> {
269
- name: string;
270
- multiple?: boolean;
272
+ /**
273
+ * Name of the plugin
274
+ */
275
+ name: string;
276
+ /**
277
+ * Allow the plugin to be used multiple times or not
278
+ */
279
+ multiple?: boolean;
271
280
  }
272
281
  /**
273
282
  * Config field for plugins
274
283
  */
275
284
  type PluginConfig = (Plugin | Plugin[])[];
276
-
285
+ //#endregion
286
+ //#region src/types/theme.d.ts
277
287
  /**
278
288
  * Vuepress theme
279
289
  *
@@ -292,135 +302,223 @@ type ThemeFunction = PluginFunction<ThemeObject>;
292
302
  * Vuepress theme object
293
303
  */
294
304
  interface ThemeObject extends Omit<PluginObject, 'multiple'> {
295
- /**
296
- * Extended parent theme
297
- */
298
- extends?: Theme;
299
- /**
300
- * Allow using plugins in theme
301
- */
302
- plugins?: PluginConfig;
303
- /**
304
- * Allow overriding default templateBuild
305
- */
306
- templateBuild?: string;
307
- /**
308
- * Allow specifying custom template renderer
309
- */
310
- templateBuildRenderer?: TemplateRenderer;
311
- /**
312
- * Allow overriding default templateDev
313
- */
314
- templateDev?: string;
305
+ /**
306
+ * Extended parent theme
307
+ */
308
+ extends?: Theme;
309
+ /**
310
+ * Allow using plugins in theme
311
+ */
312
+ plugins?: PluginConfig;
313
+ /**
314
+ * Allow overriding default templateBuild
315
+ */
316
+ templateBuild?: string;
317
+ /**
318
+ * Allow specifying custom template renderer
319
+ */
320
+ templateBuildRenderer?: TemplateRenderer;
321
+ /**
322
+ * Allow overriding default templateDev
323
+ */
324
+ templateDev?: string;
325
+ /**
326
+ * Allow specifying user styles, which will be injected into client at the bottom
327
+ */
328
+ userStyle?: string;
315
329
  }
316
330
  /**
317
331
  * Resolved theme info
318
332
  */
319
333
  interface ThemeInfo {
320
- /**
321
- * Plugins, including theme itself and plugins used by theme
322
- */
323
- plugins: PluginConfig;
324
- /**
325
- * Default build template
326
- */
327
- templateBuild?: string;
328
- /**
329
- * Default build template renderer
330
- */
331
- templateBuildRenderer?: TemplateRenderer;
332
- /**
333
- * Default dev template
334
- */
335
- templateDev?: string;
334
+ /**
335
+ * Plugins, including theme itself and plugins used by theme
336
+ */
337
+ plugins: PluginConfig;
338
+ /**
339
+ * Default build template
340
+ */
341
+ templateBuild?: string;
342
+ /**
343
+ * Default build template renderer
344
+ */
345
+ templateBuildRenderer?: TemplateRenderer;
346
+ /**
347
+ * Default dev template
348
+ */
349
+ templateDev?: string;
350
+ /**
351
+ * Allow specifying user styles, which will be injected into client at the bottom
352
+ */
353
+ userStyle?: string;
336
354
  }
337
-
355
+ //#endregion
356
+ //#region src/types/app/options.d.ts
338
357
  /**
339
358
  * Vuepress app common config that shared between dev and build
340
359
  */
341
- interface AppConfigCommon extends Partial<SiteData> {
342
- source: string;
343
- dest?: string;
344
- temp?: string;
345
- cache?: string;
346
- public?: string;
347
- debug?: boolean;
348
- markdown?: MarkdownOptions;
349
- pagePatterns?: string[];
350
- permalinkPattern?: string | null;
351
- bundler: Bundler;
352
- theme: Theme;
353
- plugins?: PluginConfig;
360
+ interface AppConfigCommon extends Partial<SiteData$1> {
361
+ /**
362
+ * Source directory of the markdown files.
363
+ *
364
+ * Vuepress will load markdown files from this directory.
365
+ *
366
+ * @required
367
+ */
368
+ source: string;
369
+ /**
370
+ * Destination directory of the output files.
371
+ *
372
+ * Vuepress will output the static site files to this directory.
373
+ *
374
+ * @default `${source}/.vuepress/dist`
375
+ */
376
+ dest?: string;
377
+ /**
378
+ * Temp files directory.
379
+ *
380
+ * Vuepress will write temp files to this directory.
381
+ *
382
+ * @default `${source}/.vuepress/.temp`
383
+ */
384
+ temp?: string;
385
+ /**
386
+ * Cache files directory.
387
+ *
388
+ * Vuepress will write cache files to this directory.
389
+ *
390
+ * @default `${source}/.vuepress/.cache`
391
+ */
392
+ cache?: string;
393
+ /**
394
+ * Public files directory.
395
+ *
396
+ * Vuepress will copy the files from public directory to the output directory.
397
+ *
398
+ * @default `${source}/.vuepress/public`
399
+ */
400
+ public?: string;
401
+ /**
402
+ * Whether to enable debug mode
403
+ *
404
+ * @default false
405
+ */
406
+ debug?: boolean;
407
+ /**
408
+ * Markdown options
409
+ *
410
+ * @default {}
411
+ */
412
+ markdown?: MarkdownOptions;
413
+ /**
414
+ * Patterns to match the markdown files as pages
415
+ *
416
+ * @default ['**\/*.md', '!.vuepress']
417
+ */
418
+ pagePatterns?: string[];
419
+ /**
420
+ * Pattern to generate permalink for pages
421
+ *
422
+ * @default null
423
+ */
424
+ permalinkPattern?: string | null;
425
+ /**
426
+ * Allow specifying user styles, which will be injected into client at the bottom
427
+ */
428
+ userStyle?: string | null;
429
+ /**
430
+ * Vuepress bundler
431
+ *
432
+ * @required
433
+ */
434
+ bundler: Bundler;
435
+ /**
436
+ * Vuepress theme
437
+ *
438
+ * @required
439
+ */
440
+ theme: Theme;
441
+ /**
442
+ * Vuepress plugins
443
+ *
444
+ * @default []
445
+ */
446
+ plugins?: PluginConfig;
354
447
  }
355
448
  /**
356
449
  * Vuepress app config for dev
357
450
  */
358
451
  interface AppConfigDev {
359
- /**
360
- * Specify the host to use for the dev server
361
- *
362
- * @default '0.0.0.0'
363
- */
364
- host?: string;
365
- /**
366
- * Specify the port to use for the dev server
367
- *
368
- * @default 8080
369
- */
370
- port?: number;
371
- /**
372
- * Whether to open the browser after dev-server had been started
373
- *
374
- * @default false
375
- */
376
- open?: boolean;
377
- /**
378
- * Specify the path of the HTML template to be used for dev
379
- *
380
- * @default '@vuepress/client/templates/dev.html'
381
- */
382
- templateDev?: string;
452
+ /**
453
+ * Specify the host to use for the dev server
454
+ *
455
+ * @default '0.0.0.0'
456
+ */
457
+ host?: string;
458
+ /**
459
+ * Specify the port to use for the dev server
460
+ *
461
+ * @default 8080
462
+ */
463
+ port?: number;
464
+ /**
465
+ * Whether to open the browser after dev-server had been started
466
+ *
467
+ * @default false
468
+ */
469
+ open?: boolean;
470
+ /**
471
+ * Specify the path of the HTML template to be used for dev
472
+ *
473
+ * @default '@vuepress/client/templates/dev.html'
474
+ */
475
+ templateDev?: string;
383
476
  }
384
477
  /**
385
478
  * Vuepress app config for build
386
479
  */
387
480
  interface AppConfigBuild {
388
- /**
389
- * Determine what resource files should be preloaded. Use boolean value to
390
- * totally enable / disable.
391
- *
392
- * @default true
393
- */
394
- shouldPreload?: ((file: string, type: string) => boolean) | boolean;
395
- /**
396
- * Determine what resource files should be prefetched. Use boolean value to
397
- * totally enable / disable.
398
- *
399
- * @default true
400
- */
401
- shouldPrefetch?: ((file: string, type: string) => boolean) | boolean;
402
- /**
403
- * Specify the path of the HTML template to be used for build
404
- *
405
- * @default '@vuepress/client/templates/build.html'
406
- */
407
- templateBuild?: string;
408
- /**
409
- * Specify the HTML template renderer to be used for build
410
- *
411
- * @default templateRenderer from '@vuepress/utils'
412
- */
413
- templateBuildRenderer?: TemplateRenderer;
481
+ /**
482
+ * Determine what resource files should be preloaded. Use boolean value to
483
+ * totally enable / disable.
484
+ *
485
+ * @default true
486
+ */
487
+ shouldPreload?: boolean | ((file: string, type: string) => boolean);
488
+ /**
489
+ * Determine what resource files should be prefetched. Use boolean value to
490
+ * totally enable / disable.
491
+ *
492
+ * @default true
493
+ */
494
+ shouldPrefetch?: boolean | ((file: string, type: string) => boolean);
495
+ /**
496
+ * Specify the path of the HTML template to be used for build
497
+ *
498
+ * @default '@vuepress/client/templates/build.html'
499
+ */
500
+ templateBuild?: string;
501
+ /**
502
+ * Specify the HTML template renderer to be used for build
503
+ *
504
+ * @default `import { templateRenderer } from '@vuepress/utils'`
505
+ */
506
+ templateBuildRenderer?: TemplateRenderer;
414
507
  }
415
508
  /**
416
- * Vuepress app config
509
+ * Vuepress app user config.
510
+ *
511
+ * It would be provided by user, typically via a config file.
417
512
  */
418
- type AppConfig = AppConfigCommon & AppConfigDev & AppConfigBuild;
513
+ type AppConfig = AppConfigBuild & AppConfigCommon & AppConfigDev;
419
514
  /**
420
- * Vuepress app options
515
+ * Vuepress app options that resolved from user config.
516
+ *
517
+ * It fills all optional fields with a default value.
421
518
  */
422
519
  type AppOptions = Required<AppConfig>;
423
-
520
+ //#endregion
521
+ //#region src/types/app/utils.d.ts
424
522
  /**
425
523
  * Directory util function
426
524
  */
@@ -429,389 +527,210 @@ type AppDirFunction = (...args: string[]) => string;
429
527
  * Directory utils
430
528
  */
431
529
  interface AppDir {
432
- cache: AppDirFunction;
433
- temp: AppDirFunction;
434
- source: AppDirFunction;
435
- dest: AppDirFunction;
436
- public: AppDirFunction;
437
- client: AppDirFunction;
530
+ /**
531
+ * Resolve file path in cache directory
532
+ */
533
+ cache: AppDirFunction;
534
+ /**
535
+ * Resolve file path in temp directory
536
+ */
537
+ temp: AppDirFunction;
538
+ /**
539
+ * Resolve file path in source directory
540
+ */
541
+ source: AppDirFunction;
542
+ /**
543
+ * Resolve file path in dest directory
544
+ */
545
+ dest: AppDirFunction;
546
+ /**
547
+ * Resolve file path in public directory
548
+ */
549
+ public: AppDirFunction;
550
+ /**
551
+ * Resolve file path in client directory
552
+ */
553
+ client: AppDirFunction;
438
554
  }
439
555
  /**
440
556
  * Environment flags
441
557
  */
442
558
  interface AppEnv {
443
- /**
444
- * Is running in build mode or not
445
- */
446
- isBuild: boolean;
447
- /**
448
- * Is running in dev mode or not
449
- */
450
- isDev: boolean;
451
- /**
452
- * Is debug mode enabled or not
453
- */
454
- isDebug: boolean;
559
+ /**
560
+ * Is running in build mode or not
561
+ */
562
+ isBuild: boolean;
563
+ /**
564
+ * Is running in dev mode or not
565
+ */
566
+ isDev: boolean;
567
+ /**
568
+ * Is debug mode enabled or not
569
+ */
570
+ isDebug: boolean;
455
571
  }
456
572
  /**
457
573
  * Write temp file util
458
574
  */
459
- type AppWriteTemp = (file: string, content: string) => Promise<string>;
460
-
575
+ interface AppWriteTemp {
576
+ (file: string, content: string): Promise<string>;
577
+ /**
578
+ * Clean up the internal write temp cache.
579
+ *
580
+ * This should be called when the dev server restarts
581
+ * to avoid stale cache and to release references to any
582
+ * in-memory write state so that pending write promises can
583
+ * complete and be garbage-collected naturally.
584
+ */
585
+ cleanup: () => void;
586
+ }
587
+ //#endregion
588
+ //#region src/types/app/app.d.ts
589
+ /**
590
+ * App base properties, will be available after creation, even before initialization
591
+ */
592
+ interface AppPropertiesBase {
593
+ /**
594
+ * Directory utils.
595
+ */
596
+ dir: AppDir;
597
+ /**
598
+ * Environment flags.
599
+ */
600
+ env: AppEnv;
601
+ /**
602
+ * Options that filled all optional fields with a default value.
603
+ */
604
+ options: AppOptions;
605
+ /**
606
+ * Plugin system.
607
+ */
608
+ pluginApi: PluginApi;
609
+ /**
610
+ * Site data, which will be used in client side.
611
+ */
612
+ siteData: SiteData$1;
613
+ /**
614
+ * Version of vuepress core.
615
+ */
616
+ version: string;
617
+ /**
618
+ * Initialize app.
619
+ *
620
+ * - Theme and plugin will be loaded.
621
+ * - Layouts and pages will be resolved.
622
+ */
623
+ init: () => Promise<void>;
624
+ /**
625
+ * Prepare data for client and write temp files.
626
+ *
627
+ * Should be called after `app.init()`.
628
+ */
629
+ prepare: () => Promise<void>;
630
+ /**
631
+ * Use a plugin.
632
+ *
633
+ * Should be called before `app.init()`.
634
+ */
635
+ use: (plugin: Plugin) => this;
636
+ /**
637
+ * Util to write temp file
638
+ */
639
+ writeTemp: AppWriteTemp;
640
+ }
461
641
  /**
462
- * Vuepress app
463
- */
464
- interface App {
465
- /**
466
- * Directory utils
467
- */
468
- dir: AppDir;
469
- /**
470
- * Environment flags
471
- */
472
- env: AppEnv;
473
- /**
474
- * Options that filled all optional fields with a default value
475
- */
476
- options: AppOptions;
477
- /**
478
- * Plugin system
479
- */
480
- pluginApi: PluginApi;
481
- /**
482
- * Site data, which will be used in client side
483
- */
484
- siteData: SiteData;
485
- /**
486
- * Version of vuepress core
487
- */
488
- version: string;
489
- /**
490
- * Write temp file
491
- */
492
- writeTemp: AppWriteTemp;
493
- /**
494
- * Use a plugin
495
- */
496
- use: (plugin: Plugin) => this;
497
- /**
498
- * Initialize app.
499
- *
500
- * - Theme and plugin will be loaded.
501
- * - Layouts and pages will be resolved.
502
- */
503
- init: () => Promise<void>;
504
- /**
505
- * Prepare data for client and write temp files.
506
- *
507
- * Should be called after `app.init()`.
508
- */
509
- prepare: () => Promise<void>;
510
- /**
511
- * Markdown-it instance.
512
- *
513
- * Only available after initialization
514
- */
515
- markdown: Markdown;
516
- /**
517
- * Page objects.
518
- *
519
- * Only available after initialization
520
- */
521
- pages: Page[];
642
+ * App initialized properties, will only be available after initialization
643
+ */
644
+ interface AppPropertiesInitialized {
645
+ /**
646
+ * Markdown-it instance.
647
+ *
648
+ * Only available after initialization
649
+ */
650
+ markdown: Markdown;
651
+ /**
652
+ * Page objects.
653
+ *
654
+ * Only available after initialization
655
+ */
656
+ pages: Page[];
657
+ /**
658
+ * Page source filepath map.
659
+ *
660
+ * Only available after initialization
661
+ */
662
+ pagesMap: Record<string, Page | undefined>;
522
663
  }
664
+ /**
665
+ * Vuepress app instance
666
+ */
667
+ type App = AppPropertiesBase & AppPropertiesInitialized;
523
668
  /**
524
669
  * Vuepress dev app
525
670
  */
526
671
  interface DevApp extends App {
527
- /**
528
- * Start dev server
529
- *
530
- * Should be called after `app.prepare()`.
531
- */
532
- dev: () => ReturnType<Bundler['dev']>;
672
+ /**
673
+ * Start dev server
674
+ *
675
+ * Should be called after `app.prepare()`.
676
+ */
677
+ dev: () => ReturnType<Bundler['dev']>;
533
678
  }
534
679
  /**
535
680
  * Vuepress build app
536
681
  */
537
682
  interface BuildApp extends App {
538
- /**
539
- * Build static files
540
- *
541
- * Should be called after `app.prepare()`.
542
- */
543
- build: () => ReturnType<Bundler['build']>;
683
+ /**
684
+ * Build static files
685
+ *
686
+ * Should be called after `app.prepare()`.
687
+ */
688
+ build: () => ReturnType<Bundler['build']>;
544
689
  }
545
-
546
- /**
547
- * Generate client configs temp file
548
- */
549
- declare const prepareClientConfigs: (app: App) => Promise<void>;
550
-
690
+ //#endregion
691
+ //#region src/app/prepare/preparePageChunk.d.ts
551
692
  /**
552
- * Generate page chunk temp file of a single page
693
+ * Generate temp file if the page does not have a source file
553
694
  */
554
695
  declare const preparePageChunk: (app: App, page: Page) => Promise<void>;
555
-
556
- /**
557
- * Generate page component temp file of a single page
558
- */
559
- declare const preparePageComponent: (app: App, page: Page) => Promise<void>;
560
-
696
+ //#endregion
697
+ //#region src/app/prepare/prepareRoutes.d.ts
561
698
  /**
562
699
  * Generate routes temp file
563
700
  */
564
701
  declare const prepareRoutes: (app: App) => Promise<void>;
565
-
566
- /**
567
- * Generate site data temp file
568
- */
569
- declare const prepareSiteData: (app: App) => Promise<void>;
570
-
571
- /**
572
- * Initialize a vuepress app
573
- *
574
- * Plugins should be used before initialization.
575
- */
576
- declare const appInit: (app: App) => Promise<void>;
577
-
578
- /**
579
- * Prepare files for development or build
580
- *
581
- * - page components
582
- * - routes
583
- * - site data
584
- * - other files that generated by plugins
585
- */
586
- declare const appPrepare: (app: App) => Promise<void>;
587
-
588
- declare const appUse: (app: App, rawPlugin: Plugin) => App;
589
-
590
- /**
591
- * Create vuepress app
592
- */
593
- declare const createBaseApp: (config: AppConfig, isBuild?: boolean) => App;
594
-
702
+ //#endregion
703
+ //#region src/app/createBuildApp.d.ts
595
704
  /**
596
- * Create vuepress build app
705
+ * Create vuepress build app.
597
706
  */
598
707
  declare const createBuildApp: (config: AppConfig) => BuildApp;
599
-
708
+ //#endregion
709
+ //#region src/app/createDevApp.d.ts
600
710
  /**
601
- * Create vuepress dev app
711
+ * Create vuepress dev app.
602
712
  */
603
713
  declare const createDevApp: (config: AppConfig) => DevApp;
604
-
605
- /**
606
- * Create directory util function
607
- */
608
- declare const createAppDirFunction: (baseDir: string) => AppDirFunction;
714
+ //#endregion
715
+ //#region src/app/resolveAppDir.d.ts
609
716
  /**
610
717
  * Resolve directory utils for vuepress app
611
718
  */
612
719
  declare const resolveAppDir: (options: AppOptions) => AppDir;
613
-
614
- /**
615
- * Resolve environment flags for vuepress app
616
- */
617
- declare const resolveAppEnv: (options: AppOptions, isBuild: boolean) => AppEnv;
618
-
619
- /**
620
- * Create app options with default values
621
- */
622
- declare const resolveAppOptions: ({ base, lang, title, description, head, locales, source, dest, temp, cache, public: publicDir, host, port, open, templateDev, shouldPreload, shouldPrefetch, templateBuild, bundler, debug, markdown, pagePatterns, permalinkPattern, plugins, theme, }: AppConfig) => AppOptions;
623
-
624
- /**
625
- * Resolve pages for vuepress app
626
- */
627
- declare const resolveAppPages: (app: App) => Promise<Page[]>;
628
-
629
- /**
630
- * Resolve site data for vuepress app
631
- *
632
- * Site data will also be used in client
633
- */
634
- declare const resolveAppSiteData: (options: AppOptions) => SiteData;
635
-
636
- /**
637
- * Resolve version of vuepress app
638
- */
639
- declare const resolveAppVersion: () => string;
640
-
720
+ //#endregion
721
+ //#region src/page/createPage.d.ts
641
722
  /**
642
- * Resolve write temp file util for vuepress app
723
+ * Create vuepress page object
643
724
  */
644
- declare const resolveAppWriteTemp: (dir: AppDir) => AppWriteTemp;
645
-
646
- /**
647
- * Resolve a plugin object according to name / path / module and config
648
- */
649
- declare const resolvePluginObject: <T extends PluginObject = PluginObject>(app: App, plugin: Plugin<T>) => T;
650
-
651
- /**
652
- * Resolve theme info and its parent theme info
653
- */
654
- declare const resolveThemeInfo: (app: App, theme: Theme) => ThemeInfo;
655
-
656
725
  declare const createPage: (app: App, options: PageOptions) => Promise<Page>;
657
-
658
- /**
659
- * Infer page path according to file path
660
- */
661
- declare const inferPagePath: ({ app, filePathRelative, }: {
662
- app: App;
663
- filePathRelative: string | null;
664
- }) => {
665
- pathInferred: string | null;
666
- pathLocale: string;
667
- };
668
-
669
- /**
670
- * Render page content and extract related info
671
- */
672
- declare const renderPageContent: ({ app, content, filePath, filePathRelative, options, }: {
673
- app: App;
674
- content: string;
675
- filePath: string | null;
676
- filePathRelative: string | null;
677
- options: PageOptions;
678
- }) => {
679
- contentRendered: string;
680
- deps: string[];
681
- markdownEnv: Record<string, unknown>;
682
- frontmatter: PageFrontmatter;
683
- headers: MarkdownHeader[];
684
- links: MarkdownLink[];
685
- sfcBlocks: MarkdownSfcBlocks;
686
- title: string;
687
- };
688
-
689
- /**
690
- * Resolve page data file path
691
- */
692
- declare const resolvePageChunkInfo: ({ app, htmlFilePathRelative, }: {
693
- app: App;
694
- htmlFilePathRelative: string;
695
- }) => {
696
- chunkFilePath: string;
697
- chunkFilePathRelative: string;
698
- chunkName: string;
699
- };
700
-
701
- /**
702
- * Resolve page component and related info
703
- */
704
- declare const resolvePageComponentInfo: ({ app, htmlFilePathRelative, }: {
705
- app: App;
706
- htmlFilePathRelative: string;
707
- }) => Promise<{
708
- componentFilePath: string;
709
- componentFilePathRelative: string;
710
- }>;
711
-
712
- /**
713
- * Resolve page date according to frontmatter or file path
714
- *
715
- * It will be resolved as 'yyyy-MM-dd' format
716
- */
717
- declare const resolvePageDate: ({ frontmatter, filePathRelative, }: {
718
- frontmatter: PageFrontmatter;
719
- filePathRelative: string | null;
720
- }) => string;
721
-
722
- /**
723
- * Resolve page file content according to filePath or options content
724
- */
725
- declare const resolvePageFileContent: ({ filePath, options, }: {
726
- filePath: string | null;
727
- options: PageOptions;
728
- }) => Promise<string>;
729
-
730
- /**
731
- * Resolve absolute and relative path of page file
732
- */
733
- declare const resolvePageFilePath: ({ app, options, }: {
734
- app: App;
735
- options: PageOptions;
736
- }) => {
737
- filePath: string | null;
738
- filePathRelative: string | null;
739
- };
740
-
741
- /**
742
- * Resolve page rendered html file path
743
- */
744
- declare const resolvePageHtmlInfo: ({ app, path: pagePath, }: {
745
- app: App;
746
- path: string;
747
- }) => {
748
- htmlFilePath: string;
749
- htmlFilePathRelative: string;
750
- };
751
-
752
- /**
753
- * Resolve language of page
754
- */
755
- declare const resolvePageLang: ({ app, frontmatter, pathLocale, }: {
756
- app: App;
757
- frontmatter: PageFrontmatter;
758
- pathLocale: string;
759
- }) => string;
760
-
761
- /**
762
- * Resolve the final route path of a page
763
- */
764
- declare const resolvePagePath: ({ permalink, pathInferred, options, }: {
765
- permalink: string | null;
766
- pathInferred: string | null;
767
- options: PageOptions;
768
- }) => string;
769
-
726
+ //#endregion
727
+ //#region src/page/renderPageToVue.d.ts
770
728
  /**
771
- * Resolve page permalink from frontmatter / options / pattern
729
+ * Render page to vue component
772
730
  */
773
- declare const resolvePagePermalink: ({ app, frontmatter, slug, date, pathInferred, pathLocale, }: {
774
- app: App;
775
- frontmatter: PageFrontmatter;
776
- slug: string;
777
- date: string;
778
- pathInferred: string | null;
779
- pathLocale: string;
780
- }) => string | null;
781
-
782
- /**
783
- * Resolve page route meta
784
- */
785
- declare const resolvePageRouteMeta: ({ frontmatter, }: {
786
- frontmatter: PageFrontmatter;
787
- }) => Record<string, unknown>;
788
-
789
- /**
790
- * Resolve page slug from filename
791
- */
792
- declare const resolvePageSlug: ({ filePathRelative, }: {
793
- filePathRelative: string | null;
794
- }) => string;
795
-
796
- /**
797
- * Create hook queue for plugin system
798
- */
799
- declare const createHookQueue: <T extends keyof Hooks>(name: T) => HookQueue<T>;
800
-
801
- declare const createPluginApi: () => PluginApi;
802
-
803
- declare const createPluginApiHooks: () => PluginApi['hooks'];
804
-
805
- declare const createPluginApiRegisterHooks: (plugins: PluginApi['plugins'], hooks: PluginApi['hooks']) => PluginApi['registerHooks'];
806
-
807
- /**
808
- * Normalize alias and define hook
809
- */
810
- declare const normalizeAliasDefineHook: (hook: AliasDefineHook['exposed']) => AliasDefineHook['normalized'];
811
-
812
- /**
813
- * Normalize hook for client config file
814
- */
815
- declare const normalizeClientConfigFileHook: (hook: ClientConfigFileHook['exposed']) => ClientConfigFileHook['normalized'];
816
-
817
- export { type AliasDefineHook, type App, type AppConfig, type AppConfigBuild, type AppConfigCommon, type AppConfigDev, type AppDir, type AppDirFunction, type AppEnv, type AppOptions, type AppWriteTemp, type BuildApp, type Bundler, type ClientConfigFileHook, type DevApp, type ExtendsHook, type Hook, type HookItem, type HookQueue, type Hooks, type HooksExposed, type HooksName, type HooksNormalized, type HooksResult, type LifeCycleHook, type Page, type PageOptions, type Plugin, type PluginApi, type PluginConfig, type PluginFunction, type PluginObject, type Theme, type ThemeFunction, type ThemeInfo, type ThemeObject, appInit, appPrepare, appUse, createAppDirFunction, createBaseApp, createBuildApp, createDevApp, createHookQueue, createPage, createPluginApi, createPluginApiHooks, createPluginApiRegisterHooks, inferPagePath, normalizeAliasDefineHook, normalizeClientConfigFileHook, prepareClientConfigs, preparePageChunk, preparePageComponent, prepareRoutes, prepareSiteData, renderPageContent, resolveAppDir, resolveAppEnv, resolveAppOptions, resolveAppPages, resolveAppSiteData, resolveAppVersion, resolveAppWriteTemp, resolvePageChunkInfo, resolvePageComponentInfo, resolvePageDate, resolvePageFileContent, resolvePageFilePath, resolvePageHtmlInfo, resolvePageLang, resolvePagePath, resolvePagePermalink, resolvePageRouteMeta, resolvePageSlug, resolvePluginObject, resolveThemeInfo };
731
+ declare const renderPageToVue: (app: App, page: Page) => string;
732
+ //#endregion
733
+ //#region src/constants.d.ts
734
+ declare const DEFAULT_IGNORE_PATTERNS: string[];
735
+ //#endregion
736
+ export { AliasHook, App, AppConfig, AppConfigBuild, AppConfigCommon, AppConfigDev, AppDir, AppDirFunction, AppEnv, AppOptions, AppPropertiesBase, AppPropertiesInitialized, AppWriteTemp, BuildApp, Bundler, BundlerOptions, ClientConfigFileHook, DEFAULT_IGNORE_PATTERNS, DefineHook, DevApp, ExtendsHook, type HeadAttrsConfig, type HeadConfig, type HeadTag, type HeadTagEmpty, type HeadTagNonEmpty, Hook, HookItem, HookQueue, Hooks, HooksExposed, HooksName, HooksNormalized, HooksResult, LifeCycleHook, type LocaleConfig, type LocaleData, Page, type PageData, type PageFrontmatter, type PageHeader, PageOptions, Plugin, PluginApi, PluginConfig, PluginFunction, PluginObject, type SiteData, type SiteLocaleConfig, Theme, ThemeFunction, ThemeInfo, ThemeObject, createBuildApp, createDevApp, createPage, preparePageChunk, prepareRoutes, renderPageToVue, resolveAppDir };