Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
171 changes: 91 additions & 80 deletions packages/core/src/build-time-plugins/buildTimeOptionsBase.ts
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes in this file are basically just a back-port of the changes in the bundler-plugin type.

getsentry/sentry-javascript-bundler-plugins@main/packages/bundler-plugin-core/src/types.ts

Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,37 @@ interface SourceMapsOptions {
filesToDeleteAfterUpload?: string | Array<string>;
}

type AutoSetCommitsOptions = {
/**
* Automatically sets `commit` and `previousCommit`. Sets `commit` to `HEAD`
* and `previousCommit` as described in the option's documentation.
*
* If you set this to `true`, manually specified `commit` and `previousCommit`
* options will be overridden. It is best to not specify them at all if you
* set this option to `true`.
*/
auto: true;
repo?: undefined;
commit?: undefined;
};

type ManualSetCommitsOptions = {
auto?: false | undefined;
/**
* The full repo name as defined in Sentry.
*
* Required if the `auto` option is not set to `true`.
*/
repo: string;

/**
* The current (last) commit in the release.
*
* Required if the `auto` option is not set to `true`.
*/
commit: string;
};

interface ReleaseOptions {
/**
* Unique identifier for the release you want to create.
Expand Down Expand Up @@ -299,101 +330,81 @@ interface ReleaseOptions {

/**
* Configuration for associating the release with its commits in Sentry.
*
* Set to `false` to disable commit association.
*
* @default { auto: true }
*/
setCommits?: (
| {
setCommits?:
| false
| ((AutoSetCommitsOptions | ManualSetCommitsOptions) & {
/**
* Automatically sets `commit` and `previousCommit`. Sets `commit` to `HEAD`
* and `previousCommit` as described in the option's documentation.
* The commit before the beginning of this release (in other words,
* the last commit of the previous release).
*
* Defaults to the last commit of the previous release in Sentry.
*
* If you set this to `true`, manually specified `commit` and `previousCommit`
* options will be overridden. It is best to not specify them at all if you
* set this option to `true`.
* If there was no previous release, the last 10 commits will be used.
*/
auto: true;
repo?: undefined;
commit?: undefined;
}
| {
auto?: false | undefined;
previousCommit?: string;

/**
* The full repo name as defined in Sentry.
* If the flag is to `true` and the previous release commit was not found
* in the repository, the plugin creates a release with the default commits
* count instead of failing the command.
*
* Required if the `auto` option is not set to `true`.
* @default false
*/
repo: string;
ignoreMissing?: boolean;

/**
* The current (last) commit in the release.
* If this flag is set, the setCommits step will not fail and just exit
* silently if no new commits for a given release have been found.
*
* Required if the `auto` option is not set to `true`.
* @default false
*/
commit: string;
}
) & {
/**
* The commit before the beginning of this release (in other words,
* the last commit of the previous release).
*
* Defaults to the last commit of the previous release in Sentry.
*
* If there was no previous release, the last 10 commits will be used.
*/
previousCommit?: string;

/**
* If the flag is to `true` and the previous release commit was not found
* in the repository, the plugin creates a release with the default commits
* count instead of failing the command.
*
* @default false
*/
ignoreMissing?: boolean;

/**
* If this flag is set, the setCommits step will not fail and just exit
* silently if no new commits for a given release have been found.
*
* @default false
*/
ignoreEmpty?: boolean;
};
ignoreEmpty?: boolean;
});

/**
* Configuration for adding deployment information to the release in Sentry.
*
* Set to `false` to disable automatic deployment detection and creation.
*/
deploy?: {
/**
* Environment for this release. Values that make sense here would
* be `production` or `staging`.
*/
env: string;

/**
* Deployment start time in Unix timestamp (in seconds) or ISO 8601 format.
*/
started?: number | string;

/**
* Deployment finish time in Unix timestamp (in seconds) or ISO 8601 format.
*/
finished?: number | string;

/**
* Deployment duration (in seconds). Can be used instead of started and finished.
*/
time?: number;

/**
* Human-readable name for the deployment.
*/
name?: string;

/**
* URL that points to the deployment.
*/
url?: string;
};
deploy?:
| false
| {
/**
* Environment for this release. Values that make sense here would
* be `production` or `staging`.
*/
env: string;

/**
* Deployment start time in Unix timestamp (in seconds) or ISO 8601 format.
*/
started?: number | string;

/**
* Deployment finish time in Unix timestamp (in seconds) or ISO 8601 format.
*/
finished?: number | string;

/**
* Deployment duration (in seconds). Can be used instead of started and finished.
*/
time?: number;

/**
* Human-readable name for the deployment.
*/
name?: string;

/**
* URL that points to the deployment.
*/
url?: string;
};
}

