Skip to content

Commit 42b1a5e

Browse files
authored
remove shiki@1 (#1269)
* remove shiki@1 * WIP * i think it works?
1 parent 55d8003 commit 42b1a5e

File tree

5 files changed

+39
-145
lines changed

5 files changed

+39
-145
lines changed

apps/svelte.dev/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
"@lezer/javascript": "^1.4.7",
2222
"@lezer/lr": "^1.3.10",
2323
"@rich_harris/svelte-split-pane": "^2.0.0",
24-
"@shikijs/twoslash": "^1.22.0",
2524
"@sveltejs/amp": "^1.1.4",
2625
"@sveltejs/repl": "workspace:*",
2726
"@testing-library/dom": "^10.4.0",
@@ -41,7 +40,6 @@
4140
"flexsearch": "^0.7.43",
4241
"flru": "^1.0.2",
4342
"port-authority": "^2.0.1",
44-
"shiki": "^1.22.0",
4543
"topojson-client": "^3.1.0",
4644
"vitest": "^2.1.9",
4745
"ws": "^8.18.0",

apps/svelte.dev/vite.config.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,20 @@ const config: UserConfig = {
5959
}
6060
},
6161
build: {
62-
cssMinify: 'lightningcss'
62+
cssMinify: 'lightningcss',
63+
rollupOptions: {
64+
output: {
65+
banner: (chunk) => {
66+
// this monstrosity is required for twoslash (which uses `require`) to work during prerendering.
67+
// it is brittle and may not work in perpetuity but i'm not sure what a better solution would be
68+
if (chunk.type === 'chunk' && chunk.name === 'renderer') {
69+
return `import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);`;
70+
}
71+
72+
return '';
73+
}
74+
}
75+
}
6376
},
6477
server: {
6578
fs: { allow: ['../../packages', '../../../KIT/kit/packages/kit'] },
@@ -74,8 +87,7 @@ const config: UserConfig = {
7487
exclude: ['@sveltejs/site-kit', '@sveltejs/repl', '@rollup/browser']
7588
},
7689
ssr: {
77-
noExternal: ['@sveltejs/site-kit', '@sveltejs/repl'],
78-
external: ['shiki', '@shikijs/twoslash']
90+
noExternal: ['@sveltejs/site-kit', '@sveltejs/repl']
7991
},
8092
worker: {
8193
format: 'es'

packages/site-kit/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"@fontsource/fira-sans": "^5.1.0",
3939
"@lezer/common": "^1.0.4",
4040
"@replit/codemirror-lang-svelte": "^6.0.0",
41+
"@shikijs/langs": "^3.2.1",
4142
"@shikijs/twoslash": "^3.2.1",
4243
"esm-env": "^1.0.0",
4344
"json5": "^2.2.3",

packages/site-kit/src/lib/markdown/renderer.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import process from 'node:process';
55
import path from 'node:path';
66
import ts from 'typescript';
77
import * as marked from 'marked';
8-
import { codeToHtml, createCssVariablesTheme } from 'shiki';
8+
import { createHighlighterCore } from 'shiki/core';
9+
import { createOnigurumaEngine } from 'shiki/engine/oniguruma';
10+
import { createCssVariablesTheme } from 'shiki';
911
import { transformerTwoslash } from '@shikijs/twoslash';
1012
import { SHIKI_LANGUAGE_MAP, slugify, smart_quotes, transform } from './utils';
1113

@@ -43,6 +45,20 @@ if (!fs.existsSync(original_file)) {
4345
hash_graph(hash, original_file);
4446
const digest = hash.digest().toString('base64').replace(/\//g, '-');
4547

48+
const highlighter = await createHighlighterCore({
49+
themes: [],
50+
langs: [
51+
import('@shikijs/langs/javascript'),
52+
import('@shikijs/langs/typescript'),
53+
import('@shikijs/langs/html'),
54+
import('@shikijs/langs/css'),
55+
import('@shikijs/langs/bash'),
56+
import('@shikijs/langs/yaml'),
57+
import('@shikijs/langs/svelte')
58+
],
59+
engine: createOnigurumaEngine(import('shiki/wasm'))
60+
});
61+
4662
/**
4763
* Utility function to work with code snippet caching.
4864
*
@@ -722,7 +738,7 @@ async function syntax_highlight({
722738

723739
if (/^(dts|yaml|yml)/.test(language)) {
724740
html = replace_blank_lines(
725-
await codeToHtml(source, {
741+
highlighter.codeToHtml(source, {
726742
lang: language === 'dts' ? 'ts' : language,
727743
theme
728744
})
@@ -737,7 +753,7 @@ async function syntax_highlight({
737753
});
738754

739755
try {
740-
html = await codeToHtml(prelude + redacted, {
756+
html = highlighter.codeToHtml(prelude + redacted, {
741757
lang: language,
742758
theme,
743759
transformers: check
@@ -833,7 +849,7 @@ async function syntax_highlight({
833849

834850
html = replace_blank_lines(html);
835851
} else {
836-
const highlighted = await codeToHtml(source, {
852+
const highlighted = highlighter.codeToHtml(source, {
837853
lang: SHIKI_LANGUAGE_MAP[language as keyof typeof SHIKI_LANGUAGE_MAP],
838854
theme
839855
});

0 commit comments

Comments
 (0)