Skip to content

Commit bd0671d

Browse files
authored
feat(sveltekit): Align build time options with shared type (#17413)
Closes #17065
1 parent 47342f3 commit bd0671d

File tree

4 files changed

+388
-101
lines changed

4 files changed

+388
-101
lines changed

packages/core/src/build-time-plugins/buildTimeOptionsBase.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,13 @@ interface ReleaseOptions {
257257
*/
258258
name?: string;
259259

260+
/**
261+
* Whether the plugin should inject release information into the build for the SDK to pick it up when sending events (recommended).
262+
*
263+
* @default true
264+
*/
265+
inject?: boolean;
266+
260267
/**
261268
* Whether to create a new release.
262269
*

packages/sveltekit/src/vite/sentryVitePlugins.ts

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,31 +91,80 @@ export function generateVitePluginOptions(
9191
};
9292
}
9393

94+
// todo(v11): remove deprecated options (Also from options type)
95+
9496
// Source Maps
9597
if (svelteKitPluginOptions.autoUploadSourceMaps && process.env.NODE_ENV !== 'development') {
96-
const { unstable_sentryVitePluginOptions, ...sourceMapsUploadOptions } =
97-
svelteKitPluginOptions.sourceMapsUploadOptions || {};
98+
const {
99+
// eslint-disable-next-line deprecation/deprecation
100+
unstable_sentryVitePluginOptions: deprecated_unstableSourceMapUploadOptions,
101+
...deprecatedSourceMapUploadOptions
102+
// eslint-disable-next-line deprecation/deprecation
103+
} = svelteKitPluginOptions.sourceMapsUploadOptions || {};
104+
105+
const {
106+
// eslint-disable-next-line @typescript-eslint/no-unused-vars,deprecation/deprecation
107+
sourceMapsUploadOptions: _filtered1,
108+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
109+
unstable_sentryVitePluginOptions: _filtered2,
110+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
111+
autoUploadSourceMaps: _filtered3,
112+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
113+
autoInstrument: _filtered4,
114+
sentryUrl,
115+
...newSvelteKitPluginOptions
116+
} = svelteKitPluginOptions;
117+
118+
const { unstable_sentryVitePluginOptions } = svelteKitPluginOptions;
98119

99120
sentryVitePluginsOptions = {
100121
...(sentryVitePluginsOptions ? sentryVitePluginsOptions : {}),
101122

102-
...sourceMapsUploadOptions,
123+
...deprecatedSourceMapUploadOptions,
124+
...newSvelteKitPluginOptions,
125+
126+
url: sentryUrl,
127+
128+
...deprecated_unstableSourceMapUploadOptions,
103129
...unstable_sentryVitePluginOptions,
130+
104131
adapter: svelteKitPluginOptions.adapter,
105132
// override the plugin's debug flag with the one from the top-level options
106133
debug: svelteKitPluginOptions.debug,
107134
};
108135

109-
if (sentryVitePluginsOptions.sourcemaps) {
136+
// Handle sourcemaps options - merge deprecated and new, with new taking precedence
137+
if (
138+
// eslint-disable-next-line deprecation/deprecation
139+
deprecatedSourceMapUploadOptions.sourcemaps ||
140+
svelteKitPluginOptions.sourcemaps ||
141+
deprecated_unstableSourceMapUploadOptions?.sourcemaps ||
142+
unstable_sentryVitePluginOptions?.sourcemaps
143+
) {
110144
sentryVitePluginsOptions.sourcemaps = {
111-
...sourceMapsUploadOptions?.sourcemaps,
145+
// eslint-disable-next-line deprecation/deprecation
146+
...deprecatedSourceMapUploadOptions.sourcemaps,
147+
...svelteKitPluginOptions.sourcemaps,
148+
// Also handle nested deprecated options from unstable plugin options
149+
...deprecated_unstableSourceMapUploadOptions?.sourcemaps,
112150
...unstable_sentryVitePluginOptions?.sourcemaps,
113151
};
114152
}
115153

116-
if (sentryVitePluginsOptions.release) {
154+
// Handle release options - merge deprecated and new, with new taking precedence
155+
if (
156+
// eslint-disable-next-line deprecation/deprecation
157+
deprecatedSourceMapUploadOptions.release ||
158+
svelteKitPluginOptions.release ||
159+
deprecated_unstableSourceMapUploadOptions?.release ||
160+
unstable_sentryVitePluginOptions?.release
161+
) {
117162
sentryVitePluginsOptions.release = {
118-
...sourceMapsUploadOptions?.release,
163+
// eslint-disable-next-line deprecation/deprecation
164+
...deprecatedSourceMapUploadOptions.release,
165+
...svelteKitPluginOptions.release,
166+
// Also handle nested deprecated options from unstable plugin options
167+
...deprecated_unstableSourceMapUploadOptions?.release,
119168
...unstable_sentryVitePluginOptions?.release,
120169
};
121170
}
Lines changed: 65 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { BuildTimeOptionsBase, UnstableVitePluginOptions } from '@sentry/core';
12
import type { SentryVitePluginOptions } from '@sentry/vite-plugin';
23
import type { AutoInstrumentSelection } from './autoInstrument';
34
import type { SupportedSvelteKitAdapters } from './detectAdapter';
@@ -19,18 +20,24 @@ type SourceMapsUploadOptions = {
1920
*
2021
* To create an auth token, follow this guide:
2122
* @see https://docs.sentry.io/product/accounts/auth-tokens/#organization-auth-tokens
23+
*
24+
* @deprecated Use option `authToken` instead of `sourceMapsUploadOptions.authToken`
2225
*/
2326
authToken?: string;
2427

2528
/**
2629
* The organization slug of your Sentry organization.
2730
* Instead of specifying this option, you can also set the `SENTRY_ORG` environment variable.
31+
*
32+
* @deprecated Use option `org` instead of `sourceMapsUploadOptions.org`
2833
*/
2934
org?: string;
3035

3136
/**
3237
* The project slug of your Sentry project.
3338
* Instead of specifying this option, you can also set the `SENTRY_PROJECT` environment variable.
39+
*
40+
* @deprecated Use option `project` instead of `sourceMapsUploadOptions.project`
3441
*/
3542
project?: string;
3643

@@ -39,11 +46,13 @@ type SourceMapsUploadOptions = {
3946
* It will not collect any sensitive or user-specific data.
4047
*
4148
* @default true
49+
* @deprecated Use option `telemetry` instead of `sourceMapsUploadOptions.telemetry`
4250
*/
4351
telemetry?: boolean;
4452

4553
/**
4654
* Options related to sourcemaps
55+
* @deprecated Use `sourcemaps` instead of `sourceMapsUploadOptions.sourcemaps`
4756
*/
4857
sourcemaps?: {
4958
/**
@@ -55,6 +64,7 @@ type SourceMapsUploadOptions = {
5564
*
5665
* The globbing patterns must follow the implementation of the `glob` package.
5766
* @see https://www.npmjs.com/package/glob#glob-primer
67+
* @deprecated Use `sourcemaps.assets` instead of `sourceMapsUploadOptions.sourcemaps.assets`
5868
*/
5969
assets?: string | Array<string>;
6070

@@ -65,6 +75,8 @@ type SourceMapsUploadOptions = {
6575
* or the default value for `assets` are uploaded.
6676
*
6777
* The globbing patterns follow the implementation of the glob package. (https://www.npmjs.com/package/glob)
78+
*
79+
* @deprecated Use `sourcemaps.ignore` instead of `sourceMapsUploadOptions.sourcemaps.ignore`
6880
*/
6981
ignore?: string | Array<string>;
7082

@@ -75,6 +87,8 @@ type SourceMapsUploadOptions = {
7587
* @default [] - By default no files are deleted.
7688
*
7789
* The globbing patterns follow the implementation of the glob package. (https://www.npmjs.com/package/glob)
90+
*
91+
* @deprecated Use `sourcemaps.filesToDeleteAfterUpload` instead of `sourceMapsUploadOptions.sourcemaps.filesToDeleteAfterUpload`
7892
*/
7993
filesToDeleteAfterUpload?: string | Array<string>;
8094
};
@@ -83,6 +97,8 @@ type SourceMapsUploadOptions = {
8397
* Options related to managing the Sentry releases for a build.
8498
*
8599
* Note: Managing releases is optional and not required for uploading source maps.
100+
*
101+
* @deprecated Use `release` instead of `sourceMapsUploadOptions.release`
86102
*/
87103
release?: {
88104
/**
@@ -94,6 +110,8 @@ type SourceMapsUploadOptions = {
94110
* access to git CLI and for the root directory to be a valid repository).
95111
*
96112
* If you didn't provide a value and the plugin can't automatically detect one, no release will be created.
113+
*
114+
* @deprecated Use `release.name` instead of `sourceMapsUploadOptions.release.name`
97115
*/
98116
name?: string;
99117

@@ -102,12 +120,16 @@ type SourceMapsUploadOptions = {
102120
* sending events.
103121
*
104122
* Defaults to `true`.
123+
*
124+
* @deprecated Use `release.inject` instead of `sourceMapsUploadOptions.release.inject`
105125
*/
106126
inject?: boolean;
107127
};
108128

109129
/**
110130
* The URL of the Sentry instance to upload the source maps to.
131+
*
132+
* @deprecated Use `sentryUrl` instead of `sourceMapsUploadOptions.url`
111133
*/
112134
url?: string;
113135

@@ -123,105 +145,54 @@ type SourceMapsUploadOptions = {
123145
* changes can occur at any time within a major SDK version.
124146
*
125147
* Furthermore, some options are untested with SvelteKit specifically. Use with caution.
126-
*/
127-
unstable_sentryVitePluginOptions?: Partial<SentryVitePluginOptions>;
128-
};
129-
130-
type BundleSizeOptimizationOptions = {
131-
/**
132-
* If set to `true`, the plugin will attempt to tree-shake (remove) any debugging code within the Sentry SDK.
133-
* Note that the success of this depends on tree shaking being enabled in your build tooling.
134148
*
135-
* Setting this option to `true` will disable features like the SDK's `debug` option.
136-
*/
137-
excludeDebugStatements?: boolean;
138-
139-
/**
140-
* If set to true, the plugin will try to tree-shake tracing statements out.
141-
* Note that the success of this depends on tree shaking generally being enabled in your build.
142-
* Attention: DO NOT enable this when you're using any performance monitoring-related SDK features (e.g. Sentry.startSpan()).
149+
* @deprecated Use `unstable_sentryVitePluginOptions` instead of `sourceMapsUploadOptions.unstable_sentryVitePluginOptions`
143150
*/
144-
excludeTracing?: boolean;
145-
146-
/**
147-
* If set to `true`, the plugin will attempt to tree-shake (remove) code related to the Sentry SDK's Session Replay Shadow DOM recording functionality.
148-
* Note that the success of this depends on tree shaking being enabled in your build tooling.
149-
*
150-
* This option is safe to be used when you do not want to capture any Shadow DOM activity via Sentry Session Replay.
151-
*/
152-
excludeReplayShadowDom?: boolean;
153-
154-
/**
155-
* If set to `true`, the plugin will attempt to tree-shake (remove) code related to the Sentry SDK's Session Replay `iframe` recording functionality.
156-
* Note that the success of this depends on tree shaking being enabled in your build tooling.
157-
*
158-
* You can safely do this when you do not want to capture any `iframe` activity via Sentry Session Replay.
159-
*/
160-
excludeReplayIframe?: boolean;
161-
162-
/**
163-
* If set to `true`, the plugin will attempt to tree-shake (remove) code related to the Sentry SDK's Session Replay's Compression Web Worker.
164-
* Note that the success of this depends on tree shaking being enabled in your build tooling.
165-
*
166-
* **Notice:** You should only do use this option if you manually host a compression worker and configure it in your Sentry Session Replay integration config via the `workerUrl` option.
167-
*/
168-
excludeReplayWorker?: boolean;
151+
unstable_sentryVitePluginOptions?: Partial<SentryVitePluginOptions>;
169152
};
170153

171154
/** Options for the Sentry SvelteKit plugin */
172-
export type SentrySvelteKitPluginOptions = {
173-
/**
174-
* If this flag is `true`, the Sentry plugins will log some useful debug information.
175-
* @default false.
176-
*/
177-
debug?: boolean;
178-
179-
/**
180-
* The Sentry plugin will automatically instrument certain parts of your SvelteKit application at build time.
181-
* Set this option to `false` to disable this behavior or what is intrumented by passing an object.
182-
*
183-
* Auto instrumentation includes:
184-
* - Universal `load` functions in `+page.(js|ts)` files
185-
* - Server-only `load` functions in `+page.server.(js|ts)` files
186-
*
187-
* @default true (meaning, the plugin will instrument all of the above)
188-
*/
189-
autoInstrument?: boolean | AutoInstrumentSelection;
190-
191-
/**
192-
* Specify which SvelteKit adapter you're using.
193-
* By default, the SDK will attempt auto-detect the used adapter at build time and apply the
194-
* correct config for source maps upload or auto-instrumentation.
195-
*
196-
* Currently, the SDK supports the following adapters:
197-
* - node (@sveltejs/adapter-node)
198-
* - auto (@sveltejs/adapter-auto) only Vercel
199-
* - vercel (@sveltejs/adapter-auto) only Serverless functions, no edge runtime
200-
*
201-
* Set this option, if the SDK detects the wrong adapter or you want to use an adapter
202-
* that is not in this list. If you specify 'other', you'll most likely need to configure
203-
* source maps upload yourself.
204-
*
205-
* @default {} the SDK attempts to auto-detect the used adapter at build time
206-
*/
207-
adapter?: SupportedSvelteKitAdapters;
155+
export type SentrySvelteKitPluginOptions = BuildTimeOptionsBase &
156+
UnstableVitePluginOptions<Partial<SentryVitePluginOptions>> & {
157+
/**
158+
* The Sentry plugin will automatically instrument certain parts of your SvelteKit application at build time.
159+
* Set this option to `false` to disable this behavior or what is intrumented by passing an object.
160+
*
161+
* Auto instrumentation includes:
162+
* - Universal `load` functions in `+page.(js|ts)` files
163+
* - Server-only `load` functions in `+page.server.(js|ts)` files
164+
*
165+
* @default true (meaning, the plugin will instrument all of the above)
166+
*/
167+
autoInstrument?: boolean | AutoInstrumentSelection;
208168

209-
/**
210-
* Options for the Sentry Vite plugin to customize bundle size optimizations.
211-
*
212-
* These options are always read from the `sentryAstro` integration.
213-
* Do not define them in the `sentry.client.config.(js|ts)` or `sentry.server.config.(js|ts)` files.
214-
*/
215-
bundleSizeOptimizations?: BundleSizeOptimizationOptions;
169+
/**
170+
* Specify which SvelteKit adapter you're using.
171+
* By default, the SDK will attempt auto-detect the used adapter at build time and apply the
172+
* correct config for source maps upload or auto-instrumentation.
173+
*
174+
* Currently, the SDK supports the following adapters:
175+
* - node (@sveltejs/adapter-node)
176+
* - auto (@sveltejs/adapter-auto) only Vercel
177+
* - vercel (@sveltejs/adapter-auto) only Serverless functions, no edge runtime
178+
*
179+
* Set this option, if the SDK detects the wrong adapter or you want to use an adapter
180+
* that is not in this list. If you specify 'other', you'll most likely need to configure
181+
* source maps upload yourself.
182+
*
183+
* @default {} the SDK attempts to auto-detect the used adapter at build time
184+
*/
185+
adapter?: SupportedSvelteKitAdapters;
216186

217-
/**
218-
* If this flag is `true`, the Sentry plugins will automatically upload source maps to Sentry.
219-
* @default true`.
220-
*/
221-
autoUploadSourceMaps?: boolean;
187+
/**
188+
* If this flag is `true`, the Sentry plugins will automatically upload source maps to Sentry.
189+
* @default true`.
190+
*/
191+
autoUploadSourceMaps?: boolean;
222192

223-
/**
224-
* Options related to source maps upload to Sentry
225-
*/
226-
sourceMapsUploadOptions?: SourceMapsUploadOptions;
227-
};
193+
/** * Options related to source maps upload to Sentry
194+
*
195+
* @deprecated This option was deprecated as it adds unnecessary nesting. Put the options one level higher to the root-level of the Sentry Svelte plugin options.
196+
*/
197+
sourceMapsUploadOptions?: SourceMapsUploadOptions;
198+
};

0 commit comments

Comments
 (0)