@@ -21,18 +21,6 @@ export { SentryWebpackPlugin };
21
21
// TODO: merge default SentryWebpackPlugin include with their SentryWebpackPlugin include
22
22
// TODO: drop merged keys from override check? `includeDefaults` option?
23
23
24
- const defaultSentryWebpackPluginOptions = dropUndefinedKeys ( {
25
- url : process . env . SENTRY_URL ,
26
- org : process . env . SENTRY_ORG ,
27
- project : process . env . SENTRY_PROJECT ,
28
- authToken : process . env . SENTRY_AUTH_TOKEN ,
29
- configFile : 'sentry.properties' ,
30
- stripPrefix : [ 'webpack://_N_E/' ] ,
31
- urlPrefix : `~/_next` ,
32
- include : '.next/' ,
33
- ignore : [ '.next/cache' , 'server/ssr-module-cache.js' , 'static/*/_ssgManifest.js' , 'static/*/_buildManifest.js' ] ,
34
- } ) ;
35
-
36
24
/**
37
25
* Construct the function which will be used as the nextjs config's `webpack` value.
38
26
*
@@ -88,18 +76,11 @@ export function constructWebpackConfigFunction(
88
76
newConfig . devtool = 'source-map' ;
89
77
}
90
78
91
- checkWebpackPluginOverrides ( defaultSentryWebpackPluginOptions , userSentryWebpackPluginOptions ) ;
92
-
93
79
newConfig . plugins = newConfig . plugins || [ ] ;
94
80
newConfig . plugins . push (
95
81
// @ts -ignore Our types for the plugin are messed up somehow - TS wants this to be `SentryWebpackPlugin.default`,
96
82
// but that's not actually a thing
97
- new SentryWebpackPlugin ( {
98
- dryRun : buildContext . dev ,
99
- release : getSentryRelease ( buildContext . buildId ) ,
100
- ...defaultSentryWebpackPluginOptions ,
101
- ...userSentryWebpackPluginOptions ,
102
- } ) ,
83
+ new SentryWebpackPlugin ( getWebpackPluginOptions ( buildContext , userSentryWebpackPluginOptions ) ) ,
103
84
) ;
104
85
}
105
86
@@ -248,3 +229,46 @@ function checkWebpackPluginOverrides(
248
229
function shouldAddSentryToEntryPoint ( entryPointName : string ) : boolean {
249
230
return entryPointName === 'pages/_app' || entryPointName . includes ( 'pages/api' ) ;
250
231
}
232
+
233
+ /**
234
+ * Combine default and user-provided SentryWebpackPlugin options, accounting for whether we're building server files or
235
+ * client files.
236
+ *
237
+ * @param buildContext Nexjs-provided data about the current build
238
+ * @param userPluginOptions User-provided SentryWebpackPlugin options
239
+ * @returns Final set of combined options
240
+ */
241
+ function getWebpackPluginOptions (
242
+ buildContext : BuildContext ,
243
+ userPluginOptions : Partial < SentryWebpackPluginOptions > ,
244
+ ) : SentryWebpackPluginOptions {
245
+ const { isServer, dir : projectDir , buildId, dev : isDev } = buildContext ;
246
+
247
+ const hasSentryProperties = fs . existsSync ( path . resolve ( projectDir , 'sentry.properties' ) ) ;
248
+
249
+ const serverInclude = [
250
+ { paths : [ '.next/server/chunks/' ] , urlPrefix : '~/_next/server/chunks' } ,
251
+ { paths : [ '.next/server/pages/' ] , urlPrefix : '~/_next/server/pages' } ,
252
+ { paths : [ '.next/serverless/' ] , urlPrefix : '~/_next/serverless' } ,
253
+ ] ;
254
+ const clientInclude = [ { paths : [ '.next/static/chunks/pages' ] , urlPrefix : '~/_next/static/chunks/pages' } ] ;
255
+
256
+ const defaultPluginOptions = dropUndefinedKeys ( {
257
+ include : isServer ? serverInclude : clientInclude ,
258
+ ignore : [ ] ,
259
+ url : process . env . SENTRY_URL ,
260
+ org : process . env . SENTRY_ORG ,
261
+ project : process . env . SENTRY_PROJECT ,
262
+ authToken : process . env . SENTRY_AUTH_TOKEN ,
263
+ configFile : hasSentryProperties ? 'sentry.properties' : undefined ,
264
+ stripPrefix : [ 'webpack://_N_E/' ] ,
265
+ urlPrefix : `~/_next` ,
266
+ entries : shouldAddSentryToEntryPoint ,
267
+ release : getSentryRelease ( buildId ) ,
268
+ dryRun : isDev ,
269
+ } ) ;
270
+
271
+ checkWebpackPluginOverrides ( defaultPluginOptions , userPluginOptions ) ;
272
+
273
+ return { ...defaultPluginOptions , ...userPluginOptions } ;
274
+ }
0 commit comments