55} from '@shikijs/twoslash' ;
66import type { ElementContent } from 'hast' ;
77import 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' ;
1010import * as ts from 'typescript' ;
1111
1212type TransformerFactory = ( options ?: TransformerTwoslashOptions ) => ShikiTransformer ;
@@ -26,37 +26,46 @@ const twoslashStorageMap = new Map();
2626export 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-
4145export const cdnTwoslashTransformer : TransformerFactory = createTransformerFactory (
4246 cdnTwoslash . runSync
4347) ;
4448
4549export 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