@vuepress/core 2.0.0-beta.4 → 2.0.0-beta.40

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.
Files changed (146) hide show
  1. package/lib/app/appInit.js +6 -16
  2. package/lib/app/appPrepare.js +12 -15
  3. package/lib/app/appUse.d.ts +2 -2
  4. package/lib/app/appUse.js +17 -15
  5. package/lib/app/createBaseApp.d.ts +5 -0
  6. package/lib/app/createBaseApp.js +46 -0
  7. package/lib/app/createBuildApp.d.ts +5 -0
  8. package/lib/app/createBuildApp.js +13 -0
  9. package/lib/app/createDevApp.d.ts +5 -0
  10. package/lib/app/createDevApp.js +13 -0
  11. package/lib/app/index.d.ts +13 -12
  12. package/lib/app/index.js +18 -13
  13. package/lib/app/prepare/index.d.ts +1 -3
  14. package/lib/app/prepare/index.js +6 -4
  15. package/lib/app/prepare/prepareLayoutComponents.js +2 -2
  16. package/lib/app/prepare/preparePageComponent.js +6 -1
  17. package/lib/app/prepare/preparePageData.js +7 -11
  18. package/lib/app/prepare/{preparePagesComponent.d.ts → preparePagesComponents.d.ts} +1 -1
  19. package/lib/app/prepare/preparePagesComponents.js +24 -0
  20. package/lib/app/prepare/preparePagesData.js +5 -4
  21. package/lib/app/prepare/preparePagesRoutes.js +61 -11
  22. package/lib/app/prepare/prepareSiteData.js +19 -1
  23. package/lib/app/{createAppDir.d.ts → resolveAppDir.d.ts} +2 -2
  24. package/lib/app/resolveAppDir.js +32 -0
  25. package/lib/app/resolveAppEnv.d.ts +5 -0
  26. package/lib/app/resolveAppEnv.js +12 -0
  27. package/lib/app/resolveAppMarkdown.d.ts +6 -0
  28. package/lib/app/resolveAppMarkdown.js +16 -0
  29. package/lib/app/resolveAppOptions.d.ts +5 -0
  30. package/lib/app/{createAppOptions.js → resolveAppOptions.js} +16 -20
  31. package/lib/app/resolveAppPages.d.ts +5 -0
  32. package/lib/app/resolveAppPages.js +31 -0
  33. package/lib/app/resolveAppSiteData.d.ts +7 -0
  34. package/lib/app/resolveAppSiteData.js +17 -0
  35. package/lib/app/resolveAppVersion.d.ts +4 -0
  36. package/lib/app/resolveAppVersion.js +10 -0
  37. package/lib/app/resolveAppWriteTemp.d.ts +5 -0
  38. package/lib/app/{createAppWriteTemp.js → resolveAppWriteTemp.js} +5 -5
  39. package/lib/app/resolvePluginObject.d.ts +5 -0
  40. package/lib/app/resolvePluginObject.js +9 -0
  41. package/lib/app/resolveThemeInfo.d.ts +5 -0
  42. package/lib/app/resolveThemeInfo.js +32 -0
  43. package/lib/app/resolveThemeLayouts.d.ts +5 -0
  44. package/lib/app/resolveThemeLayouts.js +25 -0
  45. package/lib/app/setupAppThemeAndPlugins.d.ts +5 -0
  46. package/lib/app/setupAppThemeAndPlugins.js +22 -0
  47. package/lib/index.d.ts +0 -1
  48. package/lib/index.js +5 -2
  49. package/lib/page/createPage.js +75 -39
  50. package/lib/page/index.d.ts +4 -3
  51. package/lib/page/index.js +9 -4
  52. package/lib/page/inferPagePath.js +2 -2
  53. package/lib/page/renderPageContent.d.ts +19 -0
  54. package/lib/page/renderPageContent.js +26 -0
  55. package/lib/page/renderPageExcerpt.d.ts +11 -0
  56. package/lib/page/renderPageExcerpt.js +17 -0
  57. package/lib/page/resolvePageComponentInfo.d.ts +2 -9
  58. package/lib/page/resolvePageComponentInfo.js +2 -24
  59. package/lib/page/resolvePageContent.js +1 -2
  60. package/lib/page/resolvePageDataInfo.d.ts +2 -1
  61. package/lib/page/resolvePageDataInfo.js +2 -2
  62. package/lib/page/resolvePageDate.d.ts +1 -1
  63. package/lib/page/resolvePageDate.js +6 -6
  64. package/lib/page/resolvePageFileContent.js +2 -2
  65. package/lib/page/resolvePageFilePath.d.ts +1 -1
  66. package/lib/page/resolvePageFilePath.js +6 -11
  67. package/lib/page/resolvePageHtmlInfo.d.ts +11 -0
  68. package/lib/page/resolvePageHtmlInfo.js +18 -0
  69. package/lib/page/resolvePageKey.js +1 -1
  70. package/lib/page/resolvePageLang.js +3 -3
  71. package/lib/page/resolvePagePath.js +12 -1
  72. package/lib/page/resolvePagePermalink.js +3 -3
  73. package/lib/page/resolvePageRouteMeta.d.ts +7 -0
  74. package/lib/page/resolvePageRouteMeta.js +8 -0
  75. package/lib/pluginApi/createHookQueue.d.ts +1 -1
  76. package/lib/pluginApi/createHookQueue.js +7 -46
  77. package/lib/pluginApi/createPluginApi.js +2 -2
  78. package/lib/pluginApi/createPluginApiHooks.js +14 -14
  79. package/lib/pluginApi/createPluginApiRegisterHooks.js +6 -6
  80. package/lib/pluginApi/index.js +5 -1
  81. package/lib/pluginApi/normalizeClientFilesHook.js +5 -2
  82. package/lib/pluginApi/normalizeReturnObjectHook.js +1 -1
  83. package/lib/types/app/app.d.ts +82 -14
  84. package/lib/types/app/index.js +5 -1
  85. package/lib/types/app/options.d.ts +78 -27
  86. package/lib/types/app/utils.d.ts +10 -3
  87. package/lib/types/bundler.d.ts +3 -24
  88. package/lib/types/index.d.ts +2 -3
  89. package/lib/types/index.js +6 -3
  90. package/lib/types/page.d.ts +78 -32
  91. package/lib/types/plugin.d.ts +5 -24
  92. package/lib/types/{plugin-api → pluginApi}/hooks.d.ts +7 -9
  93. package/lib/types/{plugin-api → pluginApi}/hooks.js +0 -0
  94. package/lib/types/{plugin-api → pluginApi}/index.d.ts +0 -0
  95. package/lib/types/{plugin-api → pluginApi}/index.js +5 -1
  96. package/lib/types/{plugin-api → pluginApi}/pluginApi.d.ts +0 -0
  97. package/lib/types/{plugin-api → pluginApi}/pluginApi.js +0 -0
  98. package/lib/types/theme.d.ts +42 -14
  99. package/package.json +17 -14
  100. package/CHANGELOG.md +0 -260
  101. package/lib/app/appUseByConfig.d.ts +0 -2
  102. package/lib/app/appUseByConfig.js +0 -14
  103. package/lib/app/createApp.d.ts +0 -5
  104. package/lib/app/createApp.js +0 -44
  105. package/lib/app/createAppDir.js +0 -32
  106. package/lib/app/createAppEnv.d.ts +0 -5
  107. package/lib/app/createAppEnv.js +0 -14
  108. package/lib/app/createAppOptions.d.ts +0 -5
  109. package/lib/app/createAppPages.d.ts +0 -5
  110. package/lib/app/createAppPages.js +0 -33
  111. package/lib/app/createAppSiteData.d.ts +0 -7
  112. package/lib/app/createAppSiteData.js +0 -19
  113. package/lib/app/createAppVersion.d.ts +0 -4
  114. package/lib/app/createAppVersion.js +0 -11
  115. package/lib/app/createAppWriteTemp.d.ts +0 -5
  116. package/lib/app/normalizePlugin.d.ts +0 -2
  117. package/lib/app/normalizePlugin.js +0 -19
  118. package/lib/app/normalizePluginConfig.d.ts +0 -2
  119. package/lib/app/normalizePluginConfig.js +0 -18
  120. package/lib/app/prepare/preparePageRoutes.d.ts +0 -5
  121. package/lib/app/prepare/preparePageRoutes.js +0 -57
  122. package/lib/app/prepare/preparePagesComponent.js +0 -23
  123. package/lib/app/prepare/resolvePageData.d.ts +0 -5
  124. package/lib/app/prepare/resolvePageData.js +0 -18
  125. package/lib/app/resolveBundler.d.ts +0 -2
  126. package/lib/app/resolveBundler.js +0 -10
  127. package/lib/app/resolvePlugin.d.ts +0 -5
  128. package/lib/app/resolvePlugin.js +0 -20
  129. package/lib/page/resolvePageExcerpt.d.ts +0 -9
  130. package/lib/page/resolvePageExcerpt.js +0 -15
  131. package/lib/page/resolvePageRoutesInfo.d.ts +0 -11
  132. package/lib/page/resolvePageRoutesInfo.js +0 -16
  133. package/lib/page/resolvePageTitle.d.ts +0 -9
  134. package/lib/page/resolvePageTitle.js +0 -26
  135. package/lib/themeApi/createThemeApi.d.ts +0 -7
  136. package/lib/themeApi/createThemeApi.js +0 -30
  137. package/lib/themeApi/index.d.ts +0 -1
  138. package/lib/themeApi/index.js +0 -13
  139. package/lib/themeApi/resolveThemeInfo.d.ts +0 -2
  140. package/lib/themeApi/resolveThemeInfo.js +0 -34
  141. package/lib/themeApi/resolveThemeLayouts.d.ts +0 -5
  142. package/lib/themeApi/resolveThemeLayouts.js +0 -33
  143. package/lib/types/theme-api/index.d.ts +0 -1
  144. package/lib/types/theme-api/index.js +0 -13
  145. package/lib/types/theme-api/themeApi.d.ts +0 -44
  146. package/lib/types/theme-api/themeApi.js +0 -2
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.renderPageContent = void 0;
4
+ /**
5
+ * Render page content and extract related info
6
+ */
7
+ const renderPageContent = async ({ app, content, frontmatter, filePath, filePathRelative, }) => {
8
+ const markdownEnv = {
9
+ base: app.options.base,
10
+ filePath,
11
+ filePathRelative,
12
+ frontmatter,
13
+ };
14
+ const contentRendered = app.markdown.render(content, markdownEnv);
15
+ /* istanbul ignore next */
16
+ const { headers = [], hoistedTags = [], importedFiles = [], links = [], title = '', } = markdownEnv;
17
+ return {
18
+ contentRendered,
19
+ deps: importedFiles,
20
+ headers,
21
+ hoistedTags,
22
+ links,
23
+ title,
24
+ };
25
+ };
26
+ exports.renderPageContent = renderPageContent;
@@ -0,0 +1,11 @@
1
+ import type { App, PageFrontmatter } from '../types';
2
+ /**
3
+ * Render page excerpt from raw excerpt
4
+ */
5
+ export declare const renderPageExcerpt: ({ app, excerptRaw, frontmatter, filePath, filePathRelative, }: {
6
+ app: App;
7
+ excerptRaw: string;
8
+ frontmatter: PageFrontmatter;
9
+ filePath: string | null;
10
+ filePathRelative: string | null;
11
+ }) => string;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.renderPageExcerpt = void 0;
4
+ /**
5
+ * Render page excerpt from raw excerpt
6
+ */
7
+ const renderPageExcerpt = ({ app, excerptRaw, frontmatter, filePath, filePathRelative, }) => {
8
+ const markdownEnv = {
9
+ base: app.options.base,
10
+ filePath,
11
+ filePathRelative,
12
+ frontmatter,
13
+ };
14
+ const renderedExcerpt = app.markdown.render(excerptRaw, markdownEnv);
15
+ return renderedExcerpt;
16
+ };
17
+ exports.renderPageExcerpt = renderPageExcerpt;
@@ -1,20 +1,13 @@
1
- import type { MarkdownHeader, MarkdownLink } from '@vuepress/markdown';
2
- import { path } from '@vuepress/utils';
3
1
  import type { App } from '../types';
