From 7c93961b2a3fc94a1c6d42fa9cef26cc57865810 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Tue, 16 Aug 2022 18:36:49 +0000 Subject: [PATCH] Remove unnecessary regex --- .../src/config/loaders/dataFetchersLoader.ts | 9 ++++----- packages/nextjs/src/config/webpack.ts | 14 +------------- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/packages/nextjs/src/config/loaders/dataFetchersLoader.ts b/packages/nextjs/src/config/loaders/dataFetchersLoader.ts index 71cc6d789858..4c5688491ae1 100644 --- a/packages/nextjs/src/config/loaders/dataFetchersLoader.ts +++ b/packages/nextjs/src/config/loaders/dataFetchersLoader.ts @@ -112,8 +112,7 @@ export default function wrapDataFetchersLoader(this: LoaderThis, } // We know one or the other will be defined, depending on the version of webpack being used - const { projectDir, pagesDir, underscoreAppRegex, underscoreDocumentRegex, underscoreErrorRegex } = - 'getOptions' in this ? this.getOptions() : this.query; + const { projectDir, pagesDir } = 'getOptions' in this ? this.getOptions() : this.query; // Get the parameterized route name from this page's filepath const parameterizedRouteName = path @@ -157,13 +156,13 @@ export default function wrapDataFetchersLoader(this: LoaderThis, import { default as _sentry_default } from "${this.resourcePath}?sentry-proxy-loader"; import { withSentryGetInitialProps } from "@sentry/nextjs";`; - if (this.resourcePath.match(underscoreAppRegex)) { + if (parameterizedRouteName === '/_app') { // getInitialProps signature is a bit different in _app.js so we need a different wrapper // Currently a no-op - } else if (this.resourcePath.match(underscoreErrorRegex)) { + } else if (parameterizedRouteName === '/_error') { // getInitialProps behaviour is a bit different in _error.js so we probably want different wrapper // Currently a no-op - } else if (this.resourcePath.match(underscoreDocumentRegex)) { + } else if (parameterizedRouteName === '/_document') { // getInitialProps signature is a bit different in _document.js so we need a different wrapper // Currently a no-op } else { diff --git a/packages/nextjs/src/config/webpack.ts b/packages/nextjs/src/config/webpack.ts index 7e576a9ce85b..93b79a1c7313 100644 --- a/packages/nextjs/src/config/webpack.ts +++ b/packages/nextjs/src/config/webpack.ts @@ -78,12 +78,6 @@ export function constructWebpackConfigFunction( ], }; - const underscoreAppRegex = new RegExp(`${escapeStringForRegex(projectDir)}(/src)?/pages/_app\\.(jsx?|tsx?)`); - const underscoreErrorRegex = new RegExp(`${escapeStringForRegex(projectDir)}(/src)?/pages/_error\\.(jsx?|tsx?)`); - const underscoreDocumentRegex = new RegExp( - `${escapeStringForRegex(projectDir)}(/src)?/pages/_document\\.(jsx?|tsx?)`, - ); - if (userSentryOptions.experiments?.autoWrapDataFetchers) { const pagesDir = newConfig.resolve?.alias?.['private-next-pages'] as string; @@ -93,13 +87,7 @@ export function constructWebpackConfigFunction( use: [ { loader: path.resolve(__dirname, 'loaders/dataFetchersLoader.js'), - options: { - projectDir, - pagesDir, - underscoreAppRegex, - underscoreErrorRegex, - underscoreDocumentRegex, - }, + options: { projectDir, pagesDir }, }, ], });