diff --git a/react-native-sdk/package.json b/react-native-sdk/package.json index bae90977af3f..29a04e149e81 100644 --- a/react-native-sdk/package.json +++ b/react-native-sdk/package.json @@ -58,7 +58,6 @@ "peerDependencies": { "@amplitude/react-native": "0.0.0", "@giphy/react-native-sdk": "0.0.0", - "@react-native/metro-config": "*", "@react-native-async-storage/async-storage": "0.0.0", "@react-native-clipboard/clipboard": "0.0.0", "@react-native-community/netinfo": "0.0.0", diff --git a/react-native-sdk/update_sdk_dependencies.js b/react-native-sdk/update_sdk_dependencies.js index 0f3d64b75533..3d2f32f7e68e 100644 --- a/react-native-sdk/update_sdk_dependencies.js +++ b/react-native-sdk/update_sdk_dependencies.js @@ -1,9 +1,13 @@ const fs = require('fs'); +const semver = require('semver'); const packageJSON = require('../package.json'); const SDKPackageJSON = require('./package.json'); +// Skip checking these. +const skipDeps = [ 'react', 'react-native' ]; + /** * Merges the dependency versions from the root package.json with the dependencies of the SDK package.json. */ @@ -18,15 +22,21 @@ function mergeDependencyVersions() { // Updates SDK peer dependencies. for (const key in packageJSON.dependencies) { - if (SDKPackageJSON.peerDependencies.hasOwnProperty(key)) { - - // Updates all peer dependencies except react and react-native. - if (key !== 'react' && key !== 'react-native') { - SDKPackageJSON.peerDependencies[key] = packageJSON.dependencies[key]; - } + if (SDKPackageJSON.peerDependencies.hasOwnProperty(key) && !skipDeps.includes(key)) { + SDKPackageJSON.peerDependencies[key] = packageJSON.dependencies[key]; } } + // Set RN peer dependency. + const rnVersion = semver.parse(packageJSON.dependencies['react-native']); + + if (!rnVersion) { + throw new Error('failed to parse React Native version'); + } + + // In RN the "major" version is the Semver minor. + SDKPackageJSON.peerDependencies['react-native'] = `~0.${rnVersion.minor}.0`; + // Updates SDK overrides dependencies. for (const key in packageJSON.overrides) { if (SDKPackageJSON.overrides.hasOwnProperty(key)) {