'fix' treeshaking for sentry
This commit is contained in:
+11
-2
@@ -282,6 +282,11 @@ export default defineConfig(
|
||||
message:
|
||||
'Import the helpers from #/lib/notifications/expo-helpers (or the hooks from #/lib/notifications/notifications) instead. expo-notifications is stubbed on web; importing it directly pulls ~70KB of dead weight into the web bundle.',
|
||||
},
|
||||
{
|
||||
name: '@sentry/react-native',
|
||||
message:
|
||||
'Import the curated Sentry barrel from #/logger/sentry/lib instead. Importing @sentry/react-native directly (especially as `import * as Sentry`) defeats Metro tree-shaking and pulls ~180KB of dead weight into the web bundle.',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
@@ -318,14 +323,18 @@ export default defineConfig(
|
||||
},
|
||||
|
||||
/**
|
||||
* Native-only files that legitimately wrap expo-notifications. The .web.ts
|
||||
* counterparts to these files don't import the package.
|
||||
* Files that legitimately wrap restricted packages (the no-restricted-imports
|
||||
* rule above blocks `expo-notifications` and `@sentry/react-native` by
|
||||
* default; these wrappers are how the rest of the codebase reaches them).
|
||||
*/
|
||||
{
|
||||
files: [
|
||||
'src/lib/notifications/notifications.ts',
|
||||
'src/lib/notifications/expo-helpers.ts',
|
||||
'src/lib/hooks/useNotificationHandler.ts',
|
||||
'src/logger/sentry/lib/index.ts',
|
||||
'src/logger/sentry/setup/index.ts',
|
||||
'src/logger/__tests__/logger.test.ts',
|
||||
],
|
||||
rules: {
|
||||
'no-restricted-imports': 'off',
|
||||
|
||||
+1
-1
@@ -12,7 +12,6 @@ import * as ScreenOrientation from 'expo-screen-orientation'
|
||||
import * as SplashScreen from 'expo-splash-screen'
|
||||
import * as SystemUI from 'expo-system-ui'
|
||||
import {useLingui} from '@lingui/react/macro'
|
||||
import * as Sentry from '@sentry/react-native'
|
||||
|
||||
import {Provider as HideBottomBarBorderProvider} from '#/lib/hooks/useHideBottomBarBorder'
|
||||
import {QueryProvider} from '#/lib/react-query'
|
||||
@@ -20,6 +19,7 @@ import {ThemeProvider} from '#/lib/ThemeContext'
|
||||
import {Provider as TranslateOnDeviceProvider} from '#/lib/translation'
|
||||
import I18nProvider from '#/locale/i18nProvider'
|
||||
import {logger} from '#/logger'
|
||||
import * as Sentry from '#/logger/sentry/lib'
|
||||
import {Provider as A11yProvider} from '#/state/a11y'
|
||||
import {
|
||||
prefetchAppConfig,
|
||||
|
||||
+1
-1
@@ -6,7 +6,6 @@ import {Fragment, useEffect, useState} from 'react'
|
||||
import {KeyboardProvider as KeyboardControllerProvider} from 'react-native-keyboard-controller'
|
||||
import {SafeAreaProvider} from 'react-native-safe-area-context'
|
||||
import {useLingui} from '@lingui/react/macro'
|
||||
import * as Sentry from '@sentry/react-native'
|
||||
|
||||
import {Provider as HotkeysProvider} from '#/lib/hotkeys'
|
||||
import {QueryProvider} from '#/lib/react-query'
|
||||
@@ -14,6 +13,7 @@ import {ThemeProvider} from '#/lib/ThemeContext'
|
||||
import {Provider as TranslateOnDeviceProvider} from '#/lib/translation'
|
||||
import I18nProvider from '#/locale/i18nProvider'
|
||||
import {logger} from '#/logger'
|
||||
import * as Sentry from '#/logger/sentry/lib'
|
||||
import {Provider as A11yProvider} from '#/state/a11y'
|
||||
import {
|
||||
prefetchAppConfig,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import slugify from 'slugify'
|
||||
|
||||
import {getEntries} from '#/logger/logDump'
|
||||
import {Sentry} from '#/logger/sentry/lib'
|
||||
import * as Sentry from '#/logger/sentry/lib'
|
||||
|
||||
export function sendErrorReport({
|
||||
title,
|
||||
|
||||
@@ -1 +1,13 @@
|
||||
export * as Sentry from '@sentry/react-native'
|
||||
// Curated re-export of @sentry/react-native. We list only the symbols the app
|
||||
// actually uses, because `import * as Sentry from '@sentry/react-native'`
|
||||
// defeats Metro's tree-shaker and pulls in ~180KB of dead weight.
|
||||
//
|
||||
// When adding a new function, add it here and run a web build to confirm
|
||||
// tree-shaking is still working.
|
||||
export {
|
||||
addBreadcrumb,
|
||||
captureException,
|
||||
captureMessage,
|
||||
withScope,
|
||||
wrap,
|
||||
} from '@sentry/react-native'
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
export * as Sentry from '@sentry/react-native'
|
||||
@@ -1,5 +1,5 @@
|
||||
import {isNetworkError} from '#/lib/strings/errors'
|
||||
import {Sentry} from '#/logger/sentry/lib'
|
||||
import * as Sentry from '#/logger/sentry/lib'
|
||||
import {LogLevel, type Transport} from '#/logger/types'
|
||||
import {prepareMetadata} from '#/logger/util'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user