@sentry/nextjs
Version:
Official Sentry SDK for Next.js
52 lines (41 loc) • 2.13 kB
JavaScript
var {
_optionalChain
} = require('@sentry/utils');
Object.defineProperty(exports, '__esModule', { value: true });
const path = require('path');
const core = require('@sentry/core');
const integrations = require('@sentry/integrations');
const utils = require('@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(utils.escapeStringForRegex(distDirAbsPath));
return integrations.rewriteFramesIntegration({
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: integrations.RewriteFrames.id,
// eslint-disable-next-line @typescript-eslint/no-empty-function
setupOnce: () => {},
processEvent: event => event,
};
}) ;
const rewriteFramesIntegration = core.defineIntegration(customRewriteFramesIntegration);
exports.customRewriteFramesIntegration = customRewriteFramesIntegration;
exports.rewriteFramesIntegration = rewriteFramesIntegration;
//# sourceMappingURL=rewriteFramesIntegration.js.map