interface BundleSizeOptimizationsOptions {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-router/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = {
{
files: ['vite.config.ts'],
parserOptions: {
project: ['tsconfig.test.json'],
project: ['tsconfig.vite.json'],
},
},
],
Expand Down
33 changes: 25 additions & 8 deletions packages/react-router/src/vite/buildEnd/handleOnBuildEnd.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { rm } from 'node:fs/promises';
import type { Config } from '@react-router/dev/config';
import SentryCli from '@sentry/cli';
import type { SentryVitePluginOptions } from '@sentry/vite-plugin';
import { glob } from 'glob';
import type { SentryReactRouterBuildOptions } from '../types';

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

// todo(v11): Remove deprecated sourceMapsUploadOptions support (no need for spread/pick anymore)
const {
sourceMapsUploadOptions, // extract to exclude from rest config
...sentryConfigWithoutDeprecatedSourceMapOption
} = sentryConfig;

const {
authToken,
org,
project,
release,
sourceMapsUploadOptions = { enabled: true },
sourcemaps = { disable: false },
debug = false,
unstable_sentryVitePluginOptions,
}: SentryReactRouterBuildOptions = {
}: Omit<SentryReactRouterBuildOptions, 'sourcemaps' | 'sourceMapsUploadOptions'> &
// Pick 'sourcemaps' from Vite plugin options as the types allow more (e.g. Promise values for `deleteFilesAfterUpload`)
Pick<SentryVitePluginOptions, 'sourcemaps'> = {
...sentryConfig.unstable_sentryVitePluginOptions,
...sentryConfig,
...sentryConfigWithoutDeprecatedSourceMapOption, // spread in the config without the deprecated sourceMapsUploadOptions
sourcemaps: {
...sentryConfig.unstable_sentryVitePluginOptions?.sourcemaps,
...sentryConfig.sourcemaps,
...sourceMapsUploadOptions,
// eslint-disable-next-line deprecation/deprecation
disable: sourceMapsUploadOptions?.enabled === false ? true : sentryConfig.sourcemaps?.disable,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l: following would do the same and is a little shorter

Suggested change
disable: sourceMapsUploadOptions?.enabled === false ? true : sentryConfig.sourcemaps?.disable,
disable: sourceMapsUploadOptions?.enabled === false || sentryConfig.sourcemaps?.disable,

},
release: {
...sentryConfig.unstable_sentryVitePluginOptions?.release,
...sentryConfig.release,
Expand All @@ -44,8 +59,9 @@ export const sentryOnBuildEnd: BuildEndHook = async ({ reactRouterConfig, viteCo
authToken,
org,
project,
...unstable_sentryVitePluginOptions,
...sentryConfig.unstable_sentryVitePluginOptions,
});

// check if release should be created
if (release?.name) {
try {
Expand All @@ -56,7 +72,7 @@ export const sentryOnBuildEnd: BuildEndHook = async ({ reactRouterConfig, viteCo
}
}

if (sourceMapsUploadOptions?.enabled ?? (true && viteConfig.build.sourcemap !== false)) {
if (!sourcemaps?.disable && viteConfig.build.sourcemap !== false) {
// inject debugIds
try {
await cliInstance.execute(
Expand Down Expand Up @@ -84,9 +100,10 @@ export const sentryOnBuildEnd: BuildEndHook = async ({ reactRouterConfig, viteCo
}
}
// delete sourcemaps after upload
let updatedFilesToDeleteAfterUpload = sourceMapsUploadOptions?.filesToDeleteAfterUpload;
let updatedFilesToDeleteAfterUpload = await sourcemaps?.filesToDeleteAfterUpload;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

q: Why is this awaited?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this can be a Promise when coming from the unstable_... option: getsentry/sentry-javascript-bundler-plugins@4255012


// set a default value no option was set
if (typeof sourceMapsUploadOptions?.filesToDeleteAfterUpload === 'undefined') {
if (typeof updatedFilesToDeleteAfterUpload === 'undefined') {
updatedFilesToDeleteAfterUpload = [`${reactRouterConfig.buildDirectory}/**/*.map`];
debug &&
// eslint-disable-next-line no-console
Expand Down
4 changes: 2 additions & 2 deletions packages/react-router/src/vite/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import type { SentryReactRouterBuildOptions } from './types';
*/
export async function sentryReactRouter(
options: SentryReactRouterBuildOptions = {},
config: ConfigEnv,
viteConfig: ConfigEnv,
): Promise<Plugin[]> {
const plugins: Plugin[] = [];

plugins.push(makeConfigInjectorPlugin(options));

if (process.env.NODE_ENV !== 'development' && config.command === 'build' && config.mode !== 'development') {
if (process.env.NODE_ENV !== 'development' && viteConfig.command === 'build' && viteConfig.mode !== 'development') {
plugins.push(makeEnableSourceMapsPlugin(options));
plugins.push(...(await makeCustomSentryVitePlugins(options)));
}
Expand Down
Loading