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,50 @@ const twoslashStorageMap = new Map();
26
26
export const cdnTwoslash = createTwoslashFromCDN ( {
27
27
compilerOptions : twoslashCompilerOptions ,
28
28
fsMap,
29
+ fetcher ( input , init ) {
30
+ console . warn ( `[GLOBAL__FETCHER]: Fetching ${ input } ` ) ;
31
+ return fetch ( input , init ) ;
32
+ } ,
29
33
storage : {
30
34
getItemRaw ( key ) {
35
+ console . warn ( `[GLOBAL__CDN-TWOSLASH] Getting item from cache: ${ key } ` ) ;
31
36
return twoslashStorageMap . get ( key ) ;
32
37
} ,
33
38
setItemRaw ( key , value ) {
39
+ console . warn (
40
+ `[GLOBAL__CDN-TWOSLASH] Setting new item in cache: { key: ${ key } , value: ${ value . slice ( 0 , 100 ) } ... }`
41
+ ) ;
34
42
twoslashStorageMap . set ( key , value ) ;
35
43
} ,
36
44
} ,
37
45
} ) ;
38
46
39
- let cachedInstance : TwoslashCdnReturn | undefined ;
40
-
41
47
export const cdnTwoslashTransformer : TransformerFactory = createTransformerFactory (
42
48
cdnTwoslash . runSync
43
49
) ;
44
50
45
51
export function getCdnTwoslashTransformer ( options : TransformerTwoslashOptions ) : ShikiTransformer {
46
52
function getInstance ( ) {
47
- cachedInstance ??= createTwoslashFromCDN ( {
53
+ return createTwoslashFromCDN ( {
48
54
compilerOptions : twoslashCompilerOptions ,
55
+ fetcher ( input , init ) {
56
+ console . warn ( `[FETCHER]: Fetching ${ input } ` ) ;
57
+ return fetch ( input , init ) ;
58
+ } ,
49
59
fsMap,
50
60
storage : {
51
61
getItemRaw ( key ) {
62
+ console . warn ( `[CDN-TWOSLASH] Getting item from cache: ${ key } ` ) ;
52
63
return twoslashStorageMap . get ( key ) ;
53
64
} ,
54
65
setItemRaw ( key , value ) {
66
+ console . warn (
67
+ `[CDN-TWOSLASH] Setting new item in cache: { key: ${ key } , value: ${ value . slice ( 0 , 100 ) } ... }`
68
+ ) ;
55
69
twoslashStorageMap . set ( key , value ) ;
56
70
} ,
57
71
} ,
58
72
} ) ;
59
- return cachedInstance ;
60
73
}
61
74
62
75
return createTransformerFactory (
0 commit comments