4
2
  /**
5
3
  * Resolve page component and related info
6
4
  */
7
- export declare const resolvePageComponentInfo: ({ app, content, filePathRelative, path: routePath, key, }: {
5
+ export declare const resolvePageComponentInfo: ({ app, htmlFilePathRelative, key, }: {
8
6
  app: App;
9
- content: string;
10
- filePathRelative: string | null;
11
- path: string;
7
+ htmlFilePathRelative: string;
12
8
  key: string;
13
9
  }) => Promise<{
14
- headers: MarkdownHeader[];
15
- links: MarkdownLink[];
16
10
  componentFilePath: string;
17
11
  componentFilePathRelative: string;
18
- componentFileContent: string;
19
12
  componentFileChunkName: string;
20
13
  }>;
@@ -5,36 +5,14 @@ const utils_1 = require("@vuepress/utils");
5
5
  /**
6
6
  * Resolve page component and related info
7
7
  */
8
- const resolvePageComponentInfo = async ({ app, content, filePathRelative, path: routePath, key, }) => {
9
- var _a;
10
- const markdownEnv = {
11
- base: app.options.base,
12
- filePathRelative,
13
- };
14
- const rendered = app.markdown.render(content, markdownEnv);
15
- const { headers = [], links = [], hoistedTags = [] } = markdownEnv;
16
- // TODO: links check
17
- // resolve component file content
18
- // take the rendered markdown content as <template>
19
- // hoist `<script>`, `<style>` and other custom blocks
20
- const componentFileContent = [
21
- // if the `<template>` block is empty, vue will print a runtime warning
22
- // during development, so here we add a whitespace to temporarily avoid
23
- // the warning
24
- // @see https://github.com/vuejs/vue-next/issues/2463
25
- `<template>${rendered || ' '}</template>`,
26
- ...hoistedTags,
27
- ].join('\n\n');
8
+ const resolvePageComponentInfo = async ({ app, htmlFilePathRelative, key, }) => {
28
9
  // resolve component file path
29
- const componentFilePathRelative = utils_1.path.join('pages', (_a = filePathRelative === null || filePathRelative === void 0 ? void 0 : filePathRelative.replace(/\.md$/, '.vue')) !== null && _a !== void 0 ? _a : `${routePath || key}.vue`);
10
+ const componentFilePathRelative = utils_1.path.join('pages', `${htmlFilePathRelative}.vue`);
30
11
  const componentFilePath = app.dir.temp(componentFilePathRelative);
31
12
  const componentFileChunkName = key;
32
13
  return {
33
- headers,
34
- links,
35
14
  componentFilePath,
36
15
  componentFilePathRelative,
37
- componentFileContent,
38
16
  componentFileChunkName,
39
17
  };
40
18
  };
@@ -14,9 +14,8 @@ const resolvePageContent = ({ contentRaw, }) => {
14
14
  excerptRaw: '',
15
15
  };
16
16
  }
17
- const { data, content,
18
17
  /* istanbul ignore next */
19
- excerpt = '', } = matter(contentRaw, {
18
+ const { data, content, excerpt = '', } = matter(contentRaw, {
20
19
  excerpt_separator: '<!-- more -->',
21
20
  engines: {
22
21
  toml: toml.parse.bind(toml),
@@ -2,8 +2,9 @@ import type { App } from '../types';
2
2
  /**
3
3
  * Resolve page data file path
4
4
  */
5
- export declare const resolvePageDataInfo: ({ app, key, }: {
5
+ export declare const resolvePageDataInfo: ({ app, htmlFilePathRelative, key, }: {
6
6
  app: App;
7
+ htmlFilePathRelative: string;
7
8
  key: string;
8
9
  }) => {
9
10
  dataFilePath: string;
@@ -5,8 +5,8 @@ const utils_1 = require("@vuepress/utils");
5
5
  /**
6
6
  * Resolve page data file path
7
7
  */
8
- const resolvePageDataInfo = ({ app, key, }) => {
9
- const dataFilePathRelative = utils_1.path.join(`internal/pageData/${key}.js`);
8
+ const resolvePageDataInfo = ({ app, htmlFilePathRelative, key, }) => {
9
+ const dataFilePathRelative = utils_1.path.join('pages', `${htmlFilePathRelative}.js`);
10
10
  const dataFilePath = app.dir.temp(dataFilePathRelative);
11
11
  const dataFileChunkName = key;
12
12
  return {
@@ -1,4 +1,4 @@
1
- import { PageFrontmatter } from '../types';
1
+ import type { PageFrontmatter } from '../types';
2
2
  /**
3
3
  * Resolve page date according to frontmatter or file path
4
4
  *
@@ -15,14 +15,14 @@ const resolvePageDate = ({ frontmatter, filePathRelative, }) => {
15
15
  var _a, _b;
16
16
  // `frontmatter.date` could be parsed as UTC Date directly
17
17
  if (frontmatter.date instanceof Date) {
18
- return shared_1.formatDateString([
18
+ return (0, shared_1.formatDateString)([
19
19
  frontmatter.date.getUTCFullYear(),
20
20
  frontmatter.date.getUTCMonth() + 1,
21
21
  frontmatter.date.getUTCDate(),
22
22
  ].join('-'), DEFAULT_DATE);
23
23
  }
24
- if (shared_1.isString(frontmatter.date)) {
25
- return shared_1.formatDateString(frontmatter.date, DEFAULT_DATE);
24
+ if ((0, shared_1.isString)(frontmatter.date)) {
25
+ return (0, shared_1.formatDateString)(frontmatter.date, DEFAULT_DATE);
26
26
  }
27
27
  if (filePathRelative === null) {
28
28
  return DEFAULT_DATE;
@@ -31,14 +31,14 @@ const resolvePageDate = ({ frontmatter, filePathRelative, }) => {
31
31
  if (filename) {
32
32
  const matches = filename.match(FILENAME_DATE_RE);
33
33
  if (matches) {
34
- return shared_1.formatDateString(`${matches[1]}-${matches[2]}-${(_a = matches[3]) !== null && _a !== void 0 ? _a : '01'}`, DEFAULT_DATE);
34
+ return (0, shared_1.formatDateString)(`${matches[1]}-${matches[2]}-${(_a = matches[3]) !== null && _a !== void 0 ? _a : '01'}`, DEFAULT_DATE);
35
35
  }
36
36
  }
37
37
  const dirname = utils_1.path.dirname(filePathRelative);
38
- if (dirname) {
38
+ if (dirname !== '.') {
39
39
  const matches = dirname.match(DIRNAME_DATE_RE);
40
40
  if (matches) {
41
- return shared_1.formatDateString(`${matches[1]}-${matches[2]}-${(_b = matches[3]) !== null && _b !== void 0 ? _b : '01'}`, DEFAULT_DATE);
41
+ return (0, shared_1.formatDateString)(`${matches[1]}-${matches[2]}-${(_b = matches[3]) !== null && _b !== void 0 ? _b : '01'}`, DEFAULT_DATE);
42
42
  }
43
43
  }
44
44
  return DEFAULT_DATE;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resolvePageFileContent = void 0;
4
4
  const utils_1 = require("@vuepress/utils");
5
- const log = utils_1.debug('vuepress:core/page');
5
+ const log = (0, utils_1.debug)('vuepress:core/page');
6
6
  /**
7
7
  * Resolve page file content according to filePath or options content
8
8
  */
@@ -15,7 +15,7 @@ const resolvePageFileContent = async ({ filePath, options, }) => {
15
15
  return content;
16
16
  }
17
17
  catch (e) {
18
- log(e.message);
18
+ log(e instanceof Error ? e.message : e);
19
19
  }
20
20
  }
21
21
  // load raw content from options
@@ -2,7 +2,7 @@ import type { App, PageOptions } from '../types';
2
2
  /**
3
3
  * Resolve absolute and relative path of page file
4
4
  */
5
- export declare const resolvePageFilePath: ({ app, options: { filePath }, }: {
5
+ export declare const resolvePageFilePath: ({ app, options, }: {
6
6
  app: App;
7
7
  options: PageOptions;
8
8
  }) => {
@@ -5,25 +5,20 @@ const utils_1 = require("@vuepress/utils");
5
5
  /**
6
6
  * Resolve absolute and relative path of page file
7
7
  */
8
- const resolvePageFilePath = ({ app, options: { filePath }, }) => {
8
+ const resolvePageFilePath = ({ app, options, }) => {
9
9
  // empty file path
10
- if (!filePath) {
10
+ if (!options.filePath) {
11
11
  return {
12
12
  filePath: null,
13
13
  filePathRelative: null,
14
14
  };
15
15
  }
16
- // absolute file path
17
- if (utils_1.path.isAbsolute(filePath)) {
18
- return {
19
- filePath,
20
- filePathRelative: utils_1.path.relative(app.dir.source(), filePath),
21
- };
16
+ if (!utils_1.path.isAbsolute(options.filePath)) {
17
+ throw utils_1.logger.createError(`filePath is not absolute file path: ${options.filePath}}`);
22
18
  }
23
- // relative file path
24
19
  return {
25
- filePath: app.dir.source(filePath),
26
- filePathRelative: filePath,
20
+ filePath: options.filePath,
21
+ filePathRelative: utils_1.path.relative(app.dir.source(), options.filePath),
27
22
  };
28
23
  };
29
24
  exports.resolvePageFilePath = resolvePageFilePath;
@@ -0,0 +1,11 @@
1
+ import type { App } from '../types';
2
+ /**
3
+ * Resolve page rendered html file path
4
+ */
5
+ export declare const resolvePageHtmlInfo: ({ app, path: pagePath, }: {
6
+ app: App;
7
+ path: string;
8
+ }) => {
9
+ htmlFilePath: string;
10
+ htmlFilePathRelative: string;
11
+ };
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolvePageHtmlInfo = void 0;
4
+ const shared_1 = require("@vuepress/shared");
5
+ /**
6
+ * Resolve page rendered html file path
7
+ */
8
+ const resolvePageHtmlInfo = ({ app, path: pagePath, }) => {
9
+ // /foo.html -> foo.html
10
+ // /foo/ -> foo/index.html
11
+ const htmlFilePathRelative = (0, shared_1.removeLeadingSlash)(decodeURI(pagePath.replace(/\/$/, '/index.html')));
12
+ const htmlFilePath = app.dir.dest(htmlFilePathRelative);
13
+ return {
14
+ htmlFilePath,
15
+ htmlFilePathRelative,
16
+ };
17
+ };
18
+ exports.resolvePageHtmlInfo = resolvePageHtmlInfo;
@@ -5,5 +5,5 @@ const utils_1 = require("@vuepress/utils");
5
5
  /**
6
6
  * Resolve page key to identify the page
7
7
  */
8
- const resolvePageKey = ({ path }) => `v-${utils_1.hash(path)}`;
8
+ const resolvePageKey = ({ path }) => `v-${(0, utils_1.hash)(path)}`;
9
9
  exports.resolvePageKey = resolvePageKey;
@@ -6,10 +6,10 @@ const shared_1 = require("@vuepress/shared");
6
6
  * Resolve language of page
7
7
  */
8
8
  const resolvePageLang = ({ app, frontmatter, pathLocale, }) => {
9
- var _a, _b, _c;
10
- if (shared_1.isString(frontmatter.lang) && frontmatter.lang) {
9
+ var _a, _b;
10
+ if ((0, shared_1.isString)(frontmatter.lang) && frontmatter.lang) {
11
11
  return frontmatter.lang;
12
12
  }
13
- return (_c = (_b = (_a = app.siteData.locales[pathLocale]) === null || _a === void 0 ? void 0 : _a.lang) !== null && _b !== void 0 ? _b : app.siteData.lang) !== null && _c !== void 0 ? _c : '';
13
+ return (_b = (_a = app.siteData.locales[pathLocale]) === null || _a === void 0 ? void 0 : _a.lang) !== null && _b !== void 0 ? _b : app.siteData.lang;
14
14
  };
15
15
  exports.resolvePageLang = resolvePageLang;
@@ -1,8 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resolvePagePath = void 0;
4
+ const shared_1 = require("@vuepress/shared");
5
+ const utils_1 = require("@vuepress/utils");
4
6
  /**
5
7
  * Resolve the final route path of a page
6
8
  */
7
- const resolvePagePath = ({ permalink, pathInferred, options, }) => encodeURI(permalink || pathInferred || options.path || '');
9
+ const resolvePagePath = ({ permalink, pathInferred, options, }) => {
10
+ let pagePath = options.path || permalink || pathInferred;
11
+ if (!pagePath) {
12
+ throw utils_1.logger.createError(`page path is empty, page options: ${JSON.stringify(options, null, 2)}`);
13
+ }
14
+ if (!pagePath.endsWith('.html')) {
15
+ pagePath = (0, shared_1.ensureEndingSlash)(pagePath);
16
+ }
17
+ return encodeURI(pagePath);
18
+ };
8
19
  exports.resolvePagePath = resolvePagePath;
@@ -9,11 +9,11 @@ const utils_1 = require("@vuepress/utils");
9
9
  const resolvePagePermalink = ({ frontmatter, slug, date, pathInferred, pathLocale, }) => {
10
10
  var _a;
11
11
  // use permalink in frontmatter directly
12
- if (shared_1.isString(frontmatter.permalink)) {
12
+ if ((0, shared_1.isString)(frontmatter.permalink)) {
13
13
  return frontmatter.permalink;
14
14
  }
15
15
  // get permalink pattern from frontmatter or options
16
- const pattern = shared_1.isString(frontmatter.permalinkPattern)
16
+ const pattern = (0, shared_1.isString)(frontmatter.permalinkPattern)
17
17
  ? frontmatter.permalinkPattern
18
18
  : null;
19
19
  if (!pattern) {
@@ -27,6 +27,6 @@ const resolvePagePermalink = ({ frontmatter, slug, date, pathInferred, pathLocal
27
27
  .replace(/:day/, day)
28
28
  .replace(/:slug/, slug)
29
29
  .replace(/:raw/, (_a = pathInferred === null || pathInferred === void 0 ? void 0 : pathInferred.replace(/^\//, '')) !== null && _a !== void 0 ? _a : ''));
30
- return shared_1.ensureLeadingSlash(link);
30
+ return (0, shared_1.ensureLeadingSlash)(link);
31
31
  };
32
32
  exports.resolvePagePermalink = resolvePagePermalink;
@@ -0,0 +1,7 @@
1
+ import type { PageFrontmatter } from '../types';
2
+ /**
3
+ * Resolve page route meta
4
+ */
5
+ export declare const resolvePageRouteMeta: ({ frontmatter, }: {
6
+ frontmatter: PageFrontmatter;
7
+ }) => Record<string, unknown>;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolvePageRouteMeta = void 0;
4
+ /**
5
+ * Resolve page route meta
6
+ */
7
+ const resolvePageRouteMeta = ({ frontmatter, }) => { var _a; return (_a = frontmatter.routeMeta) !== null && _a !== void 0 ? _a : {}; };
8
+ exports.resolvePageRouteMeta = resolvePageRouteMeta;
@@ -2,4 +2,4 @@ import type { HookQueue } from '../types';
2
2
  /**
3
3
  * Create hook queue for plugin system
4
4
  */
5
- export declare const createHookQueue: <T extends keyof import("../types").Hooks>(name: T, parallel?: boolean) => HookQueue<T>;
5
+ export declare const createHookQueue: <T extends keyof import("../types").Hooks>(name: T) => HookQueue<T>;
@@ -1,76 +1,37 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createHookQueue = void 0;
4
- const shared_1 = require("@vuepress/shared");
5
4
  const utils_1 = require("@vuepress/utils");
6
- const log = utils_1.debug('vuepress:core/plugin-api');
5
+ const log = (0, utils_1.debug)('vuepress:core/plugin-api');
7
6
  /**
8
7
  * Create hook queue for plugin system
9
8
  */
10
- const createHookQueue = (name, parallel = false) => {
9
+ const createHookQueue = (name) => {
11
10
  const items = [];
12
11
  const hookQueue = {
13
- // hook name
14
12
  name,
15
- // hook items array
16
13
  items,
17
- // add hook item to queue
18
14
  add: (item) => {
19
15
  items.push(item);
20
16
  },
21
- // process the hook queue and get the results
22
17
  process: async (...args) => {
23
18
  // store the results of all hook items
24
19
  const results = [];
25
- // process a hook item and store the result
26
- const processItem = async (item, ...args) => {
20
+ // process all hook items
21
+ for (const item of items) {
27
22
  log(`process ${utils_1.chalk.magenta(name)} from ${utils_1.chalk.magenta(item.pluginName)}`);
28
23
  try {
29
24
  // process and get the result of the the hook item
30
- // @ts-ignore
25
+ // @ts-expect-error: the types could not be narrowed correctly
31
26
  const result = (await item.hook(...args));
32
27
  // push the result to results array
33
28
  if (result !== undefined) {
34
29
  results.push(result);
35
30
  }
36
31
  }
37
- catch (error) {
38
- utils_1.logger.error(`error in hook ${utils_1.chalk.magenta(name)} from ${utils_1.chalk.magenta(item.pluginName)}`);
39
- throw error;
40
- }
41
- };
42
- // process all hook items in current queue
43
- if (parallel) {
44
- // process in parallel
45
- await Promise.all(items.map((item) => processItem(item, ...args)));
46
- }
47
- else {
48
- // process in serial
49
- for (const item of items) {
50
- await processItem(item, ...args);
51
- }
52
- }
53
- return results;
54
- },
55
- // process the hook queue and get the results
56
- processSync: (...args) => {
57
- // store the results of all hook items
58
- const results = [];
59
- // process all hook items
60
- for (const item of items) {
61
- log(`processSync ${utils_1.chalk.magenta(name)} from ${utils_1.chalk.magenta(item.pluginName)}`);
62
- try {
63
- // @ts-ignore
64
- // process and get the result of the the hook item
65
- const result = item.hook(...args);
66
- // push the result to results array
67
- if (result !== undefined && !shared_1.isPromise(result)) {
68
- results.push(result);
69
- }
70
- }
71
- catch (error) {
32
+ catch (e) {
72
33
  utils_1.logger.error(`error in hook ${utils_1.chalk.magenta(name)} from ${utils_1.chalk.magenta(item.pluginName)}`);
73
- throw error;
34
+ throw e;
74
35
  }
75
36
  }
76
37
  return results;
@@ -5,8 +5,8 @@ const createPluginApiHooks_1 = require("./createPluginApiHooks");
5
5
  const createPluginApiRegisterHooks_1 = require("./createPluginApiRegisterHooks");
6
6
  const createPluginApi = () => {
7
7
  const plugins = [];
8
- const hooks = createPluginApiHooks_1.createPluginApiHooks();
9
- const registerHooks = createPluginApiRegisterHooks_1.createPluginApiRegisterHooks(plugins, hooks);
8
+ const hooks = (0, createPluginApiHooks_1.createPluginApiHooks)();
9
+ const registerHooks = (0, createPluginApiRegisterHooks_1.createPluginApiRegisterHooks)(plugins, hooks);
10
10
  return {
11
11
  plugins,
12
12
  hooks,
@@ -4,21 +4,21 @@ exports.createPluginApiHooks = void 0;
4
4
  const createHookQueue_1 = require("./createHookQueue");
5
5
  const createPluginApiHooks = () => ({
6
6
  // life cycle hooks
7
- onInitialized: createHookQueue_1.createHookQueue('onInitialized'),
8
- onPrepared: createHookQueue_1.createHookQueue('onPrepared'),
9
- onWatched: createHookQueue_1.createHookQueue('onWatched'),
10
- onGenerated: createHookQueue_1.createHookQueue('onGenerated'),
11
- // page hooks
12
- extendsPageOptions: createHookQueue_1.createHookQueue('extendsPageOptions'),
13
- extendsPageData: createHookQueue_1.createHookQueue('extendsPageData'),
14
- // markdown hooks
15
- extendsMarkdown: createHookQueue_1.createHookQueue('extendsMarkdown'),
7
+ onInitialized: (0, createHookQueue_1.createHookQueue)('onInitialized'),
8
+ onPrepared: (0, createHookQueue_1.createHookQueue)('onPrepared'),
9
+ onWatched: (0, createHookQueue_1.createHookQueue)('onWatched'),
10
+ onGenerated: (0, createHookQueue_1.createHookQueue)('onGenerated'),
11
+ // extends hooks
12
+ extendsMarkdownOptions: (0, createHookQueue_1.createHookQueue)('extendsMarkdownOptions'),
13
+ extendsMarkdown: (0, createHookQueue_1.createHookQueue)('extendsMarkdown'),
14
+ extendsPageOptions: (0, createHookQueue_1.createHookQueue)('extendsPageOptions'),
15
+ extendsPage: (0, createHookQueue_1.createHookQueue)('extendsPage'),
16
16
  // client files hooks
17
- clientAppEnhanceFiles: createHookQueue_1.createHookQueue('clientAppEnhanceFiles', true),
18
- clientAppRootComponentFiles: createHookQueue_1.createHookQueue('clientAppRootComponentFiles', true),
19
- clientAppSetupFiles: createHookQueue_1.createHookQueue('clientAppSetupFiles', true),
17
+ clientAppEnhanceFiles: (0, createHookQueue_1.createHookQueue)('clientAppEnhanceFiles'),
18
+ clientAppRootComponentFiles: (0, createHookQueue_1.createHookQueue)('clientAppRootComponentFiles'),
19
+ clientAppSetupFiles: (0, createHookQueue_1.createHookQueue)('clientAppSetupFiles'),
20
20
  // bundler hooks
21
- alias: createHookQueue_1.createHookQueue('alias'),
22
- define: createHookQueue_1.createHookQueue('define'),
21
+ alias: (0, createHookQueue_1.createHookQueue)('alias'),
22
+ define: (0, createHookQueue_1.createHookQueue)('define'),
23
23
  });
24
24
  exports.createPluginApiHooks = createPluginApiHooks;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createPluginApiRegisterHooks = void 0;
4
- const normalizeReturnObjectHook_1 = require("./normalizeReturnObjectHook");
5
4
  const normalizeClientFilesHook_1 = require("./normalizeClientFilesHook");
5
+ const normalizeReturnObjectHook_1 = require("./normalizeReturnObjectHook");
6
6
  const createPluginApiRegisterHooks = (plugins, hooks) => () => {
7
7
  plugins.forEach(({ name: pluginName, alias, define, clientAppEnhanceFiles, clientAppRootComponentFiles, clientAppSetupFiles, ...commonHooks }) => {
8
8
  /**
@@ -11,31 +11,31 @@ const createPluginApiRegisterHooks = (plugins, hooks) => () => {
11
11
  if (alias) {
12
12
  hooks.alias.add({
13
13
  pluginName,
14
- hook: normalizeReturnObjectHook_1.normalizeReturnObjectHook(alias),
14
+ hook: (0, normalizeReturnObjectHook_1.normalizeReturnObjectHook)(alias),
15
15
  });
16
16
  }
17
17
  if (define) {
18
18
  hooks.define.add({
19
19
  pluginName,
20
- hook: normalizeReturnObjectHook_1.normalizeReturnObjectHook(define),
20
+ hook: (0, normalizeReturnObjectHook_1.normalizeReturnObjectHook)(define),
21
21
  });
22
22
  }
23
23
  if (clientAppEnhanceFiles) {
24
24
  hooks.clientAppEnhanceFiles.add({
25
25
  pluginName,
26
- hook: normalizeClientFilesHook_1.normalizeClientFilesHook(clientAppEnhanceFiles),
26
+ hook: (0, normalizeClientFilesHook_1.normalizeClientFilesHook)(clientAppEnhanceFiles),
27
27
  });
28
28
  }
29
29
  if (clientAppRootComponentFiles) {
30
30
  hooks.clientAppRootComponentFiles.add({
31
31
  pluginName,
32
- hook: normalizeClientFilesHook_1.normalizeClientFilesHook(clientAppRootComponentFiles),
32
+ hook: (0, normalizeClientFilesHook_1.normalizeClientFilesHook)(clientAppRootComponentFiles),
33
33
  });
34
34
  }
35
35
  if (clientAppSetupFiles) {
36
36
  hooks.clientAppSetupFiles.add({
37
37
  pluginName,
38
- hook: normalizeClientFilesHook_1.normalizeClientFilesHook(clientAppSetupFiles),
38
+ hook: (0, normalizeClientFilesHook_1.normalizeClientFilesHook)(clientAppSetupFiles),
39
39
  });
40
40
  }
41
41
  /**
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -8,8 +8,8 @@ const utils_1 = require("@vuepress/utils");
8
8
  */
9
9
  const normalizeClientFilesHook = (hook) => async (app) => {
10
10
  // resolve clientFiles result
11
- const clientFilesResult = shared_1.isFunction(hook) ? await hook(app) : hook;
12
- const clientFiles = shared_1.isArray(clientFilesResult)
11
+ const clientFilesResult = (0, shared_1.isFunction)(hook) ? await hook(app) : hook;
12
+ const clientFiles = (0, shared_1.isArray)(clientFilesResult)
13
13
  ? clientFilesResult
14
14
  : [clientFilesResult];
15
15
  // filter files that do not exist
@@ -19,6 +19,9 @@ const normalizeClientFilesHook = (hook) => async (app) => {
19
19
  if (isExisted) {
20
20
  result.push(filePath);
21
21
  }
22
+ else {
23
+ throw utils_1.logger.createError(`client file does not exist: ${filePath}`);
24
+ }
22
25
  }
23
26
  return result;
24
27
  };
@@ -5,5 +5,5 @@ const shared_1 = require("@vuepress/shared");
5
5
  /**
6
6
  * Normalize hook that returns an object
7
7
  */
8
- const normalizeReturnObjectHook = (hook) => (app) => shared_1.isFunction(hook) ? hook(app) : hook;
8
+ const normalizeReturnObjectHook = (hook) => async (app) => (0, shared_1.isFunction)(hook) ? hook(app) : hook;
9
9
  exports.normalizeReturnObjectHook = normalizeReturnObjectHook;