Skip to content

Commit 0498d1e

Browse files
committed
add sveltekit 2 app with v7
1 parent 9a86c12 commit 0498d1e

36 files changed

+3399
-61
lines changed

.prettierignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
utils/event-proxy-server/payload-files/**/*.json
1+
utils/event-proxy-server/payload-files/**/*.json
2+
payload-files/**/*.json

apps/sveltekit-2/.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.DS_Store
2+
node_modules
3+
/build
4+
/.svelte-kit
5+
/package
6+
.env
7+
.env.*
8+
!.env.example
9+
.vercel
10+
.output
11+
vite.config.js.timestamp-*
12+
vite.config.ts.timestamp-*

apps/sveltekit-2/.prettierrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"useTabs": true,
3+
"singleQuote": true,
4+
"trailingComma": "none",
5+
"printWidth": 100,
6+
"plugins": ["prettier-plugin-svelte"],
7+
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }]
8+
}

apps/sveltekit-2/package.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "sveltekit-2-test-application",
3+
"version": "0.0.1",
4+
"scripts": {
5+
"dev": "vite dev",
6+
"build": "vite build",
7+
"preview": "vite preview",
8+
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
9+
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
10+
"lint": "prettier --check . && eslint .",
11+
"format": "prettier --write ."
12+
},
13+
"dependencies": {
14+
"@sentry/sveltekit": "7.110.1"
15+
},
16+
"devDependencies": {
17+
"@sveltejs/adapter-auto": "^3.0.0",
18+
"@sveltejs/kit": "^2.0.0",
19+
"@sveltejs/vite-plugin-svelte": "^3.0.0",
20+
"@types/eslint": "^8.56.0",
21+
"@typescript-eslint/eslint-plugin": "^7.0.0",
22+
"@typescript-eslint/parser": "^7.0.0",
23+
"eslint": "^8.56.0",
24+
"eslint-config-prettier": "^9.1.0",
25+
"eslint-plugin-svelte": "^2.35.1",
26+
"prettier": "^3.1.1",
27+
"prettier-plugin-svelte": "^3.1.2",
28+
"svelte": "^4.2.7",
29+
"svelte-check": "^3.6.0",
30+
"tslib": "^2.4.1",
31+
"typescript": "^5.0.0",
32+
"vite": "^5.0.3"
33+
},
34+
"type": "module",
35+
"volta": {
36+
"extends": "../../package.json"
37+
}
38+
}

apps/sveltekit-2/src/app.d.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// See https://kit.svelte.dev/docs/types#app
2+
// for information about these interfaces
3+
declare global {
4+
namespace App {
5+
// interface Error {}
6+
// interface Locals {}
7+
// interface PageData {}
8+
// interface PageState {}
9+
// interface Platform {}
10+
}
11+
}
12+
13+
export {};

apps/sveltekit-2/src/app.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1" />
7+
%sveltekit.head%
8+
</head>
9+
<body data-sveltekit-preload-data="hover">
10+
<div style="display: contents">%sveltekit.body%</div>
11+
</body>
12+
</html>

apps/sveltekit-2/src/hooks.client.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { env } from '$env/dynamic/public';
2+
import * as Sentry from '@sentry/sveltekit';
3+
4+
Sentry.init({
5+
environment: 'qa', // dynamic sampling bias to keep transactions
6+
dsn: 'https://3b6c388182fb435097f41d181be2b2ba@o4504321058471936.ingest.sentry.io/4504321066008576',
7+
includeLocalVariables: true,
8+
tunnel: `http://localhost:3031/`, // proxy server
9+
tracesSampleRate: 1
10+
});
11+
12+
const myErrorHandler = ({ error, event }: any) => {
13+
console.error('An error occurred on the client side:', error, event);
14+
};
15+
16+
export const handleError = Sentry.handleErrorWithSentry(myErrorHandler);

apps/sveltekit-2/src/hooks.server.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { env } from '$env/dynamic/public';
2+
import * as Sentry from '@sentry/sveltekit';
3+
4+
Sentry.init({
5+
environment: 'qa', // dynamic sampling bias to keep transactions
6+
dsn: 'https://3b6c388182fb435097f41d181be2b2ba@o4504321058471936.ingest.sentry.io/4504321066008576',
7+
includeLocalVariables: true,
8+
tunnel: `http://localhost:3031/`, // proxy server
9+
tracesSampleRate: 1
10+
});
11+
12+
// not logging anything to console to avoid noise in the test output
13+
export const handleError = Sentry.handleErrorWithSentry(() => {});
14+
15+
export const handle = Sentry.sentryHandle();
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<script lang="ts">
2+
import './styles.css';
3+
</script>
4+
5+
<slot />
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<main>
2+
<ul>
3+
<li>
4+
<a href={'/test-route-handlers'}>Test Route Handlers</a>
5+
</li>
6+
</ul>
7+
</main>

