Skip to content

Commit dc9a49a

Browse files
committed
feat(astro): Align options with shared build time options type
1 parent 377c7fc commit dc9a49a

File tree

9 files changed

+394
-136
lines changed

9 files changed

+394
-136
lines changed

packages/astro/.eslintrc.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = {
88
{
99
files: ['vite.config.ts'],
1010
parserOptions: {
11-
project: ['tsconfig.test.json'],
11+
project: ['tsconfig.vite.json'],
1212
},
1313
},
1414
],

packages/astro/src/integration/index.ts

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,13 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => {
2727
clientInitPath,
2828
serverInitPath,
2929
autoInstrumentation,
30+
// eslint-disable-next-line deprecation/deprecation
3031
sourceMapsUploadOptions,
32+
sourcemaps,
33+
// todo(v11): Extract `release` build time option here - cannot be done currently, because it conflicts with the `DeprecatedRuntimeOptions` type
34+
// release,
3135
bundleSizeOptimizations,
36+
unstable_sentryVitePluginOptions,
3237
debug,
3338
...otherOptions
3439
} = options;
@@ -48,8 +53,21 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => {
4853
};
4954

5055
const sourceMapsNeeded = sdkEnabled.client || sdkEnabled.server;
51-
const { unstable_sentryVitePluginOptions, ...uploadOptions } = sourceMapsUploadOptions || {};
52-
const shouldUploadSourcemaps = (sourceMapsNeeded && uploadOptions?.enabled) ?? true;
56+
// eslint-disable-next-line deprecation/deprecation
57+
const { unstable_sentryVitePluginOptions: deprecatedVitePluginOptions, ...uploadOptions } =
58+
sourceMapsUploadOptions || {};
59+
60+
const unstableMerged_sentryVitePluginOptions = {
61+
...deprecatedVitePluginOptions,
62+
...unstable_sentryVitePluginOptions,
63+
};
64+
65+
const shouldUploadSourcemaps =
66+
(sourceMapsNeeded &&
67+
sourcemaps?.disable !== true &&
68+
// eslint-disable-next-line deprecation/deprecation
69+
uploadOptions?.enabled) ??
70+
true;
5371

