-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #686 from DataDog/marcosaia/RUM-5258/bigint-polyfill
[RUM-5258] RN 0.63 BigInt support
- Loading branch information
Showing
2 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { version as reactNativeVersion } from 'react-native/package.json'; | ||
|
||
function applyBigIntPolyfill() { | ||
const rnVersion = reactNativeVersion.split('.').map(Number); | ||
const isRn63 = rnVersion[0] === 0 && rnVersion[1] === 63; | ||
|
||
if (isRn63 && typeof BigInt === 'undefined') { | ||
try { | ||
// eslint-disable-next-line global-require, import/no-extraneous-dependencies | ||
global.BigInt = require('big-integer'); | ||
console.warn( | ||
'React Native 0.63 does not support BigInt, which is required starting from v2.4.0 of Datadog React Native SDK. ' + | ||
'The missing type has been polyfilled using `big-integer` to grant back-compatibility. ' + | ||
'We strongly suggest updating to a greater version of React Native (>= 0.64).' | ||
); | ||
} catch (e) { | ||
if (e instanceof Error && e.code === 'MODULE_NOT_FOUND') { | ||
throw new Error( | ||
'React Native 0.63 does not support BigInt, which is required starting from v2.4.0 of Datadog React Native SDK. ' + | ||
'We strongly suggest updating to a greater version of React Native (>= 0.64).\n\n' + | ||
'You can install `big-integer` to enable our polyfill that grants back-compatibility with RN 63:\n\n' + | ||
'`yarn add big-integer`\n\nOR\n\n`npm install --save big-integer`' | ||
); | ||
} else { | ||
throw e; | ||
} | ||
} | ||
} | ||
} | ||
|
||
applyBigIntPolyfill(); |