Skip to content

Commit 7cc99cd

Browse files
committed
use vite subset
1 parent fc5bfe7 commit 7cc99cd

File tree

8 files changed

+101
-121
lines changed

8 files changed

+101
-121
lines changed

packages/react-router/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"@sentry/browser": "9.1.0",
3838
"@sentry/core": "9.1.0",
3939
"@sentry/node": "9.1.0",
40-
"@sentry/vite-plugin": "^3.1.2"
40+
"@sentry/vite-plugin": "^3.2.0"
4141
},
4242
"devDependencies": {
4343
"@react-router/node": "^7.1.5",
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { sentryVitePlugin } from '@sentry/vite-plugin';
2+
import { type Plugin } from 'vite';
3+
import type { SentryReactRouterPluginOptions } from './types';
4+
5+
/**
6+
* Create a custom subset of sentry's vite plugins
7+
*/
8+
export async function makeCustomSentryVitePlugins(options: SentryReactRouterPluginOptions): Promise<Plugin[]> {
9+
const {
10+
debug,
11+
sourceMapsUploadOptions,
12+
unstable_sentryVitePluginOptions,
13+
bundleSizeOptimizations,
14+
authToken,
15+
org,
16+
project,
17+
} = options;
18+
19+
const sentryVitePlugins = sentryVitePlugin({
20+
authToken: authToken ?? process.env.SENTRY_AUTH_TOKEN,
21+
bundleSizeOptimizations,
22+
debug: debug ?? false,
23+
org: org ?? process.env.SENTRY_ORG,
24+
project: project ?? process.env.SENTRY_PROJECT,
25+
telemetry: sourceMapsUploadOptions?.telemetry ?? true,
26+
_metaOptions: {
27+
telemetry: {
28+
metaFramework: 'react-router',
29+
},
30+
},
31+
32+
...unstable_sentryVitePluginOptions,
33+
}) as Plugin[];
34+
35+
// only use a subset of the plugins as all upload and file deletion tasks will be handled in the buildEnd hook
36+
return [
37+
...sentryVitePlugins.filter(plugin => {
38+
return [
39+
'sentry-telemetry-plugin',
40+
'sentry-vite-release-injection-plugin',
41+
'sentry-release-management-plugin',
42+
'sentry-vite-debug-id-injection-plugin',
43+
].includes(plugin.name);
44+
}),
45+
];
46+
}

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

Lines changed: 0 additions & 78 deletions
This file was deleted.

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { ConfigEnv } from 'vite';
22
import { type Plugin } from 'vite';
3-
import { makeSentryVitePlugins } from './makeSentryVitePlugin';
4-
import { makeEnableSourceMapsVitePlugins } from './sourceMaps';
3+
import { makeCustomSentryVitePlugins } from './makeCustomSentryVitePlugins';
4+
import { makeEnableSourceMapsVitePlugin } from './sourceMaps';
55
import type { SentryReactRouterPluginOptions } from './types';
66

77
/**
@@ -17,13 +17,9 @@ export async function sentryReactRouter(
1717
): Promise<Plugin[]> {
1818
const plugins: Plugin[] = [];
1919

20-
if (process.env.NODE_ENV !== 'development') {
21-
if (options.sourceMapsUploadOptions?.enabled ?? true) {
22-
if (config.command === 'build' && config.isSsrBuild && config.mode === 'production') {
23-
plugins.push(...makeEnableSourceMapsVitePlugins(options));
24-
plugins.push(...(await makeSentryVitePlugins(options)));
25-
}
26-
}
20+
if (process.env.NODE_ENV !== 'development' && config.command === 'build') {
21+
plugins.push(makeEnableSourceMapsVitePlugin(options));
22+
plugins.push(...(await makeCustomSentryVitePlugins(options)));
2723
}
2824

2925
return plugins;

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

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,21 @@ import type { SentryReactRouterPluginOptions } from './types';
55
/**
66
* A Sentry plugin for React Router to enable "hidden" source maps if they are unset.
77
*/
8-
export function makeEnableSourceMapsVitePlugins(options: SentryReactRouterPluginOptions): Plugin[] {
9-
return [
10-
{
11-
name: 'sentry-react-router-update-source-map-setting',
12-
apply: 'build',
13-
enforce: 'post',
14-
config(viteConfig) {
15-
return {
16-
...viteConfig,
17-
build: {
18-
...viteConfig.build,
19-
sourcemap: getUpdatedSourceMapSettings(viteConfig, options),
20-
},
21-
};
22-
},
8+
export function makeEnableSourceMapsVitePlugin(options: SentryReactRouterPluginOptions): Plugin {
9+
return {
10+
name: 'sentry-react-router-update-source-map-setting',
11+
apply: 'build',
12+
enforce: 'post',
13+
config(viteConfig) {
14+
return {
15+
...viteConfig,
16+
build: {
17+
...viteConfig.build,
18+
sourcemap: getUpdatedSourceMapSettings(viteConfig, options),
19+
},
20+
};
2321
},
24-
];
22+
};
2523
}
2624

2725
/** There are 3 ways to set up source map generation

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,31 @@ vi.spyOn(console, 'warn').mockImplementation(() => {
99
/* noop */
1010
});
1111

12-
function getSentryReactRouterVitePlugins(options?: Parameters<typeof sentryReactRouter>[0]): Plugin[] {
12+
async function getSentryReactRouterVitePlugins(options?: Parameters<typeof sentryReactRouter>[0]): Promise<Plugin[]> {
1313
return sentryReactRouter(
1414
{
1515
project: 'project',
1616
org: 'org',
1717
authToken: 'token',
1818
...options,
1919
},
20-
{},
20+
{
21+
command: 'build',
22+
mode: 'production',
23+
},
2124
);
2225
}
2326

2427
describe('sentryReactRouter()', () => {
25-
it('returns an array of vite plugins', () => {
26-
const plugins = getSentryReactRouterVitePlugins();
28+
it('returns an array of vite plugins', async () => {
29+
const plugins = await getSentryReactRouterVitePlugins();
30+
expect(plugins).toBeDefined();
2731
const names = plugins.map(plugin => plugin.name);
2832
expect(names).toEqual([
33+
'sentry-react-router-update-source-map-setting',
2934
'sentry-telemetry-plugin',
3035
'sentry-vite-release-injection-plugin',
31-
'sentry-release-management-plugin',
3236
'sentry-vite-debug-id-injection-plugin',
33-
'sentry-vite-debug-id-upload-plugin',
34-
'sentry-file-deletion-plugin',
35-
'sentry-react-router-update-source-map-setting',
3637
]);
3738
});
3839
});

packages/react-router/test/vite/sourceMaps.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { SentryVitePluginOptions } from '@sentry/vite-plugin';
22
import { beforeEach, describe, expect, it, vi } from 'vitest';
3-
import { getUpdatedSourceMapSettings, makeEnableSourceMapsVitePlugins } from '../../src/vite/sourceMaps';
3+
import { getUpdatedSourceMapSettings, makeEnableSourceMapsVitePlugin } from '../../src/vite/sourceMaps';
44

55
const mockedSentryVitePlugin = {
66
name: 'sentry-vite-debug-id-upload-plugin',
@@ -24,14 +24,12 @@ beforeEach(() => {
2424

2525
describe('makeEnableSourceMapsVitePlugin()', () => {
2626
it('returns a plugin to set `sourcemaps` to `true`', () => {
27-
const sourceMapPlugins = makeEnableSourceMapsVitePlugins({});
28-
const enableSourceMapPlugin = sourceMapPlugins[0];
27+
const enableSourceMapPlugin = makeEnableSourceMapsVitePlugin({});
2928

3029
expect(enableSourceMapPlugin?.name).toEqual('sentry-react-router-update-source-map-setting');
3130
expect(enableSourceMapPlugin?.apply).toEqual('build');
3231
expect(enableSourceMapPlugin?.enforce).toEqual('post');
3332
expect(enableSourceMapPlugin?.config).toEqual(expect.any(Function));
34-
expect(sourceMapPlugins).toHaveLength(1);
3533
});
3634
});
3735

yarn.lock

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6817,6 +6817,11 @@
68176817
resolved "https://registry.yarnpkg.com/@sentry/babel-plugin-component-annotate/-/babel-plugin-component-annotate-3.1.2.tgz#5497ca5adbe775955e96c566511a0bed3ab0a3ce"
68186818
integrity sha512-5h2WXRJ6swKA0TwxHHryC8M2QyOfS9QhTAL6ElPfkEYe9HhJieXmxsDpyspbqAa26ccnCUcmwE5vL34jAjt4sQ==
68196819

6820+
6821+
version "3.2.0"
6822+
resolved "https://registry.yarnpkg.com/@sentry/babel-plugin-component-annotate/-/babel-plugin-component-annotate-3.2.0.tgz#17c000cf6cc315bb620eddbd95c88dfb2471cfb9"
6823+
integrity sha512-Sg7nLRP1yiJYl/KdGGxYGbjvLq5rswyeB5yESgfWX34XUNZaFgmNvw4pU/QEKVeYgcPyOulgJ+y80ewujyffTA==
6824+
68206825
68216826
version "2.22.6"
68226827
resolved "https://registry.yarnpkg.com/@sentry/bundler-plugin-core/-/bundler-plugin-core-2.22.6.tgz#a1ea1fd43700a3ece9e7db016997e79a2782b87d"
@@ -6859,6 +6864,20 @@
68596864
magic-string "0.30.8"
68606865
unplugin "1.0.1"
68616866

6867+
6868+
version "3.2.0"
6869+
resolved "https://registry.yarnpkg.com/@sentry/bundler-plugin-core/-/bundler-plugin-core-3.2.0.tgz#023ec92530a35fbec7c7077b7a8be2e79f0f9dd5"
6870+
integrity sha512-Q/ogVylue3XaFawyIxzuiic+7Dp4w63eJtRtVH8VBebNURyJ/re4GVoP1QNGccE1R243tXY1y2GiwqiJkAONOg==
6871+
dependencies:
6872+
"@babel/core" "^7.18.5"
6873+
"@sentry/babel-plugin-component-annotate" "3.2.0"
6874+
"@sentry/cli" "2.41.1"
6875+
dotenv "^16.3.1"
6876+
find-up "^5.0.0"
6877+
glob "^9.3.2"
6878+
magic-string "0.30.8"
6879+
unplugin "1.0.1"
6880+
68626881
68636882
version "2.39.1"
68646883
resolved "https://registry.yarnpkg.com/@sentry/cli-darwin/-/cli-darwin-2.39.1.tgz#75c338a53834b4cf72f57599f4c72ffb36cf0781"
@@ -6983,12 +7002,12 @@
69837002
"@sentry/bundler-plugin-core" "2.22.6"
69847003
unplugin "1.0.1"
69857004

6986-
"@sentry/vite-plugin@^3.1.2":
6987-
version "3.1.2"
6988-
resolved "https://registry.yarnpkg.com/@sentry/vite-plugin/-/vite-plugin-3.1.2.tgz#c23e82bbe1e75844408f9cdbc3152d3b430938b3"
6989-
integrity sha512-a927sabQKviA4PAs9cM3rFONHiVdfEHHkypmub+hFwJNL0sbeg/8uht0WyqDT5WjVT5pbyvLaKLDjGdwrRBY6Q==
7005+
"@sentry/vite-plugin@^3.2.0":
7006+
version "3.2.0"
7007+
resolved "https://registry.yarnpkg.com/@sentry/vite-plugin/-/vite-plugin-3.2.0.tgz#0785b6e04e0aed8a4d6b57a433a2da11c14e6cd0"
7008+
integrity sha512-IVBoAzZmpoX9+mnmIMq2ndxlFPoWMuYSE5Mek5zOWpYh+GbPxvkrxvM+vg0HeLH4r5v9Tm0FWcEZDgDIZqtoSg==
69907009
dependencies:
6991-
"@sentry/bundler-plugin-core" "3.1.2"
7010+
"@sentry/bundler-plugin-core" "3.2.0"
69927011
unplugin "1.0.1"
69937012

69947013

0 commit comments

Comments
 (0)