Skip to content

Commit

Permalink
Expose unstable_sentryVitePluginOptions as escape hatch for `@sentr…
Browse files Browse the repository at this point in the history
…y/vite-plugin`
  • Loading branch information
andreiborza committed Aug 28, 2024
1 parent 6448ce0 commit fab8cbd
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 9 deletions.
2 changes: 2 additions & 0 deletions packages/solidstart/src/vite/sourceMaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ export function makeSourceMapsVitePlugin(options: SourceMapsOptions): Plugin[] {
assets: options.sourcemaps?.assets ?? undefined,
ignore: options.sourcemaps?.ignore ?? undefined,
filesToDeleteAfterUpload: options.sourcemaps?.filesToDeleteAfterUpload ?? undefined,
...options.unstable_sentryVitePluginOptions?.sourcemaps,
},
_metaOptions: {
telemetry: {
metaFramework: 'solidstart',
},
},
debug: options.debug ?? false,
...options.unstable_sentryVitePluginOptions,
}),
];
}
17 changes: 17 additions & 0 deletions packages/solidstart/src/vite/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { SentryVitePluginOptions } from '@sentry/vite-plugin';

export type SourceMapsOptions = {
/**
* If this flag is `true`, and an auth token is detected, the Sentry SDK will
Expand Down Expand Up @@ -70,6 +72,21 @@ export type SourceMapsOptions = {
filesToDeleteAfterUpload?: string | Array<string>;
};

/**
* Options to further customize the Sentry Vite Plugin (@sentry/vite-plugin) behavior directly.
* Options specified in this object take precedence over the options specified in
* the `sourcemaps` and `release` objects.
*
* @see https://www.npmjs.com/package/@sentry/vite-plugin/v/2.22.2#options which lists all available options.
*
* Warning: Options within this object are subject to change at any time.
* We DO NOT guarantee semantic versioning for these options, meaning breaking
* changes can occur at any time within a major SDK version.
*
* Furthermore, some options are untested with SvelteKit specifically. Use with caution.
*/
unstable_sentryVitePluginOptions?: Partial<SentryVitePluginOptions>;

/**
* Enable debug functionality of the SDK during build-time.
* Enabling this will give you logs about source maps.
Expand Down
46 changes: 37 additions & 9 deletions packages/solidstart/test/vite/sourceMaps.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { SentryVitePluginOptions } from '@sentry/vite-plugin';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { makeSourceMapsVitePlugin } from '../../src/vite/sourceMaps';
import * as sourceMaps from '../../src/vite/sourceMaps';

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

const sentryVitePluginSpy = vi.fn((_options: SentryVitePluginOptions) => [mockedSentryVitePlugin]);

vi.mock('@sentry/vite-plugin', async () => {
const original = (await vi.importActual('@sentry/vite-plugin')) as any;

return {
...original,
sentryVitePlugin: () => [mockedSentryVitePlugin],
sentryVitePlugin: (options: SentryVitePluginOptions) => sentryVitePluginSpy(options),
};
});

Expand All @@ -21,7 +23,7 @@ beforeEach(() => {
});

describe('makeSourceMapsVitePlugin()', () => {
it('returns a plugin to set `sourcemaps` to `true`', async () => {
it('returns a plugin to set `sourcemaps` to `true`', () => {
const [sourceMapsConfigPlugin, sentryVitePlugin] = makeSourceMapsVitePlugin({});

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

it('passes user-specified vite plugin options to vite plugin plugin', async () => {
const makePluginSpy = vi.spyOn(sourceMaps, 'makeSourceMapsVitePlugin');

it('passes user-specified vite plugin options to vite plugin plugin', () => {
makeSourceMapsVitePlugin({
org: 'my-org',
authToken: 'my-token',
Expand All @@ -45,14 +45,42 @@ describe('makeSourceMapsVitePlugin()', () => {
},
});

expect(makePluginSpy).toHaveBeenCalledWith({
expect(sentryVitePluginSpy).toHaveBeenCalledWith(
expect.objectContaining({
org: 'my-org',
authToken: 'my-token',
sourcemaps: {
assets: ['foo/*.js'],
ignore: ['bar/*.js'],
filesToDeleteAfterUpload: ['baz/*.js'],
},
}),
);
});

it('should override options with unstable_sentryVitePluginOptions', () => {
makeSourceMapsVitePlugin({
org: 'my-org',
authToken: 'my-token',
sourcemaps: {
assets: ['foo/*.js'],
ignore: ['bar/*.js'],
filesToDeleteAfterUpload: ['baz/*.js'],
},
unstable_sentryVitePluginOptions: {
org: 'unstable-org',
sourcemaps: {
assets: ['unstable/*.js'],
},
},
});

expect(sentryVitePluginSpy).toHaveBeenCalledWith(
expect.objectContaining({
org: 'unstable-org',
authToken: 'my-token',
sourcemaps: {
assets: ['unstable/*.js'],
},
}),
);
});
});

0 comments on commit fab8cbd

Please sign in to comment.