Skip to content

Commit a765841

Browse files
authored
feat: build cli types during docs sync (#1882)
* feat: build cli repo types during docs sync for twoslash support * rmv TODO JYC as we have no error anymore * pnpm i * patch types of svelte & kit * no need comment!
1 parent 88b853c commit a765841

4 files changed

Lines changed: 57 additions & 9 deletions

File tree

apps/svelte.dev/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"@sveltejs/enhanced-img": "^0.10.3",
5858
"@sveltejs/kit": "^2.53.2",
5959
"@sveltejs/site-kit": "workspace:*",
60+
"@sveltejs/sv-utils": "^0.0.3",
6061
"@sveltejs/vite-plugin-svelte": "^7.0.0",
6162
"@types/node": "^20.19.33",
6263
"browserslist": "^4.28.1",
@@ -73,7 +74,7 @@
7374
"prettier-plugin-svelte": "^3.5.0",
7475
"satori": "^0.19.2",
7576
"satori-html": "^0.3.2",
76-
"sv": "^0.12.2",
77+
"sv": "^0.12.8",
7778
"svelte": "^5.53.5",
7879
"svelte-check": "^4.4.3",
7980
"svelte-preprocess": "^6.0.3",

apps/svelte.dev/scripts/sync-docs/index.ts

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import ts from 'typescript';
99
import glob from 'tiny-glob/sync.js';
1010
import chokidar from 'chokidar';
1111
import { fileURLToPath } from 'node:url';
12-
import { clone_repo, migrate_meta_json } from './utils.ts';
12+
import { clone_repo, invoke, migrate_meta_json } from './utils.ts';
1313
import { get_types, read_d_ts_file, read_types } from './types.ts';
1414
import type { Modules } from '@sveltejs/site-kit/markdown';
1515
import { generate_crosslinks } from './crosslinks.ts';
@@ -24,6 +24,7 @@ interface Package {
2424
docs: string;
2525
types: string | null;
2626
process_modules?: (modules: Modules, pkg: Package) => Promise<Modules>;
27+
post_clone?: (dir: string) => Promise<void>;
2728
}
2829

2930
const get_trigger = (pkg: Package) => pkg.trigger ?? pkg.name;
@@ -79,6 +80,26 @@ const get_downstream_repo = (name: string) => {
7980
return `${owner}/${downstream}`;
8081
};
8182

83+
function patch_node_modules(
84+
cloned_dir: string,
85+
pkg_subdir: string,
86+
npm_name: string,
87+
onlyDirs?: string[]
88+
) {
89+
const source = path.join(cloned_dir, pkg_subdir);
90+
const target = path.join(dirname, '../../node_modules', npm_name);
91+
if (onlyDirs) {
92+
for (const dir of onlyDirs) {
93+
const t = path.join(target, dir);
94+
fs.rmSync(t, { recursive: true, force: true });
95+
fs.cpSync(path.join(source, dir), t, { recursive: true });
96+
}
97+
} else {
98+
fs.rmSync(target, { force: true });
99+
fs.symlinkSync(source, target);
100+
}
101+
}
102+
82103
const packages: Package[] = [
83104
{
84105
name: 'svelte',
@@ -87,6 +108,9 @@ const packages: Package[] = [
87108
pkg: 'packages/svelte',
88109
docs: 'documentation/docs',
89110
types: 'types',
111+
post_clone: async (dir) => {
112+
patch_node_modules(dir, 'packages/svelte', 'svelte', ['types']);
113+
},
90114
process_modules: async (modules: Modules) => {
91115
// Remove $$_attributes from ActionReturn
92116
const module_with_ActionReturn = modules.find((m) =>
@@ -111,6 +135,9 @@ const packages: Package[] = [
111135
pkg: 'packages/kit',
112136
docs: 'documentation/docs',
113137
types: 'types',
138+
post_clone: async (dir) => {
139+
patch_node_modules(dir, 'packages/kit', '@sveltejs/kit', ['types']);
140+
},
114141
process_modules: async (modules, pkg) => {
115142
const kit_base = `${REPOS}/${pkg.name}/${pkg.pkg}/`;
116143

@@ -170,7 +197,14 @@ const packages: Package[] = [
170197
branch: branches['cli']?.branch ?? 'main',
171198
pkg: 'packages/sv',
172199
docs: 'documentation/docs',
173-
types: null
200+
types: null,
201+
post_clone: async (dir) => {
202+
await invoke('npx', ['pnpm@10', 'install'], { cwd: dir });
203+
await invoke('npx', ['pnpm@10', 'build'], { cwd: dir });
204+
205+
patch_node_modules(dir, 'packages/sv', 'sv');
206+
patch_node_modules(dir, 'packages/sv-utils', '@sveltejs/sv-utils');
207+
}
174208
},
175209
{
176210
name: 'ai',
@@ -213,6 +247,9 @@ if (parsed.values.pull) {
213247

214248
for (const pkg of filtered) {
215249
await clone_repo(`https://github.com/${pkg.repo}.git`, pkg.name, pkg.branch, REPOS);
250+
if (pkg.post_clone) {
251+
await pkg.post_clone(`${REPOS}/${pkg.name}`);
252+
}
216253
}
217254
}
218255

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1115,7 +1115,7 @@ async function syntax_highlight({
11151115
compilerOptions: {
11161116
allowJs: true,
11171117
checkJs: true,
1118-
types: ['svelte', '@sveltejs/kit', 'sv']
1118+
types: ['svelte', '@sveltejs/kit', 'sv', '@sveltejs/sv-utils']
11191119
}
11201120
},
11211121
// by default, twoslash does not run on .js files, change that through this option

pnpm-lock.yaml

Lines changed: 15 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)