From 9a8587f04d28ef2d7476176e09edba2ab9fdf1ca Mon Sep 17 00:00:00 2001 From: James Opstad Date: Tue, 6 Aug 2024 09:32:37 +0100 Subject: [PATCH 01/61] Created vite-node-vm-environment playground --- package.json | 5 + .../vite-node-vm-environment/package.json | 49 +++ .../vite-node-vm-environment/src/app.d.ts | 12 + .../vite-node-vm-environment/src/app.html | 12 + .../vite-node-vm-environment/src/lib/index.js | 1 + .../src/routes/+page.server.ts | 20 ++ .../src/routes/+page.svelte | 14 + .../static/favicon.png | Bin 0 -> 1571 bytes .../vite-node-vm-environment/svelte.config.js | 12 + .../vite-node-vm-environment/tsconfig.json | 19 ++ .../vite-node-vm-environment/vite.config.ts | 11 + pnpm-lock.yaml | 294 +++++++++++------- 12 files changed, 329 insertions(+), 120 deletions(-) create mode 100644 playgrounds/vite-node-vm-environment/package.json create mode 100644 playgrounds/vite-node-vm-environment/src/app.d.ts create mode 100644 playgrounds/vite-node-vm-environment/src/app.html create mode 100644 playgrounds/vite-node-vm-environment/src/lib/index.js create mode 100644 playgrounds/vite-node-vm-environment/src/routes/+page.server.ts create mode 100644 playgrounds/vite-node-vm-environment/src/routes/+page.svelte create mode 100644 playgrounds/vite-node-vm-environment/static/favicon.png create mode 100644 playgrounds/vite-node-vm-environment/svelte.config.js create mode 100644 playgrounds/vite-node-vm-environment/tsconfig.json create mode 100644 playgrounds/vite-node-vm-environment/vite.config.ts diff --git a/package.json b/package.json index 8b62f66d7ede..7a81a4ec696f 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,11 @@ "playwright": "^1.44.1", "typescript-eslint": "^8.0.0" }, + "pnpm": { + "overrides": { + "vite": "6.0.0-alpha.18" + } + }, "packageManager": "pnpm@9.5.0", "engines": { "pnpm": "^9.0.0" diff --git a/playgrounds/vite-node-vm-environment/package.json b/playgrounds/vite-node-vm-environment/package.json new file mode 100644 index 000000000000..5332c6a2eb6f --- /dev/null +++ b/playgrounds/vite-node-vm-environment/package.json @@ -0,0 +1,49 @@ +{ + "name": "vite-node-vm-environment", + "version": "0.0.0", + "private": true, + "scripts": { + "dev": "vite dev", + "build": "vite build && npm run package", + "preview": "vite preview", + "package": "svelte-kit sync && svelte-package && publint", + "prepublishOnly": "npm run package", + "check": "svelte-kit sync && svelte-check --tsconfig ./jsconfig.json", + "check:watch": "svelte-kit sync && svelte-check --tsconfig ./jsconfig.json --watch" + }, + "devDependencies": { + "@sveltejs/adapter-auto": "workspace:*", + "@sveltejs/adapter-cloudflare": "workspace:*", + "@sveltejs/adapter-cloudflare-workers": "workspace:*", + "@sveltejs/adapter-netlify": "workspace:*", + "@sveltejs/adapter-node": "workspace:*", + "@sveltejs/adapter-static": "workspace:*", + "@sveltejs/adapter-vercel": "workspace:*", + "@sveltejs/amp": "workspace:*", + "@sveltejs/kit": "workspace:*", + "@sveltejs/package": "workspace:*", + "@sveltejs/vite-plugin-svelte": "^3.0.1", + "publint": "^0.2.0", + "svelte": "^4.2.10", + "svelte-check": "^3.6.3", + "typescript": "^5.3.3", + "vite": "^5.3.2" + }, + "type": "module", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "svelte": "./dist/index.js" + } + }, + "files": [ + "dist", + "!dist/**/*.test.*", + "!dist/**/*.spec.*" + ], + "peerDependencies": { + "svelte": "^4.0.0" + }, + "svelte": "./dist/index.js", + "types": "./dist/index.d.ts" +} diff --git a/playgrounds/vite-node-vm-environment/src/app.d.ts b/playgrounds/vite-node-vm-environment/src/app.d.ts new file mode 100644 index 000000000000..f59b884c51ed --- /dev/null +++ b/playgrounds/vite-node-vm-environment/src/app.d.ts @@ -0,0 +1,12 @@ +// See https://kit.svelte.dev/docs/types#app +// for information about these interfaces +declare global { + namespace App { + // interface Error {} + // interface Locals {} + // interface PageData {} + // interface Platform {} + } +} + +export {}; diff --git a/playgrounds/vite-node-vm-environment/src/app.html b/playgrounds/vite-node-vm-environment/src/app.html new file mode 100644 index 000000000000..6769ed5e89c5 --- /dev/null +++ b/playgrounds/vite-node-vm-environment/src/app.html @@ -0,0 +1,12 @@ + + + + + + + %sveltekit.head% + + +
%sveltekit.body%
+ + diff --git a/playgrounds/vite-node-vm-environment/src/lib/index.js b/playgrounds/vite-node-vm-environment/src/lib/index.js new file mode 100644 index 000000000000..856f2b6c38ae --- /dev/null +++ b/playgrounds/vite-node-vm-environment/src/lib/index.js @@ -0,0 +1 @@ +// place files you want to import through the `$lib` alias in this folder. diff --git a/playgrounds/vite-node-vm-environment/src/routes/+page.server.ts b/playgrounds/vite-node-vm-environment/src/routes/+page.server.ts new file mode 100644 index 000000000000..7706a5990822 --- /dev/null +++ b/playgrounds/vite-node-vm-environment/src/routes/+page.server.ts @@ -0,0 +1,20 @@ +import type { Actions } from './$types'; + +function getUserAgentText(): string { + if (typeof navigator === 'undefined') { + return 'navigator is undefined (running in Node.js?)'; + } else { + const userAgent = navigator.userAgent; + return `navigator.userAgent = ${userAgent}`; + } +} + +export function load() { + return { userAgentText: getUserAgentText() }; +} + +export const actions = { + default: () => { + console.log('\x1b[32m no-op action \x1b[0m'); + } +} satisfies Actions; diff --git a/playgrounds/vite-node-vm-environment/src/routes/+page.svelte b/playgrounds/vite-node-vm-environment/src/routes/+page.svelte new file mode 100644 index 000000000000..0e417c18bb81 --- /dev/null +++ b/playgrounds/vite-node-vm-environment/src/routes/+page.svelte @@ -0,0 +1,14 @@ + + +
+

Svelte Kit with Vite Node VM Environment

+
+

{data.userAgentText}

+
+ +
+
\ No newline at end of file diff --git a/playgrounds/vite-node-vm-environment/static/favicon.png b/playgrounds/vite-node-vm-environment/static/favicon.png new file mode 100644 index 0000000000000000000000000000000000000000..825b9e65af7c104cfb07089bb28659393b4f2097 GIT binary patch literal 1571 zcmV+;2Hg3HP)Px)-AP12RCwC$UE6KzI1p6{F2N z1VK2vi|pOpn{~#djwYcWXTI_im_u^TJgMZ4JMOsSj!0ma>B?-(Hr@X&W@|R-$}W@Z zgj#$x=!~7LGqHW?IO8+*oE1MyDp!G=L0#^lUx?;!fXv@l^6SvTnf^ac{5OurzC#ZMYc20lI%HhX816AYVs1T3heS1*WaWH z%;x>)-J}YB5#CLzU@GBR6sXYrD>Vw(Fmt#|JP;+}<#6b63Ike{Fuo!?M{yEffez;| zp!PfsuaC)>h>-AdbnwN13g*1LowNjT5?+lFVd#9$!8Z9HA|$*6dQ8EHLu}U|obW6f z2%uGv?vr=KNq7YYa2Roj;|zooo<)lf=&2yxM@e`kM$CmCR#x>gI>I|*Ubr({5Y^rb zghxQU22N}F51}^yfDSt786oMTc!W&V;d?76)9KXX1 z+6Okem(d}YXmmOiZq$!IPk5t8nnS{%?+vDFz3BevmFNgpIod~R{>@#@5x9zJKEHLHv!gHeK~n)Ld!M8DB|Kfe%~123&Hz1Z(86nU7*G5chmyDe ziV7$pB7pJ=96hpxHv9rCR29%bLOXlKU<_13_M8x)6;P8E1Kz6G<&P?$P^%c!M5`2` zfY2zg;VK5~^>TJGQzc+33-n~gKt{{of8GzUkWmU110IgI0DLxRIM>0US|TsM=L|@F z0Bun8U!cRB7-2apz=y-7*UxOxz@Z0)@QM)9wSGki1AZ38ceG7Q72z5`i;i=J`ILzL z@iUO?SBBG-0cQuo+an4TsLy-g-x;8P4UVwk|D8{W@U1Zi z!M)+jqy@nQ$p?5tsHp-6J304Q={v-B>66$P0IDx&YT(`IcZ~bZfmn11#rXd7<5s}y zBi9eim&zQc0Dk|2>$bs0PnLmDfMP5lcXRY&cvJ=zKxI^f0%-d$tD!`LBf9^jMSYUA zI8U?CWdY@}cRq6{5~y+)#h1!*-HcGW@+gZ4B};0OnC~`xQOyH19z*TA!!BJ%9s0V3F?CAJ{hTd#*tf+ur-W9MOURF-@B77_-OshsY}6 zOXRY=5%C^*26z?l)1=$bz30!so5tfABdSYzO+H=CpV~aaUefmjvfZ3Ttu9W&W3Iu6 zROlh0MFA5h;my}8lB0tAV-Rvc2Zs_CCSJnx@d`**$idgy-iMob4dJWWw|21b4NB=LfsYp0Aeh{Ov)yztQi;eL4y5 zMi>8^SzKqk8~k?UiQK^^-5d8c%bV?$F8%X~czyiaKCI2=UH=20} peerDependencies: svelte: ^4.0.0 || ^5.0.0-next.0 - vite: ^5.0.0 + vite: 6.0.0-alpha.18 '@svitejs/changesets-changelog-github-compact@1.1.0': resolution: {integrity: sha512-qhUGGDHcpbY2zpjW3SwqchuW8J/5EzlPFud7xNntHKA7f3a/mx5+g+ruJKFHSAiVZYo30PALt+AyhmPUNKH/Og==} @@ -4155,8 +4209,8 @@ packages: engines: {node: ^18.0.0 || >=20.0.0} hasBin: true - vite@5.3.3: - resolution: {integrity: sha512-NPQdeCU0Dv2z5fu+ULotpuq5yfCS1BzKUIPhNbP3YBfAMGJXbt2nS+sbTFu+qchaqWTD+H3JK++nRwr6XIcp6A==} + vite@6.0.0-alpha.18: + resolution: {integrity: sha512-UFvwSPOjUiZR3x6G/LuxrM0hzKaxYUe6MTN6lu89NTEDgkWgFCNRP/5pyzUDEXZqtzEuq3bKrslb34VDZF+5Ig==} engines: {node: ^18.0.0 || >=20.0.0} hasBin: true peerDependencies: @@ -4186,7 +4240,7 @@ packages: vitefu@0.2.5: resolution: {integrity: sha512-SgHtMLoqaeeGnd2evZ849ZbACbnwQCIwRH57t18FxcXoZop0uQu0uzlIhJBlF/eWVzuce0sHeqPcDo+evVcg8Q==} peerDependencies: - vite: ^3.0.0 || ^4.0.0 || ^5.0.0 + vite: 6.0.0-alpha.18 peerDependenciesMeta: vite: optional: true @@ -5019,26 +5073,26 @@ snapshots: svelte: 4.2.17 svelte-persisted-store: 0.9.4(svelte@4.2.17) - '@sveltejs/vite-plugin-svelte-inspector@2.1.0(@sveltejs/vite-plugin-svelte@3.1.0(svelte@4.2.17)(vite@5.3.3(@types/node@18.19.31)(lightningcss@1.24.1)))(svelte@4.2.17)(vite@5.3.3(@types/node@18.19.31)(lightningcss@1.24.1))': + '@sveltejs/vite-plugin-svelte-inspector@2.1.0(@sveltejs/vite-plugin-svelte@3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)))(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1))': dependencies: - '@sveltejs/vite-plugin-svelte': 3.1.0(svelte@4.2.17)(vite@5.3.3(@types/node@18.19.31)(lightningcss@1.24.1)) + '@sveltejs/vite-plugin-svelte': 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) debug: 4.3.5 svelte: 4.2.17 - vite: 5.3.3(@types/node@18.19.31)(lightningcss@1.24.1) + vite: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) transitivePeerDependencies: - supports-color - '@sveltejs/vite-plugin-svelte@3.1.0(svelte@4.2.17)(vite@5.3.3(@types/node@18.19.31)(lightningcss@1.24.1))': + '@sveltejs/vite-plugin-svelte@3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1))': dependencies: - '@sveltejs/vite-plugin-svelte-inspector': 2.1.0(@sveltejs/vite-plugin-svelte@3.1.0(svelte@4.2.17)(vite@5.3.3(@types/node@18.19.31)(lightningcss@1.24.1)))(svelte@4.2.17)(vite@5.3.3(@types/node@18.19.31)(lightningcss@1.24.1)) + '@sveltejs/vite-plugin-svelte-inspector': 2.1.0(@sveltejs/vite-plugin-svelte@3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)))(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) debug: 4.3.5 deepmerge: 4.3.1 kleur: 4.1.5 magic-string: 0.30.10 svelte: 4.2.17 svelte-hmr: 0.16.0(svelte@4.2.17) - vite: 5.3.3(@types/node@18.19.31)(lightningcss@1.24.1) - vitefu: 0.2.5(vite@5.3.3(@types/node@18.19.31)(lightningcss@1.24.1)) + vite: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) + vitefu: 0.2.5(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) transitivePeerDependencies: - supports-color @@ -7070,7 +7124,7 @@ snapshots: debug: 4.3.5 pathe: 1.1.2 picocolors: 1.0.1 - vite: 5.3.3(@types/node@18.19.31)(lightningcss@1.24.1) + vite: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) transitivePeerDependencies: - '@types/node' - less @@ -7081,7 +7135,7 @@ snapshots: - supports-color - terser - vite@5.3.3(@types/node@18.19.31)(lightningcss@1.24.1): + vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1): dependencies: esbuild: 0.21.5 postcss: 8.4.39 @@ -7091,9 +7145,9 @@ snapshots: fsevents: 2.3.3 lightningcss: 1.24.1 - vitefu@0.2.5(vite@5.3.3(@types/node@18.19.31)(lightningcss@1.24.1)): + vitefu@0.2.5(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)): optionalDependencies: - vite: 5.3.3(@types/node@18.19.31)(lightningcss@1.24.1) + vite: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) vitest@2.0.1(@types/node@18.19.31)(lightningcss@1.24.1): dependencies: @@ -7112,7 +7166,7 @@ snapshots: std-env: 3.7.0 tinybench: 2.8.0 tinypool: 1.0.0 - vite: 5.3.3(@types/node@18.19.31)(lightningcss@1.24.1) + vite: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) vite-node: 2.0.1(@types/node@18.19.31)(lightningcss@1.24.1) why-is-node-running: 2.3.0 optionalDependencies: From 8edc12a0ece3c571a6dffc55c4a66b5d6c133c42 Mon Sep 17 00:00:00 2001 From: James Opstad Date: Tue, 20 Aug 2024 17:57:05 +0100 Subject: [PATCH 02/61] Created vite-workerd-environment playground --- .../vite-workerd-environment/package.json | 49 +++++++++++ .../vite-workerd-environment/src/app.d.ts | 12 +++ .../vite-workerd-environment/src/app.html | 12 +++ .../vite-workerd-environment/src/lib/index.js | 1 + .../src/routes/+page.server.ts | 20 +++++ .../src/routes/+page.svelte | 14 +++ .../static/favicon.png | Bin 0 -> 1571 bytes .../vite-workerd-environment/svelte.config.js | 12 +++ .../vite-workerd-environment/tsconfig.json | 19 +++++ .../vite-workerd-environment/vite.config.ts | 11 +++ pnpm-lock.yaml | 80 +++++++++++++++++- 11 files changed, 229 insertions(+), 1 deletion(-) create mode 100644 playgrounds/vite-workerd-environment/package.json create mode 100644 playgrounds/vite-workerd-environment/src/app.d.ts create mode 100644 playgrounds/vite-workerd-environment/src/app.html create mode 100644 playgrounds/vite-workerd-environment/src/lib/index.js create mode 100644 playgrounds/vite-workerd-environment/src/routes/+page.server.ts create mode 100644 playgrounds/vite-workerd-environment/src/routes/+page.svelte create mode 100644 playgrounds/vite-workerd-environment/static/favicon.png create mode 100644 playgrounds/vite-workerd-environment/svelte.config.js create mode 100644 playgrounds/vite-workerd-environment/tsconfig.json create mode 100644 playgrounds/vite-workerd-environment/vite.config.ts diff --git a/playgrounds/vite-workerd-environment/package.json b/playgrounds/vite-workerd-environment/package.json new file mode 100644 index 000000000000..8a93e1485480 --- /dev/null +++ b/playgrounds/vite-workerd-environment/package.json @@ -0,0 +1,49 @@ +{ + "name": "vite-workerd-environment", + "version": "0.0.0", + "private": true, + "scripts": { + "dev": "vite dev", + "build": "vite build && npm run package", + "preview": "vite preview", + "package": "svelte-kit sync && svelte-package && publint", + "prepublishOnly": "npm run package", + "check": "svelte-kit sync && svelte-check --tsconfig ./jsconfig.json", + "check:watch": "svelte-kit sync && svelte-check --tsconfig ./jsconfig.json --watch" + }, + "devDependencies": { + "@sveltejs/adapter-auto": "workspace:*", + "@sveltejs/adapter-cloudflare": "workspace:*", + "@sveltejs/adapter-cloudflare-workers": "workspace:*", + "@sveltejs/adapter-netlify": "workspace:*", + "@sveltejs/adapter-node": "workspace:*", + "@sveltejs/adapter-static": "workspace:*", + "@sveltejs/adapter-vercel": "workspace:*", + "@sveltejs/amp": "workspace:*", + "@sveltejs/kit": "workspace:*", + "@sveltejs/package": "workspace:*", + "@sveltejs/vite-plugin-svelte": "^3.0.1", + "publint": "^0.2.0", + "svelte": "^4.2.10", + "svelte-check": "^3.6.3", + "typescript": "^5.3.3", + "vite": "^5.3.2" + }, + "type": "module", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "svelte": "./dist/index.js" + } + }, + "files": [ + "dist", + "!dist/**/*.test.*", + "!dist/**/*.spec.*" + ], + "peerDependencies": { + "svelte": "^4.0.0" + }, + "svelte": "./dist/index.js", + "types": "./dist/index.d.ts" +} diff --git a/playgrounds/vite-workerd-environment/src/app.d.ts b/playgrounds/vite-workerd-environment/src/app.d.ts new file mode 100644 index 000000000000..f59b884c51ed --- /dev/null +++ b/playgrounds/vite-workerd-environment/src/app.d.ts @@ -0,0 +1,12 @@ +// See https://kit.svelte.dev/docs/types#app +// for information about these interfaces +declare global { + namespace App { + // interface Error {} + // interface Locals {} + // interface PageData {} + // interface Platform {} + } +} + +export {}; diff --git a/playgrounds/vite-workerd-environment/src/app.html b/playgrounds/vite-workerd-environment/src/app.html new file mode 100644 index 000000000000..6769ed5e89c5 --- /dev/null +++ b/playgrounds/vite-workerd-environment/src/app.html @@ -0,0 +1,12 @@ + + + + + + + %sveltekit.head% + + +
%sveltekit.body%
+ + diff --git a/playgrounds/vite-workerd-environment/src/lib/index.js b/playgrounds/vite-workerd-environment/src/lib/index.js new file mode 100644 index 000000000000..856f2b6c38ae --- /dev/null +++ b/playgrounds/vite-workerd-environment/src/lib/index.js @@ -0,0 +1 @@ +// place files you want to import through the `$lib` alias in this folder. diff --git a/playgrounds/vite-workerd-environment/src/routes/+page.server.ts b/playgrounds/vite-workerd-environment/src/routes/+page.server.ts new file mode 100644 index 000000000000..7706a5990822 --- /dev/null +++ b/playgrounds/vite-workerd-environment/src/routes/+page.server.ts @@ -0,0 +1,20 @@ +import type { Actions } from './$types'; + +function getUserAgentText(): string { + if (typeof navigator === 'undefined') { + return 'navigator is undefined (running in Node.js?)'; + } else { + const userAgent = navigator.userAgent; + return `navigator.userAgent = ${userAgent}`; + } +} + +export function load() { + return { userAgentText: getUserAgentText() }; +} + +export const actions = { + default: () => { + console.log('\x1b[32m no-op action \x1b[0m'); + } +} satisfies Actions; diff --git a/playgrounds/vite-workerd-environment/src/routes/+page.svelte b/playgrounds/vite-workerd-environment/src/routes/+page.svelte new file mode 100644 index 000000000000..030959917b57 --- /dev/null +++ b/playgrounds/vite-workerd-environment/src/routes/+page.svelte @@ -0,0 +1,14 @@ + + +
+

Svelte Kit with Vite Workerd Environment

+
+

{data.userAgentText}

+
+ +
+
\ No newline at end of file diff --git a/playgrounds/vite-workerd-environment/static/favicon.png b/playgrounds/vite-workerd-environment/static/favicon.png new file mode 100644 index 0000000000000000000000000000000000000000..825b9e65af7c104cfb07089bb28659393b4f2097 GIT binary patch literal 1571 zcmV+;2Hg3HP)Px)-AP12RCwC$UE6KzI1p6{F2N z1VK2vi|pOpn{~#djwYcWXTI_im_u^TJgMZ4JMOsSj!0ma>B?-(Hr@X&W@|R-$}W@Z zgj#$x=!~7LGqHW?IO8+*oE1MyDp!G=L0#^lUx?;!fXv@l^6SvTnf^ac{5OurzC#ZMYc20lI%HhX816AYVs1T3heS1*WaWH z%;x>)-J}YB5#CLzU@GBR6sXYrD>Vw(Fmt#|JP;+}<#6b63Ike{Fuo!?M{yEffez;| zp!PfsuaC)>h>-AdbnwN13g*1LowNjT5?+lFVd#9$!8Z9HA|$*6dQ8EHLu}U|obW6f z2%uGv?vr=KNq7YYa2Roj;|zooo<)lf=&2yxM@e`kM$CmCR#x>gI>I|*Ubr({5Y^rb zghxQU22N}F51}^yfDSt786oMTc!W&V;d?76)9KXX1 z+6Okem(d}YXmmOiZq$!IPk5t8nnS{%?+vDFz3BevmFNgpIod~R{>@#@5x9zJKEHLHv!gHeK~n)Ld!M8DB|Kfe%~123&Hz1Z(86nU7*G5chmyDe ziV7$pB7pJ=96hpxHv9rCR29%bLOXlKU<_13_M8x)6;P8E1Kz6G<&P?$P^%c!M5`2` zfY2zg;VK5~^>TJGQzc+33-n~gKt{{of8GzUkWmU110IgI0DLxRIM>0US|TsM=L|@F z0Bun8U!cRB7-2apz=y-7*UxOxz@Z0)@QM)9wSGki1AZ38ceG7Q72z5`i;i=J`ILzL z@iUO?SBBG-0cQuo+an4TsLy-g-x;8P4UVwk|D8{W@U1Zi z!M)+jqy@nQ$p?5tsHp-6J304Q={v-B>66$P0IDx&YT(`IcZ~bZfmn11#rXd7<5s}y zBi9eim&zQc0Dk|2>$bs0PnLmDfMP5lcXRY&cvJ=zKxI^f0%-d$tD!`LBf9^jMSYUA zI8U?CWdY@}cRq6{5~y+)#h1!*-HcGW@+gZ4B};0OnC~`xQOyH19z*TA!!BJ%9s0V3F?CAJ{hTd#*tf+ur-W9MOURF-@B77_-OshsY}6 zOXRY=5%C^*26z?l)1=$bz30!so5tfABdSYzO+H=CpV~aaUefmjvfZ3Ttu9W&W3Iu6 zROlh0MFA5h;my}8lB0tAV-Rvc2Zs_CCSJnx@d`**$idgy-iMob4dJWWw|21b4NB=LfsYp0Aeh{Ov)yztQi;eL4y5 zMi>8^SzKqk8~k?UiQK^^-5d8c%bV?$F8%X~czyiaKCI2=UH= 5' typescript-eslint: '>= 7.5' + '@sveltejs/kit@2.5.24': + resolution: {integrity: sha512-Nr2oxsCsDfEkdS/zzQQQbsPYTbu692Qs3/iE3L7VHzCVjG2+WujF9oMUozWI7GuX98KxYSoPMlAsfmDLSg44hQ==} + engines: {node: '>=18.13'} + hasBin: true + peerDependencies: + '@sveltejs/vite-plugin-svelte': ^3.0.0 || ^4.0.0-next.1 + svelte: ^4.0.0 || ^5.0.0-next.0 + vite: 6.0.0-alpha.18 + '@sveltejs/site-kit@6.0.0-next.64': resolution: {integrity: sha512-SosLY07DBA79yJhRR9vQpk9eXlSc3VjzOlIJQFvPzgsbu727rq5u3dudFEsm0NeQFoAF+NNgDYi5D85v5Yc+vQ==} peerDependencies: @@ -5066,6 +5126,24 @@ snapshots: typescript: 5.4.5 typescript-eslint: 8.0.0(eslint@9.6.0)(typescript@5.4.5) + '@sveltejs/kit@2.5.24(@sveltejs/vite-plugin-svelte@3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)))(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1))': + dependencies: + '@sveltejs/vite-plugin-svelte': 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) + '@types/cookie': 0.6.0 + cookie: 0.6.0 + devalue: 5.0.0 + esm-env: 1.0.0 + import-meta-resolve: 4.1.0 + kleur: 4.1.5 + magic-string: 0.30.10 + mrmime: 2.0.0 + sade: 1.8.1 + set-cookie-parser: 2.6.0 + sirv: 2.0.4 + svelte: 4.2.17 + tiny-glob: 0.2.9 + vite: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) + '@sveltejs/site-kit@6.0.0-next.64(@sveltejs/kit@packages+kit)(svelte@4.2.17)': dependencies: '@sveltejs/kit': link:packages/kit From 558f42b349dbcb654ca225d202bafccb8059ee9c Mon Sep 17 00:00:00 2001 From: James Opstad Date: Tue, 20 Aug 2024 18:48:10 +0100 Subject: [PATCH 03/61] Returned response from workerd environment --- packages/kit/src/exports/vite/dev/index.js | 41 ++++++++++----- .../vite/dev/workerd-dev-entrypoint.ts | 7 +++ .../vite-workerd-environment/package.json | 4 +- .../vite-workerd-environment/vite.config.ts | 3 +- .../worker-configuration.d.ts | 6 +++ .../vite-workerd-environment/wrangler.toml | 50 +++++++++++++++++++ pnpm-lock.yaml | 24 ++++++++- 7 files changed, 120 insertions(+), 15 deletions(-) create mode 100644 packages/kit/src/exports/vite/dev/workerd-dev-entrypoint.ts create mode 100644 playgrounds/vite-workerd-environment/worker-configuration.d.ts create mode 100644 playgrounds/vite-workerd-environment/wrangler.toml diff --git a/packages/kit/src/exports/vite/dev/index.js b/packages/kit/src/exports/vite/dev/index.js index e3e69432aa81..155f5490dea1 100644 --- a/packages/kit/src/exports/vite/dev/index.js +++ b/packages/kit/src/exports/vite/dev/index.js @@ -1,6 +1,6 @@ import fs from 'node:fs'; import path from 'node:path'; -import { URL } from 'node:url'; +import { fileURLToPath, URL } from 'node:url'; import { AsyncLocalStorage } from 'node:async_hooks'; import colors from 'kleur'; import sirv from 'sirv'; @@ -20,6 +20,8 @@ import { check_feature } from '../../../utils/features.js'; const cwd = process.cwd(); +const WORKERD_DEV_ENV_NAME = 'vite-plugin-cloudflare-workerd-env'; + /** * @param {import('vite').ViteDevServer} vite * @param {import('vite').ResolvedConfig} vite_config @@ -521,19 +523,34 @@ export async function dev(vite, vite_config, svelte_config) { return; } - const rendered = await server.respond(request, { - getClientAddress: () => { - const { remoteAddress } = req.socket; - if (remoteAddress) return remoteAddress; - throw new Error('Could not determine clientAddress'); - }, - read: (file) => fs.readFileSync(path.join(svelte_config.kit.files.assets, file)), - before_handle: (event, config, prerender) => { - async_local_storage.enterWith({ event, config, prerender }); - }, - emulator + /** @type {{ api: { getHandler: (opts: { entrypoint: string }) => Promise<(req: Request) => Promise> }}} */ + const devEnv = vite.environments[WORKERD_DEV_ENV_NAME]; + + if (!devEnv) { + throw new Error('No Cloudflare dev environment is present'); + } + + const __dirname = fileURLToPath(new URL('.', import.meta.url)); + + const handler = await devEnv.api.getHandler({ + entrypoint: path.join(__dirname, 'workerd-dev-entrypoint.ts') }); + const rendered = await handler(request); + + // const rendered = await server.respond(request, { + // getClientAddress: () => { + // const { remoteAddress } = req.socket; + // if (remoteAddress) return remoteAddress; + // throw new Error('Could not determine clientAddress'); + // }, + // read: (file) => fs.readFileSync(path.join(svelte_config.kit.files.assets, file)), + // before_handle: (event, config, prerender) => { + // async_local_storage.enterWith({ event, config, prerender }); + // }, + // emulator + // }); + if (rendered.status === 404) { // @ts-expect-error serve_static_middleware.handle(req, res, () => { diff --git a/packages/kit/src/exports/vite/dev/workerd-dev-entrypoint.ts b/packages/kit/src/exports/vite/dev/workerd-dev-entrypoint.ts new file mode 100644 index 000000000000..c7b28d20ef4a --- /dev/null +++ b/packages/kit/src/exports/vite/dev/workerd-dev-entrypoint.ts @@ -0,0 +1,7 @@ +const handler = { + fetch: (req: Request, env: any, ctx: any): Promise => { + return new Promise((resolve) => resolve(new Response('Hello from workerd'))); + } +}; + +export default handler; diff --git a/playgrounds/vite-workerd-environment/package.json b/playgrounds/vite-workerd-environment/package.json index 8a93e1485480..f5cac6dd921e 100644 --- a/playgrounds/vite-workerd-environment/package.json +++ b/playgrounds/vite-workerd-environment/package.json @@ -9,9 +9,11 @@ "package": "svelte-kit sync && svelte-package && publint", "prepublishOnly": "npm run package", "check": "svelte-kit sync && svelte-check --tsconfig ./jsconfig.json", - "check:watch": "svelte-kit sync && svelte-check --tsconfig ./jsconfig.json --watch" + "check:watch": "svelte-kit sync && svelte-check --tsconfig ./jsconfig.json --watch", + "typegen": "wrangler types" }, "devDependencies": { + "@dario-hacking/vite-6-alpha-environment-provider-workerd": "^0.0.5", "@sveltejs/adapter-auto": "workspace:*", "@sveltejs/adapter-cloudflare": "workspace:*", "@sveltejs/adapter-cloudflare-workers": "workspace:*", diff --git a/playgrounds/vite-workerd-environment/vite.config.ts b/playgrounds/vite-workerd-environment/vite.config.ts index 7617d19b8849..ff846fef29c3 100644 --- a/playgrounds/vite-workerd-environment/vite.config.ts +++ b/playgrounds/vite-workerd-environment/vite.config.ts @@ -1,8 +1,9 @@ +import { workerdEnvironment } from '@dario-hacking/vite-6-alpha-environment-provider-workerd'; import { sveltekit } from '@sveltejs/kit/vite'; import { defineConfig } from 'vite'; export default defineConfig({ - plugins: [sveltekit()], + plugins: [workerdEnvironment('vite-plugin-cloudflare-workerd-env'), sveltekit()], server: { fs: { allow: ['../../packages/kit'] diff --git a/playgrounds/vite-workerd-environment/worker-configuration.d.ts b/playgrounds/vite-workerd-environment/worker-configuration.d.ts new file mode 100644 index 000000000000..129bc4591858 --- /dev/null +++ b/playgrounds/vite-workerd-environment/worker-configuration.d.ts @@ -0,0 +1,6 @@ +// Generated by Wrangler on Tue Aug 20 2024 18:19:21 GMT+0100 (British Summer Time) +// by running `wrangler types` + +interface Env { + MY_KV: KVNamespace; +} diff --git a/playgrounds/vite-workerd-environment/wrangler.toml b/playgrounds/vite-workerd-environment/wrangler.toml new file mode 100644 index 000000000000..98cb694edfe8 --- /dev/null +++ b/playgrounds/vite-workerd-environment/wrangler.toml @@ -0,0 +1,50 @@ +name = "vite-workerd-environment" +compatibility_date = "2024-03-04" + +# Variable bindings. These are arbitrary, plaintext strings (similar to environment variables) +# Note: Use secrets to store sensitive data. +# Docs: https://developers.cloudflare.com/workers/platform/environment-variables +# [vars] +# MY_VARIABLE = "production_value" + +# Bind a KV Namespace. Use KV as persistent storage for small key-value pairs. +# Docs: https://developers.cloudflare.com/workers/runtime-apis/kv +[[kv_namespaces]] +binding = "MY_KV" +id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + +# Bind an R2 Bucket. Use R2 to store arbitrarily large blobs of data, such as files. +# Docs: https://developers.cloudflare.com/r2/api/workers/workers-api-usage/ +# [[r2_buckets]] +# binding = "MY_BUCKET" +# bucket_name = "my-bucket" + +# Bind a Queue producer. Use this binding to schedule an arbitrary task that may be processed later by a Queue consumer. +# Docs: https://developers.cloudflare.com/queues/get-started +# [[queues.producers]] +# binding = "MY_QUEUE" +# queue = "my-queue" + +# Bind a Queue consumer. Queue Consumers can retrieve tasks scheduled by Producers to act on them. +# Docs: https://developers.cloudflare.com/queues/get-started +# [[queues.consumers]] +# queue = "my-queue" + +# Bind another Worker service. Use this binding to call another Worker without network overhead. +# Docs: https://developers.cloudflare.com/workers/platform/services +# [[services]] +# binding = "MY_SERVICE" +# service = "my-service" + +# Bind a Durable Object. Durable objects are a scale-to-zero compute primitive based on the actor model. +# Durable Objects can live for as long as needed. Use these when you need a long-running "server", such as in realtime apps. +# Docs: https://developers.cloudflare.com/workers/runtime-apis/durable-objects +# [[durable_objects.bindings]] +# name = "MY_DURABLE_OBJECT" +# class_name = "MyDurableObject" + +# Durable Object migrations. +# Docs: https://developers.cloudflare.com/workers/learning/using-durable-objects#configure-durable-object-classes-with-migrations +# [[migrations]] +# tag = "v1" +# new_classes = ["MyDurableObject"] diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f84652ed693f..f058fc057bea 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1289,6 +1289,9 @@ importers: playgrounds/vite-workerd-environment: devDependencies: + '@dario-hacking/vite-6-alpha-environment-provider-workerd': + specifier: ^0.0.5 + version: 0.0.5(miniflare@3.20240701.0)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1))(wrangler@3.63.1) '@sveltejs/adapter-auto': specifier: workspace:* version: link:../../packages/adapter-auto @@ -1538,6 +1541,13 @@ packages: resolution: {integrity: sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==} engines: {node: '>=12'} + '@dario-hacking/vite-6-alpha-environment-provider-workerd@0.0.5': + resolution: {integrity: sha512-9SXOJDE4IGszLG0cRzU38OLSXyJhKkmnzoeNYPua142bvb5XCeL9zNGqXk4sjQfVd7Dhh+iut89a3ubROhkPwg==} + peerDependencies: + miniflare: ^3.20240129.3 + vite: 6.0.0-alpha.18 + wrangler: ^3.57.2 + '@emnapi/runtime@1.2.0': resolution: {integrity: sha512-bV21/9LQmcQeCPEg3BDFtvwL6cwiTMksYNWQQ4KOxCZikEGalWtenoZ0wCiukJINlGCIi2KXx01g4FoH/LxpzQ==} @@ -2578,6 +2588,9 @@ packages: resolution: {integrity: sha512-NIxF55hv4nSqQswkAeiOi1r83xy8JldOFDTWiug55KBu9Jnblncd2U6ViHmYgHf01TPZS77NJBhBMKdWj9HQMQ==} engines: {node: '>=8'} + cjs-module-lexer@1.3.1: + resolution: {integrity: sha512-a3KdPAANPbNE4ZUv9h6LckSl9zLsYOP4MBmhIPkRaeyybt+r4UghLvq+xw/YwUcC1gqylCkL4rdVs3Lwupjm4Q==} + code-block-writer@13.0.1: resolution: {integrity: sha512-c5or4P6erEA69TxaxTNcHUNcIn+oyxSRTOWV+pSYF+z4epXqNvwvJ70XPGjPNgue83oAFAPBRQYwpAJ/Hpe/Sg==} @@ -2623,7 +2636,7 @@ packages: resolution: {integrity: sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg==} concat-map@0.0.1: - resolution: {integrity: sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=} + resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==} consola@3.2.3: resolution: {integrity: sha512-I5qxpzLv+sJhTVEoLYNcTW+bThDCPsit0vLNKShZx6rLtpilNpmmeTPaeqJb9ZE9dV3DGaeby6Vuhrw38WjeyQ==} @@ -4643,6 +4656,13 @@ snapshots: dependencies: '@jridgewell/trace-mapping': 0.3.9 + '@dario-hacking/vite-6-alpha-environment-provider-workerd@0.0.5(miniflare@3.20240701.0)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1))(wrangler@3.63.1)': + dependencies: + cjs-module-lexer: 1.3.1 + miniflare: 3.20240701.0 + vite: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) + wrangler: 3.63.1(@cloudflare/workers-types@4.20240405.0) + '@emnapi/runtime@1.2.0': dependencies: tslib: 2.6.2 @@ -5565,6 +5585,8 @@ snapshots: ci-info@3.9.0: {} + cjs-module-lexer@1.3.1: {} + code-block-writer@13.0.1: {} code-red@1.0.4: From aa1679e98b2248cf510427071518dfd1a4252a25 Mon Sep 17 00:00:00 2001 From: James Opstad Date: Thu, 22 Aug 2024 09:57:23 +0100 Subject: [PATCH 04/61] Added node module runner and entrypoint --- packages/kit/src/exports/vite/dev/index.js | 34 +++++++++--------- .../src/exports/vite/dev/node_entrypoint.js | 5 +++ .../vite/dev/workerd-dev-entrypoint.ts | 7 ---- .../exports/vite/dev/workerd__entrypoint.js | 5 +++ packages/kit/src/exports/vite/index.js | 9 +++++ .../package.json | 2 +- .../src/app.d.ts | 0 .../src/app.html | 0 .../src/lib/index.js | 0 .../src/routes/+page.server.ts | 0 .../src/routes/+page.svelte | 2 +- .../static/favicon.png | Bin .../svelte.config.js | 0 .../tsconfig.json | 0 .../vite.config.ts | 0 pnpm-lock.yaml | 2 +- 16 files changed, 38 insertions(+), 28 deletions(-) create mode 100644 packages/kit/src/exports/vite/dev/node_entrypoint.js delete mode 100644 packages/kit/src/exports/vite/dev/workerd-dev-entrypoint.ts create mode 100644 packages/kit/src/exports/vite/dev/workerd__entrypoint.js rename playgrounds/{vite-node-vm-environment => vite-node-environment}/package.json (97%) rename playgrounds/{vite-node-vm-environment => vite-node-environment}/src/app.d.ts (100%) rename playgrounds/{vite-node-vm-environment => vite-node-environment}/src/app.html (100%) rename playgrounds/{vite-node-vm-environment => vite-node-environment}/src/lib/index.js (100%) rename playgrounds/{vite-node-vm-environment => vite-node-environment}/src/routes/+page.server.ts (100%) rename playgrounds/{vite-node-vm-environment => vite-node-environment}/src/routes/+page.svelte (80%) rename playgrounds/{vite-node-vm-environment => vite-node-environment}/static/favicon.png (100%) rename playgrounds/{vite-node-vm-environment => vite-node-environment}/svelte.config.js (100%) rename playgrounds/{vite-node-vm-environment => vite-node-environment}/tsconfig.json (100%) rename playgrounds/{vite-node-vm-environment => vite-node-environment}/vite.config.ts (100%) diff --git a/packages/kit/src/exports/vite/dev/index.js b/packages/kit/src/exports/vite/dev/index.js index 155f5490dea1..e83c420becd6 100644 --- a/packages/kit/src/exports/vite/dev/index.js +++ b/packages/kit/src/exports/vite/dev/index.js @@ -18,9 +18,9 @@ import { not_found } from '../utils.js'; import { SCHEME } from '../../../utils/url.js'; import { check_feature } from '../../../utils/features.js'; -const cwd = process.cwd(); +import { createServerModuleRunner } from 'vite'; -const WORKERD_DEV_ENV_NAME = 'vite-plugin-cloudflare-workerd-env'; +const cwd = process.cwd(); /** * @param {import('vite').ViteDevServer} vite @@ -523,20 +523,18 @@ export async function dev(vite, vite_config, svelte_config) { return; } - /** @type {{ api: { getHandler: (opts: { entrypoint: string }) => Promise<(req: Request) => Promise> }}} */ - const devEnv = vite.environments[WORKERD_DEV_ENV_NAME]; - - if (!devEnv) { - throw new Error('No Cloudflare dev environment is present'); - } - + const module_runner = createServerModuleRunner(vite.environments.node); const __dirname = fileURLToPath(new URL('.', import.meta.url)); + const entrypoint = await module_runner.import(path.join(__dirname, 'node_entrypoint.js')); + const handler = entrypoint.default.fetch; - const handler = await devEnv.api.getHandler({ - entrypoint: path.join(__dirname, 'workerd-dev-entrypoint.ts') - }); + const rendered = await handler(); + + // const handler = await devEnv.api.getHandler({ + // entrypoint: path.join(__dirname, 'workerd-dev-entrypoint.ts') + // }); - const rendered = await handler(request); + // const rendered = await handler(request); // const rendered = await server.respond(request, { // getClientAddress: () => { @@ -544,11 +542,11 @@ export async function dev(vite, vite_config, svelte_config) { // if (remoteAddress) return remoteAddress; // throw new Error('Could not determine clientAddress'); // }, - // read: (file) => fs.readFileSync(path.join(svelte_config.kit.files.assets, file)), - // before_handle: (event, config, prerender) => { - // async_local_storage.enterWith({ event, config, prerender }); - // }, - // emulator + // read: (file) => fs.readFileSync(path.join(svelte_config.kit.files.assets, file)) + // // before_handle: (event, config, prerender) => { + // // async_local_storage.enterWith({ event, config, prerender }); + // // }, + // // emulator // }); if (rendered.status === 404) { diff --git a/packages/kit/src/exports/vite/dev/node_entrypoint.js b/packages/kit/src/exports/vite/dev/node_entrypoint.js new file mode 100644 index 000000000000..63ea26bc7944 --- /dev/null +++ b/packages/kit/src/exports/vite/dev/node_entrypoint.js @@ -0,0 +1,5 @@ +export default { + fetch: () => { + return new Promise((resolve) => resolve(new Response('hello from node environment'))); + } +}; diff --git a/packages/kit/src/exports/vite/dev/workerd-dev-entrypoint.ts b/packages/kit/src/exports/vite/dev/workerd-dev-entrypoint.ts deleted file mode 100644 index c7b28d20ef4a..000000000000 --- a/packages/kit/src/exports/vite/dev/workerd-dev-entrypoint.ts +++ /dev/null @@ -1,7 +0,0 @@ -const handler = { - fetch: (req: Request, env: any, ctx: any): Promise => { - return new Promise((resolve) => resolve(new Response('Hello from workerd'))); - } -}; - -export default handler; diff --git a/packages/kit/src/exports/vite/dev/workerd__entrypoint.js b/packages/kit/src/exports/vite/dev/workerd__entrypoint.js new file mode 100644 index 000000000000..e00177892667 --- /dev/null +++ b/packages/kit/src/exports/vite/dev/workerd__entrypoint.js @@ -0,0 +1,5 @@ +export default { + fetch: () => { + return new Promise((resolve) => resolve(new Response('Hello from workerd'))); + } +}; diff --git a/packages/kit/src/exports/vite/index.js b/packages/kit/src/exports/vite/index.js index 2280025bcc62..74d4b0421987 100644 --- a/packages/kit/src/exports/vite/index.js +++ b/packages/kit/src/exports/vite/index.js @@ -35,6 +35,8 @@ import { } from './module_ids.js'; import { resolve_peer_dependency } from '../../utils/import.js'; +// import * as vite from 'vite' + const cwd = process.cwd(); /** @type {import('./types.js').EnforcedConfig} */ @@ -250,6 +252,13 @@ async function kit({ svelte_config }) { // dev and preview config can be shared /** @type {import('vite').UserConfig} */ const new_config = { + environments: { + node: { + dev: { + createEnvironment: vite.createNodeEnvironment + } + } + }, resolve: { alias: [ { find: '__SERVER__', replacement: `${generated}/server` }, diff --git a/playgrounds/vite-node-vm-environment/package.json b/playgrounds/vite-node-environment/package.json similarity index 97% rename from playgrounds/vite-node-vm-environment/package.json rename to playgrounds/vite-node-environment/package.json index 5332c6a2eb6f..949cb7d74e37 100644 --- a/playgrounds/vite-node-vm-environment/package.json +++ b/playgrounds/vite-node-environment/package.json @@ -1,5 +1,5 @@ { - "name": "vite-node-vm-environment", + "name": "vite-node-environment", "version": "0.0.0", "private": true, "scripts": { diff --git a/playgrounds/vite-node-vm-environment/src/app.d.ts b/playgrounds/vite-node-environment/src/app.d.ts similarity index 100% rename from playgrounds/vite-node-vm-environment/src/app.d.ts rename to playgrounds/vite-node-environment/src/app.d.ts diff --git a/playgrounds/vite-node-vm-environment/src/app.html b/playgrounds/vite-node-environment/src/app.html similarity index 100% rename from playgrounds/vite-node-vm-environment/src/app.html rename to playgrounds/vite-node-environment/src/app.html diff --git a/playgrounds/vite-node-vm-environment/src/lib/index.js b/playgrounds/vite-node-environment/src/lib/index.js similarity index 100% rename from playgrounds/vite-node-vm-environment/src/lib/index.js rename to playgrounds/vite-node-environment/src/lib/index.js diff --git a/playgrounds/vite-node-vm-environment/src/routes/+page.server.ts b/playgrounds/vite-node-environment/src/routes/+page.server.ts similarity index 100% rename from playgrounds/vite-node-vm-environment/src/routes/+page.server.ts rename to playgrounds/vite-node-environment/src/routes/+page.server.ts diff --git a/playgrounds/vite-node-vm-environment/src/routes/+page.svelte b/playgrounds/vite-node-environment/src/routes/+page.svelte similarity index 80% rename from playgrounds/vite-node-vm-environment/src/routes/+page.svelte rename to playgrounds/vite-node-environment/src/routes/+page.svelte index 0e417c18bb81..8a71c359751b 100644 --- a/playgrounds/vite-node-vm-environment/src/routes/+page.svelte +++ b/playgrounds/vite-node-environment/src/routes/+page.svelte @@ -5,7 +5,7 @@
-

Svelte Kit with Vite Node VM Environment

+

Svelte Kit with Vite Node Environment


{data.userAgentText}

diff --git a/playgrounds/vite-node-vm-environment/static/favicon.png b/playgrounds/vite-node-environment/static/favicon.png similarity index 100% rename from playgrounds/vite-node-vm-environment/static/favicon.png rename to playgrounds/vite-node-environment/static/favicon.png diff --git a/playgrounds/vite-node-vm-environment/svelte.config.js b/playgrounds/vite-node-environment/svelte.config.js similarity index 100% rename from playgrounds/vite-node-vm-environment/svelte.config.js rename to playgrounds/vite-node-environment/svelte.config.js diff --git a/playgrounds/vite-node-vm-environment/tsconfig.json b/playgrounds/vite-node-environment/tsconfig.json similarity index 100% rename from playgrounds/vite-node-vm-environment/tsconfig.json rename to playgrounds/vite-node-environment/tsconfig.json diff --git a/playgrounds/vite-node-vm-environment/vite.config.ts b/playgrounds/vite-node-environment/vite.config.ts similarity index 100% rename from playgrounds/vite-node-vm-environment/vite.config.ts rename to playgrounds/vite-node-environment/vite.config.ts diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f058fc057bea..097d0e0a13d2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1236,7 +1236,7 @@ importers: specifier: 6.0.0-alpha.18 version: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) - playgrounds/vite-node-vm-environment: + playgrounds/vite-node-environment: devDependencies: '@sveltejs/adapter-auto': specifier: workspace:* From dde5922b5639c05df7496b247a7d25d38066be12 Mon Sep 17 00:00:00 2001 From: James Opstad Date: Fri, 23 Aug 2024 17:03:53 +0100 Subject: [PATCH 05/61] Initial POC for running inside module runner --- packages/kit/src/exports/vite/dev/index.js | 27 +-- .../src/exports/vite/dev/node_entrypoint.js | 20 ++- packages/kit/src/exports/vite/index.js | 160 +++++++++++++++++- packages/kit/src/exports/vite/module_ids.js | 1 + packages/kit/src/types/ambient-private.d.ts | 9 + .../src/routes/+page.server.ts | 8 +- 6 files changed, 202 insertions(+), 23 deletions(-) diff --git a/packages/kit/src/exports/vite/dev/index.js b/packages/kit/src/exports/vite/dev/index.js index e83c420becd6..2be46c36ef52 100644 --- a/packages/kit/src/exports/vite/dev/index.js +++ b/packages/kit/src/exports/vite/dev/index.js @@ -4,7 +4,7 @@ import { fileURLToPath, URL } from 'node:url'; import { AsyncLocalStorage } from 'node:async_hooks'; import colors from 'kleur'; import sirv from 'sirv'; -import { isCSSRequest, loadEnv, buildErrorMessage } from 'vite'; +import { isCSSRequest, loadEnv, buildErrorMessage, createServerModuleRunner } from 'vite'; import { createReadableStream, getRequest, setResponse } from '../../../exports/node/index.js'; import { installPolyfills } from '../../../exports/node/polyfills.js'; import { coalesce_to_error } from '../../../utils/error.js'; @@ -18,17 +18,16 @@ import { not_found } from '../utils.js'; import { SCHEME } from '../../../utils/url.js'; import { check_feature } from '../../../utils/features.js'; -import { createServerModuleRunner } from 'vite'; - const cwd = process.cwd(); /** * @param {import('vite').ViteDevServer} vite * @param {import('vite').ResolvedConfig} vite_config * @param {import('types').ValidatedConfig} svelte_config + * @param {any} environment_context * @return {Promise void>>} */ -export async function dev(vite, vite_config, svelte_config) { +export async function dev(vite, vite_config, svelte_config, environment_context) { installPolyfills(); const async_local_storage = new AsyncLocalStorage(); @@ -94,6 +93,9 @@ export async function dev(vite, vite_config, svelte_config) { const module = await loud_ssr_load_module(url); const module_node = await vite.moduleGraph.getModuleByUrl(url); + + vite.environments.node.moduleGraph.getModuleByUrl; + if (!module_node) throw new Error(`Could not find node for ${url}`); return { module, module_node, url }; @@ -421,7 +423,7 @@ export async function dev(vite, vite_config, svelte_config) { }); const env = loadEnv(vite_config.mode, svelte_config.kit.env.dir, ''); - const emulator = await svelte_config.kit.adapter?.emulate?.(); + // const emulator = await svelte_config.kit.adapter?.emulate?.(); return () => { const serve_static_middleware = vite.middlewares.stack.find( @@ -433,6 +435,8 @@ export async function dev(vite, vite_config, svelte_config) { // serving routes with those names. See https://github.com/vitejs/vite/issues/7363 remove_static_middlewares(vite.middlewares); + const module_runner = createServerModuleRunner(vite.environments.node); + vite.middlewares.use(async (req, res) => { // Vite's base middleware strips out the base path. Restore it const original_url = req.url; @@ -523,18 +527,15 @@ export async function dev(vite, vite_config, svelte_config) { return; } - const module_runner = createServerModuleRunner(vite.environments.node); + environment_context.manifest_data = manifest_data; + environment_context.env = env; + environment_context.remote_address = req.socket.remoteAddress; + const __dirname = fileURLToPath(new URL('.', import.meta.url)); const entrypoint = await module_runner.import(path.join(__dirname, 'node_entrypoint.js')); const handler = entrypoint.default.fetch; - const rendered = await handler(); - - // const handler = await devEnv.api.getHandler({ - // entrypoint: path.join(__dirname, 'workerd-dev-entrypoint.ts') - // }); - - // const rendered = await handler(request); + const rendered = await handler(request); // const rendered = await server.respond(request, { // getClientAddress: () => { diff --git a/packages/kit/src/exports/vite/dev/node_entrypoint.js b/packages/kit/src/exports/vite/dev/node_entrypoint.js index 63ea26bc7944..40299dec402f 100644 --- a/packages/kit/src/exports/vite/dev/node_entrypoint.js +++ b/packages/kit/src/exports/vite/dev/node_entrypoint.js @@ -1,5 +1,21 @@ +import { Server } from '../../../runtime/server/index.js'; + export default { - fetch: () => { - return new Promise((resolve) => resolve(new Response('hello from node environment'))); + fetch: /** @param {Request} request **/ async (request) => { + const environment_context = await import('__sveltekit/environment_context'); + + const server = new Server(environment_context.manifest); + + await server.init({ + env: environment_context.env + }); + + return server.respond(request, { + getClientAddress: () => { + if (environment_context.remote_address) return environment_context.remote_address; + + throw new Error('Could not determine clientAddress'); + } + }); } }; diff --git a/packages/kit/src/exports/vite/index.js b/packages/kit/src/exports/vite/index.js index 74d4b0421987..ae4a60beacb0 100644 --- a/packages/kit/src/exports/vite/index.js +++ b/packages/kit/src/exports/vite/index.js @@ -3,11 +3,19 @@ import path from 'node:path'; import colors from 'kleur'; -import { copy, mkdirp, posixify, read, resolve_entry, rimraf } from '../../utils/filesystem.js'; +import { + copy, + mkdirp, + posixify, + read, + resolve_entry, + rimraf, + to_fs +} from '../../utils/filesystem.js'; import { create_static_module, create_dynamic_module } from '../../core/env.js'; import * as sync from '../../core/sync/sync.js'; import { create_assets } from '../../core/sync/create_manifest_data/index.js'; -import { runtime_directory, logger } from '../../core/utils.js'; +import { runtime_directory, logger, get_mime_lookup, runtime_base } from '../../core/utils.js'; import { load_config } from '../../core/config/index.js'; import { generate_manifest } from '../../core/generate_manifest/index.js'; import { build_server_nodes } from './build/build_server.js'; @@ -31,11 +39,13 @@ import { service_worker, sveltekit_environment, sveltekit_paths, - sveltekit_server + sveltekit_server, + sveltekit_environment_context } from './module_ids.js'; import { resolve_peer_dependency } from '../../utils/import.js'; -// import * as vite from 'vite' +/** @type {{ manifest_data: import('types').ManifestData, env: Record, remote_address: string | undefined }} */ +const environment_context = {}; const cwd = process.cwd(); @@ -510,6 +520,146 @@ async function kit({ svelte_config }) { } `; } + + case sveltekit_environment_context: { + const { manifest_data, env, remote_address } = environment_context; + + return dedent` + import path from 'node:path'; + import fs from 'node:fs'; + import { to_fs, from_fs } from '../../packages/kit/src/utils/filesystem.js'; + import { compact } from '../../packages/kit/src/utils/array.js'; + + export const cwd = process.cwd(); + + async function loud_ssr_load_module(url) { + return await import(/* @vite-ignore */ url); + } + + async function resolve(id) { + const url = id.startsWith('..') ? to_fs(path.posix.resolve(id)) : \`/\${id}\`; + + const module = await loud_ssr_load_module(url); + + return { module, url }; + } + + export let manifest = { + appDir: ${JSON.stringify(svelte_config.kit.appDir)}, + appPath: ${JSON.stringify(svelte_config.kit.appDir)}, + assets: new Set(${JSON.stringify(manifest_data.assets.map((asset) => asset.file))}), + mimeTypes: ${JSON.stringify(get_mime_lookup(manifest_data))}, + _: { + client: { + start: ${JSON.stringify(`${runtime_base}/client/entry.js`)}, + app: ${JSON.stringify(`${to_fs(svelte_config.kit.outDir)}/generated/client/app.js`)}, + imports: [], + stylesheets: [], + fonts: [], + uses_env_dynamic_public: true + }, + server_assets: {}, + nodes: ${JSON.stringify(manifest_data.nodes, (key, value) => { + if (['depth', 'parent', 'child_pages'].includes(key)) return; + + return value; + })}.map((node, index) => { + return async () => { + /** @type {import('types').SSRNode} */ + const result = {}; + + /** @type {import('vite').ModuleNode[]} */ + const module_nodes = []; + + result.index = index; + + // these are unused in dev, it's easier to include them + result.imports = []; + result.stylesheets = []; + result.fonts = []; + + if (node.component) { + result.component = async () => { + const { module } = await resolve( + /** @type {string} */ (node.component) + ); + + return module.default; + }; + } + + if (node.universal) { + const { module } = await resolve(node.universal); + + result.universal = module; + result.universal_id = node.universal; + } + + if (node.server) { + const { module } = await resolve(node.server); + + result.server = module; + result.server_id = node.server; + } + + return result; + }; + }), + routes: compact( + ${JSON.stringify(manifest_data.routes, (key, value) => { + if (['parent'].includes(key)) return; + + if (key === 'pattern') return value.toString(); + + return value; + })}.map((route) => { + if (!route.page && !route.endpoint) return null; + + const endpoint = route.endpoint; + + return { + id: route.id, + pattern: /^\\/$/, + params: route.params, + page: route.page, + endpoint: endpoint + ? async () => { + const url = path.resolve(cwd, endpoint.file); + return await loud_ssr_load_module(url); + } + : null, + endpoint_id: endpoint?.file + }; + }) + ), + matchers: async () => { + /** @type {Record} */ + const matchers = {}; + + for (const key in ${JSON.stringify(manifest_data.matchers)}) { + const file = ${JSON.stringify(manifest_data.matchers)}[key]; + const url = path.resolve(cwd, file); + const module = await import(/* @vite-ignore */ url); + + if (module.match) { + matchers[key] = module.match; + } else { + throw new Error(\`\${file} does not export a 'match' function\`); + } + } + + return matchers; + } + } + }; + + export let env = ${JSON.stringify(env)} + + export let remote_address = ${JSON.stringify(remote_address)} + + export let assets_directory = ${JSON.stringify(svelte_config.kit.files.assets)} + `; + } } } }; @@ -678,7 +828,7 @@ async function kit({ svelte_config }) { * @see https://vitejs.dev/guide/api-plugin.html#configureserver */ async configureServer(vite) { - return await dev(vite, vite_config, svelte_config); + return await dev(vite, vite_config, svelte_config, environment_context); }, /** diff --git a/packages/kit/src/exports/vite/module_ids.js b/packages/kit/src/exports/vite/module_ids.js index 3be16f68a71f..432eb1d9b141 100644 --- a/packages/kit/src/exports/vite/module_ids.js +++ b/packages/kit/src/exports/vite/module_ids.js @@ -10,6 +10,7 @@ export const service_worker = '\0virtual:$service-worker'; export const sveltekit_environment = '\0virtual:__sveltekit/environment'; export const sveltekit_paths = '\0virtual:__sveltekit/paths'; export const sveltekit_server = '\0virtual:__sveltekit/server'; +export const sveltekit_environment_context = '\0virtual:__sveltekit/environment_context'; export const app_server = fileURLToPath( new URL('../../runtime/app/server/index.js', import.meta.url) diff --git a/packages/kit/src/types/ambient-private.d.ts b/packages/kit/src/types/ambient-private.d.ts index 4f1491475355..e07096a66c99 100644 --- a/packages/kit/src/types/ambient-private.d.ts +++ b/packages/kit/src/types/ambient-private.d.ts @@ -26,3 +26,12 @@ declare module '__sveltekit/server' { export function set_manifest(manifest: SSRManifest): void; export function set_read_implementation(fn: (path: string) => ReadableStream): void; } + +declare module '__sveltekit/environment_context' { + import { SSRManifest } from '@sveltejs/kit'; + + export let manifest: SSRManifest; + export let env: Record; + export let remote_address: string | undefined; + export let assets_directory: string; +} diff --git a/playgrounds/vite-node-environment/src/routes/+page.server.ts b/playgrounds/vite-node-environment/src/routes/+page.server.ts index 7706a5990822..6082fcb3cfab 100644 --- a/playgrounds/vite-node-environment/src/routes/+page.server.ts +++ b/playgrounds/vite-node-environment/src/routes/+page.server.ts @@ -1,4 +1,4 @@ -import type { Actions } from './$types'; +import type { Actions, PageServerLoad } from './$types'; function getUserAgentText(): string { if (typeof navigator === 'undefined') { @@ -9,9 +9,11 @@ function getUserAgentText(): string { } } -export function load() { +export const load: PageServerLoad = async ({ fetch }) => { + const res = await fetch('favicon.png'); + console.log(res); return { userAgentText: getUserAgentText() }; -} +}; export const actions = { default: () => { From 87b7f9f05ce05a382ea1dfc0a1b77da3de383f3b Mon Sep 17 00:00:00 2001 From: James Opstad Date: Tue, 27 Aug 2024 12:17:09 +0100 Subject: [PATCH 06/61] Revised manifest routes --- packages/kit/src/exports/vite/index.js | 364 ++++++++++++------ .../src/routes/+page.server.ts | 4 +- .../src/routes/about/+page.svelte | 1 + 3 files changed, 252 insertions(+), 117 deletions(-) create mode 100644 playgrounds/vite-node-environment/src/routes/about/+page.svelte diff --git a/packages/kit/src/exports/vite/index.js b/packages/kit/src/exports/vite/index.js index ae4a60beacb0..1d884be84ef8 100644 --- a/packages/kit/src/exports/vite/index.js +++ b/packages/kit/src/exports/vite/index.js @@ -525,140 +525,276 @@ async function kit({ svelte_config }) { const { manifest_data, env, remote_address } = environment_context; return dedent` - import path from 'node:path'; - import fs from 'node:fs'; - import { to_fs, from_fs } from '../../packages/kit/src/utils/filesystem.js'; - import { compact } from '../../packages/kit/src/utils/array.js'; + import path from 'node:path'; + import fs from 'node:fs'; + import { to_fs, from_fs } from '../../packages/kit/src/utils/filesystem.js'; + import { compact } from '../../packages/kit/src/utils/array.js'; - export const cwd = process.cwd(); + export const cwd = process.cwd(); - async function loud_ssr_load_module(url) { - return await import(/* @vite-ignore */ url); - } + async function loud_ssr_load_module(url) { + return await import(/* @vite-ignore */ url); + } - async function resolve(id) { - const url = id.startsWith('..') ? to_fs(path.posix.resolve(id)) : \`/\${id}\`; + async function resolve(id) { + const url = id.startsWith('..') ? to_fs(path.posix.resolve(id)) : \`/\${id}\`; - const module = await loud_ssr_load_module(url); + const module = await loud_ssr_load_module(url); - return { module, url }; - } + return { module, url }; + } - export let manifest = { - appDir: ${JSON.stringify(svelte_config.kit.appDir)}, - appPath: ${JSON.stringify(svelte_config.kit.appDir)}, - assets: new Set(${JSON.stringify(manifest_data.assets.map((asset) => asset.file))}), - mimeTypes: ${JSON.stringify(get_mime_lookup(manifest_data))}, - _: { - client: { - start: ${JSON.stringify(`${runtime_base}/client/entry.js`)}, - app: ${JSON.stringify(`${to_fs(svelte_config.kit.outDir)}/generated/client/app.js`)}, - imports: [], - stylesheets: [], - fonts: [], - uses_env_dynamic_public: true - }, - server_assets: {}, - nodes: ${JSON.stringify(manifest_data.nodes, (key, value) => { - if (['depth', 'parent', 'child_pages'].includes(key)) return; - - return value; - })}.map((node, index) => { - return async () => { - /** @type {import('types').SSRNode} */ - const result = {}; - - /** @type {import('vite').ModuleNode[]} */ - const module_nodes = []; - - result.index = index; - - // these are unused in dev, it's easier to include them - result.imports = []; - result.stylesheets = []; - result.fonts = []; - - if (node.component) { - result.component = async () => { - const { module } = await resolve( - /** @type {string} */ (node.component) - ); - - return module.default; - }; - } + export let manifest = { + appDir: ${s(svelte_config.kit.appDir)}, + appPath: ${s(svelte_config.kit.appDir)}, + assets: new Set(${s(manifest_data.assets.map((asset) => asset.file))}), + mimeTypes: ${s(get_mime_lookup(manifest_data))}, + _: { + client: { + start: ${s(`${runtime_base}/client/entry.js`)}, + app: ${s(`${to_fs(svelte_config.kit.outDir)}/generated/client/app.js`)}, + imports: [], + stylesheets: [], + fonts: [], + uses_env_dynamic_public: true + }, + server_assets: {}, + nodes: ${s(manifest_data.nodes, (key, value) => { + if (['depth', 'parent_id', 'parent', 'child_pages'].includes(key)) return; + return value; + })}.map((node, index) => { + return async () => { + /** @type {import('types').SSRNode} */ + const result = {}; - if (node.universal) { - const { module } = await resolve(node.universal); + /** @type {import('vite').ModuleNode[]} */ + const module_nodes = []; - result.universal = module; - result.universal_id = node.universal; - } + result.index = index; - if (node.server) { - const { module } = await resolve(node.server); + // these are unused in dev, it's easier to include them + result.imports = []; + result.stylesheets = []; + result.fonts = []; - result.server = module; - result.server_id = node.server; - } + if (node.component) { + result.component = async () => { + const { module } = await resolve( + /** @type {string} */ (node.component) + ); - return result; - }; - }), - routes: compact( - ${JSON.stringify(manifest_data.routes, (key, value) => { - if (['parent'].includes(key)) return; + return module.default; + }; + } - if (key === 'pattern') return value.toString(); + if (node.universal) { + const { module } = await resolve(node.universal); - return value; - })}.map((route) => { - if (!route.page && !route.endpoint) return null; - - const endpoint = route.endpoint; - - return { - id: route.id, - pattern: /^\\/$/, - params: route.params, - page: route.page, - endpoint: endpoint - ? async () => { - const url = path.resolve(cwd, endpoint.file); - return await loud_ssr_load_module(url); - } - : null, - endpoint_id: endpoint?.file + result.universal = module; + result.universal_id = node.universal; + } + + if (node.server) { + const { module } = await resolve(node.server); + + result.server = module; + result.server_id = node.server; + } + + return result; }; - }) - ), - matchers: async () => { - /** @type {Record} */ - const matchers = {}; - - for (const key in ${JSON.stringify(manifest_data.matchers)}) { - const file = ${JSON.stringify(manifest_data.matchers)}[key]; - const url = path.resolve(cwd, file); - const module = await import(/* @vite-ignore */ url); - - if (module.match) { - matchers[key] = module.match; - } else { - throw new Error(\`\${file} does not export a 'match' function\`); + }), + routes: [ + ${manifest_data.routes + .map((route) => { + if (!route.page && !route.endpoint) return; + + const endpoint = route.endpoint; + + return dedent` + { + id: ${s(route.id)}, + pattern: ${route.pattern}, + params: ${s(route.params)}, + page: ${s(route.page)}, + endpoint: ${s( + endpoint + ? ` + async () => { + const url = path.resolve(cwd, endpoint.file); + return await loud_ssr_load_module(url); + } + ` + : 'null' + )} + } + `; + }) + .filter(Boolean) + .join(',\n')} + ], + matchers: async () => { + /** @type {Record} */ + const matchers = {}; + + for (const key in ${s(manifest_data.matchers)}) { + const file = ${s(manifest_data.matchers)}[key]; + const url = path.resolve(cwd, file); + const module = await import(/* @vite-ignore */ url); + + if (module.match) { + matchers[key] = module.match; + } else { + throw new Error(\`\${file} does not export a 'match' function\`); + } } - } - return matchers; + return matchers; + } } - } - }; + }; - export let env = ${JSON.stringify(env)} + export let env = ${s(env)} - export let remote_address = ${JSON.stringify(remote_address)} + export let remote_address = ${s(remote_address)} - export let assets_directory = ${JSON.stringify(svelte_config.kit.files.assets)} - `; + export let assets_directory = ${s(svelte_config.kit.files.assets)} + `; + + // return dedent` + // import path from 'node:path'; + // import fs from 'node:fs'; + // import { to_fs, from_fs } from '../../packages/kit/src/utils/filesystem.js'; + // import { compact } from '../../packages/kit/src/utils/array.js'; + + // export const cwd = process.cwd(); + + // async function loud_ssr_load_module(url) { + // return await import(/* @vite-ignore */ url); + // } + + // async function resolve(id) { + // const url = id.startsWith('..') ? to_fs(path.posix.resolve(id)) : \`/\${id}\`; + + // const module = await loud_ssr_load_module(url); + + // return { module, url }; + // } + + // export let manifest = { + // appDir: ${s(svelte_config.kit.appDir)}, + // appPath: ${s(svelte_config.kit.appDir)}, + // assets: new Set(${s(manifest_data.assets.map((asset) => asset.file))}), + // mimeTypes: ${s(get_mime_lookup(manifest_data))}, + // _: { + // client: { + // start: ${s(`${runtime_base}/client/entry.js`)}, + // app: ${s(`${to_fs(svelte_config.kit.outDir)}/generated/client/app.js`)}, + // imports: [], + // stylesheets: [], + // fonts: [], + // uses_env_dynamic_public: true + // }, + // server_assets: {}, + // nodes: ${s(manifest_data.nodes, (key, value) => { + // if (['depth', 'parent_id', 'parent', 'child_pages'].includes(key)) return; + // return value; + // })}.map((node, index) => { + // return async () => { + // /** @type {import('types').SSRNode} */ + // const result = {}; + + // /** @type {import('vite').ModuleNode[]} */ + // const module_nodes = []; + + // result.index = index; + + // // these are unused in dev, it's easier to include them + // result.imports = []; + // result.stylesheets = []; + // result.fonts = []; + + // if (node.component) { + // result.component = async () => { + // const { module } = await resolve( + // /** @type {string} */ (node.component) + // ); + + // return module.default; + // }; + // } + + // if (node.universal) { + // const { module } = await resolve(node.universal); + + // result.universal = module; + // result.universal_id = node.universal; + // } + + // if (node.server) { + // const { module } = await resolve(node.server); + + // result.server = module; + // result.server_id = node.server; + // } + + // return result; + // }; + // }), + // routes: compact( + // ${s(manifest_data.routes, (key, value) => { + // if (['parent'].includes(key)) return; + + // if (key === 'pattern') return value.toString(); + + // return value; + // })}.map((route) => { + // if (!route.page && !route.endpoint) return null; + + // const endpoint = route.endpoint; + + // return { + // id: route.id, + // pattern: /^\\/$/, + // params: route.params, + // page: route.page, + // endpoint: endpoint + // ? async () => { + // const url = path.resolve(cwd, endpoint.file); + // return await loud_ssr_load_module(url); + // } + // : null, + // endpoint_id: endpoint?.file + // }; + // }) + // ), + // matchers: async () => { + // /** @type {Record} */ + // const matchers = {}; + + // for (const key in ${s(manifest_data.matchers)}) { + // const file = ${s(manifest_data.matchers)}[key]; + // const url = path.resolve(cwd, file); + // const module = await import(/* @vite-ignore */ url); + + // if (module.match) { + // matchers[key] = module.match; + // } else { + // throw new Error(\`\${file} does not export a 'match' function\`); + // } + // } + + // return matchers; + // } + // } + // }; + + // export let env = ${s(env)} + + // export let remote_address = ${s(remote_address)} + + // export let assets_directory = ${s(svelte_config.kit.files.assets)} + // `; } } } diff --git a/playgrounds/vite-node-environment/src/routes/+page.server.ts b/playgrounds/vite-node-environment/src/routes/+page.server.ts index 6082fcb3cfab..0e9996e8120e 100644 --- a/playgrounds/vite-node-environment/src/routes/+page.server.ts +++ b/playgrounds/vite-node-environment/src/routes/+page.server.ts @@ -9,9 +9,7 @@ function getUserAgentText(): string { } } -export const load: PageServerLoad = async ({ fetch }) => { - const res = await fetch('favicon.png'); - console.log(res); +export const load: PageServerLoad = () => { return { userAgentText: getUserAgentText() }; }; diff --git a/playgrounds/vite-node-environment/src/routes/about/+page.svelte b/playgrounds/vite-node-environment/src/routes/about/+page.svelte new file mode 100644 index 000000000000..7d877fdd78f3 --- /dev/null +++ b/playgrounds/vite-node-environment/src/routes/about/+page.svelte @@ -0,0 +1 @@ +

About

\ No newline at end of file From e9e61e13efb35a62ea8a863302dc21e592f82c99 Mon Sep 17 00:00:00 2001 From: James Opstad Date: Tue, 27 Aug 2024 13:39:51 +0100 Subject: [PATCH 07/61] Revised manifest nodes --- packages/kit/src/exports/vite/index.js | 88 ++++++++++++++------------ 1 file changed, 47 insertions(+), 41 deletions(-) diff --git a/packages/kit/src/exports/vite/index.js b/packages/kit/src/exports/vite/index.js index 1d884be84ef8..b7dc86ad3ade 100644 --- a/packages/kit/src/exports/vite/index.js +++ b/packages/kit/src/exports/vite/index.js @@ -524,7 +524,7 @@ async function kit({ svelte_config }) { case sveltekit_environment_context: { const { manifest_data, env, remote_address } = environment_context; - return dedent` + const manifest = dedent` import path from 'node:path'; import fs from 'node:fs'; import { to_fs, from_fs } from '../../packages/kit/src/utils/filesystem.js'; @@ -559,51 +559,55 @@ async function kit({ svelte_config }) { uses_env_dynamic_public: true }, server_assets: {}, - nodes: ${s(manifest_data.nodes, (key, value) => { - if (['depth', 'parent_id', 'parent', 'child_pages'].includes(key)) return; - return value; - })}.map((node, index) => { - return async () => { - /** @type {import('types').SSRNode} */ - const result = {}; - - /** @type {import('vite').ModuleNode[]} */ - const module_nodes = []; - - result.index = index; - - // these are unused in dev, it's easier to include them - result.imports = []; - result.stylesheets = []; - result.fonts = []; - - if (node.component) { - result.component = async () => { - const { module } = await resolve( - /** @type {string} */ (node.component) - ); - - return module.default; - }; - } + nodes: [ + ${manifest_data.nodes + .map((node, i) => { + const index = s(i); + const component = s(node.component); + const universal = s(node.universal); + const server = s(node.server); - if (node.universal) { - const { module } = await resolve(node.universal); + return dedent` + async () => { + /** @type {import('types').SSRNode} */ + const result = {}; - result.universal = module; - result.universal_id = node.universal; - } + /** @type {import('vite').ModuleNode[]} */ + const module_nodes = []; - if (node.server) { - const { module } = await resolve(node.server); + result.index = ${index}; - result.server = module; - result.server_id = node.server; - } + // these are unused in dev, it's easier to include them + result.imports = []; + result.stylesheets = []; + result.fonts = []; + + if (${component}) { + result.component = async () => { + const { module } = await resolve(${component}); + } + } + + if (${universal}) { + const { module } = await resolve(${universal}); + + result.universal = module; + result.universal_id = ${universal}; + } + + if (${server}) { + const { module } = await resolve(${server}); - return result; - }; - }), + result.server = module; + result.server_id = ${server}; + } + + return result; + } + `; + }) + .join(',\n')} + ], routes: [ ${manifest_data.routes .map((route) => { @@ -661,6 +665,8 @@ async function kit({ svelte_config }) { export let assets_directory = ${s(svelte_config.kit.files.assets)} `; + return manifest; + // return dedent` // import path from 'node:path'; // import fs from 'node:fs'; From 588941042ec23c83878a4686966369b17533994b Mon Sep 17 00:00:00 2001 From: James Opstad Date: Wed, 28 Aug 2024 12:49:11 +0100 Subject: [PATCH 08/61] Used pathe for path resolution --- packages/kit/package.json | 1 + packages/kit/src/exports/vite/dev/index.js | 2 +- .../src/exports/vite/dev/node_entrypoint.js | 4 +- packages/kit/src/exports/vite/dev/utils.js | 18 ++ packages/kit/src/exports/vite/index.js | 216 ++++++++---------- .../src/routes/+page.server.ts | 2 +- .../src/routes/+page.svelte | 8 +- .../src/routes/about/+page.svelte | 8 +- .../src/routes/endpoint/+server.ts | 13 ++ pnpm-lock.yaml | 3 + 10 files changed, 153 insertions(+), 122 deletions(-) create mode 100644 packages/kit/src/exports/vite/dev/utils.js create mode 100644 playgrounds/vite-node-environment/src/routes/endpoint/+server.ts diff --git a/packages/kit/package.json b/packages/kit/package.json index e6cdb4854708..3de5aa1b3afc 100644 --- a/packages/kit/package.json +++ b/packages/kit/package.json @@ -26,6 +26,7 @@ "kleur": "^4.1.5", "magic-string": "^0.30.5", "mrmime": "^2.0.0", + "pathe": "^1.1.2", "sade": "^1.8.1", "set-cookie-parser": "^2.6.0", "sirv": "^2.0.4", diff --git a/packages/kit/src/exports/vite/dev/index.js b/packages/kit/src/exports/vite/dev/index.js index 2be46c36ef52..178e3f9ef6e1 100644 --- a/packages/kit/src/exports/vite/dev/index.js +++ b/packages/kit/src/exports/vite/dev/index.js @@ -243,7 +243,7 @@ export async function dev(vite, vite_config, svelte_config, environment_context) ? async () => { const url = path.resolve(cwd, endpoint.file); return await loud_ssr_load_module(url); - } + } : null, endpoint_id: endpoint?.file }; diff --git a/packages/kit/src/exports/vite/dev/node_entrypoint.js b/packages/kit/src/exports/vite/dev/node_entrypoint.js index 40299dec402f..7600fc219da8 100644 --- a/packages/kit/src/exports/vite/dev/node_entrypoint.js +++ b/packages/kit/src/exports/vite/dev/node_entrypoint.js @@ -1,9 +1,9 @@ import { Server } from '../../../runtime/server/index.js'; +const environment_context = await import('__sveltekit/environment_context'); + export default { fetch: /** @param {Request} request **/ async (request) => { - const environment_context = await import('__sveltekit/environment_context'); - const server = new Server(environment_context.manifest); await server.init({ diff --git a/packages/kit/src/exports/vite/dev/utils.js b/packages/kit/src/exports/vite/dev/utils.js new file mode 100644 index 000000000000..983b85075015 --- /dev/null +++ b/packages/kit/src/exports/vite/dev/utils.js @@ -0,0 +1,18 @@ +import * as pathe from 'pathe'; + +const cwd = process.cwd(); + +/** @param {string} url */ +export async function loud_ssr_load_module(url) { + return await import(/* @vite-ignore */ url); +} + +/** @param {string} id */ +export async function resolve(id) { + // use to_fs? + const url = id.startsWith('..') ? pathe.resolve(cwd, id) : `/${id}`; + + const module = await loud_ssr_load_module(url); + + return { module, url }; +} diff --git a/packages/kit/src/exports/vite/index.js b/packages/kit/src/exports/vite/index.js index b7dc86ad3ade..0001ea439681 100644 --- a/packages/kit/src/exports/vite/index.js +++ b/packages/kit/src/exports/vite/index.js @@ -3,6 +3,7 @@ import path from 'node:path'; import colors from 'kleur'; +import { compact } from '../../utils/array.js'; import { copy, mkdirp, @@ -525,145 +526,128 @@ async function kit({ svelte_config }) { const { manifest_data, env, remote_address } = environment_context; const manifest = dedent` - import path from 'node:path'; - import fs from 'node:fs'; - import { to_fs, from_fs } from '../../packages/kit/src/utils/filesystem.js'; - import { compact } from '../../packages/kit/src/utils/array.js'; - - export const cwd = process.cwd(); - - async function loud_ssr_load_module(url) { - return await import(/* @vite-ignore */ url); - } - - async function resolve(id) { - const url = id.startsWith('..') ? to_fs(path.posix.resolve(id)) : \`/\${id}\`; - - const module = await loud_ssr_load_module(url); - - return { module, url }; - } - - export let manifest = { - appDir: ${s(svelte_config.kit.appDir)}, - appPath: ${s(svelte_config.kit.appDir)}, - assets: new Set(${s(manifest_data.assets.map((asset) => asset.file))}), - mimeTypes: ${s(get_mime_lookup(manifest_data))}, - _: { - client: { - start: ${s(`${runtime_base}/client/entry.js`)}, - app: ${s(`${to_fs(svelte_config.kit.outDir)}/generated/client/app.js`)}, - imports: [], - stylesheets: [], - fonts: [], - uses_env_dynamic_public: true - }, - server_assets: {}, - nodes: [ - ${manifest_data.nodes - .map((node, i) => { - const index = s(i); - const component = s(node.component); - const universal = s(node.universal); - const server = s(node.server); - - return dedent` - async () => { - /** @type {import('types').SSRNode} */ - const result = {}; - - /** @type {import('vite').ModuleNode[]} */ - const module_nodes = []; - - result.index = ${index}; - - // these are unused in dev, it's easier to include them - result.imports = []; - result.stylesheets = []; - result.fonts = []; - - if (${component}) { - result.component = async () => { - const { module } = await resolve(${component}); - } + import * as path from 'path'; + import { loud_ssr_load_module, resolve } from '../../packages/kit/src/exports/vite/dev/utils.js' + + export let manifest = { + appDir: ${s(svelte_config.kit.appDir)}, + appPath: ${s(svelte_config.kit.appDir)}, + assets: new Set(${s(manifest_data.assets.map((asset) => asset.file))}), + mimeTypes: ${s(get_mime_lookup(manifest_data))}, + _: { + client: { + start: ${s(`${runtime_base}/client/entry.js`)}, + app: ${s(`${to_fs(svelte_config.kit.outDir)}/generated/client/app.js`)}, + imports: [], + stylesheets: [], + fonts: [], + uses_env_dynamic_public: true + }, + server_assets: {}, + nodes: [ + ${manifest_data.nodes + .map((node, i) => { + const index = s(i); + const component = s(node.component); + const universal = s(node.universal); + const server = s(node.server); + + return dedent` + async () => { + /** @type {import('types').SSRNode} */ + const result = {}; + + /** @type {import('vite').ModuleNode[]} */ + const module_nodes = []; + + result.index = ${index}; + + // these are unused in dev, it's easier to include them + result.imports = []; + result.stylesheets = []; + result.fonts = []; + + if (${component}) { + result.component = async () => { + const { module } = await resolve(${component}); } + } - if (${universal}) { - const { module } = await resolve(${universal}); - - result.universal = module; - result.universal_id = ${universal}; - } - - if (${server}) { - const { module } = await resolve(${server}); + if (${universal}) { + const { module } = await resolve(${universal}); - result.server = module; - result.server_id = ${server}; - } + result.universal = module; + result.universal_id = ${universal}; + } + + if (${server}) { + const { module } = await resolve(${server}); - return result; + result.server = module; + result.server_id = ${server}; } - `; - }) - .join(',\n')} - ], - routes: [ - ${manifest_data.routes - .map((route) => { - if (!route.page && !route.endpoint) return; - - const endpoint = route.endpoint; - - return dedent` + + return result; + } + `; + }) + .join(',\n')} + ], + routes: [ + ${compact( + manifest_data.routes.map((route) => { + if (!route.page && !route.endpoint) return; + + const endpoint = route.endpoint; + + return dedent` { - id: ${s(route.id)}, + id: ${s(route.id)}, pattern: ${route.pattern}, params: ${s(route.params)}, page: ${s(route.page)}, - endpoint: ${s( + endpoint: ${ endpoint ? ` async () => { - const url = path.resolve(cwd, endpoint.file); + const url = path.resolve(process.cwd(), ${s(endpoint.file)}); return await loud_ssr_load_module(url); } ` : 'null' - )} + }, + endpoint_id: ${s(endpoint?.file)} } - `; - }) - .filter(Boolean) - .join(',\n')} - ], - matchers: async () => { - /** @type {Record} */ - const matchers = {}; - - for (const key in ${s(manifest_data.matchers)}) { - const file = ${s(manifest_data.matchers)}[key]; - const url = path.resolve(cwd, file); - const module = await import(/* @vite-ignore */ url); - - if (module.match) { - matchers[key] = module.match; - } else { - throw new Error(\`\${file} does not export a 'match' function\`); - } + `; + }) + ).join(',\n')} + ], + matchers: async () => { + /** @type {Record} */ + const matchers = {}; + + for (const [key, file] of ${s(Object.entries(manifest_data.matchers))}) { + const url = path.resolve(cwd, file); + const module = await import(/* @vite-ignore */ url); + + if (module.match) { + matchers[key] = module.match; + } else { + throw new Error(\`\${file} does not export a 'match' function\`); } - - return matchers; } + + return matchers; } - }; + } + }; - export let env = ${s(env)} + export let env = ${s(env)} - export let remote_address = ${s(remote_address)} + export let remote_address = ${s(remote_address)} - export let assets_directory = ${s(svelte_config.kit.files.assets)} - `; + export let assets_directory = ${s(svelte_config.kit.files.assets)} + `; return manifest; diff --git a/playgrounds/vite-node-environment/src/routes/+page.server.ts b/playgrounds/vite-node-environment/src/routes/+page.server.ts index 0e9996e8120e..80ef8437e1cd 100644 --- a/playgrounds/vite-node-environment/src/routes/+page.server.ts +++ b/playgrounds/vite-node-environment/src/routes/+page.server.ts @@ -9,7 +9,7 @@ function getUserAgentText(): string { } } -export const load: PageServerLoad = () => { +export const load: PageServerLoad = async () => { return { userAgentText: getUserAgentText() }; }; diff --git a/playgrounds/vite-node-environment/src/routes/+page.svelte b/playgrounds/vite-node-environment/src/routes/+page.svelte index 8a71c359751b..7660db3268cb 100644 --- a/playgrounds/vite-node-environment/src/routes/+page.svelte +++ b/playgrounds/vite-node-environment/src/routes/+page.svelte @@ -11,4 +11,10 @@ -
\ No newline at end of file + + + \ No newline at end of file diff --git a/playgrounds/vite-node-environment/src/routes/about/+page.svelte b/playgrounds/vite-node-environment/src/routes/about/+page.svelte index 7d877fdd78f3..438da7994cea 100644 --- a/playgrounds/vite-node-environment/src/routes/about/+page.svelte +++ b/playgrounds/vite-node-environment/src/routes/about/+page.svelte @@ -1 +1,7 @@ -

About

\ No newline at end of file +

About

+ + \ No newline at end of file diff --git a/playgrounds/vite-node-environment/src/routes/endpoint/+server.ts b/playgrounds/vite-node-environment/src/routes/endpoint/+server.ts new file mode 100644 index 000000000000..6e88328e1cff --- /dev/null +++ b/playgrounds/vite-node-environment/src/routes/endpoint/+server.ts @@ -0,0 +1,13 @@ +import { error } from '@sveltejs/kit'; +import type { RequestHandler } from './$types'; + +export const GET: RequestHandler = ({ url }) => { + const min = Number(url.searchParams.get('min') ?? '0'); + const max = Number(url.searchParams.get('max') ?? '1'); + const d = max - min; + if (isNaN(d) || d < 0) { + error(400, 'min and max must be numbers, and min must be less than max'); + } + const random = min + Math.random() * d; + return new Response(String(random)); +}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 097d0e0a13d2..c359ea47a3d4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -428,6 +428,9 @@ importers: mrmime: specifier: ^2.0.0 version: 2.0.0 + pathe: + specifier: ^1.1.2 + version: 1.1.2 sade: specifier: ^1.8.1 version: 1.8.1 From 0e6185322623c62c35136cd879a7d44be0ea0da2 Mon Sep 17 00:00:00 2001 From: James Opstad Date: Wed, 28 Aug 2024 13:03:37 +0100 Subject: [PATCH 09/61] Fixed support for endpoints --- packages/kit/src/exports/vite/dev/utils.js | 19 ++++++++++--------- packages/kit/src/exports/vite/index.js | 9 ++++++--- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/packages/kit/src/exports/vite/dev/utils.js b/packages/kit/src/exports/vite/dev/utils.js index 983b85075015..0eafd09fac8e 100644 --- a/packages/kit/src/exports/vite/dev/utils.js +++ b/packages/kit/src/exports/vite/dev/utils.js @@ -1,18 +1,19 @@ import * as pathe from 'pathe'; -const cwd = process.cwd(); - /** @param {string} url */ -export async function loud_ssr_load_module(url) { +async function loud_ssr_load_module(url) { return await import(/* @vite-ignore */ url); } -/** @param {string} id */ -export async function resolve(id) { - // use to_fs? - const url = id.startsWith('..') ? pathe.resolve(cwd, id) : `/${id}`; +/** @param {string} cwd */ +export function create_resolve(cwd) { + /** @param {string} id */ + return async function resolve(id) { + // use to_fs? + const url = id.startsWith('..') ? pathe.resolve(cwd, id) : `/${id}`; - const module = await loud_ssr_load_module(url); + const module = await loud_ssr_load_module(url); - return { module, url }; + return { module, url }; + }; } diff --git a/packages/kit/src/exports/vite/index.js b/packages/kit/src/exports/vite/index.js index 0001ea439681..3d5f08471969 100644 --- a/packages/kit/src/exports/vite/index.js +++ b/packages/kit/src/exports/vite/index.js @@ -527,7 +527,9 @@ async function kit({ svelte_config }) { const manifest = dedent` import * as path from 'path'; - import { loud_ssr_load_module, resolve } from '../../packages/kit/src/exports/vite/dev/utils.js' + import { loud_ssr_load_module, create_resolve } from '../../packages/kit/src/exports/vite/dev/utils.js' + + const resolve = create_resolve(${s(cwd)}) export let manifest = { appDir: ${s(svelte_config.kit.appDir)}, @@ -610,8 +612,9 @@ async function kit({ svelte_config }) { endpoint ? ` async () => { - const url = path.resolve(process.cwd(), ${s(endpoint.file)}); - return await loud_ssr_load_module(url); + const { module } = await resolve(${s(endpoint.file)}); + + return module; } ` : 'null' From 63135161b01903d227193ccb0b7ac29433671f0a Mon Sep 17 00:00:00 2001 From: James Opstad Date: Wed, 28 Aug 2024 13:13:30 +0100 Subject: [PATCH 10/61] Added links to playground example --- packages/kit/src/exports/vite/dev/index.js | 5 +++++ packages/kit/src/exports/vite/index.js | 3 +-- playgrounds/vite-node-environment/src/routes/+page.svelte | 7 +++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/kit/src/exports/vite/dev/index.js b/packages/kit/src/exports/vite/dev/index.js index 178e3f9ef6e1..f162b2f7af26 100644 --- a/packages/kit/src/exports/vite/dev/index.js +++ b/packages/kit/src/exports/vite/dev/index.js @@ -537,6 +537,11 @@ export async function dev(vite, vite_config, svelte_config, environment_context) const rendered = await handler(request); + fs.writeFileSync( + '/Users/jopstad/Desktop/module_keys_2.json', + JSON.stringify([...module_runner.moduleCache.keys()]) + ); + // const rendered = await server.respond(request, { // getClientAddress: () => { // const { remoteAddress } = req.socket; diff --git a/packages/kit/src/exports/vite/index.js b/packages/kit/src/exports/vite/index.js index 3d5f08471969..995e3b1e4e7d 100644 --- a/packages/kit/src/exports/vite/index.js +++ b/packages/kit/src/exports/vite/index.js @@ -526,8 +526,7 @@ async function kit({ svelte_config }) { const { manifest_data, env, remote_address } = environment_context; const manifest = dedent` - import * as path from 'path'; - import { loud_ssr_load_module, create_resolve } from '../../packages/kit/src/exports/vite/dev/utils.js' + import { create_resolve } from '../../packages/kit/src/exports/vite/dev/utils.js' const resolve = create_resolve(${s(cwd)}) diff --git a/playgrounds/vite-node-environment/src/routes/+page.svelte b/playgrounds/vite-node-environment/src/routes/+page.svelte index 7660db3268cb..c9a30339ad14 100644 --- a/playgrounds/vite-node-environment/src/routes/+page.svelte +++ b/playgrounds/vite-node-environment/src/routes/+page.svelte @@ -6,6 +6,13 @@

Svelte Kit with Vite Node Environment

+

{data.userAgentText}

From 04efeec50a5685ff19579111badc31cae54bb78f Mon Sep 17 00:00:00 2001 From: James Opstad Date: Wed, 28 Aug 2024 13:50:52 +0100 Subject: [PATCH 11/61] Removed commented code --- packages/kit/src/exports/vite/dev/index.js | 5 - packages/kit/src/exports/vite/index.js | 189 +++------------------ 2 files changed, 27 insertions(+), 167 deletions(-) diff --git a/packages/kit/src/exports/vite/dev/index.js b/packages/kit/src/exports/vite/dev/index.js index f162b2f7af26..178e3f9ef6e1 100644 --- a/packages/kit/src/exports/vite/dev/index.js +++ b/packages/kit/src/exports/vite/dev/index.js @@ -537,11 +537,6 @@ export async function dev(vite, vite_config, svelte_config, environment_context) const rendered = await handler(request); - fs.writeFileSync( - '/Users/jopstad/Desktop/module_keys_2.json', - JSON.stringify([...module_runner.moduleCache.keys()]) - ); - // const rendered = await server.respond(request, { // getClientAddress: () => { // const { remoteAddress } = req.socket; diff --git a/packages/kit/src/exports/vite/index.js b/packages/kit/src/exports/vite/index.js index 995e3b1e4e7d..cebeb4d21098 100644 --- a/packages/kit/src/exports/vite/index.js +++ b/packages/kit/src/exports/vite/index.js @@ -554,42 +554,42 @@ async function kit({ svelte_config }) { const server = s(node.server); return dedent` - async () => { - /** @type {import('types').SSRNode} */ - const result = {}; + async () => { + /** @type {import('types').SSRNode} */ + const result = {}; - /** @type {import('vite').ModuleNode[]} */ - const module_nodes = []; + /** @type {import('vite').ModuleNode[]} */ + const module_nodes = []; - result.index = ${index}; + result.index = ${index}; - // these are unused in dev, it's easier to include them - result.imports = []; - result.stylesheets = []; - result.fonts = []; + // these are unused in dev, it's easier to include them + result.imports = []; + result.stylesheets = []; + result.fonts = []; - if (${component}) { - result.component = async () => { - const { module } = await resolve(${component}); + if (${component}) { + result.component = async () => { + const { module } = await resolve(${component}); + } } - } - if (${universal}) { - const { module } = await resolve(${universal}); + if (${universal}) { + const { module } = await resolve(${universal}); - result.universal = module; - result.universal_id = ${universal}; - } - - if (${server}) { - const { module } = await resolve(${server}); + result.universal = module; + result.universal_id = ${universal}; + } + + if (${server}) { + const { module } = await resolve(${server}); - result.server = module; - result.server_id = ${server}; - } + result.server = module; + result.server_id = ${server}; + } - return result; - } + return result; + } `; }) .join(',\n')} @@ -652,141 +652,6 @@ async function kit({ svelte_config }) { `; return manifest; - - // return dedent` - // import path from 'node:path'; - // import fs from 'node:fs'; - // import { to_fs, from_fs } from '../../packages/kit/src/utils/filesystem.js'; - // import { compact } from '../../packages/kit/src/utils/array.js'; - - // export const cwd = process.cwd(); - - // async function loud_ssr_load_module(url) { - // return await import(/* @vite-ignore */ url); - // } - - // async function resolve(id) { - // const url = id.startsWith('..') ? to_fs(path.posix.resolve(id)) : \`/\${id}\`; - - // const module = await loud_ssr_load_module(url); - - // return { module, url }; - // } - - // export let manifest = { - // appDir: ${s(svelte_config.kit.appDir)}, - // appPath: ${s(svelte_config.kit.appDir)}, - // assets: new Set(${s(manifest_data.assets.map((asset) => asset.file))}), - // mimeTypes: ${s(get_mime_lookup(manifest_data))}, - // _: { - // client: { - // start: ${s(`${runtime_base}/client/entry.js`)}, - // app: ${s(`${to_fs(svelte_config.kit.outDir)}/generated/client/app.js`)}, - // imports: [], - // stylesheets: [], - // fonts: [], - // uses_env_dynamic_public: true - // }, - // server_assets: {}, - // nodes: ${s(manifest_data.nodes, (key, value) => { - // if (['depth', 'parent_id', 'parent', 'child_pages'].includes(key)) return; - // return value; - // })}.map((node, index) => { - // return async () => { - // /** @type {import('types').SSRNode} */ - // const result = {}; - - // /** @type {import('vite').ModuleNode[]} */ - // const module_nodes = []; - - // result.index = index; - - // // these are unused in dev, it's easier to include them - // result.imports = []; - // result.stylesheets = []; - // result.fonts = []; - - // if (node.component) { - // result.component = async () => { - // const { module } = await resolve( - // /** @type {string} */ (node.component) - // ); - - // return module.default; - // }; - // } - - // if (node.universal) { - // const { module } = await resolve(node.universal); - - // result.universal = module; - // result.universal_id = node.universal; - // } - - // if (node.server) { - // const { module } = await resolve(node.server); - - // result.server = module; - // result.server_id = node.server; - // } - - // return result; - // }; - // }), - // routes: compact( - // ${s(manifest_data.routes, (key, value) => { - // if (['parent'].includes(key)) return; - - // if (key === 'pattern') return value.toString(); - - // return value; - // })}.map((route) => { - // if (!route.page && !route.endpoint) return null; - - // const endpoint = route.endpoint; - - // return { - // id: route.id, - // pattern: /^\\/$/, - // params: route.params, - // page: route.page, - // endpoint: endpoint - // ? async () => { - // const url = path.resolve(cwd, endpoint.file); - // return await loud_ssr_load_module(url); - // } - // : null, - // endpoint_id: endpoint?.file - // }; - // }) - // ), - // matchers: async () => { - // /** @type {Record} */ - // const matchers = {}; - - // for (const key in ${s(manifest_data.matchers)}) { - // const file = ${s(manifest_data.matchers)}[key]; - // const url = path.resolve(cwd, file); - // const module = await import(/* @vite-ignore */ url); - - // if (module.match) { - // matchers[key] = module.match; - // } else { - // throw new Error(\`\${file} does not export a 'match' function\`); - // } - // } - - // return matchers; - // } - // } - // }; - - // export let env = ${s(env)} - - // export let remote_address = ${s(remote_address)} - - // export let assets_directory = ${s(svelte_config.kit.files.assets)} - // `; } } } From 47d037980a389e0cfce841be58f1ad3dfa756ad2 Mon Sep 17 00:00:00 2001 From: James Opstad Date: Wed, 28 Aug 2024 14:04:16 +0100 Subject: [PATCH 12/61] Used Cloudflare plugin to run in workerd environment --- packages/kit/src/exports/vite/dev/index.js | 13 +++++++++-- .../src/exports/vite/dev/node_entrypoint.js | 6 +++-- .../exports/vite/dev/workerd__entrypoint.js | 5 ---- .../exports/vite/dev/workerd_entrypoint.js | 23 +++++++++++++++++++ .../src/routes/+page.server.ts | 2 +- .../src/routes/+page.server.ts | 6 ++--- .../src/routes/+page.svelte | 15 +++++++++++- .../src/routes/about/+page.svelte | 7 ++++++ .../src/routes/endpoint/+server.ts | 13 +++++++++++ 9 files changed, 76 insertions(+), 14 deletions(-) delete mode 100644 packages/kit/src/exports/vite/dev/workerd__entrypoint.js create mode 100644 packages/kit/src/exports/vite/dev/workerd_entrypoint.js create mode 100644 playgrounds/vite-workerd-environment/src/routes/about/+page.svelte create mode 100644 playgrounds/vite-workerd-environment/src/routes/endpoint/+server.ts diff --git a/packages/kit/src/exports/vite/dev/index.js b/packages/kit/src/exports/vite/dev/index.js index 178e3f9ef6e1..5714f93225e8 100644 --- a/packages/kit/src/exports/vite/dev/index.js +++ b/packages/kit/src/exports/vite/dev/index.js @@ -531,9 +531,18 @@ export async function dev(vite, vite_config, svelte_config, environment_context) environment_context.env = env; environment_context.remote_address = req.socket.remoteAddress; + const devEnv = vite.environments['vite-plugin-cloudflare-workerd-env']; + + if (!devEnv) { + throw new Error('No Cloudflare dev environment is present'); + } + const __dirname = fileURLToPath(new URL('.', import.meta.url)); - const entrypoint = await module_runner.import(path.join(__dirname, 'node_entrypoint.js')); - const handler = entrypoint.default.fetch; + // const entrypoint = await module_runner.import(path.join(__dirname, 'node_entrypoint.js')); + // const handler = entrypoint.default.fetch; + const handler = await devEnv.api.getHandler({ + entrypoint: path.join(__dirname, 'workerd_entrypoint.js') + }); const rendered = await handler(request); diff --git a/packages/kit/src/exports/vite/dev/node_entrypoint.js b/packages/kit/src/exports/vite/dev/node_entrypoint.js index 7600fc219da8..0e80e5b2fa01 100644 --- a/packages/kit/src/exports/vite/dev/node_entrypoint.js +++ b/packages/kit/src/exports/vite/dev/node_entrypoint.js @@ -12,9 +12,11 @@ export default { return server.respond(request, { getClientAddress: () => { - if (environment_context.remote_address) return environment_context.remote_address; + if (!environment_context.remote_address) { + throw new Error('Could not determine clientAddress'); + } - throw new Error('Could not determine clientAddress'); + return environment_context.remote_address; } }); } diff --git a/packages/kit/src/exports/vite/dev/workerd__entrypoint.js b/packages/kit/src/exports/vite/dev/workerd__entrypoint.js deleted file mode 100644 index e00177892667..000000000000 --- a/packages/kit/src/exports/vite/dev/workerd__entrypoint.js +++ /dev/null @@ -1,5 +0,0 @@ -export default { - fetch: () => { - return new Promise((resolve) => resolve(new Response('Hello from workerd'))); - } -}; diff --git a/packages/kit/src/exports/vite/dev/workerd_entrypoint.js b/packages/kit/src/exports/vite/dev/workerd_entrypoint.js new file mode 100644 index 000000000000..0e80e5b2fa01 --- /dev/null +++ b/packages/kit/src/exports/vite/dev/workerd_entrypoint.js @@ -0,0 +1,23 @@ +import { Server } from '../../../runtime/server/index.js'; + +const environment_context = await import('__sveltekit/environment_context'); + +export default { + fetch: /** @param {Request} request **/ async (request) => { + const server = new Server(environment_context.manifest); + + await server.init({ + env: environment_context.env + }); + + return server.respond(request, { + getClientAddress: () => { + if (!environment_context.remote_address) { + throw new Error('Could not determine clientAddress'); + } + + return environment_context.remote_address; + } + }); + } +}; diff --git a/playgrounds/vite-node-environment/src/routes/+page.server.ts b/playgrounds/vite-node-environment/src/routes/+page.server.ts index 80ef8437e1cd..0e9996e8120e 100644 --- a/playgrounds/vite-node-environment/src/routes/+page.server.ts +++ b/playgrounds/vite-node-environment/src/routes/+page.server.ts @@ -9,7 +9,7 @@ function getUserAgentText(): string { } } -export const load: PageServerLoad = async () => { +export const load: PageServerLoad = () => { return { userAgentText: getUserAgentText() }; }; diff --git a/playgrounds/vite-workerd-environment/src/routes/+page.server.ts b/playgrounds/vite-workerd-environment/src/routes/+page.server.ts index 7706a5990822..0e9996e8120e 100644 --- a/playgrounds/vite-workerd-environment/src/routes/+page.server.ts +++ b/playgrounds/vite-workerd-environment/src/routes/+page.server.ts @@ -1,4 +1,4 @@ -import type { Actions } from './$types'; +import type { Actions, PageServerLoad } from './$types'; function getUserAgentText(): string { if (typeof navigator === 'undefined') { @@ -9,9 +9,9 @@ function getUserAgentText(): string { } } -export function load() { +export const load: PageServerLoad = () => { return { userAgentText: getUserAgentText() }; -} +}; export const actions = { default: () => { diff --git a/playgrounds/vite-workerd-environment/src/routes/+page.svelte b/playgrounds/vite-workerd-environment/src/routes/+page.svelte index 030959917b57..34ca98c15f2e 100644 --- a/playgrounds/vite-workerd-environment/src/routes/+page.svelte +++ b/playgrounds/vite-workerd-environment/src/routes/+page.svelte @@ -6,9 +6,22 @@

Svelte Kit with Vite Workerd Environment

+

{data.userAgentText}

-
\ No newline at end of file +
+ + \ No newline at end of file diff --git a/playgrounds/vite-workerd-environment/src/routes/about/+page.svelte b/playgrounds/vite-workerd-environment/src/routes/about/+page.svelte new file mode 100644 index 000000000000..438da7994cea --- /dev/null +++ b/playgrounds/vite-workerd-environment/src/routes/about/+page.svelte @@ -0,0 +1,7 @@ +

About

+ + \ No newline at end of file diff --git a/playgrounds/vite-workerd-environment/src/routes/endpoint/+server.ts b/playgrounds/vite-workerd-environment/src/routes/endpoint/+server.ts new file mode 100644 index 000000000000..6e88328e1cff --- /dev/null +++ b/playgrounds/vite-workerd-environment/src/routes/endpoint/+server.ts @@ -0,0 +1,13 @@ +import { error } from '@sveltejs/kit'; +import type { RequestHandler } from './$types'; + +export const GET: RequestHandler = ({ url }) => { + const min = Number(url.searchParams.get('min') ?? '0'); + const max = Number(url.searchParams.get('max') ?? '1'); + const d = max - min; + if (isNaN(d) || d < 0) { + error(400, 'min and max must be numbers, and min must be less than max'); + } + const random = min + Math.random() * d; + return new Response(String(random)); +}; From 7dd8cedde5bf32c55c379e3c93e6ff2a1ff932c8 Mon Sep 17 00:00:00 2001 From: James Opstad Date: Wed, 28 Aug 2024 14:13:37 +0100 Subject: [PATCH 13/61] Added Cloudflare platform context --- .../src/exports/vite/dev/workerd_entrypoint.js | 15 +++++++++++++-- .../src/routes/+page.server.ts | 3 ++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/kit/src/exports/vite/dev/workerd_entrypoint.js b/packages/kit/src/exports/vite/dev/workerd_entrypoint.js index 0e80e5b2fa01..e476884514be 100644 --- a/packages/kit/src/exports/vite/dev/workerd_entrypoint.js +++ b/packages/kit/src/exports/vite/dev/workerd_entrypoint.js @@ -3,20 +3,31 @@ import { Server } from '../../../runtime/server/index.js'; const environment_context = await import('__sveltekit/environment_context'); export default { - fetch: /** @param {Request} request **/ async (request) => { + /** + * @param {Request & { cf: any }} req + * @param {any} env + * @param {any} ctx + */ + fetch: async (req, env, ctx) => { const server = new Server(environment_context.manifest); await server.init({ env: environment_context.env }); - return server.respond(request, { + return server.respond(req, { getClientAddress: () => { if (!environment_context.remote_address) { throw new Error('Could not determine clientAddress'); } return environment_context.remote_address; + }, + platform: { + env, + cf: req.cf, + ctx, + caches } }); } diff --git a/playgrounds/vite-workerd-environment/src/routes/+page.server.ts b/playgrounds/vite-workerd-environment/src/routes/+page.server.ts index 0e9996e8120e..3d7f75957ba8 100644 --- a/playgrounds/vite-workerd-environment/src/routes/+page.server.ts +++ b/playgrounds/vite-workerd-environment/src/routes/+page.server.ts @@ -9,7 +9,8 @@ function getUserAgentText(): string { } } -export const load: PageServerLoad = () => { +export const load: PageServerLoad = ({ platform }) => { + console.log(platform); return { userAgentText: getUserAgentText() }; }; From 483d1379e59d2fa31d9e2d6fae911fb8b568b657 Mon Sep 17 00:00:00 2001 From: James Opstad Date: Wed, 28 Aug 2024 14:51:14 +0100 Subject: [PATCH 14/61] Added cloudflare properties route to workerd playground --- .../src/routes/+page.server.ts | 3 +- .../src/routes/+page.svelte | 1 + .../cf-properties/[[key]]/+page.server.ts | 9 ++++++ .../routes/cf-properties/[[key]]/+page.svelte | 31 +++++++++++++++++++ 4 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 playgrounds/vite-workerd-environment/src/routes/cf-properties/[[key]]/+page.server.ts create mode 100644 playgrounds/vite-workerd-environment/src/routes/cf-properties/[[key]]/+page.svelte diff --git a/playgrounds/vite-workerd-environment/src/routes/+page.server.ts b/playgrounds/vite-workerd-environment/src/routes/+page.server.ts index 3d7f75957ba8..0e9996e8120e 100644 --- a/playgrounds/vite-workerd-environment/src/routes/+page.server.ts +++ b/playgrounds/vite-workerd-environment/src/routes/+page.server.ts @@ -9,8 +9,7 @@ function getUserAgentText(): string { } } -export const load: PageServerLoad = ({ platform }) => { - console.log(platform); +export const load: PageServerLoad = () => { return { userAgentText: getUserAgentText() }; }; diff --git a/playgrounds/vite-workerd-environment/src/routes/+page.svelte b/playgrounds/vite-workerd-environment/src/routes/+page.svelte index 34ca98c15f2e..4d97f823c0b1 100644 --- a/playgrounds/vite-workerd-environment/src/routes/+page.svelte +++ b/playgrounds/vite-workerd-environment/src/routes/+page.svelte @@ -10,6 +10,7 @@ diff --git a/playgrounds/vite-workerd-environment/src/routes/cf-properties/[[key]]/+page.server.ts b/playgrounds/vite-workerd-environment/src/routes/cf-properties/[[key]]/+page.server.ts new file mode 100644 index 000000000000..7deba359c363 --- /dev/null +++ b/playgrounds/vite-workerd-environment/src/routes/cf-properties/[[key]]/+page.server.ts @@ -0,0 +1,9 @@ +import type { PageServerLoad } from './$types'; + +export const load: PageServerLoad = ({ params, platform }) => { + const cf = platform.cf; + const key = params?.key; + const value = JSON.stringify(cf[key]); + + return { key, value: key && key in cf && value, keys: Object.keys(cf) }; +}; diff --git a/playgrounds/vite-workerd-environment/src/routes/cf-properties/[[key]]/+page.svelte b/playgrounds/vite-workerd-environment/src/routes/cf-properties/[[key]]/+page.svelte new file mode 100644 index 000000000000..38aba6fc871f --- /dev/null +++ b/playgrounds/vite-workerd-environment/src/routes/cf-properties/[[key]]/+page.svelte @@ -0,0 +1,31 @@ + + +
+ {#if data.key} + {#if data.value} +

Cloudflare property: {data.key}

+

Value: {data.value}

+ {:else} +

Cloudflare property '{data.key}' not found

+ {/if} +
+ {/if} +

Available Cloudflare properties:

+
    + {#each data.keys as key} +
  • {key}
  • + {/each} +
+
+ + \ No newline at end of file From 97489b2232e354196182c20194e72bc7e7a129d6 Mon Sep 17 00:00:00 2001 From: James Opstad Date: Wed, 28 Aug 2024 15:10:31 +0100 Subject: [PATCH 15/61] Added KV example --- .../src/routes/+page.server.ts | 24 +++++++++++++++---- .../src/routes/+page.svelte | 19 ++++++++++++--- .../routes/cf-properties/[[key]]/+page.svelte | 8 +------ 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/playgrounds/vite-workerd-environment/src/routes/+page.server.ts b/playgrounds/vite-workerd-environment/src/routes/+page.server.ts index 0e9996e8120e..3735645f8d05 100644 --- a/playgrounds/vite-workerd-environment/src/routes/+page.server.ts +++ b/playgrounds/vite-workerd-environment/src/routes/+page.server.ts @@ -9,12 +9,28 @@ function getUserAgentText(): string { } } -export const load: PageServerLoad = () => { - return { userAgentText: getUserAgentText() }; +const KEY = '__my-key__'; + +export const load: PageServerLoad = async ({ platform }) => { + const { MY_KV } = platform.env; + const value = await MY_KV.get(KEY); + + return { userAgentText: getUserAgentText(), value: value === 'null' ? null : value }; }; export const actions = { - default: () => { - console.log('\x1b[32m no-op action \x1b[0m'); + create: async ({ request, platform }) => { + const { MY_KV } = platform.env; + const formData = await request.formData(); + const value = formData.get('value') as string; + await MY_KV.put(KEY, value); + + return null; + }, + delete: async ({ platform }) => { + const { MY_KV } = platform.env; + await MY_KV.delete(KEY); + + return null; } } satisfies Actions; diff --git a/playgrounds/vite-workerd-environment/src/routes/+page.svelte b/playgrounds/vite-workerd-environment/src/routes/+page.svelte index 4d97f823c0b1..2165d73cc121 100644 --- a/playgrounds/vite-workerd-environment/src/routes/+page.svelte +++ b/playgrounds/vite-workerd-environment/src/routes/+page.svelte @@ -16,9 +16,22 @@

{data.userAgentText}

-
- -
+
+

KV example

+ {#if data.value} +

Value: {data.value}

+
+ +
+ {:else} +

No value

+
+ + +
+ +
+ {/if} \ No newline at end of file + \ No newline at end of file From e50f543fc2642e86d17a937f5ace2afb11a1b119 Mon Sep 17 00:00:00 2001 From: James Opstad Date: Wed, 28 Aug 2024 17:40:21 +0100 Subject: [PATCH 16/61] Added matchers example to workerd playground --- packages/kit/src/exports/vite/index.js | 5 +++-- .../vite-workerd-environment/src/params/fruit.ts | 3 +++ .../src/routes/+page.svelte | 1 + .../routes/matchers/[page=fruit]/+page.svelte | 16 ++++++++++++++++ 4 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 playgrounds/vite-workerd-environment/src/params/fruit.ts create mode 100644 playgrounds/vite-workerd-environment/src/routes/matchers/[page=fruit]/+page.svelte diff --git a/packages/kit/src/exports/vite/index.js b/packages/kit/src/exports/vite/index.js index cebeb4d21098..b3479f1139df 100644 --- a/packages/kit/src/exports/vite/index.js +++ b/packages/kit/src/exports/vite/index.js @@ -629,8 +629,9 @@ async function kit({ svelte_config }) { const matchers = {}; for (const [key, file] of ${s(Object.entries(manifest_data.matchers))}) { - const url = path.resolve(cwd, file); - const module = await import(/* @vite-ignore */ url); + // const url = path.resolve(cwd, file); + // const module = await import(/* @vite-ignore */ url); + const { module } = await resolve(file); if (module.match) { matchers[key] = module.match; diff --git a/playgrounds/vite-workerd-environment/src/params/fruit.ts b/playgrounds/vite-workerd-environment/src/params/fruit.ts new file mode 100644 index 000000000000..dceeb7da08d9 --- /dev/null +++ b/playgrounds/vite-workerd-environment/src/params/fruit.ts @@ -0,0 +1,3 @@ +export function match(param: string) { + return param === 'apple' || param === 'orange'; +} diff --git a/playgrounds/vite-workerd-environment/src/routes/+page.svelte b/playgrounds/vite-workerd-environment/src/routes/+page.svelte index 2165d73cc121..277d3a26904c 100644 --- a/playgrounds/vite-workerd-environment/src/routes/+page.svelte +++ b/playgrounds/vite-workerd-environment/src/routes/+page.svelte @@ -12,6 +12,7 @@
  • About
  • Cloudflare Properties
  • Endpoint
  • +
  • Matchers

  • diff --git a/playgrounds/vite-workerd-environment/src/routes/matchers/[page=fruit]/+page.svelte b/playgrounds/vite-workerd-environment/src/routes/matchers/[page=fruit]/+page.svelte new file mode 100644 index 000000000000..f5d570567a32 --- /dev/null +++ b/playgrounds/vite-workerd-environment/src/routes/matchers/[page=fruit]/+page.svelte @@ -0,0 +1,16 @@ + + +

    {$page.params.page}

    + + + \ No newline at end of file From c7484d014cf2842515e5a48efa13664c80055cab Mon Sep 17 00:00:00 2001 From: James Opstad Date: Thu, 29 Aug 2024 11:44:01 +0100 Subject: [PATCH 17/61] Added layout and improved playground example --- .../vite-workerd-environment/src/app.d.ts | 5 +++- .../src/routes/+layout.svelte | 20 +++++++++++++ .../src/routes/+page.server.ts | 11 ++++--- .../src/routes/+page.svelte | 30 ++++--------------- .../src/routes/about/+page.svelte | 4 +-- .../cf-properties/[[key]]/+page.server.ts | 10 +++---- .../routes/cf-properties/[[key]]/+page.svelte | 5 ++-- .../src/routes/endpoint/+server.ts | 7 +++-- 8 files changed, 47 insertions(+), 45 deletions(-) create mode 100644 playgrounds/vite-workerd-environment/src/routes/+layout.svelte diff --git a/playgrounds/vite-workerd-environment/src/app.d.ts b/playgrounds/vite-workerd-environment/src/app.d.ts index f59b884c51ed..237626ef7f0b 100644 --- a/playgrounds/vite-workerd-environment/src/app.d.ts +++ b/playgrounds/vite-workerd-environment/src/app.d.ts @@ -5,7 +5,10 @@ declare global { // interface Error {} // interface Locals {} // interface PageData {} - // interface Platform {} + interface Platform { + cf: any; + env: any; + } } } diff --git a/playgrounds/vite-workerd-environment/src/routes/+layout.svelte b/playgrounds/vite-workerd-environment/src/routes/+layout.svelte new file mode 100644 index 000000000000..6c0ef5150b94 --- /dev/null +++ b/playgrounds/vite-workerd-environment/src/routes/+layout.svelte @@ -0,0 +1,20 @@ +
    +

    Svelte Kit with Vite Workerd Environment

    + +
    +
    + + + \ No newline at end of file diff --git a/playgrounds/vite-workerd-environment/src/routes/+page.server.ts b/playgrounds/vite-workerd-environment/src/routes/+page.server.ts index 3735645f8d05..4b9e76060c47 100644 --- a/playgrounds/vite-workerd-environment/src/routes/+page.server.ts +++ b/playgrounds/vite-workerd-environment/src/routes/+page.server.ts @@ -1,22 +1,21 @@ -import type { Actions, PageServerLoad } from './$types'; +import type { Actions, PageServerLoadEvent } from './$types'; function getUserAgentText(): string { if (typeof navigator === 'undefined') { return 'navigator is undefined (running in Node.js?)'; - } else { - const userAgent = navigator.userAgent; - return `navigator.userAgent = ${userAgent}`; } + + return `navigator.userAgent = ${navigator.userAgent}`; } const KEY = '__my-key__'; -export const load: PageServerLoad = async ({ platform }) => { +export async function load({ platform }: PageServerLoadEvent) { const { MY_KV } = platform.env; const value = await MY_KV.get(KEY); return { userAgentText: getUserAgentText(), value: value === 'null' ? null : value }; -}; +} export const actions = { create: async ({ request, platform }) => { diff --git a/playgrounds/vite-workerd-environment/src/routes/+page.svelte b/playgrounds/vite-workerd-environment/src/routes/+page.svelte index 277d3a26904c..3ec070f39b91 100644 --- a/playgrounds/vite-workerd-environment/src/routes/+page.svelte +++ b/playgrounds/vite-workerd-environment/src/routes/+page.svelte @@ -1,42 +1,22 @@ -
    -

    Svelte Kit with Vite Workerd Environment

    - -
    +

    {data.userAgentText}

    -
    -

    KV example

    +

    KV example:

    {#if data.value} -

    Value: {data.value}

    +

    Value: {data.value}

    {:else} -

    No value

    -
    {/if} -
    - - \ No newline at end of file + \ No newline at end of file diff --git a/playgrounds/vite-workerd-environment/src/routes/about/+page.svelte b/playgrounds/vite-workerd-environment/src/routes/about/+page.svelte index 438da7994cea..3cd438d637fb 100644 --- a/playgrounds/vite-workerd-environment/src/routes/about/+page.svelte +++ b/playgrounds/vite-workerd-environment/src/routes/about/+page.svelte @@ -1,7 +1,7 @@ -

    About

    +

    About

    \ No newline at end of file diff --git a/playgrounds/vite-workerd-environment/src/routes/cf-properties/[[key]]/+page.server.ts b/playgrounds/vite-workerd-environment/src/routes/cf-properties/[[key]]/+page.server.ts index 7deba359c363..71627c7511a9 100644 --- a/playgrounds/vite-workerd-environment/src/routes/cf-properties/[[key]]/+page.server.ts +++ b/playgrounds/vite-workerd-environment/src/routes/cf-properties/[[key]]/+page.server.ts @@ -1,9 +1,9 @@ -import type { PageServerLoad } from './$types'; +import type { PageServerLoadEvent } from './$types'; -export const load: PageServerLoad = ({ params, platform }) => { +export function load({ params, platform }: PageServerLoadEvent) { const cf = platform.cf; const key = params?.key; - const value = JSON.stringify(cf[key]); + const value = key && key in cf && JSON.stringify(cf[key]); - return { key, value: key && key in cf && value, keys: Object.keys(cf) }; -}; + return { key, value, keys: Object.keys(cf) }; +} diff --git a/playgrounds/vite-workerd-environment/src/routes/cf-properties/[[key]]/+page.svelte b/playgrounds/vite-workerd-environment/src/routes/cf-properties/[[key]]/+page.svelte index bfc39fd76fe8..2041bb671e17 100644 --- a/playgrounds/vite-workerd-environment/src/routes/cf-properties/[[key]]/+page.svelte +++ b/playgrounds/vite-workerd-environment/src/routes/cf-properties/[[key]]/+page.svelte @@ -10,13 +10,12 @@ {#if data.key} {#if data.value}

    Cloudflare property: {data.key}

    -

    Value: {data.value}

    +

    Value: {data.value}

    {:else}

    Cloudflare property '{data.key}' not found

    {/if} -
    {/if} -

    Available Cloudflare properties:

    +

    Available Cloudflare properties:

      {#each data.keys as key}
    • {key}
    • diff --git a/playgrounds/vite-workerd-environment/src/routes/endpoint/+server.ts b/playgrounds/vite-workerd-environment/src/routes/endpoint/+server.ts index 6e88328e1cff..8ba35ce74030 100644 --- a/playgrounds/vite-workerd-environment/src/routes/endpoint/+server.ts +++ b/playgrounds/vite-workerd-environment/src/routes/endpoint/+server.ts @@ -1,7 +1,7 @@ import { error } from '@sveltejs/kit'; -import type { RequestHandler } from './$types'; +import type { RequestEvent } from './$types'; -export const GET: RequestHandler = ({ url }) => { +export function GET({ url }: RequestEvent) { const min = Number(url.searchParams.get('min') ?? '0'); const max = Number(url.searchParams.get('max') ?? '1'); const d = max - min; @@ -9,5 +9,6 @@ export const GET: RequestHandler = ({ url }) => { error(400, 'min and max must be numbers, and min must be less than max'); } const random = min + Math.random() * d; + return new Response(String(random)); -}; +} From a356404268af5190701d02bfef7cbf8923cba353 Mon Sep 17 00:00:00 2001 From: James Opstad Date: Thu, 29 Aug 2024 12:58:10 +0100 Subject: [PATCH 18/61] Commented out unused code and added invalidation for environment_context virtual module --- packages/kit/src/exports/vite/dev/index.js | 407 +++++++++--------- .../exports/vite/dev/workerd_entrypoint.js | 3 +- packages/kit/src/exports/vite/index.js | 2 +- packages/kit/src/types/ambient-private.d.ts | 1 - packages/kit/src/types/internal.d.ts | 6 + 5 files changed, 218 insertions(+), 201 deletions(-) diff --git a/packages/kit/src/exports/vite/dev/index.js b/packages/kit/src/exports/vite/dev/index.js index 5714f93225e8..2519c967ade0 100644 --- a/packages/kit/src/exports/vite/dev/index.js +++ b/packages/kit/src/exports/vite/dev/index.js @@ -17,14 +17,15 @@ import { compact } from '../../../utils/array.js'; import { not_found } from '../utils.js'; import { SCHEME } from '../../../utils/url.js'; import { check_feature } from '../../../utils/features.js'; +import { sveltekit_environment_context } from '../module_ids.js'; -const cwd = process.cwd(); +// const cwd = process.cwd(); /** * @param {import('vite').ViteDevServer} vite * @param {import('vite').ResolvedConfig} vite_config * @param {import('types').ValidatedConfig} svelte_config - * @param {any} environment_context + * @param {import('types').EnvironmentContext} environment_context * @return {Promise void>>} */ export async function dev(vite, vite_config, svelte_config, environment_context) { @@ -52,58 +53,72 @@ export async function dev(vite, vite_config, svelte_config, environment_context) sync.init(svelte_config, vite_config.mode); - /** @type {import('types').ManifestData} */ - let manifest_data; - /** @type {import('@sveltejs/kit').SSRManifest} */ - let manifest; + // /** @type {import('types').ManifestData} */ + // let manifest_data; + // /** @type {import('@sveltejs/kit').SSRManifest} */ + // let manifest; /** @type {Error | null} */ let manifest_error = null; - /** @param {string} url */ - async function loud_ssr_load_module(url) { - try { - return await vite.ssrLoadModule(url, { fixStacktrace: true }); - } catch (/** @type {any} */ err) { - const msg = buildErrorMessage(err, [colors.red(`Internal server error: ${err.message}`)]); + // /** @param {string} url */ + // async function loud_ssr_load_module(url) { + // try { + // return await vite.ssrLoadModule(url, { fixStacktrace: true }); + // } catch (/** @type {any} */ err) { + // const msg = buildErrorMessage(err, [colors.red(`Internal server error: ${err.message}`)]); - if (!vite.config.logger.hasErrorLogged(err)) { - vite.config.logger.error(msg, { error: err }); - } + // if (!vite.config.logger.hasErrorLogged(err)) { + // vite.config.logger.error(msg, { error: 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 - } - }); + // 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; - } - } + // throw err; + // } + // } + + // /** @param {string} id */ + // async function resolve(id) { + // const url = id.startsWith('..') ? to_fs(path.posix.resolve(id)) : `/${id}`; - /** @param {string} id */ - async function resolve(id) { - const url = id.startsWith('..') ? to_fs(path.posix.resolve(id)) : `/${id}`; + // const module = await loud_ssr_load_module(url); - const module = await loud_ssr_load_module(url); + // const module_node = await vite.moduleGraph.getModuleByUrl(url); - const module_node = await vite.moduleGraph.getModuleByUrl(url); + // vite.environments.node.moduleGraph.getModuleByUrl; - vite.environments.node.moduleGraph.getModuleByUrl; + // if (!module_node) throw new Error(`Could not find node for ${url}`); - if (!module_node) throw new Error(`Could not find node for ${url}`); + // return { module, module_node, url }; + // } - return { module, module_node, url }; + function invalidate_environment_context_module() { + for (const environment in vite.environments) { + const module = vite.environments[environment].moduleGraph.getModuleById( + sveltekit_environment_context + ); + + if (module) { + vite.environments[environment].moduleGraph.invalidateModule(module); + } + } } function update_manifest() { try { - ({ manifest_data } = sync.create(svelte_config)); + environment_context.manifest_data = sync.create(svelte_config).manifest_data; + + invalidate_environment_context_module(); if (manifest_error) { manifest_error = null; @@ -124,151 +139,151 @@ export async function dev(vite, vite_config, svelte_config, environment_context) return; } - manifest = { - appDir: svelte_config.kit.appDir, - appPath: svelte_config.kit.appDir, - assets: new Set(manifest_data.assets.map((asset) => asset.file)), - mimeTypes: get_mime_lookup(manifest_data), - _: { - client: { - start: `${runtime_base}/client/entry.js`, - app: `${to_fs(svelte_config.kit.outDir)}/generated/client/app.js`, - imports: [], - stylesheets: [], - fonts: [], - uses_env_dynamic_public: true - }, - server_assets: new Proxy( - {}, - { - has: (_, /** @type {string} */ file) => fs.existsSync(from_fs(file)), - get: (_, /** @type {string} */ file) => fs.statSync(from_fs(file)).size - } - ), - nodes: manifest_data.nodes.map((node, index) => { - return async () => { - /** @type {import('types').SSRNode} */ - const result = {}; - - /** @type {import('vite').ModuleNode[]} */ - const module_nodes = []; - - result.index = index; - - // these are unused in dev, it's easier to include them - result.imports = []; - result.stylesheets = []; - result.fonts = []; - - if (node.component) { - result.component = async () => { - const { module_node, module } = await resolve( - /** @type {string} */ (node.component) - ); - - module_nodes.push(module_node); - - return module.default; - }; - } - - if (node.universal) { - const { module, module_node } = await resolve(node.universal); - - module_nodes.push(module_node); - - result.universal = module; - result.universal_id = node.universal; - } - - if (node.server) { - const { module } = await resolve(node.server); - result.server = module; - result.server_id = node.server; - } - - // in dev we inline all styles to avoid FOUC. this gets populated lazily so that - // components/stylesheets loaded via import() during `load` are included - result.inline_styles = async () => { - const deps = new Set(); - - for (const module_node of module_nodes) { - await find_deps(vite, module_node, deps); - } - - /** @type {Record} */ - const styles = {}; - - for (const dep of deps) { - const url = new URL(dep.url, 'dummy:/'); - const query = url.searchParams; - - if ( - (isCSSRequest(dep.file) || - (query.has('svelte') && query.get('type') === 'style')) && - !(query.has('raw') || query.has('url') || query.has('inline')) - ) { - try { - query.set('inline', ''); - const mod = await vite.ssrLoadModule( - `${decodeURI(url.pathname)}${url.search}${url.hash}` - ); - styles[dep.url] = mod.default; - } catch { - // this can happen with dynamically imported modules, I think - // because the Vite module graph doesn't distinguish between - // static and dynamic imports? TODO investigate, submit fix - } - } - } - - return styles; - }; - - return result; - }; - }), - routes: compact( - manifest_data.routes.map((route) => { - if (!route.page && !route.endpoint) return null; - - const endpoint = route.endpoint; - - return { - id: route.id, - pattern: route.pattern, - params: route.params, - page: route.page, - endpoint: endpoint - ? async () => { - const url = path.resolve(cwd, endpoint.file); - return await loud_ssr_load_module(url); - } - : null, - endpoint_id: endpoint?.file - }; - }) - ), - matchers: async () => { - /** @type {Record} */ - const matchers = {}; - - for (const key in manifest_data.matchers) { - const file = manifest_data.matchers[key]; - const url = path.resolve(cwd, file); - const module = await vite.ssrLoadModule(url, { fixStacktrace: true }); - - if (module.match) { - matchers[key] = module.match; - } else { - throw new Error(`${file} does not export a \`match\` function`); - } - } - - return matchers; - } - } - }; + // manifest = { + // appDir: svelte_config.kit.appDir, + // appPath: svelte_config.kit.appDir, + // assets: new Set(manifest_data.assets.map((asset) => asset.file)), + // mimeTypes: get_mime_lookup(manifest_data), + // _: { + // client: { + // start: `${runtime_base}/client/entry.js`, + // app: `${to_fs(svelte_config.kit.outDir)}/generated/client/app.js`, + // imports: [], + // stylesheets: [], + // fonts: [], + // uses_env_dynamic_public: true + // }, + // server_assets: new Proxy( + // {}, + // { + // has: (_, /** @type {string} */ file) => fs.existsSync(from_fs(file)), + // get: (_, /** @type {string} */ file) => fs.statSync(from_fs(file)).size + // } + // ), + // nodes: manifest_data.nodes.map((node, index) => { + // return async () => { + // /** @type {import('types').SSRNode} */ + // const result = {}; + + // /** @type {import('vite').ModuleNode[]} */ + // const module_nodes = []; + + // result.index = index; + + // // these are unused in dev, it's easier to include them + // result.imports = []; + // result.stylesheets = []; + // result.fonts = []; + + // if (node.component) { + // result.component = async () => { + // const { module_node, module } = await resolve( + // /** @type {string} */ (node.component) + // ); + + // module_nodes.push(module_node); + + // return module.default; + // }; + // } + + // if (node.universal) { + // const { module, module_node } = await resolve(node.universal); + + // module_nodes.push(module_node); + + // result.universal = module; + // result.universal_id = node.universal; + // } + + // if (node.server) { + // const { module } = await resolve(node.server); + // result.server = module; + // result.server_id = node.server; + // } + + // // in dev we inline all styles to avoid FOUC. this gets populated lazily so that + // // components/stylesheets loaded via import() during `load` are included + // result.inline_styles = async () => { + // const deps = new Set(); + + // for (const module_node of module_nodes) { + // await find_deps(vite, module_node, deps); + // } + + // /** @type {Record} */ + // const styles = {}; + + // for (const dep of deps) { + // const url = new URL(dep.url, 'dummy:/'); + // const query = url.searchParams; + + // if ( + // (isCSSRequest(dep.file) || + // (query.has('svelte') && query.get('type') === 'style')) && + // !(query.has('raw') || query.has('url') || query.has('inline')) + // ) { + // try { + // query.set('inline', ''); + // const mod = await vite.ssrLoadModule( + // `${decodeURI(url.pathname)}${url.search}${url.hash}` + // ); + // styles[dep.url] = mod.default; + // } catch { + // // this can happen with dynamically imported modules, I think + // // because the Vite module graph doesn't distinguish between + // // static and dynamic imports? TODO investigate, submit fix + // } + // } + // } + + // return styles; + // }; + + // return result; + // }; + // }), + // routes: compact( + // manifest_data.routes.map((route) => { + // if (!route.page && !route.endpoint) return null; + + // const endpoint = route.endpoint; + + // return { + // id: route.id, + // pattern: route.pattern, + // params: route.params, + // page: route.page, + // endpoint: endpoint + // ? async () => { + // const url = path.resolve(cwd, endpoint.file); + // return await loud_ssr_load_module(url); + // } + // : null, + // endpoint_id: endpoint?.file + // }; + // }) + // ), + // matchers: async () => { + // /** @type {Record} */ + // const matchers = {}; + + // for (const key in manifest_data.matchers) { + // const file = manifest_data.matchers[key]; + // const url = path.resolve(cwd, file); + // const module = await vite.ssrLoadModule(url, { fixStacktrace: true }); + + // if (module.match) { + // matchers[key] = module.match; + // } else { + // throw new Error(`${file} does not export a \`match\` function`); + // } + // } + + // return matchers; + // } + // } + // }; } /** @param {Error} error */ @@ -318,7 +333,7 @@ export async function dev(vite, vite_config, svelte_config, environment_context) // Don't run for a single file if the whole manifest is about to get updated if (timeout || restarting) return; - sync.update(svelte_config, manifest_data, file); + sync.update(svelte_config, environment_context.manifest_data, file); }); const { appTemplate, errorTemplate, serviceWorker, hooks } = svelte_config.kit.files; @@ -422,7 +437,7 @@ export async function dev(vite, vite_config, svelte_config, environment_context) } }); - const env = loadEnv(vite_config.mode, svelte_config.kit.env.dir, ''); + environment_context.env = loadEnv(vite_config.mode, svelte_config.kit.env.dir, ''); // const emulator = await svelte_config.kit.adapter?.emulate?.(); return () => { @@ -438,6 +453,8 @@ export async function dev(vite, vite_config, svelte_config, environment_context) const module_runner = createServerModuleRunner(vite.environments.node); vite.middlewares.use(async (req, res) => { + environment_context.remote_address = req.socket.remoteAddress; + // Vite's base middleware strips out the base path. Restore it const original_url = req.url; req.url = req.originalUrl; @@ -480,10 +497,10 @@ export async function dev(vite, vite_config, svelte_config, environment_context) return; } - // we have to import `Server` before calling `set_assets` - const { Server } = /** @type {import('types').ServerModule} */ ( - await vite.ssrLoadModule(`${runtime_base}/server/index.js`, { fixStacktrace: true }) - ); + // // we have to import `Server` before calling `set_assets` + // const { Server } = /** @type {import('types').ServerModule} */ ( + // await vite.ssrLoadModule(`${runtime_base}/server/index.js`, { fixStacktrace: true }) + // ); const { set_fix_stack_trace } = await vite.ssrLoadModule( `${runtime_base}/shared-server.js` @@ -493,12 +510,12 @@ export async function dev(vite, vite_config, svelte_config, environment_context) const { set_assets } = await vite.ssrLoadModule('__sveltekit/paths'); set_assets(assets); - const server = new Server(manifest); + // const server = new Server(manifest); - await server.init({ - env, - read: (file) => createReadableStream(from_fs(file)) - }); + // await server.init({ + // env, + // read: (file) => createReadableStream(from_fs(file)) + // }); const request = await getRequest({ base, @@ -527,10 +544,6 @@ export async function dev(vite, vite_config, svelte_config, environment_context) return; } - environment_context.manifest_data = manifest_data; - environment_context.env = env; - environment_context.remote_address = req.socket.remoteAddress; - const devEnv = vite.environments['vite-plugin-cloudflare-workerd-env']; if (!devEnv) { diff --git a/packages/kit/src/exports/vite/dev/workerd_entrypoint.js b/packages/kit/src/exports/vite/dev/workerd_entrypoint.js index e476884514be..2c204e0496f9 100644 --- a/packages/kit/src/exports/vite/dev/workerd_entrypoint.js +++ b/packages/kit/src/exports/vite/dev/workerd_entrypoint.js @@ -1,7 +1,5 @@ import { Server } from '../../../runtime/server/index.js'; -const environment_context = await import('__sveltekit/environment_context'); - export default { /** * @param {Request & { cf: any }} req @@ -9,6 +7,7 @@ export default { * @param {any} ctx */ fetch: async (req, env, ctx) => { + const environment_context = await import('__sveltekit/environment_context'); const server = new Server(environment_context.manifest); await server.init({ diff --git a/packages/kit/src/exports/vite/index.js b/packages/kit/src/exports/vite/index.js index b3479f1139df..09f05ab97c90 100644 --- a/packages/kit/src/exports/vite/index.js +++ b/packages/kit/src/exports/vite/index.js @@ -45,7 +45,7 @@ import { } from './module_ids.js'; import { resolve_peer_dependency } from '../../utils/import.js'; -/** @type {{ manifest_data: import('types').ManifestData, env: Record, remote_address: string | undefined }} */ +/** @type {import('types').EnvironmentContext} */ const environment_context = {}; const cwd = process.cwd(); diff --git a/packages/kit/src/types/ambient-private.d.ts b/packages/kit/src/types/ambient-private.d.ts index e07096a66c99..5d248512d55a 100644 --- a/packages/kit/src/types/ambient-private.d.ts +++ b/packages/kit/src/types/ambient-private.d.ts @@ -33,5 +33,4 @@ declare module '__sveltekit/environment_context' { export let manifest: SSRManifest; export let env: Record; export let remote_address: string | undefined; - export let assets_directory: string; } diff --git a/packages/kit/src/types/internal.d.ts b/packages/kit/src/types/internal.d.ts index c9dbb51ce007..22779c2195f5 100644 --- a/packages/kit/src/types/internal.d.ts +++ b/packages/kit/src/types/internal.d.ts @@ -121,6 +121,12 @@ export interface Env { public: Record; } +export interface EnvironmentContext { + manifest_data: ManifestData; + env: Record; + remote_address: string | undefined; +} + export class InternalServer extends Server { init(options: ServerInitOptions): Promise; respond( From 63c51f3d4922bb54b90df181a8e37e50f38c41ff Mon Sep 17 00:00:00 2001 From: James Opstad Date: Thu, 29 Aug 2024 14:27:57 +0100 Subject: [PATCH 19/61] Added cloudflare types --- packages/kit/package.json | 1 + packages/kit/src/exports/vite/dev/index.js | 31 ++++++++++--------- .../exports/vite/dev/workerd_entrypoint.js | 12 +++---- .../vite-workerd-environment/package.json | 1 + .../vite-workerd-environment/src/app.d.ts | 6 +++- .../cf-properties/[[key]]/+page.server.ts | 2 +- pnpm-lock.yaml | 10 ++++-- 7 files changed, 38 insertions(+), 25 deletions(-) diff --git a/packages/kit/package.json b/packages/kit/package.json index 3de5aa1b3afc..48f2e732b4b2 100644 --- a/packages/kit/package.json +++ b/packages/kit/package.json @@ -33,6 +33,7 @@ "tiny-glob": "^0.2.9" }, "devDependencies": { + "@cloudflare/workers-types": "^4.20231121.0", "@playwright/test": "^1.44.1", "@sveltejs/vite-plugin-svelte": "^3.0.1", "@types/connect": "^3.4.38", diff --git a/packages/kit/src/exports/vite/dev/index.js b/packages/kit/src/exports/vite/dev/index.js index 2519c967ade0..2b3e8ad17741 100644 --- a/packages/kit/src/exports/vite/dev/index.js +++ b/packages/kit/src/exports/vite/dev/index.js @@ -102,6 +102,7 @@ export async function dev(vite, vite_config, svelte_config, environment_context) // return { module, module_node, url }; // } + // this doesn't seem to be needed function invalidate_environment_context_module() { for (const environment in vite.environments) { const module = vite.environments[environment].moduleGraph.getModuleById( @@ -118,7 +119,7 @@ export async function dev(vite, vite_config, svelte_config, environment_context) try { environment_context.manifest_data = sync.create(svelte_config).manifest_data; - invalidate_environment_context_module(); + // invalidate_environment_context_module(); if (manifest_error) { manifest_error = null; @@ -440,7 +441,7 @@ export async function dev(vite, vite_config, svelte_config, environment_context) environment_context.env = loadEnv(vite_config.mode, svelte_config.kit.env.dir, ''); // const emulator = await svelte_config.kit.adapter?.emulate?.(); - return () => { + return async () => { const serve_static_middleware = vite.middlewares.stack.find( (middleware) => /** @type {function} */ (middleware.handle).name === 'viteServeStaticMiddleware' @@ -452,6 +453,19 @@ export async function dev(vite, vite_config, svelte_config, environment_context) const module_runner = createServerModuleRunner(vite.environments.node); + const devEnv = vite.environments['vite-plugin-cloudflare-workerd-env']; + + if (!devEnv) { + throw new Error('No Cloudflare dev environment is present'); + } + + const __dirname = fileURLToPath(new URL('.', import.meta.url)); + // const entrypoint = await module_runner.import(path.join(__dirname, 'node_entrypoint.js')); + // const handler = entrypoint.default.fetch; + const handler = await devEnv.api.getHandler({ + entrypoint: path.join(__dirname, 'workerd_entrypoint.js') + }); + vite.middlewares.use(async (req, res) => { environment_context.remote_address = req.socket.remoteAddress; @@ -544,19 +558,6 @@ export async function dev(vite, vite_config, svelte_config, environment_context) return; } - const devEnv = vite.environments['vite-plugin-cloudflare-workerd-env']; - - if (!devEnv) { - throw new Error('No Cloudflare dev environment is present'); - } - - const __dirname = fileURLToPath(new URL('.', import.meta.url)); - // const entrypoint = await module_runner.import(path.join(__dirname, 'node_entrypoint.js')); - // const handler = entrypoint.default.fetch; - const handler = await devEnv.api.getHandler({ - entrypoint: path.join(__dirname, 'workerd_entrypoint.js') - }); - const rendered = await handler(request); // const rendered = await server.respond(request, { diff --git a/packages/kit/src/exports/vite/dev/workerd_entrypoint.js b/packages/kit/src/exports/vite/dev/workerd_entrypoint.js index 2c204e0496f9..d2a7115fc6a1 100644 --- a/packages/kit/src/exports/vite/dev/workerd_entrypoint.js +++ b/packages/kit/src/exports/vite/dev/workerd_entrypoint.js @@ -2,11 +2,11 @@ import { Server } from '../../../runtime/server/index.js'; export default { /** - * @param {Request & { cf: any }} req + * @param {Request & { cf?: import('@cloudflare/workers-types').IncomingRequestCfProperties }} request * @param {any} env - * @param {any} ctx + * @param {any} context */ - fetch: async (req, env, ctx) => { + fetch: async (request, env, context) => { const environment_context = await import('__sveltekit/environment_context'); const server = new Server(environment_context.manifest); @@ -14,7 +14,7 @@ export default { env: environment_context.env }); - return server.respond(req, { + return server.respond(request, { getClientAddress: () => { if (!environment_context.remote_address) { throw new Error('Could not determine clientAddress'); @@ -24,8 +24,8 @@ export default { }, platform: { env, - cf: req.cf, - ctx, + cf: request.cf, + context, caches } }); diff --git a/playgrounds/vite-workerd-environment/package.json b/playgrounds/vite-workerd-environment/package.json index f5cac6dd921e..7829a5349926 100644 --- a/playgrounds/vite-workerd-environment/package.json +++ b/playgrounds/vite-workerd-environment/package.json @@ -13,6 +13,7 @@ "typegen": "wrangler types" }, "devDependencies": { + "@cloudflare/workers-types": "^4.20231121.0", "@dario-hacking/vite-6-alpha-environment-provider-workerd": "^0.0.5", "@sveltejs/adapter-auto": "workspace:*", "@sveltejs/adapter-cloudflare": "workspace:*", diff --git a/playgrounds/vite-workerd-environment/src/app.d.ts b/playgrounds/vite-workerd-environment/src/app.d.ts index 237626ef7f0b..6c1ba3ec179a 100644 --- a/playgrounds/vite-workerd-environment/src/app.d.ts +++ b/playgrounds/vite-workerd-environment/src/app.d.ts @@ -1,3 +1,5 @@ +import { CacheStorage, IncomingRequestCfProperties } from '@cloudflare/workers-types'; + // See https://kit.svelte.dev/docs/types#app // for information about these interfaces declare global { @@ -6,7 +8,9 @@ declare global { // interface Locals {} // interface PageData {} interface Platform { - cf: any; + caches: CacheStorage; + cf: IncomingRequestCfProperties; + context: any; env: any; } } diff --git a/playgrounds/vite-workerd-environment/src/routes/cf-properties/[[key]]/+page.server.ts b/playgrounds/vite-workerd-environment/src/routes/cf-properties/[[key]]/+page.server.ts index 71627c7511a9..89a248cc511b 100644 --- a/playgrounds/vite-workerd-environment/src/routes/cf-properties/[[key]]/+page.server.ts +++ b/playgrounds/vite-workerd-environment/src/routes/cf-properties/[[key]]/+page.server.ts @@ -3,7 +3,7 @@ import type { PageServerLoadEvent } from './$types'; export function load({ params, platform }: PageServerLoadEvent) { const cf = platform.cf; const key = params?.key; - const value = key && key in cf && JSON.stringify(cf[key]); + const value = key && key in cf ? JSON.stringify(cf[key]) : undefined; return { key, value, keys: Object.keys(cf) }; } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c359ea47a3d4..e86e66efc676 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -444,6 +444,9 @@ importers: specifier: ^0.2.9 version: 0.2.9 devDependencies: + '@cloudflare/workers-types': + specifier: ^4.20231121.0 + version: 4.20240405.0 '@playwright/test': specifier: ^1.44.1 version: 1.44.1 @@ -1292,9 +1295,12 @@ importers: playgrounds/vite-workerd-environment: devDependencies: + '@cloudflare/workers-types': + specifier: ^4.20231121.0 + version: 4.20240405.0 '@dario-hacking/vite-6-alpha-environment-provider-workerd': specifier: ^0.0.5 - version: 0.0.5(miniflare@3.20240701.0)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1))(wrangler@3.63.1) + version: 0.0.5(miniflare@3.20240701.0)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1))(wrangler@3.63.1(@cloudflare/workers-types@4.20240405.0)) '@sveltejs/adapter-auto': specifier: workspace:* version: link:../../packages/adapter-auto @@ -4659,7 +4665,7 @@ snapshots: dependencies: '@jridgewell/trace-mapping': 0.3.9 - '@dario-hacking/vite-6-alpha-environment-provider-workerd@0.0.5(miniflare@3.20240701.0)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1))(wrangler@3.63.1)': + '@dario-hacking/vite-6-alpha-environment-provider-workerd@0.0.5(miniflare@3.20240701.0)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1))(wrangler@3.63.1(@cloudflare/workers-types@4.20240405.0))': dependencies: cjs-module-lexer: 1.3.1 miniflare: 3.20240701.0 From ceb2a093e7437b2ab49f363bd7d32f835772fefe Mon Sep 17 00:00:00 2001 From: James Opstad Date: Thu, 29 Aug 2024 14:34:50 +0100 Subject: [PATCH 20/61] Added additional types --- .../vite-workerd-environment/package.json | 3 +- .../vite-workerd-environment/src/app.d.ts | 10 +- .../worker-configuration.d.ts | 2 +- pnpm-lock.yaml | 137 +++++++++++++++++- 4 files changed, 143 insertions(+), 9 deletions(-) diff --git a/playgrounds/vite-workerd-environment/package.json b/playgrounds/vite-workerd-environment/package.json index 7829a5349926..17fbd96fc0d7 100644 --- a/playgrounds/vite-workerd-environment/package.json +++ b/playgrounds/vite-workerd-environment/package.json @@ -30,7 +30,8 @@ "svelte": "^4.2.10", "svelte-check": "^3.6.3", "typescript": "^5.3.3", - "vite": "^5.3.2" + "vite": "^5.3.2", + "wrangler": "^3.72.3" }, "type": "module", "exports": { diff --git a/playgrounds/vite-workerd-environment/src/app.d.ts b/playgrounds/vite-workerd-environment/src/app.d.ts index 6c1ba3ec179a..979f8f576b66 100644 --- a/playgrounds/vite-workerd-environment/src/app.d.ts +++ b/playgrounds/vite-workerd-environment/src/app.d.ts @@ -1,4 +1,8 @@ -import { CacheStorage, IncomingRequestCfProperties } from '@cloudflare/workers-types'; +import type { + CacheStorage, + ExecutionContext, + IncomingRequestCfProperties +} from '@cloudflare/workers-types'; // See https://kit.svelte.dev/docs/types#app // for information about these interfaces @@ -10,8 +14,8 @@ declare global { interface Platform { caches: CacheStorage; cf: IncomingRequestCfProperties; - context: any; - env: any; + context: ExecutionContext; + env: Env; } } } diff --git a/playgrounds/vite-workerd-environment/worker-configuration.d.ts b/playgrounds/vite-workerd-environment/worker-configuration.d.ts index 129bc4591858..d62f1a062ac6 100644 --- a/playgrounds/vite-workerd-environment/worker-configuration.d.ts +++ b/playgrounds/vite-workerd-environment/worker-configuration.d.ts @@ -1,4 +1,4 @@ -// Generated by Wrangler on Tue Aug 20 2024 18:19:21 GMT+0100 (British Summer Time) +// Generated by Wrangler on Thu Aug 29 2024 14:33:34 GMT+0100 (British Summer Time) // by running `wrangler types` interface Env { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e86e66efc676..ff680a3b5286 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1300,7 +1300,7 @@ importers: version: 4.20240405.0 '@dario-hacking/vite-6-alpha-environment-provider-workerd': specifier: ^0.0.5 - version: 0.0.5(miniflare@3.20240701.0)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1))(wrangler@3.63.1(@cloudflare/workers-types@4.20240405.0)) + version: 0.0.5(miniflare@3.20240821.0)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1))(wrangler@3.72.3(@cloudflare/workers-types@4.20240405.0)) '@sveltejs/adapter-auto': specifier: workspace:* version: link:../../packages/adapter-auto @@ -1349,6 +1349,9 @@ importers: vite: specifier: 6.0.0-alpha.18 version: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) + wrangler: + specifier: ^3.72.3 + version: 3.72.3(@cloudflare/workers-types@4.20240405.0) sites/kit.svelte.dev: dependencies: @@ -1519,30 +1522,64 @@ packages: cpu: [x64] os: [darwin] + '@cloudflare/workerd-darwin-64@1.20240821.1': + resolution: {integrity: sha512-CDBpfZKrSy4YrIdqS84z67r3Tzal2pOhjCsIb63IuCnvVes59/ft1qhczBzk9EffeOE2iTCrA4YBT7Sbn7USew==} + engines: {node: '>=16'} + cpu: [x64] + os: [darwin] + '@cloudflare/workerd-darwin-arm64@1.20240701.0': resolution: {integrity: sha512-w80ZVAgfH4UwTz7fXZtk7KmS2FzlXniuQm4ku4+cIgRTilBAuKqjpOjwUCbx5g13Gqcm9NuiHce+IDGtobRTIQ==} engines: {node: '>=16'} cpu: [arm64] os: [darwin] + '@cloudflare/workerd-darwin-arm64@1.20240821.1': + resolution: {integrity: sha512-Q+9RedvNbPcEt/dKni1oN94OxbvuNAeJkgHmrLFTGF8zu21wzOhVkQeRNxcYxrMa9mfStc457NAg13OVCj2kHQ==} + engines: {node: '>=16'} + cpu: [arm64] + os: [darwin] + '@cloudflare/workerd-linux-64@1.20240701.0': resolution: {integrity: sha512-UWLr/Anxwwe/25nGv451MNd2jhREmPt/ws17DJJqTLAx6JxwGWA15MeitAIzl0dbxRFAJa+0+R8ag2WR3F/D6g==} engines: {node: '>=16'} cpu: [x64] os: [linux] + '@cloudflare/workerd-linux-64@1.20240821.1': + resolution: {integrity: sha512-j6z3KsPtawrscoLuP985LbqFrmsJL6q1mvSXOXTqXGODAHIzGBipHARdOjms3UQqovzvqB2lQaQsZtLBwCZxtA==} + engines: {node: '>=16'} + cpu: [x64] + os: [linux] + '@cloudflare/workerd-linux-arm64@1.20240701.0': resolution: {integrity: sha512-3kCnF9kYgov1ggpuWbgpXt4stPOIYtVmPCa7MO2xhhA0TWP6JDUHRUOsnmIgKrvDjXuXqlK16cdg3v+EWsaPJg==} engines: {node: '>=16'} cpu: [arm64] os: [linux] + '@cloudflare/workerd-linux-arm64@1.20240821.1': + resolution: {integrity: sha512-I9bHgZOxJQW0CV5gTdilyxzTG7ILzbTirehQWgfPx9X77E/7eIbR9sboOMgyeC69W4he0SKtpx0sYZuTJu4ERw==} + engines: {node: '>=16'} + cpu: [arm64] + os: [linux] + '@cloudflare/workerd-windows-64@1.20240701.0': resolution: {integrity: sha512-6IPGITRAeS67j3BH1rN4iwYWDt47SqJG7KlZJ5bB4UaNAia4mvMBSy/p2p4vA89bbXoDRjMtEvRu7Robu6O7hQ==} engines: {node: '>=16'} cpu: [x64] os: [win32] + '@cloudflare/workerd-windows-64@1.20240821.1': + resolution: {integrity: sha512-keC97QPArs6LWbPejQM7/Y8Jy8QqyaZow4/ZdsGo+QjlOLiZRDpAenfZx3CBUoWwEeFwQTl2FLO+8hV1SWFFYw==} + engines: {node: '>=16'} + cpu: [x64] + os: [win32] + + '@cloudflare/workers-shared@0.4.0': + resolution: {integrity: sha512-XAFOldVQsbxQ7mjbqX2q1dNIgcLbKSytk41pwuZTn9e0p7OeTpFTosJef8uwosL6CcOAHqcW1f1HJxyjwmtGxw==} + engines: {node: '>=16.7.0'} + '@cloudflare/workers-types@4.20240405.0': resolution: {integrity: sha512-sEVOhyOgXUwfLkgHqbLZa/sfkSYrh7/zLmI6EZNibPaVPvAnAcItbNNl3SAlLyLKuwf8m4wAIAgu9meKWCvXjg==} @@ -3427,6 +3464,11 @@ packages: engines: {node: '>=16.13'} hasBin: true + miniflare@3.20240821.0: + resolution: {integrity: sha512-4BhLGpssQxM/O6TZmJ10GkT3wBJK6emFkZ3V87/HyvQmVt8zMxEBvyw5uv6kdtp+7F54Nw6IKFJjPUL8rFVQrQ==} + engines: {node: '>=16.13'} + hasBin: true + minimatch@3.1.2: resolution: {integrity: sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==} @@ -4390,6 +4432,11 @@ packages: engines: {node: '>=16'} hasBin: true + workerd@1.20240821.1: + resolution: {integrity: sha512-y4phjCnEG96u8ZkgkkHB+gSw0i6uMNo23rBmixylWpjxDklB+LWD8dztasvsu7xGaZbLoTxQESdEw956F7VJDA==} + engines: {node: '>=16'} + hasBin: true + worktop@0.8.0-next.18: resolution: {integrity: sha512-+TvsA6VAVoMC3XDKR5MoC/qlLqDixEfOBysDEKnPIPou/NvoPWCAuXHXMsswwlvmEuvX56lQjvELLyLuzTKvRw==} engines: {node: '>=12'} @@ -4404,6 +4451,16 @@ packages: '@cloudflare/workers-types': optional: true + wrangler@3.72.3: + resolution: {integrity: sha512-EBlJGOcwanbzFkiJkRB47WKhvevh1AZK0ty0MyD0gptsgWnAxBfmFGiBuzOuRXbvH45ZrFrTqgi8c67EwcV1nA==} + engines: {node: '>=16.17.0'} + hasBin: true + peerDependencies: + '@cloudflare/workers-types': ^4.20240821.1 + peerDependenciesMeta: + '@cloudflare/workers-types': + optional: true + wrap-ansi@7.0.0: resolution: {integrity: sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==} engines: {node: '>=10'} @@ -4647,30 +4704,47 @@ snapshots: '@cloudflare/workerd-darwin-64@1.20240701.0': optional: true + '@cloudflare/workerd-darwin-64@1.20240821.1': + optional: true + '@cloudflare/workerd-darwin-arm64@1.20240701.0': optional: true + '@cloudflare/workerd-darwin-arm64@1.20240821.1': + optional: true + '@cloudflare/workerd-linux-64@1.20240701.0': optional: true + '@cloudflare/workerd-linux-64@1.20240821.1': + optional: true + '@cloudflare/workerd-linux-arm64@1.20240701.0': optional: true + '@cloudflare/workerd-linux-arm64@1.20240821.1': + optional: true + '@cloudflare/workerd-windows-64@1.20240701.0': optional: true + '@cloudflare/workerd-windows-64@1.20240821.1': + optional: true + + '@cloudflare/workers-shared@0.4.0': {} + '@cloudflare/workers-types@4.20240405.0': {} '@cspotcode/source-map-support@0.8.1': dependencies: '@jridgewell/trace-mapping': 0.3.9 - '@dario-hacking/vite-6-alpha-environment-provider-workerd@0.0.5(miniflare@3.20240701.0)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1))(wrangler@3.63.1(@cloudflare/workers-types@4.20240405.0))': + '@dario-hacking/vite-6-alpha-environment-provider-workerd@0.0.5(miniflare@3.20240821.0)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1))(wrangler@3.72.3(@cloudflare/workers-types@4.20240405.0))': dependencies: cjs-module-lexer: 1.3.1 - miniflare: 3.20240701.0 + miniflare: 3.20240821.0 vite: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) - wrangler: 3.63.1(@cloudflare/workers-types@4.20240405.0) + wrangler: 3.72.3(@cloudflare/workers-types@4.20240405.0) '@emnapi/runtime@1.2.0': dependencies: @@ -6429,6 +6503,25 @@ snapshots: - supports-color - utf-8-validate + miniflare@3.20240821.0: + dependencies: + '@cspotcode/source-map-support': 0.8.1 + acorn: 8.12.1 + acorn-walk: 8.3.2 + capnp-ts: 0.7.0 + exit-hook: 2.2.1 + glob-to-regexp: 0.4.1 + stoppable: 1.1.0 + undici: 5.28.4 + workerd: 1.20240821.1 + ws: 8.18.0 + youch: 3.3.3 + zod: 3.22.4 + transitivePeerDependencies: + - bufferutil + - supports-color + - utf-8-validate + minimatch@3.1.2: dependencies: brace-expansion: 1.1.11 @@ -7330,6 +7423,14 @@ snapshots: '@cloudflare/workerd-linux-arm64': 1.20240701.0 '@cloudflare/workerd-windows-64': 1.20240701.0 + workerd@1.20240821.1: + optionalDependencies: + '@cloudflare/workerd-darwin-64': 1.20240821.1 + '@cloudflare/workerd-darwin-arm64': 1.20240821.1 + '@cloudflare/workerd-linux-64': 1.20240821.1 + '@cloudflare/workerd-linux-arm64': 1.20240821.1 + '@cloudflare/workerd-windows-64': 1.20240821.1 + worktop@0.8.0-next.18: dependencies: mrmime: 2.0.0 @@ -7361,6 +7462,34 @@ snapshots: - supports-color - utf-8-validate + wrangler@3.72.3(@cloudflare/workers-types@4.20240405.0): + dependencies: + '@cloudflare/kv-asset-handler': 0.3.4 + '@cloudflare/workers-shared': 0.4.0 + '@esbuild-plugins/node-globals-polyfill': 0.2.3(esbuild@0.17.19) + '@esbuild-plugins/node-modules-polyfill': 0.2.2(esbuild@0.17.19) + blake3-wasm: 2.1.5 + chokidar: 3.6.0 + date-fns: 3.6.0 + esbuild: 0.17.19 + miniflare: 3.20240821.0 + nanoid: 3.3.7 + path-to-regexp: 6.2.2 + resolve: 1.22.8 + resolve.exports: 2.0.2 + selfsigned: 2.4.1 + source-map: 0.6.1 + unenv: unenv-nightly@1.10.0-1717606461.a117952 + workerd: 1.20240821.1 + xxhash-wasm: 1.0.2 + optionalDependencies: + '@cloudflare/workers-types': 4.20240405.0 + fsevents: 2.3.3 + transitivePeerDependencies: + - bufferutil + - supports-color + - utf-8-validate + wrap-ansi@7.0.0: dependencies: ansi-styles: 4.3.0 From 8bca02fa1c6b1adc2fead0bfae6eb88b20e16514 Mon Sep 17 00:00:00 2001 From: James Opstad Date: Thu, 29 Aug 2024 18:56:03 +0100 Subject: [PATCH 21/61] Added kit.ssrEnvironment property to svelte config and created default node environment as fallback --- packages/kit/src/core/config/options.js | 5 +++ packages/kit/src/exports/public.d.ts | 17 ++++---- packages/kit/src/exports/vite/constants.js | 1 + .../exports/vite/dev/default_environment.js | 24 +++++++++++ packages/kit/src/exports/vite/dev/index.js | 42 ++++++++++++------- packages/kit/src/exports/vite/index.js | 16 +++---- .../vite-workerd-environment/svelte.config.js | 4 +- .../vite-workerd-environment/vite.config.ts | 3 +- 8 files changed, 77 insertions(+), 35 deletions(-) create mode 100644 packages/kit/src/exports/vite/constants.js create mode 100644 packages/kit/src/exports/vite/dev/default_environment.js diff --git a/packages/kit/src/core/config/options.js b/packages/kit/src/core/config/options.js index 316e935a2793..587053d33140 100644 --- a/packages/kit/src/core/config/options.js +++ b/packages/kit/src/core/config/options.js @@ -1,4 +1,5 @@ import { join } from 'node:path'; +import { default_environment } from '../../exports/vite/dev/default_environment.js'; /** @typedef {import('./types.js').Validator} Validator */ @@ -263,6 +264,10 @@ const options = object( files: fun((filename) => !/\.DS_Store/.test(filename)) }), + ssrEnvironment: validate(default_environment, (input) => { + return input; + }), + typescript: object({ config: fun((config) => config) }), diff --git a/packages/kit/src/exports/public.d.ts b/packages/kit/src/exports/public.d.ts index 861aff321902..165e3a577b10 100644 --- a/packages/kit/src/exports/public.d.ts +++ b/packages/kit/src/exports/public.d.ts @@ -1,6 +1,7 @@ import 'svelte'; // pick up `declare module "*.svelte"` import 'vite/client'; // pick up `declare module "*.jpg"`, etc. import '../types/ambient.js'; +import { Plugin } from 'vite'; import { CompileOptions } from 'svelte/compiler'; import { @@ -55,8 +56,8 @@ export interface Adapter { export type LoadProperties | void> = input extends void ? undefined // needs to be undefined, because void will break intellisense : input extends Record - ? input - : unknown; + ? input + : unknown; export type AwaitedActions any>> = OptionalUnion< { @@ -79,12 +80,11 @@ export interface ActionFailure | undefined = u [uniqueSymbol]: true; // necessary or else UnpackValidationError could wrongly unpack objects with the same shape as ActionFailure } -type UnpackValidationError = - T extends ActionFailure - ? X - : T extends void - ? undefined // needs to be undefined, because void will corrupt union type - : T; +type UnpackValidationError = T extends ActionFailure + ? X + : T extends void + ? undefined // needs to be undefined, because void will corrupt union type + : T; /** * This object is passed to the `adapt` function of adapters. @@ -618,6 +618,7 @@ export interface KitConfig { */ files?(filepath: string): boolean; }; + ssrEnvironment?: (environmentName: string, options: any) => Plugin[]; typescript?: { /** * A function that allows you to edit the generated `tsconfig.json`. You can mutate the config (recommended) or return a new one. diff --git a/packages/kit/src/exports/vite/constants.js b/packages/kit/src/exports/vite/constants.js new file mode 100644 index 000000000000..558b866826e7 --- /dev/null +++ b/packages/kit/src/exports/vite/constants.js @@ -0,0 +1 @@ +export const SSR_ENVIRONMENT_NAME = '__ssr_environment__'; diff --git a/packages/kit/src/exports/vite/dev/default_environment.js b/packages/kit/src/exports/vite/dev/default_environment.js new file mode 100644 index 000000000000..c6f34ae45be5 --- /dev/null +++ b/packages/kit/src/exports/vite/dev/default_environment.js @@ -0,0 +1,24 @@ +import { createNodeDevEnvironment } from 'vite'; + +/** + * @param {string} environment_name + * @returns {import('vite').Plugin[]} + */ +export function default_environment(environment_name) { + return [ + { + name: 'default-environment-plugin', + config: () => { + return { + environments: { + [environment_name]: { + dev: { + createEnvironment: createNodeDevEnvironment + } + } + } + }; + } + } + ]; +} diff --git a/packages/kit/src/exports/vite/dev/index.js b/packages/kit/src/exports/vite/dev/index.js index 2b3e8ad17741..8051acfa40da 100644 --- a/packages/kit/src/exports/vite/dev/index.js +++ b/packages/kit/src/exports/vite/dev/index.js @@ -18,6 +18,7 @@ import { not_found } from '../utils.js'; import { SCHEME } from '../../../utils/url.js'; import { check_feature } from '../../../utils/features.js'; import { sveltekit_environment_context } from '../module_ids.js'; +import { SSR_ENVIRONMENT_NAME } from '../constants.js'; // const cwd = process.cwd(); @@ -441,7 +442,31 @@ export async function dev(vite, vite_config, svelte_config, environment_context) environment_context.env = loadEnv(vite_config.mode, svelte_config.kit.env.dir, ''); // const emulator = await svelte_config.kit.adapter?.emulate?.(); - return async () => { + /** @type { (import('vite').DevEnvironment & { api?: { getHandler: (opts: { entrypoint: string }) => Promise<(req: Request) => Promise> }}) } */ + const devEnv = vite.environments[SSR_ENVIRONMENT_NAME]; + + const __dirname = fileURLToPath(new URL('.', import.meta.url)); + + if (!devEnv) { + throw new Error('No Cloudflare dev environment is present'); + } + + let handler; + + if (devEnv.api) { + handler = await devEnv.api.getHandler({ + entrypoint: path.join(__dirname, 'workerd_entrypoint.js') + }); + } else { + const module_runner = createServerModuleRunner(vite.environments[SSR_ENVIRONMENT_NAME]); + const entrypoint = await module_runner.import(path.join(__dirname, 'node_entrypoint.js')); + handler = entrypoint.default.fetch; + } + + // const entrypoint = await module_runner.import(path.join(__dirname, 'node_entrypoint.js')); + // const handler = entrypoint.default.fetch; + + return () => { const serve_static_middleware = vite.middlewares.stack.find( (middleware) => /** @type {function} */ (middleware.handle).name === 'viteServeStaticMiddleware' @@ -451,21 +476,6 @@ export async function dev(vite, vite_config, svelte_config, environment_context) // serving routes with those names. See https://github.com/vitejs/vite/issues/7363 remove_static_middlewares(vite.middlewares); - const module_runner = createServerModuleRunner(vite.environments.node); - - const devEnv = vite.environments['vite-plugin-cloudflare-workerd-env']; - - if (!devEnv) { - throw new Error('No Cloudflare dev environment is present'); - } - - const __dirname = fileURLToPath(new URL('.', import.meta.url)); - // const entrypoint = await module_runner.import(path.join(__dirname, 'node_entrypoint.js')); - // const handler = entrypoint.default.fetch; - const handler = await devEnv.api.getHandler({ - entrypoint: path.join(__dirname, 'workerd_entrypoint.js') - }); - vite.middlewares.use(async (req, res) => { environment_context.remote_address = req.socket.remoteAddress; diff --git a/packages/kit/src/exports/vite/index.js b/packages/kit/src/exports/vite/index.js index 09f05ab97c90..4f14bc3b28c1 100644 --- a/packages/kit/src/exports/vite/index.js +++ b/packages/kit/src/exports/vite/index.js @@ -44,6 +44,7 @@ import { sveltekit_environment_context } from './module_ids.js'; import { resolve_peer_dependency } from '../../utils/import.js'; +import { SSR_ENVIRONMENT_NAME } from './constants.js'; /** @type {import('types').EnvironmentContext} */ const environment_context = {}; @@ -263,13 +264,6 @@ async function kit({ svelte_config }) { // dev and preview config can be shared /** @type {import('vite').UserConfig} */ const new_config = { - environments: { - node: { - dev: { - createEnvironment: vite.createNodeEnvironment - } - } - }, resolve: { alias: [ { find: '__SERVER__', replacement: `${generated}/server` }, @@ -1075,7 +1069,13 @@ async function kit({ svelte_config }) { } }; - return [plugin_setup, plugin_virtual_modules, plugin_guard, plugin_compile]; + return [ + ...svelte_config.kit.ssrEnvironment(SSR_ENVIRONMENT_NAME, {}), + plugin_setup, + plugin_virtual_modules, + plugin_guard, + plugin_compile + ]; } /** diff --git a/playgrounds/vite-workerd-environment/svelte.config.js b/playgrounds/vite-workerd-environment/svelte.config.js index 955074498330..9b987f53b3a6 100644 --- a/playgrounds/vite-workerd-environment/svelte.config.js +++ b/playgrounds/vite-workerd-environment/svelte.config.js @@ -1,10 +1,12 @@ import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'; import adapter from '@sveltejs/adapter-auto'; +import { workerd } from '@dario-hacking/vite-6-alpha-environment-provider-workerd'; /** @type {import('@sveltejs/kit').Config} */ const config = { kit: { - adapter: adapter() + adapter: adapter(), + ssrEnvironment: workerd({}) }, preprocess: [vitePreprocess()] }; diff --git a/playgrounds/vite-workerd-environment/vite.config.ts b/playgrounds/vite-workerd-environment/vite.config.ts index ff846fef29c3..7617d19b8849 100644 --- a/playgrounds/vite-workerd-environment/vite.config.ts +++ b/playgrounds/vite-workerd-environment/vite.config.ts @@ -1,9 +1,8 @@ -import { workerdEnvironment } from '@dario-hacking/vite-6-alpha-environment-provider-workerd'; import { sveltekit } from '@sveltejs/kit/vite'; import { defineConfig } from 'vite'; export default defineConfig({ - plugins: [workerdEnvironment('vite-plugin-cloudflare-workerd-env'), sveltekit()], + plugins: [sveltekit()], server: { fs: { allow: ['../../packages/kit'] From 665fb76f78215326d52f8384c1160447a44f60c8 Mon Sep 17 00:00:00 2001 From: James Opstad Date: Fri, 30 Aug 2024 11:38:33 +0100 Subject: [PATCH 22/61] Used runtime_base to resolve import in virtual module --- packages/kit/src/exports/vite/dev/index.js | 4 ---- packages/kit/src/exports/vite/index.js | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/kit/src/exports/vite/dev/index.js b/packages/kit/src/exports/vite/dev/index.js index 8051acfa40da..5245fd83a837 100644 --- a/packages/kit/src/exports/vite/dev/index.js +++ b/packages/kit/src/exports/vite/dev/index.js @@ -447,10 +447,6 @@ export async function dev(vite, vite_config, svelte_config, environment_context) const __dirname = fileURLToPath(new URL('.', import.meta.url)); - if (!devEnv) { - throw new Error('No Cloudflare dev environment is present'); - } - let handler; if (devEnv.api) { diff --git a/packages/kit/src/exports/vite/index.js b/packages/kit/src/exports/vite/index.js index 4f14bc3b28c1..114c09aeb097 100644 --- a/packages/kit/src/exports/vite/index.js +++ b/packages/kit/src/exports/vite/index.js @@ -520,7 +520,7 @@ async function kit({ svelte_config }) { const { manifest_data, env, remote_address } = environment_context; const manifest = dedent` - import { create_resolve } from '../../packages/kit/src/exports/vite/dev/utils.js' + import { create_resolve } from ${s(`${runtime_base}/../exports/vite/dev/utils.js`)}; const resolve = create_resolve(${s(cwd)}) From 2ebda302e1050ab47a2266413cc4a11382c8ff84 Mon Sep 17 00:00:00 2001 From: James Opstad Date: Fri, 30 Aug 2024 11:57:04 +0100 Subject: [PATCH 23/61] Simplified Cloudflare type imports --- packages/kit/package.json | 1 - packages/kit/src/exports/vite/dev/workerd_entrypoint.js | 2 +- playgrounds/vite-workerd-environment/src/app.d.ts | 6 ------ playgrounds/vite-workerd-environment/tsconfig.json | 1 + pnpm-lock.yaml | 3 --- 5 files changed, 2 insertions(+), 11 deletions(-) diff --git a/packages/kit/package.json b/packages/kit/package.json index 48f2e732b4b2..3de5aa1b3afc 100644 --- a/packages/kit/package.json +++ b/packages/kit/package.json @@ -33,7 +33,6 @@ "tiny-glob": "^0.2.9" }, "devDependencies": { - "@cloudflare/workers-types": "^4.20231121.0", "@playwright/test": "^1.44.1", "@sveltejs/vite-plugin-svelte": "^3.0.1", "@types/connect": "^3.4.38", diff --git a/packages/kit/src/exports/vite/dev/workerd_entrypoint.js b/packages/kit/src/exports/vite/dev/workerd_entrypoint.js index d2a7115fc6a1..7ad0eee79cfb 100644 --- a/packages/kit/src/exports/vite/dev/workerd_entrypoint.js +++ b/packages/kit/src/exports/vite/dev/workerd_entrypoint.js @@ -2,7 +2,7 @@ import { Server } from '../../../runtime/server/index.js'; export default { /** - * @param {Request & { cf?: import('@cloudflare/workers-types').IncomingRequestCfProperties }} request + * @param {Request & { cf: any }} request * @param {any} env * @param {any} context */ diff --git a/playgrounds/vite-workerd-environment/src/app.d.ts b/playgrounds/vite-workerd-environment/src/app.d.ts index 979f8f576b66..eddc939101a9 100644 --- a/playgrounds/vite-workerd-environment/src/app.d.ts +++ b/playgrounds/vite-workerd-environment/src/app.d.ts @@ -1,9 +1,3 @@ -import type { - CacheStorage, - ExecutionContext, - IncomingRequestCfProperties -} from '@cloudflare/workers-types'; - // See https://kit.svelte.dev/docs/types#app // for information about these interfaces declare global { diff --git a/playgrounds/vite-workerd-environment/tsconfig.json b/playgrounds/vite-workerd-environment/tsconfig.json index fc93cbd9409f..423423270e90 100644 --- a/playgrounds/vite-workerd-environment/tsconfig.json +++ b/playgrounds/vite-workerd-environment/tsconfig.json @@ -9,6 +9,7 @@ "skipLibCheck": true, "sourceMap": true, "strict": true, + "types": ["@cloudflare/workers-types"], "moduleResolution": "bundler" } // Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ff680a3b5286..63b9fde7c15a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -444,9 +444,6 @@ importers: specifier: ^0.2.9 version: 0.2.9 devDependencies: - '@cloudflare/workers-types': - specifier: ^4.20231121.0 - version: 4.20240405.0 '@playwright/test': specifier: ^1.44.1 version: 1.44.1 From b7b36e1358e6b3e379f5298af2ae60dd04ec37aa Mon Sep 17 00:00:00 2001 From: James Opstad Date: Fri, 30 Aug 2024 12:23:34 +0100 Subject: [PATCH 24/61] Resolved typescript errors --- .../exports/vite/dev/default_environment.js | 1 + packages/kit/src/exports/vite/dev/index.js | 97 +++++++++---------- packages/kit/src/exports/vite/index.js | 3 +- packages/kit/types/index.d.ts | 17 ++-- 4 files changed, 59 insertions(+), 59 deletions(-) diff --git a/packages/kit/src/exports/vite/dev/default_environment.js b/packages/kit/src/exports/vite/dev/default_environment.js index c6f34ae45be5..fe9793492d0b 100644 --- a/packages/kit/src/exports/vite/dev/default_environment.js +++ b/packages/kit/src/exports/vite/dev/default_environment.js @@ -8,6 +8,7 @@ export function default_environment(environment_name) { return [ { name: 'default-environment-plugin', + // @ts-ignore should the options parameter for createNodeDevEnvironment be optional? config: () => { return { environments: { diff --git a/packages/kit/src/exports/vite/dev/index.js b/packages/kit/src/exports/vite/dev/index.js index 5245fd83a837..be96f77782f0 100644 --- a/packages/kit/src/exports/vite/dev/index.js +++ b/packages/kit/src/exports/vite/dev/index.js @@ -4,16 +4,15 @@ import { fileURLToPath, URL } from 'node:url'; import { AsyncLocalStorage } from 'node:async_hooks'; import colors from 'kleur'; import sirv from 'sirv'; -import { isCSSRequest, loadEnv, buildErrorMessage, createServerModuleRunner } from 'vite'; -import { createReadableStream, getRequest, setResponse } from '../../../exports/node/index.js'; +import { loadEnv, createServerModuleRunner } from 'vite'; +import { getRequest, setResponse } from '../../../exports/node/index.js'; import { installPolyfills } from '../../../exports/node/polyfills.js'; import { coalesce_to_error } from '../../../utils/error.js'; -import { from_fs, posixify, resolve_entry, to_fs } from '../../../utils/filesystem.js'; +import { posixify, resolve_entry, to_fs } from '../../../utils/filesystem.js'; import { load_error_page } from '../../../core/config/index.js'; import { SVELTE_KIT_ASSETS } from '../../../constants.js'; import * as sync from '../../../core/sync/sync.js'; -import { get_mime_lookup, runtime_base } from '../../../core/utils.js'; -import { compact } from '../../../utils/array.js'; +import { runtime_base } from '../../../core/utils.js'; import { not_found } from '../utils.js'; import { SCHEME } from '../../../utils/url.js'; import { check_feature } from '../../../utils/features.js'; @@ -103,7 +102,7 @@ export async function dev(vite, vite_config, svelte_config, environment_context) // return { module, module_node, url }; // } - // this doesn't seem to be needed + // this may not be needed function invalidate_environment_context_module() { for (const environment in vite.environments) { const module = vite.environments[environment].moduleGraph.getModuleById( @@ -120,7 +119,7 @@ export async function dev(vite, vite_config, svelte_config, environment_context) try { environment_context.manifest_data = sync.create(svelte_config).manifest_data; - // invalidate_environment_context_module(); + invalidate_environment_context_module(); if (manifest_error) { manifest_error = null; @@ -609,48 +608,48 @@ function remove_static_middlewares(server) { } } -/** - * @param {import('vite').ViteDevServer} vite - * @param {import('vite').ModuleNode} node - * @param {Set} 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[]} */ - const branches = []; - - /** @param {import('vite').ModuleNode} node */ - async function add(node) { - if (!deps.has(node)) { - deps.add(node); - await find_deps(vite, node, deps); - } - } - - /** @param {string} url */ - async function add_by_url(url) { - const node = await vite.moduleGraph.getModuleByUrl(url); - - if (node) { - await add(node); - } - } - - if (node.ssrTransformResult) { - if (node.ssrTransformResult.deps) { - node.ssrTransformResult.deps.forEach((url) => branches.push(add_by_url(url))); - } - - if (node.ssrTransformResult.dynamicDeps) { - node.ssrTransformResult.dynamicDeps.forEach((url) => branches.push(add_by_url(url))); - } - } else { - node.importedModules.forEach((node) => branches.push(add(node))); - } - - await Promise.all(branches); -} +// /** +// * @param {import('vite').ViteDevServer} vite +// * @param {import('vite').ModuleNode} node +// * @param {Set} 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[]} */ +// const branches = []; + +// /** @param {import('vite').ModuleNode} node */ +// async function add(node) { +// if (!deps.has(node)) { +// deps.add(node); +// await find_deps(vite, node, deps); +// } +// } + +// /** @param {string} url */ +// async function add_by_url(url) { +// const node = await vite.moduleGraph.getModuleByUrl(url); + +// if (node) { +// await add(node); +// } +// } + +// if (node.ssrTransformResult) { +// if (node.ssrTransformResult.deps) { +// node.ssrTransformResult.deps.forEach((url) => branches.push(add_by_url(url))); +// } + +// if (node.ssrTransformResult.dynamicDeps) { +// node.ssrTransformResult.dynamicDeps.forEach((url) => branches.push(add_by_url(url))); +// } +// } else { +// node.importedModules.forEach((node) => branches.push(add(node))); +// } + +// await Promise.all(branches); +// } /** * Determine if a file is being requested with the correct case, diff --git a/packages/kit/src/exports/vite/index.js b/packages/kit/src/exports/vite/index.js index 114c09aeb097..6fa0c75a163f 100644 --- a/packages/kit/src/exports/vite/index.js +++ b/packages/kit/src/exports/vite/index.js @@ -46,8 +46,7 @@ import { import { resolve_peer_dependency } from '../../utils/import.js'; import { SSR_ENVIRONMENT_NAME } from './constants.js'; -/** @type {import('types').EnvironmentContext} */ -const environment_context = {}; +const environment_context = /** @type {import('types').EnvironmentContext} */ ({}); const cwd = process.cwd(); diff --git a/packages/kit/types/index.d.ts b/packages/kit/types/index.d.ts index 687ac768e331..caaa8b4a53f4 100644 --- a/packages/kit/types/index.d.ts +++ b/packages/kit/types/index.d.ts @@ -2,6 +2,7 @@ /// declare module '@sveltejs/kit' { + import type { Plugin } from 'vite'; import type { CompileOptions } from 'svelte/compiler'; import type { PluginOptions } from '@sveltejs/vite-plugin-svelte'; /** @@ -37,8 +38,8 @@ declare module '@sveltejs/kit' { export type LoadProperties | void> = input extends void ? undefined // needs to be undefined, because void will break intellisense : input extends Record - ? input - : unknown; + ? input + : unknown; export type AwaitedActions any>> = OptionalUnion< { @@ -61,12 +62,11 @@ declare module '@sveltejs/kit' { [uniqueSymbol]: true; // necessary or else UnpackValidationError could wrongly unpack objects with the same shape as ActionFailure } - type UnpackValidationError = - T extends ActionFailure - ? X - : T extends void - ? undefined // needs to be undefined, because void will corrupt union type - : T; + type UnpackValidationError = T extends ActionFailure + ? X + : T extends void + ? undefined // needs to be undefined, because void will corrupt union type + : T; /** * This object is passed to the `adapt` function of adapters. @@ -600,6 +600,7 @@ declare module '@sveltejs/kit' { */ files?(filepath: string): boolean; }; + ssrEnvironment?: (environmentName: string, options: any) => Plugin[]; typescript?: { /** * A function that allows you to edit the generated `tsconfig.json`. You can mutate the config (recommended) or return a new one. From d00737b6dbd7db1009ba59011ae51cd03326ffdf Mon Sep 17 00:00:00 2001 From: James Opstad Date: Fri, 30 Aug 2024 12:33:13 +0100 Subject: [PATCH 25/61] Asserted platform types in playground --- .../vite-workerd-environment/src/routes/+page.server.ts | 6 +++--- .../src/routes/cf-properties/[[key]]/+page.server.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/playgrounds/vite-workerd-environment/src/routes/+page.server.ts b/playgrounds/vite-workerd-environment/src/routes/+page.server.ts index 4b9e76060c47..9d317e0a0246 100644 --- a/playgrounds/vite-workerd-environment/src/routes/+page.server.ts +++ b/playgrounds/vite-workerd-environment/src/routes/+page.server.ts @@ -11,7 +11,7 @@ function getUserAgentText(): string { const KEY = '__my-key__'; export async function load({ platform }: PageServerLoadEvent) { - const { MY_KV } = platform.env; + const { MY_KV } = platform!.env; const value = await MY_KV.get(KEY); return { userAgentText: getUserAgentText(), value: value === 'null' ? null : value }; @@ -19,7 +19,7 @@ export async function load({ platform }: PageServerLoadEvent) { export const actions = { create: async ({ request, platform }) => { - const { MY_KV } = platform.env; + const { MY_KV } = platform!.env; const formData = await request.formData(); const value = formData.get('value') as string; await MY_KV.put(KEY, value); @@ -27,7 +27,7 @@ export const actions = { return null; }, delete: async ({ platform }) => { - const { MY_KV } = platform.env; + const { MY_KV } = platform!.env; await MY_KV.delete(KEY); return null; diff --git a/playgrounds/vite-workerd-environment/src/routes/cf-properties/[[key]]/+page.server.ts b/playgrounds/vite-workerd-environment/src/routes/cf-properties/[[key]]/+page.server.ts index 89a248cc511b..fab82ebd2508 100644 --- a/playgrounds/vite-workerd-environment/src/routes/cf-properties/[[key]]/+page.server.ts +++ b/playgrounds/vite-workerd-environment/src/routes/cf-properties/[[key]]/+page.server.ts @@ -1,7 +1,7 @@ import type { PageServerLoadEvent } from './$types'; export function load({ params, platform }: PageServerLoadEvent) { - const cf = platform.cf; + const cf = platform!.cf; const key = params?.key; const value = key && key in cf ? JSON.stringify(cf[key]) : undefined; From c0a478c904a81298bce639d0e8896e884a9936fb Mon Sep 17 00:00:00 2001 From: James Opstad Date: Fri, 30 Aug 2024 13:58:47 +0100 Subject: [PATCH 26/61] Updated vite to alpha.23 --- package.json | 2 +- pnpm-lock.yaml | 530 +++++++++++++++++++++++++++++++++---------------- 2 files changed, 355 insertions(+), 177 deletions(-) diff --git a/package.json b/package.json index 46e12aebb992..a95e1a5679a8 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ }, "pnpm": { "overrides": { - "vite": "6.0.0-alpha.18" + "vite": "6.0.0-alpha.23" } }, "packageManager": "pnpm@9.9.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 85737175349d..91a473750e95 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5,7 +5,7 @@ settings: excludeLinksFromLockfile: false overrides: - vite: 6.0.0-alpha.18 + vite: 6.0.0-alpha.23 importers: @@ -41,7 +41,7 @@ importers: version: link:../kit '@sveltejs/vite-plugin-svelte': specifier: ^3.0.1 - version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) + version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)) '@types/node': specifier: ^18.19.3 version: 18.19.31 @@ -134,7 +134,7 @@ importers: version: link:../kit '@sveltejs/vite-plugin-svelte': specifier: ^3.0.1 - version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) + version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)) '@types/node': specifier: ^18.19.3 version: 18.19.31 @@ -174,7 +174,7 @@ importers: version: link:../kit '@sveltejs/vite-plugin-svelte': specifier: ^3.0.1 - version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) + version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)) '@types/node': specifier: ^18.19.3 version: 18.19.31 @@ -201,7 +201,7 @@ importers: version: link:../kit '@sveltejs/vite-plugin-svelte': specifier: ^3.0.1 - version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) + version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)) '@types/node': specifier: ^18.19.3 version: 18.19.31 @@ -215,8 +215,8 @@ importers: specifier: ^5.3.3 version: 5.4.5 vite: - specifier: 6.0.0-alpha.18 - version: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) + specifier: 6.0.0-alpha.23 + version: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) packages/adapter-static/test/apps/prerendered: devDependencies: @@ -225,7 +225,7 @@ importers: version: link:../../../../kit '@sveltejs/vite-plugin-svelte': specifier: ^3.0.1 - version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) + version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)) sirv-cli: specifier: ^2.0.2 version: 2.0.2 @@ -233,8 +233,8 @@ importers: specifier: ^4.2.10 version: 4.2.17 vite: - specifier: 6.0.0-alpha.18 - version: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) + specifier: 6.0.0-alpha.23 + version: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) packages/adapter-static/test/apps/spa: devDependencies: @@ -246,7 +246,7 @@ importers: version: link:../../../../kit '@sveltejs/vite-plugin-svelte': specifier: ^3.0.1 - version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) + version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)) sirv-cli: specifier: ^2.0.2 version: 2.0.2 @@ -254,8 +254,8 @@ importers: specifier: ^4.2.10 version: 4.2.17 vite: - specifier: 6.0.0-alpha.18 - version: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) + specifier: 6.0.0-alpha.23 + version: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) packages/adapter-vercel: dependencies: @@ -271,7 +271,7 @@ importers: version: link:../kit '@sveltejs/vite-plugin-svelte': specifier: ^3.0.1 - version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) + version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)) '@types/node': specifier: ^18.19.3 version: 18.19.31 @@ -286,7 +286,7 @@ importers: dependencies: '@sveltejs/kit': specifier: ^1.0.0 || ^2.0.0 - version: 2.5.24(@sveltejs/vite-plugin-svelte@3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)))(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) + version: 2.5.24(@sveltejs/vite-plugin-svelte@3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)))(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)) devDependencies: typescript: specifier: ^5.3.3 @@ -348,7 +348,7 @@ importers: version: link:../../../kit '@sveltejs/vite-plugin-svelte': specifier: ^3.0.0 - version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) + version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)) svelte: specifier: ^4.2.10 version: 4.2.17 @@ -356,8 +356,8 @@ importers: specifier: ^5.3.3 version: 5.4.5 vite: - specifier: 6.0.0-alpha.18 - version: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) + specifier: 6.0.0-alpha.23 + version: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) packages/create-svelte/templates/skeleton: devDependencies: @@ -396,8 +396,8 @@ importers: specifier: ^5.3.3 version: 5.4.5 vite: - specifier: 6.0.0-alpha.18 - version: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) + specifier: 6.0.0-alpha.23 + version: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) vitest: specifier: ^2.0.1 version: 2.0.1(@types/node@18.19.31)(lightningcss@1.24.1) @@ -449,7 +449,7 @@ importers: version: 1.44.1 '@sveltejs/vite-plugin-svelte': specifier: ^3.0.1 - version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) + version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)) '@types/connect': specifier: ^3.4.38 version: 3.4.38 @@ -470,13 +470,13 @@ importers: version: 4.2.17 svelte-preprocess: specifier: ^6.0.0 - version: 6.0.0(postcss-load-config@3.1.4(postcss@8.4.39))(postcss@8.4.39)(svelte@4.2.17)(typescript@5.4.5) + version: 6.0.0(postcss-load-config@3.1.4(postcss@8.4.41))(postcss@8.4.41)(svelte@4.2.17)(typescript@5.4.5) typescript: specifier: ^5.3.3 version: 5.4.5 vite: - specifier: 6.0.0-alpha.18 - version: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) + specifier: 6.0.0-alpha.23 + version: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) vitest: specifier: ^2.0.1 version: 2.0.1(@types/node@18.19.31)(lightningcss@1.24.1) @@ -491,7 +491,7 @@ importers: version: link:../../.. '@sveltejs/vite-plugin-svelte': specifier: ^3.0.1 - version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) + version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)) cross-env: specifier: ^7.0.3 version: 7.0.3 @@ -503,13 +503,13 @@ importers: version: 4.2.17 svelte-check: specifier: ^3.6.3 - version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.39))(postcss@8.4.39)(svelte@4.2.17) + version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.41))(postcss@8.4.41)(svelte@4.2.17) typescript: specifier: ^5.3.3 version: 5.4.5 vite: - specifier: 6.0.0-alpha.18 - version: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) + specifier: 6.0.0-alpha.23 + version: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) packages/kit/test/apps/basics: devDependencies: @@ -518,7 +518,7 @@ importers: version: link:../../.. '@sveltejs/vite-plugin-svelte': specifier: ^3.0.1 - version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) + version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)) cross-env: specifier: ^7.0.3 version: 7.0.3 @@ -530,13 +530,13 @@ importers: version: 4.2.17 svelte-check: specifier: ^3.6.3 - version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.39))(postcss@8.4.39)(svelte@4.2.17) + version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.41))(postcss@8.4.41)(svelte@4.2.17) typescript: specifier: ^5.3.3 version: 5.4.5 vite: - specifier: 6.0.0-alpha.18 - version: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) + specifier: 6.0.0-alpha.23 + version: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) packages/kit/test/apps/dev-only: devDependencies: @@ -545,7 +545,7 @@ importers: version: link:../../.. '@sveltejs/vite-plugin-svelte': specifier: ^3.0.1 - version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) + version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)) cross-env: specifier: ^7.0.3 version: 7.0.3 @@ -584,13 +584,13 @@ importers: version: 4.2.17 svelte-check: specifier: ^3.6.3 - version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.39))(postcss@8.4.39)(svelte@4.2.17) + version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.41))(postcss@8.4.41)(svelte@4.2.17) typescript: specifier: ^5.3.3 version: 5.4.5 vite: - specifier: 6.0.0-alpha.18 - version: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) + specifier: 6.0.0-alpha.23 + version: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) packages/kit/test/apps/embed: devDependencies: @@ -599,7 +599,7 @@ importers: version: link:../../.. '@sveltejs/vite-plugin-svelte': specifier: ^3.0.1 - version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) + version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)) cross-env: specifier: ^7.0.3 version: 7.0.3 @@ -608,13 +608,13 @@ importers: version: 4.2.17 svelte-check: specifier: ^3.6.3 - version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.39))(postcss@8.4.39)(svelte@4.2.17) + version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.41))(postcss@8.4.41)(svelte@4.2.17) typescript: specifier: ^5.3.3 version: 5.4.5 vite: - specifier: 6.0.0-alpha.18 - version: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) + specifier: 6.0.0-alpha.23 + version: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) packages/kit/test/apps/no-ssr: devDependencies: @@ -623,7 +623,7 @@ importers: version: link:../../.. '@sveltejs/vite-plugin-svelte': specifier: ^3.0.1 - version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) + version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)) cross-env: specifier: ^7.0.3 version: 7.0.3 @@ -632,13 +632,13 @@ importers: version: 4.2.17 svelte-check: specifier: ^3.6.3 - version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.39))(postcss@8.4.39)(svelte@4.2.17) + version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.41))(postcss@8.4.41)(svelte@4.2.17) typescript: specifier: ^5.3.3 version: 5.4.5 vite: - specifier: 6.0.0-alpha.18 - version: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) + specifier: 6.0.0-alpha.23 + version: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) packages/kit/test/apps/options: devDependencies: @@ -647,7 +647,7 @@ importers: version: link:../../.. '@sveltejs/vite-plugin-svelte': specifier: ^3.0.1 - version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) + version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)) cross-env: specifier: ^7.0.3 version: 7.0.3 @@ -656,13 +656,13 @@ importers: version: 4.2.17 svelte-check: specifier: ^3.6.3 - version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.39))(postcss@8.4.39)(svelte@4.2.17) + version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.41))(postcss@8.4.41)(svelte@4.2.17) typescript: specifier: ^5.3.3 version: 5.4.5 vite: - specifier: 6.0.0-alpha.18 - version: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) + specifier: 6.0.0-alpha.23 + version: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) packages/kit/test/apps/options-2: devDependencies: @@ -674,7 +674,7 @@ importers: version: link:../../.. '@sveltejs/vite-plugin-svelte': specifier: ^3.0.1 - version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) + version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)) cross-env: specifier: ^7.0.3 version: 7.0.3 @@ -683,13 +683,13 @@ importers: version: 4.2.17 svelte-check: specifier: ^3.6.3 - version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.39))(postcss@8.4.39)(svelte@4.2.17) + version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.41))(postcss@8.4.41)(svelte@4.2.17) typescript: specifier: ^5.3.3 version: 5.4.5 vite: - specifier: 6.0.0-alpha.18 - version: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) + specifier: 6.0.0-alpha.23 + version: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) packages/kit/test/apps/writes: devDependencies: @@ -698,7 +698,7 @@ importers: version: link:../../.. '@sveltejs/vite-plugin-svelte': specifier: ^3.0.1 - version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) + version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)) cross-env: specifier: ^7.0.3 version: 7.0.3 @@ -707,13 +707,13 @@ importers: version: 4.2.17 svelte-check: specifier: ^3.6.3 - version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.39))(postcss@8.4.39)(svelte@4.2.17) + version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.41))(postcss@8.4.41)(svelte@4.2.17) typescript: specifier: ^5.3.3 version: 5.4.5 vite: - specifier: 6.0.0-alpha.18 - version: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) + specifier: 6.0.0-alpha.23 + version: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) packages/kit/test/build-errors: devDependencies: @@ -731,19 +731,19 @@ importers: version: link:../../../.. '@sveltejs/vite-plugin-svelte': specifier: ^3.0.1 - version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) + version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)) svelte: specifier: ^4.2.10 version: 4.2.17 svelte-check: specifier: ^3.6.3 - version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.39))(postcss@8.4.39)(svelte@4.2.17) + version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.41))(postcss@8.4.41)(svelte@4.2.17) typescript: specifier: ^5.3.3 version: 5.4.5 vite: - specifier: 6.0.0-alpha.18 - version: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) + specifier: 6.0.0-alpha.23 + version: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) packages/kit/test/build-errors/apps/prerenderable-incorrect-fragment: devDependencies: @@ -755,19 +755,19 @@ importers: version: link:../../../.. '@sveltejs/vite-plugin-svelte': specifier: ^3.0.1 - version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) + version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)) svelte: specifier: ^4.2.10 version: 4.2.17 svelte-check: specifier: ^3.6.3 - version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.39))(postcss@8.4.39)(svelte@4.2.17) + version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.41))(postcss@8.4.41)(svelte@4.2.17) typescript: specifier: ^5.3.3 version: 5.4.5 vite: - specifier: 6.0.0-alpha.18 - version: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) + specifier: 6.0.0-alpha.23 + version: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) packages/kit/test/build-errors/apps/prerenderable-not-prerendered: devDependencies: @@ -779,19 +779,19 @@ importers: version: link:../../../.. '@sveltejs/vite-plugin-svelte': specifier: ^3.0.1 - version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) + version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)) svelte: specifier: ^4.2.10 version: 4.2.17 svelte-check: specifier: ^3.6.3 - version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.39))(postcss@8.4.39)(svelte@4.2.17) + version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.41))(postcss@8.4.41)(svelte@4.2.17) typescript: specifier: ^5.3.3 version: 5.4.5 vite: - specifier: 6.0.0-alpha.18 - version: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) + specifier: 6.0.0-alpha.23 + version: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) packages/kit/test/build-errors/apps/private-dynamic-env: devDependencies: @@ -800,19 +800,19 @@ importers: version: link:../../../.. '@sveltejs/vite-plugin-svelte': specifier: ^3.0.1 - version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) + version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)) svelte: specifier: ^4.2.10 version: 4.2.17 svelte-check: specifier: ^3.6.3 - version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.39))(postcss@8.4.39)(svelte@4.2.17) + version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.41))(postcss@8.4.41)(svelte@4.2.17) typescript: specifier: ^5.3.3 version: 5.4.5 vite: - specifier: 6.0.0-alpha.18 - version: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) + specifier: 6.0.0-alpha.23 + version: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) packages/kit/test/build-errors/apps/private-dynamic-env-dynamic-import: devDependencies: @@ -821,19 +821,19 @@ importers: version: link:../../../.. '@sveltejs/vite-plugin-svelte': specifier: ^3.0.1 - version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) + version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)) svelte: specifier: ^4.2.10 version: 4.2.17 svelte-check: specifier: ^3.6.3 - version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.39))(postcss@8.4.39)(svelte@4.2.17) + version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.41))(postcss@8.4.41)(svelte@4.2.17) typescript: specifier: ^5.3.3 version: 5.4.5 vite: - specifier: 6.0.0-alpha.18 - version: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) + specifier: 6.0.0-alpha.23 + version: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) packages/kit/test/build-errors/apps/private-static-env: devDependencies: @@ -842,7 +842,7 @@ importers: version: link:../../../.. '@sveltejs/vite-plugin-svelte': specifier: ^3.0.1 - version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) + version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)) cross-env: specifier: ^7.0.3 version: 7.0.3 @@ -851,13 +851,13 @@ importers: version: 4.2.17 svelte-check: specifier: ^3.6.3 - version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.39))(postcss@8.4.39)(svelte@4.2.17) + version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.41))(postcss@8.4.41)(svelte@4.2.17) typescript: specifier: ^5.3.3 version: 5.4.5 vite: - specifier: 6.0.0-alpha.18 - version: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) + specifier: 6.0.0-alpha.23 + version: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) packages/kit/test/build-errors/apps/private-static-env-dynamic-import: devDependencies: @@ -866,19 +866,19 @@ importers: version: link:../../../.. '@sveltejs/vite-plugin-svelte': specifier: ^3.0.1 - version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) + version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)) svelte: specifier: ^4.2.10 version: 4.2.17 svelte-check: specifier: ^3.6.3 - version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.39))(postcss@8.4.39)(svelte@4.2.17) + version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.41))(postcss@8.4.41)(svelte@4.2.17) typescript: specifier: ^5.3.3 version: 5.4.5 vite: - specifier: 6.0.0-alpha.18 - version: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) + specifier: 6.0.0-alpha.23 + version: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) packages/kit/test/build-errors/apps/server-only-folder: devDependencies: @@ -887,19 +887,19 @@ importers: version: link:../../../.. '@sveltejs/vite-plugin-svelte': specifier: ^3.0.1 - version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) + version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)) svelte: specifier: ^4.2.10 version: 4.2.17 svelte-check: specifier: ^3.6.3 - version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.39))(postcss@8.4.39)(svelte@4.2.17) + version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.41))(postcss@8.4.41)(svelte@4.2.17) typescript: specifier: ^5.3.3 version: 5.4.5 vite: - specifier: 6.0.0-alpha.18 - version: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) + specifier: 6.0.0-alpha.23 + version: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) packages/kit/test/build-errors/apps/server-only-folder-dynamic-import: devDependencies: @@ -908,19 +908,19 @@ importers: version: link:../../../.. '@sveltejs/vite-plugin-svelte': specifier: ^3.0.1 - version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) + version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)) svelte: specifier: ^4.2.10 version: 4.2.17 svelte-check: specifier: ^3.6.3 - version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.39))(postcss@8.4.39)(svelte@4.2.17) + version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.41))(postcss@8.4.41)(svelte@4.2.17) typescript: specifier: ^5.3.3 version: 5.4.5 vite: - specifier: 6.0.0-alpha.18 - version: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) + specifier: 6.0.0-alpha.23 + version: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) packages/kit/test/build-errors/apps/server-only-module: devDependencies: @@ -929,19 +929,19 @@ importers: version: link:../../../.. '@sveltejs/vite-plugin-svelte': specifier: ^3.0.1 - version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) + version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)) svelte: specifier: ^4.2.10 version: 4.2.17 svelte-check: specifier: ^3.6.3 - version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.39))(postcss@8.4.39)(svelte@4.2.17) + version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.41))(postcss@8.4.41)(svelte@4.2.17) typescript: specifier: ^5.3.3 version: 5.4.5 vite: - specifier: 6.0.0-alpha.18 - version: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) + specifier: 6.0.0-alpha.23 + version: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) packages/kit/test/build-errors/apps/server-only-module-dynamic-import: devDependencies: @@ -950,19 +950,19 @@ importers: version: link:../../../.. '@sveltejs/vite-plugin-svelte': specifier: ^3.0.1 - version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) + version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)) svelte: specifier: ^4.2.10 version: 4.2.17 svelte-check: specifier: ^3.6.3 - version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.39))(postcss@8.4.39)(svelte@4.2.17) + version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.41))(postcss@8.4.41)(svelte@4.2.17) typescript: specifier: ^5.3.3 version: 5.4.5 vite: - specifier: 6.0.0-alpha.18 - version: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) + specifier: 6.0.0-alpha.23 + version: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) packages/kit/test/build-errors/apps/service-worker-dynamic-public-env: devDependencies: @@ -971,19 +971,19 @@ importers: version: link:../../../.. '@sveltejs/vite-plugin-svelte': specifier: ^3.0.1 - version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) + version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)) svelte: specifier: ^4.2.10 version: 4.2.17 svelte-check: specifier: ^3.6.3 - version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.39))(postcss@8.4.39)(svelte@4.2.17) + version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.41))(postcss@8.4.41)(svelte@4.2.17) typescript: specifier: ^5.3.3 version: 5.4.5 vite: - specifier: 6.0.0-alpha.18 - version: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) + specifier: 6.0.0-alpha.23 + version: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) packages/kit/test/build-errors/apps/service-worker-private-env: devDependencies: @@ -992,19 +992,19 @@ importers: version: link:../../../.. '@sveltejs/vite-plugin-svelte': specifier: ^3.0.1 - version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) + version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)) svelte: specifier: ^4.2.10 version: 4.2.17 svelte-check: specifier: ^3.6.3 - version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.39))(postcss@8.4.39)(svelte@4.2.17) + version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.41))(postcss@8.4.41)(svelte@4.2.17) typescript: specifier: ^5.3.3 version: 5.4.5 vite: - specifier: 6.0.0-alpha.18 - version: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) + specifier: 6.0.0-alpha.23 + version: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) packages/kit/test/build-errors/apps/syntax-error: devDependencies: @@ -1013,19 +1013,19 @@ importers: version: link:../../../.. '@sveltejs/vite-plugin-svelte': specifier: ^3.0.1 - version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) + version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)) svelte: specifier: ^4.2.10 version: 4.2.17 svelte-check: specifier: ^3.6.3 - version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.39))(postcss@8.4.39)(svelte@4.2.17) + version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.41))(postcss@8.4.41)(svelte@4.2.17) typescript: specifier: ^5.3.3 version: 5.4.5 vite: - specifier: 6.0.0-alpha.18 - version: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) + specifier: 6.0.0-alpha.23 + version: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) packages/kit/test/prerendering/basics: devDependencies: @@ -1034,19 +1034,19 @@ importers: version: link:../../.. '@sveltejs/vite-plugin-svelte': specifier: ^3.0.1 - version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) + version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)) svelte: specifier: ^4.2.10 version: 4.2.17 svelte-check: specifier: ^3.6.3 - version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.39))(postcss@8.4.39)(svelte@4.2.17) + version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.41))(postcss@8.4.41)(svelte@4.2.17) typescript: specifier: ^5.3.3 version: 5.4.5 vite: - specifier: 6.0.0-alpha.18 - version: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) + specifier: 6.0.0-alpha.23 + version: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) vitest: specifier: ^2.0.1 version: 2.0.1(@types/node@18.19.31)(lightningcss@1.24.1) @@ -1058,19 +1058,19 @@ importers: version: link:../../.. '@sveltejs/vite-plugin-svelte': specifier: ^3.0.1 - version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) + version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)) svelte: specifier: ^4.2.10 version: 4.2.17 svelte-check: specifier: ^3.6.3 - version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.39))(postcss@8.4.39)(svelte@4.2.17) + version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.41))(postcss@8.4.41)(svelte@4.2.17) typescript: specifier: ^5.3.3 version: 5.4.5 vite: - specifier: 6.0.0-alpha.18 - version: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) + specifier: 6.0.0-alpha.23 + version: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) vitest: specifier: ^2.0.1 version: 2.0.1(@types/node@18.19.31)(lightningcss@1.24.1) @@ -1082,19 +1082,19 @@ importers: version: link:../../.. '@sveltejs/vite-plugin-svelte': specifier: ^3.0.1 - version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) + version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)) svelte: specifier: ^4.2.10 version: 4.2.17 svelte-check: specifier: ^3.6.3 - version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.39))(postcss@8.4.39)(svelte@4.2.17) + version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.41))(postcss@8.4.41)(svelte@4.2.17) typescript: specifier: ^5.3.3 version: 5.4.5 vite: - specifier: 6.0.0-alpha.18 - version: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) + specifier: 6.0.0-alpha.23 + version: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) vitest: specifier: ^2.0.1 version: 2.0.1(@types/node@18.19.31)(lightningcss@1.24.1) @@ -1168,7 +1168,7 @@ importers: devDependencies: '@sveltejs/vite-plugin-svelte': specifier: ^3.0.1 - version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) + version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)) '@types/node': specifier: ^18.19.3 version: 18.19.31 @@ -1180,7 +1180,7 @@ importers: version: 4.2.17 svelte-preprocess: specifier: ^6.0.0 - version: 6.0.0(postcss-load-config@3.1.4(postcss@8.4.39))(postcss@8.4.39)(svelte@4.2.17)(typescript@5.4.5) + version: 6.0.0(postcss-load-config@3.1.4(postcss@8.4.41))(postcss@8.4.41)(svelte@4.2.17)(typescript@5.4.5) typescript: specifier: ^5.3.3 version: 5.4.5 @@ -1222,7 +1222,7 @@ importers: version: link:../../packages/package '@sveltejs/vite-plugin-svelte': specifier: ^3.0.1 - version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) + version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)) publint: specifier: ^0.2.0 version: 0.2.7 @@ -1231,13 +1231,13 @@ importers: version: 4.2.17 svelte-check: specifier: ^3.6.3 - version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.39))(postcss@8.4.39)(svelte@4.2.17) + version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.41))(postcss@8.4.41)(svelte@4.2.17) typescript: specifier: ^5.3.3 version: 5.4.5 vite: - specifier: 6.0.0-alpha.18 - version: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) + specifier: 6.0.0-alpha.23 + version: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) playgrounds/vite-node-environment: devDependencies: @@ -1273,7 +1273,7 @@ importers: version: link:../../packages/package '@sveltejs/vite-plugin-svelte': specifier: ^3.0.1 - version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) + version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)) publint: specifier: ^0.2.0 version: 0.2.7 @@ -1282,13 +1282,13 @@ importers: version: 4.2.17 svelte-check: specifier: ^3.6.3 - version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.39))(postcss@8.4.39)(svelte@4.2.17) + version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.41))(postcss@8.4.41)(svelte@4.2.17) typescript: specifier: ^5.3.3 version: 5.4.5 vite: - specifier: 6.0.0-alpha.18 - version: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) + specifier: 6.0.0-alpha.23 + version: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) playgrounds/vite-workerd-environment: devDependencies: @@ -1297,7 +1297,7 @@ importers: version: 4.20240405.0 '@dario-hacking/vite-6-alpha-environment-provider-workerd': specifier: ^0.0.5 - version: 0.0.5(miniflare@3.20240821.0)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1))(wrangler@3.72.3(@cloudflare/workers-types@4.20240405.0)) + version: 0.0.5(miniflare@3.20240821.0)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1))(wrangler@3.72.3(@cloudflare/workers-types@4.20240405.0)) '@sveltejs/adapter-auto': specifier: workspace:* version: link:../../packages/adapter-auto @@ -1330,7 +1330,7 @@ importers: version: link:../../packages/package '@sveltejs/vite-plugin-svelte': specifier: ^3.0.1 - version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) + version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)) publint: specifier: ^0.2.0 version: 0.2.7 @@ -1339,13 +1339,13 @@ importers: version: 4.2.17 svelte-check: specifier: ^3.6.3 - version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.39))(postcss@8.4.39)(svelte@4.2.17) + version: 3.6.9(postcss-load-config@3.1.4(postcss@8.4.41))(postcss@8.4.41)(svelte@4.2.17) typescript: specifier: ^5.3.3 version: 5.4.5 vite: - specifier: 6.0.0-alpha.18 - version: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) + specifier: 6.0.0-alpha.23 + version: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) wrangler: specifier: ^3.72.3 version: 3.72.3(@cloudflare/workers-types@4.20240405.0) @@ -1379,7 +1379,7 @@ importers: version: 6.0.0-next.64(@sveltejs/kit@packages+kit)(svelte@4.2.17) '@sveltejs/vite-plugin-svelte': specifier: ^3.0.1 - version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) + version: 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)) '@types/d3-geo': specifier: ^3.1.0 version: 3.1.0 @@ -1423,8 +1423,8 @@ importers: specifier: 5.0.4 version: 5.0.4 vite: - specifier: 6.0.0-alpha.18 - version: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) + specifier: 6.0.0-alpha.23 + version: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) vitest: specifier: ^2.0.1 version: 2.0.1(@types/node@18.19.31)(lightningcss@1.24.1) @@ -1588,7 +1588,7 @@ packages: resolution: {integrity: sha512-9SXOJDE4IGszLG0cRzU38OLSXyJhKkmnzoeNYPua142bvb5XCeL9zNGqXk4sjQfVd7Dhh+iut89a3ubROhkPwg==} peerDependencies: miniflare: ^3.20240129.3 - vite: 6.0.0-alpha.18 + vite: 6.0.0-alpha.23 wrangler: ^3.57.2 '@emnapi/runtime@1.2.0': @@ -2157,81 +2157,161 @@ packages: cpu: [arm] os: [android] + '@rollup/rollup-android-arm-eabi@4.21.2': + resolution: {integrity: sha512-fSuPrt0ZO8uXeS+xP3b+yYTCBUd05MoSp2N/MFOgjhhUhMmchXlpTQrTpI8T+YAwAQuK7MafsCOxW7VrPMrJcg==} + cpu: [arm] + os: [android] + '@rollup/rollup-android-arm64@4.18.0': resolution: {integrity: sha512-avCea0RAP03lTsDhEyfy+hpfr85KfyTctMADqHVhLAF3MlIkq83CP8UfAHUssgXTYd+6er6PaAhx/QGv4L1EiA==} cpu: [arm64] os: [android] + '@rollup/rollup-android-arm64@4.21.2': + resolution: {integrity: sha512-xGU5ZQmPlsjQS6tzTTGwMsnKUtu0WVbl0hYpTPauvbRAnmIvpInhJtgjj3mcuJpEiuUw4v1s4BimkdfDWlh7gA==} + cpu: [arm64] + os: [android] + '@rollup/rollup-darwin-arm64@4.18.0': resolution: {integrity: sha512-IWfdwU7KDSm07Ty0PuA/W2JYoZ4iTj3TUQjkVsO/6U+4I1jN5lcR71ZEvRh52sDOERdnNhhHU57UITXz5jC1/w==} cpu: [arm64] os: [darwin] + '@rollup/rollup-darwin-arm64@4.21.2': + resolution: {integrity: sha512-99AhQ3/ZMxU7jw34Sq8brzXqWH/bMnf7ZVhvLk9QU2cOepbQSVTns6qoErJmSiAvU3InRqC2RRZ5ovh1KN0d0Q==} + cpu: [arm64] + os: [darwin] + '@rollup/rollup-darwin-x64@4.18.0': resolution: {integrity: sha512-n2LMsUz7Ynu7DoQrSQkBf8iNrjOGyPLrdSg802vk6XT3FtsgX6JbE8IHRvposskFm9SNxzkLYGSq9QdpLYpRNA==} cpu: [x64] os: [darwin] + '@rollup/rollup-darwin-x64@4.21.2': + resolution: {integrity: sha512-ZbRaUvw2iN/y37x6dY50D8m2BnDbBjlnMPotDi/qITMJ4sIxNY33HArjikDyakhSv0+ybdUxhWxE6kTI4oX26w==} + cpu: [x64] + os: [darwin] + '@rollup/rollup-linux-arm-gnueabihf@4.18.0': resolution: {integrity: sha512-C/zbRYRXFjWvz9Z4haRxcTdnkPt1BtCkz+7RtBSuNmKzMzp3ZxdM28Mpccn6pt28/UWUCTXa+b0Mx1k3g6NOMA==} cpu: [arm] os: [linux] + '@rollup/rollup-linux-arm-gnueabihf@4.21.2': + resolution: {integrity: sha512-ztRJJMiE8nnU1YFcdbd9BcH6bGWG1z+jP+IPW2oDUAPxPjo9dverIOyXz76m6IPA6udEL12reYeLojzW2cYL7w==} + cpu: [arm] + os: [linux] + '@rollup/rollup-linux-arm-musleabihf@4.18.0': resolution: {integrity: sha512-l3m9ewPgjQSXrUMHg93vt0hYCGnrMOcUpTz6FLtbwljo2HluS4zTXFy2571YQbisTnfTKPZ01u/ukJdQTLGh9A==} cpu: [arm] os: [linux] + '@rollup/rollup-linux-arm-musleabihf@4.21.2': + resolution: {integrity: sha512-flOcGHDZajGKYpLV0JNc0VFH361M7rnV1ee+NTeC/BQQ1/0pllYcFmxpagltANYt8FYf9+kL6RSk80Ziwyhr7w==} + cpu: [arm] + os: [linux] + '@rollup/rollup-linux-arm64-gnu@4.18.0': resolution: {integrity: sha512-rJ5D47d8WD7J+7STKdCUAgmQk49xuFrRi9pZkWoRD1UeSMakbcepWXPF8ycChBoAqs1pb2wzvbY6Q33WmN2ftw==} cpu: [arm64] os: [linux] + '@rollup/rollup-linux-arm64-gnu@4.21.2': + resolution: {integrity: sha512-69CF19Kp3TdMopyteO/LJbWufOzqqXzkrv4L2sP8kfMaAQ6iwky7NoXTp7bD6/irKgknDKM0P9E/1l5XxVQAhw==} + cpu: [arm64] + os: [linux] + '@rollup/rollup-linux-arm64-musl@4.18.0': resolution: {integrity: sha512-be6Yx37b24ZwxQ+wOQXXLZqpq4jTckJhtGlWGZs68TgdKXJgw54lUUoFYrg6Zs/kjzAQwEwYbp8JxZVzZLRepQ==} cpu: [arm64] os: [linux] + '@rollup/rollup-linux-arm64-musl@4.21.2': + resolution: {integrity: sha512-48pD/fJkTiHAZTnZwR0VzHrao70/4MlzJrq0ZsILjLW/Ab/1XlVUStYyGt7tdyIiVSlGZbnliqmult/QGA2O2w==} + cpu: [arm64] + os: [linux] + '@rollup/rollup-linux-powerpc64le-gnu@4.18.0': resolution: {integrity: sha512-hNVMQK+qrA9Todu9+wqrXOHxFiD5YmdEi3paj6vP02Kx1hjd2LLYR2eaN7DsEshg09+9uzWi2W18MJDlG0cxJA==} cpu: [ppc64] os: [linux] + '@rollup/rollup-linux-powerpc64le-gnu@4.21.2': + resolution: {integrity: sha512-cZdyuInj0ofc7mAQpKcPR2a2iu4YM4FQfuUzCVA2u4HI95lCwzjoPtdWjdpDKyHxI0UO82bLDoOaLfpZ/wviyQ==} + cpu: [ppc64] + os: [linux] + '@rollup/rollup-linux-riscv64-gnu@4.18.0': resolution: {integrity: sha512-ROCM7i+m1NfdrsmvwSzoxp9HFtmKGHEqu5NNDiZWQtXLA8S5HBCkVvKAxJ8U+CVctHwV2Gb5VUaK7UAkzhDjlg==} cpu: [riscv64] os: [linux] + '@rollup/rollup-linux-riscv64-gnu@4.21.2': + resolution: {integrity: sha512-RL56JMT6NwQ0lXIQmMIWr1SW28z4E4pOhRRNqwWZeXpRlykRIlEpSWdsgNWJbYBEWD84eocjSGDu/XxbYeCmwg==} + cpu: [riscv64] + os: [linux] + '@rollup/rollup-linux-s390x-gnu@4.18.0': resolution: {integrity: sha512-0UyyRHyDN42QL+NbqevXIIUnKA47A+45WyasO+y2bGJ1mhQrfrtXUpTxCOrfxCR4esV3/RLYyucGVPiUsO8xjg==} cpu: [s390x] os: [linux] + '@rollup/rollup-linux-s390x-gnu@4.21.2': + resolution: {integrity: sha512-PMxkrWS9z38bCr3rWvDFVGD6sFeZJw4iQlhrup7ReGmfn7Oukrr/zweLhYX6v2/8J6Cep9IEA/SmjXjCmSbrMQ==} + cpu: [s390x] + os: [linux] + '@rollup/rollup-linux-x64-gnu@4.18.0': resolution: {integrity: sha512-xuglR2rBVHA5UsI8h8UbX4VJ470PtGCf5Vpswh7p2ukaqBGFTnsfzxUBetoWBWymHMxbIG0Cmx7Y9qDZzr648w==} cpu: [x64] os: [linux] + '@rollup/rollup-linux-x64-gnu@4.21.2': + resolution: {integrity: sha512-B90tYAUoLhU22olrafY3JQCFLnT3NglazdwkHyxNDYF/zAxJt5fJUB/yBoWFoIQ7SQj+KLe3iL4BhOMa9fzgpw==} + cpu: [x64] + os: [linux] + '@rollup/rollup-linux-x64-musl@4.18.0': resolution: {integrity: sha512-LKaqQL9osY/ir2geuLVvRRs+utWUNilzdE90TpyoX0eNqPzWjRm14oMEE+YLve4k/NAqCdPkGYDaDF5Sw+xBfg==} cpu: [x64] os: [linux] + '@rollup/rollup-linux-x64-musl@4.21.2': + resolution: {integrity: sha512-7twFizNXudESmC9oneLGIUmoHiiLppz/Xs5uJQ4ShvE6234K0VB1/aJYU3f/4g7PhssLGKBVCC37uRkkOi8wjg==} + cpu: [x64] + os: [linux] + '@rollup/rollup-win32-arm64-msvc@4.18.0': resolution: {integrity: sha512-7J6TkZQFGo9qBKH0pk2cEVSRhJbL6MtfWxth7Y5YmZs57Pi+4x6c2dStAUvaQkHQLnEQv1jzBUW43GvZW8OFqA==} cpu: [arm64] os: [win32] + '@rollup/rollup-win32-arm64-msvc@4.21.2': + resolution: {integrity: sha512-9rRero0E7qTeYf6+rFh3AErTNU1VCQg2mn7CQcI44vNUWM9Ze7MSRS/9RFuSsox+vstRt97+x3sOhEey024FRQ==} + cpu: [arm64] + os: [win32] + '@rollup/rollup-win32-ia32-msvc@4.18.0': resolution: {integrity: sha512-Txjh+IxBPbkUB9+SXZMpv+b/vnTEtFyfWZgJ6iyCmt2tdx0OF5WhFowLmnh8ENGNpfUlUZkdI//4IEmhwPieNg==} cpu: [ia32] os: [win32] + '@rollup/rollup-win32-ia32-msvc@4.21.2': + resolution: {integrity: sha512-5rA4vjlqgrpbFVVHX3qkrCo/fZTj1q0Xxpg+Z7yIo3J2AilW7t2+n6Q8Jrx+4MrYpAnjttTYF8rr7bP46BPzRw==} + cpu: [ia32] + os: [win32] + '@rollup/rollup-win32-x64-msvc@4.18.0': resolution: {integrity: sha512-UOo5FdvOL0+eIVTgS4tIdbW+TtnBLWg1YBCcU2KWM7nuNwRz9bksDX1bekJJCpu25N1DVWaCwnT39dVQxzqS8g==} cpu: [x64] os: [win32] + '@rollup/rollup-win32-x64-msvc@4.21.2': + resolution: {integrity: sha512-6UUxd0+SKomjdzuAcp+HAmxw1FlGBnl1v2yEPSabtx4lBfdXHDVsW7+lQkgz9cNFJGY3AWR7+V8P5BqkD9L9nA==} + cpu: [x64] + os: [win32] + '@sinclair/typebox@0.27.8': resolution: {integrity: sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA==} @@ -2259,7 +2339,7 @@ packages: peerDependencies: '@sveltejs/vite-plugin-svelte': ^3.0.0 || ^4.0.0-next.1 svelte: ^4.0.0 || ^5.0.0-next.0 - vite: 6.0.0-alpha.18 + vite: 6.0.0-alpha.23 '@sveltejs/site-kit@6.0.0-next.64': resolution: {integrity: sha512-SosLY07DBA79yJhRR9vQpk9eXlSc3VjzOlIJQFvPzgsbu727rq5u3dudFEsm0NeQFoAF+NNgDYi5D85v5Yc+vQ==} @@ -2273,14 +2353,14 @@ packages: peerDependencies: '@sveltejs/vite-plugin-svelte': ^3.0.0 svelte: ^4.0.0 || ^5.0.0-next.0 - vite: 6.0.0-alpha.18 + vite: 6.0.0-alpha.23 '@sveltejs/vite-plugin-svelte@3.1.0': resolution: {integrity: sha512-sY6ncCvg+O3njnzbZexcVtUqOBE3iYmQPJ9y+yXSkOwG576QI/xJrBnQSRXFLGwJNBa0T78JEKg5cIR0WOAuUw==} engines: {node: ^18.0.0 || >=20} peerDependencies: svelte: ^4.0.0 || ^5.0.0-next.0 - vite: 6.0.0-alpha.18 + vite: 6.0.0-alpha.23 '@svitejs/changesets-changelog-github-compact@1.1.0': resolution: {integrity: sha512-qhUGGDHcpbY2zpjW3SwqchuW8J/5EzlPFud7xNntHKA7f3a/mx5+g+ruJKFHSAiVZYo30PALt+AyhmPUNKH/Og==} @@ -3757,6 +3837,10 @@ packages: resolution: {integrity: sha512-0vzE+lAiG7hZl1/9I8yzKLx3aR9Xbof3fBHKunvMfOCYAtMhrsnccJY2iTURb9EZd5+pLuiNV9/c/GZJOHsgIw==} engines: {node: ^10 || ^12 || >=14} + postcss@8.4.41: + resolution: {integrity: sha512-TesUflQ0WKZqAvg52PWL6kHgLKP6xB6heTOdoYM0Wt2UHyxNa4K25EZZMgKns3BH1RLVbZCREPpLY0rhnNoHVQ==} + engines: {node: ^10 || ^12 || >=14} + preferred-pm@3.1.3: resolution: {integrity: sha512-MkXsENfftWSRpzCzImcp4FRsCc3y1opwB73CfCNWyzMqArju2CrlMHlqB7VexKiPEOjGMbttv1r9fSCn5S610w==} engines: {node: '>=10'} @@ -3884,6 +3968,11 @@ packages: engines: {node: '>=18.0.0', npm: '>=8.0.0'} hasBin: true + rollup@4.21.2: + resolution: {integrity: sha512-e3TapAgYf9xjdLvKQCkQTnbTKd4a6jwlpQSJJFokHGaX2IVjoEqkIIhiQfqsi0cdwlOD+tQGuOd5AJkc5RngBw==} + engines: {node: '>=18.0.0', npm: '>=8.0.0'} + hasBin: true + run-parallel@1.2.0: resolution: {integrity: sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==} @@ -4330,8 +4419,8 @@ packages: engines: {node: ^18.0.0 || >=20.0.0} hasBin: true - vite@6.0.0-alpha.18: - resolution: {integrity: sha512-UFvwSPOjUiZR3x6G/LuxrM0hzKaxYUe6MTN6lu89NTEDgkWgFCNRP/5pyzUDEXZqtzEuq3bKrslb34VDZF+5Ig==} + vite@6.0.0-alpha.23: + resolution: {integrity: sha512-+J9M4gG1J7do8MM++ODune0R1DOAD4NmkN84bTBuW62Bj0iwaL1B0dXvGwDIB2gwttkCiNPX7xvzQTNed4rvcA==} engines: {node: ^18.0.0 || >=20.0.0} hasBin: true peerDependencies: @@ -4339,6 +4428,7 @@ packages: less: '*' lightningcss: ^1.21.0 sass: '*' + sass-embedded: '*' stylus: '*' sugarss: '*' terser: ^5.4.0 @@ -4351,6 +4441,8 @@ packages: optional: true sass: optional: true + sass-embedded: + optional: true stylus: optional: true sugarss: @@ -4361,7 +4453,7 @@ packages: vitefu@0.2.5: resolution: {integrity: sha512-SgHtMLoqaeeGnd2evZ849ZbACbnwQCIwRH57t18FxcXoZop0uQu0uzlIhJBlF/eWVzuce0sHeqPcDo+evVcg8Q==} peerDependencies: - vite: 6.0.0-alpha.18 + vite: 6.0.0-alpha.23 peerDependenciesMeta: vite: optional: true @@ -4736,11 +4828,11 @@ snapshots: dependencies: '@jridgewell/trace-mapping': 0.3.9 - '@dario-hacking/vite-6-alpha-environment-provider-workerd@0.0.5(miniflare@3.20240821.0)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1))(wrangler@3.72.3(@cloudflare/workers-types@4.20240405.0))': + '@dario-hacking/vite-6-alpha-environment-provider-workerd@0.0.5(miniflare@3.20240821.0)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1))(wrangler@3.72.3(@cloudflare/workers-types@4.20240405.0))': dependencies: cjs-module-lexer: 1.3.1 miniflare: 3.20240821.0 - vite: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) + vite: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) wrangler: 3.72.3(@cloudflare/workers-types@4.20240405.0) '@emnapi/runtime@1.2.0': @@ -5160,51 +5252,99 @@ snapshots: '@rollup/rollup-android-arm-eabi@4.18.0': optional: true + '@rollup/rollup-android-arm-eabi@4.21.2': + optional: true + '@rollup/rollup-android-arm64@4.18.0': optional: true + '@rollup/rollup-android-arm64@4.21.2': + optional: true + '@rollup/rollup-darwin-arm64@4.18.0': optional: true + '@rollup/rollup-darwin-arm64@4.21.2': + optional: true + '@rollup/rollup-darwin-x64@4.18.0': optional: true + '@rollup/rollup-darwin-x64@4.21.2': + optional: true + '@rollup/rollup-linux-arm-gnueabihf@4.18.0': optional: true + '@rollup/rollup-linux-arm-gnueabihf@4.21.2': + optional: true + '@rollup/rollup-linux-arm-musleabihf@4.18.0': optional: true + '@rollup/rollup-linux-arm-musleabihf@4.21.2': + optional: true + '@rollup/rollup-linux-arm64-gnu@4.18.0': optional: true + '@rollup/rollup-linux-arm64-gnu@4.21.2': + optional: true + '@rollup/rollup-linux-arm64-musl@4.18.0': optional: true + '@rollup/rollup-linux-arm64-musl@4.21.2': + optional: true + '@rollup/rollup-linux-powerpc64le-gnu@4.18.0': optional: true + '@rollup/rollup-linux-powerpc64le-gnu@4.21.2': + optional: true + '@rollup/rollup-linux-riscv64-gnu@4.18.0': optional: true + '@rollup/rollup-linux-riscv64-gnu@4.21.2': + optional: true + '@rollup/rollup-linux-s390x-gnu@4.18.0': optional: true + '@rollup/rollup-linux-s390x-gnu@4.21.2': + optional: true + '@rollup/rollup-linux-x64-gnu@4.18.0': optional: true + '@rollup/rollup-linux-x64-gnu@4.21.2': + optional: true + '@rollup/rollup-linux-x64-musl@4.18.0': optional: true + '@rollup/rollup-linux-x64-musl@4.21.2': + optional: true + '@rollup/rollup-win32-arm64-msvc@4.18.0': optional: true + '@rollup/rollup-win32-arm64-msvc@4.21.2': + optional: true + '@rollup/rollup-win32-ia32-msvc@4.18.0': optional: true + '@rollup/rollup-win32-ia32-msvc@4.21.2': + optional: true + '@rollup/rollup-win32-x64-msvc@4.18.0': optional: true + '@rollup/rollup-win32-x64-msvc@4.21.2': + optional: true + '@sinclair/typebox@0.27.8': {} '@stylistic/eslint-plugin-js@2.1.0(eslint@9.6.0)': @@ -5226,9 +5366,9 @@ snapshots: typescript: 5.4.5 typescript-eslint: 8.0.0(eslint@9.6.0)(typescript@5.4.5) - '@sveltejs/kit@2.5.24(@sveltejs/vite-plugin-svelte@3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)))(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1))': + '@sveltejs/kit@2.5.24(@sveltejs/vite-plugin-svelte@3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)))(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1))': dependencies: - '@sveltejs/vite-plugin-svelte': 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) + '@sveltejs/vite-plugin-svelte': 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)) '@types/cookie': 0.6.0 cookie: 0.6.0 devalue: 5.0.0 @@ -5242,7 +5382,7 @@ snapshots: sirv: 2.0.4 svelte: 4.2.17 tiny-glob: 0.2.9 - vite: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) + vite: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) '@sveltejs/site-kit@6.0.0-next.64(@sveltejs/kit@packages+kit)(svelte@4.2.17)': dependencies: @@ -5251,26 +5391,26 @@ snapshots: svelte: 4.2.17 svelte-persisted-store: 0.9.4(svelte@4.2.17) - '@sveltejs/vite-plugin-svelte-inspector@2.1.0(@sveltejs/vite-plugin-svelte@3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)))(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1))': + '@sveltejs/vite-plugin-svelte-inspector@2.1.0(@sveltejs/vite-plugin-svelte@3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)))(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1))': dependencies: - '@sveltejs/vite-plugin-svelte': 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) + '@sveltejs/vite-plugin-svelte': 3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)) debug: 4.3.5 svelte: 4.2.17 - vite: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) + vite: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) transitivePeerDependencies: - supports-color - '@sveltejs/vite-plugin-svelte@3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1))': + '@sveltejs/vite-plugin-svelte@3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1))': dependencies: - '@sveltejs/vite-plugin-svelte-inspector': 2.1.0(@sveltejs/vite-plugin-svelte@3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)))(svelte@4.2.17)(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) + '@sveltejs/vite-plugin-svelte-inspector': 2.1.0(@sveltejs/vite-plugin-svelte@3.1.0(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)))(svelte@4.2.17)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)) debug: 4.3.5 deepmerge: 4.3.1 kleur: 4.1.5 magic-string: 0.30.10 svelte: 4.2.17 svelte-hmr: 0.16.0(svelte@4.2.17) - vite: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) - vitefu: 0.2.5(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)) + vite: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) + vitefu: 0.2.5(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)) transitivePeerDependencies: - supports-color @@ -6738,6 +6878,14 @@ snapshots: optionalDependencies: postcss: 8.4.39 + postcss-load-config@3.1.4(postcss@8.4.41): + dependencies: + lilconfig: 2.1.0 + yaml: 1.10.2 + optionalDependencies: + postcss: 8.4.41 + optional: true + postcss-safe-parser@6.0.0(postcss@8.4.39): dependencies: postcss: 8.4.39 @@ -6757,6 +6905,12 @@ snapshots: picocolors: 1.0.1 source-map-js: 1.2.0 + postcss@8.4.41: + dependencies: + nanoid: 3.3.7 + picocolors: 1.0.1 + source-map-js: 1.2.0 + preferred-pm@3.1.3: dependencies: find-up: 5.0.0 @@ -6887,6 +7041,28 @@ snapshots: '@rollup/rollup-win32-x64-msvc': 4.18.0 fsevents: 2.3.3 + rollup@4.21.2: + dependencies: + '@types/estree': 1.0.5 + optionalDependencies: + '@rollup/rollup-android-arm-eabi': 4.21.2 + '@rollup/rollup-android-arm64': 4.21.2 + '@rollup/rollup-darwin-arm64': 4.21.2 + '@rollup/rollup-darwin-x64': 4.21.2 + '@rollup/rollup-linux-arm-gnueabihf': 4.21.2 + '@rollup/rollup-linux-arm-musleabihf': 4.21.2 + '@rollup/rollup-linux-arm64-gnu': 4.21.2 + '@rollup/rollup-linux-arm64-musl': 4.21.2 + '@rollup/rollup-linux-powerpc64le-gnu': 4.21.2 + '@rollup/rollup-linux-riscv64-gnu': 4.21.2 + '@rollup/rollup-linux-s390x-gnu': 4.21.2 + '@rollup/rollup-linux-x64-gnu': 4.21.2 + '@rollup/rollup-linux-x64-musl': 4.21.2 + '@rollup/rollup-win32-arm64-msvc': 4.21.2 + '@rollup/rollup-win32-ia32-msvc': 4.21.2 + '@rollup/rollup-win32-x64-msvc': 4.21.2 + fsevents: 2.3.3 + run-parallel@1.2.0: dependencies: queue-microtask: 1.2.3 @@ -7091,7 +7267,7 @@ snapshots: supports-preserve-symlinks-flag@1.0.0: {} - svelte-check@3.6.9(postcss-load-config@3.1.4(postcss@8.4.39))(postcss@8.4.39)(svelte@4.2.17): + svelte-check@3.6.9(postcss-load-config@3.1.4(postcss@8.4.41))(postcss@8.4.41)(svelte@4.2.17): dependencies: '@jridgewell/trace-mapping': 0.3.25 chokidar: 3.6.0 @@ -7100,7 +7276,7 @@ snapshots: picocolors: 1.0.1 sade: 1.8.1 svelte: 4.2.17 - svelte-preprocess: 5.1.3(postcss-load-config@3.1.4(postcss@8.4.39))(postcss@8.4.39)(svelte@4.2.17)(typescript@5.4.5) + svelte-preprocess: 5.1.3(postcss-load-config@3.1.4(postcss@8.4.41))(postcss@8.4.41)(svelte@4.2.17)(typescript@5.4.5) typescript: 5.4.5 transitivePeerDependencies: - '@babel/core' @@ -7135,7 +7311,7 @@ snapshots: dependencies: svelte: 4.2.17 - svelte-preprocess@5.1.3(postcss-load-config@3.1.4(postcss@8.4.39))(postcss@8.4.39)(svelte@4.2.17)(typescript@5.4.5): + svelte-preprocess@5.1.3(postcss-load-config@3.1.4(postcss@8.4.41))(postcss@8.4.41)(svelte@4.2.17)(typescript@5.4.5): dependencies: '@types/pug': 2.0.10 detect-indent: 6.1.0 @@ -7144,18 +7320,18 @@ snapshots: strip-indent: 3.0.0 svelte: 4.2.17 optionalDependencies: - postcss: 8.4.39 - postcss-load-config: 3.1.4(postcss@8.4.39) + postcss: 8.4.41 + postcss-load-config: 3.1.4(postcss@8.4.41) typescript: 5.4.5 - svelte-preprocess@6.0.0(postcss-load-config@3.1.4(postcss@8.4.39))(postcss@8.4.39)(svelte@4.2.17)(typescript@5.4.5): + svelte-preprocess@6.0.0(postcss-load-config@3.1.4(postcss@8.4.41))(postcss@8.4.41)(svelte@4.2.17)(typescript@5.4.5): dependencies: detect-indent: 6.1.0 strip-indent: 3.0.0 svelte: 4.2.17 optionalDependencies: - postcss: 8.4.39 - postcss-load-config: 3.1.4(postcss@8.4.39) + postcss: 8.4.41 + postcss-load-config: 3.1.4(postcss@8.4.41) typescript: 5.4.5 svelte2tsx@0.7.6(svelte@4.2.17)(typescript@5.4.5): @@ -7323,30 +7499,31 @@ snapshots: debug: 4.3.5 pathe: 1.1.2 picocolors: 1.0.1 - vite: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) + vite: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) transitivePeerDependencies: - '@types/node' - less - lightningcss - sass + - sass-embedded - stylus - sugarss - supports-color - terser - vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1): + vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1): dependencies: esbuild: 0.21.5 - postcss: 8.4.39 - rollup: 4.18.0 + postcss: 8.4.41 + rollup: 4.21.2 optionalDependencies: '@types/node': 18.19.31 fsevents: 2.3.3 lightningcss: 1.24.1 - vitefu@0.2.5(vite@6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1)): + vitefu@0.2.5(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1)): optionalDependencies: - vite: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) + vite: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) vitest@2.0.1(@types/node@18.19.31)(lightningcss@1.24.1): dependencies: @@ -7365,7 +7542,7 @@ snapshots: std-env: 3.7.0 tinybench: 2.8.0 tinypool: 1.0.0 - vite: 6.0.0-alpha.18(@types/node@18.19.31)(lightningcss@1.24.1) + vite: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) vite-node: 2.0.1(@types/node@18.19.31)(lightningcss@1.24.1) why-is-node-running: 2.3.0 optionalDependencies: @@ -7374,6 +7551,7 @@ snapshots: - less - lightningcss - sass + - sass-embedded - stylus - sugarss - supports-color From 2438651d67a77f51adbe90fa67a27fb127c7066c Mon Sep 17 00:00:00 2001 From: James Opstad Date: Fri, 30 Aug 2024 16:26:17 +0100 Subject: [PATCH 27/61] Changed to environments option in svelte config --- packages/kit/src/core/config/options.js | 10 ++++++---- packages/kit/src/exports/public.d.ts | 19 +++++++++++-------- packages/kit/src/exports/vite/index.js | 2 +- .../vite-workerd-environment/svelte.config.js | 6 ++++-- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/packages/kit/src/core/config/options.js b/packages/kit/src/core/config/options.js index 587053d33140..4aab51baedc4 100644 --- a/packages/kit/src/core/config/options.js +++ b/packages/kit/src/core/config/options.js @@ -120,6 +120,12 @@ const options = object( privatePrefix: string('') }), + environments: object({ + ssr: validate(default_environment, (input) => { + return input; + }) + }), + files: object({ assets: string('static'), hooks: object({ @@ -264,10 +270,6 @@ const options = object( files: fun((filename) => !/\.DS_Store/.test(filename)) }), - ssrEnvironment: validate(default_environment, (input) => { - return input; - }), - typescript: object({ config: fun((config) => config) }), diff --git a/packages/kit/src/exports/public.d.ts b/packages/kit/src/exports/public.d.ts index 165e3a577b10..deca804dc2ff 100644 --- a/packages/kit/src/exports/public.d.ts +++ b/packages/kit/src/exports/public.d.ts @@ -56,8 +56,8 @@ export interface Adapter { export type LoadProperties | void> = input extends void ? undefined // needs to be undefined, because void will break intellisense : input extends Record - ? input - : unknown; + ? input + : unknown; export type AwaitedActions any>> = OptionalUnion< { @@ -80,11 +80,12 @@ export interface ActionFailure | undefined = u [uniqueSymbol]: true; // necessary or else UnpackValidationError could wrongly unpack objects with the same shape as ActionFailure } -type UnpackValidationError = T extends ActionFailure - ? X - : T extends void - ? undefined // needs to be undefined, because void will corrupt union type - : T; +type UnpackValidationError = + T extends ActionFailure + ? X + : T extends void + ? undefined // needs to be undefined, because void will corrupt union type + : T; /** * This object is passed to the `adapt` function of adapters. @@ -407,6 +408,9 @@ export interface KitConfig { */ privatePrefix?: string; }; + environments?: { + ssr?: (environmentName: string, options: any) => Plugin[]; + }; /** * Where to find various files within your project. */ @@ -618,7 +622,6 @@ export interface KitConfig { */ files?(filepath: string): boolean; }; - ssrEnvironment?: (environmentName: string, options: any) => Plugin[]; typescript?: { /** * A function that allows you to edit the generated `tsconfig.json`. You can mutate the config (recommended) or return a new one. diff --git a/packages/kit/src/exports/vite/index.js b/packages/kit/src/exports/vite/index.js index 6fa0c75a163f..1d20bc68c27d 100644 --- a/packages/kit/src/exports/vite/index.js +++ b/packages/kit/src/exports/vite/index.js @@ -1069,7 +1069,7 @@ async function kit({ svelte_config }) { }; return [ - ...svelte_config.kit.ssrEnvironment(SSR_ENVIRONMENT_NAME, {}), + ...svelte_config.kit.environments.ssr(SSR_ENVIRONMENT_NAME, {}), plugin_setup, plugin_virtual_modules, plugin_guard, diff --git a/playgrounds/vite-workerd-environment/svelte.config.js b/playgrounds/vite-workerd-environment/svelte.config.js index 9b987f53b3a6..d8a019be1968 100644 --- a/playgrounds/vite-workerd-environment/svelte.config.js +++ b/playgrounds/vite-workerd-environment/svelte.config.js @@ -1,12 +1,14 @@ import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'; import adapter from '@sveltejs/adapter-auto'; -import { workerd } from '@dario-hacking/vite-6-alpha-environment-provider-workerd'; +import { workerd as cloudflare } from '@dario-hacking/vite-6-alpha-environment-provider-workerd'; /** @type {import('@sveltejs/kit').Config} */ const config = { kit: { adapter: adapter(), - ssrEnvironment: workerd({}) + environments: { + ssr: cloudflare({}) + } }, preprocess: [vitePreprocess()] }; From ece53649e64b90e7607616f32aa211a943b2f012 Mon Sep 17 00:00:00 2001 From: James Opstad Date: Fri, 30 Aug 2024 17:04:48 +0100 Subject: [PATCH 28/61] Started adding original implementation back in --- packages/kit/src/core/config/options.js | 9 +- packages/kit/src/exports/vite/dev/index.js | 525 +++++++++--------- .../vite-workerd-environment/svelte.config.js | 8 +- 3 files changed, 273 insertions(+), 269 deletions(-) diff --git a/packages/kit/src/core/config/options.js b/packages/kit/src/core/config/options.js index 4aab51baedc4..b86b02a351f5 100644 --- a/packages/kit/src/core/config/options.js +++ b/packages/kit/src/core/config/options.js @@ -121,9 +121,12 @@ const options = object( }), environments: object({ - ssr: validate(default_environment, (input) => { - return input; - }) + ssr: validate( + () => [], + (input) => { + return input; + } + ) }), files: object({ diff --git a/packages/kit/src/exports/vite/dev/index.js b/packages/kit/src/exports/vite/dev/index.js index be96f77782f0..f0d6c0e7fcd0 100644 --- a/packages/kit/src/exports/vite/dev/index.js +++ b/packages/kit/src/exports/vite/dev/index.js @@ -4,22 +4,23 @@ import { fileURLToPath, URL } from 'node:url'; import { AsyncLocalStorage } from 'node:async_hooks'; import colors from 'kleur'; import sirv from 'sirv'; -import { loadEnv, createServerModuleRunner } from 'vite'; -import { getRequest, setResponse } from '../../../exports/node/index.js'; +import { isCSSRequest, loadEnv, buildErrorMessage, createServerModuleRunner } from 'vite'; +import { createReadableStream, getRequest, setResponse } from '../../../exports/node/index.js'; import { installPolyfills } from '../../../exports/node/polyfills.js'; import { coalesce_to_error } from '../../../utils/error.js'; -import { posixify, resolve_entry, to_fs } from '../../../utils/filesystem.js'; +import { from_fs, posixify, resolve_entry, to_fs } from '../../../utils/filesystem.js'; import { load_error_page } from '../../../core/config/index.js'; import { SVELTE_KIT_ASSETS } from '../../../constants.js'; import * as sync from '../../../core/sync/sync.js'; -import { runtime_base } from '../../../core/utils.js'; +import { get_mime_lookup, runtime_base } from '../../../core/utils.js'; +import { compact } from '../../../utils/array.js'; import { not_found } from '../utils.js'; import { SCHEME } from '../../../utils/url.js'; import { check_feature } from '../../../utils/features.js'; import { sveltekit_environment_context } from '../module_ids.js'; import { SSR_ENVIRONMENT_NAME } from '../constants.js'; -// const cwd = process.cwd(); +const cwd = process.cwd(); /** * @param {import('vite').ViteDevServer} vite @@ -53,54 +54,54 @@ export async function dev(vite, vite_config, svelte_config, environment_context) sync.init(svelte_config, vite_config.mode); - // /** @type {import('types').ManifestData} */ - // let manifest_data; - // /** @type {import('@sveltejs/kit').SSRManifest} */ - // let manifest; + /** @type {import('types').ManifestData} */ + let manifest_data; + /** @type {import('@sveltejs/kit').SSRManifest} */ + let manifest; /** @type {Error | null} */ let manifest_error = null; - // /** @param {string} url */ - // async function loud_ssr_load_module(url) { - // try { - // return await vite.ssrLoadModule(url, { fixStacktrace: true }); - // } catch (/** @type {any} */ err) { - // const msg = buildErrorMessage(err, [colors.red(`Internal server error: ${err.message}`)]); + /** @param {string} url */ + async function loud_ssr_load_module(url) { + try { + return await vite.ssrLoadModule(url, { fixStacktrace: true }); + } catch (/** @type {any} */ err) { + const msg = buildErrorMessage(err, [colors.red(`Internal server error: ${err.message}`)]); - // if (!vite.config.logger.hasErrorLogged(err)) { - // vite.config.logger.error(msg, { error: err }); - // } + if (!vite.config.logger.hasErrorLogged(err)) { + vite.config.logger.error(msg, { error: 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 - // } - // }); + 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; - // } - // } + throw err; + } + } - // /** @param {string} id */ - // async function resolve(id) { - // const url = id.startsWith('..') ? to_fs(path.posix.resolve(id)) : `/${id}`; + /** @param {string} id */ + async function resolve(id) { + const url = id.startsWith('..') ? to_fs(path.posix.resolve(id)) : `/${id}`; - // const module = await loud_ssr_load_module(url); + const module = await loud_ssr_load_module(url); - // const module_node = await vite.moduleGraph.getModuleByUrl(url); + const module_node = await vite.moduleGraph.getModuleByUrl(url); - // vite.environments.node.moduleGraph.getModuleByUrl; + vite.environments.node.moduleGraph.getModuleByUrl; - // if (!module_node) throw new Error(`Could not find node for ${url}`); + if (!module_node) throw new Error(`Could not find node for ${url}`); - // return { module, module_node, url }; - // } + return { module, module_node, url }; + } // this may not be needed function invalidate_environment_context_module() { @@ -117,8 +118,9 @@ export async function dev(vite, vite_config, svelte_config, environment_context) function update_manifest() { try { - environment_context.manifest_data = sync.create(svelte_config).manifest_data; + ({ manifest_data } = sync.create(svelte_config)); + environment_context.manifest_data = manifest_data; invalidate_environment_context_module(); if (manifest_error) { @@ -140,151 +142,151 @@ export async function dev(vite, vite_config, svelte_config, environment_context) return; } - // manifest = { - // appDir: svelte_config.kit.appDir, - // appPath: svelte_config.kit.appDir, - // assets: new Set(manifest_data.assets.map((asset) => asset.file)), - // mimeTypes: get_mime_lookup(manifest_data), - // _: { - // client: { - // start: `${runtime_base}/client/entry.js`, - // app: `${to_fs(svelte_config.kit.outDir)}/generated/client/app.js`, - // imports: [], - // stylesheets: [], - // fonts: [], - // uses_env_dynamic_public: true - // }, - // server_assets: new Proxy( - // {}, - // { - // has: (_, /** @type {string} */ file) => fs.existsSync(from_fs(file)), - // get: (_, /** @type {string} */ file) => fs.statSync(from_fs(file)).size - // } - // ), - // nodes: manifest_data.nodes.map((node, index) => { - // return async () => { - // /** @type {import('types').SSRNode} */ - // const result = {}; - - // /** @type {import('vite').ModuleNode[]} */ - // const module_nodes = []; - - // result.index = index; - - // // these are unused in dev, it's easier to include them - // result.imports = []; - // result.stylesheets = []; - // result.fonts = []; - - // if (node.component) { - // result.component = async () => { - // const { module_node, module } = await resolve( - // /** @type {string} */ (node.component) - // ); - - // module_nodes.push(module_node); - - // return module.default; - // }; - // } - - // if (node.universal) { - // const { module, module_node } = await resolve(node.universal); - - // module_nodes.push(module_node); - - // result.universal = module; - // result.universal_id = node.universal; - // } - - // if (node.server) { - // const { module } = await resolve(node.server); - // result.server = module; - // result.server_id = node.server; - // } - - // // in dev we inline all styles to avoid FOUC. this gets populated lazily so that - // // components/stylesheets loaded via import() during `load` are included - // result.inline_styles = async () => { - // const deps = new Set(); - - // for (const module_node of module_nodes) { - // await find_deps(vite, module_node, deps); - // } - - // /** @type {Record} */ - // const styles = {}; - - // for (const dep of deps) { - // const url = new URL(dep.url, 'dummy:/'); - // const query = url.searchParams; - - // if ( - // (isCSSRequest(dep.file) || - // (query.has('svelte') && query.get('type') === 'style')) && - // !(query.has('raw') || query.has('url') || query.has('inline')) - // ) { - // try { - // query.set('inline', ''); - // const mod = await vite.ssrLoadModule( - // `${decodeURI(url.pathname)}${url.search}${url.hash}` - // ); - // styles[dep.url] = mod.default; - // } catch { - // // this can happen with dynamically imported modules, I think - // // because the Vite module graph doesn't distinguish between - // // static and dynamic imports? TODO investigate, submit fix - // } - // } - // } - - // return styles; - // }; - - // return result; - // }; - // }), - // routes: compact( - // manifest_data.routes.map((route) => { - // if (!route.page && !route.endpoint) return null; - - // const endpoint = route.endpoint; - - // return { - // id: route.id, - // pattern: route.pattern, - // params: route.params, - // page: route.page, - // endpoint: endpoint - // ? async () => { - // const url = path.resolve(cwd, endpoint.file); - // return await loud_ssr_load_module(url); - // } - // : null, - // endpoint_id: endpoint?.file - // }; - // }) - // ), - // matchers: async () => { - // /** @type {Record} */ - // const matchers = {}; - - // for (const key in manifest_data.matchers) { - // const file = manifest_data.matchers[key]; - // const url = path.resolve(cwd, file); - // const module = await vite.ssrLoadModule(url, { fixStacktrace: true }); - - // if (module.match) { - // matchers[key] = module.match; - // } else { - // throw new Error(`${file} does not export a \`match\` function`); - // } - // } - - // return matchers; - // } - // } - // }; + manifest = { + appDir: svelte_config.kit.appDir, + appPath: svelte_config.kit.appDir, + assets: new Set(manifest_data.assets.map((asset) => asset.file)), + mimeTypes: get_mime_lookup(manifest_data), + _: { + client: { + start: `${runtime_base}/client/entry.js`, + app: `${to_fs(svelte_config.kit.outDir)}/generated/client/app.js`, + imports: [], + stylesheets: [], + fonts: [], + uses_env_dynamic_public: true + }, + server_assets: new Proxy( + {}, + { + has: (_, /** @type {string} */ file) => fs.existsSync(from_fs(file)), + get: (_, /** @type {string} */ file) => fs.statSync(from_fs(file)).size + } + ), + nodes: manifest_data.nodes.map((node, index) => { + return async () => { + /** @type {import('types').SSRNode} */ + const result = {}; + + /** @type {import('vite').ModuleNode[]} */ + const module_nodes = []; + + result.index = index; + + // these are unused in dev, it's easier to include them + result.imports = []; + result.stylesheets = []; + result.fonts = []; + + if (node.component) { + result.component = async () => { + const { module_node, module } = await resolve( + /** @type {string} */ (node.component) + ); + + module_nodes.push(module_node); + + return module.default; + }; + } + + if (node.universal) { + const { module, module_node } = await resolve(node.universal); + + module_nodes.push(module_node); + + result.universal = module; + result.universal_id = node.universal; + } + + if (node.server) { + const { module } = await resolve(node.server); + result.server = module; + result.server_id = node.server; + } + + // in dev we inline all styles to avoid FOUC. this gets populated lazily so that + // components/stylesheets loaded via import() during `load` are included + result.inline_styles = async () => { + const deps = new Set(); + + for (const module_node of module_nodes) { + await find_deps(vite, module_node, deps); + } + + /** @type {Record} */ + const styles = {}; + + for (const dep of deps) { + const url = new URL(dep.url, 'dummy:/'); + const query = url.searchParams; + + if ( + (isCSSRequest(dep.file) || + (query.has('svelte') && query.get('type') === 'style')) && + !(query.has('raw') || query.has('url') || query.has('inline')) + ) { + try { + query.set('inline', ''); + const mod = await vite.ssrLoadModule( + `${decodeURI(url.pathname)}${url.search}${url.hash}` + ); + styles[dep.url] = mod.default; + } catch { + // this can happen with dynamically imported modules, I think + // because the Vite module graph doesn't distinguish between + // static and dynamic imports? TODO investigate, submit fix + } + } + } + + return styles; + }; + + return result; + }; + }), + routes: compact( + manifest_data.routes.map((route) => { + if (!route.page && !route.endpoint) return null; + + const endpoint = route.endpoint; + + return { + id: route.id, + pattern: route.pattern, + params: route.params, + page: route.page, + endpoint: endpoint + ? async () => { + const url = path.resolve(cwd, endpoint.file); + return await loud_ssr_load_module(url); + } + : null, + endpoint_id: endpoint?.file + }; + }) + ), + matchers: async () => { + /** @type {Record} */ + const matchers = {}; + + for (const key in manifest_data.matchers) { + const file = manifest_data.matchers[key]; + const url = path.resolve(cwd, file); + const module = await vite.ssrLoadModule(url, { fixStacktrace: true }); + + if (module.match) { + matchers[key] = module.match; + } else { + throw new Error(`${file} does not export a \`match\` function`); + } + } + + return matchers; + } + } + }; } /** @param {Error} error */ @@ -334,7 +336,7 @@ export async function dev(vite, vite_config, svelte_config, environment_context) // Don't run for a single file if the whole manifest is about to get updated if (timeout || restarting) return; - sync.update(svelte_config, environment_context.manifest_data, file); + sync.update(svelte_config, manifest_data, file); }); const { appTemplate, errorTemplate, serviceWorker, hooks } = svelte_config.kit.files; @@ -438,29 +440,28 @@ export async function dev(vite, vite_config, svelte_config, environment_context) } }); - environment_context.env = loadEnv(vite_config.mode, svelte_config.kit.env.dir, ''); - // const emulator = await svelte_config.kit.adapter?.emulate?.(); + const env = loadEnv(vite_config.mode, svelte_config.kit.env.dir, ''); + environment_context.env = env; + const emulator = await svelte_config.kit.adapter?.emulate?.(); - /** @type { (import('vite').DevEnvironment & { api?: { getHandler: (opts: { entrypoint: string }) => Promise<(req: Request) => Promise> }}) } */ + /** @type { ((import('vite').DevEnvironment & { api?: { getHandler: (opts: { entrypoint: string }) => Promise<(req: Request) => Promise> }})) | undefined } */ const devEnv = vite.environments[SSR_ENVIRONMENT_NAME]; const __dirname = fileURLToPath(new URL('.', import.meta.url)); + /** @type {((req: Request) => Promise) | undefined} */ let handler; - if (devEnv.api) { + if (devEnv?.api) { handler = await devEnv.api.getHandler({ entrypoint: path.join(__dirname, 'workerd_entrypoint.js') }); } else { - const module_runner = createServerModuleRunner(vite.environments[SSR_ENVIRONMENT_NAME]); - const entrypoint = await module_runner.import(path.join(__dirname, 'node_entrypoint.js')); - handler = entrypoint.default.fetch; + // const module_runner = createServerModuleRunner(vite.environments[SSR_ENVIRONMENT_NAME]); + // const entrypoint = await module_runner.import(path.join(__dirname, 'node_entrypoint.js')); + // handler = entrypoint.default.fetch; } - // const entrypoint = await module_runner.import(path.join(__dirname, 'node_entrypoint.js')); - // const handler = entrypoint.default.fetch; - return () => { const serve_static_middleware = vite.middlewares.stack.find( (middleware) => @@ -516,10 +517,10 @@ export async function dev(vite, vite_config, svelte_config, environment_context) return; } - // // we have to import `Server` before calling `set_assets` - // const { Server } = /** @type {import('types').ServerModule} */ ( - // await vite.ssrLoadModule(`${runtime_base}/server/index.js`, { fixStacktrace: true }) - // ); + // we have to import `Server` before calling `set_assets` + const { Server } = /** @type {import('types').ServerModule} */ ( + await vite.ssrLoadModule(`${runtime_base}/server/index.js`, { fixStacktrace: true }) + ); const { set_fix_stack_trace } = await vite.ssrLoadModule( `${runtime_base}/shared-server.js` @@ -529,12 +530,12 @@ export async function dev(vite, vite_config, svelte_config, environment_context) const { set_assets } = await vite.ssrLoadModule('__sveltekit/paths'); set_assets(assets); - // const server = new Server(manifest); + const server = new Server(manifest); - // await server.init({ - // env, - // read: (file) => createReadableStream(from_fs(file)) - // }); + await server.init({ + env, + read: (file) => createReadableStream(from_fs(file)) + }); const request = await getRequest({ base, @@ -563,20 +564,20 @@ export async function dev(vite, vite_config, svelte_config, environment_context) return; } - const rendered = await handler(request); - - // const rendered = await server.respond(request, { - // getClientAddress: () => { - // const { remoteAddress } = req.socket; - // if (remoteAddress) return remoteAddress; - // throw new Error('Could not determine clientAddress'); - // }, - // read: (file) => fs.readFileSync(path.join(svelte_config.kit.files.assets, file)) - // // before_handle: (event, config, prerender) => { - // // async_local_storage.enterWith({ event, config, prerender }); - // // }, - // // emulator - // }); + const rendered = handler + ? await handler(request) + : await server.respond(request, { + getClientAddress: () => { + const { remoteAddress } = req.socket; + if (remoteAddress) return remoteAddress; + throw new Error('Could not determine clientAddress'); + }, + read: (file) => fs.readFileSync(path.join(svelte_config.kit.files.assets, file)), + before_handle: (event, config, prerender) => { + async_local_storage.enterWith({ event, config, prerender }); + }, + emulator + }); if (rendered.status === 404) { // @ts-expect-error @@ -608,48 +609,48 @@ function remove_static_middlewares(server) { } } -// /** -// * @param {import('vite').ViteDevServer} vite -// * @param {import('vite').ModuleNode} node -// * @param {Set} 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[]} */ -// const branches = []; - -// /** @param {import('vite').ModuleNode} node */ -// async function add(node) { -// if (!deps.has(node)) { -// deps.add(node); -// await find_deps(vite, node, deps); -// } -// } - -// /** @param {string} url */ -// async function add_by_url(url) { -// const node = await vite.moduleGraph.getModuleByUrl(url); - -// if (node) { -// await add(node); -// } -// } - -// if (node.ssrTransformResult) { -// if (node.ssrTransformResult.deps) { -// node.ssrTransformResult.deps.forEach((url) => branches.push(add_by_url(url))); -// } - -// if (node.ssrTransformResult.dynamicDeps) { -// node.ssrTransformResult.dynamicDeps.forEach((url) => branches.push(add_by_url(url))); -// } -// } else { -// node.importedModules.forEach((node) => branches.push(add(node))); -// } - -// await Promise.all(branches); -// } +/** + * @param {import('vite').ViteDevServer} vite + * @param {import('vite').ModuleNode} node + * @param {Set} 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[]} */ + const branches = []; + + /** @param {import('vite').ModuleNode} node */ + async function add(node) { + if (!deps.has(node)) { + deps.add(node); + await find_deps(vite, node, deps); + } + } + + /** @param {string} url */ + async function add_by_url(url) { + const node = await vite.moduleGraph.getModuleByUrl(url); + + if (node) { + await add(node); + } + } + + if (node.ssrTransformResult) { + if (node.ssrTransformResult.deps) { + node.ssrTransformResult.deps.forEach((url) => branches.push(add_by_url(url))); + } + + if (node.ssrTransformResult.dynamicDeps) { + node.ssrTransformResult.dynamicDeps.forEach((url) => branches.push(add_by_url(url))); + } + } else { + node.importedModules.forEach((node) => branches.push(add(node))); + } + + await Promise.all(branches); +} /** * Determine if a file is being requested with the correct case, diff --git a/playgrounds/vite-workerd-environment/svelte.config.js b/playgrounds/vite-workerd-environment/svelte.config.js index d8a019be1968..6b4f6a452699 100644 --- a/playgrounds/vite-workerd-environment/svelte.config.js +++ b/playgrounds/vite-workerd-environment/svelte.config.js @@ -5,10 +5,10 @@ import { workerd as cloudflare } from '@dario-hacking/vite-6-alpha-environment-p /** @type {import('@sveltejs/kit').Config} */ const config = { kit: { - adapter: adapter(), - environments: { - ssr: cloudflare({}) - } + adapter: adapter() + // environments: { + // ssr: cloudflare({}) + // } }, preprocess: [vitePreprocess()] }; From 113418a4bf12c7494851d230fa76accd6d104159 Mon Sep 17 00:00:00 2001 From: James Opstad Date: Fri, 30 Aug 2024 18:12:07 +0100 Subject: [PATCH 29/61] Fixed error and improved node playground --- packages/kit/src/exports/vite/dev/index.js | 3 --- .../vite-node-environment/src/params/fruit.ts | 3 +++ .../src/routes/+layout.svelte | 19 +++++++++++++++ .../src/routes/+page.server.ts | 17 ++++--------- .../src/routes/+page.svelte | 24 +++---------------- .../src/routes/about/+page.svelte | 4 ++-- .../src/routes/endpoint/+server.ts | 7 +++--- .../routes/matchers/[page=fruit]/+page.svelte | 16 +++++++++++++ .../vite-workerd-environment/svelte.config.js | 8 +++---- 9 files changed, 55 insertions(+), 46 deletions(-) create mode 100644 playgrounds/vite-node-environment/src/params/fruit.ts create mode 100644 playgrounds/vite-node-environment/src/routes/+layout.svelte create mode 100644 playgrounds/vite-node-environment/src/routes/matchers/[page=fruit]/+page.svelte diff --git a/packages/kit/src/exports/vite/dev/index.js b/packages/kit/src/exports/vite/dev/index.js index f0d6c0e7fcd0..9820acd96881 100644 --- a/packages/kit/src/exports/vite/dev/index.js +++ b/packages/kit/src/exports/vite/dev/index.js @@ -95,9 +95,6 @@ export async function dev(vite, vite_config, svelte_config, environment_context) const module = await loud_ssr_load_module(url); const module_node = await vite.moduleGraph.getModuleByUrl(url); - - vite.environments.node.moduleGraph.getModuleByUrl; - if (!module_node) throw new Error(`Could not find node for ${url}`); return { module, module_node, url }; diff --git a/playgrounds/vite-node-environment/src/params/fruit.ts b/playgrounds/vite-node-environment/src/params/fruit.ts new file mode 100644 index 000000000000..dceeb7da08d9 --- /dev/null +++ b/playgrounds/vite-node-environment/src/params/fruit.ts @@ -0,0 +1,3 @@ +export function match(param: string) { + return param === 'apple' || param === 'orange'; +} diff --git a/playgrounds/vite-node-environment/src/routes/+layout.svelte b/playgrounds/vite-node-environment/src/routes/+layout.svelte new file mode 100644 index 000000000000..855ac08512e9 --- /dev/null +++ b/playgrounds/vite-node-environment/src/routes/+layout.svelte @@ -0,0 +1,19 @@ +
      +

      Svelte Kit with Vite Node Environment

      + +
      +
      + + + \ No newline at end of file diff --git a/playgrounds/vite-node-environment/src/routes/+page.server.ts b/playgrounds/vite-node-environment/src/routes/+page.server.ts index 0e9996e8120e..5112c00794b2 100644 --- a/playgrounds/vite-node-environment/src/routes/+page.server.ts +++ b/playgrounds/vite-node-environment/src/routes/+page.server.ts @@ -1,20 +1,11 @@ -import type { Actions, PageServerLoad } from './$types'; - function getUserAgentText(): string { if (typeof navigator === 'undefined') { return 'navigator is undefined (running in Node.js?)'; - } else { - const userAgent = navigator.userAgent; - return `navigator.userAgent = ${userAgent}`; } + + return `navigator.userAgent = ${navigator.userAgent}`; } -export const load: PageServerLoad = () => { +export function load() { return { userAgentText: getUserAgentText() }; -}; - -export const actions = { - default: () => { - console.log('\x1b[32m no-op action \x1b[0m'); - } -} satisfies Actions; +} diff --git a/playgrounds/vite-node-environment/src/routes/+page.svelte b/playgrounds/vite-node-environment/src/routes/+page.svelte index c9a30339ad14..f5b657d769f6 100644 --- a/playgrounds/vite-node-environment/src/routes/+page.svelte +++ b/playgrounds/vite-node-environment/src/routes/+page.svelte @@ -1,27 +1,9 @@ -
      -

      Svelte Kit with Vite Node Environment

      - -
      +

      {data.userAgentText}

      -
      - -
      -
      - - \ No newline at end of file + \ No newline at end of file diff --git a/playgrounds/vite-node-environment/src/routes/about/+page.svelte b/playgrounds/vite-node-environment/src/routes/about/+page.svelte index 438da7994cea..3cd438d637fb 100644 --- a/playgrounds/vite-node-environment/src/routes/about/+page.svelte +++ b/playgrounds/vite-node-environment/src/routes/about/+page.svelte @@ -1,7 +1,7 @@ -

      About

      +

      About

      \ No newline at end of file diff --git a/playgrounds/vite-node-environment/src/routes/endpoint/+server.ts b/playgrounds/vite-node-environment/src/routes/endpoint/+server.ts index 6e88328e1cff..8ba35ce74030 100644 --- a/playgrounds/vite-node-environment/src/routes/endpoint/+server.ts +++ b/playgrounds/vite-node-environment/src/routes/endpoint/+server.ts @@ -1,7 +1,7 @@ import { error } from '@sveltejs/kit'; -import type { RequestHandler } from './$types'; +import type { RequestEvent } from './$types'; -export const GET: RequestHandler = ({ url }) => { +export function GET({ url }: RequestEvent) { const min = Number(url.searchParams.get('min') ?? '0'); const max = Number(url.searchParams.get('max') ?? '1'); const d = max - min; @@ -9,5 +9,6 @@ export const GET: RequestHandler = ({ url }) => { error(400, 'min and max must be numbers, and min must be less than max'); } const random = min + Math.random() * d; + return new Response(String(random)); -}; +} diff --git a/playgrounds/vite-node-environment/src/routes/matchers/[page=fruit]/+page.svelte b/playgrounds/vite-node-environment/src/routes/matchers/[page=fruit]/+page.svelte new file mode 100644 index 000000000000..f5d570567a32 --- /dev/null +++ b/playgrounds/vite-node-environment/src/routes/matchers/[page=fruit]/+page.svelte @@ -0,0 +1,16 @@ + + +

      {$page.params.page}

      + + + \ No newline at end of file diff --git a/playgrounds/vite-workerd-environment/svelte.config.js b/playgrounds/vite-workerd-environment/svelte.config.js index 6b4f6a452699..d8a019be1968 100644 --- a/playgrounds/vite-workerd-environment/svelte.config.js +++ b/playgrounds/vite-workerd-environment/svelte.config.js @@ -5,10 +5,10 @@ import { workerd as cloudflare } from '@dario-hacking/vite-6-alpha-environment-p /** @type {import('@sveltejs/kit').Config} */ const config = { kit: { - adapter: adapter() - // environments: { - // ssr: cloudflare({}) - // } + adapter: adapter(), + environments: { + ssr: cloudflare({}) + } }, preprocess: [vitePreprocess()] }; From 0c5c6c3f2c38ab19f62b27bc67806d0e6320bc8f Mon Sep 17 00:00:00 2001 From: James Opstad Date: Sat, 31 Aug 2024 19:47:49 +0100 Subject: [PATCH 30/61] Updated config test --- packages/kit/src/core/config/index.spec.js | 3 +++ packages/kit/src/core/config/options.js | 10 +++------- packages/kit/src/exports/vite/index.js | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/kit/src/core/config/index.spec.js b/packages/kit/src/core/config/index.spec.js index e5639defc4c2..623cdf67eb91 100644 --- a/packages/kit/src/core/config/index.spec.js +++ b/packages/kit/src/core/config/index.spec.js @@ -75,6 +75,9 @@ const get_defaults = (prefix = '') => ({ publicPrefix: 'PUBLIC_', privatePrefix: '' }, + environments: { + ssr: null + }, files: { assets: join(prefix, 'static'), hooks: { diff --git a/packages/kit/src/core/config/options.js b/packages/kit/src/core/config/options.js index b86b02a351f5..560102c1e5af 100644 --- a/packages/kit/src/core/config/options.js +++ b/packages/kit/src/core/config/options.js @@ -1,5 +1,4 @@ import { join } from 'node:path'; -import { default_environment } from '../../exports/vite/dev/default_environment.js'; /** @typedef {import('./types.js').Validator} Validator */ @@ -121,12 +120,9 @@ const options = object( }), environments: object({ - ssr: validate( - () => [], - (input) => { - return input; - } - ) + ssr: validate(null, (input) => { + return input; + }) }), files: object({ diff --git a/packages/kit/src/exports/vite/index.js b/packages/kit/src/exports/vite/index.js index 1d20bc68c27d..061ef503b7aa 100644 --- a/packages/kit/src/exports/vite/index.js +++ b/packages/kit/src/exports/vite/index.js @@ -1069,7 +1069,7 @@ async function kit({ svelte_config }) { }; return [ - ...svelte_config.kit.environments.ssr(SSR_ENVIRONMENT_NAME, {}), + ...(svelte_config.kit.environments.ssr?.(SSR_ENVIRONMENT_NAME, {}) ?? []), plugin_setup, plugin_virtual_modules, plugin_guard, From 699aa8b04a0a96b5d89fabcbc997238b5ef1852f Mon Sep 17 00:00:00 2001 From: James Opstad Date: Sat, 31 Aug 2024 20:21:21 +0100 Subject: [PATCH 31/61] Export Server class to use in entrypoint --- packages/kit/src/exports/index.js | 1 + packages/kit/src/exports/vite/dev/workerd_entrypoint.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/kit/src/exports/index.js b/packages/kit/src/exports/index.js index 32fb827dc629..5a20bf4bccad 100644 --- a/packages/kit/src/exports/index.js +++ b/packages/kit/src/exports/index.js @@ -2,6 +2,7 @@ import { HttpError, Redirect, ActionFailure } from '../runtime/control.js'; import { BROWSER, DEV } from 'esm-env'; export { VERSION } from '../version.js'; +export { Server } from '../runtime/server/index.js'; // TODO 3.0: remove these types as they are not used anymore (we can't remove them yet because that would be a breaking change) /** diff --git a/packages/kit/src/exports/vite/dev/workerd_entrypoint.js b/packages/kit/src/exports/vite/dev/workerd_entrypoint.js index 7ad0eee79cfb..ec9bf0b32041 100644 --- a/packages/kit/src/exports/vite/dev/workerd_entrypoint.js +++ b/packages/kit/src/exports/vite/dev/workerd_entrypoint.js @@ -1,4 +1,4 @@ -import { Server } from '../../../runtime/server/index.js'; +import { Server } from '@sveltejs/kit'; export default { /** From d087bbf2e5496a390385d6b5891cb05d49dcfe51 Mon Sep 17 00:00:00 2001 From: James Opstad Date: Sat, 31 Aug 2024 20:43:40 +0100 Subject: [PATCH 32/61] Tidied up virtual module code --- packages/kit/src/exports/vite/index.js | 23 +++++++------------ .../server/environment_context.js} | 0 .../routes/cf-properties/[[key]]/+page.svelte | 2 -- 3 files changed, 8 insertions(+), 17 deletions(-) rename packages/kit/src/{exports/vite/dev/utils.js => runtime/server/environment_context.js} (100%) diff --git a/packages/kit/src/exports/vite/index.js b/packages/kit/src/exports/vite/index.js index 061ef503b7aa..bd4ddc80f0a2 100644 --- a/packages/kit/src/exports/vite/index.js +++ b/packages/kit/src/exports/vite/index.js @@ -518,10 +518,10 @@ async function kit({ svelte_config }) { case sveltekit_environment_context: { const { manifest_data, env, remote_address } = environment_context; - const manifest = dedent` - import { create_resolve } from ${s(`${runtime_base}/../exports/vite/dev/utils.js`)}; + return dedent` + import { create_resolve } from "${runtime_base}/server/environment_context.js"; - const resolve = create_resolve(${s(cwd)}) + const resolve = create_resolve(${s(cwd)}); export let manifest = { appDir: ${s(svelte_config.kit.appDir)}, @@ -530,8 +530,8 @@ async function kit({ svelte_config }) { mimeTypes: ${s(get_mime_lookup(manifest_data))}, _: { client: { - start: ${s(`${runtime_base}/client/entry.js`)}, - app: ${s(`${to_fs(svelte_config.kit.outDir)}/generated/client/app.js`)}, + start: "${runtime_base}/client/entry.js", + app: "${to_fs(svelte_config.kit.outDir)}/generated/client/app.js", imports: [], stylesheets: [], fonts: [], @@ -548,10 +548,8 @@ async function kit({ svelte_config }) { return dedent` async () => { - /** @type {import('types').SSRNode} */ const result = {}; - /** @type {import('vite').ModuleNode[]} */ const module_nodes = []; result.index = ${index}; @@ -618,12 +616,9 @@ async function kit({ svelte_config }) { ).join(',\n')} ], matchers: async () => { - /** @type {Record} */ const matchers = {}; for (const [key, file] of ${s(Object.entries(manifest_data.matchers))}) { - // const url = path.resolve(cwd, file); - // const module = await import(/* @vite-ignore */ url); const { module } = await resolve(file); if (module.match) { @@ -638,14 +633,12 @@ async function kit({ svelte_config }) { } }; - export let env = ${s(env)} + export let env = ${s(env)}; - export let remote_address = ${s(remote_address)} + export let remote_address = ${s(remote_address)}; - export let assets_directory = ${s(svelte_config.kit.files.assets)} + export let assets_directory = ${s(svelte_config.kit.files.assets)}; `; - - return manifest; } } } diff --git a/packages/kit/src/exports/vite/dev/utils.js b/packages/kit/src/runtime/server/environment_context.js similarity index 100% rename from packages/kit/src/exports/vite/dev/utils.js rename to packages/kit/src/runtime/server/environment_context.js diff --git a/playgrounds/vite-workerd-environment/src/routes/cf-properties/[[key]]/+page.svelte b/playgrounds/vite-workerd-environment/src/routes/cf-properties/[[key]]/+page.svelte index 2041bb671e17..5a4252d2111e 100644 --- a/playgrounds/vite-workerd-environment/src/routes/cf-properties/[[key]]/+page.svelte +++ b/playgrounds/vite-workerd-environment/src/routes/cf-properties/[[key]]/+page.svelte @@ -2,8 +2,6 @@ import type { PageData } from "./$types"; export let data: PageData - - console.log(data)
      From afdbcdc01435fda3740104d3a4f446eecb661384 Mon Sep 17 00:00:00 2001 From: James Opstad Date: Sat, 31 Aug 2024 21:12:54 +0100 Subject: [PATCH 33/61] Imported default environment in vite-node-environment playground --- .../exports/vite/dev/default_environment.js | 36 ++++++++++--------- packages/kit/src/exports/vite/dev/index.js | 20 ++++++----- .../src/exports/vite/dev/node_entrypoint.js | 10 +++--- packages/kit/types/index.d.ts | 19 +++++----- .../vite-node-environment/svelte.config.js | 6 +++- 5 files changed, 53 insertions(+), 38 deletions(-) diff --git a/packages/kit/src/exports/vite/dev/default_environment.js b/packages/kit/src/exports/vite/dev/default_environment.js index fe9793492d0b..5ed5e1a9c4f2 100644 --- a/packages/kit/src/exports/vite/dev/default_environment.js +++ b/packages/kit/src/exports/vite/dev/default_environment.js @@ -1,25 +1,27 @@ import { createNodeDevEnvironment } from 'vite'; /** - * @param {string} environment_name - * @returns {import('vite').Plugin[]} + * + * @returns {(environment_name: string) => import('vite').Plugin[]} */ -export function default_environment(environment_name) { - return [ - { - name: 'default-environment-plugin', - // @ts-ignore should the options parameter for createNodeDevEnvironment be optional? - config: () => { - return { - environments: { - [environment_name]: { - dev: { - createEnvironment: createNodeDevEnvironment +export function node() { + // @ts-ignore + return function default_environment(environment_name) { + return [ + { + name: 'default-environment-plugin', + config: () => { + return { + environments: { + [environment_name]: { + dev: { + createEnvironment: createNodeDevEnvironment + } } } - } - }; + }; + } } - } - ]; + ]; + }; } diff --git a/packages/kit/src/exports/vite/dev/index.js b/packages/kit/src/exports/vite/dev/index.js index 9820acd96881..4e8e2e30e77b 100644 --- a/packages/kit/src/exports/vite/dev/index.js +++ b/packages/kit/src/exports/vite/dev/index.js @@ -449,14 +449,18 @@ export async function dev(vite, vite_config, svelte_config, environment_context) /** @type {((req: Request) => Promise) | undefined} */ let handler; - if (devEnv?.api) { - handler = await devEnv.api.getHandler({ - entrypoint: path.join(__dirname, 'workerd_entrypoint.js') - }); - } else { - // const module_runner = createServerModuleRunner(vite.environments[SSR_ENVIRONMENT_NAME]); - // const entrypoint = await module_runner.import(path.join(__dirname, 'node_entrypoint.js')); - // handler = entrypoint.default.fetch; + if (devEnv) { + if (devEnv.api) { + handler = await devEnv.api.getHandler({ + entrypoint: path.join(__dirname, 'workerd_entrypoint.js') + }); + console.log('Running in Cloudflare environment'); + } else { + const module_runner = createServerModuleRunner(vite.environments[SSR_ENVIRONMENT_NAME]); + const entrypoint = await module_runner.import(path.join(__dirname, 'node_entrypoint.js')); + handler = entrypoint.default.fetch; + console.log('Running in Node environment'); + } } return () => { diff --git a/packages/kit/src/exports/vite/dev/node_entrypoint.js b/packages/kit/src/exports/vite/dev/node_entrypoint.js index 0e80e5b2fa01..d517c4dfd04b 100644 --- a/packages/kit/src/exports/vite/dev/node_entrypoint.js +++ b/packages/kit/src/exports/vite/dev/node_entrypoint.js @@ -1,9 +1,11 @@ -import { Server } from '../../../runtime/server/index.js'; - -const environment_context = await import('__sveltekit/environment_context'); +import { Server } from '@sveltejs/kit'; export default { - fetch: /** @param {Request} request **/ async (request) => { + /** + * @param {Request} request + */ + fetch: async (request) => { + const environment_context = await import('__sveltekit/environment_context'); const server = new Server(environment_context.manifest); await server.init({ diff --git a/packages/kit/types/index.d.ts b/packages/kit/types/index.d.ts index caaa8b4a53f4..6699b3c9299e 100644 --- a/packages/kit/types/index.d.ts +++ b/packages/kit/types/index.d.ts @@ -38,8 +38,8 @@ declare module '@sveltejs/kit' { export type LoadProperties | void> = input extends void ? undefined // needs to be undefined, because void will break intellisense : input extends Record - ? input - : unknown; + ? input + : unknown; export type AwaitedActions any>> = OptionalUnion< { @@ -62,11 +62,12 @@ declare module '@sveltejs/kit' { [uniqueSymbol]: true; // necessary or else UnpackValidationError could wrongly unpack objects with the same shape as ActionFailure } - type UnpackValidationError = T extends ActionFailure - ? X - : T extends void - ? undefined // needs to be undefined, because void will corrupt union type - : T; + type UnpackValidationError = + T extends ActionFailure + ? X + : T extends void + ? undefined // needs to be undefined, because void will corrupt union type + : T; /** * This object is passed to the `adapt` function of adapters. @@ -389,6 +390,9 @@ declare module '@sveltejs/kit' { */ privatePrefix?: string; }; + environments?: { + ssr?: (environmentName: string, options: any) => Plugin[]; + }; /** * Where to find various files within your project. */ @@ -600,7 +604,6 @@ declare module '@sveltejs/kit' { */ files?(filepath: string): boolean; }; - ssrEnvironment?: (environmentName: string, options: any) => Plugin[]; typescript?: { /** * A function that allows you to edit the generated `tsconfig.json`. You can mutate the config (recommended) or return a new one. diff --git a/playgrounds/vite-node-environment/svelte.config.js b/playgrounds/vite-node-environment/svelte.config.js index 955074498330..e987cd5dcf11 100644 --- a/playgrounds/vite-node-environment/svelte.config.js +++ b/playgrounds/vite-node-environment/svelte.config.js @@ -1,10 +1,14 @@ import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'; import adapter from '@sveltejs/adapter-auto'; +import { node } from '../../packages/kit/src/exports/vite/dev/default_environment.js'; /** @type {import('@sveltejs/kit').Config} */ const config = { kit: { - adapter: adapter() + adapter: adapter(), + environments: { + ssr: node() + } }, preprocess: [vitePreprocess()] }; From b5a6c0068bfa3fcd9613825728789f89ed459123 Mon Sep 17 00:00:00 2001 From: James Opstad Date: Sat, 31 Aug 2024 21:41:44 +0100 Subject: [PATCH 34/61] Reverted exporting Server --- packages/kit/src/exports/index.js | 1 - packages/kit/src/exports/vite/dev/node_entrypoint.js | 3 ++- packages/kit/src/exports/vite/dev/workerd_entrypoint.js | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/kit/src/exports/index.js b/packages/kit/src/exports/index.js index 5a20bf4bccad..32fb827dc629 100644 --- a/packages/kit/src/exports/index.js +++ b/packages/kit/src/exports/index.js @@ -2,7 +2,6 @@ import { HttpError, Redirect, ActionFailure } from '../runtime/control.js'; import { BROWSER, DEV } from 'esm-env'; export { VERSION } from '../version.js'; -export { Server } from '../runtime/server/index.js'; // TODO 3.0: remove these types as they are not used anymore (we can't remove them yet because that would be a breaking change) /** diff --git a/packages/kit/src/exports/vite/dev/node_entrypoint.js b/packages/kit/src/exports/vite/dev/node_entrypoint.js index d517c4dfd04b..e08d471933a3 100644 --- a/packages/kit/src/exports/vite/dev/node_entrypoint.js +++ b/packages/kit/src/exports/vite/dev/node_entrypoint.js @@ -1,4 +1,5 @@ -import { Server } from '@sveltejs/kit'; +// This should be exported from @sveltejs/kit so that the path isn't relative +import { Server } from '../../../runtime/server/index.js'; export default { /** diff --git a/packages/kit/src/exports/vite/dev/workerd_entrypoint.js b/packages/kit/src/exports/vite/dev/workerd_entrypoint.js index ec9bf0b32041..fa8c81925b49 100644 --- a/packages/kit/src/exports/vite/dev/workerd_entrypoint.js +++ b/packages/kit/src/exports/vite/dev/workerd_entrypoint.js @@ -1,4 +1,5 @@ -import { Server } from '@sveltejs/kit'; +// This should be exported from @sveltejs/kit so that the path isn't relative +import { Server } from '../../../runtime/server/index.js'; export default { /** From be9d6a08175040bbe993b31741ac5d6ada8c55e7 Mon Sep 17 00:00:00 2001 From: James Opstad Date: Sun, 1 Sep 2024 22:36:40 +0100 Subject: [PATCH 35/61] Added comments --- packages/kit/src/core/config/options.js | 1 + packages/kit/src/exports/public.d.ts | 3 +++ .../src/exports/vite/dev/default_environment.js | 4 ++-- packages/kit/src/exports/vite/dev/index.js | 15 +++++++++++++-- .../kit/src/exports/vite/dev/node_entrypoint.js | 8 +++----- .../src/exports/vite/dev/workerd_entrypoint.js | 9 ++++----- packages/kit/src/exports/vite/index.js | 8 ++++++-- packages/kit/src/exports/vite/module_ids.js | 1 + .../kit/src/runtime/server/environment_context.js | 4 +++- 9 files changed, 36 insertions(+), 17 deletions(-) diff --git a/packages/kit/src/core/config/options.js b/packages/kit/src/core/config/options.js index 560102c1e5af..be7d31b8ef5c 100644 --- a/packages/kit/src/core/config/options.js +++ b/packages/kit/src/core/config/options.js @@ -119,6 +119,7 @@ const options = object( privatePrefix: string('') }), + // New environments option. The fallback for each environment could eventually be a default Node environment. environments: object({ ssr: validate(null, (input) => { return input; diff --git a/packages/kit/src/exports/public.d.ts b/packages/kit/src/exports/public.d.ts index deca804dc2ff..4e1442d25eaf 100644 --- a/packages/kit/src/exports/public.d.ts +++ b/packages/kit/src/exports/public.d.ts @@ -408,6 +408,9 @@ export interface KitConfig { */ privatePrefix?: string; }; + /** + * The new `environments` option. The user provides a factory function that is then used to create the plugin. + */ environments?: { ssr?: (environmentName: string, options: any) => Plugin[]; }; diff --git a/packages/kit/src/exports/vite/dev/default_environment.js b/packages/kit/src/exports/vite/dev/default_environment.js index 5ed5e1a9c4f2..08b563744216 100644 --- a/packages/kit/src/exports/vite/dev/default_environment.js +++ b/packages/kit/src/exports/vite/dev/default_environment.js @@ -1,7 +1,7 @@ import { createNodeDevEnvironment } from 'vite'; /** - * + * A default Node environment to pass to kit.environments.ssr in the Svelte config. This could eventually be used as the fallback for this option. * @returns {(environment_name: string) => import('vite').Plugin[]} */ export function node() { @@ -9,7 +9,7 @@ export function node() { return function default_environment(environment_name) { return [ { - name: 'default-environment-plugin', + name: 'vite-plugin-sveltekit-default-environment', config: () => { return { environments: { diff --git a/packages/kit/src/exports/vite/dev/index.js b/packages/kit/src/exports/vite/dev/index.js index 4e8e2e30e77b..8338db3b4174 100644 --- a/packages/kit/src/exports/vite/dev/index.js +++ b/packages/kit/src/exports/vite/dev/index.js @@ -100,7 +100,9 @@ export async function dev(vite, vite_config, svelte_config, environment_context) return { module, module_node, url }; } - // this may not be needed + /** + * Used to invalidate the `sveltekit_environment_context` module when the manifest is updated. + */ function invalidate_environment_context_module() { for (const environment in vite.environments) { const module = vite.environments[environment].moduleGraph.getModuleById( @@ -117,7 +119,9 @@ export async function dev(vite, vite_config, svelte_config, environment_context) try { ({ manifest_data } = sync.create(svelte_config)); + // Update the `manifest_data` used in the `sveltekit_environment_context` virtual module. environment_context.manifest_data = manifest_data; + // Invalidate the virtual module. invalidate_environment_context_module(); if (manifest_error) { @@ -438,10 +442,14 @@ export async function dev(vite, vite_config, svelte_config, environment_context) }); const env = loadEnv(vite_config.mode, svelte_config.kit.env.dir, ''); + // Update the `env` used in the `sveltekit_environment_context` virtual module. environment_context.env = env; const emulator = await svelte_config.kit.adapter?.emulate?.(); - /** @type { ((import('vite').DevEnvironment & { api?: { getHandler: (opts: { entrypoint: string }) => Promise<(req: Request) => Promise> }})) | undefined } */ + /** + * The environment that was provided to `kit.environments.ssr` in the Svelte config. + * @type { ((import('vite').DevEnvironment & { api?: { getHandler: (opts: { entrypoint: string }) => Promise<(req: Request) => Promise> }})) | undefined } + */ const devEnv = vite.environments[SSR_ENVIRONMENT_NAME]; const __dirname = fileURLToPath(new URL('.', import.meta.url)); @@ -449,6 +457,7 @@ export async function dev(vite, vite_config, svelte_config, environment_context) /** @type {((req: Request) => Promise) | undefined} */ let handler; + // Create the handler for the Cloudflare or Node environment if it exists. if (devEnv) { if (devEnv.api) { handler = await devEnv.api.getHandler({ @@ -474,6 +483,7 @@ export async function dev(vite, vite_config, svelte_config, environment_context) remove_static_middlewares(vite.middlewares); vite.middlewares.use(async (req, res) => { + // Update the `remote_address` used in the `sveltekit_environment_context` virtual module. environment_context.remote_address = req.socket.remoteAddress; // Vite's base middleware strips out the base path. Restore it @@ -565,6 +575,7 @@ export async function dev(vite, vite_config, svelte_config, environment_context) return; } + // Render using the environment handler if it has been created. Else, fallback to the default behaviour. const rendered = handler ? await handler(request) : await server.respond(request, { diff --git a/packages/kit/src/exports/vite/dev/node_entrypoint.js b/packages/kit/src/exports/vite/dev/node_entrypoint.js index e08d471933a3..94be053a95dc 100644 --- a/packages/kit/src/exports/vite/dev/node_entrypoint.js +++ b/packages/kit/src/exports/vite/dev/node_entrypoint.js @@ -3,6 +3,7 @@ import { Server } from '../../../runtime/server/index.js'; export default { /** + * This fetch handler is the entrypoint for the environment. * @param {Request} request */ fetch: async (request) => { @@ -15,11 +16,8 @@ export default { return server.respond(request, { getClientAddress: () => { - if (!environment_context.remote_address) { - throw new Error('Could not determine clientAddress'); - } - - return environment_context.remote_address; + if (environment_context.remote_address) return environment_context.remote_address; + throw new Error('Could not determine clientAddress'); } }); } diff --git a/packages/kit/src/exports/vite/dev/workerd_entrypoint.js b/packages/kit/src/exports/vite/dev/workerd_entrypoint.js index fa8c81925b49..c3cc3057ba91 100644 --- a/packages/kit/src/exports/vite/dev/workerd_entrypoint.js +++ b/packages/kit/src/exports/vite/dev/workerd_entrypoint.js @@ -3,6 +3,7 @@ import { Server } from '../../../runtime/server/index.js'; export default { /** + * This fetch handler is the entrypoint for the environment. * @param {Request & { cf: any }} request * @param {any} env * @param {any} context @@ -17,12 +18,10 @@ export default { return server.respond(request, { getClientAddress: () => { - if (!environment_context.remote_address) { - throw new Error('Could not determine clientAddress'); - } - - return environment_context.remote_address; + if (environment_context.remote_address) return environment_context.remote_address; + throw new Error('Could not determine clientAddress'); }, + // We can provide the platform properties directly as the code is executed in a workerd environment. platform: { env, cf: request.cf, diff --git a/packages/kit/src/exports/vite/index.js b/packages/kit/src/exports/vite/index.js index bd4ddc80f0a2..e8497b22021e 100644 --- a/packages/kit/src/exports/vite/index.js +++ b/packages/kit/src/exports/vite/index.js @@ -46,6 +46,9 @@ import { import { resolve_peer_dependency } from '../../utils/import.js'; import { SSR_ENVIRONMENT_NAME } from './constants.js'; +/** + * This is where we store the values that are needed in the `sveltekit_environment_context` virtual module. + */ const environment_context = /** @type {import('types').EnvironmentContext} */ ({}); const cwd = process.cwd(); @@ -515,6 +518,7 @@ async function kit({ svelte_config }) { `; } + // The virtual module that is imported in the environment entrypoint files. This provides all the data that is needed to create the `Server` instance. case sveltekit_environment_context: { const { manifest_data, env, remote_address } = environment_context; @@ -636,8 +640,6 @@ async function kit({ svelte_config }) { export let env = ${s(env)}; export let remote_address = ${s(remote_address)}; - - export let assets_directory = ${s(svelte_config.kit.files.assets)}; `; } } @@ -808,6 +810,7 @@ async function kit({ svelte_config }) { * @see https://vitejs.dev/guide/api-plugin.html#configureserver */ async configureServer(vite) { + // We pass the `environment_context` object in so that we can update the values inside the `dev` function. Not ideal but avoids restructuring the code for the time being. return await dev(vite, vite_config, svelte_config, environment_context); }, @@ -1062,6 +1065,7 @@ async function kit({ svelte_config }) { }; return [ + // Creates the custom SSR environment if the factory function was passed to `kit.environments.ssr` in the Svelte config. ...(svelte_config.kit.environments.ssr?.(SSR_ENVIRONMENT_NAME, {}) ?? []), plugin_setup, plugin_virtual_modules, diff --git a/packages/kit/src/exports/vite/module_ids.js b/packages/kit/src/exports/vite/module_ids.js index 432eb1d9b141..669f8cdeea06 100644 --- a/packages/kit/src/exports/vite/module_ids.js +++ b/packages/kit/src/exports/vite/module_ids.js @@ -10,6 +10,7 @@ export const service_worker = '\0virtual:$service-worker'; export const sveltekit_environment = '\0virtual:__sveltekit/environment'; export const sveltekit_paths = '\0virtual:__sveltekit/paths'; export const sveltekit_server = '\0virtual:__sveltekit/server'; +// The new virtual module to be imported in custom environments (probably not the best name!). export const sveltekit_environment_context = '\0virtual:__sveltekit/environment_context'; export const app_server = fileURLToPath( diff --git a/packages/kit/src/runtime/server/environment_context.js b/packages/kit/src/runtime/server/environment_context.js index 0eafd09fac8e..0de09795f218 100644 --- a/packages/kit/src/runtime/server/environment_context.js +++ b/packages/kit/src/runtime/server/environment_context.js @@ -1,7 +1,9 @@ +// We're using `pathe` rather than `node:path` for compatibility with other runtimes. import * as pathe from 'pathe'; /** @param {string} url */ async function loud_ssr_load_module(url) { + // We can use a dynamic import rather than `vite.ssrLoadModule` because it will be executed inside the environment module runner. return await import(/* @vite-ignore */ url); } @@ -9,7 +11,7 @@ async function loud_ssr_load_module(url) { export function create_resolve(cwd) { /** @param {string} id */ return async function resolve(id) { - // use to_fs? + // Do we need `to_fs` here? If so we'll need to split it out into a module that doesn't import from Node. const url = id.startsWith('..') ? pathe.resolve(cwd, id) : `/${id}`; const module = await loud_ssr_load_module(url); From 5f6670807db9535b019d5e08998a286803581f32 Mon Sep 17 00:00:00 2001 From: James Opstad Date: Mon, 2 Sep 2024 13:21:30 +0100 Subject: [PATCH 36/61] Replaced cloudflare environment provider dependency --- packages/kit/src/exports/public.d.ts | 2 +- packages/kit/src/exports/vite/index.js | 5 +- .../src/runtime/server/environment_context.js | 4 ++ .../vite-workerd-environment/package.json | 2 +- .../vite-workerd-environment/svelte.config.js | 4 +- pnpm-lock.yaml | 70 +++++++------------ 6 files changed, 38 insertions(+), 49 deletions(-) diff --git a/packages/kit/src/exports/public.d.ts b/packages/kit/src/exports/public.d.ts index 4e1442d25eaf..19f50e3353b3 100644 --- a/packages/kit/src/exports/public.d.ts +++ b/packages/kit/src/exports/public.d.ts @@ -412,7 +412,7 @@ export interface KitConfig { * The new `environments` option. The user provides a factory function that is then used to create the plugin. */ environments?: { - ssr?: (environmentName: string, options: any) => Plugin[]; + ssr?: (environmentName: string, options?: any) => Plugin[]; }; /** * Where to find various files within your project. diff --git a/packages/kit/src/exports/vite/index.js b/packages/kit/src/exports/vite/index.js index e8497b22021e..bbd7fe8e2d6c 100644 --- a/packages/kit/src/exports/vite/index.js +++ b/packages/kit/src/exports/vite/index.js @@ -519,6 +519,9 @@ async function kit({ svelte_config }) { } // The virtual module that is imported in the environment entrypoint files. This provides all the data that is needed to create the `Server` instance. + // Not implemented: + // - Server assets. The `read` function from `$app/server` can only be used in environments that support file system access. + // - Inlining styles. This requires communicating with the main process to collect dependencies. It should be possible (e.g. using import.meta.hot) but needs more investigation. case sveltekit_environment_context: { const { manifest_data, env, remote_address } = environment_context; @@ -1066,7 +1069,7 @@ async function kit({ svelte_config }) { return [ // Creates the custom SSR environment if the factory function was passed to `kit.environments.ssr` in the Svelte config. - ...(svelte_config.kit.environments.ssr?.(SSR_ENVIRONMENT_NAME, {}) ?? []), + ...(svelte_config.kit.environments.ssr?.(SSR_ENVIRONMENT_NAME) ?? []), plugin_setup, plugin_virtual_modules, plugin_guard, diff --git a/packages/kit/src/runtime/server/environment_context.js b/packages/kit/src/runtime/server/environment_context.js index 0de09795f218..ec694a3c801f 100644 --- a/packages/kit/src/runtime/server/environment_context.js +++ b/packages/kit/src/runtime/server/environment_context.js @@ -5,6 +5,8 @@ import * as pathe from 'pathe'; async function loud_ssr_load_module(url) { // We can use a dynamic import rather than `vite.ssrLoadModule` because it will be executed inside the environment module runner. return await import(/* @vite-ignore */ url); + + // TODO: report errors using import.meta.hot.send } /** @param {string} cwd */ @@ -17,5 +19,7 @@ export function create_resolve(cwd) { const module = await loud_ssr_load_module(url); return { module, url }; + + // TODO: return module nodes or use alternative approach to collect dependencies for inlining CSS }; } diff --git a/playgrounds/vite-workerd-environment/package.json b/playgrounds/vite-workerd-environment/package.json index 17fbd96fc0d7..deda35fa5671 100644 --- a/playgrounds/vite-workerd-environment/package.json +++ b/playgrounds/vite-workerd-environment/package.json @@ -14,7 +14,7 @@ }, "devDependencies": { "@cloudflare/workers-types": "^4.20231121.0", - "@dario-hacking/vite-6-alpha-environment-provider-workerd": "^0.0.5", + "@flarelabs-net/vite-environment-provider-cloudflare": "^0.0.1", "@sveltejs/adapter-auto": "workspace:*", "@sveltejs/adapter-cloudflare": "workspace:*", "@sveltejs/adapter-cloudflare-workers": "workspace:*", diff --git a/playgrounds/vite-workerd-environment/svelte.config.js b/playgrounds/vite-workerd-environment/svelte.config.js index d8a019be1968..a2265e8c33cd 100644 --- a/playgrounds/vite-workerd-environment/svelte.config.js +++ b/playgrounds/vite-workerd-environment/svelte.config.js @@ -1,13 +1,13 @@ import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'; import adapter from '@sveltejs/adapter-auto'; -import { workerd as cloudflare } from '@dario-hacking/vite-6-alpha-environment-provider-workerd'; +import { cloudflare } from '@flarelabs-net/vite-environment-provider-cloudflare'; /** @type {import('@sveltejs/kit').Config} */ const config = { kit: { adapter: adapter(), environments: { - ssr: cloudflare({}) + ssr: cloudflare() } }, preprocess: [vitePreprocess()] diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 91a473750e95..59daa5b4dd3b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1295,9 +1295,9 @@ importers: '@cloudflare/workers-types': specifier: ^4.20231121.0 version: 4.20240405.0 - '@dario-hacking/vite-6-alpha-environment-provider-workerd': - specifier: ^0.0.5 - version: 0.0.5(miniflare@3.20240821.0)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1))(wrangler@3.72.3(@cloudflare/workers-types@4.20240405.0)) + '@flarelabs-net/vite-environment-provider-cloudflare': + specifier: ^0.0.1 + version: 0.0.1(miniflare@3.20240821.0)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1))(wrangler@3.72.3(@cloudflare/workers-types@4.20240405.0)) '@sveltejs/adapter-auto': specifier: workspace:* version: link:../../packages/adapter-auto @@ -1584,13 +1584,6 @@ packages: resolution: {integrity: sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==} engines: {node: '>=12'} - '@dario-hacking/vite-6-alpha-environment-provider-workerd@0.0.5': - resolution: {integrity: sha512-9SXOJDE4IGszLG0cRzU38OLSXyJhKkmnzoeNYPua142bvb5XCeL9zNGqXk4sjQfVd7Dhh+iut89a3ubROhkPwg==} - peerDependencies: - miniflare: ^3.20240129.3 - vite: 6.0.0-alpha.23 - wrangler: ^3.57.2 - '@emnapi/runtime@1.2.0': resolution: {integrity: sha512-bV21/9LQmcQeCPEg3BDFtvwL6cwiTMksYNWQQ4KOxCZikEGalWtenoZ0wCiukJINlGCIi2KXx01g4FoH/LxpzQ==} @@ -1904,6 +1897,13 @@ packages: resolution: {integrity: sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA==} engines: {node: '>=14'} + '@flarelabs-net/vite-environment-provider-cloudflare@0.0.1': + resolution: {integrity: sha512-UEnV4IcFmOFYlzRuSdjCjXuTLptK5q1HuZ1jwQo9N3vmk5TOICkWvWVgwfUh/HihF9+B3lCIuJWNylakKUQbHg==} + peerDependencies: + miniflare: ^3.20240129.3 + vite: 6.0.0-alpha.23 + wrangler: ^3.57.2 + '@fontsource/fira-mono@5.0.12': resolution: {integrity: sha512-1uFRjqCcxVv4F31PjyLm8o4oNlT5ywwh6OwcDGkZbafOeFZHXekvholS9IlfZkRsZvVhSbFRHT/5iDib4KTtpg==} @@ -3833,10 +3833,6 @@ packages: resolution: {integrity: sha512-UMz42UD0UY0EApS0ZL9o1XnLhSTtvvvLe5Dc2H2O56fvRZi+KulDyf5ctDhhtYJBGKStV2FL1fy6253cmLgqVQ==} engines: {node: '>=4'} - postcss@8.4.39: - resolution: {integrity: sha512-0vzE+lAiG7hZl1/9I8yzKLx3aR9Xbof3fBHKunvMfOCYAtMhrsnccJY2iTURb9EZd5+pLuiNV9/c/GZJOHsgIw==} - engines: {node: ^10 || ^12 || >=14} - postcss@8.4.41: resolution: {integrity: sha512-TesUflQ0WKZqAvg52PWL6kHgLKP6xB6heTOdoYM0Wt2UHyxNa4K25EZZMgKns3BH1RLVbZCREPpLY0rhnNoHVQ==} engines: {node: ^10 || ^12 || >=14} @@ -4828,13 +4824,6 @@ snapshots: dependencies: '@jridgewell/trace-mapping': 0.3.9 - '@dario-hacking/vite-6-alpha-environment-provider-workerd@0.0.5(miniflare@3.20240821.0)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1))(wrangler@3.72.3(@cloudflare/workers-types@4.20240405.0))': - dependencies: - cjs-module-lexer: 1.3.1 - miniflare: 3.20240821.0 - vite: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) - wrangler: 3.72.3(@cloudflare/workers-types@4.20240405.0) - '@emnapi/runtime@1.2.0': dependencies: tslib: 2.6.2 @@ -5020,6 +5009,13 @@ snapshots: '@fastify/busboy@2.1.1': {} + '@flarelabs-net/vite-environment-provider-cloudflare@0.0.1(miniflare@3.20240821.0)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1))(wrangler@3.72.3(@cloudflare/workers-types@4.20240405.0))': + dependencies: + cjs-module-lexer: 1.3.1 + miniflare: 3.20240821.0 + vite: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) + wrangler: 3.72.3(@cloudflare/workers-types@4.20240405.0) + '@fontsource/fira-mono@5.0.12': {} '@humanwhocodes/module-importer@1.0.1': {} @@ -6070,9 +6066,9 @@ snapshots: eslint-compat-utils: 0.5.1(eslint@9.6.0) esutils: 2.0.3 known-css-properties: 0.34.0 - postcss: 8.4.39 - postcss-load-config: 3.1.4(postcss@8.4.39) - postcss-safe-parser: 6.0.0(postcss@8.4.39) + postcss: 8.4.41 + postcss-load-config: 3.1.4(postcss@8.4.41) + postcss-safe-parser: 6.0.0(postcss@8.4.41) postcss-selector-parser: 6.1.0 semver: 7.6.2 svelte-eslint-parser: 0.39.2(svelte@4.2.17) @@ -6871,40 +6867,26 @@ snapshots: '@polka/url': 1.0.0-next.25 trouter: 4.0.0 - postcss-load-config@3.1.4(postcss@8.4.39): - dependencies: - lilconfig: 2.1.0 - yaml: 1.10.2 - optionalDependencies: - postcss: 8.4.39 - postcss-load-config@3.1.4(postcss@8.4.41): dependencies: lilconfig: 2.1.0 yaml: 1.10.2 optionalDependencies: postcss: 8.4.41 - optional: true - postcss-safe-parser@6.0.0(postcss@8.4.39): + postcss-safe-parser@6.0.0(postcss@8.4.41): dependencies: - postcss: 8.4.39 + postcss: 8.4.41 - postcss-scss@4.0.9(postcss@8.4.39): + postcss-scss@4.0.9(postcss@8.4.41): dependencies: - postcss: 8.4.39 + postcss: 8.4.41 postcss-selector-parser@6.1.0: dependencies: cssesc: 3.0.0 util-deprecate: 1.0.2 - postcss@8.4.39: - dependencies: - nanoid: 3.3.7 - picocolors: 1.0.1 - source-map-js: 1.2.0 - postcss@8.4.41: dependencies: nanoid: 3.3.7 @@ -7294,8 +7276,8 @@ snapshots: eslint-scope: 7.2.2 eslint-visitor-keys: 3.4.3 espree: 9.6.1 - postcss: 8.4.39 - postcss-scss: 4.0.9(postcss@8.4.39) + postcss: 8.4.41 + postcss-scss: 4.0.9(postcss@8.4.41) optionalDependencies: svelte: 4.2.17 From a1b19cbd6f5e4a7d59634d29b720ec66772c6e45 Mon Sep 17 00:00:00 2001 From: James Opstad Date: Mon, 2 Sep 2024 13:26:37 +0100 Subject: [PATCH 37/61] Renamed vite-workerd-environment to vite-cloudflare-environment --- .../package.json | 2 +- .../src/app.d.ts | 0 .../src/app.html | 0 .../src/lib/index.js | 0 .../src/params/fruit.ts | 0 .../src/routes/+layout.svelte | 0 .../src/routes/+page.server.ts | 0 .../src/routes/+page.svelte | 0 .../src/routes/about/+page.svelte | 0 .../cf-properties/[[key]]/+page.server.ts | 0 .../routes/cf-properties/[[key]]/+page.svelte | 0 .../src/routes/endpoint/+server.ts | 0 .../routes/matchers/[page=fruit]/+page.svelte | 0 .../static/favicon.png | Bin .../svelte.config.js | 0 .../tsconfig.json | 0 .../vite.config.ts | 0 .../worker-configuration.d.ts | 0 .../wrangler.toml | 0 pnpm-lock.yaml | 22 +++++++++--------- 20 files changed, 12 insertions(+), 12 deletions(-) rename playgrounds/{vite-workerd-environment => vite-cloudflare-environment}/package.json (97%) rename playgrounds/{vite-workerd-environment => vite-cloudflare-environment}/src/app.d.ts (100%) rename playgrounds/{vite-workerd-environment => vite-cloudflare-environment}/src/app.html (100%) rename playgrounds/{vite-workerd-environment => vite-cloudflare-environment}/src/lib/index.js (100%) rename playgrounds/{vite-workerd-environment => vite-cloudflare-environment}/src/params/fruit.ts (100%) rename playgrounds/{vite-workerd-environment => vite-cloudflare-environment}/src/routes/+layout.svelte (100%) rename playgrounds/{vite-workerd-environment => vite-cloudflare-environment}/src/routes/+page.server.ts (100%) rename playgrounds/{vite-workerd-environment => vite-cloudflare-environment}/src/routes/+page.svelte (100%) rename playgrounds/{vite-workerd-environment => vite-cloudflare-environment}/src/routes/about/+page.svelte (100%) rename playgrounds/{vite-workerd-environment => vite-cloudflare-environment}/src/routes/cf-properties/[[key]]/+page.server.ts (100%) rename playgrounds/{vite-workerd-environment => vite-cloudflare-environment}/src/routes/cf-properties/[[key]]/+page.svelte (100%) rename playgrounds/{vite-workerd-environment => vite-cloudflare-environment}/src/routes/endpoint/+server.ts (100%) rename playgrounds/{vite-workerd-environment => vite-cloudflare-environment}/src/routes/matchers/[page=fruit]/+page.svelte (100%) rename playgrounds/{vite-workerd-environment => vite-cloudflare-environment}/static/favicon.png (100%) rename playgrounds/{vite-workerd-environment => vite-cloudflare-environment}/svelte.config.js (100%) rename playgrounds/{vite-workerd-environment => vite-cloudflare-environment}/tsconfig.json (100%) rename playgrounds/{vite-workerd-environment => vite-cloudflare-environment}/vite.config.ts (100%) rename playgrounds/{vite-workerd-environment => vite-cloudflare-environment}/worker-configuration.d.ts (100%) rename playgrounds/{vite-workerd-environment => vite-cloudflare-environment}/wrangler.toml (100%) diff --git a/playgrounds/vite-workerd-environment/package.json b/playgrounds/vite-cloudflare-environment/package.json similarity index 97% rename from playgrounds/vite-workerd-environment/package.json rename to playgrounds/vite-cloudflare-environment/package.json index deda35fa5671..0ddf5fd3c9b7 100644 --- a/playgrounds/vite-workerd-environment/package.json +++ b/playgrounds/vite-cloudflare-environment/package.json @@ -1,5 +1,5 @@ { - "name": "vite-workerd-environment", + "name": "vite-cloudflare-environment", "version": "0.0.0", "private": true, "scripts": { diff --git a/playgrounds/vite-workerd-environment/src/app.d.ts b/playgrounds/vite-cloudflare-environment/src/app.d.ts similarity index 100% rename from playgrounds/vite-workerd-environment/src/app.d.ts rename to playgrounds/vite-cloudflare-environment/src/app.d.ts diff --git a/playgrounds/vite-workerd-environment/src/app.html b/playgrounds/vite-cloudflare-environment/src/app.html similarity index 100% rename from playgrounds/vite-workerd-environment/src/app.html rename to playgrounds/vite-cloudflare-environment/src/app.html diff --git a/playgrounds/vite-workerd-environment/src/lib/index.js b/playgrounds/vite-cloudflare-environment/src/lib/index.js similarity index 100% rename from playgrounds/vite-workerd-environment/src/lib/index.js rename to playgrounds/vite-cloudflare-environment/src/lib/index.js diff --git a/playgrounds/vite-workerd-environment/src/params/fruit.ts b/playgrounds/vite-cloudflare-environment/src/params/fruit.ts similarity index 100% rename from playgrounds/vite-workerd-environment/src/params/fruit.ts rename to playgrounds/vite-cloudflare-environment/src/params/fruit.ts diff --git a/playgrounds/vite-workerd-environment/src/routes/+layout.svelte b/playgrounds/vite-cloudflare-environment/src/routes/+layout.svelte similarity index 100% rename from playgrounds/vite-workerd-environment/src/routes/+layout.svelte rename to playgrounds/vite-cloudflare-environment/src/routes/+layout.svelte diff --git a/playgrounds/vite-workerd-environment/src/routes/+page.server.ts b/playgrounds/vite-cloudflare-environment/src/routes/+page.server.ts similarity index 100% rename from playgrounds/vite-workerd-environment/src/routes/+page.server.ts rename to playgrounds/vite-cloudflare-environment/src/routes/+page.server.ts diff --git a/playgrounds/vite-workerd-environment/src/routes/+page.svelte b/playgrounds/vite-cloudflare-environment/src/routes/+page.svelte similarity index 100% rename from playgrounds/vite-workerd-environment/src/routes/+page.svelte rename to playgrounds/vite-cloudflare-environment/src/routes/+page.svelte diff --git a/playgrounds/vite-workerd-environment/src/routes/about/+page.svelte b/playgrounds/vite-cloudflare-environment/src/routes/about/+page.svelte similarity index 100% rename from playgrounds/vite-workerd-environment/src/routes/about/+page.svelte rename to playgrounds/vite-cloudflare-environment/src/routes/about/+page.svelte diff --git a/playgrounds/vite-workerd-environment/src/routes/cf-properties/[[key]]/+page.server.ts b/playgrounds/vite-cloudflare-environment/src/routes/cf-properties/[[key]]/+page.server.ts similarity index 100% rename from playgrounds/vite-workerd-environment/src/routes/cf-properties/[[key]]/+page.server.ts rename to playgrounds/vite-cloudflare-environment/src/routes/cf-properties/[[key]]/+page.server.ts diff --git a/playgrounds/vite-workerd-environment/src/routes/cf-properties/[[key]]/+page.svelte b/playgrounds/vite-cloudflare-environment/src/routes/cf-properties/[[key]]/+page.svelte similarity index 100% rename from playgrounds/vite-workerd-environment/src/routes/cf-properties/[[key]]/+page.svelte rename to playgrounds/vite-cloudflare-environment/src/routes/cf-properties/[[key]]/+page.svelte diff --git a/playgrounds/vite-workerd-environment/src/routes/endpoint/+server.ts b/playgrounds/vite-cloudflare-environment/src/routes/endpoint/+server.ts similarity index 100% rename from playgrounds/vite-workerd-environment/src/routes/endpoint/+server.ts rename to playgrounds/vite-cloudflare-environment/src/routes/endpoint/+server.ts diff --git a/playgrounds/vite-workerd-environment/src/routes/matchers/[page=fruit]/+page.svelte b/playgrounds/vite-cloudflare-environment/src/routes/matchers/[page=fruit]/+page.svelte similarity index 100% rename from playgrounds/vite-workerd-environment/src/routes/matchers/[page=fruit]/+page.svelte rename to playgrounds/vite-cloudflare-environment/src/routes/matchers/[page=fruit]/+page.svelte diff --git a/playgrounds/vite-workerd-environment/static/favicon.png b/playgrounds/vite-cloudflare-environment/static/favicon.png similarity index 100% rename from playgrounds/vite-workerd-environment/static/favicon.png rename to playgrounds/vite-cloudflare-environment/static/favicon.png diff --git a/playgrounds/vite-workerd-environment/svelte.config.js b/playgrounds/vite-cloudflare-environment/svelte.config.js similarity index 100% rename from playgrounds/vite-workerd-environment/svelte.config.js rename to playgrounds/vite-cloudflare-environment/svelte.config.js diff --git a/playgrounds/vite-workerd-environment/tsconfig.json b/playgrounds/vite-cloudflare-environment/tsconfig.json similarity index 100% rename from playgrounds/vite-workerd-environment/tsconfig.json rename to playgrounds/vite-cloudflare-environment/tsconfig.json diff --git a/playgrounds/vite-workerd-environment/vite.config.ts b/playgrounds/vite-cloudflare-environment/vite.config.ts similarity index 100% rename from playgrounds/vite-workerd-environment/vite.config.ts rename to playgrounds/vite-cloudflare-environment/vite.config.ts diff --git a/playgrounds/vite-workerd-environment/worker-configuration.d.ts b/playgrounds/vite-cloudflare-environment/worker-configuration.d.ts similarity index 100% rename from playgrounds/vite-workerd-environment/worker-configuration.d.ts rename to playgrounds/vite-cloudflare-environment/worker-configuration.d.ts diff --git a/playgrounds/vite-workerd-environment/wrangler.toml b/playgrounds/vite-cloudflare-environment/wrangler.toml similarity index 100% rename from playgrounds/vite-workerd-environment/wrangler.toml rename to playgrounds/vite-cloudflare-environment/wrangler.toml diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 59daa5b4dd3b..4a01f9cebc56 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1239,8 +1239,14 @@ importers: specifier: 6.0.0-alpha.23 version: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) - playgrounds/vite-node-environment: + playgrounds/vite-cloudflare-environment: devDependencies: + '@cloudflare/workers-types': + specifier: ^4.20231121.0 + version: 4.20240405.0 + '@flarelabs-net/vite-environment-provider-cloudflare': + specifier: ^0.0.1 + version: 0.0.1(miniflare@3.20240821.0)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1))(wrangler@3.72.3(@cloudflare/workers-types@4.20240405.0)) '@sveltejs/adapter-auto': specifier: workspace:* version: link:../../packages/adapter-auto @@ -1289,15 +1295,12 @@ importers: vite: specifier: 6.0.0-alpha.23 version: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) + wrangler: + specifier: ^3.72.3 + version: 3.72.3(@cloudflare/workers-types@4.20240405.0) - playgrounds/vite-workerd-environment: + playgrounds/vite-node-environment: devDependencies: - '@cloudflare/workers-types': - specifier: ^4.20231121.0 - version: 4.20240405.0 - '@flarelabs-net/vite-environment-provider-cloudflare': - specifier: ^0.0.1 - version: 0.0.1(miniflare@3.20240821.0)(vite@6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1))(wrangler@3.72.3(@cloudflare/workers-types@4.20240405.0)) '@sveltejs/adapter-auto': specifier: workspace:* version: link:../../packages/adapter-auto @@ -1346,9 +1349,6 @@ importers: vite: specifier: 6.0.0-alpha.23 version: 6.0.0-alpha.23(@types/node@18.19.31)(lightningcss@1.24.1) - wrangler: - specifier: ^3.72.3 - version: 3.72.3(@cloudflare/workers-types@4.20240405.0) sites/kit.svelte.dev: dependencies: From 71145cbd32495793a588af99fa8615016326a88b Mon Sep 17 00:00:00 2001 From: James Opstad Date: Mon, 2 Sep 2024 14:23:43 +0100 Subject: [PATCH 38/61] Changed playgrounds for TS to JS --- ...rd_entrypoint.js => cloudflare_entrypoint.js} | 0 packages/kit/src/exports/vite/dev/index.js | 2 +- packages/kit/types/index.d.ts | 5 ++++- .../jsconfig.json} | 6 ++---- .../src/params/fruit.js | 6 ++++++ .../src/params/fruit.ts | 3 --- .../src/routes/+layout.svelte | 2 +- .../routes/{+page.server.ts => +page.server.js} | 16 +++++++--------- .../src/routes/+page.svelte | 6 ++---- .../[[key]]/{+page.server.ts => +page.server.js} | 6 ++---- .../routes/cf-properties/[[key]]/+page.svelte | 6 ++---- .../src/routes/endpoint/+server.js} | 3 +-- .../routes/matchers/[page=fruit]/+page.svelte | 2 +- .../{vite.config.ts => vite.config.js} | 0 .../jsconfig.json} | 7 ++----- .../vite-node-environment/src/params/fruit.js | 6 ++++++ .../vite-node-environment/src/params/fruit.ts | 3 --- .../routes/{+page.server.ts => +page.server.js} | 2 +- .../src/routes/+page.svelte | 6 ++---- .../src/routes/endpoint/+server.js} | 3 +-- .../routes/matchers/[page=fruit]/+page.svelte | 2 +- .../{vite.config.ts => vite.config.js} | 0 22 files changed, 42 insertions(+), 50 deletions(-) rename packages/kit/src/exports/vite/dev/{workerd_entrypoint.js => cloudflare_entrypoint.js} (100%) rename playgrounds/{vite-node-environment/tsconfig.json => vite-cloudflare-environment/jsconfig.json} (76%) create mode 100644 playgrounds/vite-cloudflare-environment/src/params/fruit.js delete mode 100644 playgrounds/vite-cloudflare-environment/src/params/fruit.ts rename playgrounds/vite-cloudflare-environment/src/routes/{+page.server.ts => +page.server.js} (62%) rename playgrounds/vite-cloudflare-environment/src/routes/cf-properties/[[key]]/{+page.server.ts => +page.server.js} (50%) rename playgrounds/{vite-node-environment/src/routes/endpoint/+server.ts => vite-cloudflare-environment/src/routes/endpoint/+server.js} (79%) rename playgrounds/vite-cloudflare-environment/{vite.config.ts => vite.config.js} (100%) rename playgrounds/{vite-cloudflare-environment/tsconfig.json => vite-node-environment/jsconfig.json} (72%) create mode 100644 playgrounds/vite-node-environment/src/params/fruit.js delete mode 100644 playgrounds/vite-node-environment/src/params/fruit.ts rename playgrounds/vite-node-environment/src/routes/{+page.server.ts => +page.server.js} (86%) rename playgrounds/{vite-cloudflare-environment/src/routes/endpoint/+server.ts => vite-node-environment/src/routes/endpoint/+server.js} (79%) rename playgrounds/vite-node-environment/{vite.config.ts => vite.config.js} (100%) diff --git a/packages/kit/src/exports/vite/dev/workerd_entrypoint.js b/packages/kit/src/exports/vite/dev/cloudflare_entrypoint.js similarity index 100% rename from packages/kit/src/exports/vite/dev/workerd_entrypoint.js rename to packages/kit/src/exports/vite/dev/cloudflare_entrypoint.js diff --git a/packages/kit/src/exports/vite/dev/index.js b/packages/kit/src/exports/vite/dev/index.js index 8338db3b4174..352dafdecbcf 100644 --- a/packages/kit/src/exports/vite/dev/index.js +++ b/packages/kit/src/exports/vite/dev/index.js @@ -461,7 +461,7 @@ export async function dev(vite, vite_config, svelte_config, environment_context) if (devEnv) { if (devEnv.api) { handler = await devEnv.api.getHandler({ - entrypoint: path.join(__dirname, 'workerd_entrypoint.js') + entrypoint: path.join(__dirname, 'cloudflare_entrypoint.js') }); console.log('Running in Cloudflare environment'); } else { diff --git a/packages/kit/types/index.d.ts b/packages/kit/types/index.d.ts index 6699b3c9299e..0fa6e62e06db 100644 --- a/packages/kit/types/index.d.ts +++ b/packages/kit/types/index.d.ts @@ -390,8 +390,11 @@ declare module '@sveltejs/kit' { */ privatePrefix?: string; }; + /** + * The new `environments` option. The user provides a factory function that is then used to create the plugin. + */ environments?: { - ssr?: (environmentName: string, options: any) => Plugin[]; + ssr?: (environmentName: string, options?: any) => Plugin[]; }; /** * Where to find various files within your project. diff --git a/playgrounds/vite-node-environment/tsconfig.json b/playgrounds/vite-cloudflare-environment/jsconfig.json similarity index 76% rename from playgrounds/vite-node-environment/tsconfig.json rename to playgrounds/vite-cloudflare-environment/jsconfig.json index fc93cbd9409f..fe45e13fdd06 100644 --- a/playgrounds/vite-node-environment/tsconfig.json +++ b/playgrounds/vite-cloudflare-environment/jsconfig.json @@ -8,11 +8,9 @@ "resolveJsonModule": true, "skipLibCheck": true, "sourceMap": true, - "strict": true, - "moduleResolution": "bundler" + "strict": true } - // Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias - // except $lib which is handled by https://kit.svelte.dev/docs/configuration#files + // Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias and https://kit.svelte.dev/docs/configuration#files // // If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes // from the referenced tsconfig.json - TypeScript does not merge them in diff --git a/playgrounds/vite-cloudflare-environment/src/params/fruit.js b/playgrounds/vite-cloudflare-environment/src/params/fruit.js new file mode 100644 index 000000000000..d9d4426d4435 --- /dev/null +++ b/playgrounds/vite-cloudflare-environment/src/params/fruit.js @@ -0,0 +1,6 @@ +/** + * @param {string} param + */ +export function match(param) { + return param === 'apple' || param === 'orange'; +} diff --git a/playgrounds/vite-cloudflare-environment/src/params/fruit.ts b/playgrounds/vite-cloudflare-environment/src/params/fruit.ts deleted file mode 100644 index dceeb7da08d9..000000000000 --- a/playgrounds/vite-cloudflare-environment/src/params/fruit.ts +++ /dev/null @@ -1,3 +0,0 @@ -export function match(param: string) { - return param === 'apple' || param === 'orange'; -} diff --git a/playgrounds/vite-cloudflare-environment/src/routes/+layout.svelte b/playgrounds/vite-cloudflare-environment/src/routes/+layout.svelte index 6c0ef5150b94..ec19d552d54b 100644 --- a/playgrounds/vite-cloudflare-environment/src/routes/+layout.svelte +++ b/playgrounds/vite-cloudflare-environment/src/routes/+layout.svelte @@ -1,5 +1,5 @@
      -

      Svelte Kit with Vite Workerd Environment

      +

      Svelte Kit with Vite Cloudflare Environment