vitepress-tuck 0.6.0 → 0.7.0
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/client-types.d.ts +2 -1
- package/dist/index.js +21 -14
- package/package.json +1 -1
package/client-types.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
declare module 'virtual:enhance-app' {
|
|
2
2
|
|
|
3
|
+
import type { Awaitable } from '@pengzhanbo/utils'
|
|
3
4
|
import type { EnhanceAppContext } from 'vitepress/client'
|
|
4
5
|
|
|
5
|
-
const enhanceApp: (ctx: EnhanceAppContext) => void
|
|
6
|
+
const enhanceApp: (ctx: EnhanceAppContext) => Awaitable<void>
|
|
6
7
|
export default enhanceApp
|
|
7
8
|
}
|
package/dist/index.js
CHANGED
|
@@ -51,7 +51,6 @@ const ssrNoExternalDepsPlugin = definePlugin(() => ({
|
|
|
51
51
|
}));
|
|
52
52
|
//#endregion
|
|
53
53
|
//#region src/builtin-plugins/virtual-enhance-app.ts
|
|
54
|
-
let uuid = 0;
|
|
55
54
|
/**
|
|
56
55
|
* Creates a Vite virtual module plugin that generates the
|
|
57
56
|
* `virtual:enhance-app` module on the fly.
|
|
@@ -89,17 +88,15 @@ function virtualEnhanceApp(options) {
|
|
|
89
88
|
load(id) {
|
|
90
89
|
if (id === resolveId) {
|
|
91
90
|
const { imports = [], enhances } = options;
|
|
91
|
+
const importList = [...imports];
|
|
92
92
|
const enhanceCode = [];
|
|
93
|
+
let uuid = 0;
|
|
93
94
|
enhances?.forEach(({ moduleName, exportName }) => {
|
|
94
95
|
const alias = `${exportName}$${uuid++}`;
|
|
95
|
-
|
|
96
|
-
enhanceCode.push(` ${alias}(ctx)`);
|
|
96
|
+
importList.push(`import { ${exportName} as ${alias} } from '${moduleName}/client'`);
|
|
97
|
+
enhanceCode.push(` await ${alias}(ctx)`);
|
|
97
98
|
});
|
|
98
|
-
return `${
|
|
99
|
-
export default function enhanceApp(ctx) {
|
|
100
|
-
${enhanceCode.join("\n")}
|
|
101
|
-
}
|
|
102
|
-
`;
|
|
99
|
+
return `${importList.join("\n")}\n\nexport default async function enhanceApp(ctx) {\n${enhanceCode.join("\n")}\n}\n`;
|
|
103
100
|
}
|
|
104
101
|
}
|
|
105
102
|
};
|
|
@@ -183,22 +180,32 @@ function mergePluginHooks(hooks, config) {
|
|
|
183
180
|
if (hooks.transformHtml.length) {
|
|
184
181
|
const transformHtml = config.transformHtml;
|
|
185
182
|
config.transformHtml = async (code, id, ctx) => {
|
|
186
|
-
for (const hook of hooks.transformHtml) code = await hook(code, id, ctx)
|
|
187
|
-
return await transformHtml?.(code, id, ctx)
|
|
183
|
+
for (const hook of hooks.transformHtml) code = await hook(code, id, ctx) ?? code;
|
|
184
|
+
return await transformHtml?.(code, id, ctx) ?? code;
|
|
188
185
|
};
|
|
189
186
|
}
|
|
190
187
|
if (hooks.transformPageData.length) {
|
|
191
188
|
const transformPageData = config.transformPageData;
|
|
192
189
|
config.transformPageData = async (pageData, ctx) => {
|
|
193
|
-
for (const hook of hooks.transformPageData)
|
|
194
|
-
|
|
190
|
+
for (const hook of hooks.transformPageData) {
|
|
191
|
+
const result = await hook(pageData, ctx);
|
|
192
|
+
if (result) pageData = {
|
|
193
|
+
...pageData,
|
|
194
|
+
...result
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
const result = await transformPageData?.(pageData, ctx);
|
|
198
|
+
return result ? {
|
|
199
|
+
...pageData,
|
|
200
|
+
...result
|
|
201
|
+
} : pageData;
|
|
195
202
|
};
|
|
196
203
|
}
|
|
197
204
|
if (hooks.postRender.length) {
|
|
198
205
|
const postRender = config.postRender;
|
|
199
206
|
config.postRender = async (context) => {
|
|
200
|
-
for (const hook of hooks.postRender) context = await hook(context)
|
|
201
|
-
return await postRender?.(context)
|
|
207
|
+
for (const hook of hooks.postRender) context = await hook(context) ?? context;
|
|
208
|
+
return await postRender?.(context) ?? context;
|
|
202
209
|
};
|
|
203
210
|
}
|
|
204
211
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitepress-tuck",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.7.0",
|
|
5
5
|
"description": "Enhance vitepress configuration, provide plugins capability.",
|
|
6
6
|
"author": "pengzhanbo <q942450674@outlook.com> (https://github.com/pengzhanbo/)",
|
|
7
7
|
"license": "MIT",
|