Skip to content

Commit da18c45

Browse files
committed
use cwd for base in regex
1 parent eeb31f5 commit da18c45

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

packages/nextjs/src/config/webpack.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { getSentryRelease } from '@sentry/node';
2-
import { dropUndefinedKeys, escapeStringForRegex, logger } from '@sentry/utils';
2+
import { dropUndefinedKeys, logger } from '@sentry/utils';
3+
// import { dropUndefinedKeys, escapeStringForRegex, logger } from '@sentry/utils';
34
import { default as SentryWebpackPlugin } from '@sentry/webpack-plugin';
45
import * as fs from 'fs';
56
import * as os from 'os';
@@ -155,9 +156,10 @@ async function addSentryToEntryProperty(
155156
);
156157
console.log('cwd', process.cwd());
157158
console.log('buildContext.dir', buildContext.dir);
158-
const buildDirAbsPath = escapeStringForRegex(path.resolve(buildContext.dir, buildContext.config.distDir));
159-
const awsAbsPath = escapeStringForRegex(path.resolve('/var/task', buildContext.config.distDir));
160-
fs.writeFileSync(rewriteFramesHelper, `global.__rewriteFramesRegex__ = '${buildDirAbsPath}|${awsAbsPath}';\n`);
159+
// const buildDirAbsPath = escapeStringForRegex(path.resolve(buildContext.dir, buildContext.config.distDir));
160+
// const awsAbsPath = escapeStringForRegex(path.resolve('/var/task', buildContext.config.distDir));
161+
// fs.writeFileSync(rewriteFramesHelper, `global.__rewriteFramesRegex__ = '${buildDirAbsPath}|${awsAbsPath}';\n`);
162+
fs.writeFileSync(rewriteFramesHelper, `global.__rewriteFramesDistDir__ = '${buildContext.config.distDir}';\n`);
161163
filesToInject.unshift(rewriteFramesHelper);
162164
}
163165

packages/nextjs/src/index.server.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { RewriteFrames } from '@sentry/integrations';
22
import { configureScope, getCurrentHub, init as nodeInit, Integrations } from '@sentry/node';
33
import { hasTracingEnabled } from '@sentry/tracing';
44
import { escapeStringForRegex, logger } from '@sentry/utils';
5+
import * as path from 'path';
56

67
import { instrumentServer } from './utils/instrumentServer';
78
import { MetadataBuilder } from './utils/metadataBuilder';
@@ -49,14 +50,19 @@ function sdkAlreadyInitialized(): boolean {
4950

5051
function addServerIntegrations(options: NextjsOptions): void {
5152
// This value is injected at build time, based on the output directory specified in the build config
52-
const distDirRegex = (global as typeof global & { __rewriteFramesRegex__: string }).__rewriteFramesRegex__;
53-
const SOURCEMAP_FILENAME_REGEX = new RegExp(escapeStringForRegex(distDirRegex));
53+
const distDir = (global as typeof global & { __rewriteFramesDistDir__: string }).__rewriteFramesDistDir__;
54+
const SOURCEMAP_FILENAME_REGEX = new RegExp(escapeStringForRegex(path.resolve(process.cwd(), distDir)));
55+
// const distDirRegex = (global as typeof global & { __rewriteFramesRegex__: string }).__rewriteFramesRegex__;
56+
// const SOURCEMAP_FILENAME_REGEX = new RegExp(escapeStringForRegex(distDirRegex));
5457

55-
console.log('distDirRegex:', distDirRegex);
58+
// console.log('distDirRegex:', distDirRegex);
5659
console.log('cwd in addServerIntegrations', process.cwd());
5760

5861
const defaultRewriteFramesIntegration = new RewriteFrames({
5962
iteratee: frame => {
63+
if (frame.filename?.includes('throw')) {
64+
debugger;
65+
}
6066
frame.filename = frame.filename?.replace(SOURCEMAP_FILENAME_REGEX, 'app:///_next');
6167
return frame;
6268
},

0 commit comments

Comments
 (0)