From 340d830dc4d08a92f1113cd1333f96aa9b3b6a07 Mon Sep 17 00:00:00 2001 From: iker barriocanal <32816711+iker-barriocanal@users.noreply.github.com> Date: Wed, 22 Sep 2021 15:46:36 +0200 Subject: [PATCH 01/11] feat(nextjs): Sourcemaps for custom build directories --- packages/nextjs/src/config/webpack.ts | 28 +++++++++++++++++++++++++++ packages/nextjs/src/index.server.ts | 6 ++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/packages/nextjs/src/config/webpack.ts b/packages/nextjs/src/config/webpack.ts index 748a98e75d67..35c1dfefde3a 100644 --- a/packages/nextjs/src/config/webpack.ts +++ b/packages/nextjs/src/config/webpack.ts @@ -4,6 +4,7 @@ import * as SentryWebpackPlugin from '@sentry/webpack-plugin'; import * as fs from 'fs'; import * as path from 'path'; +import { PROJECT_BASEPATH } from '../index.server'; import { BuildContext, EntryPointValue, @@ -49,6 +50,13 @@ export function constructWebpackConfigFunction( newConfig = userNextConfig.webpack(newConfig, buildContext); } + // If a user defines a custom build directory (`distDir`), we must update the `RewriteFrames` integration so that + // the paths of the source maps match. + if (buildContext.isServer) { + // `distDir` is always defined. If the user hasn't defined a value, Next.js sets the default `.next` + updateRewriteFramesBasepath(buildContext.config.distDir as string); + } + // Tell webpack to inject user config files (containing the two `Sentry.init()` calls) into the appropriate output // bundles. Store a separate reference to the original `entry` value to avoid an infinite loop. (If we don't do // this, we'll have a statement of the form `x.y = () => f(x.y)`, where one of the things `f` does is call `x.y`. @@ -108,6 +116,26 @@ export function constructWebpackConfigFunction( return newWebpackFunction; } +// TODO: make sure in tests that `PROJECT_BASEPATH` var exists in `index.server.ts` +const BASEPATH_VARNAME = 'PROJECT_BASEPATH'; + +function updateRewriteFramesBasepath(distDir: string): void { + if (distDir === PROJECT_BASEPATH) return; + // esm + setProjectBasepath('./node_modules/@sentry/minimal/esm/index.js', 'var ', distDir); + // es5 + setProjectBasepath('./node_modules/@sentry/nextjs/dist/index.server.js', 'exports.', distDir); +} + +function setProjectBasepath(filePath: string, varPrefix: string, distDir: string): void { + const fileContents = fs.readFileSync(filePath).toString(); + const replacedContents = fileContents.replace( + new RegExp(`${varPrefix}${BASEPATH_VARNAME} = .*`), + `${varPrefix}${BASEPATH_VARNAME} = '${distDir}';`, + ); + fs.writeFileSync(filePath, replacedContents); +} + /** * Modify the webpack `entry` property so that the code in `sentry.server.config.js` and `sentry.client.config.js` is * included in the the necessary bundles. diff --git a/packages/nextjs/src/index.server.ts b/packages/nextjs/src/index.server.ts index e8c096b9baf5..1bb832fd17b7 100644 --- a/packages/nextjs/src/index.server.ts +++ b/packages/nextjs/src/index.server.ts @@ -47,11 +47,13 @@ function sdkAlreadyInitialized(): boolean { return !!hub.getClient(); } -const SOURCEMAP_FILENAME_REGEX = /^.*\/\.next\//; +export const PROJECT_BASEPATH = '.next'; +const projectBasepathRegexp = PROJECT_BASEPATH[0] === '.' ? `\\${PROJECT_BASEPATH}` : PROJECT_BASEPATH; +const sourcemapFilenameRegex = new RegExp(`^.*/${projectBasepathRegexp}/`); const defaultRewriteFramesIntegration = new RewriteFrames({ iteratee: frame => { - frame.filename = frame.filename?.replace(SOURCEMAP_FILENAME_REGEX, 'app:///_next/'); + frame.filename = frame.filename?.replace(sourcemapFilenameRegex, 'app:///_next/'); return frame; }, }); From c970f13c1b7211faa1ee8270d9829f59e548ae1b Mon Sep 17 00:00:00 2001 From: iker barriocanal <32816711+iker-barriocanal@users.noreply.github.com> Date: Wed, 22 Sep 2021 16:32:41 +0200 Subject: [PATCH 02/11] fix path --- packages/nextjs/src/config/webpack.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nextjs/src/config/webpack.ts b/packages/nextjs/src/config/webpack.ts index 35c1dfefde3a..499849fd1528 100644 --- a/packages/nextjs/src/config/webpack.ts +++ b/packages/nextjs/src/config/webpack.ts @@ -122,7 +122,7 @@ const BASEPATH_VARNAME = 'PROJECT_BASEPATH'; function updateRewriteFramesBasepath(distDir: string): void { if (distDir === PROJECT_BASEPATH) return; // esm - setProjectBasepath('./node_modules/@sentry/minimal/esm/index.js', 'var ', distDir); + setProjectBasepath('./node_modules/@sentry/minimal/esm/index.server.js', 'var ', distDir); // es5 setProjectBasepath('./node_modules/@sentry/nextjs/dist/index.server.js', 'exports.', distDir); } From e6b8c89d8dc6936e4cc247c4ea5039cd60b2ea6a Mon Sep 17 00:00:00 2001 From: iker barriocanal <32816711+iker-barriocanal@users.noreply.github.com> Date: Wed, 22 Sep 2021 16:40:20 +0200 Subject: [PATCH 03/11] fix path, again :D --- packages/nextjs/src/config/webpack.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nextjs/src/config/webpack.ts b/packages/nextjs/src/config/webpack.ts index 499849fd1528..cc22eb6c2984 100644 --- a/packages/nextjs/src/config/webpack.ts +++ b/packages/nextjs/src/config/webpack.ts @@ -122,7 +122,7 @@ const BASEPATH_VARNAME = 'PROJECT_BASEPATH'; function updateRewriteFramesBasepath(distDir: string): void { if (distDir === PROJECT_BASEPATH) return; // esm - setProjectBasepath('./node_modules/@sentry/minimal/esm/index.server.js', 'var ', distDir); + setProjectBasepath('./node_modules/@sentry/nextjs/esm/index.server.js', 'var ', distDir); // es5 setProjectBasepath('./node_modules/@sentry/nextjs/dist/index.server.js', 'exports.', distDir); } From 5a366c5150d2d5a8a2c123c43b509be98a9e3c97 Mon Sep 17 00:00:00 2001 From: iker barriocanal <32816711+iker-barriocanal@users.noreply.github.com> Date: Wed, 22 Sep 2021 17:23:35 +0200 Subject: [PATCH 04/11] Don't break tests in special scenarios --- packages/nextjs/src/config/webpack.ts | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/packages/nextjs/src/config/webpack.ts b/packages/nextjs/src/config/webpack.ts index cc22eb6c2984..06df73c30cdc 100644 --- a/packages/nextjs/src/config/webpack.ts +++ b/packages/nextjs/src/config/webpack.ts @@ -52,8 +52,9 @@ export function constructWebpackConfigFunction( // If a user defines a custom build directory (`distDir`), we must update the `RewriteFrames` integration so that // the paths of the source maps match. - if (buildContext.isServer) { - // `distDir` is always defined. If the user hasn't defined a value, Next.js sets the default `.next` + // `distDir` is always defined in real life: either the user defines a value, or Next.js sets the default `.next`. + // The check is for different environments, such as in tests. + if (buildContext.isServer && buildContext.config.distDir) { updateRewriteFramesBasepath(buildContext.config.distDir as string); } @@ -121,10 +122,20 @@ const BASEPATH_VARNAME = 'PROJECT_BASEPATH'; function updateRewriteFramesBasepath(distDir: string): void { if (distDir === PROJECT_BASEPATH) return; - // esm - setProjectBasepath('./node_modules/@sentry/nextjs/esm/index.server.js', 'var ', distDir); - // es5 - setProjectBasepath('./node_modules/@sentry/nextjs/dist/index.server.js', 'exports.', distDir); + try { + // esm + setProjectBasepath('./node_modules/@sentry/nextjs/esm/index.server.js', 'var ', distDir); + // es5 + setProjectBasepath('./node_modules/@sentry/nextjs/dist/index.server.js', 'exports.', distDir); + } catch (error) { + console.warn( + 'Sentry Logger [Warn]: ' + + `Could not set custom build directory \`${distDir}\`, required for correct display of source maps. `, + 'In order to set your own `RewriteFrames`, visit\n' + + 'https://docs.sentry.io/platforms/javascript/guides/nextjs/configuration/integrations/plugin/#rewriteframes\n', + error, + ); + } } function setProjectBasepath(filePath: string, varPrefix: string, distDir: string): void { From c0fbb21fc9077927dba4eb55951c5563a84238d6 Mon Sep 17 00:00:00 2001 From: iker barriocanal <32816711+iker-barriocanal@users.noreply.github.com> Date: Thu, 23 Sep 2021 13:01:07 +0200 Subject: [PATCH 05/11] Build paths from project root directory --- packages/nextjs/src/config/webpack.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/nextjs/src/config/webpack.ts b/packages/nextjs/src/config/webpack.ts index 06df73c30cdc..90cbdfff5fbc 100644 --- a/packages/nextjs/src/config/webpack.ts +++ b/packages/nextjs/src/config/webpack.ts @@ -55,7 +55,7 @@ export function constructWebpackConfigFunction( // `distDir` is always defined in real life: either the user defines a value, or Next.js sets the default `.next`. // The check is for different environments, such as in tests. if (buildContext.isServer && buildContext.config.distDir) { - updateRewriteFramesBasepath(buildContext.config.distDir as string); + updateRewriteFramesBasepath(buildContext.dir, buildContext.config.distDir as string); } // Tell webpack to inject user config files (containing the two `Sentry.init()` calls) into the appropriate output @@ -120,13 +120,21 @@ export function constructWebpackConfigFunction( // TODO: make sure in tests that `PROJECT_BASEPATH` var exists in `index.server.ts` const BASEPATH_VARNAME = 'PROJECT_BASEPATH'; -function updateRewriteFramesBasepath(distDir: string): void { +function updateRewriteFramesBasepath(projectRootDir: string, distDir: string): void { if (distDir === PROJECT_BASEPATH) return; try { // esm - setProjectBasepath('./node_modules/@sentry/nextjs/esm/index.server.js', 'var ', distDir); + setProjectBasepath( + path.join(projectRootDir, 'node_modules', '@sentry', 'nextjs', 'esm', 'index.server.js'), + 'var ', + distDir, + ); // es5 - setProjectBasepath('./node_modules/@sentry/nextjs/dist/index.server.js', 'exports.', distDir); + setProjectBasepath( + path.join(projectRootDir, 'node_modules', '@sentry', 'nextjs', 'dist', 'index.server.js'), + 'exports.', + distDir, + ); } catch (error) { console.warn( 'Sentry Logger [Warn]: ' + From b70837ac133de6bbd660a1a20d48deeffad28121 Mon Sep 17 00:00:00 2001 From: iker barriocanal <32816711+iker-barriocanal@users.noreply.github.com> Date: Thu, 23 Sep 2021 13:03:11 +0200 Subject: [PATCH 06/11] Add tests --- packages/nextjs/test/config.test.ts | 82 ++++++++++++++++++++++++++++- 1 file changed, 81 insertions(+), 1 deletion(-) diff --git a/packages/nextjs/test/config.test.ts b/packages/nextjs/test/config.test.ts index 8343a9053cc3..b0f3b3be4696 100644 --- a/packages/nextjs/test/config.test.ts +++ b/packages/nextjs/test/config.test.ts @@ -103,7 +103,7 @@ function getBuildContext( dev: false, buildId: 'sItStAyLiEdOwN', dir: '/Users/Maisey/projects/squirrelChasingSimulator', - config: { target: 'server', ...userNextConfig }, + config: { target: 'server', distDir: '.next', ...userNextConfig }, webpack: { version: webpackVersion }, isServer: buildTarget === 'server', }; @@ -324,6 +324,86 @@ describe('webpack config', () => { ); }); }); + + describe('RewriteFrames on base path change', () => { + const testProjectBasepath = path.join(__dirname, 'testDir'); + const testFilesPath = path.join(testProjectBasepath, 'node_modules', '@sentry', 'nextjs'); + + const moduleFormatExample = [ + { + name: 'esm', + dir: 'esm', + file: 'index.server.js', + contents: "var PROJECT_BASEPATH = '.next'", + }, + { + name: 'es5', + dir: 'dist', + file: 'index.server.js', + contents: "exports.PROJECT_BASEPATH = '.next'", + }, + ]; + + beforeAll(async () => { + await fs.promises.mkdir(testFilesPath, { recursive: true }); + moduleFormatExample.map(format => { + format.dir = path.join(testFilesPath, format.dir); + format.file = path.join(format.dir, format.file); + return fs.promises.mkdir(format.dir); + }); + }); + + afterAll(() => rimraf.sync(testProjectBasepath)); + + beforeEach(() => + moduleFormatExample.map( + // Using promises here make reading the contents of the files to be empty strings + format => fs.writeFileSync(format.file, format.contents), + ), + ); + + function addDistDirToBuildContext(buildCtxt: BuildContext, distDir: string): BuildContext { + const config = { ...buildCtxt.config, distDir }; + const res = { + ...buildCtxt, + config, + }; + return res; + } + + test.each([ + ['client without setting a dir', clientBuildContext, null], + ['client setting a normal dir', addDistDirToBuildContext(clientBuildContext, 'test'), null], + ['server without setting a dir', serverBuildContext, null], + [ + 'server setting normal dir', + addDistDirToBuildContext(serverBuildContext, 'test'), + { + esm: "var PROJECT_BASEPATH = 'test';", + es5: "exports.PROJECT_BASEPATH = 'test';", + }, + ], + [ + 'server setting hidden dir', + addDistDirToBuildContext(serverBuildContext, '.test'), + { + esm: "var PROJECT_BASEPATH = '.test';", + es5: "exports.PROJECT_BASEPATH = '.test';", + }, + ], + /** `expectedContents === null` => contents shouldn't change */ + ])('%s', async (_testName, buildContext, expectedContents: null | Record) => { + await materializeFinalWebpackConfig({ + userNextConfig, + incomingWebpackConfig: clientWebpackConfig, + incomingWebpackBuildContext: { ...buildContext, dir: testProjectBasepath }, + }); + moduleFormatExample.map(format => { + const contents = fs.readFileSync(format.file).toString(); + expect(contents).toStrictEqual(expectedContents ? expectedContents[format.name] : format.contents); + }); + }); + }); }); describe('Sentry webpack plugin config', () => { From b0da15b0bb317edd52724437b65204cde58570ba Mon Sep 17 00:00:00 2001 From: iker barriocanal <32816711+iker-barriocanal@users.noreply.github.com> Date: Thu, 23 Sep 2021 15:05:54 +0200 Subject: [PATCH 07/11] fix linting --- packages/nextjs/src/config/nextConfigToWebpackPluginConfig.ts | 1 + packages/nextjs/src/config/webpack.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/nextjs/src/config/nextConfigToWebpackPluginConfig.ts b/packages/nextjs/src/config/nextConfigToWebpackPluginConfig.ts index 89b8e00bf94f..f5ef086017d4 100644 --- a/packages/nextjs/src/config/nextConfigToWebpackPluginConfig.ts +++ b/packages/nextjs/src/config/nextConfigToWebpackPluginConfig.ts @@ -117,6 +117,7 @@ export function includeDistDir( ); // Keep the same object even if it's incorrect, so that the user can get a more precise error from sentry-cli // Casting to `any` for TS not complaining about it being `unknown` + // eslint-disable-next-line @typescript-eslint/no-explicit-any sourcesToInclude = usersInclude as any; } } diff --git a/packages/nextjs/src/config/webpack.ts b/packages/nextjs/src/config/webpack.ts index 90cbdfff5fbc..d8e84acc2ee0 100644 --- a/packages/nextjs/src/config/webpack.ts +++ b/packages/nextjs/src/config/webpack.ts @@ -136,6 +136,7 @@ function updateRewriteFramesBasepath(projectRootDir: string, distDir: string): v distDir, ); } catch (error) { + // eslint-disable-next-line no-console console.warn( 'Sentry Logger [Warn]: ' + `Could not set custom build directory \`${distDir}\`, required for correct display of source maps. `, From 3a03e22d9f9528f5086f616d80b6abca2539e751 Mon Sep 17 00:00:00 2001 From: iker barriocanal <32816711+iker-barriocanal@users.noreply.github.com> Date: Fri, 24 Sep 2021 12:51:39 +0200 Subject: [PATCH 08/11] Test the basepath variable exists in the file --- packages/nextjs/test/config.test.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/nextjs/test/config.test.ts b/packages/nextjs/test/config.test.ts index b0f3b3be4696..1c12f3af8896 100644 --- a/packages/nextjs/test/config.test.ts +++ b/packages/nextjs/test/config.test.ts @@ -14,6 +14,7 @@ import { WebpackConfigObject, } from '../src/config/types'; import { + BASEPATH_VARNAME, constructWebpackConfigFunction, getUserConfigFile, getWebpackPluginOptions, @@ -403,6 +404,12 @@ describe('webpack config', () => { expect(contents).toStrictEqual(expectedContents ? expectedContents[format.name] : format.contents); }); }); + + test(`\`${BASEPATH_VARNAME}\` is defined in \`index.server.ts\``, () => { + const indexServerPath = path.join(__dirname, '..', 'src', 'index.server.ts'); + const fileContents = fs.readFileSync(indexServerPath).toString(); + expect(fileContents).toMatch(new RegExp(`\\Wconst ${BASEPATH_VARNAME} =\\W`)); + }); }); }); From deab16028af4a4ca028e520a7a44d0494f6de942 Mon Sep 17 00:00:00 2001 From: iker barriocanal <32816711+iker-barriocanal@users.noreply.github.com> Date: Fri, 24 Sep 2021 16:00:43 +0200 Subject: [PATCH 09/11] Add docstrings --- packages/nextjs/src/config/webpack.ts | 36 ++++++++++++++++++++++++--- packages/nextjs/src/index.server.ts | 21 ++++++++++++++-- 2 files changed, 52 insertions(+), 5 deletions(-) diff --git a/packages/nextjs/src/config/webpack.ts b/packages/nextjs/src/config/webpack.ts index d8e84acc2ee0..3bcc337ecbff 100644 --- a/packages/nextjs/src/config/webpack.ts +++ b/packages/nextjs/src/config/webpack.ts @@ -51,7 +51,7 @@ export function constructWebpackConfigFunction( } // If a user defines a custom build directory (`distDir`), we must update the `RewriteFrames` integration so that - // the paths of the source maps match. + // the paths of the source maps match. This is required to correctly display server stack traces. // `distDir` is always defined in real life: either the user defines a value, or Next.js sets the default `.next`. // The check is for different environments, such as in tests. if (buildContext.isServer && buildContext.config.distDir) { @@ -117,9 +117,26 @@ export function constructWebpackConfigFunction( return newWebpackFunction; } -// TODO: make sure in tests that `PROJECT_BASEPATH` var exists in `index.server.ts` -const BASEPATH_VARNAME = 'PROJECT_BASEPATH'; +/** + * WARNING: don't modify the contents of this variable. + * The variable it refers to must be available in `index.server.ts`, and it gets + * overridden at build time. If it isn't, the build may break. + */ +export const BASEPATH_VARNAME = 'PROJECT_BASEPATH'; +/** + * Updates the base path of the server's RewriteFrames integration to match the source + * map's paths with the given distribution directory. + * + * This action is required to view correct stack traces when using a custom + * distribution directory. The project root is required to build correct paths of the + * files that must be overwritten. This use case arises when you run the build step in + * a different directory from the one the project is; for example, in tests. + * + * The project root is + * @param projectRootDir Root directory of the Next.js project. + * @param distDir The distribution directory. + */ function updateRewriteFramesBasepath(projectRootDir: string, distDir: string): void { if (distDir === PROJECT_BASEPATH) return; try { @@ -147,6 +164,19 @@ function updateRewriteFramesBasepath(projectRootDir: string, distDir: string): v } } +/** + * Overrides the base path variable with the distDir provided. + * + * Note that only replaces the first regex match. + * Different module formats have different variable prefixes and their output files + * are located in different paths. + * + * There's no error handling. + * + * @param filePath Path to the file. + * @param varPrefix Prefix of the variable declaration. + * @param distDir The distribution directory. + */ function setProjectBasepath(filePath: string, varPrefix: string, distDir: string): void { const fileContents = fs.readFileSync(filePath).toString(); const replacedContents = fileContents.replace( diff --git a/packages/nextjs/src/index.server.ts b/packages/nextjs/src/index.server.ts index 1bb832fd17b7..7a4aa21f730d 100644 --- a/packages/nextjs/src/index.server.ts +++ b/packages/nextjs/src/index.server.ts @@ -47,9 +47,26 @@ function sdkAlreadyInitialized(): boolean { return !!hub.getClient(); } +/** + * WARNING: don't refactor this variable. + * This variable gets overridden at build time to set the correct path -- what users + * defined in the `distDir` option in their Next.js configuration. + * + * Why this approach? + * There are two times to define the path: run time and build time. In any case, + * Next.js requires the user to set `distDir` in the options to compile the project. + * To get this path at run time and the SDK build it, users must also define the + * option in the SDK's server's configuration. However, to get the path at build time, + * users only need to set it once since the `withSentryConfig` wrapper can read the + * user's Next.js configuration. The SDK generates the `RewriteFrames` integration at + * initialization, meaning it's impossible to dynamically set the distribution directory + * path at build time if the option is only available at run time. To solve this issue, + * the SDK at build time rewrites the file where the default path of the integration is, + * so it's successfully generated at run time without additional configuration. + */ export const PROJECT_BASEPATH = '.next'; -const projectBasepathRegexp = PROJECT_BASEPATH[0] === '.' ? `\\${PROJECT_BASEPATH}` : PROJECT_BASEPATH; -const sourcemapFilenameRegex = new RegExp(`^.*/${projectBasepathRegexp}/`); +const projectBasepathRegex = PROJECT_BASEPATH[0] === '.' ? `\\${PROJECT_BASEPATH}` : PROJECT_BASEPATH; +const sourcemapFilenameRegex = new RegExp(`^.*/${projectBasepathRegex}/`); const defaultRewriteFramesIntegration = new RewriteFrames({ iteratee: frame => { From 508d46aef46b530a95ca2622f93233c93f2e7bc1 Mon Sep 17 00:00:00 2001 From: iker barriocanal <32816711+iker-barriocanal@users.noreply.github.com> Date: Fri, 24 Sep 2021 16:06:12 +0200 Subject: [PATCH 10/11] Move the approach reason to another part --- packages/nextjs/src/config/webpack.ts | 12 ++++++++++++ packages/nextjs/src/index.server.ts | 12 ------------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/nextjs/src/config/webpack.ts b/packages/nextjs/src/config/webpack.ts index 3bcc337ecbff..27a2e91b8970 100644 --- a/packages/nextjs/src/config/webpack.ts +++ b/packages/nextjs/src/config/webpack.ts @@ -133,6 +133,18 @@ export const BASEPATH_VARNAME = 'PROJECT_BASEPATH'; * files that must be overwritten. This use case arises when you run the build step in * a different directory from the one the project is; for example, in tests. * + * Why this approach? + * There are two times to define the path: run time and build time. In any case, + * Next.js requires the user to set `distDir` in the options to compile the project. + * To get this path at run time and the SDK build it, users must also define the + * option in the SDK's server's configuration. However, to get the path at build time, + * users only need to set it once since the `withSentryConfig` wrapper can read the + * user's Next.js configuration. The SDK generates the `RewriteFrames` integration at + * initialization, meaning it's impossible to dynamically set the distribution directory + * path at build time if the option is only available at run time. To solve this issue, + * the SDK at build time rewrites the files where the default path of the integration is, + * so it's successfully generated at run time without additional configuration. + * * The project root is * @param projectRootDir Root directory of the Next.js project. * @param distDir The distribution directory. diff --git a/packages/nextjs/src/index.server.ts b/packages/nextjs/src/index.server.ts index 7a4aa21f730d..1c18f1115537 100644 --- a/packages/nextjs/src/index.server.ts +++ b/packages/nextjs/src/index.server.ts @@ -51,18 +51,6 @@ function sdkAlreadyInitialized(): boolean { * WARNING: don't refactor this variable. * This variable gets overridden at build time to set the correct path -- what users * defined in the `distDir` option in their Next.js configuration. - * - * Why this approach? - * There are two times to define the path: run time and build time. In any case, - * Next.js requires the user to set `distDir` in the options to compile the project. - * To get this path at run time and the SDK build it, users must also define the - * option in the SDK's server's configuration. However, to get the path at build time, - * users only need to set it once since the `withSentryConfig` wrapper can read the - * user's Next.js configuration. The SDK generates the `RewriteFrames` integration at - * initialization, meaning it's impossible to dynamically set the distribution directory - * path at build time if the option is only available at run time. To solve this issue, - * the SDK at build time rewrites the file where the default path of the integration is, - * so it's successfully generated at run time without additional configuration. */ export const PROJECT_BASEPATH = '.next'; const projectBasepathRegex = PROJECT_BASEPATH[0] === '.' ? `\\${PROJECT_BASEPATH}` : PROJECT_BASEPATH; From fa2715086720e0a433cfb28acb5fdca03767cab8 Mon Sep 17 00:00:00 2001 From: iker barriocanal <32816711+iker-barriocanal@users.noreply.github.com> Date: Mon, 27 Sep 2021 17:37:15 +0200 Subject: [PATCH 11/11] Use line comment instead of block comment --- packages/nextjs/test/config.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nextjs/test/config.test.ts b/packages/nextjs/test/config.test.ts index 1c12f3af8896..62d6dd286d19 100644 --- a/packages/nextjs/test/config.test.ts +++ b/packages/nextjs/test/config.test.ts @@ -392,7 +392,7 @@ describe('webpack config', () => { es5: "exports.PROJECT_BASEPATH = '.test';", }, ], - /** `expectedContents === null` => contents shouldn't change */ + // `expectedContents === null` => contents shouldn't change ])('%s', async (_testName, buildContext, expectedContents: null | Record) => { await materializeFinalWebpackConfig({ userNextConfig,