Skip to content

Commit 21388bd

Browse files
feat(astro): Accept all vite-plugin options
Adds support for `unstable_sentryVitePluginOptions` which can be used to pass any valid vite-plugin option. Fixes getsentry#15601
1 parent defeaaf commit 21388bd

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

packages/astro/src/integration/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => {
3030
};
3131

3232
const sourceMapsNeeded = sdkEnabled.client || sdkEnabled.server;
33-
const uploadOptions = options.sourceMapsUploadOptions || {};
33+
const { unstable_sentryVitePluginOptions, ...uploadOptions } = options.sourceMapsUploadOptions || {};
3434
const shouldUploadSourcemaps = (sourceMapsNeeded && uploadOptions?.enabled) ?? true;
3535

3636
// We don't need to check for AUTH_TOKEN here, because the plugin will pick it up from the env
@@ -85,6 +85,7 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => {
8585
},
8686
},
8787
debug: options.debug ?? false,
88+
...unstable_sentryVitePluginOptions
8889
}),
8990
),
9091
],

packages/astro/src/integration/types.ts

+15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { BrowserOptions } from '@sentry/browser';
22
import type { Options } from '@sentry/core';
3+
import type { SentryVitePluginOptions } from '@sentry/vite-plugin';
34

45
type SdkInitPaths = {
56
/**
@@ -83,6 +84,20 @@ type SourceMapsOptions = {
8384
* The globbing patterns follow the implementation of the glob package. (https://www.npmjs.com/package/glob)
8485
*/
8586
filesToDeleteAfterUpload?: string | Array<string>;
87+
88+
/**
89+
* Options to further customize the Sentry Vite Plugin (@sentry/vite-plugin) behavior directly.
90+
* Options specified in this object take precedence over all other options.
91+
*
92+
* @see https://www.npmjs.com/package/@sentry/vite-plugin/v/2.14.2#options which lists all available options.
93+
*
94+
* Warning: Options within this object are subject to change at any time.
95+
* We DO NOT guarantee semantic versioning for these options, meaning breaking
96+
* changes can occur at any time within a major SDK version.
97+
*
98+
* Furthermore, some options are untested with Astro specifically. Use with caution.
99+
*/
100+
unstable_sentryVitePluginOptions?: Partial<SentryVitePluginOptions>
86101
};
87102

88103
type BundleSizeOptimizationOptions = {

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

+45
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,51 @@ describe('sentryAstro integration', () => {
202202
);
203203
});
204204

205+
it('prefers user-specified unstable vite plugin options over everything else', async () => {
206+
const integration = sentryAstro({
207+
sourceMapsUploadOptions: {
208+
enabled: true,
209+
org: 'my-org',
210+
project: 'my-project',
211+
assets: ['dist/server/**/*, dist/client/**/*'],
212+
debug: true,
213+
unstable_sentryVitePluginOptions: {
214+
org: 'my-other-org',
215+
project: 'my-other-project',
216+
applicationKey: 'my-application-key',
217+
debug: false,
218+
sourcemaps: {
219+
assets: ['foo/*.js'],
220+
ignore: ['bar/*.js'],
221+
},
222+
}
223+
},
224+
});
225+
// @ts-expect-error - the hook exists, and we only need to pass what we actually use
226+
await integration.hooks['astro:config:setup']({
227+
updateConfig,
228+
injectScript,
229+
// @ts-expect-error - only passing in partial config
230+
config: {
231+
outDir: new URL('file://path/to/project/build'),
232+
},
233+
});
234+
235+
expect(sentryVitePluginSpy).toHaveBeenCalledTimes(1);
236+
expect(sentryVitePluginSpy).toHaveBeenCalledWith(
237+
expect.objectContaining({
238+
org: 'my-other-org',
239+
project: 'my-other-project',
240+
applicationKey: 'my-application-key',
241+
debug: false,
242+
sourcemaps: {
243+
assets: ['foo/*.js'],
244+
ignore: ['bar/*.js'],
245+
},
246+
}),
247+
);
248+
});
249+
205250
it("doesn't enable source maps if `sourceMapsUploadOptions.enabled` is `false`", async () => {
206251
const integration = sentryAstro({
207252
sourceMapsUploadOptions: { enabled: false },

0 commit comments

Comments
 (0)