@sentry/react-native 5.16.0-alpha.2 → 5.16.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +51 -0
- package/dist/js/integrations/default.d.ts +11 -0
- package/dist/js/integrations/default.d.ts.map +1 -0
- package/dist/js/integrations/default.js +79 -0
- package/dist/js/integrations/default.js.map +1 -0
- package/dist/js/integrations/expocontext.d.ts +17 -0
- package/dist/js/integrations/expocontext.d.ts.map +1 -0
- package/dist/js/integrations/expocontext.js +68 -0
- package/dist/js/integrations/expocontext.js.map +1 -0
- package/dist/js/integrations/reactnativeinfo.d.ts +2 -0
- package/dist/js/integrations/reactnativeinfo.d.ts.map +1 -1
- package/dist/js/integrations/reactnativeinfo.js +9 -1
- package/dist/js/integrations/reactnativeinfo.js.map +1 -1
- package/dist/js/integrations/sdkinfo.d.ts.map +1 -1
- package/dist/js/integrations/sdkinfo.js +5 -2
- package/dist/js/integrations/sdkinfo.js.map +1 -1
- package/dist/js/options.d.ts +6 -0
- package/dist/js/options.d.ts.map +1 -1
- package/dist/js/options.js +23 -1
- package/dist/js/options.js.map +1 -1
- package/dist/js/sdk.d.ts.map +1 -1
- package/dist/js/sdk.js +13 -55
- package/dist/js/sdk.js.map +1 -1
- package/dist/js/tools/sentryMetroSerializer.d.ts +3 -4
- package/dist/js/tools/sentryMetroSerializer.d.ts.map +1 -1
- package/dist/js/tools/sentryMetroSerializer.js +25 -18
- package/dist/js/tools/sentryMetroSerializer.js.map +1 -1
- package/dist/js/tools/vendor/expo/expoconfig.d.ts +24 -0
- package/dist/js/tools/vendor/expo/expoconfig.d.ts.map +1 -0
- package/dist/js/tools/vendor/expo/expoconfig.js +3 -0
- package/dist/js/tools/vendor/expo/expoconfig.js.map +1 -0
- package/dist/js/tracing/reactnavigation.d.ts.map +1 -1
- package/dist/js/tracing/reactnavigation.js +6 -4
- package/dist/js/tracing/reactnavigation.js.map +1 -1
- package/dist/js/tracing/reactnavigationv4.d.ts.map +1 -1
- package/dist/js/tracing/reactnavigationv4.js +4 -3
- package/dist/js/tracing/reactnavigationv4.js.map +1 -1
- package/dist/js/utils/environment.d.ts +8 -0
- package/dist/js/utils/environment.d.ts.map +1 -1
- package/dist/js/utils/environment.js +23 -0
- package/dist/js/utils/environment.js.map +1 -1
- package/dist/js/utils/expoglobalobject.d.ts +51 -0
- package/dist/js/utils/expoglobalobject.d.ts.map +1 -0
- package/dist/js/utils/expoglobalobject.js +2 -0
- package/dist/js/utils/expoglobalobject.js.map +1 -0
- package/dist/js/utils/expomodules.d.ts +10 -0
- package/dist/js/utils/expomodules.d.ts.map +1 -0
- package/dist/js/utils/expomodules.js +14 -0
- package/dist/js/utils/expomodules.js.map +1 -0
- package/dist/js/utils/worldwide.d.ts +2 -1
- package/dist/js/utils/worldwide.d.ts.map +1 -1
- package/dist/js/utils/worldwide.js.map +1 -1
- package/dist/js/version.d.ts +1 -1
- package/dist/js/version.js +1 -1
- package/dist/js/version.js.map +1 -1
- package/package.json +8 -4
- package/samples/react-native/react-native.config.js +5 -0
- package/scripts/expo-upload-sourcemaps.js +160 -0
- package/ts3.8/dist/js/integrations/default.d.ts +11 -0
- package/ts3.8/dist/js/integrations/expocontext.d.ts +17 -0
- package/ts3.8/dist/js/integrations/reactnativeinfo.d.ts +2 -0
- package/ts3.8/dist/js/options.d.ts +6 -0
- package/ts3.8/dist/js/utils/environment.d.ts +8 -0
- package/ts3.8/dist/js/utils/expoglobalobject.d.ts +51 -0
- package/ts3.8/dist/js/utils/expomodules.d.ts +10 -0
- package/ts3.8/dist/js/utils/worldwide.d.ts +2 -1
- package/ts3.8/dist/js/version.d.ts +1 -1
package/dist/js/sdk.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdk.js","sourceRoot":"","sources":["../../src/js/sdk.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,GAAG,EAAE,WA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AAC,CAAC,CAAC;SAChE;IACH,CAAC,CAAC;IACF,aAAa,EAAE,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC;AAC/C,CAAC","sourcesContent":["/* eslint-disable complexity */\nimport type { Scope } from '@sentry/core';\nimport { getIntegrationsToSetup, hasTracingEnabled, Hub, initAndBind, makeMain, setExtra } from '@sentry/core';\nimport { HttpClient } from '@sentry/integrations';\nimport {\n defaultIntegrations as reactDefaultIntegrations,\n defaultStackParser,\n getCurrentHub,\n makeFetchTransport,\n} from '@sentry/react';\nimport type { Integration, UserFeedback } from '@sentry/types';\nimport { logger, stackParserFromStackParserOptions } from '@sentry/utils';\nimport * as React from 'react';\nimport { Platform } from 'react-native';\n\nimport { ReactNativeClient } from './client';\nimport {\n DebugSymbolicator,\n DeviceContext,\n EventOrigin,\n HermesProfiling,\n ModulesLoader,\n ReactNativeErrorHandlers,\n ReactNativeInfo,\n Release,\n SdkInfo,\n} from './integrations';\nimport { NativeLinkedErrors } from './integrations/nativelinkederrors';\nimport { createReactNativeRewriteFrames } from './integrations/rewriteframes';\nimport { Screenshot } from './integrations/screenshot';\nimport { ViewHierarchy } from './integrations/viewhierarchy';\nimport type { ReactNativeClientOptions, ReactNativeOptions, ReactNativeWrapperOptions } from './options';\nimport { ReactNativeScope } from './scope';\nimport { TouchEventBoundary } from './touchevents';\nimport { ReactNativeProfiler, ReactNativeTracing } from './tracing';\nimport { DEFAULT_BUFFER_SIZE, makeNativeTransportFactory } from './transports/native';\nimport { makeUtf8TextEncoder } from './transports/TextEncoder';\nimport { getDefaultEnvironment } from './utils/environment';\nimport { safeFactory, safeTracesSampler } from './utils/safe';\nimport { NATIVE } from './wrapper';\n\nconst IGNORED_DEFAULT_INTEGRATIONS = [\n 'GlobalHandlers', // We will use the react-native internal handlers\n 'TryCatch', // We don't need this\n 'LinkedErrors', // We replace this with `NativeLinkedError`\n];\nconst DEFAULT_OPTIONS: ReactNativeOptions = {\n enableNativeCrashHandling: true,\n enableNativeNagger: true,\n autoInitializeNativeSdk: true,\n enableAutoPerformanceTracing: true,\n enableWatchdogTerminationTracking: true,\n patchGlobalPromise: true,\n transportOptions: {\n textEncoder: makeUtf8TextEncoder(),\n },\n sendClientReports: true,\n maxQueueSize: DEFAULT_BUFFER_SIZE,\n attachStacktrace: true,\n enableCaptureFailedRequests: false,\n enableNdk: true,\n};\n\n/**\n * Inits the SDK and returns the final options.\n */\nexport function init(passedOptions: ReactNativeOptions): void {\n const reactNativeHub = new Hub(undefined, new ReactNativeScope());\n makeMain(reactNativeHub);\n\n const maxQueueSize = passedOptions.maxQueueSize\n // eslint-disable-next-line deprecation/deprecation\n ?? passedOptions.transportOptions?.bufferSize\n ?? DEFAULT_OPTIONS.maxQueueSize;\n\n const enableNative = passedOptions.enableNative === undefined || passedOptions.enableNative\n ? NATIVE.isNativeAvailable()\n : false;\n const options: ReactNativeClientOptions = {\n ...DEFAULT_OPTIONS,\n ...passedOptions,\n enableNative,\n // If custom transport factory fails the SDK won't initialize\n transport: passedOptions.transport\n || makeNativeTransportFactory({\n enableNative,\n })\n || makeFetchTransport,\n transportOptions: {\n ...DEFAULT_OPTIONS.transportOptions,\n ...(passedOptions.transportOptions ?? {}),\n bufferSize: maxQueueSize,\n },\n maxQueueSize,\n integrations: [],\n stackParser: stackParserFromStackParserOptions(passedOptions.stackParser || defaultStackParser),\n beforeBreadcrumb: safeFactory(passedOptions.beforeBreadcrumb, { loggerMessage: 'The beforeBreadcrumb threw an error' }),\n initialScope: safeFactory(passedOptions.initialScope, { loggerMessage: 'The initialScope threw an error' }),\n tracesSampler: safeTracesSampler(passedOptions.tracesSampler),\n };\n if (!('environment' in options)) {\n options.environment = getDefaultEnvironment();\n }\n\n const defaultIntegrations: Integration[] = passedOptions.defaultIntegrations || [];\n if (passedOptions.defaultIntegrations === undefined) {\n defaultIntegrations.push(new ModulesLoader());\n if (Platform.OS !== 'web') {\n defaultIntegrations.push(new ReactNativeErrorHandlers({\n patchGlobalPromise: options.patchGlobalPromise,\n }));\n }\n defaultIntegrations.push(new Release());\n defaultIntegrations.push(...[\n ...reactDefaultIntegrations.filter(\n (i) => !IGNORED_DEFAULT_INTEGRATIONS.includes(i.name)\n ),\n ]);\n\n defaultIntegrations.push(new NativeLinkedErrors());\n defaultIntegrations.push(new EventOrigin());\n defaultIntegrations.push(new SdkInfo());\n defaultIntegrations.push(new ReactNativeInfo());\n\n if (__DEV__) {\n defaultIntegrations.push(new DebugSymbolicator());\n }\n\n defaultIntegrations.push(createReactNativeRewriteFrames());\n if (options.enableNative) {\n defaultIntegrations.push(new DeviceContext());\n }\n if (options._experiments && typeof options._experiments.profilesSampleRate === 'number') {\n defaultIntegrations.push(new HermesProfiling());\n }\n if (hasTracingEnabled(options) && options.enableAutoPerformanceTracing) {\n defaultIntegrations.push(new ReactNativeTracing());\n }\n if (options.attachScreenshot) {\n defaultIntegrations.push(new Screenshot());\n }\n if (options.attachViewHierarchy) {\n defaultIntegrations.push(new ViewHierarchy());\n }\n if (options.enableCaptureFailedRequests) {\n defaultIntegrations.push(new HttpClient());\n }\n }\n\n options.integrations = getIntegrationsToSetup({\n integrations: safeFactory(passedOptions.integrations, { loggerMessage: 'The integrations threw an error' }),\n defaultIntegrations,\n });\n initAndBind(ReactNativeClient, options);\n}\n\n/**\n * Inits the Sentry React Native SDK with automatic instrumentation and wrapped features.\n */\nexport function wrap<P extends Record<string, unknown>>(\n RootComponent: React.ComponentType<P>,\n options?: ReactNativeWrapperOptions\n): React.ComponentType<P> {\n const tracingIntegration = getCurrentHub().getIntegration(ReactNativeTracing);\n if (tracingIntegration) {\n tracingIntegration.useAppStartWithProfiler = true;\n }\n\n const profilerProps = {\n ...(options?.profilerProps ?? {}),\n name: RootComponent.displayName ?? 'Root',\n };\n\n const RootApp: React.FC<P> = (appProps) => {\n return (\n <TouchEventBoundary {...(options?.touchEventBoundaryProps ?? {})}>\n <ReactNativeProfiler {...profilerProps}>\n <RootComponent {...appProps} />\n </ReactNativeProfiler>\n </TouchEventBoundary>\n );\n };\n\n return RootApp;\n}\n\n/**\n * Deprecated. Sets the release on the event.\n * NOTE: Does not set the release on sessions.\n * @deprecated\n */\nexport function setRelease(release: string): void {\n setExtra('__sentry_release', release);\n}\n\n/**\n * Deprecated. Sets the dist on the event.\n * NOTE: Does not set the dist on sessions.\n * @deprecated\n */\nexport function setDist(dist: string): void {\n setExtra('__sentry_dist', dist);\n}\n\n/**\n * If native client is available it will trigger a native crash.\n * Use this only for testing purposes.\n */\nexport function nativeCrash(): void {\n const client = getCurrentHub().getClient<ReactNativeClient>();\n if (client) {\n client.nativeCrash();\n }\n}\n\n/**\n * Flushes all pending events in the queue to disk.\n * Use this before applying any realtime updates such as code-push or expo updates.\n */\nexport async function flush(): Promise<boolean> {\n try {\n const client = getCurrentHub().getClient<ReactNativeClient>();\n\n if (client) {\n const result = await client.flush();\n\n return result;\n }\n // eslint-disable-next-line no-empty\n } catch (_) { }\n\n logger.error('Failed to flush the event queue.');\n\n return false;\n}\n\n/**\n * Closes the SDK, stops sending events.\n */\nexport async function close(): Promise<void> {\n try {\n const client = getCurrentHub().getClient<ReactNativeClient>();\n\n if (client) {\n await client.close();\n }\n } catch (e) {\n logger.error('Failed to close the SDK');\n }\n}\n\n/**\n * Captures user feedback and sends it to Sentry.\n */\nexport function captureUserFeedback(feedback: UserFeedback): void {\n getCurrentHub().getClient<ReactNativeClient>()?.captureUserFeedback(feedback);\n}\n\n/**\n * Creates a new scope with and executes the given operation within.\n * The scope is automatically removed once the operation\n * finishes or throws.\n *\n * This is essentially a convenience function for:\n *\n * pushScope();\n * callback();\n * popScope();\n *\n * @param callback that will be enclosed into push/popScope.\n */\nexport function withScope(callback: (scope: Scope) => void): ReturnType<Hub['withScope']> {\n const safeCallback = (scope: Scope): void => {\n try {\n callback(scope);\n } catch (e) {\n logger.error('Error while running withScope callback', e);\n }\n };\n getCurrentHub().withScope(safeCallback);\n}\n\n/**\n * Callback to set context information onto the scope.\n * @param callback Callback function that receives Scope.\n */\nexport function configureScope(callback: (scope: Scope) => void): ReturnType<Hub['configureScope']> {\n const safeCallback = (scope: Scope): void => {\n try {\n callback(scope);\n } catch (e) {\n logger.error('Error while running configureScope callback', e);\n }\n };\n getCurrentHub().configureScope(safeCallback);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"sdk.js","sourceRoot":"","sources":["../../src/js/sdk.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,sBAAsB,EAAE,GAAG,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC5F,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,kBAAkB,GACnB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,MAAM,EAAE,iCAAiC,EAAE,MAAM,eAAe,CAAC;AAC1E,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAEhE,OAAO,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AACtF,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,qBAAqB,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,MAAM,eAAe,GAAuB;IAC1C,yBAAyB,EAAE,IAAI;IAC/B,kBAAkB,EAAE,IAAI;IACxB,uBAAu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YAE9D,IAAI,MAAM,EAAE;gBACV,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;aACtB;SACF;QAAC,OAAO,CAAC,EAAE;YACV,MAAM,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC;SACzC;IACH,CAAC;CAAA;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,QAAsB;;IACxD,MAAA,aAAa,EAAE,CAAC,SAAS,EAAqB,0CAAE,mBAAmB,CAAC,QAAQ,CAAC,CAAC;AAChF,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,SAAS,CAAC,QAAgC;IACxD,MAAM,YAAY,GAAG,CAAC,KAAY,EAAQ,EAAE;QAC1C,IAAI;YACF,QAAQ,CAAC,KAAK,CAAC,CAAC;SACjB;QAAC,OAAO,CAAC,EAAE;YACV,MAAM,CAAC,KAAK,CAAC,wCAAwC,EAAE,CAAC,CAAC,CAAC;SAC3D;IACH,CAAC,CAAC;IACF,aAAa,EAAE,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;AAC1C,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,QAAgC;IAC7D,MAAM,YAAY,GAAG,CAAC,KAAY,EAAQ,EAAE;QAC1C,IAAI;YACF,QAAQ,CAAC,KAAK,CAAC,CAAC;SACjB;QAAC,OAAO,CAAC,EAAE;YACV,MAAM,CAAC,KAAK,CAAC,6CAA6C,EAAE,CAAC,CAAC,CAAC;SAChE;IACH,CAAC,CAAC;IACF,aAAa,EAAE,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC;AAC/C,CAAC","sourcesContent":["/* eslint-disable complexity */\nimport type { Scope } from '@sentry/core';\nimport { getIntegrationsToSetup, Hub, initAndBind, makeMain, setExtra } from '@sentry/core';\nimport {\n defaultStackParser,\n getCurrentHub,\n makeFetchTransport,\n} from '@sentry/react';\nimport type { Integration, UserFeedback } from '@sentry/types';\nimport { logger, stackParserFromStackParserOptions } from '@sentry/utils';\nimport * as React from 'react';\n\nimport { ReactNativeClient } from './client';\nimport { getDefaultIntegrations } from './integrations/default';\nimport type { ReactNativeClientOptions, ReactNativeOptions, ReactNativeWrapperOptions } from './options';\nimport { shouldEnableNativeNagger } from './options';\nimport { ReactNativeScope } from './scope';\nimport { TouchEventBoundary } from './touchevents';\nimport { ReactNativeProfiler, ReactNativeTracing } from './tracing';\nimport { DEFAULT_BUFFER_SIZE, makeNativeTransportFactory } from './transports/native';\nimport { makeUtf8TextEncoder } from './transports/TextEncoder';\nimport { getDefaultEnvironment, isExpoGo } from './utils/environment';\nimport { safeFactory, safeTracesSampler } from './utils/safe';\nimport { NATIVE } from './wrapper';\n\nconst DEFAULT_OPTIONS: ReactNativeOptions = {\n enableNativeCrashHandling: true,\n enableNativeNagger: true,\n autoInitializeNativeSdk: true,\n enableAutoPerformanceTracing: true,\n enableWatchdogTerminationTracking: true,\n patchGlobalPromise: true,\n transportOptions: {\n textEncoder: makeUtf8TextEncoder(),\n },\n sendClientReports: true,\n maxQueueSize: DEFAULT_BUFFER_SIZE,\n attachStacktrace: true,\n enableCaptureFailedRequests: false,\n enableNdk: true,\n};\n\n/**\n * Inits the SDK and returns the final options.\n */\nexport function init(passedOptions: ReactNativeOptions): void {\n const reactNativeHub = new Hub(undefined, new ReactNativeScope());\n makeMain(reactNativeHub);\n\n const maxQueueSize = passedOptions.maxQueueSize\n // eslint-disable-next-line deprecation/deprecation\n ?? passedOptions.transportOptions?.bufferSize\n ?? DEFAULT_OPTIONS.maxQueueSize;\n\n const enableNative = passedOptions.enableNative === undefined || passedOptions.enableNative\n ? NATIVE.isNativeAvailable()\n : false;\n const options: ReactNativeClientOptions = {\n ...DEFAULT_OPTIONS,\n ...passedOptions,\n enableNative,\n enableNativeNagger: shouldEnableNativeNagger(passedOptions.enableNativeNagger),\n // If custom transport factory fails the SDK won't initialize\n transport: passedOptions.transport\n || makeNativeTransportFactory({\n enableNative,\n })\n || makeFetchTransport,\n transportOptions: {\n ...DEFAULT_OPTIONS.transportOptions,\n ...(passedOptions.transportOptions ?? {}),\n bufferSize: maxQueueSize,\n },\n maxQueueSize,\n integrations: [],\n stackParser: stackParserFromStackParserOptions(passedOptions.stackParser || defaultStackParser),\n beforeBreadcrumb: safeFactory(passedOptions.beforeBreadcrumb, { loggerMessage: 'The beforeBreadcrumb threw an error' }),\n initialScope: safeFactory(passedOptions.initialScope, { loggerMessage: 'The initialScope threw an error' }),\n tracesSampler: safeTracesSampler(passedOptions.tracesSampler),\n };\n if (!('environment' in options)) {\n options.environment = getDefaultEnvironment();\n }\n\n const defaultIntegrations: false | Integration[] = passedOptions.defaultIntegrations === undefined\n ? getDefaultIntegrations(options)\n : passedOptions.defaultIntegrations;\n\n options.integrations = getIntegrationsToSetup({\n integrations: safeFactory(passedOptions.integrations, { loggerMessage: 'The integrations threw an error' }),\n defaultIntegrations,\n });\n initAndBind(ReactNativeClient, options);\n\n if (isExpoGo()) {\n logger.info('Offline caching, native errors features are not available in Expo Go.');\n logger.info('Use EAS Build / Native Release Build to test these features.');\n }\n}\n\n/**\n * Inits the Sentry React Native SDK with automatic instrumentation and wrapped features.\n */\nexport function wrap<P extends Record<string, unknown>>(\n RootComponent: React.ComponentType<P>,\n options?: ReactNativeWrapperOptions\n): React.ComponentType<P> {\n const tracingIntegration = getCurrentHub().getIntegration(ReactNativeTracing);\n if (tracingIntegration) {\n tracingIntegration.useAppStartWithProfiler = true;\n }\n\n const profilerProps = {\n ...(options?.profilerProps ?? {}),\n name: RootComponent.displayName ?? 'Root',\n };\n\n const RootApp: React.FC<P> = (appProps) => {\n return (\n <TouchEventBoundary {...(options?.touchEventBoundaryProps ?? {})}>\n <ReactNativeProfiler {...profilerProps}>\n <RootComponent {...appProps} />\n </ReactNativeProfiler>\n </TouchEventBoundary>\n );\n };\n\n return RootApp;\n}\n\n/**\n * Deprecated. Sets the release on the event.\n * NOTE: Does not set the release on sessions.\n * @deprecated\n */\nexport function setRelease(release: string): void {\n setExtra('__sentry_release', release);\n}\n\n/**\n * Deprecated. Sets the dist on the event.\n * NOTE: Does not set the dist on sessions.\n * @deprecated\n */\nexport function setDist(dist: string): void {\n setExtra('__sentry_dist', dist);\n}\n\n/**\n * If native client is available it will trigger a native crash.\n * Use this only for testing purposes.\n */\nexport function nativeCrash(): void {\n const client = getCurrentHub().getClient<ReactNativeClient>();\n if (client) {\n client.nativeCrash();\n }\n}\n\n/**\n * Flushes all pending events in the queue to disk.\n * Use this before applying any realtime updates such as code-push or expo updates.\n */\nexport async function flush(): Promise<boolean> {\n try {\n const client = getCurrentHub().getClient<ReactNativeClient>();\n\n if (client) {\n const result = await client.flush();\n\n return result;\n }\n // eslint-disable-next-line no-empty\n } catch (_) { }\n\n logger.error('Failed to flush the event queue.');\n\n return false;\n}\n\n/**\n * Closes the SDK, stops sending events.\n */\nexport async function close(): Promise<void> {\n try {\n const client = getCurrentHub().getClient<ReactNativeClient>();\n\n if (client) {\n await client.close();\n }\n } catch (e) {\n logger.error('Failed to close the SDK');\n }\n}\n\n/**\n * Captures user feedback and sends it to Sentry.\n */\nexport function captureUserFeedback(feedback: UserFeedback): void {\n getCurrentHub().getClient<ReactNativeClient>()?.captureUserFeedback(feedback);\n}\n\n/**\n * Creates a new scope with and executes the given operation within.\n * The scope is automatically removed once the operation\n * finishes or throws.\n *\n * This is essentially a convenience function for:\n *\n * pushScope();\n * callback();\n * popScope();\n *\n * @param callback that will be enclosed into push/popScope.\n */\nexport function withScope(callback: (scope: Scope) => void): ReturnType<Hub['withScope']> {\n const safeCallback = (scope: Scope): void => {\n try {\n callback(scope);\n } catch (e) {\n logger.error('Error while running withScope callback', e);\n }\n };\n getCurrentHub().withScope(safeCallback);\n}\n\n/**\n * Callback to set context information onto the scope.\n * @param callback Callback function that receives Scope.\n */\nexport function configureScope(callback: (scope: Scope) => void): ReturnType<Hub['configureScope']> {\n const safeCallback = (scope: Scope): void => {\n try {\n callback(scope);\n } catch (e) {\n logger.error('Error while running configureScope callback', e);\n }\n };\n getCurrentHub().configureScope(safeCallback);\n}\n"]}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import type { MetroConfig } from 'metro';
|
|
2
2
|
import type { MetroSerializer } from './utils';
|
|
3
|
+
import type { DefaultConfigOptions } from './vendor/expo/expoconfig';
|
|
3
4
|
/**
|
|
4
|
-
* This function
|
|
5
|
-
*
|
|
6
|
-
* To use custom serializers, use `createSentryMetroSerializer(customSerializer)` instead.
|
|
5
|
+
* This function returns Default Expo configuration with Sentry plugins.
|
|
7
6
|
*/
|
|
8
|
-
export declare function
|
|
7
|
+
export declare function getSentryExpoConfig(projectRoot: string, options?: DefaultConfigOptions): MetroConfig;
|
|
9
8
|
/**
|
|
10
9
|
* Creates a Metro serializer that adds Debug ID module to the plain bundle.
|
|
11
10
|
* The Debug ID module is a virtual module that provides a debug ID in runtime.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sentryMetroSerializer.d.ts","sourceRoot":"","sources":["../../../src/js/tools/sentryMetroSerializer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"sentryMetroSerializer.d.ts","sourceRoot":"","sources":["../../../src/js/tools/sentryMetroSerializer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAsC,MAAM,OAAO,CAAC;AAG7E,OAAO,KAAK,EAAU,eAAe,EAA4D,MAAM,SAAS,CAAC;AAEjH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAWrE;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,GAAE,oBAAyB,GAAG,WAAW,CASxG;AA6CD;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,sBAAuB,eAAe,KAAG,eAsDhF,CAAC"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
-
exports.createSentryMetroSerializer = exports.
|
|
2
|
+
exports.createSentryMetroSerializer = exports.getSentryExpoConfig = void 0;
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const crypto = require("crypto");
|
|
5
|
-
const metro_1 = require("metro");
|
|
6
5
|
const countLines = require("metro/src/lib/countLines");
|
|
7
6
|
const utils_1 = require("./utils");
|
|
8
7
|
const utils_2 = require("./vendor/metro/utils");
|
|
@@ -12,28 +11,36 @@ const PRELUDE_MODULE_PATH = '__prelude__';
|
|
|
12
11
|
const SOURCE_MAP_COMMENT = '//# sourceMappingURL=';
|
|
13
12
|
const DEBUG_ID_COMMENT = '//# debugId=';
|
|
14
13
|
/**
|
|
15
|
-
* This function
|
|
16
|
-
*
|
|
17
|
-
* To use custom serializers, use `createSentryMetroSerializer(customSerializer)` instead.
|
|
14
|
+
* This function returns Default Expo configuration with Sentry plugins.
|
|
18
15
|
*/
|
|
19
|
-
function
|
|
20
|
-
const {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
16
|
+
function getSentryExpoConfig(projectRoot, options = {}) {
|
|
17
|
+
const { getDefaultConfig } = loadExpoMetroConfigModule();
|
|
18
|
+
return getDefaultConfig(projectRoot, Object.assign(Object.assign({}, options), { unstable_beforeAssetSerializationPlugins: [
|
|
19
|
+
...(options.unstable_beforeAssetSerializationPlugins || []),
|
|
20
|
+
unstable_beforeAssetSerializationPlugin,
|
|
21
|
+
] }));
|
|
22
|
+
}
|
|
23
|
+
exports.getSentryExpoConfig = getSentryExpoConfig;
|
|
24
|
+
function unstable_beforeAssetSerializationPlugin({ premodules, debugId, }) {
|
|
25
|
+
if (!debugId) {
|
|
26
|
+
return premodules;
|
|
27
|
+
}
|
|
28
|
+
const debugIdModuleExists = premodules.findIndex(module => module.path === DEBUG_ID_MODULE_PATH) != -1;
|
|
29
|
+
if (debugIdModuleExists) {
|
|
30
|
+
// eslint-disable-next-line no-console
|
|
31
|
+
console.warn('\n\nDebug ID module found. Skipping Sentry Debug ID module...\n\n');
|
|
32
|
+
return premodules;
|
|
33
|
+
}
|
|
34
|
+
const debugIdModule = createDebugIdModule(debugId);
|
|
35
|
+
return [...addDebugIdModule(premodules, debugIdModule)];
|
|
28
36
|
}
|
|
29
|
-
|
|
30
|
-
function loadExpoSerializersModule() {
|
|
37
|
+
function loadExpoMetroConfigModule() {
|
|
31
38
|
try {
|
|
32
39
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
33
|
-
return require('
|
|
40
|
+
return require('expo/metro-config');
|
|
34
41
|
}
|
|
35
42
|
catch (e) {
|
|
36
|
-
throw new Error('Unable to load `
|
|
43
|
+
throw new Error('Unable to load `expo/metro-config`. Make sure you have Expo installed.');
|
|
37
44
|
}
|
|
38
45
|
}
|
|
39
46
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sentryMetroSerializer.js","sourceRoot":"","sources":["../../../src/js/tools/sentryMetroSerializer.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AAEjC,iCAAoC;AACpC,uDAAuD;AAGvD,mCAA0G;AAC1G,gDAAoE;AAIpE,MAAM,qBAAqB,GAAG,2BAA2B,CAAC;AAC1D,MAAM,oBAAoB,GAAG,aAAa,CAAC;AAC3C,MAAM,mBAAmB,GAAG,aAAa,CAAC;AAC1C,MAAM,kBAAkB,GAAG,uBAAuB,CAAC;AACnD,MAAM,gBAAgB,GAAG,cAAc,CAAC;AAExC;;;;GAIG;AACH,SAAgB,yBAAyB,CAAC,MAAmB;IAC3D,MAAM,EAAE,mBAAmB,EAAE,GAAG,yBAAyB,EAAE,CAAC;IAE5D,MAAM,YAAY,GAAG;QACnB,UAAU,EAAE;YACV,gBAAgB,EAAE,IAAA,mCAA2B,GAAE;SAChD;KACa,CAAC;IAEjB,MAAM,WAAW,GAAG,IAAA,mBAAW,EAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACtD,OAAO,mBAAmB,CAAC,WAAW,CAAC,CAAC;AAC1C,CA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,MAAM,CAAC,qBAAqB,EAAE,GAAG,CAAC,EAAE,OAAO,CAAC,CAAC;AACvE,CAAC","sourcesContent":["import * as crypto from 'crypto';\nimport type { MetroConfig, MixedOutput, Module } from 'metro';\nimport { mergeConfig } from 'metro';\nimport * as countLines from 'metro/src/lib/countLines';\n\nimport type { Bundle, MetroSerializer, MetroSerializerOutput, SerializedBundle, VirtualJSOutput } from './utils';\nimport { createDebugIdSnippet, createSet, determineDebugIdFromBundleSource, stringToUUID } from './utils';\nimport { createDefaultMetroSerializer } from './vendor/metro/utils';\n\ntype SourceMap = Record<string, unknown>;\n\nconst DEBUG_ID_PLACE_HOLDER = '__debug_id_place_holder__';\nconst DEBUG_ID_MODULE_PATH = '__debugid__';\nconst PRELUDE_MODULE_PATH = '__prelude__';\nconst SOURCE_MAP_COMMENT = '//# sourceMappingURL=';\nconst DEBUG_ID_COMMENT = '//# debugId=';\n\n/**\n * This function will overwrite any existing custom serializer with default Expo and Sentry serializers.\n *\n * To use custom serializers, use `createSentryMetroSerializer(customSerializer)` instead.\n */\nexport function withSentryExpoSerializers(config: MetroConfig): MetroConfig {\n const { withExpoSerializers } = loadExpoSerializersModule();\n\n const sentryConfig = {\n serializer: {\n customSerializer: createSentryMetroSerializer(),\n },\n } as MetroConfig;\n\n const finalConfig = mergeConfig(config, sentryConfig);\n return withExpoSerializers(finalConfig);\n}\n\nfunction loadExpoSerializersModule(): {\n withExpoSerializers: (config: MetroConfig) => MetroConfig;\n} {\n try {\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n return require('@expo/metro-config/build/serializer/withExpoSerializers');\n } catch (e) {\n throw new Error(\n 'Unable to load `withExpoSerializers` from `@expo/metro-config`. Make sure you have Expo installed.',\n );\n }\n}\n\n/**\n * Creates a Metro serializer that adds Debug ID module to the plain bundle.\n * The Debug ID module is a virtual module that provides a debug ID in runtime.\n *\n * RAM Bundles do not support custom serializers.\n */\nexport const createSentryMetroSerializer = (customSerializer?: MetroSerializer): MetroSerializer => {\n const serializer = customSerializer || createDefaultMetroSerializer();\n return async function (entryPoint, preModules, graph, options) {\n if (graph.transformOptions.hot) {\n return serializer(entryPoint, preModules, graph, options);\n }\n\n const debugIdModuleExists = preModules.findIndex(module => module.path === DEBUG_ID_MODULE_PATH) != -1;\n if (debugIdModuleExists) {\n // eslint-disable-next-line no-console\n console.warn('Debug ID module found. Skipping Sentry Debug ID module...');\n return serializer(entryPoint, preModules, graph, options);\n }\n\n const debugIdModule = createDebugIdModule(DEBUG_ID_PLACE_HOLDER);\n options.sentryBundleCallback = createSentryBundleCallback(debugIdModule);\n const modifiedPreModules = addDebugIdModule(preModules, debugIdModule);\n\n // Run wrapped serializer\n const serializerResult = serializer(entryPoint, modifiedPreModules, graph, options);\n const { code: bundleCode, map: bundleMapString } = await extractSerializerResult(serializerResult);\n\n // Add debug id comment to the bundle\n const debugId = determineDebugIdFromBundleSource(bundleCode);\n if (!debugId) {\n throw new Error(\n 'Debug ID was not found in the bundle. Call `options.sentryBundleCallback` if you are using a custom serializer.',\n );\n }\n // Only print debug id for command line builds => not hot reload from dev server\n // eslint-disable-next-line no-console\n console.log('info ' + `Bundle Debug ID: ${debugId}`);\n\n const debugIdComment = `${DEBUG_ID_COMMENT}${debugId}`;\n const indexOfSourceMapComment = bundleCode.lastIndexOf(SOURCE_MAP_COMMENT);\n const bundleCodeWithDebugId =\n indexOfSourceMapComment === -1\n ? // If source map comment is missing lets just add the debug id comment\n `${bundleCode}\\n${debugIdComment}`\n : // If source map comment is present lets add the debug id comment before it\n `${bundleCode.substring(0, indexOfSourceMapComment) + debugIdComment}\\n${bundleCode.substring(\n indexOfSourceMapComment,\n )}`;\n\n const bundleMap: SourceMap = JSON.parse(bundleMapString);\n // For now we write both fields until we know what will become the standard - if ever.\n bundleMap['debug_id'] = debugId;\n bundleMap['debugId'] = debugId;\n\n return {\n code: bundleCodeWithDebugId,\n map: JSON.stringify(bundleMap),\n };\n };\n};\n\n/**\n * This function is expected to be called after serializer creates the final bundle object\n * and before the source maps are generated.\n *\n * It injects a debug ID into the bundle and returns the modified bundle.\n *\n * Access it via `options.sentryBundleCallback` in your custom serializer.\n */\nfunction createSentryBundleCallback(debugIdModule: Module<VirtualJSOutput> & { setSource: (code: string) => void }) {\n return (bundle: Bundle) => {\n const debugId = calculateDebugId(bundle);\n debugIdModule.setSource(injectDebugId(debugIdModule.getSource().toString(), debugId));\n bundle.pre = injectDebugId(bundle.pre, debugId);\n return bundle;\n };\n}\n\nfunction addDebugIdModule(\n preModules: readonly Module<MixedOutput>[],\n debugIdModule: Module<VirtualJSOutput>,\n): readonly Module<MixedOutput>[] {\n const modifiedPreModules = [...preModules];\n if (\n modifiedPreModules.length > 0 &&\n modifiedPreModules[0] !== undefined &&\n modifiedPreModules[0].path === PRELUDE_MODULE_PATH\n ) {\n // prelude module must be first as it measures the bundle startup time\n modifiedPreModules.unshift(preModules[0]);\n modifiedPreModules[1] = debugIdModule;\n } else {\n modifiedPreModules.unshift(debugIdModule);\n }\n return modifiedPreModules;\n}\n\nasync function extractSerializerResult(serializerResult: MetroSerializerOutput): Promise<SerializedBundle> {\n if (typeof serializerResult === 'string') {\n return { code: serializerResult, map: '{}' };\n }\n\n if ('map' in serializerResult) {\n return { code: serializerResult.code, map: serializerResult.map };\n }\n\n const awaitedResult = await serializerResult;\n if (typeof awaitedResult === 'string') {\n return { code: awaitedResult, map: '{}' };\n }\n\n return { code: awaitedResult.code, map: awaitedResult.map };\n}\n\nfunction createDebugIdModule(debugId: string): Module<VirtualJSOutput> & { setSource: (code: string) => void } {\n let debugIdCode = createDebugIdSnippet(debugId);\n\n return {\n setSource: (code: string) => {\n debugIdCode = code;\n },\n dependencies: new Map(),\n getSource: () => Buffer.from(debugIdCode),\n inverseDependencies: createSet(),\n path: DEBUG_ID_MODULE_PATH,\n output: [\n {\n type: 'js/script/virtual',\n data: {\n code: debugIdCode,\n lineCount: countLines(debugIdCode),\n map: [],\n },\n },\n ],\n };\n}\n\nfunction calculateDebugId(bundle: Bundle): string {\n const hash = crypto.createHash('md5');\n hash.update(bundle.pre);\n for (const [, code] of bundle.modules) {\n hash.update(code);\n }\n hash.update(bundle.post);\n\n const debugId = stringToUUID(hash.digest('hex'));\n return debugId;\n}\n\nfunction injectDebugId(code: string, debugId: string): string {\n return code.replace(new RegExp(DEBUG_ID_PLACE_HOLDER, 'g'), debugId);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"sentryMetroSerializer.js","sourceRoot":"","sources":["../../../src/js/tools/sentryMetroSerializer.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AAEjC,uDAAuD;AAGvD,mCAA0G;AAE1G,gDAAoE;AAIpE,MAAM,qBAAqB,GAAG,2BAA2B,CAAC;AAC1D,MAAM,oBAAoB,GAAG,aAAa,CAAC;AAC3C,MAAM,mBAAmB,GAAG,aAAa,CAAC;AAC1C,MAAM,kBAAkB,GAAG,uBAAuB,CAAC;AACnD,MAAM,gBAAgB,GAAG,cAAc,CAAC;AAExC;;GAEG;AACH,SAAgB,mBAAmB,CAAC,WAAmB,EAAE,UAAgC,EAAE;IACzF,MAAM,EAAE,gBAAgB,EAAE,GAAG,yBAAyB,EAAE,CAAC;IACzD,OAAO,gBAAgB,CAAC,WAAW,kCAC9B,OAAO,KACV,wCAAwC,EAAE;YACxC,GAAG,CAAC,OAAO,CAAC,wCAAwC,IAAI,EAAE,CAAC;YAC3D,uCAAuC;SACxC,IACD,CAAC;AACL,CAAC;AATD,kDASC;AAED,SAAS,uCAAuC,CAAC,EAC/C,UAAU,EACV,OAAO,GAKR;IACC,IAAI,CAAC,OAAO,EAAE;QACZ,OAAO,UAAU,CAAC;KACnB;IAED,MAAM,mBAAmB,GAAG,UAAU,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,oBAAoB,CAAC,IAAI,CAAC,CAAC,CAAC;IACvG,IAAI,mBAAmB,EAAE;QACvB,sCAAsC;QACtC,OAAO,CAAC,IAAI,CAAC,mEAAmE,CAAC,CAA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,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IACjD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAS,aAAa,CAAC,IAAY,EAAE,OAAe;IAClD,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,qBAAqB,EAAE,GAAG,CAAC,EAAE,OAAO,CAAC,CAAC;AACvE,CAAC","sourcesContent":["import * as crypto from 'crypto';\nimport type { MetroConfig, MixedOutput, Module, ReadOnlyGraph } from 'metro';\nimport * as countLines from 'metro/src/lib/countLines';\n\nimport type { Bundle, MetroSerializer, MetroSerializerOutput, SerializedBundle, VirtualJSOutput } from './utils';\nimport { createDebugIdSnippet, createSet, determineDebugIdFromBundleSource, stringToUUID } from './utils';\nimport type { DefaultConfigOptions } from './vendor/expo/expoconfig';\nimport { createDefaultMetroSerializer } from './vendor/metro/utils';\n\ntype SourceMap = Record<string, unknown>;\n\nconst DEBUG_ID_PLACE_HOLDER = '__debug_id_place_holder__';\nconst DEBUG_ID_MODULE_PATH = '__debugid__';\nconst PRELUDE_MODULE_PATH = '__prelude__';\nconst SOURCE_MAP_COMMENT = '//# sourceMappingURL=';\nconst DEBUG_ID_COMMENT = '//# debugId=';\n\n/**\n * This function returns Default Expo configuration with Sentry plugins.\n */\nexport function getSentryExpoConfig(projectRoot: string, options: DefaultConfigOptions = {}): MetroConfig {\n const { getDefaultConfig } = loadExpoMetroConfigModule();\n return getDefaultConfig(projectRoot, {\n ...options,\n unstable_beforeAssetSerializationPlugins: [\n ...(options.unstable_beforeAssetSerializationPlugins || []),\n unstable_beforeAssetSerializationPlugin,\n ],\n });\n}\n\nfunction unstable_beforeAssetSerializationPlugin({\n premodules,\n debugId,\n}: {\n graph: ReadOnlyGraph<MixedOutput>;\n premodules: Module[];\n debugId?: string;\n}): Module[] {\n if (!debugId) {\n return premodules;\n }\n\n const debugIdModuleExists = premodules.findIndex(module => module.path === DEBUG_ID_MODULE_PATH) != -1;\n if (debugIdModuleExists) {\n // eslint-disable-next-line no-console\n console.warn('\\n\\nDebug ID module found. Skipping Sentry Debug ID module...\\n\\n');\n return premodules;\n }\n\n const debugIdModule = createDebugIdModule(debugId);\n return [...addDebugIdModule(premodules, debugIdModule)];\n}\n\nfunction loadExpoMetroConfigModule(): {\n getDefaultConfig: (\n projectRoot: string,\n options: {\n unstable_beforeAssetSerializationPlugins?: ((serializationInput: {\n graph: ReadOnlyGraph<MixedOutput>;\n premodules: Module[];\n debugId?: string;\n }) => Module[])[];\n },\n ) => MetroConfig;\n} {\n try {\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n return require('expo/metro-config');\n } catch (e) {\n throw new Error('Unable to load `expo/metro-config`. Make sure you have Expo installed.');\n }\n}\n\n/**\n * Creates a Metro serializer that adds Debug ID module to the plain bundle.\n * The Debug ID module is a virtual module that provides a debug ID in runtime.\n *\n * RAM Bundles do not support custom serializers.\n */\nexport const createSentryMetroSerializer = (customSerializer?: MetroSerializer): MetroSerializer => {\n const serializer = customSerializer || createDefaultMetroSerializer();\n return async function (entryPoint, preModules, graph, options) {\n if (graph.transformOptions.hot) {\n return serializer(entryPoint, preModules, graph, options);\n }\n\n const debugIdModuleExists = preModules.findIndex(module => module.path === DEBUG_ID_MODULE_PATH) != -1;\n if (debugIdModuleExists) {\n // eslint-disable-next-line no-console\n console.warn('Debug ID module found. Skipping Sentry Debug ID module...');\n return serializer(entryPoint, preModules, graph, options);\n }\n\n const debugIdModule = createDebugIdModule(DEBUG_ID_PLACE_HOLDER);\n options.sentryBundleCallback = createSentryBundleCallback(debugIdModule);\n const modifiedPreModules = addDebugIdModule(preModules, debugIdModule);\n\n // Run wrapped serializer\n const serializerResult = serializer(entryPoint, modifiedPreModules, graph, options);\n const { code: bundleCode, map: bundleMapString } = await extractSerializerResult(serializerResult);\n\n // Add debug id comment to the bundle\n const debugId = determineDebugIdFromBundleSource(bundleCode);\n if (!debugId) {\n throw new Error(\n 'Debug ID was not found in the bundle. Call `options.sentryBundleCallback` if you are using a custom serializer.',\n );\n }\n // Only print debug id for command line builds => not hot reload from dev server\n // eslint-disable-next-line no-console\n console.log('info ' + `Bundle Debug ID: ${debugId}`);\n\n const debugIdComment = `${DEBUG_ID_COMMENT}${debugId}`;\n const indexOfSourceMapComment = bundleCode.lastIndexOf(SOURCE_MAP_COMMENT);\n const bundleCodeWithDebugId =\n indexOfSourceMapComment === -1\n ? // If source map comment is missing lets just add the debug id comment\n `${bundleCode}\\n${debugIdComment}`\n : // If source map comment is present lets add the debug id comment before it\n `${bundleCode.substring(0, indexOfSourceMapComment) + debugIdComment}\\n${bundleCode.substring(\n indexOfSourceMapComment,\n )}`;\n\n const bundleMap: SourceMap = JSON.parse(bundleMapString);\n // For now we write both fields until we know what will become the standard - if ever.\n bundleMap['debug_id'] = debugId;\n bundleMap['debugId'] = debugId;\n\n return {\n code: bundleCodeWithDebugId,\n map: JSON.stringify(bundleMap),\n };\n };\n};\n\n/**\n * This function is expected to be called after serializer creates the final bundle object\n * and before the source maps are generated.\n *\n * It injects a debug ID into the bundle and returns the modified bundle.\n *\n * Access it via `options.sentryBundleCallback` in your custom serializer.\n */\nfunction createSentryBundleCallback(debugIdModule: Module<VirtualJSOutput> & { setSource: (code: string) => void }) {\n return (bundle: Bundle) => {\n const debugId = calculateDebugId(bundle);\n debugIdModule.setSource(injectDebugId(debugIdModule.getSource().toString(), debugId));\n bundle.pre = injectDebugId(bundle.pre, debugId);\n return bundle;\n };\n}\n\nfunction addDebugIdModule(\n preModules: readonly Module<MixedOutput>[],\n debugIdModule: Module<VirtualJSOutput>,\n): readonly Module<MixedOutput>[] {\n const modifiedPreModules = [...preModules];\n if (\n modifiedPreModules.length > 0 &&\n modifiedPreModules[0] !== undefined &&\n modifiedPreModules[0].path === PRELUDE_MODULE_PATH\n ) {\n // prelude module must be first as it measures the bundle startup time\n modifiedPreModules.unshift(preModules[0]);\n modifiedPreModules[1] = debugIdModule;\n } else {\n modifiedPreModules.unshift(debugIdModule);\n }\n return modifiedPreModules;\n}\n\nasync function extractSerializerResult(serializerResult: MetroSerializerOutput): Promise<SerializedBundle> {\n if (typeof serializerResult === 'string') {\n return { code: serializerResult, map: '{}' };\n }\n\n if ('map' in serializerResult) {\n return { code: serializerResult.code, map: serializerResult.map };\n }\n\n const awaitedResult = await serializerResult;\n if (typeof awaitedResult === 'string') {\n return { code: awaitedResult, map: '{}' };\n }\n\n return { code: awaitedResult.code, map: awaitedResult.map };\n}\n\nfunction createDebugIdModule(debugId: string): Module<VirtualJSOutput> & { setSource: (code: string) => void } {\n let debugIdCode = createDebugIdSnippet(debugId);\n\n return {\n setSource: (code: string) => {\n debugIdCode = code;\n },\n dependencies: new Map(),\n getSource: () => Buffer.from(debugIdCode),\n inverseDependencies: createSet(),\n path: DEBUG_ID_MODULE_PATH,\n output: [\n {\n type: 'js/script/virtual',\n data: {\n code: debugIdCode,\n lineCount: countLines(debugIdCode),\n map: [],\n },\n },\n ],\n };\n}\n\nfunction calculateDebugId(bundle: Bundle): string {\n const hash = crypto.createHash('md5');\n hash.update(bundle.pre);\n for (const [, code] of bundle.modules) {\n hash.update(code);\n }\n hash.update(bundle.post);\n\n const debugId = stringToUUID(hash.digest('hex'));\n return debugId;\n}\n\nfunction injectDebugId(code: string, debugId: string): string {\n return code.replace(new RegExp(DEBUG_ID_PLACE_HOLDER, 'g'), debugId);\n}\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { MixedOutput, Module, ReadOnlyGraph } from 'metro';
|
|
2
|
+
export interface DefaultConfigOptions {
|
|
3
|
+
/** @deprecated */
|
|
4
|
+
mode?: 'exotic';
|
|
5
|
+
/**
|
|
6
|
+
* **Experimental:** Enable CSS support for Metro web, and shim on native.
|
|
7
|
+
*
|
|
8
|
+
* This is an experimental feature and may change in the future. The underlying implementation
|
|
9
|
+
* is subject to change, and native support for CSS Modules may be added in the future during a non-major SDK release.
|
|
10
|
+
*/
|
|
11
|
+
isCSSEnabled?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* **Experimental:** Modify premodules before a code asset is serialized
|
|
14
|
+
*
|
|
15
|
+
* This is an experimental feature and may change in the future. The underlying implementation
|
|
16
|
+
* is subject to change.
|
|
17
|
+
*/
|
|
18
|
+
unstable_beforeAssetSerializationPlugins?: ((serializationInput: {
|
|
19
|
+
graph: ReadOnlyGraph<MixedOutput>;
|
|
20
|
+
premodules: Module[];
|
|
21
|
+
debugId?: string;
|
|
22
|
+
}) => Module[])[];
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=expoconfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expoconfig.d.ts","sourceRoot":"","sources":["../../../../../src/js/tools/vendor/expo/expoconfig.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAGhE,MAAM,WAAW,oBAAoB;IACnC,kBAAkB;IAClB,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB;;;;;OAKG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;;;;OAKG;IACH,wCAAwC,CAAC,EAAE,CAAC,CAAC,kBAAkB,EAAE;QAC/D,KAAK,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC;QAClC,UAAU,EAAE,MAAM,EAAE,CAAC;QACrB,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,KAAK,MAAM,EAAE,CAAC,EAAE,CAAC;CACnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expoconfig.js","sourceRoot":"","sources":["../../../../../src/js/tools/vendor/expo/expoconfig.ts"],"names":[],"mappings":"AAAA,wBAAwB","sourcesContent":["// The MIT License (MIT)\n\n// Copyright (c) 2015-present 650 Industries, Inc. (aka Expo)\n\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n\n// The above copyright notice and this permission notice shall be included in all\n// copies or substantial portions of the Software.\n\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n// SOFTWARE.\n\nimport type { MixedOutput, Module, ReadOnlyGraph } from 'metro';\n\n// https://github.com/expo/expo/blob/44d03f59e25b01fbfee82075da18dd7f8ce44e96/packages/%40expo/metro-config/src/ExpoMetroConfig.ts\nexport interface DefaultConfigOptions {\n /** @deprecated */\n mode?: 'exotic';\n /**\n * **Experimental:** Enable CSS support for Metro web, and shim on native.\n *\n * This is an experimental feature and may change in the future. The underlying implementation\n * is subject to change, and native support for CSS Modules may be added in the future during a non-major SDK release.\n */\n isCSSEnabled?: boolean;\n /**\n * **Experimental:** Modify premodules before a code asset is serialized\n *\n * This is an experimental feature and may change in the future. The underlying implementation\n * is subject to change.\n */\n unstable_beforeAssetSerializationPlugins?: ((serializationInput: {\n graph: ReadOnlyGraph<MixedOutput>;\n premodules: Module[];\n debugId?: string;\n }) => Module[])[];\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactnavigation.d.ts","sourceRoot":"","sources":["../../../src/js/tracing/reactnavigation.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AACnF,OAAO,EAAE,8BAA8B,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jC;;OAEG;IACH,OAAO,CAAC,wBAAwB;CAMjC;AAED;;;GAGG;AACH,eAAO,MAAM,gCAAgC,uCAAiC,CAAC;AAE/E,eAAO,MAAM,yBAAyB;;;;;;;CAOrC,CAAC"}
|
|
@@ -107,7 +107,7 @@ export class ReactNavigationInstrumentation extends InternalRoutingInstrumentati
|
|
|
107
107
|
* To be called AFTER the state has been changed to populate the transaction with the current route.
|
|
108
108
|
*/
|
|
109
109
|
_onStateChange() {
|
|
110
|
-
var _a
|
|
110
|
+
var _a;
|
|
111
111
|
// Use the getCurrentRoute method to be accurate.
|
|
112
112
|
const previousRoute = this._latestRoute;
|
|
113
113
|
if (!this._navigationContainer) {
|
|
@@ -123,13 +123,15 @@ export class ReactNavigationInstrumentation extends InternalRoutingInstrumentati
|
|
|
123
123
|
const data = Object.assign(Object.assign({}, originalContext.data), { route: {
|
|
124
124
|
name: route.name,
|
|
125
125
|
key: route.key,
|
|
126
|
-
|
|
126
|
+
// TODO: filter PII params instead of dropping them all
|
|
127
|
+
params: {},
|
|
127
128
|
hasBeenSeen: routeHasBeenSeen,
|
|
128
129
|
}, previousRoute: previousRoute
|
|
129
130
|
? {
|
|
130
131
|
name: previousRoute.name,
|
|
131
132
|
key: previousRoute.key,
|
|
132
|
-
|
|
133
|
+
// TODO: filter PII params instead of dropping them all
|
|
134
|
+
params: {},
|
|
133
135
|
}
|
|
134
136
|
: null });
|
|
135
137
|
const updatedContext = Object.assign(Object.assign({}, originalContext), { name: route.name, tags: Object.assign(Object.assign({}, originalContext.tags), { 'routing.route.name': route.name }), data });
|
|
@@ -137,7 +139,7 @@ export class ReactNavigationInstrumentation extends InternalRoutingInstrumentati
|
|
|
137
139
|
this._latestTransaction.updateWithContext(finalContext);
|
|
138
140
|
const isCustomName = updatedContext.name !== finalContext.name;
|
|
139
141
|
this._latestTransaction.setName(finalContext.name, isCustomName ? customTransactionSource : defaultTransactionSource);
|
|
140
|
-
(
|
|
142
|
+
(_a = this._onConfirmRoute) === null || _a === void 0 ? void 0 : _a.call(this, finalContext);
|
|
141
143
|
}
|
|
142
144
|
this._pushRecentRouteKey(route.key);
|
|
143
145
|
this._latestRoute = route;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactnavigation.js","sourceRoot":"","sources":["../../../src/js/tracing/reactnavigation.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,EAAE,8BAA8B,EAAE,MAAM,0BAA0B,CAAC;AAE1E,OAAO,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAC;AAyBxG,MAAM,cAAc,GAA2B;IAC7C,oBAAoB,EAAE,IAAI;CAC3B,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,OAAO,8BAA+B,SAAQ,8BAA8B;IAiBhF,YAAmB,UAA2C,EAAE;QAC9D,KAAK,EAAE,CAAC;QAfM,SAAI,GAAW,8BAA8B,CAAC,mBAAmB,CAAC;QAE1E,yBAAoB,GAA+B,IAAI,CAAC;QAE/C,uBAAkB,GAAW,GAAG,CAAC;QAI1C,yBAAoB,GAAY,KAAK,CAAC;QAEtC,qBAAgB,GAAa,EAAE,CAAC;QAoNxC,sGAAsG;QAC9F,wBAAmB,GAAG,CAAC,GAAW,EAAQ,EAAE;YAClD,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAEhC,IAAI,IAAI,CAAC,gBAAgB,CAAC,MAAM,GAAG,IAAI,CAAC,kBAAkB,EAAE;gBAC1D,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,IAAI,CAAC,gBAAgB,CAAC,MAAM,GAAG,IAAI,CAAC,kBAAkB,CAAC,CAAC;aAC7G;QACH,CAAC,CAAC;QApNA,IAAI,CAAC,QAAQ,mCACR,cAAc,GACd,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ChB,IAAI,EAAE;QACJ,yBAAyB,EAAE,8BAA8B,CAAC,mBAAmB;KAC9E;IACD,IAAI,EAAE,EAAE;CACT,CAAC","sourcesContent":["/* eslint-disable max-lines */\nimport type { Transaction as TransactionType, TransactionContext } from '@sentry/types';\nimport { logger } from '@sentry/utils';\n\nimport { RN_GLOBAL_OBJ } from '../utils/worldwide';\nimport type { OnConfirmRoute, TransactionCreator } from './routingInstrumentation';\nimport { InternalRoutingInstrumentation } from './routingInstrumentation';\nimport type { BeforeNavigate, ReactNavigationTransactionContext, RouteChangeContextData } from './types';\nimport { customTransactionSource, defaultTransactionSource, getBlankTransactionContext } from './utils';\n\nexport interface NavigationRoute {\n name: string;\n key: string;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n params?: Record<string, any>;\n}\n\ninterface NavigationContainer {\n addListener: (type: string, listener: () => void) => void;\n getCurrentRoute: () => NavigationRoute;\n}\n\ninterface ReactNavigationOptions {\n /**\n * How long the instrumentation will wait for the route to mount after a change has been initiated,\n * before the transaction is discarded.\n * Time is in ms.\n *\n * Default: 1000\n */\n routeChangeTimeoutMs: number;\n}\n\nconst defaultOptions: ReactNavigationOptions = {\n routeChangeTimeoutMs: 1000,\n};\n\n/**\n * Instrumentation for React-Navigation V5 and above. See docs or sample app for usage.\n *\n * How this works:\n * - `_onDispatch` is called every time a dispatch happens and sets an IdleTransaction on the scope without any route context.\n * - `_onStateChange` is then called AFTER the state change happens due to a dispatch and sets the route context onto the active transaction.\n * - If `_onStateChange` isn't called within `STATE_CHANGE_TIMEOUT_DURATION` of the dispatch, then the transaction is not sampled and finished.\n */\nexport class ReactNavigationInstrumentation extends InternalRoutingInstrumentation {\n public static instrumentationName: string = 'react-navigation-v5';\n\n public readonly name: string = ReactNavigationInstrumentation.instrumentationName;\n\n private _navigationContainer: NavigationContainer | null = null;\n\n private readonly _maxRecentRouteLen: number = 200;\n\n private _latestRoute?: NavigationRoute;\n private _latestTransaction?: TransactionType;\n private _initialStateHandled: boolean = false;\n private _stateChangeTimeout?: number | undefined;\n private _recentRouteKeys: string[] = [];\n\n private _options: ReactNavigationOptions;\n\n public constructor(options: Partial<ReactNavigationOptions> = {}) {\n super();\n\n this._options = {\n ...defaultOptions,\n ...options,\n };\n }\n\n /**\n * Extends by calling _handleInitialState at the end.\n */\n public registerRoutingInstrumentation(\n listener: TransactionCreator,\n beforeNavigate: BeforeNavigate,\n onConfirmRoute: OnConfirmRoute,\n ): void {\n super.registerRoutingInstrumentation(listener, beforeNavigate, onConfirmRoute);\n\n // We create an initial state here to ensure a transaction gets created before the first route mounts.\n if (!this._initialStateHandled) {\n this._onDispatch();\n if (this._navigationContainer) {\n // Navigation container already registered, just populate with route state\n this._onStateChange();\n\n this._initialStateHandled = true;\n }\n }\n }\n\n /**\n * Pass the ref to the navigation container to register it to the instrumentation\n * @param navigationContainerRef Ref to a `NavigationContainer`\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types\n public registerNavigationContainer(navigationContainerRef: any): void {\n /* We prevent duplicate routing instrumentation to be initialized on fast refreshes\n\n Explanation: If the user triggers a fast refresh on the file that the instrumentation is\n initialized in, it will initialize a new instance and will cause undefined behavior.\n */\n if (!RN_GLOBAL_OBJ.__sentry_rn_v5_registered) {\n if ('current' in navigationContainerRef) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n this._navigationContainer = navigationContainerRef.current;\n } else {\n this._navigationContainer = navigationContainerRef;\n }\n\n if (this._navigationContainer) {\n this._navigationContainer.addListener(\n '__unsafe_action__', // This action is emitted on every dispatch\n this._onDispatch.bind(this),\n );\n this._navigationContainer.addListener(\n 'state', // This action is emitted on every state change\n this._onStateChange.bind(this),\n );\n\n if (!this._initialStateHandled) {\n if (this._latestTransaction) {\n // If registerRoutingInstrumentation was called first _onDispatch has already been called\n this._onStateChange();\n\n this._initialStateHandled = true;\n } else {\n logger.log(\n '[ReactNavigationInstrumentation] Navigation container registered, but integration has not been setup yet.',\n );\n }\n }\n\n RN_GLOBAL_OBJ.__sentry_rn_v5_registered = true;\n } else {\n logger.warn('[ReactNavigationInstrumentation] Received invalid navigation container ref!');\n }\n } else {\n logger.log(\n '[ReactNavigationInstrumentation] Instrumentation already exists, but register has been called again, doing nothing.',\n );\n }\n }\n\n /**\n * To be called on every React-Navigation action dispatch.\n * It does not name the transaction or populate it with route information. Instead, it waits for the state to fully change\n * and gets the route information from there, @see _onStateChange\n */\n private _onDispatch(): void {\n if (this._latestTransaction) {\n logger.log(\n '[ReactNavigationInstrumentation] A transaction was detected that turned out to be a noop, discarding.',\n );\n this._discardLatestTransaction();\n this._clearStateChangeTimeout();\n }\n\n this._latestTransaction = this.onRouteWillChange(\n getBlankTransactionContext(ReactNavigationInstrumentation.instrumentationName),\n );\n\n this._stateChangeTimeout = setTimeout(\n this._discardLatestTransaction.bind(this),\n this._options.routeChangeTimeoutMs,\n );\n }\n\n /**\n * To be called AFTER the state has been changed to populate the transaction with the current route.\n */\n private _onStateChange(): void {\n // Use the getCurrentRoute method to be accurate.\n const previousRoute = this._latestRoute;\n\n if (!this._navigationContainer) {\n logger.warn(\n '[ReactNavigationInstrumentation] Missing navigation container ref. Route transactions will not be sent.',\n );\n\n return;\n }\n\n const route = this._navigationContainer.getCurrentRoute();\n\n if (route) {\n if (this._latestTransaction) {\n if (!previousRoute || previousRoute.key !== route.key) {\n const originalContext = this._latestTransaction.toContext() as typeof BLANK_TRANSACTION_CONTEXT;\n const routeHasBeenSeen = this._recentRouteKeys.includes(route.key);\n\n const data: RouteChangeContextData = {\n ...originalContext.data,\n route: {\n name: route.name,\n key: route.key,\n params: route.params ?? {},\n hasBeenSeen: routeHasBeenSeen,\n },\n previousRoute: previousRoute\n ? {\n name: previousRoute.name,\n key: previousRoute.key,\n params: previousRoute.params ?? {},\n }\n : null,\n };\n\n const updatedContext: ReactNavigationTransactionContext = {\n ...originalContext,\n name: route.name,\n tags: {\n ...originalContext.tags,\n 'routing.route.name': route.name,\n },\n data,\n };\n\n const finalContext = this._prepareFinalContext(updatedContext);\n this._latestTransaction.updateWithContext(finalContext);\n\n const isCustomName = updatedContext.name !== finalContext.name;\n this._latestTransaction.setName(\n finalContext.name,\n isCustomName ? customTransactionSource : defaultTransactionSource,\n );\n\n this._onConfirmRoute?.(finalContext);\n }\n\n this._pushRecentRouteKey(route.key);\n this._latestRoute = route;\n\n // Clear the latest transaction as it has been handled.\n this._latestTransaction = undefined;\n }\n }\n }\n\n /** Creates final transaction context before confirmation */\n private _prepareFinalContext(updatedContext: TransactionContext): TransactionContext {\n let finalContext = this._beforeNavigate?.({ ...updatedContext });\n\n // This block is to catch users not returning a transaction context\n if (!finalContext) {\n logger.error(\n `[ReactNavigationInstrumentation] beforeNavigate returned ${finalContext}, return context.sampled = false to not send transaction.`,\n );\n\n finalContext = {\n ...updatedContext,\n sampled: false,\n };\n }\n\n // Note: finalContext.sampled will be false at this point only if the user sets it to be so in beforeNavigate.\n if (finalContext.sampled === false) {\n logger.log(\n `[ReactNavigationInstrumentation] Will not send transaction \"${finalContext.name}\" due to beforeNavigate.`,\n );\n } else {\n // Clear the timeout so the transaction does not get cancelled.\n this._clearStateChangeTimeout();\n }\n\n return finalContext;\n }\n\n /** Pushes a recent route key, and removes earlier routes when there is greater than the max length */\n private _pushRecentRouteKey = (key: string): void => {\n this._recentRouteKeys.push(key);\n\n if (this._recentRouteKeys.length > this._maxRecentRouteLen) {\n this._recentRouteKeys = this._recentRouteKeys.slice(this._recentRouteKeys.length - this._maxRecentRouteLen);\n }\n };\n\n /** Cancels the latest transaction so it does not get sent to Sentry. */\n private _discardLatestTransaction(): void {\n if (this._latestTransaction) {\n this._latestTransaction.sampled = false;\n this._latestTransaction.finish();\n this._latestTransaction = undefined;\n }\n }\n\n /**\n *\n */\n private _clearStateChangeTimeout(): void {\n if (typeof this._stateChangeTimeout !== 'undefined') {\n clearTimeout(this._stateChangeTimeout);\n this._stateChangeTimeout = undefined;\n }\n }\n}\n\n/**\n * Backwards compatibility alias for ReactNavigationInstrumentation\n * @deprecated Use ReactNavigationInstrumentation\n */\nexport const ReactNavigationV5Instrumentation = ReactNavigationInstrumentation;\n\nexport const BLANK_TRANSACTION_CONTEXT = {\n name: 'Route Change',\n op: 'navigation',\n tags: {\n 'routing.instrumentation': ReactNavigationInstrumentation.instrumentationName,\n },\n data: {},\n};\n"]}
|
|
1
|
+
{"version":3,"file":"reactnavigation.js","sourceRoot":"","sources":["../../../src/js/tracing/reactnavigation.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,EAAE,8BAA8B,EAAE,MAAM,0BAA0B,CAAC;AAE1E,OAAO,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAC;AAyBxG,MAAM,cAAc,GAA2B;IAC7C,oBAAoB,EAAE,IAAI;CAC3B,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,OAAO,8BAA+B,SAAQ,8BAA8B;IAiBhF,YAAmB,UAA2C,EAAE;QAC9D,KAAK,EAAE,CAAC;QAfM,SAAI,GAAW,8BAA8B,CAAC,mBAAmB,CAAC;QAE1E,yBAAoB,GAA+B,IAAI,CAAC;QAE/C,uBAAkB,GAAW,GAAG,CAAC;QAI1C,yBAAoB,GAAY,KAAK,CAAC;QAEtC,qBAAgB,GAAa,EAAE,CAAC;QAsNxC,sGAAsG;QAC9F,wBAAmB,GAAG,CAAC,GAAW,EAAQ,EAAE;YAClD,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAEhC,IAAI,IAAI,CAAC,gBAAgB,CAAC,MAAM,GAAG,IAAI,CAAC,kBAAkB,EAAE;gBAC1D,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,IAAI,CAAC,gBAAgB,CAAC,MAAM,GAAG,IAAI,CAAC,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G;IACvC,IAAI,EAAE,cAAc;IACpB,EAAE,EAAE,YAAY;IAChB,IAAI,EAAE;QACJ,yBAAyB,EAAE,8BAA8B,CAAC,mBAAmB;KAC9E;IACD,IAAI,EAAE,EAAE;CACT,CAAC","sourcesContent":["/* eslint-disable max-lines */\nimport type { Transaction as TransactionType, TransactionContext } from '@sentry/types';\nimport { logger } from '@sentry/utils';\n\nimport { RN_GLOBAL_OBJ } from '../utils/worldwide';\nimport type { OnConfirmRoute, TransactionCreator } from './routingInstrumentation';\nimport { InternalRoutingInstrumentation } from './routingInstrumentation';\nimport type { BeforeNavigate, ReactNavigationTransactionContext, RouteChangeContextData } from './types';\nimport { customTransactionSource, defaultTransactionSource, getBlankTransactionContext } from './utils';\n\nexport interface NavigationRoute {\n name: string;\n key: string;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n params?: Record<string, any>;\n}\n\ninterface NavigationContainer {\n addListener: (type: string, listener: () => void) => void;\n getCurrentRoute: () => NavigationRoute;\n}\n\ninterface ReactNavigationOptions {\n /**\n * How long the instrumentation will wait for the route to mount after a change has been initiated,\n * before the transaction is discarded.\n * Time is in ms.\n *\n * Default: 1000\n */\n routeChangeTimeoutMs: number;\n}\n\nconst defaultOptions: ReactNavigationOptions = {\n routeChangeTimeoutMs: 1000,\n};\n\n/**\n * Instrumentation for React-Navigation V5 and above. See docs or sample app for usage.\n *\n * How this works:\n * - `_onDispatch` is called every time a dispatch happens and sets an IdleTransaction on the scope without any route context.\n * - `_onStateChange` is then called AFTER the state change happens due to a dispatch and sets the route context onto the active transaction.\n * - If `_onStateChange` isn't called within `STATE_CHANGE_TIMEOUT_DURATION` of the dispatch, then the transaction is not sampled and finished.\n */\nexport class ReactNavigationInstrumentation extends InternalRoutingInstrumentation {\n public static instrumentationName: string = 'react-navigation-v5';\n\n public readonly name: string = ReactNavigationInstrumentation.instrumentationName;\n\n private _navigationContainer: NavigationContainer | null = null;\n\n private readonly _maxRecentRouteLen: number = 200;\n\n private _latestRoute?: NavigationRoute;\n private _latestTransaction?: TransactionType;\n private _initialStateHandled: boolean = false;\n private _stateChangeTimeout?: number | undefined;\n private _recentRouteKeys: string[] = [];\n\n private _options: ReactNavigationOptions;\n\n public constructor(options: Partial<ReactNavigationOptions> = {}) {\n super();\n\n this._options = {\n ...defaultOptions,\n ...options,\n };\n }\n\n /**\n * Extends by calling _handleInitialState at the end.\n */\n public registerRoutingInstrumentation(\n listener: TransactionCreator,\n beforeNavigate: BeforeNavigate,\n onConfirmRoute: OnConfirmRoute,\n ): void {\n super.registerRoutingInstrumentation(listener, beforeNavigate, onConfirmRoute);\n\n // We create an initial state here to ensure a transaction gets created before the first route mounts.\n if (!this._initialStateHandled) {\n this._onDispatch();\n if (this._navigationContainer) {\n // Navigation container already registered, just populate with route state\n this._onStateChange();\n\n this._initialStateHandled = true;\n }\n }\n }\n\n /**\n * Pass the ref to the navigation container to register it to the instrumentation\n * @param navigationContainerRef Ref to a `NavigationContainer`\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types\n public registerNavigationContainer(navigationContainerRef: any): void {\n /* We prevent duplicate routing instrumentation to be initialized on fast refreshes\n\n Explanation: If the user triggers a fast refresh on the file that the instrumentation is\n initialized in, it will initialize a new instance and will cause undefined behavior.\n */\n if (!RN_GLOBAL_OBJ.__sentry_rn_v5_registered) {\n if ('current' in navigationContainerRef) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n this._navigationContainer = navigationContainerRef.current;\n } else {\n this._navigationContainer = navigationContainerRef;\n }\n\n if (this._navigationContainer) {\n this._navigationContainer.addListener(\n '__unsafe_action__', // This action is emitted on every dispatch\n this._onDispatch.bind(this),\n );\n this._navigationContainer.addListener(\n 'state', // This action is emitted on every state change\n this._onStateChange.bind(this),\n );\n\n if (!this._initialStateHandled) {\n if (this._latestTransaction) {\n // If registerRoutingInstrumentation was called first _onDispatch has already been called\n this._onStateChange();\n\n this._initialStateHandled = true;\n } else {\n logger.log(\n '[ReactNavigationInstrumentation] Navigation container registered, but integration has not been setup yet.',\n );\n }\n }\n\n RN_GLOBAL_OBJ.__sentry_rn_v5_registered = true;\n } else {\n logger.warn('[ReactNavigationInstrumentation] Received invalid navigation container ref!');\n }\n } else {\n logger.log(\n '[ReactNavigationInstrumentation] Instrumentation already exists, but register has been called again, doing nothing.',\n );\n }\n }\n\n /**\n * To be called on every React-Navigation action dispatch.\n * It does not name the transaction or populate it with route information. Instead, it waits for the state to fully change\n * and gets the route information from there, @see _onStateChange\n */\n private _onDispatch(): void {\n if (this._latestTransaction) {\n logger.log(\n '[ReactNavigationInstrumentation] A transaction was detected that turned out to be a noop, discarding.',\n );\n this._discardLatestTransaction();\n this._clearStateChangeTimeout();\n }\n\n this._latestTransaction = this.onRouteWillChange(\n getBlankTransactionContext(ReactNavigationInstrumentation.instrumentationName),\n );\n\n this._stateChangeTimeout = setTimeout(\n this._discardLatestTransaction.bind(this),\n this._options.routeChangeTimeoutMs,\n );\n }\n\n /**\n * To be called AFTER the state has been changed to populate the transaction with the current route.\n */\n private _onStateChange(): void {\n // Use the getCurrentRoute method to be accurate.\n const previousRoute = this._latestRoute;\n\n if (!this._navigationContainer) {\n logger.warn(\n '[ReactNavigationInstrumentation] Missing navigation container ref. Route transactions will not be sent.',\n );\n\n return;\n }\n\n const route = this._navigationContainer.getCurrentRoute();\n\n if (route) {\n if (this._latestTransaction) {\n if (!previousRoute || previousRoute.key !== route.key) {\n const originalContext = this._latestTransaction.toContext() as typeof BLANK_TRANSACTION_CONTEXT;\n const routeHasBeenSeen = this._recentRouteKeys.includes(route.key);\n\n const data: RouteChangeContextData = {\n ...originalContext.data,\n route: {\n name: route.name,\n key: route.key,\n // TODO: filter PII params instead of dropping them all\n params: {},\n hasBeenSeen: routeHasBeenSeen,\n },\n previousRoute: previousRoute\n ? {\n name: previousRoute.name,\n key: previousRoute.key,\n // TODO: filter PII params instead of dropping them all\n params: {},\n }\n : null,\n };\n\n const updatedContext: ReactNavigationTransactionContext = {\n ...originalContext,\n name: route.name,\n tags: {\n ...originalContext.tags,\n 'routing.route.name': route.name,\n },\n data,\n };\n\n const finalContext = this._prepareFinalContext(updatedContext);\n this._latestTransaction.updateWithContext(finalContext);\n\n const isCustomName = updatedContext.name !== finalContext.name;\n this._latestTransaction.setName(\n finalContext.name,\n isCustomName ? customTransactionSource : defaultTransactionSource,\n );\n\n this._onConfirmRoute?.(finalContext);\n }\n\n this._pushRecentRouteKey(route.key);\n this._latestRoute = route;\n\n // Clear the latest transaction as it has been handled.\n this._latestTransaction = undefined;\n }\n }\n }\n\n /** Creates final transaction context before confirmation */\n private _prepareFinalContext(updatedContext: TransactionContext): TransactionContext {\n let finalContext = this._beforeNavigate?.({ ...updatedContext });\n\n // This block is to catch users not returning a transaction context\n if (!finalContext) {\n logger.error(\n `[ReactNavigationInstrumentation] beforeNavigate returned ${finalContext}, return context.sampled = false to not send transaction.`,\n );\n\n finalContext = {\n ...updatedContext,\n sampled: false,\n };\n }\n\n // Note: finalContext.sampled will be false at this point only if the user sets it to be so in beforeNavigate.\n if (finalContext.sampled === false) {\n logger.log(\n `[ReactNavigationInstrumentation] Will not send transaction \"${finalContext.name}\" due to beforeNavigate.`,\n );\n } else {\n // Clear the timeout so the transaction does not get cancelled.\n this._clearStateChangeTimeout();\n }\n\n return finalContext;\n }\n\n /** Pushes a recent route key, and removes earlier routes when there is greater than the max length */\n private _pushRecentRouteKey = (key: string): void => {\n this._recentRouteKeys.push(key);\n\n if (this._recentRouteKeys.length > this._maxRecentRouteLen) {\n this._recentRouteKeys = this._recentRouteKeys.slice(this._recentRouteKeys.length - this._maxRecentRouteLen);\n }\n };\n\n /** Cancels the latest transaction so it does not get sent to Sentry. */\n private _discardLatestTransaction(): void {\n if (this._latestTransaction) {\n this._latestTransaction.sampled = false;\n this._latestTransaction.finish();\n this._latestTransaction = undefined;\n }\n }\n\n /**\n *\n */\n private _clearStateChangeTimeout(): void {\n if (typeof this._stateChangeTimeout !== 'undefined') {\n clearTimeout(this._stateChangeTimeout);\n this._stateChangeTimeout = undefined;\n }\n }\n}\n\n/**\n * Backwards compatibility alias for ReactNavigationInstrumentation\n * @deprecated Use ReactNavigationInstrumentation\n */\nexport const ReactNavigationV5Instrumentation = ReactNavigationInstrumentation;\n\nexport const BLANK_TRANSACTION_CONTEXT = {\n name: 'Route Change',\n op: 'navigation',\n tags: {\n 'routing.instrumentation': ReactNavigationInstrumentation.instrumentationName,\n },\n data: {},\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactnavigationv4.d.ts","sourceRoot":"","sources":["../../../src/js/tracing/reactnavigationv4.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAe,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAIrE,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AACnF,OAAO,EAAE,8BAA8B,EAAE,MAAM,0BAA0B,CAAC;AAC1E,OAAO,KAAK,EAAE,cAAc,EAA6D,MAAM,SAAS,CAAC;AAGzG,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;IAEZ,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC9B;AAED,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,eAAe,EAAE,OAAO,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,CAAC,iBAAiB,GAAG,iBAAiB,CAAC,EAAE,CAAC;CACnD;AAED,MAAM,WAAW,oBAAoB;IACnC,WAAW,EAAE;QACX,KAAK,EAAE,iBAAiB,CAAC;QACzB,MAAM,EAAE;YACN,iBAAiB,EAAE,CAEjB,MAAM,EAAE,GAAG,EACX,KAAK,EAAE,iBAAiB,KACrB,iBAAiB,CAAC;SACxB,CAAC;K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,EAAE,kBAAkB,EAC5B,cAAc,EAAE,cAAc,EAC9B,cAAc,EAAE,cAAc,GAC7B,IAAI;IAmBP;;;OAGG;IAEI,oBAAoB,CAAC,eAAe,EAAE,GAAG,GAAG,IAAI;IAmCvD;;OAEG;IACH,OAAO,CAAC,wBAAwB;IAchC;;;OAGG;IACH,OAAO,CAAC,YAAY;IAcpB;;OAEG;IACH,OAAO,CAAC,cAAc;IA4CtB,4DAA4D;IAC5D,OAAO,CAAC,oBAAoB;IAsB5B;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAiC9B;;OAEG;IACH,OAAO,CAAC,yBAAyB;IAejC,sGAAsG;IACtG,OAAO,CAAC,mBAAmB,CAMzB;IAEF,6EAA6E;IAC7E,OAAO,CAAC,2BAA2B,CAIjC;IAEF,wEAAwE;IACxE,OAAO,CAAC,yBAAyB;CAOlC;AAED,QAAA,MAAM,8BAA8B,EAAE,kBAUrC,CAAC;AAEF,OAAO,EAAE,gCAAgC,EAAE,8BAA8B,EAAE,CAAC"}
|
|
@@ -164,19 +164,20 @@ class ReactNavigationV4Instrumentation extends InternalRoutingInstrumentation {
|
|
|
164
164
|
* Gets the transaction context for a `NavigationRouteV4`
|
|
165
165
|
*/
|
|
166
166
|
_getTransactionContext(route, previousRoute) {
|
|
167
|
-
var _a, _b;
|
|
168
167
|
const data = {
|
|
169
168
|
route: {
|
|
170
169
|
name: route.routeName,
|
|
171
170
|
key: route.key,
|
|
172
|
-
|
|
171
|
+
// TODO: filter PII params instead of dropping them all
|
|
172
|
+
params: {},
|
|
173
173
|
hasBeenSeen: this._recentRouteKeys.includes(route.key),
|
|
174
174
|
},
|
|
175
175
|
previousRoute: previousRoute
|
|
176
176
|
? {
|
|
177
177
|
name: previousRoute.routeName,
|
|
178
178
|
key: previousRoute.key,
|
|
179
|
-
|
|
179
|
+
// TODO: filter PII params instead of dropping them all
|
|
180
|
+
params: {},
|
|
180
181
|
}
|
|
181
182
|
: null,
|
|
182
183
|
};
|
|
@@ -1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I,WAAW;YACvB,OAAO,WAAW,CAAC,KAAK,KAAK,QAAQ;YACrC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,EACjC;YACA,OAAO,IAAI,CAAC,yBAAyB,CAAC,WAAW,CAAC,CAAC;SACpD;QAED,OAAO,WAAgC,CAAC;IAC1C,CAAC;IAkBD,wEAAwE;IAChE,yBAAyB;QAC/B,IAAI,IAAI,CAAC,kBAAkB,EAAE;YAC3B,IAAI,CAAC,kBAAkB,CAAC,OAAO,GAAG,KAAK,CAAC;YACxC,IAAI,CAAC,kBAAkB,CAAC,MAAM,EAAE,CAAC;YACjC,IAAI,CAAC,kBAAkB,GAAG,SAAS,CAAC;SACrC;IACH,CAAC;;AAhRa,oDAAmB,GAAW,qBAAqB,CAAC;AAmRpE,MAAM,8BAA8B,GAAuB;IACzD,IAAI,EAAE,YAAY;IAClB,EAAE,EAAE,YAAY;IAChB,IAAI,EAAE;QACJ,yBAAyB,EAAE,gCAAgC,CAAC,mBAAmB;KAChF;IACD,IAAI,EAAE,EAAE;IACR,QAAQ,EAAE;QACR,MAAM,EAAE,MAAM;KACf;CACF,CAAC;AAEF,OAAO,EAAE,gCAAgC,EAAE,8BAA8B,EAAE,CAAC","sourcesContent":["/* eslint-disable max-lines */\nimport type { Transaction, TransactionContext } from '@sentry/types';\nimport { logger } from '@sentry/utils';\n\nimport { RN_GLOBAL_OBJ } from '../utils/worldwide';\nimport type { OnConfirmRoute, TransactionCreator } from './routingInstrumentation';\nimport { InternalRoutingInstrumentation } from './routingInstrumentation';\nimport type { BeforeNavigate, ReactNavigationTransactionContext, RouteChangeContextData } from './types';\nimport { customTransactionSource, defaultTransactionSource } from './utils';\n\nexport interface NavigationRouteV4 {\n routeName: string;\n key: string;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n params?: Record<string, any>;\n}\n\nexport interface NavigationStateV4 {\n index: number;\n key: string;\n isTransitioning: boolean;\n routeName?: string;\n routes: (NavigationRouteV4 | NavigationStateV4)[];\n}\n\nexport interface AppContainerInstance {\n _navigation: {\n state: NavigationStateV4;\n router: {\n getStateForAction: (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n action: any,\n state: NavigationStateV4,\n ) => NavigationStateV4;\n };\n };\n}\n\ninterface ReactNavigationV4Options {\n /**\n * How long the instrumentation will wait for the route to mount after a change has been initiated,\n * before the transaction is discarded.\n * Time is in ms.\n *\n * Default: 1000\n */\n routeChangeTimeoutMs: number;\n}\n\nconst defaultOptions: ReactNavigationV4Options = {\n routeChangeTimeoutMs: 1000,\n};\n\n/**\n * Instrumentation for React-Navigation V4.\n * Register the app container with `registerAppContainer` to use, or see docs for more details.\n */\nclass ReactNavigationV4Instrumentation extends InternalRoutingInstrumentation {\n public static instrumentationName: string = 'react-navigation-v4';\n\n public readonly name: string = ReactNavigationV4Instrumentation.instrumentationName;\n\n private _appContainer: AppContainerInstance | null = null;\n\n private readonly _maxRecentRouteLen: number = 200;\n\n private _prevRoute?: NavigationRouteV4;\n private _recentRouteKeys: string[] = [];\n\n private _latestTransaction?: Transaction;\n private _initialStateHandled: boolean = false;\n private _stateChangeTimeout?: number | undefined;\n\n private _options: ReactNavigationV4Options;\n\n public constructor(options: Partial<ReactNavigationV4Options> = {}) {\n super();\n\n this._options = {\n ...defaultOptions,\n ...options,\n };\n }\n\n /**\n * Extends by calling _handleInitialState at the end.\n */\n public registerRoutingInstrumentation(\n listener: TransactionCreator,\n beforeNavigate: BeforeNavigate,\n onConfirmRoute: OnConfirmRoute,\n ): void {\n super.registerRoutingInstrumentation(listener, beforeNavigate, onConfirmRoute);\n\n // Need to handle the initial state as the router patch will only attach transactions on subsequent route changes.\n if (!this._initialStateHandled) {\n this._latestTransaction = this.onRouteWillChange(INITIAL_TRANSACTION_CONTEXT_V4);\n if (this._appContainer) {\n this._updateLatestTransaction();\n\n this._initialStateHandled = true;\n } else {\n this._stateChangeTimeout = setTimeout(\n this._discardLatestTransaction.bind(this),\n this._options.routeChangeTimeoutMs,\n );\n }\n }\n }\n\n /**\n * Pass the ref to the app container to register it to the instrumentation\n * @param appContainerRef Ref to an `AppContainer`\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types\n public registerAppContainer(appContainerRef: any): void {\n /* We prevent duplicate routing instrumentation to be initialized on fast refreshes\n\n Explanation: If the user triggers a fast refresh on the file that the instrumentation is\n initialized in, it will initialize a new instance and will cause undefined behavior.\n */\n if (!RN_GLOBAL_OBJ.__sentry_rn_v4_registered) {\n if ('current' in appContainerRef) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n this._appContainer = appContainerRef.current;\n } else {\n this._appContainer = appContainerRef;\n }\n\n if (this._appContainer) {\n this._patchRouter();\n\n if (!this._initialStateHandled) {\n if (this._latestTransaction) {\n this._updateLatestTransaction();\n } else {\n logger.log(\n '[ReactNavigationV4Instrumentation] App container registered, but integration has not been setup yet.',\n );\n }\n this._initialStateHandled = true;\n }\n\n RN_GLOBAL_OBJ.__sentry_rn_v4_registered = true;\n } else {\n logger.warn('[ReactNavigationV4Instrumentation] Received invalid app container ref!');\n }\n }\n }\n\n /**\n * Updates the latest transaction with the current state and calls beforeNavigate.\n */\n private _updateLatestTransaction(): void {\n // We can assume the ref is present as this is called from registerAppContainer\n if (this._appContainer && this._latestTransaction) {\n const state = this._appContainer._navigation.state;\n\n if (typeof this._stateChangeTimeout !== 'undefined') {\n clearTimeout(this._stateChangeTimeout);\n this._stateChangeTimeout = undefined;\n }\n\n this._onStateChange(state, true);\n }\n }\n\n /**\n * Patches the react navigation router so we can listen to the route changes and attach the `IdleTransaction` before the\n * new screen is mounted.\n */\n private _patchRouter(): void {\n if (this._appContainer) {\n const originalGetStateForAction = this._appContainer._navigation.router.getStateForAction;\n\n this._appContainer._navigation.router.getStateForAction = (action, state) => {\n const newState = originalGetStateForAction(action, state);\n\n this._onStateChange(newState);\n\n return newState;\n };\n }\n }\n\n /**\n * To be called on navigation state changes and creates the transaction.\n */\n private _onStateChange(state: NavigationStateV4 | undefined, updateLatestTransaction: boolean = false): void {\n // it's not guaranteed that a state is always produced.\n // see: https://github.com/react-navigation/react-navigation/blob/45d419be93c34e900e8734ce98321ae875ac4997/packages/core/src/routers/SwitchRouter.js?rgh-link-date=2021-09-25T12%3A43%3A36Z#L301\n if (!state || state === undefined) {\n logger.warn('[ReactNavigationV4Instrumentation] onStateChange called without a valid state.');\n\n return;\n }\n\n const currentRoute = this._getCurrentRouteFromState(state);\n\n // If the route is a different key, this is so we ignore actions that pertain to the same screen.\n if (!this._prevRoute || currentRoute.key !== this._prevRoute.key) {\n const originalContext = this._getTransactionContext(currentRoute, this._prevRoute);\n\n let mergedContext = originalContext;\n if (updateLatestTransaction && this._latestTransaction) {\n mergedContext = {\n ...this._latestTransaction.toContext(),\n ...originalContext,\n };\n }\n\n const finalContext = this._prepareFinalContext(mergedContext);\n\n if (updateLatestTransaction && this._latestTransaction) {\n // Update the latest transaction instead of calling onRouteWillChange\n this._latestTransaction.updateWithContext(finalContext);\n const isCustomName = mergedContext.name !== finalContext.name;\n this._latestTransaction.setName(\n finalContext.name,\n isCustomName ? customTransactionSource : defaultTransactionSource,\n );\n } else {\n this._latestTransaction = this.onRouteWillChange(finalContext);\n }\n\n this._onConfirmRoute?.(finalContext);\n\n this._pushRecentRouteKey(currentRoute.key);\n this._prevRoute = currentRoute;\n }\n }\n\n /** Creates final transaction context before confirmation */\n private _prepareFinalContext(mergedContext: TransactionContext): TransactionContext {\n let finalContext = this._beforeNavigate?.({ ...mergedContext });\n\n // This block is to catch users not returning a transaction context\n if (!finalContext) {\n logger.error(\n `[ReactNavigationV4Instrumentation] beforeNavigate returned ${finalContext}, return context.sampled = false to not send transaction.`,\n );\n\n finalContext = {\n ...mergedContext,\n sampled: false,\n };\n }\n\n if (finalContext.sampled === false) {\n this._onBeforeNavigateNotSampled(finalContext.name);\n }\n\n return finalContext;\n }\n\n /**\n * Gets the transaction context for a `NavigationRouteV4`\n */\n private _getTransactionContext(\n route: NavigationRouteV4,\n previousRoute?: NavigationRouteV4,\n ): ReactNavigationTransactionContext {\n const data: RouteChangeContextData = {\n route: {\n name: route.routeName, // Include name here too for use in `beforeNavigate`\n key: route.key,\n params: route.params ?? {},\n hasBeenSeen: this._recentRouteKeys.includes(route.key),\n },\n previousRoute: previousRoute\n ? {\n name: previousRoute.routeName,\n key: previousRoute.key,\n params: previousRoute.params ?? {},\n }\n : null,\n };\n\n return {\n name: route.routeName,\n op: 'navigation',\n tags: {\n 'routing.instrumentation': ReactNavigationV4Instrumentation.instrumentationName,\n 'routing.route.name': route.routeName,\n },\n data,\n };\n }\n\n /**\n * Gets the current route given a navigation state\n */\n private _getCurrentRouteFromState(state: NavigationStateV4): NavigationRouteV4 {\n const parentRoute = state.routes[state.index];\n\n if (\n 'index' in parentRoute &&\n 'routes' in parentRoute &&\n typeof parentRoute.index === 'number' &&\n Array.isArray(parentRoute.routes)\n ) {\n return this._getCurrentRouteFromState(parentRoute);\n }\n\n return parentRoute as NavigationRouteV4;\n }\n\n /** Pushes a recent route key, and removes earlier routes when there is greater than the max length */\n private _pushRecentRouteKey = (key: string): void => {\n this._recentRouteKeys.push(key);\n\n if (this._recentRouteKeys.length > this._maxRecentRouteLen) {\n this._recentRouteKeys = this._recentRouteKeys.slice(this._recentRouteKeys.length - this._maxRecentRouteLen);\n }\n };\n\n /** Helper to log a transaction that was not sampled due to beforeNavigate */\n private _onBeforeNavigateNotSampled = (transactionName: string): void => {\n logger.log(\n `[ReactNavigationV4Instrumentation] Will not send transaction \"${transactionName}\" due to beforeNavigate.`,\n );\n };\n\n /** Cancels the latest transaction so it does not get sent to Sentry. */\n private _discardLatestTransaction(): void {\n if (this._latestTransaction) {\n this._latestTransaction.sampled = false;\n this._latestTransaction.finish();\n this._latestTransaction = undefined;\n }\n }\n}\n\nconst INITIAL_TRANSACTION_CONTEXT_V4: TransactionContext = {\n name: 'App Launch',\n op: 'navigation',\n tags: {\n 'routing.instrumentation': ReactNavigationV4Instrumentation.instrumentationName,\n },\n data: {},\n metadata: {\n source: 'view',\n },\n};\n\nexport { ReactNavigationV4Instrumentation, INITIAL_TRANSACTION_CONTEXT_V4 };\n"]}
|
|
1
|
+
{"version":3,"file":"reactnavigationv4.js","sourceRoot":"","sources":["../../../src/js/tracing/reactnavigationv4.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,EAAE,8BAA8B,EAAE,MAAM,0BAA0B,CAAC;AAE1E,OAAO,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAyC5E,MAAM,cAAc,GAA6B;IAC/C,oBAAoB,EAAE,IAAI;CAC3B,CAAC;AAEF;;;GAGG;AACH,MAAM,gCAAiC,SAAQ,8BAA8B;IAkB3E,YAAmB,UAA6C,EAAE;QAChE,KAAK,EAAE,CAAC;QAhBM,SAAI,GAAW,gCAAgC,CAAC,mBAAmB,CAAC;QAE5E,kBAAa,GAAgC,IAAI,CAAC;QAEzC,uBAAkB,GAAW,GAAG,CAAC;QAG1C,qBAAgB,GAAa,EAAE,CAAC;QAGhC,yBAAoB,GAAY,KAAK,CAAC;QA+O9C,sGAAsG;QAC9F,wBAAmB,GAAG,CAAC,GAAW,EAAQ,EAAE;YAClD,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAEhC,IAAI,IAAI,CAAC,gBAAgB,CAAC,MAAM,GAAG,IAAI,CAAC,kBAAkB,EAAE;gBAC1D,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,IAAI,CAAC,gBAAgB,CAAC,MAAM,GAAG,IAAI,CAAC,kBAAkB,CAAC,CAAC;aAC7G;QACH,CAAC,CAAC;QAEF,6EAA6E;QACrE,gCAA2B,GAAG,CAAC,eAAuB,EAAQ,EAAE;YACtE,MAAM,CAAC,G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K,CAAC,CAAC;QAE9C,IACE,OAAO,IAAI,WAAW;YACtB,QAAQ,IAAI,WAAW;YACvB,OAAO,WAAW,CAAC,KAAK,KAAK,QAAQ;YACrC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,EACjC;YACA,OAAO,IAAI,CAAC,yBAAyB,CAAC,WAAW,CAAC,CAAC;SACpD;QAED,OAAO,WAAgC,CAAC;IAC1C,CAAC;IAkBD,wEAAwE;IAChE,yBAAyB;QAC/B,IAAI,IAAI,CAAC,kBAAkB,EAAE;YAC3B,IAAI,CAAC,kBAAkB,CAAC,OAAO,GAAG,KAAK,CAAC;YACxC,IAAI,CAAC,kBAAkB,CAAC,MAAM,EAAE,CAAC;YACjC,IAAI,CAAC,kBAAkB,GAAG,SAAS,CAAC;SACrC;IACH,CAAC;;AAlRa,oDAAmB,GAAW,qBAAqB,CAAC;AAqRpE,MAAM,8BAA8B,GAAuB;IACzD,IAAI,EAAE,YAAY;IAClB,EAAE,EAAE,YAAY;IAChB,IAAI,EAAE;QACJ,yBAAyB,EAAE,gCAAgC,CAAC,mBAAmB;KAChF;IACD,IAAI,EAAE,EAAE;IACR,QAAQ,EAAE;QACR,MAAM,EAAE,MAAM;KACf;CACF,CAAC;AAEF,OAAO,EAAE,gCAAgC,EAAE,8BAA8B,EAAE,CAAC","sourcesContent":["/* eslint-disable max-lines */\nimport type { Transaction, TransactionContext } from '@sentry/types';\nimport { logger } from '@sentry/utils';\n\nimport { RN_GLOBAL_OBJ } from '../utils/worldwide';\nimport type { OnConfirmRoute, TransactionCreator } from './routingInstrumentation';\nimport { InternalRoutingInstrumentation } from './routingInstrumentation';\nimport type { BeforeNavigate, ReactNavigationTransactionContext, RouteChangeContextData } from './types';\nimport { customTransactionSource, defaultTransactionSource } from './utils';\n\nexport interface NavigationRouteV4 {\n routeName: string;\n key: string;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n params?: Record<string, any>;\n}\n\nexport interface NavigationStateV4 {\n index: number;\n key: string;\n isTransitioning: boolean;\n routeName?: string;\n routes: (NavigationRouteV4 | NavigationStateV4)[];\n}\n\nexport interface AppContainerInstance {\n _navigation: {\n state: NavigationStateV4;\n router: {\n getStateForAction: (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n action: any,\n state: NavigationStateV4,\n ) => NavigationStateV4;\n };\n };\n}\n\ninterface ReactNavigationV4Options {\n /**\n * How long the instrumentation will wait for the route to mount after a change has been initiated,\n * before the transaction is discarded.\n * Time is in ms.\n *\n * Default: 1000\n */\n routeChangeTimeoutMs: number;\n}\n\nconst defaultOptions: ReactNavigationV4Options = {\n routeChangeTimeoutMs: 1000,\n};\n\n/**\n * Instrumentation for React-Navigation V4.\n * Register the app container with `registerAppContainer` to use, or see docs for more details.\n */\nclass ReactNavigationV4Instrumentation extends InternalRoutingInstrumentation {\n public static instrumentationName: string = 'react-navigation-v4';\n\n public readonly name: string = ReactNavigationV4Instrumentation.instrumentationName;\n\n private _appContainer: AppContainerInstance | null = null;\n\n private readonly _maxRecentRouteLen: number = 200;\n\n private _prevRoute?: NavigationRouteV4;\n private _recentRouteKeys: string[] = [];\n\n private _latestTransaction?: Transaction;\n private _initialStateHandled: boolean = false;\n private _stateChangeTimeout?: number | undefined;\n\n private _options: ReactNavigationV4Options;\n\n public constructor(options: Partial<ReactNavigationV4Options> = {}) {\n super();\n\n this._options = {\n ...defaultOptions,\n ...options,\n };\n }\n\n /**\n * Extends by calling _handleInitialState at the end.\n */\n public registerRoutingInstrumentation(\n listener: TransactionCreator,\n beforeNavigate: BeforeNavigate,\n onConfirmRoute: OnConfirmRoute,\n ): void {\n super.registerRoutingInstrumentation(listener, beforeNavigate, onConfirmRoute);\n\n // Need to handle the initial state as the router patch will only attach transactions on subsequent route changes.\n if (!this._initialStateHandled) {\n this._latestTransaction = this.onRouteWillChange(INITIAL_TRANSACTION_CONTEXT_V4);\n if (this._appContainer) {\n this._updateLatestTransaction();\n\n this._initialStateHandled = true;\n } else {\n this._stateChangeTimeout = setTimeout(\n this._discardLatestTransaction.bind(this),\n this._options.routeChangeTimeoutMs,\n );\n }\n }\n }\n\n /**\n * Pass the ref to the app container to register it to the instrumentation\n * @param appContainerRef Ref to an `AppContainer`\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types\n public registerAppContainer(appContainerRef: any): void {\n /* We prevent duplicate routing instrumentation to be initialized on fast refreshes\n\n Explanation: If the user triggers a fast refresh on the file that the instrumentation is\n initialized in, it will initialize a new instance and will cause undefined behavior.\n */\n if (!RN_GLOBAL_OBJ.__sentry_rn_v4_registered) {\n if ('current' in appContainerRef) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n this._appContainer = appContainerRef.current;\n } else {\n this._appContainer = appContainerRef;\n }\n\n if (this._appContainer) {\n this._patchRouter();\n\n if (!this._initialStateHandled) {\n if (this._latestTransaction) {\n this._updateLatestTransaction();\n } else {\n logger.log(\n '[ReactNavigationV4Instrumentation] App container registered, but integration has not been setup yet.',\n );\n }\n this._initialStateHandled = true;\n }\n\n RN_GLOBAL_OBJ.__sentry_rn_v4_registered = true;\n } else {\n logger.warn('[ReactNavigationV4Instrumentation] Received invalid app container ref!');\n }\n }\n }\n\n /**\n * Updates the latest transaction with the current state and calls beforeNavigate.\n */\n private _updateLatestTransaction(): void {\n // We can assume the ref is present as this is called from registerAppContainer\n if (this._appContainer && this._latestTransaction) {\n const state = this._appContainer._navigation.state;\n\n if (typeof this._stateChangeTimeout !== 'undefined') {\n clearTimeout(this._stateChangeTimeout);\n this._stateChangeTimeout = undefined;\n }\n\n this._onStateChange(state, true);\n }\n }\n\n /**\n * Patches the react navigation router so we can listen to the route changes and attach the `IdleTransaction` before the\n * new screen is mounted.\n */\n private _patchRouter(): void {\n if (this._appContainer) {\n const originalGetStateForAction = this._appContainer._navigation.router.getStateForAction;\n\n this._appContainer._navigation.router.getStateForAction = (action, state) => {\n const newState = originalGetStateForAction(action, state);\n\n this._onStateChange(newState);\n\n return newState;\n };\n }\n }\n\n /**\n * To be called on navigation state changes and creates the transaction.\n */\n private _onStateChange(state: NavigationStateV4 | undefined, updateLatestTransaction: boolean = false): void {\n // it's not guaranteed that a state is always produced.\n // see: https://github.com/react-navigation/react-navigation/blob/45d419be93c34e900e8734ce98321ae875ac4997/packages/core/src/routers/SwitchRouter.js?rgh-link-date=2021-09-25T12%3A43%3A36Z#L301\n if (!state || state === undefined) {\n logger.warn('[ReactNavigationV4Instrumentation] onStateChange called without a valid state.');\n\n return;\n }\n\n const currentRoute = this._getCurrentRouteFromState(state);\n\n // If the route is a different key, this is so we ignore actions that pertain to the same screen.\n if (!this._prevRoute || currentRoute.key !== this._prevRoute.key) {\n const originalContext = this._getTransactionContext(currentRoute, this._prevRoute);\n\n let mergedContext = originalContext;\n if (updateLatestTransaction && this._latestTransaction) {\n mergedContext = {\n ...this._latestTransaction.toContext(),\n ...originalContext,\n };\n }\n\n const finalContext = this._prepareFinalContext(mergedContext);\n\n if (updateLatestTransaction && this._latestTransaction) {\n // Update the latest transaction instead of calling onRouteWillChange\n this._latestTransaction.updateWithContext(finalContext);\n const isCustomName = mergedContext.name !== finalContext.name;\n this._latestTransaction.setName(\n finalContext.name,\n isCustomName ? customTransactionSource : defaultTransactionSource,\n );\n } else {\n this._latestTransaction = this.onRouteWillChange(finalContext);\n }\n\n this._onConfirmRoute?.(finalContext);\n\n this._pushRecentRouteKey(currentRoute.key);\n this._prevRoute = currentRoute;\n }\n }\n\n /** Creates final transaction context before confirmation */\n private _prepareFinalContext(mergedContext: TransactionContext): TransactionContext {\n let finalContext = this._beforeNavigate?.({ ...mergedContext });\n\n // This block is to catch users not returning a transaction context\n if (!finalContext) {\n logger.error(\n `[ReactNavigationV4Instrumentation] beforeNavigate returned ${finalContext}, return context.sampled = false to not send transaction.`,\n );\n\n finalContext = {\n ...mergedContext,\n sampled: false,\n };\n }\n\n if (finalContext.sampled === false) {\n this._onBeforeNavigateNotSampled(finalContext.name);\n }\n\n return finalContext;\n }\n\n /**\n * Gets the transaction context for a `NavigationRouteV4`\n */\n private _getTransactionContext(\n route: NavigationRouteV4,\n previousRoute?: NavigationRouteV4,\n ): ReactNavigationTransactionContext {\n const data: RouteChangeContextData = {\n route: {\n name: route.routeName, // Include name here too for use in `beforeNavigate`\n key: route.key,\n // TODO: filter PII params instead of dropping them all\n params: {},\n hasBeenSeen: this._recentRouteKeys.includes(route.key),\n },\n previousRoute: previousRoute\n ? {\n name: previousRoute.routeName,\n key: previousRoute.key,\n // TODO: filter PII params instead of dropping them all\n params: {},\n }\n : null,\n };\n\n return {\n name: route.routeName,\n op: 'navigation',\n tags: {\n 'routing.instrumentation': ReactNavigationV4Instrumentation.instrumentationName,\n 'routing.route.name': route.routeName,\n },\n data,\n };\n }\n\n /**\n * Gets the current route given a navigation state\n */\n private _getCurrentRouteFromState(state: NavigationStateV4): NavigationRouteV4 {\n const parentRoute = state.routes[state.index];\n\n if (\n 'index' in parentRoute &&\n 'routes' in parentRoute &&\n typeof parentRoute.index === 'number' &&\n Array.isArray(parentRoute.routes)\n ) {\n return this._getCurrentRouteFromState(parentRoute);\n }\n\n return parentRoute as NavigationRouteV4;\n }\n\n /** Pushes a recent route key, and removes earlier routes when there is greater than the max length */\n private _pushRecentRouteKey = (key: string): void => {\n this._recentRouteKeys.push(key);\n\n if (this._recentRouteKeys.length > this._maxRecentRouteLen) {\n this._recentRouteKeys = this._recentRouteKeys.slice(this._recentRouteKeys.length - this._maxRecentRouteLen);\n }\n };\n\n /** Helper to log a transaction that was not sampled due to beforeNavigate */\n private _onBeforeNavigateNotSampled = (transactionName: string): void => {\n logger.log(\n `[ReactNavigationV4Instrumentation] Will not send transaction \"${transactionName}\" due to beforeNavigate.`,\n );\n };\n\n /** Cancels the latest transaction so it does not get sent to Sentry. */\n private _discardLatestTransaction(): void {\n if (this._latestTransaction) {\n this._latestTransaction.sampled = false;\n this._latestTransaction.finish();\n this._latestTransaction = undefined;\n }\n }\n}\n\nconst INITIAL_TRANSACTION_CONTEXT_V4: TransactionContext = {\n name: 'App Launch',\n op: 'navigation',\n tags: {\n 'routing.instrumentation': ReactNavigationV4Instrumentation.instrumentationName,\n },\n data: {},\n metadata: {\n source: 'view',\n },\n};\n\nexport { ReactNavigationV4Instrumentation, INITIAL_TRANSACTION_CONTEXT_V4 };\n"]}
|
|
@@ -8,6 +8,14 @@ export declare function isFabricEnabled(): boolean;
|
|
|
8
8
|
export declare function getReactNativeVersion(): string | undefined;
|
|
9
9
|
/** Checks if Expo is present in the runtime */
|
|
10
10
|
export declare function isExpo(): boolean;
|
|
11
|
+
/** Check if JS runs in Expo Go */
|
|
12
|
+
export declare function isExpoGo(): boolean;
|
|
13
|
+
/** Check Expo Go version if available */
|
|
14
|
+
export declare function getExpoGoVersion(): string | undefined;
|
|
15
|
+
/** Returns Expo SDK version if available */
|
|
16
|
+
export declare function getExpoSdkVersion(): string | undefined;
|
|
17
|
+
/** Checks if the current platform is not web */
|
|
18
|
+
export declare function notWeb(): boolean;
|
|
11
19
|
/** Returns Hermes Version if hermes is present in the runtime */
|
|
12
20
|
export declare function getHermesVersion(): string | undefined;
|
|
13
21
|
/** Returns default environment based on __DEV__ */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../../../src/js/utils/environment.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../../../src/js/utils/environment.ts"],"names":[],"mappings":"AAMA,0DAA0D;AAC1D,wBAAgB,eAAe,IAAI,OAAO,CAEzC;AAED,0DAA0D;AAC1D,wBAAgB,oBAAoB,IAAI,OAAO,CAE9C;AAED,4DAA4D;AAC5D,wBAAgB,eAAe,IAAI,OAAO,CAEzC;AAED,oDAAoD;AACpD,wBAAgB,qBAAqB,IAAI,MAAM,GAAG,SAAS,CAM1D;AAED,+CAA+C;AAC/C,wBAAgB,MAAM,IAAI,OAAO,CAEhC;AAED,kCAAkC;AAClC,wBAAgB,QAAQ,IAAI,OAAO,CAGlC;AAED,yCAAyC;AACzC,wBAAgB,gBAAgB,IAAI,MAAM,GAAG,SAAS,CAGrD;AAED,4CAA4C;AAC5C,wBAAgB,iBAAiB,IAAI,MAAM,GAAG,SAAS,CAKtD;AAED,gDAAgD;AAChD,wBAAgB,MAAM,IAAI,OAAO,CAEhC;AAED,iEAAiE;AACjE,wBAAgB,gBAAgB,IAAI,MAAM,GAAG,SAAS,CAMrD;AAED,mDAAmD;AACnD,wBAAgB,qBAAqB,IAAI,aAAa,GAAG,YAAY,CAEpE"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { Platform } from 'react-native';
|
|
1
2
|
import { RN_GLOBAL_OBJ } from '../utils/worldwide';
|
|
3
|
+
import { getExpoConstants } from './expomodules';
|
|
2
4
|
import { ReactNativeLibraries } from './rnlibraries';
|
|
3
5
|
/** Checks if the React Native Hermes engine is running */
|
|
4
6
|
export function isHermesEnabled() {
|
|
@@ -24,6 +26,27 @@ export function getReactNativeVersion() {
|
|
|
24
26
|
export function isExpo() {
|
|
25
27
|
return RN_GLOBAL_OBJ.expo != null;
|
|
26
28
|
}
|
|
29
|
+
/** Check if JS runs in Expo Go */
|
|
30
|
+
export function isExpoGo() {
|
|
31
|
+
const expoConstants = getExpoConstants();
|
|
32
|
+
return (expoConstants && expoConstants.appOwnership) === 'expo';
|
|
33
|
+
}
|
|
34
|
+
/** Check Expo Go version if available */
|
|
35
|
+
export function getExpoGoVersion() {
|
|
36
|
+
const expoConstants = getExpoConstants();
|
|
37
|
+
return typeof (expoConstants === null || expoConstants === void 0 ? void 0 : expoConstants.expoVersion) === 'string' ? expoConstants.expoVersion : undefined;
|
|
38
|
+
}
|
|
39
|
+
/** Returns Expo SDK version if available */
|
|
40
|
+
export function getExpoSdkVersion() {
|
|
41
|
+
var _a;
|
|
42
|
+
const expoConstants = getExpoConstants();
|
|
43
|
+
const [, expoSdkVersion] = typeof ((_a = expoConstants === null || expoConstants === void 0 ? void 0 : expoConstants.manifest) === null || _a === void 0 ? void 0 : _a.runtimeVersion) === 'string' ? expoConstants.manifest.runtimeVersion.split(':') : [];
|
|
44
|
+
return expoSdkVersion;
|
|
45
|
+
}
|
|
46
|
+
/** Checks if the current platform is not web */
|
|
47
|
+
export function notWeb() {
|
|
48
|
+
return Platform.OS !== 'web';
|
|
49
|
+
}
|
|
27
50
|
/** Returns Hermes Version if hermes is present in the runtime */
|
|
28
51
|
export function getHermesVersion() {
|
|
29
52
|
return (RN_GLOBAL_OBJ.HermesInternal &&
|