Skip to content

Commit

Permalink
Hardcode JS library version in checkVersion (software-mansion#4101)
Browse files Browse the repository at this point in the history
<!-- Thanks for submitting a pull request! We appreciate you spending
the time to work on these changes. Please follow the template so that
the reviewers can easily understand what the code changes affect. -->

## 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.
<!-- Explain the motivation for this PR. Include "Fixes #<number>" if
applicable. -->

## Test plan

<!-- Provide a minimal but complete code snippet that can be used to
test out this change along with instructions how to run it and a
description of the expected behavior. -->
  • Loading branch information
jwajgelt authored and fluiddot committed Jun 5, 2023
1 parent d24a17f commit 269b4f0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
21 changes: 21 additions & 0 deletions __tests__/versionCheck.test.js
Original file line number Diff line number Diff line change
@@ -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();
});
});
9 changes: 9 additions & 0 deletions src/reanimated2/NativeReanimated/NativeReanimated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/reanimated2/platform-specific/checkVersion.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down

0 comments on commit 269b4f0

Please sign in to comment.