mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-25 04:20:02 +00:00
Core: Fix rehypeCode() tsdoc for lazy option
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'fumadocs-core': patch
|
||||
---
|
||||
|
||||
Fix `rehypeCode()` tsdoc for `lazy` option
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'fumadocs-twoslash': patch
|
||||
---
|
||||
|
||||
bump deps
|
||||
@@ -60,7 +60,17 @@ function parseLineNumber(str: string, data: Record<string, unknown>) {
|
||||
});
|
||||
}
|
||||
|
||||
export type RehypeCodeOptions = RehypeShikiOptions & {
|
||||
type DistributiveOmit<T, K extends keyof T> = T extends unknown
|
||||
? Omit<T, K>
|
||||
: never;
|
||||
|
||||
export type RehypeCodeOptions = DistributiveOmit<RehypeShikiOptions, 'lazy'> & {
|
||||
/**
|
||||
* Load languages and themes on-demand.
|
||||
* @defaultValue true
|
||||
*/
|
||||
lazy?: boolean;
|
||||
|
||||
/**
|
||||
* The regex engine to use.
|
||||
*
|
||||
|
||||
@@ -28,9 +28,16 @@ export function transformerTwoslash(
|
||||
): ShikiTransformer {
|
||||
const ignoreClass = 'nd-copy-ignore';
|
||||
|
||||
function getInstance() {
|
||||
cachedInstance ??= createTwoslasher(options.twoslashOptions);
|
||||
return cachedInstance;
|
||||
// lazy load Twoslash instance so it works on serverless platforms
|
||||
function lazyInstance(): TwoslashInstance {
|
||||
function get() {
|
||||
return (cachedInstance ??= createTwoslasher(options.twoslashOptions));
|
||||
}
|
||||
|
||||
const wrapper: TwoslashInstance = (...args) => get()(...args);
|
||||
|
||||
wrapper.getCacheMap = () => get().getCacheMap();
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
const renderer = rendererRich({
|
||||
@@ -109,8 +116,7 @@ export function transformerTwoslash(
|
||||
return result;
|
||||
};
|
||||
return createTransformerFactory(
|
||||
// lazy load Twoslash instance so it works on serverless platforms
|
||||
((...args) => getInstance()(...args)) as TwoslashInstance,
|
||||
lazyInstance(),
|
||||
renderer,
|
||||
)({
|
||||
explicitTrigger: true,
|
||||
|
||||
Reference in New Issue
Block a user