Skip to content

Commit 253b7db

Browse files
chore: add logging
1 parent b1bf129 commit 253b7db

File tree

1 file changed

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

1 file changed

+19
-6
lines changed

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

Lines changed: 19 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,50 @@ const twoslashStorageMap = new Map();
2626
export const cdnTwoslash = createTwoslashFromCDN({
2727
compilerOptions: twoslashCompilerOptions,
2828
fsMap,
29+
fetcher(input, init) {
30+
console.warn(`[GLOBAL__FETCHER]: Fetching ${input}`);
31+
return fetch(input, init);
32+
},
2933
storage: {
3034
getItemRaw(key) {
35+
console.warn(`[GLOBAL__CDN-TWOSLASH] Getting item from cache: ${key}`);
3136
return twoslashStorageMap.get(key);
3237
},
3338
setItemRaw(key, value) {
39+
console.warn(
40+
`[GLOBAL__CDN-TWOSLASH] Setting new item in cache: { key: ${key}, value: ${value} }`
41+
);
3442
twoslashStorageMap.set(key, value);
3543
},
3644
},
3745
});
3846

39-
let cachedInstance: TwoslashCdnReturn | undefined;
40-
4147
export const cdnTwoslashTransformer: TransformerFactory = createTransformerFactory(
4248
cdnTwoslash.runSync
4349
);
4450

4551
export function getCdnTwoslashTransformer(options: TransformerTwoslashOptions): ShikiTransformer {
4652
function getInstance() {
47-
cachedInstance ??= createTwoslashFromCDN({
53+
return createTwoslashFromCDN({
4854
compilerOptions: twoslashCompilerOptions,
55+
fetcher(input, init) {
56+
console.warn(`[FETCHER]: Fetching ${input}`);
57+
return fetch(input, init);
58+
},
4959
fsMap,
5060
storage: {
5161
getItemRaw(key) {
62+
console.warn(`[CDN-TWOSLASH] Getting item from cache: ${key}`);
5263
return twoslashStorageMap.get(key);
5364
},
5465
setItemRaw(key, value) {
66+
console.warn(
67+
`[CDN-TWOSLASH] Setting new item in cache: { key: ${key}, value: ${value} }`
68+
);
5569
twoslashStorageMap.set(key, value);
5670
},
5771
},
5872
});
59-
return cachedInstance;
6073
}
6174

6275
return createTransformerFactory(

0 commit comments

Comments
 (0)