From 6ae3c92cbcdaae3cf0ecbc43d51ea64469f7ca33 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Thu, 15 Dec 2022 16:35:18 +0100 Subject: [PATCH] Update to sveltekit 1.0 + fix warnings and errors --- ui/package.json | 5 +-- ui/src/service-worker.ts | 80 ---------------------------------------- ui/static/nojs.html | 0 ui/svelte.config.js | 3 -- 4 files changed, 2 insertions(+), 86 deletions(-) delete mode 100644 ui/src/service-worker.ts create mode 100644 ui/static/nojs.html diff --git a/ui/package.json b/ui/package.json index fa3fd94..86515b8 100644 --- a/ui/package.json +++ b/ui/package.json @@ -12,9 +12,8 @@ "format": "prettier --ignore-path .gitignore --write --plugin-search-dir=. ." }, "devDependencies": { - "@sveltejs/adapter-auto": "^1.0.0-next.18", - "@sveltejs/adapter-static": "^1.0.0-next.26", - "@sveltejs/kit": "^1.0.0-next.260", + "@sveltejs/adapter-static": "^1.0.0", + "@sveltejs/kit": "^1.0.0", "@typescript-eslint/eslint-plugin": "^5.0.0", "@typescript-eslint/parser": "^5.0.0", "bootstrap": "^5.1.3", diff --git a/ui/src/service-worker.ts b/ui/src/service-worker.ts deleted file mode 100644 index 96b80f5..0000000 --- a/ui/src/service-worker.ts +++ /dev/null @@ -1,80 +0,0 @@ -/// - -import { build, files, timestamp } from '$service-worker'; - -const worker = (self as unknown) as ServiceWorkerGlobalScope; -const FILES = `cache${timestamp}`; - -// `build` is an array of all the files generated by the bundler, -// `files` is an array of everything in the `static` directory -const to_cache = build.concat(files); -const staticAssets = new Set(to_cache); - -worker.addEventListener('install', (event) => { - event.waitUntil( - caches - .open(FILES) - .then((cache) => cache.addAll(to_cache)) - .then(() => { - worker.skipWaiting(); - }) - ); -}); - -worker.addEventListener('activate', (event) => { - event.waitUntil( - caches.keys().then(async (keys) => { - // delete old caches - for (const key of keys) { - if (key !== FILES) await caches.delete(key); - } - - worker.clients.claim(); - }) - ); -}); - -/** - * Fetch the asset from the network and store it in the cache. - * Fall back to the cache if the user is offline. - */ -async function fetchAndCache(request: Request) { - const cache = await caches.open(`offline${timestamp}`); - - try { - const response = await fetch(request); - cache.put(request, response.clone()); - return response; - } catch (err) { - const response = await cache.match(request); - if (response) return response; - - throw err; - } -} - -worker.addEventListener('fetch', (event) => { - if (event.request.method !== 'GET' || event.request.headers.has('range')) return; - - const url = new URL(event.request.url); - - // don't try to handle e.g. data: URIs - const isHttp = url.protocol.startsWith('http'); - const isDevServerRequest = - url.hostname === self.location.hostname && url.port !== self.location.port; - const isStaticAsset = url.host === self.location.host && staticAssets.has(url.pathname); - const skipBecauseUncached = event.request.cache === 'only-if-cached' && !isStaticAsset; - - if (isHttp && !isDevServerRequest && !skipBecauseUncached) { - event.respondWith( - (async () => { - // always serve static files and bundler-generated assets from cache. - // if your application has other URLs with data that will never change, - // set this variable to true for them and they will only be fetched once. - const cachedAsset = isStaticAsset && (await caches.match(event.request)); - - return cachedAsset || fetchAndCache(event.request); - })() - ); - } -}); diff --git a/ui/static/nojs.html b/ui/static/nojs.html new file mode 100644 index 0000000..e69de29 diff --git a/ui/svelte.config.js b/ui/svelte.config.js index c080695..d792a1d 100644 --- a/ui/svelte.config.js +++ b/ui/svelte.config.js @@ -11,9 +11,6 @@ const config = { adapter: adapter({ fallback: '404.html' }), - paths: { - // base: '{{.urlbase}}', - } } };