Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

feat: Transform class integrations into functional integrations #21

Merged
merged 1 commit into from
Apr 22, 2024

Conversation

mydea
Copy link
Member

@mydea mydea commented Apr 22, 2024

This does a few things related to integrations:

  1. Rewrite class-based integrations to the functional style
  2. Handle integrations on the Integrations hash (e.g. new Sentry.Integrations.Http())

I wrote a lot of test cases here, hopefully covering all the important stuff...

@mydea mydea requested review from lforst, Lms24, AbhiPrasad and s1gr1d April 22, 2024 14:02
@mydea mydea self-assigned this Apr 22, 2024
@mydea
Copy link
Member Author

mydea commented Apr 22, 2024

Hmm, actually, thinking about this - maybe we need to split this up in two transforms? 😬 one that does the functional change, and one that removes the integrations package - as the latter will only work on v8 (not on v7)? We don't have such a case yet, so far all transforms work on v7...

Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Had a question but it doesn't block this PR IMO

@@ -0,0 +1,66 @@
import { BrowserTracing, Integrations } from '@sentry/browser';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember if we supported this previously anywhere but theoretically, users could also just import { BrowserTracing as MyBrowserTracing } from '@sentry/browser.

In case we currently don't handle this, I think it's also totally fair to ignore this for now. (Even if we say we want to handle this, feel free to open a follow up PR).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, this will not work with renamed imports for now! We can look at this later if needed :)

const tracingImportPaths = rewriteEsmImports(SENTRY_REPLAY_PACKAGE, options.sentry.sdk, root, j);

// 2. Dedupe imports
if (tracingImportPaths.length > 0) {
dedupeImportStatements(options.sentry.sdk, root, j);
}

// 3. Replace requires
rewriteCjsRequires(SENTRY_REPLAY_PACKAGE, options.sentry.sdk, root, j);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l: Do we need CJS rewrites for replay (considering it's client-side)? I mean I guess it doesn't hurt us either so why not 😅

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticed this while working on this, I think it's OK to just have it here as well 😅

@mydea mydea force-pushed the fn/integrations branch from cba9c68 to 42b12e8 Compare April 22, 2024 14:30
@mydea mydea merged commit 4959a75 into main Apr 22, 2024
2 checks passed
@mydea mydea deleted the fn/integrations branch April 22, 2024 15:08
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants