@@ -98,12 +98,84 @@ function generateRandomTunnelRoute(): string {
9898 return `/${ randomString } ` ;
9999}
100100
101+ /**
102+ * Migrates deprecated top-level webpack options to the new `webpack.*` path for backward compatibility.
103+ * The new path takes precedence over deprecated options. This mutates the userSentryOptions object.
104+ */
105+ function migrateDeprecatedWebpackOptions ( userSentryOptions : SentryBuildOptions ) : void {
106+ // Initialize webpack options if not present
107+ userSentryOptions . webpack = userSentryOptions . webpack || { } ;
108+
109+ const webpack = userSentryOptions . webpack ;
110+
111+ const withDeprecatedFallback = < T > ( newValue : T | undefined , deprecatedValue : T | undefined ) : T | undefined => {
112+ return newValue ?? deprecatedValue ;
113+ } ;
114+
115+ /* eslint-disable deprecation/deprecation */
116+ // Migrate each deprecated option to the new path, but only if the new path isn't already set
117+ webpack . autoInstrumentServerFunctions = withDeprecatedFallback (
118+ webpack . autoInstrumentServerFunctions ,
119+ userSentryOptions . autoInstrumentServerFunctions ,
120+ ) ;
121+
122+ webpack . autoInstrumentMiddleware = withDeprecatedFallback (
123+ webpack . autoInstrumentMiddleware ,
124+ userSentryOptions . autoInstrumentMiddleware ,
125+ ) ;
126+
127+ webpack . autoInstrumentAppDirectory = withDeprecatedFallback (
128+ webpack . autoInstrumentAppDirectory ,
129+ userSentryOptions . autoInstrumentAppDirectory ,
130+ ) ;
131+
132+ webpack . excludeServerRoutes = withDeprecatedFallback (
133+ webpack . excludeServerRoutes ,
134+ userSentryOptions . excludeServerRoutes ,
135+ ) ;
136+
137+ webpack . widenClientFileUpload = withDeprecatedFallback (
138+ webpack . widenClientFileUpload ,
139+ userSentryOptions . widenClientFileUpload ,
140+ ) ;
141+
142+ webpack . unstable_sentryWebpackPluginOptions = withDeprecatedFallback (
143+ webpack . unstable_sentryWebpackPluginOptions ,
144+ userSentryOptions . unstable_sentryWebpackPluginOptions ,
145+ ) ;
146+
147+ webpack . disableSentryConfig = withDeprecatedFallback (
148+ webpack . disableSentryConfig ,
149+ userSentryOptions . disableSentryWebpackConfig ,
150+ ) ;
151+
152+ // Handle treeshake.debugLogs specially since it's nested
153+ if ( userSentryOptions . disableLogger !== undefined ) {
154+ webpack . treeshake = webpack . treeshake || { } ;
155+ webpack . treeshake . debugLogs = withDeprecatedFallback ( webpack . treeshake . debugLogs , userSentryOptions . disableLogger ) ;
156+ }
157+
158+ webpack . automaticVercelMonitors = withDeprecatedFallback (
159+ webpack . automaticVercelMonitors ,
160+ userSentryOptions . automaticVercelMonitors ,
161+ ) ;
162+
163+ webpack . reactComponentAnnotation = withDeprecatedFallback (
164+ webpack . reactComponentAnnotation ,
165+ userSentryOptions . reactComponentAnnotation ,
166+ ) ;
167+ /* eslint-enable deprecation/deprecation */
168+ }
169+
101170// Modify the materialized object form of the user's next config by deleting the `sentry` property and wrapping the
102171// `webpack` property
103172function getFinalConfigObject (
104173 incomingUserNextConfigObject : NextConfigObject ,
105174 userSentryOptions : SentryBuildOptions ,
106175) : NextConfigObject {
176+ // Migrate deprecated webpack options to new webpack path for backward compatibility
177+ migrateDeprecatedWebpackOptions ( userSentryOptions ) ;
178+
107179 // Only determine a release name if release creation is not explicitly disabled
108180 // This prevents injection of Git commit hashes that break build determinism
109181 const shouldCreateRelease = userSentryOptions . release ?. create !== false ;
@@ -363,7 +435,7 @@ function getFinalConfigObject(
363435 ] ,
364436 } ,
365437 } ) ,
366- ...( isWebpack && ! userSentryOptions . disableSentryWebpackConfig
438+ ...( isWebpack && ! userSentryOptions . webpack ?. disableSentryConfig
367439 ? {
368440 webpack : constructWebpackConfigFunction ( {
369441 userNextConfig : incomingUserNextConfigObject ,
0 commit comments