|
1 | 1 | import { sentryVitePlugin } from '@sentry/bundler-plugins/vite'; |
| 2 | +import { warnOnRemovedBuildOptions } from '@sentry/core'; |
2 | 3 | import { type Plugin } from 'vite'; |
3 | 4 | import type { SentryReactRouterBuildOptions } from './types'; |
4 | 5 |
|
5 | 6 | /** |
6 | 7 | * Create a custom subset of sentry's vite plugins |
7 | 8 | */ |
8 | 9 | export async function makeCustomSentryVitePlugins(options: SentryReactRouterBuildOptions): Promise<Plugin[]> { |
| 10 | + warnOnRemovedBuildOptions(options, ['unstable_sentryVitePluginOptions']); |
| 11 | + |
9 | 12 | const { |
10 | 13 | debug, |
11 | | - unstable_sentryVitePluginOptions, |
12 | 14 | bundleSizeOptimizations, |
13 | 15 | applicationKey, |
14 | 16 | authToken, |
| 17 | + moduleMetadata, |
15 | 18 | org, |
16 | 19 | project, |
17 | 20 | telemetry, |
18 | 21 | reactComponentAnnotation, |
19 | 22 | release, |
20 | 23 | } = options; |
21 | 24 |
|
22 | | - const unstableSourcemapsDisable = unstable_sentryVitePluginOptions?.sourcemaps?.disable; |
23 | | - |
24 | | - // Anything other than `true` would have the Vite plugin inject debug IDs on top of the |
25 | | - // ones `sentryOnBuildEnd` injects, which breaks source map resolution. The value still |
26 | | - // applies to the buildEnd hook - only the Vite plugin ignores it. |
27 | | - if (unstableSourcemapsDisable !== undefined && unstableSourcemapsDisable !== true) { |
28 | | - // eslint-disable-next-line no-console |
29 | | - console.warn( |
30 | | - `[Sentry] \`unstable_sentryVitePluginOptions.sourcemaps.disable: ${JSON.stringify( |
31 | | - unstableSourcemapsDisable, |
32 | | - )}\` does not apply to the Vite plugin. Debug ID injection and source map upload are handled by the \`sentryOnBuildEnd\` hook for React Router, so letting the Vite plugin do it as well would inject a second debug ID per chunk. The option still applies to \`sentryOnBuildEnd\`.`, |
33 | | - ); |
34 | | - } |
35 | | - |
36 | 25 | const sentryVitePlugins = sentryVitePlugin({ |
37 | 26 | applicationKey, |
38 | 27 | authToken: authToken ?? process.env.SENTRY_AUTH_TOKEN, |
39 | 28 | bundleSizeOptimizations, |
40 | 29 | debug: debug ?? false, |
| 30 | + moduleMetadata, |
41 | 31 | org: org ?? process.env.SENTRY_ORG, |
42 | 32 | project: project ?? process.env.SENTRY_PROJECT, |
| 33 | + reactComponentAnnotation, |
| 34 | + release, |
43 | 35 | telemetry: telemetry ?? true, |
44 | | - // Spread here so it can override the plain options above, but not the objects |
45 | | - // merged below - object spread replaces whole keys rather than deep-merging. |
46 | | - ...unstable_sentryVitePluginOptions, |
47 | 36 | _metaOptions: { |
48 | | - ...unstable_sentryVitePluginOptions?._metaOptions, |
49 | 37 | telemetry: { |
50 | | - ...unstable_sentryVitePluginOptions?._metaOptions?.telemetry, |
51 | 38 | metaFramework: 'react-router', |
52 | 39 | }, |
53 | 40 | }, |
54 | | - reactComponentAnnotation: { |
55 | | - // Only assign when set, as an explicit `undefined` would erase the unstable value |
56 | | - ...(reactComponentAnnotation?.enabled !== undefined && { enabled: reactComponentAnnotation.enabled }), |
57 | | - ...(reactComponentAnnotation?.ignoredComponents !== undefined && { |
58 | | - ignoredComponents: reactComponentAnnotation.ignoredComponents, |
59 | | - }), |
60 | | - ...unstable_sentryVitePluginOptions?.reactComponentAnnotation, |
61 | | - }, |
62 | | - release: { |
63 | | - ...unstable_sentryVitePluginOptions?.release, |
64 | | - ...release, |
65 | | - }, |
66 | 41 | sourcemaps: { |
67 | | - ...unstable_sentryVitePluginOptions?.sourcemaps, |
68 | | - // Injection and upload are handled in the buildEnd hook, so the Vite plugin must |
69 | | - // never do it too. This is deliberately not overridable - see the warning above. |
| 42 | + // Debug ID injection and upload are handled by the `sentryOnBuildEnd` hook, so the Vite plugin |
| 43 | + // must never do it as well - that would inject a second debug ID per chunk and break source |
| 44 | + // map resolution. |
70 | 45 | disable: true, |
71 | | - // The plugin deletes these in a `finally` block that runs regardless of `disable`, |
72 | | - // which would remove the maps before `sentryOnBuildEnd` gets to upload them. |
73 | | - // Deletion is handled there instead, from the same option. |
| 46 | + // The plugin deletes these in a `finally` block that runs regardless of `disable`, which would |
| 47 | + // remove the maps before `sentryOnBuildEnd` gets to upload them. Deletion happens there instead. |
74 | 48 | filesToDeleteAfterUpload: undefined, |
75 | 49 | }, |
76 | 50 | }) as Plugin[]; |
|
0 commit comments