rewriteframes.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. Object.defineProperty(exports, '__esModule', { value: true });
  2. const core = require('@sentry/core');
  3. const utils = require('@sentry/utils');
  4. const INTEGRATION_NAME = 'RewriteFrames';
  5. const _rewriteFramesIntegration = ((options = {}) => {
  6. const root = options.root;
  7. const prefix = options.prefix || 'app:///';
  8. const iteratee =
  9. options.iteratee ||
  10. ((frame) => {
  11. if (!frame.filename) {
  12. return frame;
  13. }
  14. // Determine if this is a Windows frame by checking for a Windows-style prefix such as `C:\`
  15. const isWindowsFrame =
  16. /^[a-zA-Z]:\\/.test(frame.filename) ||
  17. // or the presence of a backslash without a forward slash (which are not allowed on Windows)
  18. (frame.filename.includes('\\') && !frame.filename.includes('/'));
  19. // Check if the frame filename begins with `/`
  20. const startsWithSlash = /^\//.test(frame.filename);
  21. if (isWindowsFrame || startsWithSlash) {
  22. const filename = isWindowsFrame
  23. ? frame.filename
  24. .replace(/^[a-zA-Z]:/, '') // remove Windows-style prefix
  25. .replace(/\\/g, '/') // replace all `\\` instances with `/`
  26. : frame.filename;
  27. const base = root ? utils.relative(root, filename) : utils.basename(filename);
  28. frame.filename = `${prefix}${base}`;
  29. }
  30. return frame;
  31. });
  32. /** Process an exception event. */
  33. function _processExceptionsEvent(event) {
  34. try {
  35. return {
  36. ...event,
  37. exception: {
  38. ...event.exception,
  39. // The check for this is performed inside `process` call itself, safe to skip here
  40. // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
  41. values: event.exception.values.map(value => ({
  42. ...value,
  43. ...(value.stacktrace && { stacktrace: _processStacktrace(value.stacktrace) }),
  44. })),
  45. },
  46. };
  47. } catch (_oO) {
  48. return event;
  49. }
  50. }
  51. /** Process a stack trace. */
  52. function _processStacktrace(stacktrace) {
  53. return {
  54. ...stacktrace,
  55. frames: stacktrace && stacktrace.frames && stacktrace.frames.map(f => iteratee(f)),
  56. };
  57. }
  58. return {
  59. name: INTEGRATION_NAME,
  60. // TODO v8: Remove this
  61. setupOnce() {}, // eslint-disable-line @typescript-eslint/no-empty-function
  62. processEvent(originalEvent) {
  63. let processedEvent = originalEvent;
  64. if (originalEvent.exception && Array.isArray(originalEvent.exception.values)) {
  65. processedEvent = _processExceptionsEvent(processedEvent);
  66. }
  67. return processedEvent;
  68. },
  69. };
  70. }) ;
  71. const rewriteFramesIntegration = core.defineIntegration(_rewriteFramesIntegration);
  72. /**
  73. * Rewrite event frames paths.
  74. * @deprecated Use `rewriteFramesIntegration()` instead.
  75. */
  76. // eslint-disable-next-line deprecation/deprecation
  77. const RewriteFrames = core.convertIntegrationFnToClass(
  78. INTEGRATION_NAME,
  79. rewriteFramesIntegration,
  80. )
  81. ;
  82. exports.RewriteFrames = RewriteFrames;
  83. exports.rewriteFramesIntegration = rewriteFramesIntegration;
  84. //# sourceMappingURL=rewriteframes.js.map