-
-
Notifications
You must be signed in to change notification settings - Fork 360
feat(core): Add includeFeedback Metro option to exclude feedback widget from bundle #6025
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
antonis
wants to merge
5
commits into
main
Choose a base branch
from
feat/metro-include-feedback
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+238
โ10
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d0df539
feat(core): Add includeFeedback Metro option to exclude feedback widgโฆ
antonis d82da05
Fix changelog
antonis 0449f5e
refactor(core): Rename include to includePackage in buildSentryPackagโฆ
antonis 8dcac24
Merge branch 'main' into feat/metro-include-feedback
antonis 8367db6
Merge branch 'main' into feat/metro-include-feedback
antonis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,3 +1,4 @@ | ||||||
| /* oxlint-disable eslint(max-lines) */ | ||||||
| import type { MetroConfig, MixedOutput, Module, ReadOnlyGraph } from 'metro'; | ||||||
| import type { CustomResolutionContext, CustomResolver, Resolution } from 'metro-resolver'; | ||||||
|
|
||||||
|
|
@@ -38,6 +39,11 @@ export interface SentryMetroConfigOptions { | |||||
| * @default true | ||||||
| */ | ||||||
| includeWebReplay?: boolean; | ||||||
| /** | ||||||
| * Adds the Sentry user feedback widget package for web. | ||||||
| * @default true | ||||||
| */ | ||||||
| includeFeedback?: boolean; | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets be more specific with the naming so it points out to be only include the web replay
Suggested change
|
||||||
| /** | ||||||
| * Add Sentry Metro Server Middleware which | ||||||
| * enables the app to fetch stack frames source context. | ||||||
|
|
@@ -79,6 +85,7 @@ export function withSentryConfig( | |||||
| { | ||||||
| annotateReactComponents = false, | ||||||
| includeWebReplay = true, | ||||||
| includeFeedback = true, | ||||||
| enableSourceContextInDevelopment = true, | ||||||
| optionsFile = true, | ||||||
| }: SentryMetroConfigOptions = {}, | ||||||
|
|
@@ -95,6 +102,9 @@ export function withSentryConfig( | |||||
| if (includeWebReplay === false) { | ||||||
| newConfig = withSentryResolver(newConfig, includeWebReplay); | ||||||
| } | ||||||
| if (includeFeedback === false) { | ||||||
| newConfig = withSentryFeedbackResolver(newConfig, includeFeedback); | ||||||
| } | ||||||
| newConfig = withSentryExcludeServerOnlyResolver(newConfig); | ||||||
| if (enableSourceContextInDevelopment) { | ||||||
| newConfig = withSentryMiddleware(newConfig); | ||||||
|
|
@@ -135,6 +145,9 @@ export function getSentryExpoConfig( | |||||
| if (options.includeWebReplay === false) { | ||||||
| newConfig = withSentryResolver(newConfig, options.includeWebReplay); | ||||||
| } | ||||||
| if (options.includeFeedback === false) { | ||||||
| newConfig = withSentryFeedbackResolver(newConfig, options.includeFeedback); | ||||||
| } | ||||||
| newConfig = withSentryExcludeServerOnlyResolver(newConfig); | ||||||
|
|
||||||
| if (options.enableSourceContextInDevelopment ?? true) { | ||||||
|
|
@@ -230,21 +243,26 @@ type CustomResolverBeforeMetro068 = ( | |||||
| ) => Resolution; | ||||||
|
|
||||||
| /** | ||||||
| * Includes `@sentry/replay` packages based on the `includeWebReplay` flag and current bundle `platform`. | ||||||
| * Builds a Metro resolver that returns `{ type: 'empty' }` for Sentry sub-packages | ||||||
| * matching `moduleRegex` when the user opts out on web or the platform is native. | ||||||
| */ | ||||||
| export function withSentryResolver(config: MetroConfig, includeWebReplay: boolean | undefined): MetroConfig { | ||||||
| function buildSentryPackageExcludeResolver( | ||||||
| config: MetroConfig, | ||||||
| includePackage: boolean | undefined, | ||||||
| moduleRegex: RegExp, | ||||||
| optionName: string, | ||||||
| ): MetroConfig { | ||||||
| const originalResolver = config.resolver?.resolveRequest as CustomResolver | CustomResolverBeforeMetro068 | undefined; | ||||||
|
|
||||||
| const sentryResolverRequest: CustomResolver = ( | ||||||
| const resolverRequest: CustomResolver = ( | ||||||
| context: CustomResolutionContext, | ||||||
| moduleName: string, | ||||||
| platform: string | null, | ||||||
| oldMetroModuleName?: string, | ||||||
| ) => { | ||||||
| if ( | ||||||
| (includeWebReplay === false || | ||||||
| (includeWebReplay === undefined && (platform === 'android' || platform === 'ios'))) && | ||||||
| !!(oldMetroModuleName ?? moduleName).match(/@sentry(?:-internal)?\/replay/) | ||||||
| (includePackage === false || (includePackage === undefined && (platform === 'android' || platform === 'ios'))) && | ||||||
| !!(oldMetroModuleName ?? moduleName).match(moduleRegex) | ||||||
| ) { | ||||||
| return { type: 'empty' } as Resolution; | ||||||
| } | ||||||
|
|
@@ -254,15 +272,15 @@ export function withSentryResolver(config: MetroConfig, includeWebReplay: boolea | |||||
| : originalResolver(context, moduleName, platform); | ||||||
| } | ||||||
|
|
||||||
| // Prior 0.68, resolve context.resolveRequest is sentryResolver itself, where on later version it is the default resolver. | ||||||
| if (context.resolveRequest === sentryResolverRequest) { | ||||||
| // Prior 0.68, context.resolveRequest is resolverRequest itself, where on later version it is the default resolver. | ||||||
| if (context.resolveRequest === resolverRequest) { | ||||||
| // oxlint-disable-next-line eslint(no-console) | ||||||
| console.error( | ||||||
| `Error: [@sentry/react-native/metro] Can not resolve the defaultResolver on Metro older than 0.68. | ||||||
| Please follow one of the following options: | ||||||
| - Include your resolverRequest on your metroconfig. | ||||||
| - Update your Metro version to 0.68 or higher. | ||||||
| - Set includeWebReplay as true on your metro config. | ||||||
| - Set ${optionName} as true on your metro config. | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. q: why this change? |
||||||
| - If you are still facing issues, report the issue at http://www.github.com/getsentry/sentry-react-native/issues`, | ||||||
| ); | ||||||
| // Return required for test. | ||||||
|
|
@@ -276,11 +294,35 @@ Please follow one of the following options: | |||||
| ...config, | ||||||
| resolver: { | ||||||
| ...config.resolver, | ||||||
| resolveRequest: sentryResolverRequest, | ||||||
| resolveRequest: resolverRequest, | ||||||
| }, | ||||||
| }; | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Includes `@sentry/replay` packages based on the `includeWebReplay` flag and current bundle `platform`. | ||||||
| */ | ||||||
| export function withSentryResolver(config: MetroConfig, includeWebReplay: boolean | undefined): MetroConfig { | ||||||
| return buildSentryPackageExcludeResolver( | ||||||
| config, | ||||||
| includeWebReplay, | ||||||
| /@sentry(?:-internal)?\/replay/, | ||||||
| 'includeWebReplay', | ||||||
| ); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Includes `@sentry-internal/feedback` packages based on the `includeFeedback` flag and current bundle `platform`. | ||||||
| */ | ||||||
| export function withSentryFeedbackResolver(config: MetroConfig, includeFeedback: boolean | undefined): MetroConfig { | ||||||
| return buildSentryPackageExcludeResolver( | ||||||
| config, | ||||||
| includeFeedback, | ||||||
| /@sentry(?:-internal)?\/feedback/, | ||||||
| 'includeFeedback', | ||||||
| ); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Matches relative import paths to server-only AI/MCP modules within `@sentry/core`. | ||||||
| * | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since a release was done on main branch, this changelog may be out of sync