Repository: sveltejs/kit (js)

Issue:
Gracefully recover from malformed svelte.config.js during development
### Describe the problem

At present if I make changes to `svelte.config.js`, the during development, the DEV server tries to load it and crashes because I've set my editor to autosave and have not yet completed typing. This is frustrating, especially when working on a Vite plugin or configuring other build scripts that require frequent changes.

### Describe the proposed solution

If the config load succeeded before, reuse the old config and a present a warning about the malformed `svelte.config.js` in the terminal. I assume it's as simple as a adding a try-catch somewhere, though I may be wrong.

### Alternatives considered

_No response_

### Importance

would make my life easier

### Additional Information

_No response_

Pull request:
pass config to vite-plugin-svelte instead of reloading it
At present, `svelte.config.js` is loaded multiple times — once by SvelteKit, then again by vite-plugin-svelte (twice, during `svelte-kit build`). Aside from being marginally less efficient than reusing the config, this can result in surprising behaviour if you're doing any kind of setup work in the config file.

This uses the new `configFile: false` option and passes config directly to the plugin instead.

It also fixes #4909.

### Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
- [x] It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
- [x] This message body should clearly illustrate what problems it solves.
- [ ] Ideally, include a test that fails without this PR but passes with it.

### Tests
- [ ] Run the tests with `pnpm test` and lint the project with `pnpm lint` and `pnpm check`

### Changesets
- [x] If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running `pnpx changeset` and following the prompts. All changesets should be `patch` until SvelteKit 1.0


