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,50 @@ const twoslashStorageMap = new Map();
2626export 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 . slice ( 0 , 100 ) } ... }`
41+ ) ;
3442 twoslashStorageMap . set ( key , value ) ;
3543 } ,
3644 } ,
3745} ) ;
3846
39- let cachedInstance : TwoslashCdnReturn | undefined ;
40-
4147export const cdnTwoslashTransformer : TransformerFactory = createTransformerFactory (
4248 cdnTwoslash . runSync
4349) ;
4450
4551export 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 . slice ( 0 , 100 ) } ... }`
68+ ) ;
5569 twoslashStorageMap . set ( key , value ) ;
5670 } ,
5771 } ,
5872 } ) ;
59- return cachedInstance ;
6073 }
6174
6275 return createTransformerFactory (
0 commit comments