@vuepress/bundlerutils 2.0.0-rc.30 → 2.0.0-rc.32

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,42 +1,62 @@
1
- import { App } from "vue";
2
- import { Router } from "vue-router";
3
- import { App as App$1, Page } from "@vuepress/core";
1
+ import { App, Page } from "@vuepress/core";
2
+ import { App as App$1 } from "vue";
4
3
  import { VuepressSSRContext } from "@vuepress/shared";
4
+ import { Router } from "vue-router";
5
5
  import { SSRContext } from "vue/server-renderer";
6
-
7
- //#region src/build/createVueServerApp.d.ts
6
+ import { MarkdownLink } from "@vuepress/markdown";
7
+ /**
8
+ * Map from page route path to its chunk output file names.
9
+ * Used by prefetch/preload strategy.
10
+ */
11
+ type PageChunkFilesMap = Map<string, string[]>;
12
+ /**
13
+ * Create a map from page route paths to their chunk output file names.
14
+ */
15
+ export declare const createPageChunkFilesMap: ({ pages, resolvePageChunkFiles }: {
16
+ pages: Page[];
17
+ resolvePageChunkFiles: (page: Page) => string[];
18
+ }) => PageChunkFilesMap;
8
19
  /**
9
20
  * Create vue app and router for server side rendering
10
21
  */
11
- declare const createVueServerApp: (serverAppPath: string) => Promise<{
12
- vueApp: App;
22
+ export declare const createVueServerApp: (serverAppPath: string) => Promise<{
23
+ vueApp: App$1;
13
24
  vueRouter: Router;
14
25
  }>;
15
- //#endregion
16
- //#region src/build/getSsrTemplate.d.ts
17
26
  /**
18
27
  * Util to read the ssr template file
19
28
  */
20
- declare const getSsrTemplate: (app: App$1) => Promise<string>;
21
- //#endregion
22
- //#region src/build/renderPageToString.d.ts
23
- type PageSSRContext = SSRContext & VuepressSSRContext;
29
+ export declare const getSsrTemplate: (app: App) => Promise<string>;
30
+ export type PageSSRContext = SSRContext & VuepressSSRContext;
24
31
  /**
25
32
  * Render a vuepress page to string
26
33
  */
27
- declare const renderPageToString: <T extends PageSSRContext = PageSSRContext>({
28
- page,
29
- vueApp,
30
- vueRouter,
31
- ssrContextInit
32
- }: {
34
+ export declare const renderPageToString: <T extends PageSSRContext = PageSSRContext>({ page, vueApp, vueRouter, ssrContextInit }: {
33
35
  page: Page;
34
- vueApp: App;
36
+ vueApp: App$1;
35
37
  vueRouter: Router;
36
38
  ssrContextInit?: Partial<T>;
37
39
  }) => Promise<{
38
40
  ssrContext: T;
39
41
  ssrString: string;
40
42
  }>;
41
- //#endregion
42
- export { PageSSRContext, createVueServerApp, getSsrTemplate, renderPageToString };
43
+ /**
44
+ * Normalize a MarkdownLink to a route path
45
+ * that can be matched against Page.path.
46
+ *
47
+ * Returns null if the link is unresolvable.
48
+ */
49
+ export declare const resolveLinkRoutePath: ({ base, current, link }: {
50
+ base: string;
51
+ current: string;
52
+ link: MarkdownLink;
53
+ }) => string | null;
54
+ /**
55
+ * Resolve the chunk output file names of pages linked from the current page.
56
+ */
57
+ export declare const resolveLinkedPageChunkFiles: ({ base, page, pageChunkFilesMap }: {
58
+ base: string;
59
+ page: Page;
60
+ pageChunkFilesMap: PageChunkFilesMap;
61
+ }) => Set<string>;
62
+ export type { PageChunkFilesMap };
package/dist/index.js CHANGED
@@ -1,6 +1,22 @@
1
+ import { resolvePageRedirects } from "@vuepress/core";
1
2
  import { fs, importFile, importFileDefault } from "@vuepress/utils";
2
3
  import { ssrContextKey } from "vue";
3
- //#region src/build/createVueServerApp.ts
4
+ import { inferRoutePath, normalizeRoutePath } from "@vuepress/shared";
5
+ // src/build/createPageChunkFilesMap.ts
6
+ /**
7
+ * Create a map from page route paths to their chunk output file names.
8
+ */
9
+ const createPageChunkFilesMap = ({ pages, resolvePageChunkFiles }) => {
10
+ const pageChunkFilesMap = /* @__PURE__ */ new Map();
11
+ const pagePaths = new Set(pages.map((page) => page.path));
12
+ for (const page of pages) {
13
+ const pageChunkFiles = resolvePageChunkFiles(page);
14
+ pageChunkFilesMap.set(page.path, pageChunkFiles);
15
+ for (const redirect of resolvePageRedirects(page)) if (!pagePaths.has(redirect)) pageChunkFilesMap.set(redirect, pageChunkFiles);
16
+ }
17
+ return pageChunkFilesMap;
18
+ };
19
+ // src/build/createVueServerApp.ts
4
20
  /**
5
21
  * Create vue app and router for server side rendering
6
22
  */
@@ -12,14 +28,12 @@ const createVueServerApp = async (serverAppPath) => {
12
28
  vueRouter: router
13
29
  };
14
30
  };
15
- //#endregion
16
- //#region src/build/getSsrTemplate.ts
31
+ // src/build/getSsrTemplate.ts
17
32
  /**
18
33
  * Util to read the ssr template file
19
34
  */
20
35
  const getSsrTemplate = async (app) => fs.readFile(app.options.templateBuild, { encoding: "utf8" });
21
- //#endregion
22
- //#region src/build/renderPageToString.ts
36
+ // src/build/renderPageToString.ts
23
37
  /**
24
38
  * Render a vuepress page to string
25
39
  */
@@ -38,5 +52,35 @@ const renderPageToString = async ({ page, vueApp, vueRouter, ssrContextInit }) =
38
52
  ssrString: await renderToString(vueApp, ssrContext)
39
53
  };
40
54
  };
