Commit c0a0e40 1 parent 787de2c commit c0a0e40 Copy full SHA for c0a0e40
File tree 1 file changed +15
-2
lines changed
packages/slidev/node/setups
1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change 1
1
import fs from 'node:fs/promises'
2
2
import type { MarkdownItShikiOptions } from '@shikijs/markdown-it'
3
3
import type { ShikiSetup } from '@slidev/types'
4
+ import type { Highlighter } from 'shiki'
4
5
import { bundledLanguages , createHighlighter } from 'shiki'
5
6
import { loadSetups } from './load'
6
7
8
+ let cachedRoots : string [ ] | undefined
9
+ let cachedShiki : {
10
+ shiki : Highlighter
11
+ shikiOptions : MarkdownItShikiOptions
12
+ } | undefined
13
+
7
14
export default async function setupShiki ( roots : string [ ] ) {
15
+ // Here we use shallow equality because when server is restarted, the roots will be different object.
16
+ if ( cachedRoots === roots )
17
+ return cachedShiki !
18
+ cachedShiki ?. shiki . dispose ( )
19
+
8
20
const options = await loadSetups < ShikiSetup > (
9
21
roots ,
10
22
'shiki.ts' ,
@@ -44,8 +56,9 @@ export default async function setupShiki(roots: string[]) {
44
56
themes : 'themes' in mergedOptions ? Object . values ( mergedOptions . themes ) : [ mergedOptions . theme ] ,
45
57
} )
46
58
47
- return {
59
+ cachedRoots = roots
60
+ return cachedShiki = {
48
61
shiki,
49
- shikiOptions : mergedOptions as MarkdownItShikiOptions ,
62
+ shikiOptions : mergedOptions ,
50
63
}
51
64
}
You can’t perform that action at this time.
0 commit comments