sveltekit-cache-first 1.1.0 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- <<<<<<< HEAD
1
+
2
2
  # SvelteKit Cache First
3
3
 
4
4
  A small library to make your SvelteKit Web App / PWA use a cache first approach: instant second visit loads and fast performance on poor network conditions.
@@ -42,7 +42,7 @@ setupServiceWorker(self, { version, build, files });
42
42
  ```js
43
43
  // src/routes/+layout.svelte
44
44
  import { toast } from 'svelte-sonner';
45
- import { onUpdate } from 'sveltekit-cache-first';
45
+ import { onUpdate } from 'sveltekit-cache-first/client';
46
46
 
47
47
  onMount(() => {
48
48
  onUpdate((accept) => {
@@ -68,70 +68,4 @@ const options = {
68
68
  };
69
69
 
70
70
  setupServiceWorker(self, { version, build, files, options });
71
- =======
72
- # Svelte library
73
-
74
- Everything you need to build a Svelte library, powered by [`sv`](https://npmjs.com/package/sv).
75
-
76
- Read more about creating a library [in the docs](https://svelte.dev/docs/kit/packaging).
77
-
78
- ## Creating a project
79
-
80
- If you're seeing this, you've probably already done this step. Congrats!
81
-
82
- ```sh
83
- # create a new project in the current directory
84
- npx sv create
85
-
86
- # create a new project in my-app
87
- npx sv create my-app
88
- ```
89
-
90
- To recreate this project with the same configuration:
91
-
92
- ```sh
93
- # recreate this project
94
- pnpm dlx sv@0.16.6 create --template library --types ts --install pnpm sveltekit-cache-first
95
- ```
96
-
97
- ## Developing
98
-
99
- Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
100
-
101
- ```sh
102
- npm run dev
103
-
104
- # or start the server and open the app in a new browser tab
105
- npm run dev -- --open
106
- ```
107
-
108
- Everything inside `src/lib` is part of your library, everything inside `src/routes` can be used as a showcase or preview app.
109
-
110
- ## Building
111
-
112
- To build your library:
113
-
114
- ```sh
115
- npm pack
116
- ```
117
-
118
- To create a production version of your showcase app:
119
-
120
- ```sh
121
- npm run build
122
- ```
123
-
124
- You can preview the production build with `npm run preview`.
125
-
126
- > To deploy your app, you may need to install an [adapter](https://svelte.dev/docs/kit/adapters) for your target environment.
127
-
128
- ## Publishing
129
-
130
- Go into the `package.json` and give your package the desired name through the `"name"` option. Also consider adding a `"license"` field and point it to a `LICENSE` file which you can create from a template (one popular option is the [MIT license](https://opensource.org/license/mit/)).
131
-
132
- To publish your library to [npm](https://www.npmjs.com):
133
-
134
- ```sh
135
- npm publish
136
- >>>>>>> b1866e7 (Fix imports and double updates)
137
71
  ```
package/dist/index.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export { default as UpdateAvailable } from "./update-available.svelte";
2
+ export { default as NoUpdateAvailable } from "./no-update.svelte";
package/dist/index.js CHANGED
@@ -1 +1,2 @@
1
1
  export { default as UpdateAvailable } from "./update-available.svelte";
2
+ export { default as NoUpdateAvailable } from "./no-update.svelte";
package/package.json CHANGED
@@ -1,68 +1,70 @@
1
1
  {
2
- "name": "sveltekit-cache-first",
3
- "version": "1.1.0",
4
- "repository": "github:isaxk/sveltekit-cache-first",
5
- "scripts": {
6
- "dev": "vite dev",
7
- "build": "vite build && npm run prepack",
8
- "preview": "vite preview",
9
- "prepare": "svelte-kit sync || echo ''",
10
- "prepack": "svelte-kit sync && svelte-package && publint",
11
- "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
12
- "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
13
- "lint": "prettier --check . && eslint .",
14
- "format": "prettier --write ."
15
- },
16
- "files": [
17
- "dist",
18
- "!dist/**/*.test.*",
19
- "!dist/**/*.spec.*"
20
- ],
21
- "sideEffects": [
22
- "**/*.css"
23
- ],
24
- "svelte": "./dist/index.js",
25
- "types": "./dist/index.d.ts",
26
- "type": "module",
27
- "exports": {
28
- ".": {
29
- "types": "./dist/index.d.ts",
30
- "svelte": "./dist/index.js"
31
- },
32
- "sw": {
33
- "types": "./dist/sw.d.ts",
34
- "svelte": "./dist/sw.js"
35
- },
36
- "client": {
37
- "types": "./dist/client.d.ts",
38
- "svelte": "./dist/client.js"
39
- }
40
- },
41
- "peerDependencies": {
42
- "@sveltejs/kit": "^2.63.0",
43
- "svelte": "^5.0.0"
44
- },
45
- "devDependencies": {
46
- "@eslint/js": "^10.0.1",
47
- "@sveltejs/adapter-auto": "^7.0.1",
48
- "@sveltejs/kit": "^2.63.0",
49
- "@sveltejs/package": "^2.5.8",
50
- "@sveltejs/vite-plugin-svelte": "^7.1.2",
51
- "@types/node": "^24",
52
- "eslint": "^10.4.1",
53
- "eslint-config-prettier": "^10.1.8",
54
- "eslint-plugin-svelte": "^3.19.0",
55
- "globals": "^17.6.0",
56
- "prettier": "^3.8.3",
57
- "prettier-plugin-svelte": "^4.1.0",
58
- "publint": "^0.3.21",
59
- "svelte": "^5.56.1",
60
- "svelte-check": "^4.6.0",
61
- "typescript": "^6.0.3",
62
- "typescript-eslint": "^8.60.1",
63
- "vite": "^8.0.16"
64
- },
65
- "keywords": [
66
- "svelte"
67
- ]
68
- }
2
+ "name": "sveltekit-cache-first",
3
+ "version": "1.1.3",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "github:isaxk/sveltekit-cache-first"
7
+ },
8
+ "license": "MIT",
9
+ "files": [
10
+ "dist",
11
+ "!dist/**/*.test.*",
12
+ "!dist/**/*.spec.*"
13
+ ],
14
+ "sideEffects": [
15
+ "**/*.css"
16
+ ],
17
+ "svelte": "./dist/index.js",
18
+ "types": "./dist/index.d.ts",
19
+ "type": "module",
20
+ "exports": {
21
+ ".": {
22
+ "types": "./dist/index.d.ts",
23
+ "svelte": "./dist/index.js"
24
+ },
25
+ "sw": {
26
+ "types": "./dist/sw.d.ts",
27
+ "default": "./dist/sw.js"
28
+ },
29
+ "client": {
30
+ "types": "./dist/client.d.ts",
31
+ "default": "./dist/client.js"
32
+ }
33
+ },
34
+ "peerDependencies": {
35
+ "@sveltejs/kit": "^2.63.0",
36
+ "svelte": "^5.0.0"
37
+ },
38
+ "devDependencies": {
39
+ "@eslint/js": "^10.0.1",
40
+ "@sveltejs/adapter-auto": "^7.0.1",
41
+ "@sveltejs/kit": "^2.63.0",
42
+ "@sveltejs/package": "^2.5.8",
43
+ "@sveltejs/vite-plugin-svelte": "^7.1.2",
44
+ "@types/node": "^24",
45
+ "eslint": "^10.4.1",
46
+ "eslint-config-prettier": "^10.1.8",
47
+ "eslint-plugin-svelte": "^3.19.0",
48
+ "globals": "^17.6.0",
49
+ "prettier": "^3.8.3",
50
+ "prettier-plugin-svelte": "^4.1.0",
51
+ "publint": "^0.3.21",
52
+ "svelte": "^5.56.1",
53
+ "svelte-check": "^4.6.0",
54
+ "typescript": "^6.0.3",
55
+ "typescript-eslint": "^8.60.1",
56
+ "vite": "^8.0.16"
57
+ },
58
+ "keywords": [
59
+ "svelte"
60
+ ],
61
+ "scripts": {
62
+ "dev": "vite dev",
63
+ "build": "vite build && npm run prepack",
64
+ "preview": "vite preview",
65
+ "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
66
+ "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
67
+ "lint": "prettier --check . && eslint .",
68
+ "format": "prettier --write ."
69
+ }
70
+ }
package/dist/update.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare function onUpdate(handle: (onAccept: () => void) => void): void;
package/dist/update.js DELETED
@@ -1,63 +0,0 @@
1
- function getVersion(worker) {
2
- return new Promise((resolve) => {
3
- const channel = new MessageChannel();
4
- channel.port1.onmessage = (e) => resolve(e.data ?? null);
5
- worker.postMessage({ type: 'SKLOCALFIRST_GET_VERSION' }, [channel.port2]);
6
- });
7
- }
8
- async function checkVersionChanged(worker) {
9
- const version = await getVersion(worker);
10
- if (!version)
11
- return false;
12
- const lastPrompted = localStorage.getItem('lastPrompted');
13
- if (lastPrompted === version)
14
- return false;
15
- localStorage.setItem('lastPrompted', version);
16
- return true;
17
- }
18
- function handleAccept(worker) {
19
- worker.postMessage({ type: 'SKLOCALFIRST_SKIP_WAITING' });
20
- }
21
- const handlers = [];
22
- let listenerSetUp = false;
23
- function setupSWListener() {
24
- if (!('serviceWorker' in navigator)) {
25
- return () => { };
26
- }
27
- navigator.serviceWorker.getRegistration().then(async (reg) => {
28
- if (!reg)
29
- return;
30
- // 1️⃣ Detect if a waiting SW already exists
31
- if (reg.waiting) {
32
- const sw = reg.waiting;
33
- if (await checkVersionChanged(sw)) {
34
- handlers.forEach((handle) => handle(() => handleAccept(sw)));
35
- }
36
- }
37
- // 2️⃣ Listen for new SW installations
38
- reg.addEventListener('updatefound', () => {
39
- const sw = reg.installing;
40
- if (!sw)
41
- return;
42
- sw.addEventListener('statechange', async () => {
43
- if (sw.state === 'installed' && navigator.serviceWorker.controller) {
44
- if (await checkVersionChanged(sw)) {
45
- handlers.forEach((handle) => handle(() => handleAccept(sw)));
46
- }
47
- }
48
- });
49
- });
50
- });
51
- // 3️⃣ Reload page when the new SW takes control
52
- navigator.serviceWorker.addEventListener('controllerchange', () => {
53
- window.location.reload();
54
- });
55
- listenerSetUp = true;
56
- }
57
- export function onUpdate(handle) {
58
- handlers.push(handle);
59
- if (!listenerSetUp) {
60
- setupSWListener();
61
- }
62
- handlers.push(handle);
63
- }