rewriteFramesIntegration.js 2.1 KB

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