Skip to content

Commit e123255

Browse files
chargomeclaude
andcommitted
feat(astro)!: Remove unstable_sentryVitePluginOptions
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 39db3cd commit e123255

4 files changed

Lines changed: 47 additions & 123 deletions

File tree

packages/astro/src/integration/index.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { sentryVitePlugin } from '@sentry/bundler-plugins/vite';
2+
import { warnOnRemovedBuildOptions } from '@sentry/core';
23
import { sentryOrchestrionPlugin } from '@sentry/server-utils/orchestrion/vite';
34
import type { AstroConfig, AstroIntegration, AstroIntegrationLogger } from 'astro';
45
import * as fs from 'fs';
@@ -39,7 +40,7 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => {
3940
buildTimeInstrumentation,
4041
bundleSizeOptimizations,
4142
applicationKey,
42-
unstable_sentryVitePluginOptions,
43+
moduleMetadata,
4344
debug,
4445
org,
4546
project,
@@ -52,7 +53,19 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => {
5253
...deprecatedOptions
5354
} = options;
5455

55-
const deprecatedOptionsKeys = Object.keys(deprecatedOptions);
56+
warnOnRemovedBuildOptions(options, ['unstable_sentryVitePluginOptions'], message => logger.warn(message));
57+
// The nested spelling is not covered by the check above, and `sourceMapsUploadOptions` is a
58+
// known field so it never reaches the generic "additional options" warning either.
59+
// eslint-disable-next-line typescript/no-deprecated
60+
warnOnRemovedBuildOptions(options.sourceMapsUploadOptions, ['unstable_sentryVitePluginOptions'], message =>
61+
logger.warn(message),
62+
);
63+
64+
const deprecatedOptionsKeys = Object.keys(deprecatedOptions).filter(
65+
// Reported above with an accurate message - the generic warning below would wrongly tell
66+
// users to move it into their `sentry.client.config` file.
67+
key => key !== 'unstable_sentryVitePluginOptions',
68+
);
5669
if (deprecatedOptionsKeys.length > 0) {
5770
logger.warn(
5871
`You passed in additional options (${deprecatedOptionsKeys.join(
@@ -67,14 +80,7 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => {
6780
};
6881

6982
const sourceMapsNeeded = sdkEnabled.client || sdkEnabled.server;
70-
// eslint-disable-next-line typescript/no-deprecated
71-
const { unstable_sentryVitePluginOptions: deprecatedVitePluginOptions, ...uploadOptions } =
72-
sourceMapsUploadOptions || {};
73-
74-
const unstableMerged_sentryVitePluginOptions = {
75-
...deprecatedVitePluginOptions,
76-
...unstable_sentryVitePluginOptions,
77-
};
83+
const uploadOptions = sourceMapsUploadOptions || {};
7884

7985
const shouldUploadSourcemaps =
8086
(sourceMapsNeeded &&
@@ -114,6 +120,7 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => {
114120
plugins: [
115121
sentryVitePlugin({
116122
applicationKey,
123+
moduleMetadata,
117124
// Priority: top-level options > deprecated options > env vars
118125
// eslint-disable-next-line typescript/no-deprecated
119126
org: org ?? uploadOptions.org ?? env.SENTRY_ORG,
@@ -132,7 +139,6 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => {
132139
metaFramework: 'astro',
133140
},
134141
},
135-
...unstableMerged_sentryVitePluginOptions,
136142
debug: debug ?? false,
137143
sourcemaps: {
138144
...sourcemaps,
@@ -143,11 +149,9 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => {
143149
// eslint-disable-next-line typescript/no-deprecated
144150
uploadOptions?.filesToDeleteAfterUpload ??
145151
updatedFilesToDeleteAfterUpload,
146-
...unstableMerged_sentryVitePluginOptions?.sourcemaps,
147152
},
148153
bundleSizeOptimizations: {
149154
...bundleSizeOptimizations,
150-
...unstableMerged_sentryVitePluginOptions?.bundleSizeOptimizations,
151155
},
152156
}),
153157
],

packages/astro/src/integration/types.ts

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import type { BuildTimeOptionsBase, UnstableVitePluginOptions } from '@sentry/core';
2-
import type { SentryVitePluginOptions } from '@sentry/bundler-plugins/vite';
1+
import type { BuildTimeOptionsBase } from '@sentry/core';
32
import type { RouteData } from 'astro';
43

54
type SdkInitPaths = {
@@ -99,22 +98,6 @@ type SourceMapsOptions = {
9998
* @deprecated Use `sourcemaps.filesToDeleteAfterUpload` instead
10099
*/
101100
filesToDeleteAfterUpload?: string | Array<string>;
102-
103-
/**
104-
* Options to further customize the Sentry Vite Plugin (@sentry/bundler-plugins/vite) behavior directly.
105-
* Options specified in this object take precedence over all other options.
106-
*
107-
* @see https://www.npmjs.com/package/@sentry/vite-plugin/v/2.14.2#options which lists all available options.
108-
*
109-
* Warning: Options within this object are subject to change at any time.
110-
* We DO NOT guarantee semantic versioning for these options, meaning breaking
111-
* changes can occur at any time within a major SDK version.
112-
*
113-
* Furthermore, some options are untested with Astro specifically. Use with caution.
114-
*
115-
* @deprecated Use top-level `unstable_sentryVitePluginOptions` instead
116-
*/
117-
unstable_sentryVitePluginOptions?: Partial<SentryVitePluginOptions>;
118101
};
119102

120103
type InstrumentationOptions = {
@@ -177,7 +160,6 @@ type DeprecatedRuntimeOptions = Record<string, unknown>;
177160
*/
178161
export type SentryOptions = Omit<BuildTimeOptionsBase, 'release'> &
179162
// todo(v11): `release` and `debug` need to be removed from BuildTimeOptionsBase as it is currently conflicting with `DeprecatedRuntimeOptions`
180-
UnstableVitePluginOptions<SentryVitePluginOptions> &
181163
SdkInitPaths &
182164
InstrumentationOptions &
183165
SdkEnabledOptions & {

packages/astro/test/buildOptions.test-d.ts

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,6 @@ describe('Sentry Astro build-time options type', () => {
5252
excludeReplayWorker: true,
5353
},
5454

55-
// --- UnstableVitePluginOptions ---
56-
unstable_sentryVitePluginOptions: {
57-
sourcemaps: {
58-
assets: './dist/**/*',
59-
},
60-
bundleSizeOptimizations: {
61-
excludeDebugStatements: true,
62-
},
63-
},
64-
6555
// --- SentryOptions specific options ---
6656
enabled: true,
6757
clientInitPath: './src/sentry.client.config.ts',
@@ -92,15 +82,6 @@ describe('Sentry Astro build-time options type', () => {
9282
autoInstrumentation: {
9383
requestHandler: true,
9484
},
95-
unstable_sentryVitePluginOptions: {
96-
sourcemaps: {
97-
assets: './dist/**/*',
98-
},
99-
bundleSizeOptimizations: {
100-
excludeDebugStatements: true,
101-
},
102-
},
103-
10485
// Deprecated sourceMapsUploadOptions
10586
sourceMapsUploadOptions: {
10687
enabled: true,
@@ -110,11 +91,6 @@ describe('Sentry Astro build-time options type', () => {
11091
telemetry: false,
11192
assets: './build/**/*',
11293
filesToDeleteAfterUpload: ['./build/*.map'],
113-
unstable_sentryVitePluginOptions: {
114-
sourcemaps: {
115-
ignore: ['./build/*.spec.js'],
116-
},
117-
},
11894
},
11995
};
12096

@@ -166,25 +142,4 @@ describe('Sentry Astro build-time options type', () => {
166142

167143
expectTypeOf(baseOptions).toEqualTypeOf<SentryOptions>();
168144
});
169-
170-
it('supports UnstableVitePluginOptions at top level', () => {
171-
const viteOptions: SentryOptions = {
172-
unstable_sentryVitePluginOptions: {
173-
org: 'override-org',
174-
project: 'override-project',
175-
sourcemaps: {
176-
assets: './custom-dist/**/*',
177-
ignore: ['./custom-dist/ignore/**/*'],
178-
},
179-
bundleSizeOptimizations: {
180-
excludeDebugStatements: true,
181-
excludeTracing: false,
182-
},
183-
debug: true,
184-
silent: false,
185-
},
186-
};
187-
188-
expectTypeOf(viteOptions).toEqualTypeOf<SentryOptions>();
189-
});
190145
});

packages/astro/test/integration/index.test.ts

Lines changed: 29 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -259,58 +259,41 @@ describe('sentryAstro integration', () => {
259259
);
260260
});
261261

262-
it('prefers user-specified unstable vite plugin options and merges them with default values', async () => {
262+
// No `@ts-expect-error` here on purpose: `SentryOptions` intersects `Record<string, unknown>`, so
263+
// TypeScript accepts any key and this runtime warning is the only signal an Astro user ever gets.
264+
it('warns for the removed option nested inside `sourceMapsUploadOptions`', async () => {
263265
const integration = sentryAstro({
264-
bundleSizeOptimizations: {
265-
excludeReplayShadowDom: true,
266-
},
267-
sourceMapsUploadOptions: {
268-
enabled: true,
269-
org: 'my-org',
270-
project: 'my-project',
271-
assets: ['dist/server/**/*, dist/client/**/*'],
272-
unstable_sentryVitePluginOptions: {
273-
org: 'my-other-org',
274-
project: 'my-other-project',
275-
applicationKey: 'my-application-key',
276-
sourcemaps: {
277-
assets: ['foo/*.js'],
278-
ignore: ['bar/*.js'],
279-
},
280-
bundleSizeOptimizations: {
281-
excludeReplayIframe: true,
282-
},
283-
},
284-
},
266+
// @ts-expect-error - removed in v11
267+
sourceMapsUploadOptions: { unstable_sentryVitePluginOptions: { org: 'my-other-org' } },
285268
});
286269
// @ts-expect-error - the hook exists, and we only need to pass what we actually use
287-
await integration.hooks['astro:config:setup']({
288-
...baseConfigHookObject,
289-
updateConfig,
290-
injectScript,
291-
// @ts-expect-error - only passing in partial config
292-
config: {
293-
outDir: new URL('file://path/to/project/build'),
294-
},
270+
await integration.hooks['astro:config:setup']({ ...baseConfigHookObject, updateConfig, injectScript, config });
271+
272+
expect(baseConfigHookObject.logger.warn).toHaveBeenCalledWith(
273+
expect.stringContaining('unstable_sentryVitePluginOptions'),
274+
);
275+
});
276+
277+
it('forwards moduleMetadata to the vite plugin', async () => {
278+
const integration = sentryAstro({ moduleMetadata: { team: 'sdk' } });
279+
// @ts-expect-error - the hook exists, and we only need to pass what we actually use
280+
await integration.hooks['astro:config:setup']({ ...baseConfigHookObject, updateConfig, injectScript, config });
281+
282+
expect(sentryVitePluginSpy).toHaveBeenCalledWith(expect.objectContaining({ moduleMetadata: { team: 'sdk' } }));
283+
});
284+
285+
it('warns via the Astro logger when the removed `unstable_sentryVitePluginOptions` is still set', async () => {
286+
const integration = sentryAstro({
287+
unstable_sentryVitePluginOptions: { org: 'my-other-org' },
295288
});
289+
// @ts-expect-error - the hook exists, and we only need to pass what we actually use
290+
await integration.hooks['astro:config:setup']({ ...baseConfigHookObject, updateConfig, injectScript, config });
296291

297-
expect(sentryVitePluginSpy).toHaveBeenCalledTimes(1);
298-
expect(sentryVitePluginSpy).toHaveBeenCalledWith(
299-
expect.objectContaining({
300-
org: 'my-other-org',
301-
project: 'my-other-project',
302-
applicationKey: 'my-application-key',
303-
sourcemaps: {
304-
assets: ['foo/*.js'],
305-
ignore: ['bar/*.js'],
306-
filesToDeleteAfterUpload: ['./dist/**/client/**/*.map', './dist/**/server/**/*.map'],
307-
},
308-
bundleSizeOptimizations: {
309-
excludeReplayShadowDom: true,
310-
excludeReplayIframe: true,
311-
},
312-
}),
292+
expect(baseConfigHookObject.logger.warn).toHaveBeenCalledWith(
293+
expect.stringContaining('unstable_sentryVitePluginOptions'),
313294
);
295+
// The generic "additional options" warning would wrongly point users at their SDK init file.
296+
expect(baseConfigHookObject.logger.warn).not.toHaveBeenCalledWith(expect.stringContaining('sentry.client.config'));
314297
});
315298

316299
it('passes top-level applicationKey to the vite plugin', async () => {

0 commit comments

Comments
 (0)