Skip to content

Commit

Permalink
refactor: use JavaScriptRegexp Engine for shiki, drop wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
alexzhang1030 committed Sep 2, 2024
1 parent a134eaf commit 16fb886
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 40 deletions.
2 changes: 1 addition & 1 deletion packages/applet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@vue/devtools-ui": "workspace:^",
"lodash-es": "^4.17.21",
"perfect-debounce": "^1.0.0",
"shiki": "^1.14.1",
"shiki": "^1.16.1",
"splitpanes": "^3.1.5",
"vue-virtual-scroller": "2.0.0-beta.8"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/chrome-extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
}
],
"content_security_policy": {
"extension_pages": "script-src 'self' 'wasm-unsafe-eval'; object-src 'self'"
"extension_pages": "script-src 'self'; object-src 'self'"
},
"description": "DevTools browser extension for Vue.js",
"devtools_page": "pages/devtools-background.html",
Expand Down
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"fast-deep-equal": "^3.1.3",
"fuse.js": "^7.0.0",
"minimatch": "^10.0.1",
"shiki": "^1.14.1",
"shiki": "^1.16.1",
"splitpanes": "^3.1.5",
"vis-network": "^9.1.9",
"vite-hot-client": "^0.2.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/firefox-extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"run_at": "document_idle"
}
],
"content_security_policy": "script-src 'self' 'wasm-unsafe-eval'; object-src 'self'",
"content_security_policy": "script-src 'self'; object-src 'self'",
"description": "DevTools browser extension for Vue.js",
"devtools_page": "devtools-background.html",
"icons": {
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"peerDependencies": {
"@unocss/reset": ">=0.50.0-0",
"floating-vue": ">=2.0.0-0",
"shiki": ">=1.10.0",
"shiki": ">=1.16.0",
"unocss": ">=0.50.0-0",
"vue": ">=3.0.0-0"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/ui/src/composables/shiki.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { BuiltinLanguage, HighlighterCore } from 'shiki'
import { createHighlighterCore } from 'shiki/core'
import getWasm from 'shiki/wasm'
import { createHighlighterCore, createJavaScriptRegexEngine } from 'shiki/core'
import { shallowRef } from 'vue'

export const shiki = shallowRef<HighlighterCore>()
Expand All @@ -9,6 +8,7 @@ let promise: Promise<any> | null = null

export function renderCodeHighlight(code: string, lang: BuiltinLanguage | 'text' = 'text') {
if (!promise && !shiki.value) {
const jsEngine = createJavaScriptRegexEngine()
// Only loading when needed
promise = createHighlighterCore({
themes: [
Expand All @@ -27,7 +27,7 @@ export function renderCodeHighlight(code: string, lang: BuiltinLanguage | 'text'
import('shiki/langs/diff.mjs'),
import('shiki/langs/shellscript.mjs'),
],
loadWasm: getWasm,
engine: jsEngine,
}).then((i) => {
shiki.value = i
})
Expand Down
66 changes: 34 additions & 32 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 16fb886

Please sign in to comment.