diff --git a/demo/src/hooks.client.ts b/demo/src/hooks.client.ts index f9c2aea..e305c82 100644 --- a/demo/src/hooks.client.ts +++ b/demo/src/hooks.client.ts @@ -1,4 +1,4 @@ -import { init } from '$dist/client/index.js' +import { init } from '$dist/client' const onError = init( 'https://7e30b84f392c05d4a9a21e30f3ef6801@o4505814639312896.ingest.sentry.io/4505817123323904' diff --git a/demo/src/hooks.server.ts b/demo/src/hooks.server.ts index 1ee4e23..a76c45a 100644 --- a/demo/src/hooks.server.ts +++ b/demo/src/hooks.server.ts @@ -1,4 +1,4 @@ -import { init } from '$dist/server/index.js' +import { init } from '$dist/server' const { onHandle, onError } = init( 'https://7e30b84f392c05d4a9a21e30f3ef6801@o4505814639312896.ingest.sentry.io/4505817123323904' diff --git a/package.json b/package.json index f37dfd4..3cd2651 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@jill64/sentry-sveltekit-cloudflare", - "version": "1.4.2", + "version": "1.5.0", "description": "♟️ Unofficial Sentry Integration for SvelteKit Cloudflare Adapter", "type": "module", "main": "dist/index.js", @@ -27,14 +27,17 @@ "exports": { "./client": { "types": "./dist/client/index.d.ts", + "development": "./dist/client/index-dev.js", "default": "./dist/client/index.js" }, "./server": { "types": "./dist/server/index.d.ts", + "development": "./dist/server/index-dev.js", "default": "./dist/server/index.js" }, ".": { "types": "./dist/index.d.ts", + "development": "./dist/index-dev.js", "default": "./dist/index.js" } }, @@ -43,7 +46,7 @@ }, "prettier": "@jill64/prettier-config", "scripts": { - "dev": "cd demo && npm run dev", + "dev": "pnpm build:lib && cd demo && npm run dev", "build": "npm run build:lib && npm run build:demo && npx publint", "build:lib": "tsc && npx tsx scripts/build.ts", "build:demo": "cd demo && npm run build", diff --git a/scripts/build.ts b/scripts/build.ts index 43c20bc..159d225 100644 --- a/scripts/build.ts +++ b/scripts/build.ts @@ -1,28 +1,18 @@ -import { build } from 'esbuild' +import esbuild from 'esbuild' -const opts = { - bundle: true, - minify: true, - format: 'esm' -} as const +const build = (path: string, external?: string[]) => + esbuild.build({ + entryPoints: [`src/${path}.ts`], + outfile: `dist/${path}.js`, + bundle: true, + minify: true, + format: 'esm', + external: ['$app/*', ...(external ?? [])] + }) -build({ - ...opts, - entryPoints: ['src/index.ts'], - outfile: 'dist/index.js', - external: ['$app/*', 'toucan-js'] -}) - -build({ - ...opts, - entryPoints: ['src/client/index.ts'], - outfile: 'dist/client/index.js', - external: ['$app/*'] -}) - -build({ - ...opts, - entryPoints: ['src/server/index.ts'], - outfile: 'dist/server/index.js', - external: ['$app/*', 'toucan-js'] -}) +build('index', ['toucan-js']) +build('index-dev', ['toucan-js']) +build('client/index') +build('client/index-dev') +build('server/index', ['toucan-js']) +build('server/index-dev', ['toucan-js']) diff --git a/src/client/index-dev.ts b/src/client/index-dev.ts new file mode 100644 index 0000000..9b0720d --- /dev/null +++ b/src/client/index-dev.ts @@ -0,0 +1 @@ +export { init } from './init-dev.js' diff --git a/src/client/init-dev.ts b/src/client/init-dev.ts new file mode 100644 index 0000000..1e54bfd --- /dev/null +++ b/src/client/init-dev.ts @@ -0,0 +1,19 @@ +import { HandleClientError } from '@sveltejs/kit' +import { Captured } from '../common/types/Captured.js' +import { init as initProd } from './init.js' +import { InitOptions } from './types/InitOptions.js' + +export const init = ( + /** + * Sentry DSN + * @see https://docs.sentry.io/product/sentry-basics/dsn-explainer/ + */ + dsn: string, + /** + * Client Init Options + */ + options?: InitOptions +): Captured => + options?.enableInDevMode + ? initProd(dsn, options) + : (handleError = () => {}) => handleError diff --git a/src/client/init.ts b/src/client/init.ts index 379e181..afc68be 100644 --- a/src/client/init.ts +++ b/src/client/init.ts @@ -1,4 +1,3 @@ -import { dev } from '$app/environment' import { HandleClientError } from '@sveltejs/kit' import { Captured } from '../common/types/Captured.js' import { handleErrorWithSentry } from './sentry/handleError.js' @@ -16,19 +15,13 @@ export const init = ( */ options?: InitOptions ): Captured => { - const { sentryOptions, enableInDevMode } = options ?? {} - - if (dev && !enableInDevMode) { - return (handleError = () => {}) => handleError - } - Sentry.init({ dsn, tracesSampleRate: 1.0, replaysSessionSampleRate: 0.1, replaysOnErrorSampleRate: 1.0, integrations: [new Sentry.Replay()], - ...sentryOptions + ...options?.sentryOptions }) return handleErrorWithSentry diff --git a/src/index-dev.ts b/src/index-dev.ts new file mode 100644 index 0000000..1ef065f --- /dev/null +++ b/src/index-dev.ts @@ -0,0 +1,2 @@ +export { init as clientInit } from './client/init-dev.js' +export { init as serverInit } from './server/init-dev.js' diff --git a/src/server/index-dev.ts b/src/server/index-dev.ts new file mode 100644 index 0000000..9b0720d --- /dev/null +++ b/src/server/index-dev.ts @@ -0,0 +1 @@ +export { init } from './init-dev.js' diff --git a/src/server/init-dev.ts b/src/server/init-dev.ts new file mode 100644 index 0000000..05bd079 --- /dev/null +++ b/src/server/init-dev.ts @@ -0,0 +1,23 @@ +import { init as initProd } from './init.js' +import { HandleWrappers } from './types/HandleWrappers.js' +import { InitOptions } from './types/InitOptions.js' +import { defaultErrorHandler } from './util/defaultErrorHandler.js' +import { defaultHandler } from './util/defaultHandler.js' + +export const init = ( + /** + * Sentry DSN + * @see https://docs.sentry.io/product/sentry-basics/dsn-explainer/ + */ + dsn: string, + /** + * Server Init Options + */ + options?: InitOptions +): HandleWrappers => + options?.enableInDevMode + ? initProd(dsn, options) + : { + onHandle: (handle = defaultHandler) => handle, + onError: (handleError = defaultErrorHandler) => handleError + } diff --git a/src/server/init.ts b/src/server/init.ts index afbc9cc..4a72426 100644 --- a/src/server/init.ts +++ b/src/server/init.ts @@ -1,9 +1,6 @@ -import { dev } from '$app/environment' import { makeHandler } from './makeHandler.js' import { HandleWrappers } from './types/HandleWrappers.js' import { InitOptions } from './types/InitOptions.js' -import { defaultErrorHandler } from './util/defaultErrorHandler.js' -import { defaultHandler } from './util/defaultHandler.js' export const init = ( /** @@ -15,15 +12,4 @@ export const init = ( * Server Init Options */ options?: InitOptions -): HandleWrappers => { - const { enableInDevMode } = options ?? {} - - if (dev && !enableInDevMode) { - return { - onHandle: (handle = defaultHandler) => handle, - onError: (handleError = defaultErrorHandler) => handleError - } - } - - return makeHandler(dsn, options) -} +): HandleWrappers => makeHandler(dsn, options)