5472
// We don't need to check for AUTH_TOKEN here, because the plugin will pick it up from the env
5573
if (shouldUploadSourcemaps && command !== 'dev') {
@@ -58,7 +76,9 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => {
5876
let updatedFilesToDeleteAfterUpload: string[] | undefined = undefined;
5977

6078
if (
79+
// eslint-disable-next-line deprecation/deprecation
6180
typeof uploadOptions?.filesToDeleteAfterUpload === 'undefined' &&
81+
typeof sourcemaps?.filesToDeleteAfterUpload === 'undefined' &&
6282
computedSourceMapSettings.previousUserSourceMapSetting === 'unset'
6383
) {
6484
// This also works for adapters, as the source maps are also copied to e.g. the .vercel folder
@@ -79,26 +99,40 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => {
7999
},
80100
plugins: [
81101
sentryVitePlugin({
82-
org: uploadOptions.org ?? env.SENTRY_ORG,
83-
project: uploadOptions.project ?? env.SENTRY_PROJECT,
84-
authToken: uploadOptions.authToken ?? env.SENTRY_AUTH_TOKEN,
85-
telemetry: uploadOptions.telemetry ?? true,
102+
// Priority: top-level options > deprecated options > env vars
103+
// eslint-disable-next-line deprecation/deprecation
104+
org: options.org ?? uploadOptions.org ?? env.SENTRY_ORG,
105+
// eslint-disable-next-line deprecation/deprecation
106+
project: options.project ?? uploadOptions.project ?? env.SENTRY_PROJECT,
107+
// eslint-disable-next-line deprecation/deprecation
108+
authToken: options.authToken ?? uploadOptions.authToken ?? env.SENTRY_AUTH_TOKEN,
109+
url: options.sentryUrl ?? env.SENTRY_URL,
110+
headers: options.headers,
111+
// eslint-disable-next-line deprecation/deprecation
112+
telemetry: options.telemetry ?? uploadOptions.telemetry ?? true,
113+
silent: options.silent ?? false,
114+
errorHandler: options.errorHandler,
86115
_metaOptions: {
87116
telemetry: {
88117
metaFramework: 'astro',
89118
},
90119
},
91-
...unstable_sentryVitePluginOptions,
92-
debug: debug ?? false,
120+
...unstableMerged_sentryVitePluginOptions,
121+
debug: options.debug ?? false,
93122
sourcemaps: {
94-
assets: uploadOptions.assets ?? [getSourcemapsAssetsGlob(config)],
123+
...options.sourcemaps,
124+
// eslint-disable-next-line deprecation/deprecation
125+
assets: sourcemaps?.assets ?? uploadOptions.assets ?? [getSourcemapsAssetsGlob(config)],
95126
filesToDeleteAfterUpload:
96-
uploadOptions?.filesToDeleteAfterUpload ?? updatedFilesToDeleteAfterUpload,
97-
...unstable_sentryVitePluginOptions?.sourcemaps,
127+
sourcemaps?.filesToDeleteAfterUpload ??
128+
// eslint-disable-next-line deprecation/deprecation
129+
uploadOptions?.filesToDeleteAfterUpload ??
130+
updatedFilesToDeleteAfterUpload,
131+
...unstableMerged_sentryVitePluginOptions?.sourcemaps,
98132
},
99133
bundleSizeOptimizations: {
100134
...bundleSizeOptimizations,
101-
...unstable_sentryVitePluginOptions?.bundleSizeOptimizations,
135+
...unstableMerged_sentryVitePluginOptions?.bundleSizeOptimizations,
102136
},
103137
}),
104138
],

packages/astro/src/integration/types.ts

Lines changed: 26 additions & 53 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 { RouteData } from 'astro';
34

@@ -23,12 +24,16 @@ type SdkInitPaths = {
2324
serverInitPath?: string;
2425
};
2526

27+
/**
28+
* @deprecated Move these options to the top-level of your Sentry configuration.
29+
*/
2630
type SourceMapsOptions = {
2731
/**
2832
* If this flag is `true`, and an auth token is detected, the Sentry integration will
2933
* automatically generate and upload source maps to Sentry during a production build.
3034
*
3135
* @default true
36+
* @deprecated Use `sourcemaps.disable` instead (with inverted logic)
3237
*/
3338
enabled?: boolean;
3439

@@ -39,18 +44,24 @@ type SourceMapsOptions = {
3944
*
4045
* To create an auth token, follow this guide:
4146
* @see https://docs.sentry.io/product/accounts/auth-tokens/#organization-auth-tokens
47+
*
48+
* @deprecated Use top-level `authToken` option instead
4249
*/
4350
authToken?: string;
4451

4552
/**
4653
* The organization slug of your Sentry organization.
4754
* Instead of specifying this option, you can also set the `SENTRY_ORG` environment variable.
55+
*
56+
* @deprecated Use top-level `org` option instead
4857
*/
4958
org?: string;
5059

5160
/**
5261
* The project slug of your Sentry project.
5362
* Instead of specifying this option, you can also set the `SENTRY_PROJECT` environment variable.
63+
*
64+
* @deprecated Use top-level `project` option instead
5465
*/
5566
project?: string;
5667

@@ -59,6 +70,7 @@ type SourceMapsOptions = {
5970
* It will not collect any sensitive or user-specific data.
6071
*
6172
* @default true
73+
* @deprecated Use top-level `telemetry` option instead
6274
*/
6375
telemetry?: boolean;
6476

@@ -71,6 +83,8 @@ type SourceMapsOptions = {
7183
*
7284
* The globbing patterns must follow the implementation of the `glob` package.
7385
* @see https://www.npmjs.com/package/glob#glob-primer
86+
*
87+
* @deprecated Use `sourcemaps.assets` instead
7488
*/
7589
assets?: string | Array<string>;
7690

@@ -81,6 +95,8 @@ type SourceMapsOptions = {
8195
* @default [] - By default no files are deleted.
8296
*
8397
* The globbing patterns follow the implementation of the glob package. (https://www.npmjs.com/package/glob)
98+
*
99+
* @deprecated Use `sourcemaps.filesToDeleteAfterUpload` instead
84100
*/
85101
filesToDeleteAfterUpload?: string | Array<string>;
86102

@@ -95,49 +111,10 @@ type SourceMapsOptions = {
95111
* changes can occur at any time within a major SDK version.
96112
*
97113
* Furthermore, some options are untested with Astro specifically. Use with caution.
98-
*/
99-
unstable_sentryVitePluginOptions?: Partial<SentryVitePluginOptions>;
100-
};
101-
102-
type BundleSizeOptimizationOptions = {
103-
/**
104-
* If set to `true`, the plugin will attempt to tree-shake (remove) any debugging code within the Sentry SDK.
105-
* Note that the success of this depends on tree shaking being enabled in your build tooling.
106-
*
107-
* Setting this option to `true` will disable features like the SDK's `debug` option.
108-
*/
109-
excludeDebugStatements?: boolean;
110-
111-
/**
112-
* If set to true, the plugin will try to tree-shake performance monitoring statements out.
113-
* Note that the success of this depends on tree shaking generally being enabled in your build.
114-
* Attention: DO NOT enable this when you're using any performance monitoring-related SDK features (e.g. Sentry.startSpan()).
115-
*/
116-
excludeTracing?: boolean;
117-
118-
/**
119-
* 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.
120-
* Note that the success of this depends on tree shaking being enabled in your build tooling.
121114
*
122-
* This option is safe to be used when you do not want to capture any Shadow DOM activity via Sentry Session Replay.
115+
* @deprecated Use top-level `unstable_sentryVitePluginOptions` instead
123116
*/
124-
excludeReplayShadowDom?: boolean;
125-
126-
/**
127-
* If set to `true`, the plugin will attempt to tree-shake (remove) code related to the Sentry SDK's Session Replay `iframe` recording functionality.
128-
* Note that the success of this depends on tree shaking being enabled in your build tooling.
129-
*
130-
* You can safely do this when you do not want to capture any `iframe` activity via Sentry Session Replay.
131-
*/
132-
excludeReplayIframe?: boolean;
133-
134-
/**
135-
* 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.
136-
* Note that the success of this depends on tree shaking being enabled in your build tooling.
137-
*
138-
* **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.
139-
*/
140-
excludeReplayWorker?: boolean;
117+
unstable_sentryVitePluginOptions?: Partial<SentryVitePluginOptions>;
141118
};
142119

143120
type InstrumentationOptions = {
@@ -202,27 +179,23 @@ type DeprecatedRuntimeOptions = Record<string, unknown>;
202179
*
203180
* If you specify a dedicated init file, the SDK options passed to `sentryAstro` will be ignored.
204181
*/
205-
export type SentryOptions = SdkInitPaths &
182+
export type SentryOptions = Omit<BuildTimeOptionsBase, 'release'> &
183+
// todo(v11): `release` and `debug` need to be removed from BuildTimeOptionsBase as it is currently conflicting with `DeprecatedRuntimeOptions`
184+
UnstableVitePluginOptions<SentryVitePluginOptions> &
185+
SdkInitPaths &
206186
InstrumentationOptions &
207187
SdkEnabledOptions & {
208188
/**
209189
* Options for the Sentry Vite plugin to customize the source maps upload process.
210190
*
211191
* These options are always read from the `sentryAstro` integration.
212192
* Do not define them in the `sentry.client.config.(js|ts)` or `sentry.server.config.(js|ts)` files.
213-
*/
214-
sourceMapsUploadOptions?: SourceMapsOptions;
215-
/**
216-
* Options for the Sentry Vite plugin to customize bundle size optimizations.
217193
*
218-
* These options are always read from the `sentryAstro` integration.
219-
* Do not define them in the `sentry.client.config.(js|ts)` or `sentry.server.config.(js|ts)` files.
194+
* @deprecated This option was deprecated. Please move the options to the top-level configuration.
195+
* See the migration guide in the SourceMapsOptions type documentation.
220196
*/
221-
bundleSizeOptimizations?: BundleSizeOptimizationOptions;
222-
/**
223-
* If enabled, prints debug logs during the build process.
224-
*/
225-
debug?: boolean;
197+
// eslint-disable-next-line deprecation/deprecation
198+
sourceMapsUploadOptions?: SourceMapsOptions;
226199
// eslint-disable-next-line deprecation/deprecation
227200
} & DeprecatedRuntimeOptions;
228201

0 commit comments

Comments
 (0)