rewriteFramesIntegration.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. var {
  2. _optionalChain
  3. } = require('@sentry/utils');
  4. Object.defineProperty(exports, '__esModule', { value: true });
  5. const path = require('path');
  6. const core = require('@sentry/core');
  7. const integrations = require('@sentry/integrations');
  8. const utils = require('@sentry/utils');
  9. const globalWithInjectedValues = global
  10. ;
  11. const customRewriteFramesIntegration = ((options) => {
  12. // This value is injected at build time, based on the output directory specified in the build config. Though a default
  13. // is set there, we set it here as well, just in case something has gone wrong with the injection.
  14. const distDirName = globalWithInjectedValues.__rewriteFramesDistDir__;
  15. if (distDirName) {
  16. // nextjs always puts the build directory at the project root level, which is also where you run `next start` from, so
  17. // we can read in the project directory from the currently running process
  18. const distDirAbsPath = path.resolve(distDirName).replace(/(\/|\\)$/, ''); // We strip trailing slashes because "app:///_next" also doesn't have one
  19. // eslint-disable-next-line @sentry-internal/sdk/no-regexp-constructor -- user input is escaped
  20. const SOURCEMAP_FILENAME_REGEX = new RegExp(utils.escapeStringForRegex(distDirAbsPath));
  21. return integrations.rewriteFramesIntegration({
  22. iteratee: frame => {
  23. frame.filename = _optionalChain([frame, 'access', _ => _.filename, 'optionalAccess', _2 => _2.replace, 'call', _3 => _3(SOURCEMAP_FILENAME_REGEX, 'app:///_next')]);
  24. return frame;
  25. },
  26. ...options,
  27. });
  28. }
  29. // Do nothing if we can't find a distDirName
  30. return {
  31. // eslint-disable-next-line deprecation/deprecation
  32. name: integrations.RewriteFrames.id,
  33. // eslint-disable-next-line @typescript-eslint/no-empty-function
  34. setupOnce: () => {},
  35. processEvent: event => event,
  36. };
  37. }) ;
  38. const rewriteFramesIntegration = core.defineIntegration(customRewriteFramesIntegration);
  39. exports.customRewriteFramesIntegration = customRewriteFramesIntegration;
  40. exports.rewriteFramesIntegration = rewriteFramesIntegration;
  41. //# sourceMappingURL=rewriteFramesIntegration.js.map