rewriteFramesIntegration.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 globalWithInjectedValues = global
  8. ;
  9. const customRewriteFramesIntegration = ((options) => {
  10. // This value is injected at build time, based on the output directory specified in the build config. Though a default
  11. // is set there, we set it here as well, just in case something has gone wrong with the injection.
  12. const assetPrefixPath = globalWithInjectedValues.__rewriteFramesAssetPrefixPath__ || '';
  13. return integrations.rewriteFramesIntegration({
  14. // Turn `<origin>/<path>/_next/static/...` into `app:///_next/static/...`
  15. iteratee: frame => {
  16. try {
  17. const { origin } = new URL(frame.filename );
  18. frame.filename = _optionalChain([frame, 'access', _ => _.filename, 'optionalAccess', _2 => _2.replace, 'call', _3 => _3(origin, 'app://'), 'access', _4 => _4.replace, 'call', _5 => _5(assetPrefixPath, '')]);
  19. } catch (err) {
  20. // Filename wasn't a properly formed URL, so there's nothing we can do
  21. }
  22. // 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.
  23. // 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.
  24. if (frame.filename && frame.filename.startsWith('app:///_next')) {
  25. frame.filename = decodeURI(frame.filename);
  26. }
  27. if (
  28. frame.filename &&
  29. frame.filename.match(
  30. /^app:\/\/\/_next\/static\/chunks\/(main-|main-app-|polyfills-|webpack-|framework-|framework\.)[0-9a-f]+\.js$/,
  31. )
  32. ) {
  33. // We don't care about these frames. It's Next.js internal code.
  34. frame.in_app = false;
  35. }
  36. return frame;
  37. },
  38. ...options,
  39. });
  40. }) ;
  41. const rewriteFramesIntegration = core.defineIntegration(customRewriteFramesIntegration);
  42. exports.customRewriteFramesIntegration = customRewriteFramesIntegration;
  43. exports.rewriteFramesIntegration = rewriteFramesIntegration;
  44. //# sourceMappingURL=rewriteFramesIntegration.js.map