Skip to content

Commit b3d44be

Browse files
committed
feat(react-router): Align options with shared build time options type
1 parent fe8393a commit b3d44be

File tree

13 files changed

+250
-174
lines changed

13 files changed

+250
-174
lines changed

packages/core/src/build-time-plugins/buildTimeOptionsBase.ts

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,12 @@ interface ReleaseOptions {
330330

331331
/**
332332
* Configuration for associating the release with its commits in Sentry.
333+
*
334+
* Set to `false` to disable commit association.
335+
*
336+
* @default { auto: true }
333337
*/
334-
setCommits?: (AutoSetCommitsOptions | ManualSetCommitsOptions) & {
338+
setCommits?: false | (AutoSetCommitsOptions | ManualSetCommitsOptions) & {
335339
/**
336340
* The commit before the beginning of this release (in other words,
337341
* the last commit of the previous release).
@@ -362,39 +366,43 @@ interface ReleaseOptions {
362366

363367
/**
364368
* Configuration for adding deployment information to the release in Sentry.
365-
*/
366-
deploy?: {
367-
/**
368-
* Environment for this release. Values that make sense here would
369-
* be `production` or `staging`.
370-
*/
371-
env: string;
372-
373-
/**
374-
* Deployment start time in Unix timestamp (in seconds) or ISO 8601 format.
375-
*/
376-
started?: number | string;
377-
378-
/**
379-
* Deployment finish time in Unix timestamp (in seconds) or ISO 8601 format.
380-
*/
381-
finished?: number | string;
382-
383-
/**
384-
* Deployment duration (in seconds). Can be used instead of started and finished.
385-
*/
386-
time?: number;
387-
388-
/**
389-
* Human-readable name for the deployment.
390-
*/
391-
name?: string;
392-
393-
/**
394-
* URL that points to the deployment.
395-
*/
396-
url?: string;
397-
};
369+
*
370+
* Set to `false` to disable automatic deployment detection and creation.
371+
*/
372+
deploy?:
373+
| false
374+
| {
375+
/**
376+
* Environment for this release. Values that make sense here would
377+
* be `production` or `staging`.
378+
*/
379+
env: string;
380+
381+
/**
382+
* Deployment start time in Unix timestamp (in seconds) or ISO 8601 format.
383+
*/
384+
started?: number | string;
385+
386+
/**
387+
* Deployment finish time in Unix timestamp (in seconds) or ISO 8601 format.
388+
*/
389+
finished?: number | string;
390+
391+
/**
392+
* Deployment duration (in seconds). Can be used instead of started and finished.
393+
*/
394+
time?: number;
395+
396+
/**
397+
* Human-readable name for the deployment.
398+
*/
399+
name?: string;
400+
401+
/**
402+
* URL that points to the deployment.
403+
*/
404+
url?: string;
405+
};
398406
}
399407

400408
interface BundleSizeOptimizationsOptions {

packages/react-router/.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = {
77
{
88
files: ['vite.config.ts'],
99
parserOptions: {
10-
project: ['tsconfig.test.json'],
10+
project: ['tsconfig.vite.json'],
1111
},
1212
},
1313
],

packages/react-router/src/vite/buildEnd/handleOnBuildEnd.ts

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { rm } from 'node:fs/promises';
22
import type { Config } from '@react-router/dev/config';
33
import SentryCli from '@sentry/cli';
4+
import type { SentryVitePluginOptions } from '@sentry/vite-plugin';
45
import { glob } from 'glob';
56
import type { SentryReactRouterBuildOptions } from '../types';
67

@@ -23,17 +24,31 @@ function getSentryConfig(viteConfig: unknown): SentryReactRouterBuildOptions {
2324
export const sentryOnBuildEnd: BuildEndHook = async ({ reactRouterConfig, viteConfig }) => {
2425
const sentryConfig = getSentryConfig(viteConfig);
2526

27+
// todo(v11): Remove deprecated sourceMapsUploadOptions support (no need for spread/pick anymore)
28+
const {
29+
sourceMapsUploadOptions, // extract to exclude from rest config
30+
...sentryConfigWithoutDeprecatedSourceMapOption
31+
} = sentryConfig;
32+
2633
const {
2734
authToken,
2835
org,
2936
project,
3037
release,
31-
sourceMapsUploadOptions = { enabled: true },
38+
sourcemaps = { disable: false },
3239
debug = false,
33-
unstable_sentryVitePluginOptions,
34-
}: SentryReactRouterBuildOptions = {
40+
}: Omit<SentryReactRouterBuildOptions, 'sourcemaps' | 'sourceMapsUploadOptions'> &
41+
// Pick 'sourcemaps' from Vite plugin options as the types allow more (e.g. Promise values for `deleteFilesAfterUpload`)
42+
Pick<SentryVitePluginOptions, 'sourcemaps'> = {
3543
...sentryConfig.unstable_sentryVitePluginOptions,
36-
...sentryConfig,
44+
...sentryConfigWithoutDeprecatedSourceMapOption, // spread in the config without the deprecated sourceMapsUploadOptions
45+
sourcemaps: {
46+
...sentryConfig.unstable_sentryVitePluginOptions?.sourcemaps,
47+
...sentryConfig.sourcemaps,
48+
...sourceMapsUploadOptions,
49+
// eslint-disable-next-line deprecation/deprecation
50+
disable: sourceMapsUploadOptions?.enabled === false ? true : sentryConfig.sourcemaps?.disable,
51+
},
3752
release: {
3853
...sentryConfig.unstable_sentryVitePluginOptions?.release,
3954
...sentryConfig.release,
@@ -44,8 +59,9 @@ export const sentryOnBuildEnd: BuildEndHook = async ({ reactRouterConfig, viteCo
4459
authToken,
4560
org,
4661
project,
47-
...unstable_sentryVitePluginOptions,
62+
...sentryConfig.unstable_sentryVitePluginOptions,
4863
});
64+
4965
// check if release should be created
5066
if (release?.name) {
5167
try {
@@ -56,7 +72,7 @@ export const sentryOnBuildEnd: BuildEndHook = async ({ reactRouterConfig, viteCo
5672
}
5773
}
5874

59-
if (sourceMapsUploadOptions?.enabled ?? (true && viteConfig.build.sourcemap !== false)) {
75+
if (!sourcemaps?.disable && viteConfig.build.sourcemap !== false) {
6076
// inject debugIds
6177
try {
6278
await cliInstance.execute(
@@ -84,9 +100,10 @@ export const sentryOnBuildEnd: BuildEndHook = async ({ reactRouterConfig, viteCo
84100
}
85101
}
86102
// delete sourcemaps after upload
87-
let updatedFilesToDeleteAfterUpload = sourceMapsUploadOptions?.filesToDeleteAfterUpload;
103+
let updatedFilesToDeleteAfterUpload = await sourcemaps?.filesToDeleteAfterUpload;
104+
88105
// set a default value no option was set
89-
if (typeof sourceMapsUploadOptions?.filesToDeleteAfterUpload === 'undefined') {
106+
if (typeof updatedFilesToDeleteAfterUpload === 'undefined') {
90107
updatedFilesToDeleteAfterUpload = [`${reactRouterConfig.buildDirectory}/**/*.map`];
91108
debug &&
92109
// eslint-disable-next-line no-console

packages/react-router/src/vite/plugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ import type { SentryReactRouterBuildOptions } from './types';
1414
*/
1515
export async function sentryReactRouter(
1616
options: SentryReactRouterBuildOptions = {},
17-
config: ConfigEnv,
17+
viteConfig: ConfigEnv,
1818
): Promise<Plugin[]> {
1919
const plugins: Plugin[] = [];
2020

2121
plugins.push(makeConfigInjectorPlugin(options));
2222

23-
if (process.env.NODE_ENV !== 'development' && config.command === 'build' && config.mode !== 'development') {
23+
if (process.env.NODE_ENV !== 'development' && viteConfig.command === 'build' && viteConfig.mode !== 'development') {
2424
plugins.push(makeEnableSourceMapsPlugin(options));
2525
plugins.push(...(await makeCustomSentryVitePlugins(options)));
2626
}
Lines changed: 29 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { BuildTimeOptionsBase, UnstableVitePluginOptions } from '@sentry/core';
12
import type { SentryVitePluginOptions } from '@sentry/vite-plugin';
23

34
type SourceMapsOptions = {
@@ -6,6 +7,7 @@ type SourceMapsOptions = {
67
* automatically generate and upload source maps to Sentry during a production build.
78
*
89
* @default true
10+
* @deprecated Use `sourcemaps.disable` option instead of `sourceMapsUploadOptions.enabled`.
911
*/
1012
enabled?: boolean;
1113

@@ -16,14 +18,19 @@ type SourceMapsOptions = {
1618
* @default [] - By default no files are deleted.
1719
*
1820
* The globbing patterns follow the implementation of the glob package. (https://www.npmjs.com/package/glob)
21+
*
22+
* @deprecated Use `sourcemaps.filesToDeleteAfterUpload` option instead of `sourceMapsUploadOptions.filesToDeleteAfterUpload`.
1923
*/
2024
filesToDeleteAfterUpload?: string | Array<string>;
2125

2226
/**
2327
* Options related to managing the Sentry releases for a build.
2428
*
2529
* More info: https://docs.sentry.io/product/releases/
30+
*
31+
* @deprecated Use the `release` option at the root of `SentryVitePluginOptions` instead.
2632
*/
33+
// todo(v11): Remove this option (currently it's not in use either, but it's kept to not cause a breaking change)
2734
release?: {
2835
/**
2936
* Unique identifier for the release you want to create.
@@ -40,136 +47,31 @@ type SourceMapsOptions = {
4047
};
4148
};
4249

43-
type BundleSizeOptimizationOptions = {
44-
/**
45-
* If set to `true`, the plugin will attempt to tree-shake (remove) any debugging code within the Sentry SDK.
46-
* Note that the success of this depends on tree shaking being enabled in your build tooling.
47-
*
48-
* Setting this option to `true` will disable features like the SDK's `debug` option.
49-
*/
50-
excludeDebugStatements?: boolean;
51-
52-
/**
53-
* If set to true, the plugin will try to tree-shake tracing statements out.
54-
* Note that the success of this depends on tree shaking generally being enabled in your build.
55-
* Attention: DO NOT enable this when you're using any performance monitoring-related SDK features (e.g. Sentry.startSpan()).
56-
*/
57-
excludeTracing?: boolean;
58-
59-
/**
60-
* If set to `true`, the plugin will attempt to tree-shake (remove) code related to the Sentry SDK's Session Replay Shadow DOM recording functionality.
61-
* Note that the success of this depends on tree shaking being enabled in your build tooling.
62-
*
63-
* This option is safe to be used when you do not want to capture any Shadow DOM activity via Sentry Session Replay.
64-
*/
65-
excludeReplayShadowDom?: boolean;
66-
67-
/**
68-
* If set to `true`, the plugin will attempt to tree-shake (remove) code related to the Sentry SDK's Session Replay `iframe` recording functionality.
69-
* Note that the success of this depends on tree shaking being enabled in your build tooling.
70-
*
71-
* You can safely do this when you do not want to capture any `iframe` activity via Sentry Session Replay.
72-
*/
73-
excludeReplayIframe?: boolean;
74-
75-
/**
76-
* If set to `true`, the plugin will attempt to tree-shake (remove) code related to the Sentry SDK's Session Replay's Compression Web Worker.
77-
* Note that the success of this depends on tree shaking being enabled in your build tooling.
78-
*
79-
* **Notice:** You should only do use this option if you manually host a compression worker and configure it in your Sentry Session Replay integration config via the `workerUrl` option.
80-
*/
81-
excludeReplayWorker?: boolean;
82-
};
83-
84-
export type SentryReactRouterBuildOptions = {
85-
/**
86-
* Options for configuring the Sentry release.
87-
*/
88-
release?: {
89-
/**
90-
* The name of the release to create in Sentry
91-
*/
92-
name?: string;
93-
};
94-
95-
/**
96-
* The auth token to use when uploading source maps to Sentry.
97-
*
98-
* Instead of specifying this option, you can also set the `SENTRY_AUTH_TOKEN` environment variable.
99-
*
100-
* To create an auth token, follow this guide:
101-
* @see https://docs.sentry.io/product/accounts/auth-tokens/#organization-auth-tokens
102-
*/
103-
authToken?: string;
104-
105-
/**
106-
* The organization slug of your Sentry organization.
107-
* Instead of specifying this option, you can also set the `SENTRY_ORG` environment variable.
108-
*/
109-
org?: string;
110-
111-
/**
112-
* The project slug of your Sentry project.
113-
* Instead of specifying this option, you can also set the `SENTRY_PROJECT` environment variable.
114-
*/
115-
project?: string;
116-
117-
/**
118-
* Options for the Sentry Vite plugin to customize bundle size optimizations.
119-
*/
120-
bundleSizeOptimizations?: BundleSizeOptimizationOptions;
121-
122-
/**
123-
* If this flag is `true`, Sentry will log debug information during build time.
124-
* @default false.
125-
*/
126-
debug?: boolean;
127-
128-
/**
129-
* Options related to react component name annotations.
130-
* Disabled by default, unless a value is set for this option.
131-
* When enabled, your app's DOM will automatically be annotated during build-time with their respective component names.
132-
* This will unlock the capability to search for Replays in Sentry by component name, as well as see component names in breadcrumbs and performance monitoring.
133-
* Please note that this feature is not currently supported by the esbuild bundler plugins, and will only annotate React components
134-
*/
135-
reactComponentAnnotation?: {
50+
export type SentryReactRouterBuildOptions = BuildTimeOptionsBase &
51+
UnstableVitePluginOptions<Partial<SentryVitePluginOptions>> & {
13652
/**
137-
* Whether the component name annotate plugin should be enabled or not.
53+
* Options related to react component name annotations.
54+
* Disabled by default, unless a value is set for this option.
55+
* When enabled, your app's DOM will automatically be annotated during build-time with their respective component names.
56+
* This will unlock the capability to search for Replays in Sentry by component name, as well as see component names in breadcrumbs and performance monitoring.
57+
* Please note that this feature is not currently supported by the esbuild bundler plugins, and will only annotate React components
13858
*/
139-
enabled?: boolean;
59+
reactComponentAnnotation?: {
60+
/**
61+
* Whether the component name annotate plugin should be enabled or not.
62+
*/
63+
enabled?: boolean;
64+
65+
/**
66+
* A list of strings representing the names of components to ignore. The plugin will not apply `data-sentry` annotations on the DOM element for these components.
67+
*/
68+
ignoredComponents?: string[];
69+
};
14070

14171
/**
142-
* A list of strings representing the names of components to ignore. The plugin will not apply `data-sentry` annotations on the DOM element for these components.
72+
* Options for the Sentry Vite plugin to customize the source maps upload process.
73+
*
14374
*/
144-
ignoredComponents?: string[];
75+
sourceMapsUploadOptions?: SourceMapsOptions;
76+
// todo(v11): Remove this option (all options already exist in BuildTimeOptionsBase)
14577
};
146-
147-
/**
148-
* Options for the Sentry Vite plugin to customize the source maps upload process.
149-
*
150-
*/
151-
sourceMapsUploadOptions?: SourceMapsOptions;
152-
153-
/**
154-
* If this flag is `true`, the Sentry plugin will collect some telemetry data and send it to Sentry.
155-
* It will not collect any sensitive or user-specific data.
156-
*
157-
* @default true
158-
*/
159-
telemetry?: boolean;
160-
161-
/**
162-
* Options to further customize the Sentry Vite Plugin (@sentry/vite-plugin) behavior directly.
163-
* Options specified in this object take precedence over the options specified in
164-
* the `sourcemaps` and `release` objects.
165-
*
166-
* @see https://www.npmjs.com/package/@sentry/vite-plugin/v/2.22.2#options which lists all available options.
167-
*
168-
* Warning: Options within this object are subject to change at any time.
169-
* We DO NOT guarantee semantic versioning for these options, meaning breaking
170-
* changes can occur at any time within a major SDK version.
171-
*
172-
* Furthermore, some options are untested with SvelteKit specifically. Use with caution.
173-
*/
174-
unstable_sentryVitePluginOptions?: Partial<SentryVitePluginOptions>;
175-
};

packages/react-router/test/client/tracingIntegration.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ describe('reactRouterTracingIntegration', () => {
1717

1818
it('calls instrumentHydratedRouter and browserTracingIntegrationInstance.afterAllSetup in afterAllSetup', () => {
1919
const browserTracingSpy = vi.spyOn(sentryBrowser, 'browserTracingIntegration').mockImplementation(() => ({
20+
setup: vi.fn(),
2021
afterAllSetup: vi.fn(),
2122
name: 'BrowserTracing',
2223
}));

0 commit comments

Comments
 (0)