Skip to content

Commit 01dfc60

Browse files
committed
Flatten and simplify options
1 parent 5710c9f commit 01dfc60

File tree

5 files changed

+48
-52
lines changed

5 files changed

+48
-52
lines changed

packages/solidstart/src/vite/sentrySolidStartVite.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const sentrySolidStartVite = (options: SentrySolidStartPluginOptions): Pl
1010

1111
if (process.env.NODE_ENV !== 'development') {
1212
if (options.sourceMapsUploadOptions?.enabled ?? true) {
13-
sentryPlugins.push(...makeSourceMapsVitePlugin({ ...options.sourceMapsUploadOptions, debug: options.debug }));
13+
sentryPlugins.push(...makeSourceMapsVitePlugin(options));
1414
}
1515
}
1616

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
import { sentryVitePlugin } from '@sentry/vite-plugin';
22
import type { Plugin } from 'vite';
3-
import type { SourceMapsOptions } from './types';
3+
import type { SentrySolidStartPluginOptions } from './types';
44

55
/**
66
* A Sentry plugin for SolidStart to enable source maps and use
77
* @sentry/vite-plugin to automatically upload source maps to Sentry.
88
* @param {SourceMapsOptions} options
99
*/
10-
export function makeSourceMapsVitePlugin(options: SourceMapsOptions): Plugin[] {
10+
export function makeSourceMapsVitePlugin(options: SentrySolidStartPluginOptions): Plugin[] {
11+
const { authToken, debug, org, project, sourceMapsUploadOptions } = options;
1112
return [
1213
{
1314
name: 'sentry-solidstart-source-maps',
1415
apply: 'build',
1516
enforce: 'post',
1617
config(config) {
1718
const sourceMapsPreviouslyNotEnabled = !config.build?.sourcemap;
18-
if (options.debug && sourceMapsPreviouslyNotEnabled) {
19+
if (debug && sourceMapsPreviouslyNotEnabled) {
1920
// eslint-disable-next-line no-console
2021
console.log('[Sentry SolidStart Plugin] Enabling source map generation');
21-
if (!options.filesToDeleteAfterUpload) {
22+
if (!sourceMapsUploadOptions?.filesToDeleteAfterUpload) {
2223
// eslint-disable-next-line no-console
2324
console.warn(
2425
`[Sentry SolidStart PLugin] We recommend setting the \`sourceMapsUploadOptions.filesToDeleteAfterUpload\` option to clean up source maps after uploading.
@@ -36,21 +37,21 @@ export function makeSourceMapsVitePlugin(options: SourceMapsOptions): Plugin[] {
3637
},
3738
},
3839
...sentryVitePlugin({
39-
org: options.org ?? process.env.SENTRY_ORG,
40-
project: options.project ?? process.env.SENTRY_PROJECT,
41-
authToken: options.authToken ?? process.env.SENTRY_AUTH_TOKEN,
42-
telemetry: options.telemetry ?? true,
40+
org: org ?? process.env.SENTRY_ORG,
41+
project: project ?? process.env.SENTRY_PROJECT,
42+
authToken: authToken ?? process.env.SENTRY_AUTH_TOKEN,
43+
telemetry: sourceMapsUploadOptions?.telemetry ?? true,
4344
sourcemaps: {
44-
filesToDeleteAfterUpload: options.filesToDeleteAfterUpload ?? undefined,
45-
...options.unstable_sentryVitePluginOptions?.sourcemaps,
45+
filesToDeleteAfterUpload: sourceMapsUploadOptions?.filesToDeleteAfterUpload ?? undefined,
46+
...sourceMapsUploadOptions?.unstable_sentryVitePluginOptions?.sourcemaps,
4647
},
4748
_metaOptions: {
4849
telemetry: {
4950
metaFramework: 'solidstart',
5051
},
5152
},
52-
debug: options.debug ?? false,
53-
...options.unstable_sentryVitePluginOptions,
53+
debug: debug ?? false,
54+
...sourceMapsUploadOptions?.unstable_sentryVitePluginOptions,
5455
}),
5556
];
5657
}

packages/solidstart/src/vite/types.ts

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,6 @@ export type SourceMapsOptions = {
99
*/
1010
enabled?: boolean;
1111

12-
/**
13-
* The auth token to use when uploading source maps to Sentry.
14-
*
15-
* Instead of specifying this option, you can also set the `SENTRY_AUTH_TOKEN` environment variable.
16-
*
17-
* To create an auth token, follow this guide:
18-
* @see https://docs.sentry.io/product/accounts/auth-tokens/#organization-auth-tokens
19-
*/
20-
authToken?: string;
21-
22-
/**
23-
* The organization slug of your Sentry organization.
24-
* Instead of specifying this option, you can also set the `SENTRY_ORG` environment variable.
25-
*/
26-
org?: string;
27-
28-
/**
29-
* The project slug of your Sentry project.
30-
* Instead of specifying this option, you can also set the `SENTRY_PROJECT` environment variable.
31-
*/
32-
project?: string;
33-
3412
/**
3513
* If this flag is `true`, the Sentry plugin will collect some telemetry data and send it to Sentry.
3614
* It will not collect any sensitive or user-specific data.
@@ -63,18 +41,34 @@ export type SourceMapsOptions = {
6341
* Furthermore, some options are untested with SvelteKit specifically. Use with caution.
6442
*/
6543
unstable_sentryVitePluginOptions?: Partial<SentryVitePluginOptions>;
66-
67-
/**
68-
* Enable debug functionality of the SDK during build-time.
69-
* Enabling this will give you logs about source maps.
70-
*/
71-
debug?: boolean;
7244
};
7345

7446
/**
7547
* Build options for the Sentry module. These options are used during build-time by the Sentry SDK.
7648
*/
7749
export type SentrySolidStartPluginOptions = {
50+
/**
51+
* The auth token to use when uploading source maps to Sentry.
52+
*
53+
* Instead of specifying this option, you can also set the `SENTRY_AUTH_TOKEN` environment variable.
54+
*
55+
* To create an auth token, follow this guide:
56+
* @see https://docs.sentry.io/product/accounts/auth-tokens/#organization-auth-tokens
57+
*/
58+
authToken?: string;
59+
60+
/**
61+
* The organization slug of your Sentry organization.
62+
* Instead of specifying this option, you can also set the `SENTRY_ORG` environment variable.
63+
*/
64+
org?: string;
65+
66+
/**
67+
* The project slug of your Sentry project.
68+
* Instead of specifying this option, you can also set the `SENTRY_PROJECT` environment variable.
69+
*/
70+
project?: string;
71+
7872
/**
7973
* Options for the Sentry Vite plugin to customize the source maps upload process.
8074
*/

packages/solidstart/test/vite/sentrySolidStartVite.test.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,9 @@ vi.spyOn(console, 'warn').mockImplementation(() => {
1111

1212
function getSentrySolidStartVitePlugins(options?: Parameters<typeof sentrySolidStartVite>[0]): Plugin[] {
1313
return sentrySolidStartVite({
14-
sourceMapsUploadOptions: {
15-
authToken: 'token',
16-
org: 'org',
17-
project: 'project',
18-
...options?.sourceMapsUploadOptions,
19-
},
14+
project: 'project',
15+
org: 'org',
16+
authToken: 'token',
2017
...options,
2118
});
2219
}

packages/solidstart/test/vite/sourceMaps.test.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ describe('makeSourceMapsVitePlugin()', () => {
3838
makeSourceMapsVitePlugin({
3939
org: 'my-org',
4040
authToken: 'my-token',
41-
filesToDeleteAfterUpload: ['baz/*.js'],
41+
sourceMapsUploadOptions: {
42+
filesToDeleteAfterUpload: ['baz/*.js'],
43+
},
4244
});
4345

4446
expect(sentryVitePluginSpy).toHaveBeenCalledWith(
@@ -56,10 +58,12 @@ describe('makeSourceMapsVitePlugin()', () => {
5658
makeSourceMapsVitePlugin({
5759
org: 'my-org',
5860
authToken: 'my-token',
59-
unstable_sentryVitePluginOptions: {
60-
org: 'unstable-org',
61-
sourcemaps: {
62-
assets: ['unstable/*.js'],
61+
sourceMapsUploadOptions: {
62+
unstable_sentryVitePluginOptions: {
63+
org: 'unstable-org',
64+
sourcemaps: {
65+
assets: ['unstable/*.js'],
66+
},
6367
},
6468
},
6569
});

0 commit comments

Comments
 (0)