Skip to content

Commit 64edb6d

Browse files
chore: add logging
1 parent 8b16236 commit 64edb6d

File tree

1 file changed

+15
-6
lines changed
  • packages/mdx/src/plugins/rehype/twoslash

1 file changed

+15
-6
lines changed

packages/mdx/src/plugins/rehype/twoslash/config.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import {
55
} from '@shikijs/twoslash';
66
import type { ElementContent } from 'hast';
77
import type { ShikiTransformer } from 'shiki/types';
8-
import { createTwoslasher, type TwoslashInstance } from 'twoslash';
9-
import { createTwoslashFromCDN, TwoslashCdnReturn } from 'twoslash-cdn';
8+
import type { TwoslashInstance } from 'twoslash';
9+
import { createTwoslashFromCDN } from 'twoslash-cdn';
1010
import * as ts from 'typescript';
1111

1212
type TransformerFactory = (options?: TransformerTwoslashOptions) => ShikiTransformer;
@@ -26,37 +26,46 @@ const twoslashStorageMap = new Map();
2626
export const cdnTwoslash = createTwoslashFromCDN({
2727
compilerOptions: twoslashCompilerOptions,
2828
fsMap,
29+
fetcher(input, init) {
30+
console.log(`[GLOBAL__FETCHER] Fetching ${input}`);
31+
return fetch(input, init);
32+
},
2933
storage: {
3034
getItemRaw(key) {
35+
console.log(`[GLOBAL__STORAGE] Getting ${key}`);
3136
return twoslashStorageMap.get(key);
3237
},
3338
setItemRaw(key, value) {
39+
console.log(`[GLOBAL__STORAGE] Setting ${key}`);
3440
twoslashStorageMap.set(key, value);
3541
},
3642
},
3743
});
3844

39-
let cachedInstance: TwoslashCdnReturn | undefined;
40-
4145
export const cdnTwoslashTransformer: TransformerFactory = createTransformerFactory(
4246
cdnTwoslash.runSync
4347
);
4448

4549
export function getCdnTwoslashTransformer(options: TransformerTwoslashOptions): ShikiTransformer {
4650
function getInstance() {
47-
cachedInstance ??= createTwoslashFromCDN({
51+
return createTwoslashFromCDN({
4852
compilerOptions: twoslashCompilerOptions,
53+
fetcher(input, init) {
54+
console.log(`[FETCHER] Fetching ${input}`);
55+
return fetch(input, init);
56+
},
4957
fsMap,
5058
storage: {
5159
getItemRaw(key) {
60+
console.log(`[STORAGE] Getting ${key}`);
5261
return twoslashStorageMap.get(key);
5362
},
5463
setItemRaw(key, value) {
64+
console.log(`[STORAGE] Setting ${key}`);
5565
twoslashStorageMap.set(key, value);
5666
},
5767
},
5868
});
59-
return cachedInstance;
6069
}
6170

6271
return createTransformerFactory(

0 commit comments

Comments
 (0)