From 5191e165b75f5616bd6b4aadf9d8a6c52e75c562 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 26 Mar 2023 00:50:39 -0700 Subject: [PATCH 01/74] chore(deps): update pnpm to v7.30.3 (#9498) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 38b539a61991..23c7c32b49ce 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "tiny-glob": "^0.2.9", "typescript": "^4.9.4" }, - "packageManager": "pnpm@7.30.1", + "packageManager": "pnpm@7.30.3", "engines": { "pnpm": "^7.0.0" }, From ae6ddad365cd8046ed4566963a55e379f0cfc8c8 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 29 Mar 2023 07:50:31 -0400 Subject: [PATCH 02/74] fix: make `error.message` enumerable (#9440) fixes #9010 --------- Co-authored-by: Rich Harris Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com> --- .changeset/sharp-trainers-search.md | 5 +++++ packages/kit/src/exports/vite/dev/index.js | 11 ++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 .changeset/sharp-trainers-search.md diff --git a/.changeset/sharp-trainers-search.md b/.changeset/sharp-trainers-search.md new file mode 100644 index 000000000000..0d143f8a4dc8 --- /dev/null +++ b/.changeset/sharp-trainers-search.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +fix: make `error.message` enumerable when sending `ssrLoadModule` error to client diff --git a/packages/kit/src/exports/vite/dev/index.js b/packages/kit/src/exports/vite/dev/index.js index 1addb038e199..d279e488c5a0 100644 --- a/packages/kit/src/exports/vite/dev/index.js +++ b/packages/kit/src/exports/vite/dev/index.js @@ -58,7 +58,16 @@ export async function dev(vite, vite_config, svelte_config) { const msg = buildErrorMessage(err, [colors.red(`Internal server error: ${err.message}`)]); vite.config.logger.error(msg, { error: err }); - vite.ws.send({ type: 'error', err: err }); + vite.ws.send({ + type: 'error', + err: { + ...err, + // these properties are non-enumerable and will + // not be serialized unless we explicitly include them + message: err.message, + stack: err.stack + } + }); throw err; } From 369e7d6851f543a40c947e033bfc4a9506fdc0a8 Mon Sep 17 00:00:00 2001 From: Hofer Ivan Date: Thu, 30 Mar 2023 10:37:31 +0200 Subject: [PATCH 03/74] feat: expose stronger typed `SubmitFunction` (#9201) partially implements #7161 --------- Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com> --- .changeset/stupid-trains-push.md | 5 ++ .../kit/src/core/sync/write_types/index.js | 27 +++--- .../src/core/sync/write_types/index.spec.js | 1 + .../write_types/test/actions/+page.server.js | 87 +++++++++++++++++++ packages/kit/types/index.d.ts | 10 +-- 5 files changed, 115 insertions(+), 15 deletions(-) create mode 100644 .changeset/stupid-trains-push.md create mode 100644 packages/kit/src/core/sync/write_types/test/actions/+page.server.js diff --git a/.changeset/stupid-trains-push.md b/.changeset/stupid-trains-push.md new file mode 100644 index 000000000000..58f77cd1c2a3 --- /dev/null +++ b/.changeset/stupid-trains-push.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': minor +--- + +feat: expose stronger typed `SubmitFunction` through `./$types` diff --git a/packages/kit/src/core/sync/write_types/index.js b/packages/kit/src/core/sync/write_types/index.js index 0ae180492f12..c1e0c827c825 100644 --- a/packages/kit/src/core/sync/write_types/index.js +++ b/packages/kit/src/core/sync/write_types/index.js @@ -390,16 +390,23 @@ function process_node(node, outdir, is_page, proxies, all_pages_have_load = true if (is_page) { let type = 'unknown'; - if (proxy) { - if (proxy.exports.includes('actions')) { - // If the file wasn't tweaked, we can use the return type of the original file. - // The advantage is that type updates are reflected without saving. - const from = proxy.modified - ? `./proxy${replace_ext_with_js(basename)}` - : path_to_original(outdir, node.server); - - type = `Expand> | null`; - } + if (proxy && proxy.exports.includes('actions')) { + // If the file wasn't tweaked, we can use the return type of the original file. + // The advantage is that type updates are reflected without saving. + const from = proxy.modified + ? `./proxy${replace_ext_with_js(basename)}` + : path_to_original(outdir, node.server); + + exports.push( + `type ExcludeActionFailure = T extends Kit.ActionFailure ? never : T extends void ? never : T;`, + `type ActionsSuccess any>> = { [Key in keyof T]: ExcludeActionFailure>>; }[keyof T];`, + `type ExtractActionFailure = T extends Kit.ActionFailure ? X extends void ? never : X : never;`, + `type ActionsFailure any>> = { [Key in keyof T]: Exclude>>, void>; }[keyof T];`, + `type ActionsExport = typeof import('${from}').actions`, + `export type SubmitFunction = Kit.SubmitFunction>, Expand>>` + ); + + type = `Expand> | null`; } exports.push(`export type ActionData = ${type};`); } diff --git a/packages/kit/src/core/sync/write_types/index.spec.js b/packages/kit/src/core/sync/write_types/index.spec.js index 5abb42c6624b..1971a959f6c7 100644 --- a/packages/kit/src/core/sync/write_types/index.spec.js +++ b/packages/kit/src/core/sync/write_types/index.spec.js @@ -33,6 +33,7 @@ test('Creates correct $types', async () => { // To safe us from creating a real SvelteKit project for each of the tests, // we first run the type generation directly for each test case, and then // call `tsc` to check that the generated types are valid. + await run_test('actions'); await run_test('simple-page-shared-only'); await run_test('simple-page-server-only'); await run_test('simple-page-server-and-shared'); diff --git a/packages/kit/src/core/sync/write_types/test/actions/+page.server.js b/packages/kit/src/core/sync/write_types/test/actions/+page.server.js new file mode 100644 index 000000000000..46dd8f8f4823 --- /dev/null +++ b/packages/kit/src/core/sync/write_types/test/actions/+page.server.js @@ -0,0 +1,87 @@ +import { fail } from '../../../../../../types/internal.js'; + +let condition = false; + +export const actions = { + default: () => { + if (condition) { + return fail(400, { + fail: 'oops' + }); + } + + return { + success: true + }; + }, + successWithPayload: () => { + return { + id: 42, + username: 'John Doe', + profession: 'Svelte specialist' + }; + }, + successWithoutPayload: () => {}, + failWithPayload: () => { + return fail(400, { + reason: { + error: { + code: /** @type {const} */ ('VALIDATION_FAILED') + } + } + }); + }, + failWithoutPayload: () => { + return fail(400); + } +}; + +/** @type {import('./.svelte-kit/types/src/core/sync/write_types/test/actions/$types').SubmitFunction} */ +const submit = () => { + return ({ result }) => { + if (result.type === 'success') { + // @ts-expect-error does only exist on `failure` result + result.data?.fail; + // @ts-expect-error unknown property + result.data?.something; + + if (result.data && 'success' in result.data) { + result.data.success === true; + // @ts-expect-error should be of type `boolean` + result.data.success === 'success'; + // @ts-expect-error does not exist in this branch + result.data.id; + } + + if (result.data && 'id' in result.data) { + result.data.id === 42; + // @ts-expect-error should be of type `number` + result.data.id === 'John'; + // @ts-expect-error does not exist in this branch + result.data.success; + } + } + + if (result.type === 'failure') { + result.data; + // @ts-expect-error does only exist on `success` result + result.data.success; + // @ts-expect-error unknown property + result.data.unknown; + + if (result.data && 'fail' in result.data) { + result.data.fail === ''; + // @ts-expect-error does not exist in this branch + result.data.reason; + } + + if (result.data && 'reason' in result.data) { + result.data.reason.error.code === 'VALIDATION_FAILED'; + // @ts-expect-error should be a const + result.data.reason.error.code === ''; + // @ts-expect-error does not exist in this branch + result.data.fail; + } + } + }; +}; diff --git a/packages/kit/types/index.d.ts b/packages/kit/types/index.d.ts index c2019c4e27b0..19d6c8424f38 100644 --- a/packages/kit/types/index.d.ts +++ b/packages/kit/types/index.d.ts @@ -1167,10 +1167,10 @@ export type Actions< */ export type ActionResult< Success extends Record | undefined = Record, - Invalid extends Record | undefined = Record + Failure extends Record | undefined = Record > = | { type: 'success'; status: number; data?: Success } - | { type: 'failure'; status: number; data?: Invalid } + | { type: 'failure'; status: number; data?: Failure } | { type: 'redirect'; status: number; location: string } | { type: 'error'; status?: number; error: any }; @@ -1239,7 +1239,7 @@ export function text(body: string, init?: ResponseInit): Response; * @param status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses). Must be in the range 400-599. * @param data Data associated with the failure (e.g. validation errors) */ -export function fail | undefined>( +export function fail | undefined = undefined>( status: number, data?: T ): ActionFailure; @@ -1257,7 +1257,7 @@ export interface ActionFailure | undefined = u export interface SubmitFunction< Success extends Record | undefined = Record, - Invalid extends Record | undefined = Record + Failure extends Record | undefined = Record > { (input: { action: URL; @@ -1271,7 +1271,7 @@ export interface SubmitFunction< | ((opts: { form: HTMLFormElement; action: URL; - result: ActionResult; + result: ActionResult; /** * Call this to get the default behavior of a form submission response. * @param options Set `reset: false` if you don't want the `
` values to be reset after a successful submission. From 5fa78207b9a5fc2a84919fabc876c0f4e015fe38 Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Fri, 31 Mar 2023 03:01:10 +0800 Subject: [PATCH 04/74] fix: pass publicDir in ssr (#9565) --- .changeset/sharp-wolves-march.md | 5 +++++ packages/kit/src/exports/vite/index.js | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 .changeset/sharp-wolves-march.md diff --git a/.changeset/sharp-wolves-march.md b/.changeset/sharp-wolves-march.md new file mode 100644 index 000000000000..64aa30be21d3 --- /dev/null +++ b/.changeset/sharp-wolves-march.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +fix: pass `publicDir` Vite config in SSR diff --git a/packages/kit/src/exports/vite/index.js b/packages/kit/src/exports/vite/index.js index 028d873e3cca..c2a339693909 100644 --- a/packages/kit/src/exports/vite/index.js +++ b/packages/kit/src/exports/vite/index.js @@ -564,11 +564,12 @@ function kit({ svelte_config }) { preserveEntrySignatures: 'strict' }, ssrEmitAssets: true, + copyPublicDir: !ssr, target: ssr ? 'node16.14' : undefined, // don't use the default name to avoid collisions with 'static/manifest.json' manifest: 'vite-manifest.json' }, - publicDir: ssr ? false : kit.files.assets, + publicDir: kit.files.assets, worker: { rollupOptions: { output: { From 8b127502f725b4ff12ef709e528a70cef7fea570 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 30 Mar 2023 15:07:56 -0400 Subject: [PATCH 05/74] chore(deps): update pnpm to v7.30.5 (#9536) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 23c7c32b49ce..83923a0ee561 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "tiny-glob": "^0.2.9", "typescript": "^4.9.4" }, - "packageManager": "pnpm@7.30.3", + "packageManager": "pnpm@7.30.5", "engines": { "pnpm": "^7.0.0" }, From cc1d666ee772d07eeb07e39f4fc63185c7f85cc5 Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Thu, 30 Mar 2023 21:12:39 +0200 Subject: [PATCH 06/74] chore: bump site-kit, use new components (#9535) * chore: bump site-kit, use new components - removed most of search as it's now part of site-kit - use new shell/separator components - adjust NavItem usages * oops * oh * bump, use barrel exports * fix type usage --- pnpm-lock.yaml | 14 +- sites/kit.svelte.dev/package.json | 2 +- sites/kit.svelte.dev/src/lib/actions/focus.js | 68 --- .../src/lib/search/Search.svelte | 130 ------ .../src/lib/search/SearchBox.svelte | 418 ------------------ .../src/lib/search/SearchResultList.svelte | 161 ------- .../src/lib/search/SearchResults.svelte | 28 -- sites/kit.svelte.dev/src/lib/search/search.js | 106 ----- sites/kit.svelte.dev/src/lib/search/stores.js | 31 -- .../kit.svelte.dev/src/lib/search/types.d.ts | 13 - .../kit.svelte.dev/src/lib/workers/search.js | 26 -- .../kit.svelte.dev/src/routes/+layout.svelte | 154 ++----- .../src/routes/content.json/+server.js | 2 +- .../content.json}/content.server.js | 8 +- .../src/routes/docs/+layout.svelte | 6 +- .../src/routes/docs/[slug]/+page.svelte | 2 +- .../src/routes/home/Deployment.svelte | 2 +- .../src/routes/home/Features.svelte | 2 +- .../src/routes/home/Intro.svelte | 2 +- .../src/routes/home/Showcase.svelte | 2 +- .../src/routes/home/Svelte.svelte | 6 +- .../kit.svelte.dev/src/routes/home/Try.svelte | 2 +- .../src/routes/search/+page.server.js | 2 +- .../src/routes/search/+page.svelte | 4 +- sites/kit.svelte.dev/vite.config.js | 7 + 25 files changed, 80 insertions(+), 1118 deletions(-) delete mode 100644 sites/kit.svelte.dev/src/lib/actions/focus.js delete mode 100644 sites/kit.svelte.dev/src/lib/search/Search.svelte delete mode 100644 sites/kit.svelte.dev/src/lib/search/SearchBox.svelte delete mode 100644 sites/kit.svelte.dev/src/lib/search/SearchResultList.svelte delete mode 100644 sites/kit.svelte.dev/src/lib/search/SearchResults.svelte delete mode 100644 sites/kit.svelte.dev/src/lib/search/search.js delete mode 100644 sites/kit.svelte.dev/src/lib/search/stores.js delete mode 100644 sites/kit.svelte.dev/src/lib/search/types.d.ts delete mode 100644 sites/kit.svelte.dev/src/lib/workers/search.js rename sites/kit.svelte.dev/src/{lib/search => routes/content.json}/content.server.js (91%) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0c7b645652e2..e730ac26b10e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -689,7 +689,7 @@ importers: '@sveltejs/adapter-vercel': workspace:^ '@sveltejs/amp': workspace:^ '@sveltejs/kit': workspace:^ - '@sveltejs/site-kit': ^3.1.0 + '@sveltejs/site-kit': ^3.3.6 '@types/d3-geo': ^3.0.2 '@types/node': ^16.18.6 d3-geo: ^3.0.1 @@ -715,7 +715,7 @@ importers: '@sveltejs/adapter-vercel': link:../../packages/adapter-vercel '@sveltejs/amp': link:../../packages/amp '@sveltejs/kit': link:../../packages/kit - '@sveltejs/site-kit': 3.1.0 + '@sveltejs/site-kit': 3.3.6_r4kk7euspt2csvnnykfg5n6pxi '@types/d3-geo': 3.0.2 '@types/node': 16.18.6 flexsearch: 0.7.31 @@ -1590,8 +1590,14 @@ packages: picomatch: 2.3.1 rollup: 3.7.0 - /@sveltejs/site-kit/3.1.0: - resolution: {integrity: sha512-Vv9Efzax+NMRZUfZ9TdUqQYicj2Z3kynLkUUdGPfahjlFEwQ3EGyj1vVCg5jxyqvNUgOsVVUb35nXI5CPsmCfA==} + /@sveltejs/site-kit/3.3.6_r4kk7euspt2csvnnykfg5n6pxi: + resolution: {integrity: sha512-MUqHseHHFJOT6AcJYTbUqK7hMy1OkBa231tS4TXkmbgQ8EaFVI2unjs9+WY8m3CXASc4p31givOiKVSqtorbbg==} + peerDependencies: + '@sveltejs/kit': ^1.0.0 + svelte: ^3.54.0 + dependencies: + '@sveltejs/kit': link:packages\kit + svelte: 3.56.0 dev: true /@sveltejs/vite-plugin-svelte/2.0.0_svelte@3.56.0+vite@4.2.0: diff --git a/sites/kit.svelte.dev/package.json b/sites/kit.svelte.dev/package.json index b6afda661674..3ffcb5c260f4 100644 --- a/sites/kit.svelte.dev/package.json +++ b/sites/kit.svelte.dev/package.json @@ -14,7 +14,7 @@ "@sveltejs/adapter-vercel": "workspace:^", "@sveltejs/amp": "workspace:^", "@sveltejs/kit": "workspace:^", - "@sveltejs/site-kit": "^3.1.0", + "@sveltejs/site-kit": "^3.3.6", "@types/d3-geo": "^3.0.2", "@types/node": "^16.18.6", "flexsearch": "^0.7.31", diff --git a/sites/kit.svelte.dev/src/lib/actions/focus.js b/sites/kit.svelte.dev/src/lib/actions/focus.js deleted file mode 100644 index b688318bf0ce..000000000000 --- a/sites/kit.svelte.dev/src/lib/actions/focus.js +++ /dev/null @@ -1,68 +0,0 @@ -/** @param {HTMLElement} node */ -export function focusable_children(node) { - const nodes = Array.from( - node.querySelectorAll( - 'a[href], button, input, textarea, select, details, [tabindex]:not([tabindex="-1"])' - ) - ); - - const index = nodes.indexOf(document.activeElement); - - const update = (d) => { - let i = index + d; - i += nodes.length; - i %= nodes.length; - - // @ts-expect-error - nodes[i].focus(); - }; - - return { - /** @param {string} [selector] */ - next: (selector) => { - const reordered = [...nodes.slice(index + 1), ...nodes.slice(0, index + 1)]; - - for (let i = 0; i < reordered.length; i += 1) { - if (!selector || reordered[i].matches(selector)) { - reordered[i].focus(); - return; - } - } - }, - /** @param {string} [selector] */ - prev: (selector) => { - const reordered = [...nodes.slice(index + 1), ...nodes.slice(0, index + 1)]; - - for (let i = reordered.length - 2; i >= 0; i -= 1) { - if (!selector || reordered[i].matches(selector)) { - reordered[i].focus(); - return; - } - } - }, - update - }; -} - -export function trap(node) { - const handle_keydown = (e) => { - if (e.key === 'Tab') { - e.preventDefault(); - - const group = focusable_children(node); - if (e.shiftKey) { - group.prev(); - } else { - group.next(); - } - } - }; - - node.addEventListener('keydown', handle_keydown); - - return { - destroy: () => { - node.removeEventListener('keydown', handle_keydown); - } - }; -} diff --git a/sites/kit.svelte.dev/src/lib/search/Search.svelte b/sites/kit.svelte.dev/src/lib/search/Search.svelte deleted file mode 100644 index c5feb5ef8f22..000000000000 --- a/sites/kit.svelte.dev/src/lib/search/Search.svelte +++ /dev/null @@ -1,130 +0,0 @@ - - - - { - $searching = true; - $query = e.target.value; - e.target.value = ''; - }} - on:mousedown|preventDefault={() => ($searching = true)} - on:touchend|preventDefault={() => ($searching = true)} - type="search" - name="q" - placeholder="Search" - aria-label="Search" - spellcheck="false" - /> - - {#if browser} -
- {navigator.platform === 'MacIntel' ? '⌘' : 'Ctrl'} K -
- {/if} - - - diff --git a/sites/kit.svelte.dev/src/lib/search/SearchBox.svelte b/sites/kit.svelte.dev/src/lib/search/SearchBox.svelte deleted file mode 100644 index 841a8be1146d..000000000000 --- a/sites/kit.svelte.dev/src/lib/search/SearchBox.svelte +++ /dev/null @@ -1,418 +0,0 @@ - - - { - if (e.key === 'k' && (navigator.platform === 'MacIntel' ? e.metaKey : e.ctrlKey)) { - e.preventDefault(); - $query = ''; - - if ($searching) { - close(); - } else { - $searching = true; - } - } - - if (e.code === 'Escape') { - close(); - } - }} -/> - -{#if $searching && ready} -