Skip to content

Commit

Permalink
Remove unnecessary regex
Browse files Browse the repository at this point in the history
  • Loading branch information
lforst committed Aug 17, 2022
1 parent 88b8d18 commit 7c93961
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 18 deletions.
9 changes: 4 additions & 5 deletions packages/nextjs/src/config/loaders/dataFetchersLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ export default function wrapDataFetchersLoader(this: LoaderThis<LoaderOptions>,
}

// 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
Expand Down Expand Up @@ -157,13 +156,13 @@ export default function wrapDataFetchersLoader(this: LoaderThis<LoaderOptions>,
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 {
Expand Down
14 changes: 1 addition & 13 deletions packages/nextjs/src/config/webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -93,13 +87,7 @@ export function constructWebpackConfigFunction(
use: [
{
loader: path.resolve(__dirname, 'loaders/dataFetchersLoader.js'),
options: {
projectDir,
pagesDir,
underscoreAppRegex,
underscoreErrorRegex,
underscoreDocumentRegex,
},
options: { projectDir, pagesDir },
},
],
});
Expand Down

0 comments on commit 7c93961

Please sign in to comment.