rewriteFramesIntegration.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { _optionalChain } from '@sentry/utils';
  2. import { defineIntegration } from '@sentry/core';
  3. import { rewriteFramesIntegration as rewriteFramesIntegration$1 } from '@sentry/integrations';
  4. const globalWithInjectedValues = global
  5. ;
  6. const customRewriteFramesIntegration = ((options) => {
  7. // This value is injected at build time, based on the output directory specified in the build config. Though a default
  8. // is set there, we set it here as well, just in case something has gone wrong with the injection.
  9. const assetPrefixPath = globalWithInjectedValues.__rewriteFramesAssetPrefixPath__ || '';
  10. return rewriteFramesIntegration$1({
  11. // Turn `<origin>/<path>/_next/static/...` into `app:///_next/static/...`
  12. iteratee: frame => {
  13. try {
  14. const { origin } = new URL(frame.filename );
  15. frame.filename = _optionalChain([frame, 'access', _ => _.filename, 'optionalAccess', _2 => _2.replace, 'call', _3 => _3(origin, 'app://'), 'access', _4 => _4.replace, 'call', _5 => _5(assetPrefixPath, '')]);
  16. } catch (err) {
  17. // Filename wasn't a properly formed URL, so there's nothing we can do
  18. }
  19. // We need to URI-decode the filename because Next.js has wildcard routes like "/users/[id].js" which show up as "/users/%5id%5.js" in Error stacktraces.
  20. // The corresponding sources that Next.js generates have proper brackets so we also need proper brackets in the frame so that source map resolving works.
  21. if (frame.filename && frame.filename.startsWith('app:///_next')) {
  22. frame.filename = decodeURI(frame.filename);
  23. }
  24. if (
  25. frame.filename &&
  26. frame.filename.match(
  27. /^app:\/\/\/_next\/static\/chunks\/(main-|main-app-|polyfills-|webpack-|framework-|framework\.)[0-9a-f]+\.js$/,
  28. )
  29. ) {
  30. // We don't care about these frames. It's Next.js internal code.
  31. frame.in_app = false;
  32. }
  33. return frame;
  34. },
  35. ...options,
  36. });
  37. }) ;
  38. const rewriteFramesIntegration = defineIntegration(customRewriteFramesIntegration);
  39. export { customRewriteFramesIntegration, rewriteFramesIntegration };
  40. //# sourceMappingURL=rewriteFramesIntegration.js.map