Skip to content

Commit 03c62c9

Browse files
committed
fix
1 parent 73922ea commit 03c62c9

File tree

4 files changed

+1124
-29
lines changed

4 files changed

+1124
-29
lines changed

apps/svelte.dev/package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,20 @@
4747
"yootils": "^0.3.1"
4848
},
4949
"devDependencies": {
50-
"@cloudflare/workers-types": "^4.20241127.0",
50+
"@cloudflare/workers-types": "^4.20250620.0",
5151
"@resvg/resvg-js": "^2.6.2",
5252
"@supabase/supabase-js": "^2.43.4",
53+
"@sveltejs/adapter-cloudflare": "^7.0.4",
54+
"@sveltejs/adapter-netlify": "^5.0.2",
55+
"@sveltejs/adapter-node": "^5.2.12",
56+
"@sveltejs/adapter-static": "^3.0.8",
5357
"@sveltejs/adapter-vercel": "^5.7.0",
5458
"@sveltejs/enhanced-img": "^0.4.3",
5559
"@sveltejs/kit": "^2.20.0",
5660
"@sveltejs/site-kit": "workspace:*",
5761
"@sveltejs/vite-plugin-svelte": "4.0.3",
5862
"@types/cookie": "^0.6.0",
63+
"@types/express": "^5.0.3",
5964
"@types/node": "^20.14.2",
6065
"browserslist": "^4.24.2",
6166
"chokidar": "^4.0.1",

apps/svelte.dev/src/lib/server/renderer.ts

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@ export const render_content = (
77
) => {
88
return render_content_markdown(filename, body, options, (filename, source) => {
99
// TODO these are copied from Svelte and SvelteKit - adjust for new filenames
10-
const injected = [];
11-
12-
if (/(svelte)/.test(source) || filename.includes('typescript')) {
13-
injected.push(`// @filename: ambient.d.ts`, `/// <reference types="svelte" />`);
14-
}
10+
const injected: string[] = [];
1511

1612
if (filename.includes('svelte-compiler')) {
1713
injected.push('// @esModuleInterop');
@@ -22,7 +18,7 @@ export const render_content = (
2218
}
2319

2420
// Actions JSDoc examples are invalid. Too many errors, edge cases
25-
// d.ts files are not properly supported right now, fix this later
21+
// TODO: d.ts files are not properly supported right now, fix this later
2622
if (filename.includes('svelte-action') || source.includes(' declare const ')) {
2723
injected.push('// @noErrors');
2824
}
@@ -31,10 +27,11 @@ export const render_content = (
3127
injected.push('// @errors: 2304');
3228
}
3329

30+
// twoslash doesn't recognise these as SvelteKit imports, so we need to
31+
// explicitly reference the types in these instances
3432
if (
3533
source.includes('$app/') ||
36-
source.includes('$service-worker') ||
37-
source.includes('@sveltejs/kit/')
34+
source.includes('$service-worker')
3835
) {
3936
injected.push(`// @filename: ambient-kit.d.ts`, `/// <reference types="@sveltejs/kit" />`);
4037
}
@@ -43,10 +40,11 @@ export const render_content = (
4340
// TODO we're hardcoding static env vars that are used in code examples
4441
// in the types, which isn't... totally ideal, but will do for now
4542
injected.push(
46-
`declare module '$env/dynamic/private' { export const env: Record<string, string> }`,
47-
`declare module '$env/dynamic/public' { export const env: Record<string, string> }`,
48-
`declare module '$env/static/private' { export const API_KEY: string }`,
49-
`declare module '$env/static/public' { export const PUBLIC_BASE_URL: string }`
43+
`declare module '$env/dynamic/private' { export const env: Record<string, string>; }`,
44+
`declare module '$env/dynamic/public' { export const env: Record<string, string>; }`,
45+
// TODO: detect when a snippet imports from $env/static then generate the types on the fly
46+
`declare module '$env/static/private' { export const API_KEY: string; export const BYPASS_TOKEN: string; export const VERCEL_COMMIT_REF: string; }`,
47+
`declare module '$env/static/public' { export const PUBLIC_BASE_URL: string; }`
5048
);
5149
}
5250

@@ -71,10 +69,6 @@ export const render_content = (
7169
injected.push('// @errors: 7006 7031');
7270
}
7371

74-
if (filename.endsWith('10-configuration.md')) {
75-
injected.push('// @errors: 2307');
76-
}
77-
7872
// another special case
7973
if (source.includes('$lib/types')) {
8074
injected.push(`declare module '$lib/types' { export interface User {} }`);

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ const highlighter = await createHighlighterCore({
5454
import('@shikijs/langs/css'),
5555
import('@shikijs/langs/bash'),
5656
import('@shikijs/langs/yaml'),
57+
import('@shikijs/langs/toml'),
5758
import('@shikijs/langs/svelte')
5859
],
5960
engine: createOnigurumaEngine(import('shiki/wasm'))
@@ -234,7 +235,14 @@ export async function render_content_markdown(
234235

235236
if ((token.lang === 'js' || token.lang === 'ts') && check) {
236237
const match = /((?:[\s\S]+)\/\/ ---cut---\n)?([\s\S]+)/.exec(source)!;
237-
[, prelude = '// ---cut---\n', source] = match;
238+
// we need to ensure that the source content is separated from the
239+
// injected content by a '// @filename: ...' otherwise it will be
240+
// interpreted as the same file and prevent types from working
241+
[
242+
,
243+
prelude = `${source.includes('// @filename:') ? '' : '// @filename: dummy.' + token.lang}\n// ---cut---\n`,
244+
source
245+
] = match;
238246

239247
const banner = twoslashBanner?.(filename, source);
240248
if (banner) prelude = '// @filename: injected.d.ts\n' + banner + '\n' + prelude;
@@ -757,7 +765,7 @@ async function syntax_highlight({
757765
/** We need to stash code wrapped in `---` highlights, because otherwise TS will error on e.g. bad syntax, duplicate declarations */
758766
const redactions: string[] = [];
759767

760-
const redacted = source.replace(/( {13}(?:[^ ][^]+?) {13})/g, (_, content) => {
768+
let redacted = source.replace(/( {13}(?:[^ ][^]+?) {13})/g, (_, content) => {
761769
redactions.push(content);
762770
return ' '.repeat(content.length);
763771
});
@@ -773,7 +781,9 @@ async function syntax_highlight({
773781
compilerOptions: {
774782
allowJs: true,
775783
checkJs: true,
776-
types: ['svelte', '@sveltejs/kit']
784+
// we always include the Svelte types because it's easier
785+
// than adding a reference when we detect a rune being used
786+
types: ['node', 'svelte']
777787
}
778788
},
779789
// by default, twoslash does not run on .js files, change that through this option
@@ -860,7 +870,7 @@ async function syntax_highlight({
860870
html = replace_blank_lines(html);
861871
} else {
862872
const highlighted = highlighter.codeToHtml(source, {
863-
lang: SHIKI_LANGUAGE_MAP[language as keyof typeof SHIKI_LANGUAGE_MAP],
873+
lang: SHIKI_LANGUAGE_MAP[language as keyof typeof SHIKI_LANGUAGE_MAP] ?? language,
864874
theme
865875
});
866876

@@ -884,6 +894,7 @@ async function syntax_highlight({
884894
.replace(/ {11}([^ ][^]+?) {11}/g, (_, content) => {
885895
return highlight_spans(content, 'highlight add');
886896
})
897+
// TODO: make this not highlight the static adapter's github yaml deploy file
887898
.replace(/ {9}([^ ][^]+?) {9}/g, (_, content) => {
888899
return highlight_spans(content, 'highlight');
889900
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy