rewriteFramesIntegration.js 2.0 KB

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