Repository: sveltejs/kit (js)

Issue:
Prettier is ignoring svelte files
### Describe the bug

I created a new sveltekit app but when running the lint or format script prettier is ignoring all svelte files. It only works when explicitly telling prettier to check for svelte files with for example `src/**/*.{ts,svelte}` instead of `.`.

### Reproduction

- create a new sveltekit app with `pnpm create svelte@latest` and make sure to add prettier for code formatting
- install the packages with `pnpm install`
- run `pnpm format`

> You won't see any svelte files getting formatted

### Logs

_No response_

### System Info

```shell
System:
  OS: Linux 5.10 Ubuntu 22.04.1 LTS 22.04.1 LTS (Jammy Jellyfish)
  CPU: (24) x64 AMD Ryzen 9 3900X 12-Core Processor
  Memory: 23.82 GB / 24.99 GB
  Container: Yes
  Shell: 5.8.1 - /usr/bin/zsh
Binaries:
  Node: 16.17.0 - ~/.local/share/pnpm/node
  npm: 8.15.0 - ~/.local/share/pnpm/npm
npmPackages:
  @sveltejs/adapter-node: next => 1.0.0-next.90
  @sveltejs/kit: next => 1.0.0-next.481
  svelte: ^3.50.1 => 3.50.1
  vite: ^3.1.0 => 3.1.0
```


### Severity

annoyance

### Additional Information

_No response_

Pull request:
fix: prettier not working for svelte files in create-svelte projects
fixes #6804 

i'm not sure why this is needed again, it was previously removed in favor of the `pluginSearchDirs` setting in prettierrc. 
Now we use both.

Note: the tests for create-svelte received 2 updates
1) pin them to the same vite version kit uses to avoid type incompatibility errors with `pnpm check` during tests
2) updated list of tested commands to include `format`, remove `prepare` and sort them differently

### 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
- [x] 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 `pnpm changeset` and following the prompts. All changesets should be `patch` until SvelteKit 1.0


