Skip to content

Commit

Permalink
Merge pull request #686 from DataDog/marcosaia/RUM-5258/bigint-polyfill
Browse files Browse the repository at this point in the history
[RUM-5258] RN 0.63 BigInt support
  • Loading branch information
marco-saia-datadog authored Jul 8, 2024
2 parents 3717f76 + 26c6a16 commit 1927121
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/core/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2016-Present Datadog, Inc.
*/
/* eslint-disable arca/import-ordering */

import './polyfills';
import {
DatadogProviderConfiguration,
DdSdkReactNativeConfiguration,
Expand Down Expand Up @@ -32,6 +34,8 @@ import { DefaultTimeProvider } from './utils/time-provider/DefaultTimeProvider';
import { TimeProvider } from './utils/time-provider/TimeProvider';
import type { Timestamp } from './utils/time-provider/TimeProvider';

/* eslint-enable arca/import-ordering */

export {
DatadogProvider,
DatadogProviderConfiguration,
Expand Down
31 changes: 31 additions & 0 deletions packages/core/src/polyfills.js
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();

0 comments on commit 1927121

Please sign in to comment.