apps/sveltekit-2/src/routes/+page.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// since there's no dynamic data here, we can prerender
2+
// it so that it gets served as a static asset in production
3+
export const prerender = true;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { RequestHandler } from './$types';
2+
import * as Sentry from '@sentry/nextjs';
3+
4+
export const GET: RequestHandler = async () => {
5+
Sentry.startSpan({ name: 'test-span' }, () => {
6+
Sentry.startSpan({ name: 'child-span' }, () => {
7+
Sentry.captureException(new Error('This is an error'));
8+
});
9+
});
10+
11+
await Sentry.flush();
12+
13+
return Response.json({ data: 'test-error-body' });
14+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { RequestHandler } from './$types';
2+
import * as Sentry from '@sentry/nextjs';
3+
4+
export const GET: RequestHandler = async () => {
5+
const exceptionId = Sentry.captureException(new Error('This is an error'));
6+
7+
await Sentry.flush(2000);
8+
return Response.json({ exceptionId });
9+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import type { RequestHandler } from './$types';
2+
import * as Sentry from '@sentry/nextjs';
3+
4+
export const GET: RequestHandler = () => {
5+
const randomVariableToRecord = 'LOCAL_VARIABLE';
6+
7+
let exceptionId: string;
8+
try {
9+
throw new Error('Local Variable Error');
10+
} catch (e) {
11+
exceptionId = Sentry.captureException(e);
12+
}
13+
14+
return Response.json({ exceptionId, randomVariableToRecord });
15+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import type { RequestHandler } from './$types';
2+
3+
export const GET: RequestHandler = () => {
4+
const randomVariableToRecord = 'LOCAL_VARIABLE';
5+
throw new Error(`Uncaught Local Variable Error - ${JSON.stringify({ randomVariableToRecord })}`);
6+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { RequestHandler } from './$types';
2+
import * as Sentry from '@sentry/nextjs';
3+
4+
export const GET: RequestHandler = async ({ url }) => {
5+
const exceptionId = Sentry.captureException(new Error('This is an error'));
6+
7+
await Sentry.flush(2000);
8+
9+
const pathname = url.pathname;
10+
const parts = pathname.split('/');
11+
const param = parts[parts.length - 1];
12+
13+
return Response.json({ exceptionId, paramWas: param });
14+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { RequestHandler } from './$types';
2+
3+
export const GET: RequestHandler = ({ url }) => {
4+
const pathname = url.pathname;
5+
const parts = pathname.split('/');
6+
const param = parts[parts.length - 1];
7+
8+
return Response.json({ paramWas: param });
9+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type { RequestHandler } from './$types';
2+
import * as Sentry from '@sentry/nextjs';
3+
4+
export const GET: RequestHandler = async () => {
5+
Sentry.startSpan({ name: 'test-span' }, () => {
6+
Sentry.startSpan({ name: 'child-span' }, () => {});
7+
});
8+
9+
await Sentry.flush();
10+
11+
return Response.json({ data: 'test-success-body' });
12+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import type { RequestHandler } from './$types';
2+
3+
export const GET: RequestHandler = () => {
4+
return Response.json({ version: 'v1' });
5+
};
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
* {
2+
box-sizing: border-box;
3+
padding: 0;
4+
margin: 0;
5+
}
6+
7+
html,
8+
body {
9+
max-width: 100vw;
10+
overflow-x: hidden;
11+
font-family: sans-serif;
12+
}
13+
14+
a {
15+
margin: 1rem;
16+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<script lang="ts">
2+
import { type Writable, writable } from 'svelte/store';
3+
4+
let dataSuccess = writable('No data');
5+
let testErrorError = writable('No data');
6+
let dataParamSuccess = writable('No data');
7+
let dataParamError = writable('No data');
8+
let dataSuccessManual = writable('No data');
9+
let dataErrorManual = writable('No data');
10+
let dataLocalVariablesUncaught = writable('No data');
11+
let dataLocalVariablesCaught = writable('No data');
12+
13+
const fetchData = async (url: string, store: Writable<any>) => {
14+
console.log('fetching', url);
15+
const res = await fetch(url);
16+
const data = await res.json();
17+
store.set(data);
18+
};
19+
20+
const displayData = (data: any) => (data ? JSON.stringify(data, null, 2) : 'No data');
21+
</script>
22+
23+
<main>
24+
<div>
25+
<h1>Layout (/)</h1>
26+
<button on:click={() => fetchData('/api/test-success', dataSuccess)}>Test Success</button>
27+
<p>{displayData($dataSuccess)}</p>
28+
29+
<button on:click={() => fetchData('/api/test-error', testErrorError)}>Test Error</button>
30+
<p>{$testErrorError}</p>
31+
32+
<button on:click={() => fetchData('/api/test-param-success/1337', dataParamSuccess)}
33+
>Test Param Success</button
34+
>
35+
<p>{$dataParamSuccess}</p>
36+
37+
<button on:click={() => fetchData('api/test-param-error/1337', dataParamError)}
38+
>Test Param Error</button
39+
>
40+
<p>{$dataParamError}</p>
41+
42+
<button on:click={() => fetchData('/api/test-success-manual', dataSuccessManual)}
43+
>Test Success Manual</button
44+
>
45+
<p>{$dataSuccessManual}</p>
46+
47+
<button on:click={() => fetchData('/api/test-error-manual', dataErrorManual)}
48+
>Test Error Manual</button
49+
>
50+
<p>{$dataErrorManual}</p>
51+
52+
<button
53+
on:click={() => fetchData('/api/test-local-variables-uncaught', dataLocalVariablesUncaught)}
54+
>Test Local Variables Uncaught</button
55+
>
56+
<p>{$dataLocalVariablesUncaught}</p>
57+
58+
<button on:click={() => fetchData('/api/test-local-variables-caught', dataLocalVariablesCaught)}
59+
>Test Local Variables Caught</button
60+
>
61+
<p>{$dataLocalVariablesCaught}</p>
62+
</div>
63+
</main>

apps/sveltekit-2/static/favicon.png

1.53 KB
Loading

apps/sveltekit-2/svelte.config.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import adapter from '@sveltejs/adapter-auto';
2+
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
3+
4+
/** @type {import('@sveltejs/kit').Config} */
5+
const config = {
6+
// Consult https://kit.svelte.dev/docs/integrations#preprocessors
7+
// for more information about preprocessors
8+
preprocess: vitePreprocess(),
9+
10+
kit: {
11+
// adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
12+
// If your environment is not supported or you settled on a specific environment, switch out the adapter.
13+
// See https://kit.svelte.dev/docs/adapters for more information about adapters.
14+
adapter: adapter()
15+
}
16+
};
17+
18+
export default config;

apps/sveltekit-2/tsconfig.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"extends": "./.svelte-kit/tsconfig.json",
3+
"compilerOptions": {
4+
"allowJs": true,
5+
"checkJs": true,
6+
"esModuleInterop": true,
7+
"forceConsistentCasingInFileNames": true,
8+
"resolveJsonModule": true,
9+
"skipLibCheck": true,
10+
"sourceMap": true,
11+
"strict": true,
12+
"moduleResolution": "bundler"
13+
}
14+
// Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
15+
// except $lib which is handled by https://kit.svelte.dev/docs/configuration#files
16+
//
17+
// If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
18+
// from the referenced tsconfig.json - TypeScript does not merge them in
19+
}

apps/sveltekit-2/vite.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { sveltekit } from '@sveltejs/kit/vite';
2+
import { defineConfig } from 'vite';
3+
import { sentrySvelteKit } from '@sentry/sveltekit';
4+
5+
export default defineConfig({
6+
plugins: [sentrySvelteKit(), sveltekit()]
7+
});

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,23 @@
1616
"start:proxy-server:koa": "APP_NAME=koa yarn workspace event-proxy-server run start",
1717
"start:proxy-server:nextjs-13_2_0": "APP_NAME=nextjs-13_2_0 yarn workspace event-proxy-server run start",
1818
"start:proxy-server:nextjs-14_2_1": "APP_NAME=nextjs-14_2_1 yarn workspace event-proxy-server run start",
19+
"start:proxy-server:sveltekit-2": "APP_NAME=sveltekit-2 yarn workspace event-proxy-server run start",
1920
"start:app:express": "yarn workspace express-test-application run start",
2021
"start:app:fastify": "yarn workspace fastify-test-application run start",
2122
"start:app:connect": "APP_NAME=connect yarn workspace connect-test-application run start",
2223
"start:app:nestjs": "yarn workspace nestjs-test-application run start",
2324
"start:app:koa": "yarn workspace koa-test-application run start",
2425
"start:app:nextjs-13_2_0": "yarn workspace nextjs-13_2_0-test-application run dev",
2526
"start:app:nextjs-14_2_1": "yarn workspace nextjs-14_2_1-test-application run dev",
27+
"start:app:sveltekit-2": "yarn workspace sveltekit-2-test-application run dev",
2628
"start:express": "run-p start:proxy-server:express start:app:express",
2729
"start:fastify": "run-p start:proxy-server:fastify start:app:fastify",
2830
"start:connect": "run-p start:proxy-server:connect start:app:connect",
2931
"start:nestjs": "run-p start:proxy-server:nestjs start:app:nestjs",
3032
"start:koa": "run-p start:proxy-server:koa start:app:koa",
3133
"start:nextjs-13_2_0": "run-p start:proxy-server:nextjs-13_2_0 start:app:nextjs-13_2_0",
3234
"start:nextjs-14_2_1": "run-p start:proxy-server:nextjs-14_2_1 start:app:nextjs-14_2_1",
35+
"start:sveltekit-2": "run-p start:proxy-server:sveltekit-2 start:app:sveltekit-2",
3336
"fix:prettier": "prettier . --write",
3437
"fix:lint": "yarn run eslint --fix",
3538
"lint": "yarn run eslint"
@@ -42,7 +45,8 @@
4245
"apps/nestjs",
4346
"apps/koa",
4447
"apps/nextjs-13_2_0",
45-
"apps/nextjs-14_2_1"
48+
"apps/nextjs-14_2_1",
49+
"apps/sveltekit-2"
4650
],
4751
"devDependencies": {
4852
"@eslint/js": "^9.0.0",

0 commit comments

Comments
 (0)