1
- import { escapeStringForRegex , logger } from '@sentry/utils' ;
1
+ import { escapeStringForRegex , logger , stringMatchesSomePattern } from '@sentry/utils' ;
2
2
import * as fs from 'fs' ;
3
3
import * as path from 'path' ;
4
4
@@ -8,6 +8,7 @@ import { LoaderThis } from './types';
8
8
type LoaderOptions = {
9
9
pagesDir : string ;
10
10
pageExtensionRegex : string ;
11
+ excludeServerRoutes : Array < RegExp | string > ;
11
12
} ;
12
13
13
14
/**
@@ -17,7 +18,11 @@ type LoaderOptions = {
17
18
*/
18
19
export default async function proxyLoader ( this : LoaderThis < LoaderOptions > , userCode : string ) : Promise < string > {
19
20
// We know one or the other will be defined, depending on the version of webpack being used
20
- const { pagesDir, pageExtensionRegex } = 'getOptions' in this ? this . getOptions ( ) : this . query ;
21
+ const {
22
+ pagesDir,
23
+ pageExtensionRegex,
24
+ excludeServerRoutes = [ ] ,
25
+ } = 'getOptions' in this ? this . getOptions ( ) : this . query ;
21
26
22
27
// Get the parameterized route name from this page's filepath
23
28
const parameterizedRoute = path
@@ -34,6 +39,11 @@ export default async function proxyLoader(this: LoaderThis<LoaderOptions>, userC
34
39
// homepage), sub back in the root route
35
40
. replace ( / ^ $ / , '/' ) ;
36
41
42
+ // Skip explicitly-ignored pages
43
+ if ( stringMatchesSomePattern ( parameterizedRoute , excludeServerRoutes , true ) ) {
44
+ return userCode ;
45
+ }
46
+
37
47
// We don't want to wrap twice (or infinitely), so in the proxy we add this query string onto references to the
38
48
// wrapped file, so that we know that it's already been processed. (Adding this query string is also necessary to
39
49
// convince webpack that it's a different file than the one it's in the middle of loading now, so that the originals
0 commit comments