Skip to content

Commit

Permalink
Merge branch 'main' into fix-implicit-download-before-navigate
Browse files Browse the repository at this point in the history
  • Loading branch information
eltigerchino committed Jul 24, 2024
2 parents a5c0efd + 348cd36 commit a9c1801
Show file tree
Hide file tree
Showing 70 changed files with 497 additions and 497 deletions.
6 changes: 6 additions & 0 deletions .changeset/dry-mirrors-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@sveltejs/adapter-cloudflare-workers": patch
"@sveltejs/adapter-cloudflare": patch
---

fix: correctly return static assets if base path is set
5 changes: 5 additions & 0 deletions .changeset/lucky-lobsters-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'create-svelte': patch
---

chore: upgrade to vitest 2
5 changes: 5 additions & 0 deletions .changeset/slow-beans-develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-svelte": patch
---

fix: remove unnecessary `tslib` dependency
5 changes: 5 additions & 0 deletions .changeset/ten-shirts-add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sveltejs/adapter-cloudflare": minor
---

feat: generate static `_redirects` for Cloudflare Pages
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ jobs:
- run: pnpm playwright install ${{ matrix.e2e-browser }}
- run: pnpm run sync-all
- run: pnpm test:kit
- name: Print flaky test report
run: node scripts/print-flaky-test-report.js
- name: Archive test results
if: failure()
shell: bash
Expand Down Expand Up @@ -115,6 +117,8 @@ jobs:
- run: pnpm playwright install ${{ matrix.e2e-browser }}
- run: pnpm run sync-all
- run: pnpm test:cross-platform:${{ matrix.mode }}
- name: Print flaky test report
run: node scripts/print-flaky-test-report.js
- name: Archive test results
if: failure()
shell: bash
Expand Down
3 changes: 3 additions & 0 deletions documentation/docs/10-getting-started/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
title: Getting started
---
3 changes: 0 additions & 3 deletions documentation/docs/10-getting-started/meta.json

This file was deleted.

3 changes: 3 additions & 0 deletions documentation/docs/20-core-concepts/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
title: Core concepts
---
3 changes: 0 additions & 3 deletions documentation/docs/20-core-concepts/meta.json

This file was deleted.

3 changes: 3 additions & 0 deletions documentation/docs/25-build-and-deploy/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
title: Build and deploy
---
3 changes: 0 additions & 3 deletions documentation/docs/25-build-and-deploy/meta.json

This file was deleted.

3 changes: 3 additions & 0 deletions documentation/docs/30-advanced/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
title: Advanced
---
3 changes: 0 additions & 3 deletions documentation/docs/30-advanced/meta.json

This file was deleted.

3 changes: 3 additions & 0 deletions documentation/docs/40-best-practices/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
title: Best practices
---
3 changes: 0 additions & 3 deletions documentation/docs/40-best-practices/meta.json

This file was deleted.

3 changes: 3 additions & 0 deletions documentation/docs/50-reference/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
title: Reference
---
3 changes: 0 additions & 3 deletions documentation/docs/50-reference/meta.json

This file was deleted.

3 changes: 3 additions & 0 deletions documentation/docs/60-appendix/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
title: Appendix
---
3 changes: 0 additions & 3 deletions documentation/docs/60-appendix/meta.json

This file was deleted.

