1
1
/* eslint-disable max-lines */
2
2
import { getSentryRelease } from '@sentry/node' ;
3
- import { arrayify , dropUndefinedKeys , escapeStringForRegex , logger } from '@sentry/utils' ;
3
+ import { arrayify , dropUndefinedKeys , escapeStringForRegex , logger , stringMatchesSomePattern } from '@sentry/utils' ;
4
4
import { default as SentryWebpackPlugin } from '@sentry/webpack-plugin' ;
5
5
import * as chalk from 'chalk' ;
6
6
import * as fs from 'fs' ;
@@ -139,7 +139,7 @@ export function constructWebpackConfigFunction(
139
139
// will call the callback which will call `f` which will call `x.y`... and on and on. Theoretically this could also
140
140
// be fixed by using `bind`, but this is way simpler.)
141
141
const origEntryProperty = newConfig . entry ;
142
- newConfig . entry = async ( ) => addSentryToEntryProperty ( origEntryProperty , buildContext ) ;
142
+ newConfig . entry = async ( ) => addSentryToEntryProperty ( origEntryProperty , buildContext , userSentryOptions ) ;
143
143
144
144
// Enable the Sentry plugin (which uploads source maps to Sentry when not in dev) by default
145
145
if ( shouldEnableWebpackPlugin ( buildContext , userSentryOptions ) ) {
@@ -252,6 +252,7 @@ function findTranspilationRules(rules: WebpackModuleRule[] | undefined, projectD
252
252
async function addSentryToEntryProperty (
253
253
currentEntryProperty : WebpackEntryProperty ,
254
254
buildContext : BuildContext ,
255
+ userSentryOptions : UserSentryOptions ,
255
256
) : Promise < EntryPropertyObject > {
256
257
// The `entry` entry in a webpack config can be a string, array of strings, object, or function. By default, nextjs
257
258
// sets it to an async function which returns the promise of an object of string arrays. Because we don't know whether
@@ -272,7 +273,7 @@ async function addSentryToEntryProperty(
272
273
273
274
// inject into all entry points which might contain user's code
274
275
for ( const entryPointName in newEntryProperty ) {
275
- if ( shouldAddSentryToEntryPoint ( entryPointName , isServer ) ) {
276
+ if ( shouldAddSentryToEntryPoint ( entryPointName , isServer , userSentryOptions . excludeServerRoutes ) ) {
276
277
addFilesToExistingEntryPoint ( newEntryProperty , entryPointName , filesToInject ) ;
277
278
}
278
279
}
@@ -381,13 +382,21 @@ function checkWebpackPluginOverrides(
381
382
*
382
383
* @param entryPointName The name of the entry point in question
383
384
* @param isServer Whether or not this function is being called in the context of a server build
385
+ * @param excludeServerRoutes A list of excluded serverside entrypoints provided by the user
384
386
* @returns `true` if sentry code should be injected, and `false` otherwise
385
387
*/
386
- function shouldAddSentryToEntryPoint ( entryPointName : string , isServer : boolean ) : boolean {
388
+ function shouldAddSentryToEntryPoint (
389
+ entryPointName : string ,
390
+ isServer : boolean ,
391
+ excludeServerRoutes : Array < string | RegExp > = [ ] ,
392
+ ) : boolean {
387
393
// On the server side, by default we inject the `Sentry.init()` code into every page (with a few exceptions).
388
394
if ( isServer ) {
389
395
const entryPointRoute = entryPointName . replace ( / ^ p a g e s / , '' ) ;
390
396
if (
397
+ // User-specified pages to skip. (Note: For ease of use, `excludeServerRoutes` is specified in terms of routes,
398
+ // which don't have the `pages` prefix.)
399
+ stringMatchesSomePattern ( entryPointRoute , excludeServerRoutes , true ) ||
391
400
// All non-API pages contain both of these components, and we don't want to inject more than once, so as long as
392
401
// we're doing the individual pages, it's fine to skip these. (Note: Even if a given user doesn't have either or
393
402
// both of these in their `pages/` folder, they'll exist as entrypoints because nextjs will supply default
0 commit comments