Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2c6e710

Browse files
authored
feat(react-router): Align options with shared build time options type (#18014)
closes #17066 Also updates the shared `BuildTimeOptionsBase` type a bit to align with the latest changes.
1 parent fd26569 commit 2c6e710

File tree

13 files changed

+299
-220
lines changed

13 files changed

+299
-220
lines changed

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

Lines changed: 91 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,37 @@ interface SourceMapsOptions {
243243
filesToDeleteAfterUpload?: string | Array<string>;
244244
}
245245

246+
type AutoSetCommitsOptions = {
247+
/**
248+
* Automatically sets `commit` and `previousCommit`. Sets `commit` to `HEAD`
249+
* and `previousCommit` as described in the option's documentation.
250+
*
251+
* If you set this to `true`, manually specified `commit` and `previousCommit`
252+
* options will be overridden. It is best to not specify them at all if you
253+
* set this option to `true`.
254+
*/
255+
auto: true;
256+
repo?: undefined;
257+
commit?: undefined;
258+
};
259+
260+
type ManualSetCommitsOptions = {
261+
auto?: false | undefined;
262+
/**
263+
* The full repo name as defined in Sentry.
264+
*
265+
* Required if the `auto` option is not set to `true`.
266+
*/
267+
repo: string;
268+
269+
/**
270+
* The current (last) commit in the release.
271+
*
272+
* Required if the `auto` option is not set to `true`.
273+
*/
274+
commit: string;
275+
};
276+
246277
interface ReleaseOptions {
247278
/**
248279
* Unique identifier for the release you want to create.
@@ -299,101 +330,81 @@ interface ReleaseOptions {
299330

300331
/**
301332
* Configuration for associating the release with its commits in Sentry.
333+
*
334+
* Set to `false` to disable commit association.
335+
*
336+
* @default { auto: true }
302337
*/
303-
setCommits?: (
304-
| {
338+
setCommits?:
339+
| false
340+
| ((AutoSetCommitsOptions | ManualSetCommitsOptions) & {
305341
/**
306-
* Automatically sets `commit` and `previousCommit`. Sets `commit` to `HEAD`
307-
* and `previousCommit` as described in the option's documentation.
342+
* The commit before the beginning of this release (in other words,
343+
* the last commit of the previous release).
344+
*
345+
* Defaults to the last commit of the previous release in Sentry.
308346
*
309-
* If you set this to `true`, manually specified `commit` and `previousCommit`
310-
* options will be overridden. It is best to not specify them at all if you
311-
* set this option to `true`.
347+
* If there was no previous release, the last 10 commits will be used.
312348
*/
313-
auto: true;
314-
repo?: undefined;
315-
commit?: undefined;
316-
}
317-
| {
318-
auto?: false | undefined;
349+
previousCommit?: string;
350+
319351
/**
320-
* The full repo name as defined in Sentry.
352+
* If the flag is to `true` and the previous release commit was not found
353+
* in the repository, the plugin creates a release with the default commits
354+
* count instead of failing the command.
321355
*
322-
* Required if the `auto` option is not set to `true`.
356+
* @default false
323357
*/
324-
repo: string;
358+
ignoreMissing?: boolean;
325359

326360
/**
327-
* The current (last) commit in the release.
361+
* If this flag is set, the setCommits step will not fail and just exit
362+
* silently if no new commits for a given release have been found.
328363
*
329-
* Required if the `auto` option is not set to `true`.
364+
* @default false
330365
*/
331-
commit: string;
332-
}
333-
) & {
334-
/**
335-
* The commit before the beginning of this release (in other words,
336-
* the last commit of the previous release).
337-
*
338-
* Defaults to the last commit of the previous release in Sentry.
339-
*
340-
* If there was no previous release, the last 10 commits will be used.
341-
*/
342-
previousCommit?: string;
343-
344-
/**
345-
* If the flag is to `true` and the previous release commit was not found
346-
* in the repository, the plugin creates a release with the default commits
347-
* count instead of failing the command.
348-
*
349-
* @default false
350-
*/
351-
ignoreMissing?: boolean;
352-
353-
/**
354-
* If this flag is set, the setCommits step will not fail and just exit
355-
* silently if no new commits for a given release have been found.
356-
*
357-
* @default false
358-
*/
359-
ignoreEmpty?: boolean;
360-
};
366+
ignoreEmpty?: boolean;
367+
});
361368

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

399410
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
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /