@vuepress/core 2.0.0-rc.3 → 2.0.0-rc.31

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