Skip to content

Commit 6aed02f

Browse files
authored
chore: upgrade shiki v3 (#349)
1 parent 9717a71 commit 6aed02f

File tree

7 files changed

+73
-75
lines changed

7 files changed

+73
-75
lines changed

package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,12 @@
6868
"lint": "eslint .",
6969
"typecheck": "nuxt typecheck",
7070
"test": "vitest run",
71-
"test:watch": "vitest watch"
71+
"test:watch": "vitest watch",
72+
"verify": "npm run dev:prepare && npm run lint && npm run test && npm run typecheck"
7273
},
7374
"dependencies": {
7475
"@nuxt/kit": "^3.15.2",
75-
"@shikijs/transformers": "^1.27.2",
76+
"@shikijs/transformers": "^3.0.0",
7677
"@types/hast": "^3.0.4",
7778
"@types/mdast": "^4.0.4",
7879
"@vue/compiler-core": "^3.5.13",
@@ -105,7 +106,7 @@
105106
"remark-rehype": "^11.1.1",
106107
"remark-stringify": "^11.0.0",
107108
"scule": "^1.3.0",
108-
"shiki": "^1.27.2",
109+
"shiki": "^3.0.0",
109110
"ufo": "^1.5.4",
110111
"unified": "^11.0.5",
111112
"unist-builder": "^4.0.0",

playground/nuxt.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default defineNuxtConfig({
1414
default: 'vitesse-light',
1515
dark: 'material-theme-palenight'
1616
},
17-
shikiEngine: 'javascript',
17+
shikiEngine: 'oniguruma',
1818
preload: [
1919
'sql'
2020
]

playground/pages/index.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ onMounted(() => {
5151
<Editor v-model:code="source" class="flex-1" />
5252
<!-- MDC AST -->
5353
<code class="text-xs px-2 py-1">MDC AST</code>
54-
<Editor :code="JSON.stringify(ast?.body, null, 2)" language="json" class="flex-1" read-only />
54+
<Editor :code="JSON.stringify(ast?.body, null, 2) || ''" language="json" class="flex-1" read-only />
5555
</div>
5656
<div class="flex-1 h-full flex flex-col border-2 border-neutral-900">
5757
<code class="text-xs px-2 py-1">Source -> MDC -> Render</code>

pnpm-lock.yaml

+61-64
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/runtime/highlighter/shiki.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { CodeToHastOptions } from 'shiki/core'
2-
import type { HighlighterCore, LanguageInput, ShikiTransformer, ThemeInput, RegexEngine } from 'shiki'
2+
import { type HighlighterCore, type LanguageInput, type ShikiTransformer, type ThemeInput, type RegexEngine, createJavaScriptRegexEngine } from 'shiki'
33
import type { Element } from 'hast'
44
import type { MdcConfig, Highlighter } from '@nuxtjs/mdc'
55

@@ -39,7 +39,7 @@ export function createShikiHighlighter({
3939
const shiki: HighlighterCore = await createHighlighterCore({
4040
langs,
4141
themes,
42-
engine
42+
engine: engine || createJavaScriptRegexEngine()
4343
})
4444

4545
for await (const config of await getConfigs()) {

src/templates/mdc-highlighter.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export async function mdcHighlighter({
7575
'import { getMdcConfigs } from \'#mdc-configs\'',
7676
shikiEngine === 'javascript'
7777
? 'import { createJavaScriptRegexEngine } from \'shiki/engine/javascript\''
78-
: 'import { createWasmOnigEngine } from \'shiki/engine/oniguruma\'',
78+
: 'import { createOnigurumaEngine } from \'shiki/engine/oniguruma\'',
7979
code,
8080
'const bundledLangs = {',
8181
...Array.from(langsMap.entries())
@@ -94,7 +94,7 @@ export async function mdcHighlighter({
9494
}),
9595
shikiEngine === 'javascript'
9696
? 'const engine = createJavaScriptRegexEngine({ forgiving: true })'
97-
: `const engine = createWasmOnigEngine(() => import('shiki/wasm'))`,
97+
: `const engine = createOnigurumaEngine(() => import('shiki/wasm'))`,
9898
'const highlighter = createShikiHighlighter({ bundledLangs, bundledThemes, options, getMdcConfigs, engine })',
9999
'export default highlighter'
100100
].join('\n')

test/utils/parser.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { vi } from 'vitest'
2-
import { createWasmOnigEngine } from 'shiki/engine/oniguruma'
2+
import { createOnigurumaEngine } from 'shiki/engine/oniguruma'
33
import { createShikiHighlighter } from '../../src/runtime/highlighter/shiki'
44
import { rehypeHighlight } from '../../src/runtime/highlighter/rehype-nuxt'
55
import type { MDCParseOptions } from '../../src/types'
@@ -35,7 +35,7 @@ export const parseMarkdown = (md: string, options: MDCParseOptions = {}) => {
3535
],
3636
options: {},
3737
getMdcConfigs: async () => [],
38-
engine: createWasmOnigEngine(import('shiki/wasm'))
38+
engine: createOnigurumaEngine(import('shiki/wasm'))
3939
})
4040

4141
options.highlight.highlighter = highlighter

0 commit comments

Comments
 (0)