Skip to content

Commit 0a22a61

Browse files
authored
ref(nextjs): Remove redundant pagesDirectory variable in webpack config (#6044)
This removes the `pagesDirectory` variable in the nextjs SDK's `constructWebpackConfigFunction` function, as its computed value matches that of `pagesDir` a few lines above, which we read from nextjs config.
1 parent fe1a22c commit 0a22a61

File tree

3 files changed

+7
-11
lines changed

3 files changed

+7
-11
lines changed

packages/nextjs/src/config/webpack.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,21 +82,12 @@ export function constructWebpackConfigFunction(
8282
if (userSentryOptions.autoInstrumentServerFunctions !== false) {
8383
const pagesDir = newConfig.resolve?.alias?.['private-next-pages'] as string;
8484

85-
// Next.js allows users to have the `pages` folder inside a `src` folder, however "`src/pages` will be ignored
86-
// if `pages` is present in the root directory"
87-
// - https://nextjs.org/docs/advanced-features/src-directory
88-
const shouldIncludeSrcDirectory = !fs.existsSync(path.resolve(projectDir, 'pages'));
89-
const pagesDirectory = shouldIncludeSrcDirectory // We're intentionally not including slashes in the paths because we wanne let node do the path resolution for Windows
90-
? path.resolve(projectDir, 'src', 'pages')
91-
: path.resolve(projectDir, 'pages');
92-
9385
// Default page extensions per https://github.com/vercel/next.js/blob/f1dbc9260d48c7995f6c52f8fbcc65f08e627992/packages/next/server/config-shared.ts#L161
9486
const pageExtensions = userNextConfig.pageExtensions || ['tsx', 'ts', 'jsx', 'js'];
9587
const pageExtensionRegex = pageExtensions.map(escapeStringForRegex).join('|');
9688

9789
newConfig.module.rules.push({
98-
// Nextjs allows the `pages` folder to optionally live inside a `src` folder
99-
test: new RegExp(`^${escapeStringForRegex(pagesDirectory)}.*\\.(${pageExtensionRegex})$`),
90+
test: new RegExp(`^${escapeStringForRegex(pagesDir)}.*\\.(${pageExtensionRegex})$`),
10091
use: [
10192
{
10293
loader: path.resolve(__dirname, 'loaders/proxyLoader.js'),

packages/nextjs/test/config/fixtures.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export const serverWebpackConfig: WebpackConfigObject = {
5656
output: { filename: '[name].js', path: '/Users/Maisey/projects/squirrelChasingSimulator/.next' },
5757
target: 'node',
5858
context: '/Users/Maisey/projects/squirrelChasingSimulator',
59+
resolve: { alias: { 'private-next-pages': '/Users/Maisey/projects/squirrelChasingSimulator/pages' } },
5960
};
6061
export const clientWebpackConfig: WebpackConfigObject = {
6162
entry: () =>

packages/nextjs/test/config/webpack/constructWebpackConfig.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ describe('constructWebpackConfigFunction()', () => {
5050
it("doesn't set devtool if webpack plugin is disabled", () => {
5151
const finalNextConfig = materializeFinalNextConfig({
5252
...exportedNextConfig,
53-
webpack: () => ({ devtool: 'something-besides-source-map' } as any),
53+
webpack: () =>
54+
({
55+
...serverWebpackConfig,
56+
devtool: 'something-besides-source-map',
57+
} as any),
5458
sentry: { disableServerWebpackPlugin: true },
5559
});
5660
const finalWebpackConfig = finalNextConfig.webpack?.(serverWebpackConfig, serverBuildContext);

0 commit comments

Comments
 (0)