3 changes: 3 additions & 0 deletions documentation/docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
title: SvelteKit
---
4 changes: 2 additions & 2 deletions packages/adapter-cloudflare-workers/files/entry.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Server } from 'SERVER';
import { manifest, prerendered } from 'MANIFEST';
import { manifest, prerendered, base_path } from 'MANIFEST';
import { getAssetFromKV, mapRequestToAsset } from '@cloudflare/kv-asset-handler';
import static_asset_manifest_json from '__STATIC_CONTENT_MANIFEST';
const static_asset_manifest = JSON.parse(static_asset_manifest_json);
Expand Down Expand Up @@ -54,7 +54,7 @@ export default {

// prerendered pages and /static files
let is_static_asset = false;
const filename = stripped_pathname.substring(1);
const filename = stripped_pathname.slice(base_path.length + 1);
if (filename) {
is_static_asset =
manifest.assets.has(filename) || manifest.assets.has(filename + '/index.html');
Expand Down
6 changes: 3 additions & 3 deletions packages/adapter-cloudflare-workers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ export default function ({ config = 'wrangler.toml', platformProxy = {} } = {})

writeFileSync(
`${tmp}/manifest.js`,
`export const manifest = ${builder.generateManifest({
relativePath
})};\n\nexport const prerendered = new Map(${JSON.stringify(prerendered_entries)});\n`
`export const manifest = ${builder.generateManifest({ relativePath })};\n\n` +
`export const prerendered = new Map(${JSON.stringify(prerendered_entries)});\n\n` +
`export const base_path = ${JSON.stringify(builder.config.kit.paths.base)};\n`
);

const external = ['__STATIC_CONTENT_MANIFEST', 'cloudflare:*'];
Expand Down
1 change: 1 addition & 0 deletions packages/adapter-cloudflare-workers/placeholders.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ declare module 'MANIFEST' {

export const manifest: SSRManifest;
export const prerendered: Map<string, { file: string }>;
export const base_path: string;
}

declare module '__STATIC_CONTENT_MANIFEST' {
Expand Down
33 changes: 23 additions & 10 deletions packages/adapter-cloudflare/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default function (options = {}) {
`${tmp}/manifest.js`,
`export const manifest = ${builder.generateManifest({ relativePath })};\n\n` +
`export const prerendered = new Set(${JSON.stringify(builder.prerendered.paths)});\n\n` +
`export const app_path = ${JSON.stringify(builder.getAppPath())};\n`
`export const base_path = ${JSON.stringify(builder.config.kit.paths.base)};\n`
);

writeFileSync(
Expand All @@ -68,6 +68,12 @@ export default function (options = {}) {

writeFileSync(`${dest}/_headers`, generate_headers(builder.getAppPath()), { flag: 'a' });

if (builder.prerendered.redirects.size > 0) {
writeFileSync(`${dest}/_redirects`, generate_redirects(builder.prerendered.redirects), {
flag: 'a'
});
}

builder.copy(`${files}/worker.js`, `${tmp}/_worker.js`, {
replace: {
SERVER: `${relativePath}/index.js`,
Expand Down Expand Up @@ -204,18 +210,11 @@ function get_routes_json(builder, assets, { include = ['/*'], exclude = ['<all>'
file === '_redirects'
)
)
.map((file) => `/${file}`);
.map((file) => `${builder.config.kit.paths.base}/${file}`);
}

if (rule === '<prerendered>') {
const prerendered = [];
for (const path of builder.prerendered.paths) {
if (!builder.prerendered.redirects.has(path)) {
prerendered.push(path);
}
}

return prerendered;
return builder.prerendered.paths;
}

return rule;
Expand Down Expand Up @@ -250,3 +249,17 @@ function generate_headers(app_dir) {
# === END AUTOGENERATED SVELTE IMMUTABLE HEADERS ===
`.trimEnd();
}

/** @param {Map<string, { status: number; location: string }>} redirects */
function generate_redirects(redirects) {
const rules = Array.from(
redirects.entries(),
([path, redirect]) => `${path} ${redirect.location} ${redirect.status}`
).join('\n');

return `
# === START AUTOGENERATED SVELTE PRERENDERED REDIRECTS ===
${rules}
# === END AUTOGENERATED SVELTE PRERENDERED REDIRECTS ===
`.trimEnd();
}
1 change: 1 addition & 0 deletions packages/adapter-cloudflare/placeholders.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ declare module 'MANIFEST' {
export const manifest: SSRManifest;
export const prerendered: Set<string>;
export const app_path: string;
export const base_path: string;
}
10 changes: 6 additions & 4 deletions packages/adapter-cloudflare/src/worker.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { Server } from 'SERVER';
import { manifest, prerendered, app_path } from 'MANIFEST';
import { manifest, prerendered, base_path } from 'MANIFEST';
import * as Cache from 'worktop/cfw.cache';

const server = new Server(manifest);

const immutable = `/${app_path}/immutable/`;
const version_file = `/${app_path}/version.json`;
const app_path = `/${manifest.appPath}`;

const immutable = `${app_path}/immutable/`;
const version_file = `${app_path}/version.json`;

/** @type {import('worktop/cfw').Module.Worker<{ ASSETS: import('worktop/cfw.durable').Durable.Object }>} */
const worker = {
Expand All @@ -28,7 +30,7 @@ const worker = {

// prerendered pages and /static files
let is_static_asset = false;
const filename = stripped_pathname.substring(1);
const filename = stripped_pathname.slice(base_path.length + 1);
if (filename) {
is_static_asset =
manifest.assets.has(filename) || manifest.assets.has(filename + '/index.html');
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-netlify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"@types/set-cookie-parser": "^2.4.7",
"rollup": "^4.14.2",
"typescript": "^5.3.3",
"vitest": "^1.6.0"
"vitest": "^2.0.1"
},
"peerDependencies": {
"@sveltejs/kit": "^2.4.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"polka": "1.0.0-next.25",
"sirv": "^2.0.4",
"typescript": "^5.3.3",
"vitest": "^1.6.0"
"vitest": "^2.0.1"
},
"dependencies": {
"@rollup/plugin-commonjs": "^26.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-vercel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"@sveltejs/vite-plugin-svelte": "^3.0.1",
"@types/node": "^18.19.3",
"typescript": "^5.3.3",
"vitest": "^1.6.0"
"vitest": "^2.0.1"
},
"peerDependencies": {
"@sveltejs/kit": "^2.4.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/create-svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"svelte": "^4.2.10",
"tiny-glob": "^0.2.9",
"typescript": "^5.3.3",
"vitest": "^1.6.0"
"vitest": "^2.0.1"
},
"scripts": {
"build": "node scripts/build-templates",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"devDependencies": {
"@playwright/test": "^1.28.1",
"vitest": "^1.2.0"
"vitest": "^2.0.0"
},
"scripts": {
"test:integration": "playwright test",
Expand Down
1 change: 0 additions & 1 deletion packages/create-svelte/shared/+typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
},
"devDependencies": {
"typescript": "^5.0.0",
"tslib": "^2.4.1",
"svelte-check": "^3.6.0"
}
}
2 changes: 1 addition & 1 deletion packages/create-svelte/shared/+vitest/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"devDependencies": {
"vitest": "^1.2.0"
"vitest": "^2.0.0"
},
"scripts": {
"test": "vitest"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"@sveltejs/vite-plugin-svelte": "^3.0.0",
"publint": "^0.1.9",
"svelte": "^4.2.7",
"tslib": "^2.4.1",
"typescript": "^5.3.2",
"vite": "^5.0.11"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/enhanced-img/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"svelte": "^4.2.10",
"typescript": "^5.3.3",
"vite": "^5.3.2",
"vitest": "^1.6.0"
"vitest": "^2.0.1"
},
"peerDependencies": {
"svelte": "^4.0.0 || ^5.0.0-next.0",
Expand Down
8 changes: 6 additions & 2 deletions packages/kit/kit.vitest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import { defineConfig } from 'vitest/config';

// this file needs a custom name so that the numerous test subprojects don't all pick it up
export default defineConfig({
server: {
watch: {
ignored: ['**/node_modules/**', '**/.svelte-kit/**']
}
},
test: {
// shave a couple seconds off the tests
isolate: false,
Expand All @@ -16,7 +21,6 @@ export default defineConfig({
'**/.svelte-kit/**',
'**/.{idea,git,cache,output,temp}/**',
'**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*'
],
watchExclude: ['**/node_modules/**', '**/.svelte-kit/**']
]
}
});
2 changes: 1 addition & 1 deletion packages/kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"svelte-preprocess": "^6.0.0",
"typescript": "^5.3.3",
"vite": "^5.3.2",
"vitest": "^1.6.0"
"vitest": "^2.0.1"
},
"peerDependencies": {
"@sveltejs/vite-plugin-svelte": "^3.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
}
</script>

<p>Count is {data.count}</p>
<p class="counter">Count is {data.count}</p>
<button on:click={update}>update</button>
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { json } from '@sveltejs/kit';
import { count } from '../state.js';

export function GET({ setHeaders }) {
export function GET({ setHeaders, cookies }) {
setHeaders({ 'cache-control': 'public, max-age=4', age: '2' });

const count = +(cookies.get('cache-control-bust-count') ?? 0);

return json({ count });
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { json } from '@sveltejs/kit';
import { increment } from '../state.js';

export function GET() {
increment();
export function GET({ cookies }) {
cookies.set(
'cache-control-bust-count',
+(cookies.get('cache-control-bust-count') ?? 0) + 1 + '',
{ path: '/' }
);

return json({});
}

This file was deleted.

Loading

0 comments on commit a9c1801

Please sign in to comment.