Patch:
diff --git a/.changeset/breezy-pots-wave.md b/.changeset/breezy-pots-wave.md
new file mode 100644
index 000000000..483da04ce
--- /dev/null
+++ b/.changeset/breezy-pots-wave.md
@@ -0,0 +1,5 @@
+---
+'@sveltejs/kit': patch
+---
+
+fix to ActionData type generation
diff --git a/.changeset/chatty-moose-love.md b/.changeset/chatty-moose-love.md
new file mode 100644
index 000000000..b6accabe6
--- /dev/null
+++ b/.changeset/chatty-moose-love.md
@@ -0,0 +1,5 @@
+---
+'@sveltejs/kit': patch
+---
+
+The return type of cookies.get is string|undefined #6865
diff --git a/.changeset/light-eagles-call.md b/.changeset/light-eagles-call.md
new file mode 100644
index 000000000..c5aa2bba6
--- /dev/null
+++ b/.changeset/light-eagles-call.md
@@ -0,0 +1,5 @@
+---
+'create-svelte': patch
+---
+
+[fix] prettier not formatting svelte files
diff --git a/documentation/docs/06-form-actions.md b/documentation/docs/06-form-actions.md
index d235852b4..fcf1300a8 100644
--- a/documentation/docs/06-form-actions.md
+++ b/documentation/docs/06-form-actions.md
@@ -148,12 +148,13 @@ export const actions = {
 		const email = data.get('email');
 		const password = data.get('password');
 
-		const user = await db.getUser(email);
-+		if (!user) {
++		if (!email) {
 +			return invalid(400, { email, missing: true });
 +		}
-+
-+		if (user.password !== hash(password)) {
+
+		const user = await db.getUser(email);
+
++		if (!user || user.password !== hash(password)) {
 +			return invalid(400, { email, incorrect: true });
 +		}
 
@@ -173,11 +174,10 @@ export const actions = {
 /// file: src/routes/login/+page.svelte
 <form method="POST" action="?/login">
 -	<input name="email" type="email">
-+	{#if form?.missing}<p class="error">No user found with this email</p>{/if}
++	{#if form?.missing}<p class="error">The email field is required</p>{/if}
++	{#if form?.incorrect}<p class="error">Invalid credentials!</p>{/if}
 +	<input name="email" type="email" value={form?.email ?? ''}>
 
--	<input name="password" type="password">
-+	{#if form?.incorrect}<p class="error">Wrong password!</p>{/if}
 	<input name="password" type="password">
 	<button>Log in</button>
 	<button formaction="?/register">Register</button>
diff --git a/package.json b/package.json
index 811b4bc04..817041bcc 100644
--- a/package.json
+++ b/package.json
@@ -36,7 +36,7 @@
 		"turbo": "^1.3.4",
 		"typescript": "^4.8.2"
 	},
-	"packageManager": "pnpm@7.11.0",
+	"packageManager": "pnpm@7.12.0",
 	"engines": {
 		"pnpm": "^7.0.0"
 	},
diff --git a/packages/create-svelte/shared/+eslint+prettier/package.json b/packages/create-svelte/shared/+eslint+prettier/package.json
index a8b937b25..a6492f385 100644
--- a/packages/create-svelte/shared/+eslint+prettier/package.json
+++ b/packages/create-svelte/shared/+eslint+prettier/package.json
@@ -3,7 +3,7 @@
 		"eslint-config-prettier": "^8.3.0"
 	},
 	"scripts": {
-		"lint": "prettier --check . && eslint .",
-		"format": "prettier --write ."
+		"lint": "prettier --plugin-search-dir . --check . && eslint .",
+		"format": "prettier --plugin-search-dir . --write ."
 	}
 }
diff --git a/packages/create-svelte/shared/+prettier/.prettierrc b/packages/create-svelte/shared/+prettier/.prettierrc
index d177cd62d..a77fddea9 100644
--- a/packages/create-svelte/shared/+prettier/.prettierrc
+++ b/packages/create-svelte/shared/+prettier/.prettierrc
@@ -3,6 +3,7 @@
 	"singleQuote": true,
 	"trailingComma": "none",
 	"printWidth": 100,
+	"plugins": ["prettier-plugin-svelte"],
 	"pluginSearchDirs": ["."],
 	"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }]
 }
diff --git a/packages/create-svelte/shared/-eslint+prettier/package.json b/packages/create-svelte/shared/-eslint+prettier/package.json
index bcdff7cf9..0193de97c 100644
--- a/packages/create-svelte/shared/-eslint+prettier/package.json
+++ b/packages/create-svelte/shared/-eslint+prettier/package.json
@@ -1,6 +1,6 @@
 {
 	"scripts": {
-		"lint": "prettier --check .",
-		"format": "prettier --write ."
+		"lint": "prettier --plugin-search-dir . --check .",
+		"format": "prettier --plugin-search-dir . --write ."
 	}
 }
diff --git a/packages/kit/types/index.d.ts b/packages/kit/types/index.d.ts
index 0c9d7e828..876295274 100644
--- a/packages/kit/types/index.d.ts
+++ b/packages/kit/types/index.d.ts
@@ -35,9 +35,20 @@ export type AwaitedProperties<input extends Record<string, any> | void> = input
 	? input
 	: unknown;
 
-export type AwaitedActions<T extends Record<string, (...args: any) => any>> = {
-	[Key in keyof T]: UnpackValidationError<Awaited<ReturnType<T[Key]>>>;
-}[keyof T];
+export type AwaitedActions<T extends Record<string, (...args: any) => any>> = Expand<
+	{
+		[Key in keyof T]: OptionalUnion<UnpackValidationError<Awaited<ReturnType<T[Key]>>>>;
+	}[keyof T]
+>;
+
+// Makes sure a type is "repackaged" and therefore more readable
+type Expand<T> = T extends infer O ? { [K in keyof O]: O[K] } : never;
+// Takes a union type and returns a union type where each type also has all properties
+// of all possible types (typed as undefined), making accessing them more ergonomic
+type OptionalUnion<
+	U extends Record<string, any>, // not unknown, else interfaces don't satisfy this constraint
+	A extends keyof U = U extends U ? keyof U : never
+> = U extends unknown ? { [P in Exclude<A, keyof U>]?: never } & U : never;
 
 // Needs to be here, else ActionData will be resolved to unknown - probably because of "d.ts file imports .js file" in combination with allowJs
 interface ValidationError<T extends Record<string, unknown> | undefined = undefined> {
@@ -128,7 +139,7 @@ export interface Cookies {
 	/**
 	 * Gets a cookie that was previously set with `cookies.set`, or from the request headers.
 	 */
-	get(name: string, opts?: import('cookie').CookieParseOptions): string | void;
+	get(name: string, opts?: import('cookie').CookieParseOptions): string | undefined;
 
 	/**
 	 * Sets a cookie. This will add a `set-cookie` header to the response, but also make the cookie available via `cookies.get` during the current request.


Test patch:
diff --git a/packages/create-svelte/test/check.js b/packages/create-svelte/test/check.js
index 5e74a81da..31d14e7f7 100644
--- a/packages/create-svelte/test/check.js
+++ b/packages/create-svelte/test/check.js
@@ -2,7 +2,6 @@ import fs from 'fs';
 import { execSync } from 'child_process';
 import path from 'path';
 import { test } from 'uvu';
-import { Writable } from 'stream';
 import * as assert from 'uvu/assert';
 import { create } from '../index.js';
 import { fileURLToPath } from 'url';
@@ -25,6 +24,16 @@ const overrides = { ...existing_workspace_overrides };
 	overrides[name] = path.dirname(path.resolve(pkgPath));
 });
 
+try {
+	const kit_dir = fileURLToPath(new URL('../../../packages/kit', import.meta.url));
+	const ls_vite_result = execSync(`pnpm ls --json vite`, { cwd: kit_dir });
+	const vite_version = JSON.parse(ls_vite_result)[0].devDependencies.vite.version;
+	overrides.vite = vite_version;
+} catch (e) {
+	console.error('failed to parse installed vite version from packages/kit');
+	throw e;
+}
+
 test.before(() => {
 	try {
 		// prepare test pnpm workspace
@@ -90,7 +99,7 @@ for (const template of fs.readdirSync('templates')) {
 			execSync('pnpm install --no-frozen-lockfile', { cwd, stdio: 'ignore' });
 
 			// run provided scripts that are non-blocking. All of them should exit with 0
-			const scripts_to_test = ['prepare', 'check', 'lint', 'build', 'sync'];
+			const scripts_to_test = ['sync', 'format', 'lint', 'check', 'build'];
 
 			// package script requires lib dir
 			if (fs.existsSync(path.join(cwd, 'src', 'lib'))) {
@@ -99,7 +108,7 @@ for (const template of fs.readdirSync('templates')) {
 
 			// not all templates have all scripts
 			console.group(`${template}-${types}`);
-			for (const script of Object.keys(pkg.scripts).filter((s) => scripts_to_test.includes(s))) {
+			for (const script of scripts_to_test.filter((s) => !!pkg.scripts[s])) {
 				try {
 					execSync(`pnpm run ${script}`, { cwd, stdio: 'pipe' });
 					console.log(`✅ ${script}`);