vitepress-tuck 0.5.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 +28 -18
- 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
|
@@ -44,8 +44,13 @@ const autoComponentsPlugin = definePlugin((options) => ({
|
|
|
44
44
|
})] }
|
|
45
45
|
}));
|
|
46
46
|
//#endregion
|
|
47
|
+
//#region src/builtin-plugins/ssr-no-external-deps.ts
|
|
48
|
+
const ssrNoExternalDepsPlugin = definePlugin(() => ({
|
|
49
|
+
name: "vitepress-tuck:deps",
|
|
50
|
+
vite: { ssr: { noExternal: ["vitepress-plugin-toolkit"] } }
|
|
51
|
+
}));
|
|
52
|
+
//#endregion
|
|
47
53
|
//#region src/builtin-plugins/virtual-enhance-app.ts
|
|
48
|
-
let uuid = 0;
|
|
49
54
|
/**
|
|
50
55
|
* Creates a Vite virtual module plugin that generates the
|
|
51
56
|
* `virtual:enhance-app` module on the fly.
|
|
@@ -83,17 +88,15 @@ function virtualEnhanceApp(options) {
|
|
|
83
88
|
load(id) {
|
|
84
89
|
if (id === resolveId) {
|
|
85
90
|
const { imports = [], enhances } = options;
|
|
91
|
+
const importList = [...imports];
|
|
86
92
|
const enhanceCode = [];
|
|
93
|
+
let uuid = 0;
|
|
87
94
|
enhances?.forEach(({ moduleName, exportName }) => {
|
|
88
95
|
const alias = `${exportName}$${uuid++}`;
|
|
89
|
-
|
|
90
|
-
enhanceCode.push(` ${alias}(ctx)`);
|
|
96
|
+
importList.push(`import { ${exportName} as ${alias} } from '${moduleName}/client'`);
|
|
97
|
+
enhanceCode.push(` await ${alias}(ctx)`);
|
|
91
98
|
});
|
|
92
|
-
return `${
|
|
93
|
-
export default function enhanceApp(ctx) {
|
|
94
|
-
${enhanceCode.join("\n")}
|
|
95
|
-
}
|
|
96
|
-
`;
|
|
99
|
+
return `${importList.join("\n")}\n\nexport default async function enhanceApp(ctx) {\n${enhanceCode.join("\n")}\n}\n`;
|
|
97
100
|
}
|
|
98
101
|
}
|
|
99
102
|
};
|
|
@@ -131,10 +134,7 @@ function builtinPlugins(options) {
|
|
|
131
134
|
return [
|
|
132
135
|
virtualEnhanceAppPlugin(options.enhanceApp),
|
|
133
136
|
autoComponentsPlugin(options.components),
|
|
134
|
-
()
|
|
135
|
-
name: "vitepress-tuck:deps",
|
|
136
|
-
vite: { ssr: { noExternal: ["vitepress-plugin-toolkit"] } }
|
|
137
|
-
})
|
|
137
|
+
ssrNoExternalDepsPlugin()
|
|
138
138
|
];
|
|
139
139
|
}
|
|
140
140
|
//#endregion
|
|
@@ -180,22 +180,32 @@ function mergePluginHooks(hooks, config) {
|
|
|
180
180
|
if (hooks.transformHtml.length) {
|
|
181
181
|
const transformHtml = config.transformHtml;
|
|
182
182
|
config.transformHtml = async (code, id, ctx) => {
|
|
183
|
-
for (const hook of hooks.transformHtml) code = await hook(code, id, ctx)
|
|
184
|
-
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;
|
|
185
185
|
};
|
|
186
186
|
}
|
|
187
187
|
if (hooks.transformPageData.length) {
|
|
188
188
|
const transformPageData = config.transformPageData;
|
|
189
189
|
config.transformPageData = async (pageData, ctx) => {
|
|
190
|
-
for (const hook of hooks.transformPageData)
|
|
191
|
-
|
|
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;
|
|
192
202
|
};
|
|
193
203
|
}
|
|
194
204
|
if (hooks.postRender.length) {
|
|
195
205
|
const postRender = config.postRender;
|
|
196
206
|
config.postRender = async (context) => {
|
|
197
|
-
for (const hook of hooks.postRender) context = await hook(context)
|
|
198
|
-
return await postRender?.(context)
|
|
207
|
+
for (const hook of hooks.postRender) context = await hook(context) ?? context;
|
|
208
|
+
return await postRender?.(context) ?? context;
|
|
199
209
|
};
|
|
200
210
|
}
|
|
201
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",
|