Skip to content

Commit eebbda1

Browse files
committed
Expose unstable_sentryVitePluginOptions as escape hatch for @sentry/vite-plugin
1 parent 3c437d1 commit eebbda1

File tree

3 files changed

+56
-9
lines changed

3 files changed

+56
-9
lines changed

packages/solidstart/src/vite/sourceMaps.ts

+2
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,15 @@ export function makeSourceMapsVitePlugin(options: SourceMapsOptions): Plugin[] {
4444
assets: options.sourcemaps?.assets ?? undefined,
4545
ignore: options.sourcemaps?.ignore ?? undefined,
4646
filesToDeleteAfterUpload: options.sourcemaps?.filesToDeleteAfterUpload ?? undefined,
47+
...options.unstable_sentryVitePluginOptions?.sourcemaps,
4748
},
4849
_metaOptions: {
4950
telemetry: {
5051
metaFramework: 'solidstart',
5152
},
5253
},
5354
debug: options.debug ?? false,
55+
...options.unstable_sentryVitePluginOptions,
5456
}),
5557
];
5658
}

packages/solidstart/src/vite/types.ts

+17
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { SentryVitePluginOptions } from '@sentry/vite-plugin';
2+
13
export type SourceMapsOptions = {
24
/**
35
* If this flag is `true`, and an auth token is detected, the Sentry SDK will
@@ -70,6 +72,21 @@ export type SourceMapsOptions = {
7072
filesToDeleteAfterUpload?: string | Array<string>;
7173
};
7274

75+
/**
76+
* Options to further customize the Sentry Vite Plugin (@sentry/vite-plugin) behavior directly.
77+
* Options specified in this object take precedence over the options specified in
78+
* the `sourcemaps` and `release` objects.
79+
*
80+
* @see https://www.npmjs.com/package/@sentry/vite-plugin/v/2.22.2#options which lists all available options.
81+
*
82+
* Warning: Options within this object are subject to change at any time.
83+
* We DO NOT guarantee semantic versioning for these options, meaning breaking
84+
* changes can occur at any time within a major SDK version.
85+
*
86+
* Furthermore, some options are untested with SvelteKit specifically. Use with caution.
87+
*/
88+
unstable_sentryVitePluginOptions?: Partial<SentryVitePluginOptions>;
89+
7390
/**
7491
* Enable debug functionality of the SDK during build-time.
7592
* Enabling this will give you logs about source maps.
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1+
import { SentryVitePluginOptions } from '@sentry/vite-plugin';
12
import { beforeEach, describe, expect, it, vi } from 'vitest';
23
import { makeSourceMapsVitePlugin } from '../../src/vite/sourceMaps';
3-
import * as sourceMaps from '../../src/vite/sourceMaps';
44

55
const mockedSentryVitePlugin = {
66
name: 'sentry-vite-debug-id-upload-plugin',
77
writeBundle: vi.fn(),
88
};
99

10+
const sentryVitePluginSpy = vi.fn((_options: SentryVitePluginOptions) => [mockedSentryVitePlugin]);
11+
1012
vi.mock('@sentry/vite-plugin', async () => {
1113
const original = (await vi.importActual('@sentry/vite-plugin')) as any;
1214

1315
return {
1416
...original,
15-
sentryVitePlugin: () => [mockedSentryVitePlugin],
17+
sentryVitePlugin: (options: SentryVitePluginOptions) => sentryVitePluginSpy(options),
1618
};
1719
});
1820

@@ -21,7 +23,7 @@ beforeEach(() => {
2123
});
2224

2325
describe('makeSourceMapsVitePlugin()', () => {
24-
it('returns a plugin to set `sourcemaps` to `true`', async () => {
26+
it('returns a plugin to set `sourcemaps` to `true`', () => {
2527
const [sourceMapsConfigPlugin, sentryVitePlugin] = makeSourceMapsVitePlugin({});
2628

2729
expect(sourceMapsConfigPlugin?.name).toEqual('sentry-solidstart-source-maps');
@@ -32,9 +34,7 @@ describe('makeSourceMapsVitePlugin()', () => {
3234
expect(sentryVitePlugin).toEqual(mockedSentryVitePlugin);
3335
});
3436

35-
it('passes user-specified vite plugin options to vite plugin plugin', async () => {
36-
const makePluginSpy = vi.spyOn(sourceMaps, 'makeSourceMapsVitePlugin');
37-
37+
it('passes user-specified vite plugin options to vite plugin plugin', () => {
3838
makeSourceMapsVitePlugin({
3939
org: 'my-org',
4040
authToken: 'my-token',
@@ -45,14 +45,42 @@ describe('makeSourceMapsVitePlugin()', () => {
4545
},
4646
});
4747

48-
expect(makePluginSpy).toHaveBeenCalledWith({
48+
expect(sentryVitePluginSpy).toHaveBeenCalledWith(
49+
expect.objectContaining({
50+
org: 'my-org',
51+
authToken: 'my-token',
52+
sourcemaps: {
53+
assets: ['foo/*.js'],
54+
ignore: ['bar/*.js'],
55+
filesToDeleteAfterUpload: ['baz/*.js'],
56+
},
57+
}),
58+
);
59+
});
60+
61+
it('should override options with unstable_sentryVitePluginOptions', () => {
62+
makeSourceMapsVitePlugin({
4963
org: 'my-org',
5064
authToken: 'my-token',
5165
sourcemaps: {
5266
assets: ['foo/*.js'],
53-
ignore: ['bar/*.js'],
54-
filesToDeleteAfterUpload: ['baz/*.js'],
67+
},
68+
unstable_sentryVitePluginOptions: {
69+
org: 'unstable-org',
70+
sourcemaps: {
71+
assets: ['unstable/*.js'],
72+
},
5573
},
5674
});
75+
76+
expect(sentryVitePluginSpy).toHaveBeenCalledWith(
77+
expect.objectContaining({
78+
org: 'unstable-org',
79+
authToken: 'my-token',
80+
sourcemaps: {
81+
assets: ['unstable/*.js'],
82+
},
83+
}),
84+
);
5785
});
5886
});

0 commit comments

Comments
 (0)