Skip to content

Commit b24970e

Browse files
authored
feat!: add SvelteKit 2 support (#76)
* feat!: add SvelteKit 2 support * chore: update Vitest to v1 * chore: update readme * chore: fix readme typo * chore: . * chore: add offline and trailing slash tests * chore: add reload about page when offline test
1 parent a6d5ec7 commit b24970e

File tree

10 files changed

+1009
-578
lines changed

10 files changed

+1009
-578
lines changed

.npmrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
node-version=16.14.0
21
engine-strict=true
32
ignore-workspace-root-check=true
43
shamefully-hoist=true

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ Zero-config PWA Plugin for SvelteKit
4545

4646
## 📦 Install
4747

48+
> From v0.3.0, `@vite-pwa/sveltekit` supports SvelteKit 2 (should also support SvelteKit 1).
49+
4850
> From v0.2.0, `@vite-pwa/sveltekit` requires **SvelteKit 1.3.1 or above**.
4951
5052
```bash
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import {test, expect} from '@playwright/test';
2+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
3+
// @ts-ignore
4+
import {generateSW} from "../pwa.mjs";
5+
6+
test('Test offline and trailing slashes', async ({ browser}) => {
7+
// test offline + trailing slashes routes
8+
const context = await browser.newContext()
9+
const offlinePage = await context.newPage()
10+
await offlinePage.goto('/')
11+
const offlineSwURL = await offlinePage.evaluate(async () => {
12+
const registration = await Promise.race([
13+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
14+
// @ts-ignore
15+
navigator.serviceWorker.ready,
16+
new Promise((_, reject) => setTimeout(() => reject(new Error('Service worker registration failed: time out')), 10000))
17+
])
18+
// @ts-expect-error registration is of type unknown
19+
return registration.active?.scriptURL
20+
});
21+
const offlineSwName = generateSW ? 'sw.js' : 'prompt-sw.js'
22+
expect(offlineSwURL).toBe(`http://localhost:4173/${offlineSwName}`);
23+
await context.setOffline(true)
24+
const aboutAnchor = offlinePage.getByRole('link', { name: 'About' })
25+
expect(await aboutAnchor.getAttribute('href')).toBe('/about')
26+
await aboutAnchor.click({ noWaitAfter: false })
27+
const url = await offlinePage.evaluate(async () => {
28+
await new Promise(resolve => setTimeout(resolve, 3000))
29+
return location.href
30+
})
31+
expect(url).toBe('http://localhost:4173/about')
32+
expect(offlinePage.locator('li[aria-current="page"] a').getByText('About')).toBeTruthy()
33+
await offlinePage.reload({ waitUntil: 'load' })
34+
expect(offlinePage.url()).toBe('http://localhost:4173/about')
35+
expect(offlinePage.locator('li[aria-current="page"] a').getByText('About')).toBeTruthy()
36+
// Dispose context once it's no longer needed.
37+
await context.close();
38+
});

examples/sveltekit-ts/package.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,20 @@
2525
},
2626
"devDependencies": {
2727
"@playwright/test": "^1.37.1",
28-
"@sveltejs/adapter-static": "^2.0.3",
29-
"@sveltejs/adapter-node": "^1.3.1",
30-
"@sveltejs/kit": "^1.24.1",
31-
"@types/cookie": "^0.5.2",
32-
"@typescript-eslint/eslint-plugin": "^6.13.2",
33-
"@typescript-eslint/parser": "^6.13.2",
28+
"@sveltejs/adapter-static": "^3.0.0",
29+
"@sveltejs/adapter-node": "^2.0.0",
30+
"@sveltejs/kit": "^2.0.1",
31+
"@types/cookie": "^0.6.0",
32+
"@typescript-eslint/eslint-plugin": "^6.14.0",
33+
"@typescript-eslint/parser": "^6.14.0",
3434
"@vite-pwa/sveltekit": "workspace:*",
35-
"eslint": "^8.49.0",
36-
"eslint-plugin-svelte": "^2.34.0",
37-
"svelte": "^4.2.0",
38-
"svelte-check": "^3.5.1",
35+
"eslint": "^8.55.0",
36+
"eslint-plugin-svelte": "^2.35.1",
37+
"svelte": "^4.2.8",
38+
"svelte-check": "^3.6.2",
3939
"tslib": "^2.6.2",
40-
"typescript": "^5.2.2",
41-
"vitest": "^0.34.4"
40+
"typescript": "^5.3.3",
41+
"vitest": "^1.0.4"
4242
},
4343
"type": "module",
4444
"dependencies": {

examples/sveltekit-ts/playwright.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export default defineConfig({
4343
actionTimeout: 0,
4444
/* Base URL to use in actions like `await page.goto('/')`. */
4545
baseURL: url,
46+
//offline: true,
4647

4748
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
4849
trace: 'on-first-retry',

examples/sveltekit-ts/svelte.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { vitePreprocess } from '@sveltejs/kit/vite';
1+
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
22
// you don't need to do this if you're using generateSW strategy in your app
33
import { generateSW } from './pwa.mjs'
44
import { adapter } from './adapter.mjs'

examples/sveltekit-ts/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"resolveJsonModule": true,
99
"skipLibCheck": true,
1010
"sourceMap": true,
11-
"strict": true
11+
"strict": true,
12+
"moduleResolution": "bundler"
1213
}
1314
// Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
1415
//

package.json

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@vite-pwa/sveltekit",
33
"type": "module",
44
"version": "0.2.10",
5-
"packageManager": "pnpm@8.11.0",
5+
"packageManager": "pnpm@8.12.1",
66
"description": "Zero-config PWA for SvelteKit",
77
"author": "antfu <anthonyfu117@hotmail.com>",
88
"license": "MIT",
@@ -39,7 +39,7 @@
3939
"*.d.ts"
4040
],
4141
"engines": {
42-
"node": ">=16.14 || >=18"
42+
"node": ">=16.14 || >=18.13"
4343
},
4444
"scripts": {
4545
"build": "unbuild",
@@ -50,8 +50,8 @@
5050
"test": "pnpm run -C examples/sveltekit-ts test"
5151
},
5252
"peerDependencies": {
53-
"@sveltejs/kit": "^1.3.1",
54-
"vite-plugin-pwa": ">=0.16.7 <1"
53+
"@sveltejs/kit": "^1.3.1 || ^2.0.1",
54+
"vite-plugin-pwa": ">=0.17.4 <1"
5555
},
5656
"dependencies": {
5757
"kolorist": "^1.8.0"
@@ -62,12 +62,11 @@
6262
"@types/debug": "^4.1.8",
6363
"@types/node": "^18.17.15",
6464
"@typescript-eslint/eslint-plugin": "^6.13.2",
65-
"@vite-pwa/sveltekit": "workspace:*",
6665
"bumpp": "^9.2.0",
6766
"eslint": "^8.55.0",
6867
"typescript": "^5.3.3",
6968
"unbuild": "^2.0.0",
70-
"vite": "^4.5.1",
71-
"vite-plugin-pwa": ">=0.16.7 <1"
69+
"vite": "^5.0.10",
70+
"vite-plugin-pwa": ">=0.17.4 <1"
7271
}
7372
}

0 commit comments

Comments
 (0)