41
- //#endregion
42
- export { createVueServerApp, getSsrTemplate, renderPageToString };
55
+ // src/build/resolveLinkRoutePath.ts
56
+ /**
57
+ * Normalize a MarkdownLink to a route path
58
+ * that can be matched against Page.path.
59
+ *
60
+ * Returns null if the link is unresolvable.
61
+ */
62
+ const resolveLinkRoutePath = ({ base, current, link }) => {
63
+ if (!link.absolute) return link.relative ? normalizeRoutePath(link.relative, current) : null;
64
+ const pathWithoutBase = link.absolute.startsWith(base) ? `/${link.absolute.slice(base.length)}` : link.absolute;
65
+ return inferRoutePath(pathWithoutBase);
66
+ };
67
+ // src/build/resolveLinkedPageChunkFiles.ts
68
+ /**
69
+ * Resolve the chunk output file names of pages linked from the current page.
70
+ */
71
+ const resolveLinkedPageChunkFiles = ({ base, page, pageChunkFilesMap }) => {
72
+ const linkedPageChunkFiles = /* @__PURE__ */ new Set();
73
+ for (const link of page.links) {
74
+ const routePath = resolveLinkRoutePath({
75
+ base,
76
+ current: page.path,
77
+ link
78
+ });
79
+ if (routePath) {
80
+ const targetChunks = pageChunkFilesMap.get(routePath);
81
+ if (targetChunks) for (const file of targetChunks) linkedPageChunkFiles.add(file);
82
+ }
83
+ }
84
+ return linkedPageChunkFiles;
85
+ };
86
+ export { createPageChunkFilesMap, createVueServerApp, getSsrTemplate, renderPageToString, resolveLinkRoutePath, resolveLinkedPageChunkFiles };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuepress/bundlerutils",
3
- "version": "2.0.0-rc.30",
3
+ "version": "2.0.0-rc.32",
4
4
  "description": "Utils package of VuePress bundler",
5
5
  "keywords": [
6
6
  "bundler",
@@ -32,12 +32,13 @@
32
32
  "access": "public"
33
33
  },
34
34
  "dependencies": {
35
- "vue": "^3.5.34",
36
- "vue-router": "^5.0.6",
37
- "@vuepress/client": "2.0.0-rc.30",
38
- "@vuepress/core": "2.0.0-rc.30",
39
- "@vuepress/shared": "2.0.0-rc.30",
40
- "@vuepress/utils": "2.0.0-rc.30"
35
+ "@vuepress/client": "2.0.0-rc.32",
36
+ "@vuepress/core": "2.0.0-rc.32",
37
+ "@vuepress/markdown": "2.0.0-rc.32",
38
+ "@vuepress/shared": "2.0.0-rc.32",
39
+ "@vuepress/utils": "2.0.0-rc.32",
40
+ "vue": "^3.5.45",
41
+ "vue-router": "^5.4.0"
41
42
  },
42
43
  "tsdown": {
43
44
  "dts": true,