Skip to content

Commit

Permalink
v0.7.0 Fix endpoints of static files (#204)
Browse files Browse the repository at this point in the history
* update tsconfig & sveltekit from 2.5.0 to 2.5.2 (#192)

* update sveltekit from 2.5.0 to 2.5.2

* remove unused properties on tsconfig

* fix: format

* [Snyk] Upgrade prettier-plugin-svelte from 3.1.2 to 3.2.0 (#195)

* fix: upgrade prettier-plugin-svelte from 3.1.2 to 3.2.0

Snyk has created this PR to upgrade prettier-plugin-svelte from 3.1.2 to 3.2.0.

See this package in npm:
https://www.npmjs.com/package/prettier-plugin-svelte

See this project in Snyk:
https://app.snyk.io/org/u-sho/project/56523540-5a4b-485d-ae86-4b4f9b0ef853?utm_source=github&utm_medium=referral&page=upgrade-pr

* fetch package-lock.json

---------

Co-authored-by: snyk-bot <[email protected]>

* [Snyk] Upgrade vitest from 1.2.2 to 1.3.1 (#198)

* fix: upgrade @vitest/coverage-v8 from 1.2.2 to 1.3.0

Snyk has created this PR to upgrade @vitest/coverage-v8 from 1.2.2 to 1.3.0.

See this package in npm:
https://www.npmjs.com/package/@vitest/coverage-v8

See this project in Snyk:
https://app.snyk.io/org/u-sho/project/56523540-5a4b-485d-ae86-4b4f9b0ef853?utm_source=github&utm_medium=referral&page=upgrade-pr

* upgrade vitest from 1.2.2 to 1.3.1

---------

Co-authored-by: snyk-bot <[email protected]>

* Update build tool packages (#201)

* update vite(st) to the latest

* update SvelteKit and its toolchanis to the latest

* fix: file access conflict on coverage directory

* fix: type safety of service-worker
  see https://kit.svelte.dev/docs/service-workers#type-safety

* save static files to cache & don't separate cache with online/offline (#202)

* Fix: deployments and analytics (vercel) (#203)

* fix CSP setting for vercel/analytics

* fix: trailing slash of static files

* update sitemap: last modified date

---------

Co-authored-by: snyk-bot <[email protected]>
  • Loading branch information
u-sho and snyk-bot authored Mar 17, 2024
1 parent ab973ce commit 4553cba
Show file tree
Hide file tree
Showing 11 changed files with 222 additions and 212 deletions.
233 changes: 115 additions & 118 deletions package-lock.json

Large diffs are not rendered by default.

19 changes: 10 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,37 +33,38 @@
"check": "run-p typecheck:*",
"typecheck:svelte": "svelte-check",
"typecheck:vitest": "vitest --typecheck",
"ci": "run-p format:dry lint:dry check test",
"ci": "run-p format:dry lint:dry typecheck:svelte vitest:all",
"test": "vitest",
"vitest:all": "run-s typecheck:vitest test",
"format:dry": "prettier --cache --check .",
"lint:dry": "eslint --cache --cache-location ./node_modules/.cache/eslint/.eslintcache .",
"format": "prettier --cache --write .",
"lint": "eslint --fix --cache --cache-location ./node_modules/.cache/eslint/.eslintcache ."
},
"devDependencies": {
"@sveltejs/adapter-vercel": "^5.1.0",
"@sveltejs/kit": "^2.5.0",
"@sveltejs/adapter-vercel": "^5.1.1",
"@sveltejs/kit": "^2.5.4",
"@sveltejs/vite-plugin-svelte": "^3.0.2",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"@typescript/lib-dom": "npm:@types/web@^0.0.130",
"@vitest/coverage-v8": "^1.2.2",
"@vitest/coverage-v8": "^1.4.0",
"better-typescript-lib": "^2.6.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-svelte": "^2.35.1",
"npm-run-all": "^4.1.5",
"prettier": "^3.2.5",
"prettier-plugin-svelte": "^3.1.2",
"sass": "^1.70.0",
"prettier-plugin-svelte": "^3.2.2",
"sass": "^1.72.0",
"svelte": "^4.2.12",
"svelte-check": "^3.6.3",
"svelte-check": "^3.6.7",
"svelte-scrollto": "0.2.0",
"tslib": "^2.6.2",
"typescript": "~5.3.2",
"typescript-eslint-language-service": "^5.0.5",
"vite": "^5.0.12",
"vitest": "^1.2.2",
"vite": "^5.1.6",
"vitest": "^1.4.0",
"vscode-emmet-helper": "npm:@vscode/emmet-helper@^2.9.2"
},
"engines": {
Expand Down
79 changes: 79 additions & 0 deletions src/service-worker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/// <reference types="@sveltejs/kit" />
/// <reference no-default-lib="true"/>
/// <reference lib="esnext" />
/// <reference lib="WebWorker" />

import { build, files, version } from '$service-worker';

declare const self: ServiceWorkerGlobalScope;

const ASSETS = `cache${version}`;
const cached = [...build, ...files];

self.addEventListener('install', (event) => {
event.waitUntil(
caches
.open(ASSETS)
.then(async (cache) => cache.addAll(cached))
.then(() => {
void self.skipWaiting();
})
);
});

self.addEventListener('activate', (event) => {
event.waitUntil(
caches.keys().then(async (keys) => {
// delete old caches
for (const key of keys) {
if (key !== ASSETS) await caches.delete(key);
}
void self.clients.claim();
})
);
});

self.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
if (!url.protocol.startsWith('http')) return;

// ignore dev server requests
if (url.hostname === self.location.hostname && url.port !== self.location.port) return;

async function respond(): Promise<Response> {
const cache = await caches.open(ASSETS);

// always serve static files and bundler-generated assets from cache
if (url.host === self.location.host && cached.includes(url.pathname)) {
const response = await cache.match(event.request);
if (response) return response;
}

// if (event.request.cache === 'only-if-cached') return;

// for everything else, try the network first, falling back to
// cache if the user is offline. (If the pages never change, you
// might prefer a cache-first approach to a network-first one.)
try {
const response = await fetch(event.request);
if (!(response instanceof Response)) {
throw new Error('invalid response from fetch');
}
if (response.status === 200) {
void cache.put(event.request, response.clone());
}
return response;
} catch (err) {
const response = await cache.match(event.request);
if (response) return response;

throw err;
}
}

event.respondWith(respond());
});
69 changes: 0 additions & 69 deletions src/service-worker/index.ts

This file was deleted.

6 changes: 3 additions & 3 deletions static/sitemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://qgame.app</loc>
<lastmod>2022-09-29</lastmod>
<lastmod>2023-12-22</lastmod>
<changefreq>monthly</changefreq>
<priority>0.8</priority>
</url>
Expand All @@ -16,13 +16,13 @@

<url>
<loc>https://qgame.app/games/quantum-tictactoe/tutorial</loc>
<lastmod>2022-09-29</lastmod>
<lastmod>2023-09-23</lastmod>
<changefreq>yearly</changefreq>
</url>

<url>
<loc>https://qgame.app/games/quantum-tictactoe/play/human</loc>
<lastmod>2022-09-29</lastmod>
<lastmod>2023-12-22</lastmod>
<changefreq>monthly</changefreq>
<priority>1.0</priority>
</url>
Expand Down
3 changes: 2 additions & 1 deletion svelte.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ const config = {
'https://pbs.twimg.com/profile_banners/1398377057772470274/1623818332/*',
'vitals.vercel-insights.com'
],
'style-src': ['self', 'unsafe-inline', 'vitals.vercel-insights.com']
'style-src': ['self', 'unsafe-inline', 'vitals.vercel-insights.com'],
'script-src-elem': ['self', 'va.vercel-scripts.com']
}
},
prerender: {
Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions tsconfig.eslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
"extends": "./tsconfig.json",
"include": [
"./.svelte-kit/ambient.d.ts",
"./.svelte-kit/non-ambient.d.ts",
"./.svelte-kit/types/**/$types.d.ts",
"./svelte.config.js",
"./vite.config.ts",
"./src/**/*.ts",
"./src/**/*.svelte",
"./tests/**/*.ts",
"./tests/**/*.svelte",

"./**/*.test.ts",
"./**/*.test-d.ts",
"./.eslintrc.cjs",
"./svelte.config.js"
]
"./.eslintrc.cjs"
],
"exclude": ["./node_modules/**"]
}
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

"downlevelIteration": true,
"importHelpers": true,
"verbatimModuleSyntax": true,
"newLine": "lf",
"noEmitHelpers": true,
"removeComments": true,
Expand Down
10 changes: 4 additions & 6 deletions tsconfig.vitest-typecheck.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"verbatimModuleSyntax": true,
"isolatedModules": true,
"lib": ["esnext", "DOM", "DOM.Iterable"],
"moduleResolution": "node",
"moduleResolution": "Bundler",
"module": "esnext",
"target": "esnext",

Expand Down Expand Up @@ -41,16 +41,14 @@
},
"include": [
"./.svelte-kit/ambient.d.ts",
"./.svelte-kit/non-ambient.d.ts",
"./.svelte-kit/types/**/$types.d.ts",
"./svelte.config.js",
"./vite.config.ts",
"./src/**/*.ts",
"./src/**/*.svelte",
"./tests/**/*.ts",
"./tests/**/*.svelte"
],
"exclude": [
"./node_modules/**",
"./.svelte-kit/[!ambient.d.ts]**",
"./src/service-worker/index.ts"
]
"exclude": ["./node_modules/**"]
}
4 changes: 4 additions & 0 deletions vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$schema": "http://openapi.vercel.sh/vercel.json",
"trailingSlash": false
}

0 comments on commit 4553cba

Please sign in to comment.