5
5
} from '@shikijs/twoslash' ;
6
6
import type { ElementContent } from 'hast' ;
7
7
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' ;
10
10
import * as ts from 'typescript' ;
11
11
12
12
type TransformerFactory = ( options ?: TransformerTwoslashOptions ) => ShikiTransformer ;
@@ -26,37 +26,46 @@ const twoslashStorageMap = new Map();
26
26
export const cdnTwoslash = createTwoslashFromCDN ( {
27
27
compilerOptions : twoslashCompilerOptions ,
28
28
fsMap,
29
+ fetcher ( input , init ) {
30
+ console . log ( `[GLOBAL__FETCHER] Fetching ${ input } ` ) ;
31
+ return fetch ( input , init ) ;
32
+ } ,
29
33
storage : {
30
34
getItemRaw ( key ) {
35
+ console . log ( `[GLOBAL__STORAGE] Getting item from cache: ${ key } ` ) ;
31
36
return twoslashStorageMap . get ( key ) ;
32
37
} ,
33
38
setItemRaw ( key , value ) {
39
+ console . log ( `[GLOBAL__STORAGE] Setting new item in cache: ${ key } ` ) ;
34
40
twoslashStorageMap . set ( key , value ) ;
35
41
} ,
36
42
} ,
37
43
} ) ;
38
44
39
- let cachedInstance : TwoslashCdnReturn | undefined ;
40
-
41
45
export const cdnTwoslashTransformer : TransformerFactory = createTransformerFactory (
42
46
cdnTwoslash . runSync
43
47
) ;
44
48
45
49
export function getCdnTwoslashTransformer ( options : TransformerTwoslashOptions ) : ShikiTransformer {
46
50
function getInstance ( ) {
47
- cachedInstance ??= createTwoslashFromCDN ( {
51
+ return createTwoslashFromCDN ( {
48
52
compilerOptions : twoslashCompilerOptions ,
53
+ fetcher ( input , init ) {
54
+ console . log ( `[FETCHER] Fetching ${ input } ` ) ;
55
+ return fetch ( input , init ) ;
56
+ } ,
49
57
fsMap,
50
58
storage : {
51
59
getItemRaw ( key ) {
60
+ console . log ( `[STORAGE] Getting item from cache: ${ key } ` ) ;
52
61
return twoslashStorageMap . get ( key ) ;
53
62
} ,
54
63
setItemRaw ( key , value ) {
64
+ console . log ( `[STORAGE] Setting new item in cache: ${ key } ` ) ;
55
65
twoslashStorageMap . set ( key , value ) ;
56
66
} ,
57
67
} ,
58
68
} ) ;
59
- return cachedInstance ;
60
69
}
61
70
62
71
return createTransformerFactory (
0 commit comments