Patch:
diff --git a/.changeset/fuzzy-spoons-report.md b/.changeset/fuzzy-spoons-report.md
new file mode 100644
index 000000000..d1579bf27
--- /dev/null
+++ b/.changeset/fuzzy-spoons-report.md
@@ -0,0 +1,5 @@
+---
+'@sveltejs/kit': patch
+---
+
+Pass config to vite-plugin-svelte instead of reloading it
diff --git a/.changeset/moody-moose-jump.md b/.changeset/moody-moose-jump.md
new file mode 100644
index 000000000..da1c4b92e
--- /dev/null
+++ b/.changeset/moody-moose-jump.md
@@ -0,0 +1,5 @@
+---
+'@sveltejs/kit': patch
+---
+
+fix FOUC regression during dev
diff --git a/.changeset/smart-nails-work.md b/.changeset/smart-nails-work.md
new file mode 100644
index 000000000..524cea9d1
--- /dev/null
+++ b/.changeset/smart-nails-work.md
@@ -0,0 +1,5 @@
+---
+'create-svelte': patch
+---
+
+import generated types from `__types/index.d.ts` file
diff --git a/.changeset/soft-months-fail.md b/.changeset/soft-months-fail.md
new file mode 100644
index 000000000..418e71ce3
--- /dev/null
+++ b/.changeset/soft-months-fail.md
@@ -0,0 +1,5 @@
+---
+'@sveltejs/kit': patch
+---
+
+[breaking] write generated types to `__types` directories
diff --git a/documentation/docs/02-routing.md b/documentation/docs/02-routing.md
index 12d4d879c..88d15a051 100644
--- a/documentation/docs/02-routing.md
+++ b/documentation/docs/02-routing.md
@@ -343,6 +343,8 @@ export function match(param) {
 
 If the pathname doesn't match, SvelteKit will try to match other routes (using the sort order specified below), before eventually returning a 404.
 
+> Matchers run both on the server and in the browser.
+
 #### Sorting
 
 It's possible for multiple routes to match a given path. For example each of these routes would match `/foo-abc`:
diff --git a/documentation/docs/15-types.md b/documentation/docs/15-types.md
index 07d6bccd5..7e573f5b8 100644
--- a/documentation/docs/15-types.md
+++ b/documentation/docs/15-types.md
@@ -26,7 +26,7 @@ Needless to say, this is cumbersome to write out, and less portable (if you were
 To solve this problem, SvelteKit generates `.d.ts` files for each of your endpoints and pages:
 
 ```ts
-/// file: .svelte-kit/types/src/routes/[foo]/[bar]/[baz].d.ts
+/// file: .svelte-kit/types/src/routes/[foo]/[bar]/__types/[baz].d.ts
 /// link: false
 import type { RequestHandler as GenericRequestHandler, Load as GenericLoad } from '@sveltejs/kit';
 
@@ -45,7 +45,7 @@ These files can be imported into your endpoints and pages as siblings, thanks to
 
 ```js
 /// file: src/routes/[foo]/[bar]/[baz].js
-// @filename: [baz].d.ts
+// @filename: __types/[baz].d.ts
 import type { RequestHandler as GenericRequestHandler, Load as GenericLoad } from '@sveltejs/kit';
 
 export type RequestHandler<Body = any> = GenericRequestHandler<
@@ -56,7 +56,7 @@ export type RequestHandler<Body = any> = GenericRequestHandler<
 // @filename: index.js
 // @errors: 2355
 // ---cut---
-/** @type {import('./[baz]').RequestHandler} */
+/** @type {import('./__types/[baz]').RequestHandler} */
 export async function get({ params }) {
 	// ...
 }
@@ -64,7 +64,7 @@ export async function get({ params }) {
 
 ```svelte
 <script context="module">
-	/** @type {import('./[baz]').Load} */
+	/** @type {import('./__types/[baz]').Load} */
 	export async function load({ params, fetch, session, stuff }) {
 		// ...
 	}
diff --git a/package.json b/package.json
index 21fb2057a..de108360f 100644
--- a/package.json
+++ b/package.json
@@ -40,7 +40,7 @@
 		"turbo": "^1.2.6",
 		"typescript": "~4.6.2"
 	},
-	"packageManager": "pnpm@7.1.1",
+	"packageManager": "pnpm@7.1.2",
 	"engines": {
 		"pnpm": "^7.0.0"
 	},
diff --git a/packages/create-svelte/templates/default/src/routes/todos/index.ts b/packages/create-svelte/templates/default/src/routes/todos/index.ts
index 5ca318899..d463fc054 100644
--- a/packages/create-svelte/templates/default/src/routes/todos/index.ts
+++ b/packages/create-svelte/templates/default/src/routes/todos/index.ts
@@ -1,7 +1,7 @@
 import { api } from './_api';
-import type { RequestHandler } from './index';
+import type { RequestHandler } from './__types';
 
-/** @type {import('./index').RequestHandler} */
+/** @type {import('./__types').RequestHandler} */
 export const get: RequestHandler = async ({ locals }) => {
 	// locals.userid comes from src/hooks.js
 	const response = await api('get', `todos/${locals.userid}`);
diff --git a/packages/kit/package.json b/packages/kit/package.json
index b7c874646..d3868eed3 100644
--- a/packages/kit/package.json
+++ b/packages/kit/package.json
@@ -10,7 +10,7 @@
 	"homepage": "https://kit.svelte.dev",
 	"type": "module",
 	"dependencies": {
-		"@sveltejs/vite-plugin-svelte": "^1.0.0-next.32",
+		"@sveltejs/vite-plugin-svelte": "^1.0.0-next.44",
 		"chokidar": "^3.5.3",
 		"sade": "^1.7.4",
 		"vite": "^2.9.0"
diff --git a/packages/kit/src/cli.js b/packages/kit/src/cli.js
index 138059520..9f9e34e46 100755
--- a/packages/kit/src/cli.js
+++ b/packages/kit/src/cli.js
@@ -3,6 +3,7 @@ import colors from 'kleur';
 import fs from 'fs';
 import { relative } from 'path';
 import * as ports from 'port-authority';
+import chokidar from 'chokidar';
 import { load_config } from './core/config/index.js';
 import { networkInterfaces, release } from 'os';
 import { coalesce_to_error } from './utils/error.js';
@@ -53,17 +54,20 @@ prog
 	.option('--https', 'Use self-signed HTTPS certificate')
 	.option('-H', 'no longer supported, use --https instead') // TODO remove for 1.0
 	.action(async ({ port, host, https, open, H }) => {
-		try {
-			if (H) throw new Error('-H is no longer supported — use --https instead');
+		let first = true;
+		let relaunching = false;
+		let uid = 1;
 
-			process.env.NODE_ENV = process.env.NODE_ENV || 'development';
-			const config = await load_config();
+		/** @type {() => Promise<void>} */
+		let close;
 
+		/** @param {import('types').ValidatedConfig} config */
+		async function start(config) {
 			const { dev } = await import('./core/dev/index.js');
 
 			const cwd = process.cwd();
 
-			const { address_info, server_config } = await dev({
+			const { address_info, server_config, close } = await dev({
 				cwd,
 				port,
 				host,
@@ -75,12 +79,52 @@ prog
 				port: address_info.port,
 				host: address_info.address,
 				https: !!(https || server_config.https),
-				open: open || !!server_config.open,
+				open: first && (open || !!server_config.open),
 				base: config.kit.paths.base,
 				loose: server_config.fs.strict === false,
 				allow: server_config.fs.allow,
 				cwd
 			});
+
+			first = false;
+
+			return close;
+		}
+
+		async function relaunch() {
+			const id = uid;
+			relaunching = true;
+
+			try {
+				const updated_config = await load_config();
+				await close();
+				close = await start(updated_config);
+
+				if (id !== uid) relaunch();
+			} catch (e) {
+				const error = /** @type {Error} */ (e);
+
+				console.error(colors.bold().red(`> ${error.message}`));
+				if (error.stack) {
+					console.error(colors.gray(error.stack.split('\n').slice(1).join('\n')));
+				}
+			}
+
+			relaunching = false;
+		}
+
+		try {
+			if (H) throw new Error('-H is no longer supported — use --https instead');
+
+			process.env.NODE_ENV = process.env.NODE_ENV || 'development';
+
+			const config = await load_config();
+			close = await start(config);
+
+			chokidar.watch('svelte.config.js', { ignoreInitial: true }).on('change', () => {
+				if (relaunching) uid += 1;
+				else relaunch();
+			});
 		} catch (error) {
 			handle_error(error);
 		}
diff --git a/packages/kit/src/core/build/build_client.js b/packages/kit/src/core/build/build_client.js
index 3f0cfaf60..cfdda0370 100644
--- a/packages/kit/src/core/build/build_client.js
+++ b/packages/kit/src/core/build/build_client.js
@@ -78,7 +78,7 @@ export async function build_client({
 		},
 		plugins: [
 			svelte({
-				extensions: config.extensions,
+				...config,
 				// In AMP mode, we know that there are no conditional component imports. In that case, we
 				// don't need to include CSS for components that are imported but unused, so we can just
 				// include rendered CSS.
@@ -86,8 +86,10 @@ export async function build_client({
 				// has been enabled at the page level, so we don't do anything there.
 				emitCss: !config.kit.amp,
 				compilerOptions: {
+					...config.compilerOptions,
 					hydratable: !!config.kit.browser.hydrate
-				}
+				},
+				configFile: false
 			})
 		],
 		// prevent Vite copying the contents of `config.kit.files.assets`,
diff --git a/packages/kit/src/core/build/build_server.js b/packages/kit/src/core/build/build_server.js
index 6181eec62..6b13537fb 100644
--- a/packages/kit/src/core/build/build_server.js
+++ b/packages/kit/src/core/build/build_server.js
@@ -231,10 +231,12 @@ export async function build_server(
 		},
 		plugins: [
 			svelte({
-				extensions: config.extensions,
+				...config,
 				compilerOptions: {
+					...config.compilerOptions,
 					hydratable: !!config.kit.browser.hydrate
-				}
+				},
+				configFile: false
 			})
 		],
 		resolve: {
diff --git a/packages/kit/src/core/config/index.js b/packages/kit/src/core/config/index.js
index 662b2f742..cfbe2c9d3 100644
--- a/packages/kit/src/core/config/index.js
+++ b/packages/kit/src/core/config/index.js
@@ -36,7 +36,7 @@ export async function load_config({ cwd = process.cwd() } = {}) {
 		);
 	}
 
-	const config = await import(url.pathToFileURL(config_file).href);
+	const config = await import(`${url.pathToFileURL(config_file).href}?ts=${Date.now()}`);
 
 	const validated = validate_config(config.default);
 
diff --git a/packages/kit/src/core/dev/index.js b/packages/kit/src/core/dev/index.js
index df72470c8..4a88cdc00 100644
--- a/packages/kit/src/core/dev/index.js
+++ b/packages/kit/src/core/dev/index.js
@@ -60,7 +60,7 @@ export async function dev({ cwd, port, host, https, config }) {
 		},
 		plugins: [
 			svelte({
-				extensions: config.extensions,
+				...config,
 				// In AMP mode, we know that there are no conditional component imports. In that case, we
 				// don't need to include CSS for components that are imported but unused, so we can just
 				// include rendered CSS.
@@ -68,8 +68,10 @@ export async function dev({ cwd, port, host, https, config }) {
 				// has been enabled at the page level, so we don't do anything there.
 				emitCss: !config.kit.amp,
 				compilerOptions: {
+					...config.compilerOptions,
 					hydratable: !!config.kit.browser.hydrate
-				}
+				},
+				configFile: false
 			}),
 			await create_plugin(config, cwd)
 		],
diff --git a/packages/kit/src/core/dev/plugin.js b/packages/kit/src/core/dev/plugin.js
index a5269fa77..a589330de 100644
--- a/packages/kit/src/core/dev/plugin.js
+++ b/packages/kit/src/core/dev/plugin.js
@@ -391,32 +391,36 @@ function remove_html_middlewares(server) {
  * @param {import('vite').ModuleNode} node
  * @param {Set<import('vite').ModuleNode>} deps
  */
-function find_deps(vite, node, deps) {
+async function find_deps(vite, node, deps) {
 	// since `ssrTransformResult.deps` contains URLs instead of `ModuleNode`s, this process is asynchronous.
 	// instead of using `await`, we resolve all branches in parallel.
 	/** @type {Promise<void>[]} */
 	const branches = [];
 
 	/** @param {import('vite').ModuleNode} node */
-	function add(node) {
+	async function add(node) {
 		if (!deps.has(node)) {
 			deps.add(node);
-			branches.push(find_deps(vite, node, deps));
+			await find_deps(vite, node, deps);
 		}
 	}
 
 	/** @param {string} url */
 	async function add_by_url(url) {
-		branches.push(vite.moduleGraph.getModuleByUrl(url).then((node) => node && add(node)));
+		const node = await vite.moduleGraph.getModuleByUrl(url);
+
+		if (node) {
+			await add(node);
+		}
 	}
 
 	if (node.ssrTransformResult) {
 		if (node.ssrTransformResult.deps) {
-			node.ssrTransformResult.deps.forEach(add_by_url);
+			node.ssrTransformResult.deps.forEach((url) => branches.push(add_by_url(url)));
 		}
 	} else {
-		node.importedModules.forEach(add);
+		node.importedModules.forEach((node) => branches.push(add(node)));
 	}
 
-	return Promise.all(branches).then(() => {});
+	await Promise.all(branches);
 }
diff --git a/packages/kit/src/core/sync/write_types.js b/packages/kit/src/core/sync/write_types.js
index b1da50b81..01f129aa8 100644
--- a/packages/kit/src/core/sync/write_types.js
+++ b/packages/kit/src/core/sync/write_types.js
@@ -1,3 +1,4 @@
+import { rimraf } from '../../utils/filesystem.js';
 import { parse_route_id } from '../../utils/routing.js';
 import { write_if_changed } from './utils.js';
 
@@ -22,6 +23,8 @@ export type Load<
  * @param {import('types').ManifestData} manifest_data
  */
 export function write_types(config, manifest_data) {
+	rimraf(`${config.kit.outDir}/types`);
+
 	/** @type {Map<string, { params: string[], type: 'page' | 'endpoint' | 'both' }>} */
 	const shadow_types = new Map();
 
@@ -70,8 +73,11 @@ export function write_types(config, manifest_data) {
 
 		content.unshift(header(imports.join(', ')));
 
+		const parts = (key || 'index').split('/');
+		parts.push('__types', /** @type {string} */ (parts.pop()));
+
 		write_if_changed(
-			`${config.kit.outDir}/types/${key || 'index'}.d.ts`,
+			`${config.kit.outDir}/types/${parts.join('/')}.d.ts`,
 			content.join('\n').trim()
 		);
 	});
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 546e2a71b..965b7257b 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -253,7 +253,7 @@ importers:
     specifiers:
       '@playwright/test': ^1.21.0
       '@rollup/plugin-replace': ^4.0.0
-      '@sveltejs/vite-plugin-svelte': ^1.0.0-next.32
+      '@sveltejs/vite-plugin-svelte': ^1.0.0-next.44
       '@types/amphtml-validator': ^1.0.1
       '@types/connect': ^3.4.35
       '@types/cookie': ^0.5.0
@@ -288,7 +288,7 @@ importers:
       uvu: ^0.5.2
       vite: ^2.9.0
     dependencies:
-      '@sveltejs/vite-plugin-svelte': 1.0.0-next.32_svelte@3.44.2+vite@2.9.0
+      '@sveltejs/vite-plugin-svelte': 1.0.0-next.44_svelte@3.44.2+vite@2.9.0
       chokidar: 3.5.3
       sade: 1.7.4
       vite: 2.9.0
@@ -1460,6 +1460,15 @@ packages:
     dependencies:
       estree-walker: 2.0.2
       picomatch: 2.3.0
+    dev: true
+
+  /@rollup/pluginutils/4.2.1:
+    resolution: {integrity: sha512-iKnFXr7NkdZAIHiIWE+BX5ULi/ucVFYWD6TbAV+rZctiRTY2PL6tsIKhoIOaoskiWAkgu+VsbXgUVDNLHf+InQ==}
+    engines: {node: '>= 8.0.0'}
+    dependencies:
+      estree-walker: 2.0.2
+      picomatch: 2.3.1
+    dev: false
 
   /@sveltejs/site-kit/2.1.0:
     resolution: {integrity: sha512-nJddyYdBHXmiyhIAq0DQZpEjJ0B2Up4NCg08gVZuUxuOsshjUK8wZ5kuszP3Tl/q176MxFbceJo2Me4fj9bu9w==}
@@ -1467,24 +1476,24 @@ packages:
       golden-fleece: 1.0.9
     dev: true
 
-  /@sveltejs/vite-plugin-svelte/1.0.0-next.32_svelte@3.44.2+vite@2.9.0:
-    resolution: {integrity: sha512-Lhf5BxVylosHIW6U2s6WDQA39ycd+bXivC8gHsXCJeLzxoHj7Pv7XAOk25xRSXT4wHg9DWFMBQh2DFU0DxHZ2g==}
+  /@sveltejs/vite-plugin-svelte/1.0.0-next.44_svelte@3.44.2+vite@2.9.0:
+    resolution: {integrity: sha512-n+sssEWbzykPS447FmnNyU5GxEhrBPDVd0lxNZnxRGz9P6651LjjwAnISKr3CKgT9v8IybP8VD0n2i5XzbqExg==}
     engines: {node: ^14.13.1 || >= 16}
     peerDependencies:
       diff-match-patch: ^1.0.5
       svelte: ^3.44.0
-      vite: ^2.7.0
+      vite: ^2.9.0
     peerDependenciesMeta:
       diff-match-patch:
         optional: true
     dependencies:
-      '@rollup/pluginutils': 4.1.2
-      debug: 4.3.3
+      '@rollup/pluginutils': 4.2.1
+      debug: 4.3.4
+      deepmerge: 4.2.2
       kleur: 4.1.4
-      magic-string: 0.25.7
-      require-relative: 0.8.7
+      magic-string: 0.26.2
       svelte: 3.44.2
-      svelte-hmr: 0.14.7_svelte@3.44.2
+      svelte-hmr: 0.14.11_svelte@3.44.2
       vite: 2.9.0
     transitivePeerDependencies:
       - supports-color
@@ -2428,6 +2437,7 @@ packages:
         optional: true
     dependencies:
       ms: 2.1.2
+    dev: true
 
   /debug/4.3.4:
     resolution: {integrity: sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==}
@@ -2439,7 +2449,6 @@ packages:
         optional: true
     dependencies:
       ms: 2.1.2
-    dev: true
 
   /decamelize-keys/1.1.0:
     resolution: {integrity: sha1-0XGoeTMlKAfrPLYdwcFEXQeN8tk=}
@@ -2477,7 +2486,6 @@ packages:
   /deepmerge/4.2.2:
     resolution: {integrity: sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg==}
     engines: {node: '>=0.10.0'}
-    dev: true
 
   /defaults/1.0.3:
     resolution: {integrity: sha1-xlYFHpgX2f8I7YgUd/P+QBnz730=}
@@ -3291,7 +3299,7 @@ packages:
       is-stream: 1.1.0
       npm-run-path: 2.0.2
       p-finally: 1.0.0
-      signal-exit: 3.0.6
+      signal-exit: 3.0.7
       strip-eof: 1.0.0
     dev: true
 
@@ -4203,6 +4211,14 @@ packages:
     resolution: {integrity: sha512-4CrMT5DOHTDk4HYDlzmwu4FVCcIYI8gauveasrdCu2IKIFOJ3f0v/8MDGJCDL9oD2ppz/Av1b0Nj345H9M+XIA==}
     dependencies:
       sourcemap-codec: 1.4.8
+    dev: true
+
+  /magic-string/0.26.2:
+    resolution: {integrity: sha512-NzzlXpclt5zAbmo6h6jNc8zl2gNRGHvmsZW4IvZhTC4W7k4OlLP+S5YLussa/r3ixNT66KOQfNORlXHSOy/X4A==}
+    engines: {node: '>=12'}
+    dependencies:
+      sourcemap-codec: 1.4.8
+    dev: false
 
   /make-dir/3.1.0:
     resolution: {integrity: sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==}
@@ -4676,6 +4692,7 @@ packages:
   /picomatch/2.3.0:
     resolution: {integrity: sha512-lY1Q/PiJGC2zOv/z391WOTD+Z02bCgsFfvxoXXf6h7kv9o+WmsmzYqrAwY63sNgOxE4xEdq0WyUnXfKeBrSvYw==}
     engines: {node: '>=8.6'}
+    dev: true
 
   /picomatch/2.3.1:
     resolution: {integrity: sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==}
@@ -5032,10 +5049,6 @@ packages:
     resolution: {integrity: sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==}
     dev: true
 
-  /require-relative/0.8.7:
-    resolution: {integrity: sha1-eZlTn8ngR6N5KPoZb44VY9q9Nt4=}
-    dev: false
-
   /resolve-from/4.0.0:
     resolution: {integrity: sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==}
     engines: {node: '>=4'}
@@ -5555,8 +5568,8 @@ packages:
       sade: 1.7.4
       source-map: 0.7.3
       svelte: 3.48.0
-      svelte-preprocess: 4.9.8_c64miirrcucob5yjzfkddrmila
-      typescript: 4.6.2
+      svelte-preprocess: 4.9.8_wwvk7nlptlrqo2czohjtk6eiqm
+      typescript: 4.6.4
     transitivePeerDependencies:
       - '@babel/core'
       - coffeescript
@@ -5570,15 +5583,16 @@ packages:
       - sugarss
     dev: true
 
-  /svelte-hmr/0.14.7_svelte@3.44.2:
-    resolution: {integrity: sha512-pDrzgcWSoMaK6AJkBWkmgIsecW0GChxYZSZieIYfCP0v2oPyx2CYU/zm7TBIcjLVUPP714WxmViE9Thht4etog==}
+  /svelte-hmr/0.14.11_svelte@3.44.2:
+    resolution: {integrity: sha512-R9CVfX6DXxW1Kn45Jtmx+yUe+sPhrbYSUp7TkzbW0jI5fVPn6lsNG9NEs5dFg5qRhFNAoVdRw5qQDLALNKhwbQ==}
+    engines: {node: ^12.20 || ^14.13.1 || >= 16}
     peerDependencies:
       svelte: '>=3.19.0'
     dependencies:
       svelte: 3.44.2
     dev: false
 
-  /svelte-preprocess/4.9.8_c64miirrcucob5yjzfkddrmila:
+  /svelte-preprocess/4.9.8_svelte@3.44.2:
     resolution: {integrity: sha512-EQS/oRZzMtYdAprppZxY3HcysKh11w54MgA63ybtL+TAZ4hVqYOnhw41JVJjWN9dhPnNjjLzvbZ2tMhTsla1Og==}
     engines: {node: '>= 9.11.2'}
     requiresBuild: true
@@ -5625,11 +5639,10 @@ packages:
       magic-string: 0.25.7
       sorcery: 0.10.0
       strip-indent: 3.0.0
-      svelte: 3.48.0
-      typescript: 4.6.2
+      svelte: 3.44.2
     dev: true
 
-  /svelte-preprocess/4.9.8_svelte@3.44.2:
+  /svelte-preprocess/4.9.8_uydhuxrsxpjnlqukdpt4rb2fam:
     resolution: {integrity: sha512-EQS/oRZzMtYdAprppZxY3HcysKh11w54MgA63ybtL+TAZ4hVqYOnhw41JVJjWN9dhPnNjjLzvbZ2tMhTsla1Og==}
     engines: {node: '>= 9.11.2'}
     requiresBuild: true
@@ -5677,9 +5690,10 @@ packages:
       sorcery: 0.10.0
       strip-indent: 3.0.0
       svelte: 3.44.2
+      typescript: 4.6.2
     dev: true
 
-  /svelte-preprocess/4.9.8_uydhuxrsxpjnlqukdpt4rb2fam:
+  /svelte-preprocess/4.9.8_wgapq35fvzy6mzjhiipmcyqsqu:
     resolution: {integrity: sha512-EQS/oRZzMtYdAprppZxY3HcysKh11w54MgA63ybtL+TAZ4hVqYOnhw41JVJjWN9dhPnNjjLzvbZ2tMhTsla1Og==}
     engines: {node: '>= 9.11.2'}
     requiresBuild: true
@@ -5727,10 +5741,10 @@ packages:
       sorcery: 0.10.0
       strip-indent: 3.0.0
       svelte: 3.44.2
-      typescript: 4.6.2
+      typescript: 4.6.4
     dev: true
 
-  /svelte-preprocess/4.9.8_wgapq35fvzy6mzjhiipmcyqsqu:
+  /svelte-preprocess/4.9.8_wwvk7nlptlrqo2czohjtk6eiqm:
     resolution: {integrity: sha512-EQS/oRZzMtYdAprppZxY3HcysKh11w54MgA63ybtL+TAZ4hVqYOnhw41JVJjWN9dhPnNjjLzvbZ2tMhTsla1Og==}
     engines: {node: '>= 9.11.2'}
     requiresBuild: true
@@ -5777,7 +5791,7 @@ packages:
       magic-string: 0.25.7
       sorcery: 0.10.0
       strip-indent: 3.0.0
-      svelte: 3.44.2
+      svelte: 3.48.0
       typescript: 4.6.4
     dev: true
 


Test patch:
diff --git a/packages/kit/src/packaging/test/fixtures/emitTypes-false/expected/Test2.svelte b/packages/kit/src/packaging/test/fixtures/emitTypes-false/expected/Test2.svelte
index 06a5a3408..852fe8cd5 100644
--- a/packages/kit/src/packaging/test/fixtures/emitTypes-false/expected/Test2.svelte
+++ b/packages/kit/src/packaging/test/fixtures/emitTypes-false/expected/Test2.svelte
@@ -1,6 +1,6 @@
 <script>
-    /**
-     * @type {import('./foo').Foo}
-     */
-    export let foo;
+	/**
+	 * @type {import('./foo').Foo}
+	 */
+	export let foo;
 </script>
diff --git a/packages/kit/src/packaging/test/fixtures/emitTypes-false/src/lib/Test2.svelte b/packages/kit/src/packaging/test/fixtures/emitTypes-false/src/lib/Test2.svelte
index 06a5a3408..852fe8cd5 100644
--- a/packages/kit/src/packaging/test/fixtures/emitTypes-false/src/lib/Test2.svelte
+++ b/packages/kit/src/packaging/test/fixtures/emitTypes-false/src/lib/Test2.svelte
@@ -1,6 +1,6 @@
 <script>
-    /**
-     * @type {import('./foo').Foo}
-     */
-    export let foo;
+	/**
+	 * @type {import('./foo').Foo}
+	 */
+	export let foo;
 </script>
diff --git a/packages/kit/src/packaging/test/fixtures/exports-merge/expected/internal/Test.svelte b/packages/kit/src/packaging/test/fixtures/exports-merge/expected/internal/Test.svelte
index 06a5a3408..852fe8cd5 100644
--- a/packages/kit/src/packaging/test/fixtures/exports-merge/expected/internal/Test.svelte
+++ b/packages/kit/src/packaging/test/fixtures/exports-merge/expected/internal/Test.svelte
@@ -1,6 +1,6 @@
 <script>
-    /**
-     * @type {import('./foo').Foo}
-     */
-    export let foo;
+	/**
+	 * @type {import('./foo').Foo}
+	 */
+	export let foo;
 </script>
diff --git a/packages/kit/src/packaging/test/fixtures/exports-merge/src/lib/internal/Test.svelte b/packages/kit/src/packaging/test/fixtures/exports-merge/src/lib/internal/Test.svelte
index 06a5a3408..852fe8cd5 100644
--- a/packages/kit/src/packaging/test/fixtures/exports-merge/src/lib/internal/Test.svelte
+++ b/packages/kit/src/packaging/test/fixtures/exports-merge/src/lib/internal/Test.svelte
@@ -1,6 +1,6 @@
 <script>
-    /**
-     * @type {import('./foo').Foo}
-     */
-    export let foo;
+	/**
+	 * @type {import('./foo').Foo}
+	 */
+	export let foo;
 </script>
diff --git a/packages/kit/src/packaging/test/fixtures/exports-replace/expected/internal/Test.svelte b/packages/kit/src/packaging/test/fixtures/exports-replace/expected/internal/Test.svelte
index 06a5a3408..852fe8cd5 100644
--- a/packages/kit/src/packaging/test/fixtures/exports-replace/expected/internal/Test.svelte
+++ b/packages/kit/src/packaging/test/fixtures/exports-replace/expected/internal/Test.svelte
@@ -1,6 +1,6 @@
 <script>
-    /**
-     * @type {import('./foo').Foo}
-     */
-    export let foo;
+	/**
+	 * @type {import('./foo').Foo}
+	 */
+	export let foo;
 </script>
diff --git a/packages/kit/src/packaging/test/fixtures/exports-replace/src/lib/internal/Test.svelte b/packages/kit/src/packaging/test/fixtures/exports-replace/src/lib/internal/Test.svelte
index 06a5a3408..852fe8cd5 100644
--- a/packages/kit/src/packaging/test/fixtures/exports-replace/src/lib/internal/Test.svelte
+++ b/packages/kit/src/packaging/test/fixtures/exports-replace/src/lib/internal/Test.svelte
@@ -1,6 +1,6 @@
 <script>
-    /**
-     * @type {import('./foo').Foo}
-     */
-    export let foo;
+	/**
+	 * @type {import('./foo').Foo}
+	 */
+	export let foo;
 </script>
diff --git a/packages/kit/src/packaging/test/fixtures/javascript/expected/Test2.svelte b/packages/kit/src/packaging/test/fixtures/javascript/expected/Test2.svelte
index 06a5a3408..852fe8cd5 100644
--- a/packages/kit/src/packaging/test/fixtures/javascript/expected/Test2.svelte
+++ b/packages/kit/src/packaging/test/fixtures/javascript/expected/Test2.svelte
@@ -1,6 +1,6 @@
 <script>
-    /**
-     * @type {import('./foo').Foo}
-     */
-    export let foo;
+	/**
+	 * @type {import('./foo').Foo}
+	 */
+	export let foo;
 </script>
diff --git a/packages/kit/src/packaging/test/fixtures/javascript/expected/internal/Test.svelte b/packages/kit/src/packaging/test/fixtures/javascript/expected/internal/Test.svelte
index 06a5a3408..852fe8cd5 100644
--- a/packages/kit/src/packaging/test/fixtures/javascript/expected/internal/Test.svelte
+++ b/packages/kit/src/packaging/test/fixtures/javascript/expected/internal/Test.svelte
@@ -1,6 +1,6 @@
 <script>
-    /**
-     * @type {import('./foo').Foo}
-     */
-    export let foo;
+	/**
+	 * @type {import('./foo').Foo}
+	 */
+	export let foo;
 </script>
diff --git a/packages/kit/src/packaging/test/fixtures/javascript/src/lib/Test2.svelte b/packages/kit/src/packaging/test/fixtures/javascript/src/lib/Test2.svelte
index 06a5a3408..852fe8cd5 100644
--- a/packages/kit/src/packaging/test/fixtures/javascript/src/lib/Test2.svelte
+++ b/packages/kit/src/packaging/test/fixtures/javascript/src/lib/Test2.svelte
@@ -1,6 +1,6 @@
 <script>
-    /**
-     * @type {import('./foo').Foo}
-     */
-    export let foo;
+	/**
+	 * @type {import('./foo').Foo}
+	 */
+	export let foo;
 </script>
diff --git a/packages/kit/src/packaging/test/fixtures/javascript/src/lib/internal/Test.svelte b/packages/kit/src/packaging/test/fixtures/javascript/src/lib/internal/Test.svelte
index 06a5a3408..852fe8cd5 100644
--- a/packages/kit/src/packaging/test/fixtures/javascript/src/lib/internal/Test.svelte
+++ b/packages/kit/src/packaging/test/fixtures/javascript/src/lib/internal/Test.svelte
@@ -1,6 +1,6 @@
 <script>
-    /**
-     * @type {import('./foo').Foo}
-     */
-    export let foo;
+	/**
+	 * @type {import('./foo').Foo}
+	 */
+	export let foo;
 </script>
diff --git a/packages/kit/test/apps/basics/src/routes/encoded/[slug].svelte b/packages/kit/test/apps/basics/src/routes/encoded/[slug].svelte
index a0acf4eb0..03089c2e7 100644
--- a/packages/kit/test/apps/basics/src/routes/encoded/[slug].svelte
+++ b/packages/kit/test/apps/basics/src/routes/encoded/[slug].svelte
@@ -1,5 +1,5 @@
 <script context="module">
-	/** @type {import('./[slug]').Load} */
+	/** @type {import('./__types/[slug]').Load} */
 	export function load({ url, params }) {
 		return {
 			props: {
diff --git a/packages/kit/test/apps/basics/src/routes/load/set-cookie-fetch/a.json.js b/packages/kit/test/apps/basics/src/routes/load/set-cookie-fetch/a.json.js
index fbfc10108..20fd05dc2 100644
--- a/packages/kit/test/apps/basics/src/routes/load/set-cookie-fetch/a.json.js
+++ b/packages/kit/test/apps/basics/src/routes/load/set-cookie-fetch/a.json.js
@@ -1,4 +1,4 @@
-/** @type {import('./a.json').RequestHandler} */
+/** @type {import('./__types/a.json').RequestHandler} */
 export function get({ url }) {
 	const answer = url.searchParams.get('answer') || '42';
 
diff --git a/packages/kit/test/apps/basics/src/routes/load/set-cookie-fetch/b.json.js b/packages/kit/test/apps/basics/src/routes/load/set-cookie-fetch/b.json.js
index e16a4a451..1575a1a08 100644
--- a/packages/kit/test/apps/basics/src/routes/load/set-cookie-fetch/b.json.js
+++ b/packages/kit/test/apps/basics/src/routes/load/set-cookie-fetch/b.json.js
@@ -1,4 +1,4 @@
-/** @type {import('./b.json').RequestHandler} */
+/** @type {import('./__types/b.json').RequestHandler} */
 export function get({ request }) {
 	const cookie = request.headers.get('cookie');
 
diff --git a/packages/kit/test/apps/basics/src/routes/routing/params-in-handle/[x].js b/packages/kit/test/apps/basics/src/routes/routing/params-in-handle/[x].js
index 26b5bb284..9966833e4 100644
--- a/packages/kit/test/apps/basics/src/routes/routing/params-in-handle/[x].js
+++ b/packages/kit/test/apps/basics/src/routes/routing/params-in-handle/[x].js
@@ -1,4 +1,4 @@
-/** @type {import('./[x]').RequestHandler} */
+/** @type {import('./__types/[x]').RequestHandler} */
 export function get({ locals }) {
 	return {
 		body: {
diff --git a/packages/kit/test/apps/basics/src/routes/routing/route-id/[x].svelte b/packages/kit/test/apps/basics/src/routes/routing/route-id/[x].svelte
index 426c5a67e..972fff95d 100644
--- a/packages/kit/test/apps/basics/src/routes/routing/route-id/[x].svelte
+++ b/packages/kit/test/apps/basics/src/routes/routing/route-id/[x].svelte
@@ -1,5 +1,5 @@
 <script context="module">
-	/** @type {import('./[x]').Load} */
+	/** @type {import('./__types/[x]').Load} */
 	export function load({ routeId }) {
 		return {
 			props: { routeId }
diff --git a/packages/kit/test/prerendering/basics/src/routes/fetch-404.svelte b/packages/kit/test/prerendering/basics/src/routes/fetch-404.svelte
index b44cf77ec..023d8f902 100644
--- a/packages/kit/test/prerendering/basics/src/routes/fetch-404.svelte
+++ b/packages/kit/test/prerendering/basics/src/routes/fetch-404.svelte
@@ -1,5 +1,5 @@
 <script context="module">
-	/** @type {import('./fetch-404').Load} */
+	/** @type {import('./__types/fetch-404').Load} */
 	export async function load({ fetch }) {
 		const { status } = await fetch('/missing.json');