From fab8cbddaf45a152712609d554ddd85de520e5f3 Mon Sep 17 00:00:00 2001 From: Andrei Borza Date: Wed, 28 Aug 2024 13:54:47 +0200 Subject: [PATCH] Expose `unstable_sentryVitePluginOptions` as escape hatch for `@sentry/vite-plugin` --- packages/solidstart/src/vite/sourceMaps.ts | 2 + packages/solidstart/src/vite/types.ts | 17 +++++++ .../solidstart/test/vite/sourceMaps.test.ts | 46 +++++++++++++++---- 3 files changed, 56 insertions(+), 9 deletions(-) diff --git a/packages/solidstart/src/vite/sourceMaps.ts b/packages/solidstart/src/vite/sourceMaps.ts index 2133edbfa9dd..3a3afd187ae3 100644 --- a/packages/solidstart/src/vite/sourceMaps.ts +++ b/packages/solidstart/src/vite/sourceMaps.ts @@ -44,6 +44,7 @@ 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: { @@ -51,6 +52,7 @@ export function makeSourceMapsVitePlugin(options: SourceMapsOptions): Plugin[] { }, }, debug: options.debug ?? false, + ...options.unstable_sentryVitePluginOptions, }), ]; } diff --git a/packages/solidstart/src/vite/types.ts b/packages/solidstart/src/vite/types.ts index 0a1c6dc81acb..8d595be1a54d 100644 --- a/packages/solidstart/src/vite/types.ts +++ b/packages/solidstart/src/vite/types.ts @@ -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 @@ -70,6 +72,21 @@ export type SourceMapsOptions = { filesToDeleteAfterUpload?: string | Array; }; + /** + * 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; + /** * Enable debug functionality of the SDK during build-time. * Enabling this will give you logs about source maps. diff --git a/packages/solidstart/test/vite/sourceMaps.test.ts b/packages/solidstart/test/vite/sourceMaps.test.ts index 7aea5bb24978..d1e8d3f4633c 100644 --- a/packages/solidstart/test/vite/sourceMaps.test.ts +++ b/packages/solidstart/test/vite/sourceMaps.test.ts @@ -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), }; }); @@ -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'); @@ -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', @@ -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'], + }, + }), + ); }); });