Skip to content

Commit 79f795f

Browse files
committed
apply code review suggestions
1 parent 3e7797d commit 79f795f

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

packages/nextjs/src/index.server.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ export * from '@sentry/node';
1414
// because or SSR of next.js we can only use this.
1515
export { ErrorBoundary, withErrorBoundary } from '@sentry/react';
1616

17+
type GlobalWithDistDir = typeof global & { __rewriteFramesDistDir__: string };
18+
1719
/** Inits the Sentry NextJS SDK on node. */
1820
export function init(options: NextjsOptions): void {
1921
if (options.debug) {
@@ -49,7 +51,7 @@ function sdkAlreadyInitialized(): boolean {
4951

5052
function addServerIntegrations(options: NextjsOptions): void {
5153
// This value is injected at build time, based on the output directory specified in the build config
52-
const distDirName = (global as typeof global & { __rewriteFramesDistDir__: string }).__rewriteFramesDistDir__;
54+
const distDirName = (global as GlobalWithDistDir).__rewriteFramesDistDir__ || '.next';
5355
// nextjs always puts the build directory at the project root level, which is also where you run `next start` from, so
5456
// we can read in the project directory from the currently running process
5557
const distDirAbsPath = path.resolve(process.cwd(), distDirName);

packages/nextjs/test/config.test.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,10 @@ afterAll(() => {
5757
// In order to know what to expect in the webpack config `entry` property, we need to know the path of the temporary
5858
// directory created when doing the file injection, so wrap the real `mkdtempSync` and store the resulting path where we
5959
// can access it
60-
let tempDir: string;
61-
const realMkdtempSync = jest.requireActual('fs').mkdtempSync;
62-
jest.spyOn(fs, 'mkdtempSync').mockImplementation(prefix => {
63-
tempDir = realMkdtempSync(prefix);
64-
return tempDir;
60+
const mkdtempSyncSpy = jest.spyOn(fs, 'mkdtempSync');
61+
62+
afterEach(() => {
63+
mkdtempSyncSpy.mockClear();
6564
});
6665

6766
/** Mocks of the arguments passed to `withSentryConfig` */
@@ -311,6 +310,7 @@ describe('webpack config', () => {
311310
incomingWebpackBuildContext: serverBuildContext,
312311
});
313312

313+
const tempDir = mkdtempSyncSpy.mock.results[0].value;
314314
const rewriteFramesHelper = path.join(tempDir, 'rewriteFramesHelper.js');
315315

316316
expect(finalWebpackConfig.entry).toEqual(
@@ -405,6 +405,8 @@ describe('webpack config', () => {
405405
incomingWebpackConfig: serverWebpackConfig,
406406
incomingWebpackBuildContext: getBuildContext('server', userNextConfigDistDir),
407407
});
408+
409+
const tempDir = mkdtempSyncSpy.mock.results[0].value;
408410
const rewriteFramesHelper = path.join(tempDir, 'rewriteFramesHelper.js');
409411

410412
expect(fs.existsSync(rewriteFramesHelper)).toBe(true);
@@ -668,6 +670,8 @@ describe('Sentry webpack plugin config', () => {
668670
});
669671

670672
describe('getUserConfigFile', () => {
673+
let tempDir: string;
674+
671675
beforeAll(() => {
672676
exitsSync.mockImplementation(realExistsSync);
673677
});
@@ -677,6 +681,7 @@ describe('Sentry webpack plugin config', () => {
677681
// that the location of the created folder is stored in `tempDir`
678682
const tempDirPathPrefix = path.join(os.tmpdir(), 'sentry-nextjs-test-');
679683
fs.mkdtempSync(tempDirPathPrefix);
684+
tempDir = mkdtempSyncSpy.mock.results[0].value;
680685
});
681686

682687
afterAll(() => {

0 commit comments

Comments
 (0)