From 38aa7ec93e230caf6cb7a664dce49646f03ee562 Mon Sep 17 00:00:00 2001 From: Sergei Butko Date: Mon, 15 Jul 2024 10:34:03 +0200 Subject: [PATCH 1/6] Change React Native Version import to the one from Platform --- src/js/utils/rnlibraries.ts | 5 ++--- src/js/utils/rnlibrariesinterface.ts | 5 +++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/js/utils/rnlibraries.ts b/src/js/utils/rnlibraries.ts index 1cca39403..0fcc852fb 100644 --- a/src/js/utils/rnlibraries.ts +++ b/src/js/utils/rnlibraries.ts @@ -1,7 +1,6 @@ /* eslint-disable @typescript-eslint/no-var-requires */ -import { TurboModuleRegistry } from 'react-native'; -import { version as RNV } from 'react-native/Libraries/Core/ReactNativeVersion'; +import { Platform, TurboModuleRegistry } from 'react-native'; import type * as ReactNative from '../vendor/react-native'; import type { ReactNativeLibrariesInterface } from './rnlibrariesinterface'; @@ -32,7 +31,7 @@ export const ReactNativeLibraries: Required = { }, }, ReactNativeVersion: { - version: RNV, + version: Platform.constants.reactNativeVersion, }, TurboModuleRegistry, }; diff --git a/src/js/utils/rnlibrariesinterface.ts b/src/js/utils/rnlibrariesinterface.ts index 925039832..8e25d9969 100644 --- a/src/js/utils/rnlibrariesinterface.ts +++ b/src/js/utils/rnlibrariesinterface.ts @@ -5,13 +5,14 @@ // that don't have all the internals available. For example react-native-web. // -import type { version as RNV } from 'react-native/Libraries/Core/ReactNativeVersion'; +import type { Platform } from 'react-native'; import type * as ReactNative from '../vendor/react-native'; export type { UnsafeObject } from 'react-native/Libraries/Types/CodegenTypes'; export type { EmitterSubscription } from 'react-native/Libraries/vendor/emitter/EventEmitter'; + export interface ReactNativeLibrariesInterface { Devtools?: { parseErrorStack: (errorStack: string) => Array; @@ -26,7 +27,7 @@ export interface ReactNativeLibrariesInterface { }; Promise?: typeof Promise; ReactNativeVersion?: { - version: typeof RNV; + version: typeof Platform.constants.reactNativeVersion; }; TurboModuleRegistry?: ReactNative.TurboModuleRegistry; } From da311f45117ab0e50fd147fc065bde21007157de Mon Sep 17 00:00:00 2001 From: Krystof Woldrich <31292499+krystofwoldrich@users.noreply.github.com> Date: Wed, 31 Jul 2024 13:23:37 +0200 Subject: [PATCH 2/6] Update rnlibrariesinterface.ts --- src/js/utils/rnlibrariesinterface.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/js/utils/rnlibrariesinterface.ts b/src/js/utils/rnlibrariesinterface.ts index 8e25d9969..5027f2525 100644 --- a/src/js/utils/rnlibrariesinterface.ts +++ b/src/js/utils/rnlibrariesinterface.ts @@ -12,7 +12,6 @@ import type * as ReactNative from '../vendor/react-native'; export type { UnsafeObject } from 'react-native/Libraries/Types/CodegenTypes'; export type { EmitterSubscription } from 'react-native/Libraries/vendor/emitter/EventEmitter'; - export interface ReactNativeLibrariesInterface { Devtools?: { parseErrorStack: (errorStack: string) => Array; From 6c4a868c189c0e34d1ed3c012868740eddf44854 Mon Sep 17 00:00:00 2001 From: Krystof Woldrich <31292499+krystofwoldrich@users.noreply.github.com> Date: Wed, 31 Jul 2024 13:25:59 +0200 Subject: [PATCH 3/6] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 47693b8e7..0c0ed31a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Pass `sampleRate` option to the Android SDK ([#3979](https://github.com/getsentry/sentry-react-native/pull/3979)) - Drop app start data older than one minute ([#3974](https://github.com/getsentry/sentry-react-native/pull/3974)) +- Use `Platform.constants.reactNativeVersion` instead of `react-native` internal export ([#3949](https://github.com/getsentry/sentry-react-native/pull/3949)) ### Dependencies From 0ad82e03aadea5980722d809e354204567b9ba46 Mon Sep 17 00:00:00 2001 From: Sergei Butko Date: Wed, 31 Jul 2024 13:42:21 +0200 Subject: [PATCH 4/6] Fix potential empty constants coming from Platform --- src/js/utils/rnlibraries.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/utils/rnlibraries.ts b/src/js/utils/rnlibraries.ts index 0fcc852fb..614164d35 100644 --- a/src/js/utils/rnlibraries.ts +++ b/src/js/utils/rnlibraries.ts @@ -31,7 +31,7 @@ export const ReactNativeLibraries: Required = { }, }, ReactNativeVersion: { - version: Platform.constants.reactNativeVersion, + version: Platform.constants?.reactNativeVersion, }, TurboModuleRegistry, }; From 61ffbb2742192c5d47da17a4d37d05d57e3eb04b Mon Sep 17 00:00:00 2001 From: Krystof Woldrich Date: Wed, 31 Jul 2024 15:05:40 +0200 Subject: [PATCH 5/6] fix types --- src/js/utils/rnlibrariesinterface.ts | 6 +----- src/js/vendor/react-native/index.ts | 10 ++++++++++ typings/react-native.d.ts | 8 -------- 3 files changed, 11 insertions(+), 13 deletions(-) delete mode 100644 typings/react-native.d.ts diff --git a/src/js/utils/rnlibrariesinterface.ts b/src/js/utils/rnlibrariesinterface.ts index 5027f2525..46dc0fc60 100644 --- a/src/js/utils/rnlibrariesinterface.ts +++ b/src/js/utils/rnlibrariesinterface.ts @@ -5,8 +5,6 @@ // that don't have all the internals available. For example react-native-web. // -import type { Platform } from 'react-native'; - import type * as ReactNative from '../vendor/react-native'; export type { UnsafeObject } from 'react-native/Libraries/Types/CodegenTypes'; @@ -25,8 +23,6 @@ export interface ReactNativeLibrariesInterface { polyfillGlobal: (name: string, getValue: () => T) => void; }; Promise?: typeof Promise; - ReactNativeVersion?: { - version: typeof Platform.constants.reactNativeVersion; - }; + ReactNativeVersion?: ReactNative.ReactNativeVersion; TurboModuleRegistry?: ReactNative.TurboModuleRegistry; } diff --git a/src/js/vendor/react-native/index.ts b/src/js/vendor/react-native/index.ts index de5438238..d393eeed1 100644 --- a/src/js/vendor/react-native/index.ts +++ b/src/js/vendor/react-native/index.ts @@ -64,3 +64,13 @@ export type TurboModuleRegistry = { get(name: string): T | null; getEnforcing(name: string): T; }; + +// Adapted from https://github.com/facebook/react-native/blob/575ab7862553d7ad7bc753951ed19dcd50d59b95/packages/react-native/Libraries/Utilities/Platform.d.ts#L23-L28 +export type ReactNativeVersion = { + version: { + major: number; + minor: number; + patch: number; + prerelease?: number | null | undefined; + }, +}; diff --git a/typings/react-native.d.ts b/typings/react-native.d.ts deleted file mode 100644 index 6cd00da3b..000000000 --- a/typings/react-native.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -declare module 'react-native/Libraries/Core/ReactNativeVersion' { - export const version: { - major: number; - minor: number; - patch: number; - prerelease: string | null; - }; -}; From 86e616a9ae7d1313fb3024a060a6ba7319de2f6e Mon Sep 17 00:00:00 2001 From: Krystof Woldrich Date: Wed, 31 Jul 2024 15:06:48 +0200 Subject: [PATCH 6/6] fix lint --- src/js/vendor/react-native/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/vendor/react-native/index.ts b/src/js/vendor/react-native/index.ts index d393eeed1..9735d5ce1 100644 --- a/src/js/vendor/react-native/index.ts +++ b/src/js/vendor/react-native/index.ts @@ -72,5 +72,5 @@ export type ReactNativeVersion = { minor: number; patch: number; prerelease?: number | null | undefined; - }, + }; };