From 269b4f0c7fe1ece5f680a619ce4d4b69f2bf1cb5 Mon Sep 17 00:00:00 2001 From: Juliusz Wajgelt <49338439+jwajgelt@users.noreply.github.com> Date: Fri, 24 Feb 2023 13:58:13 +0100 Subject: [PATCH] Hardcode JS library version in `checkVersion` (#4101) ## Summary We hardcode the version of Reanimated here in order to compare it with the version used to build the native part of the library in runtime. Ideally, we'd grab this version from the `package.json` file instead, but this causes issues when packaging the library due to misaligned relative paths. ## Test plan --- __tests__/versionCheck.test.js | 21 +++++++++++++++++++ .../NativeReanimated/NativeReanimated.ts | 9 ++++++++ .../platform-specific/checkVersion.ts | 7 ++++++- 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 __tests__/versionCheck.test.js diff --git a/__tests__/versionCheck.test.js b/__tests__/versionCheck.test.js new file mode 100644 index 00000000000..1bafe957568 --- /dev/null +++ b/__tests__/versionCheck.test.js @@ -0,0 +1,21 @@ +const { + checkVersion, +} = require('../src/reanimated2/platform-specific/checkVersion'); +const { version: packageVersion } = require('../package.json'); + +describe('desc', () => { + beforeAll(() => { + global._REANIMATED_VERSION_CPP = packageVersion; + jest.spyOn(console, 'error'); + }); + + afterAll(() => { + delete global._REANIMATED_VERSION_CPP; + console.error.mockRestore(); + }); + + it('checks version successfully', () => { + checkVersion(); + expect(console.error).not.toHaveBeenCalled(); + }); +}); diff --git a/src/reanimated2/NativeReanimated/NativeReanimated.ts b/src/reanimated2/NativeReanimated/NativeReanimated.ts index 6916460baa8..faf1403f75c 100644 --- a/src/reanimated2/NativeReanimated/NativeReanimated.ts +++ b/src/reanimated2/NativeReanimated/NativeReanimated.ts @@ -23,6 +23,15 @@ export class NativeReanimated { this.InnerNativeModule = global.__reanimatedModuleProxy; this.native = native; if (native) { + if (this.InnerNativeModule === undefined) { + console.error( + `[Reanimated] The native part of Reanimated doesn't seem to be initialized. This could be caused by\n\ + - not rebuilding the app after installing or upgrading Reanimated\n\ + - trying to run Reanimated on an unsupported platform\n\ + - running in a brownfield app without manually initializing the native library` + ); + return; + } checkVersion(); } } diff --git a/src/reanimated2/platform-specific/checkVersion.ts b/src/reanimated2/platform-specific/checkVersion.ts index 1b64bb62d62..45d6db73bc6 100644 --- a/src/reanimated2/platform-specific/checkVersion.ts +++ b/src/reanimated2/platform-specific/checkVersion.ts @@ -1,4 +1,9 @@ -import { version as jsVersion } from '../../../package.json'; +/** + * We hardcode the version of Reanimated here in order to compare it + * with the version used to build the native part of the library in runtime. + * Remember to keep this in sync with the version declared in `package.json` + */ +const jsVersion = '3.0.0-rc.10'; /** * Checks that native and js versions of reanimated match.