@sentry/nextjs
Version:
Official Sentry SDK for Next.js
46 lines (37 loc) • 2.04 kB
JavaScript
import { _optionalChain } from '@sentry/utils';
import * as path from 'path';
import { defineIntegration } from '@sentry/core';
import { rewriteFramesIntegration as rewriteFramesIntegration$1, RewriteFrames } from '@sentry/integrations';
import { escapeStringForRegex } from '@sentry/utils';
const globalWithInjectedValues = global
;
const customRewriteFramesIntegration = ((options) => {
// This value is injected at build time, based on the output directory specified in the build config. Though a default
// is set there, we set it here as well, just in case something has gone wrong with the injection.
const distDirName = globalWithInjectedValues.__rewriteFramesDistDir__;
if (distDirName) {
// nextjs always puts the build directory at the project root level, which is also where you run `next start` from, so
// we can read in the project directory from the currently running process
const distDirAbsPath = path.resolve(distDirName).replace(/(\/|\\)$/, ''); // We strip trailing slashes because "app:///_next" also doesn't have one
// eslint-disable-next-line @sentry-internal/sdk/no-regexp-constructor -- user input is escaped
const SOURCEMAP_FILENAME_REGEX = new RegExp(escapeStringForRegex(distDirAbsPath));
return rewriteFramesIntegration$1({
iteratee: frame => {
frame.filename = _optionalChain([frame, 'access', _ => _.filename, 'optionalAccess', _2 => _2.replace, 'call', _3 => _3(SOURCEMAP_FILENAME_REGEX, 'app:///_next')]);
return frame;
},
...options,
});
}
// Do nothing if we can't find a distDirName
return {
// eslint-disable-next-line deprecation/deprecation
name: RewriteFrames.id,
// eslint-disable-next-line @typescript-eslint/no-empty-function
setupOnce: () => {},
processEvent: event => event,
};
}) ;
const rewriteFramesIntegration = defineIntegration(customRewriteFramesIntegration);
export { customRewriteFramesIntegration, rewriteFramesIntegration };
//# sourceMappingURL=rewriteFramesIntegration.js.map