Skip to content

Commit

Permalink
fix(rnsdk) specify the RN version we support
Browse files Browse the repository at this point in the history
Our SDK is only really tested with a single RN version, make sure to put
that in peerDependencies.

In addition, drop the peer dependency on @react-native/metro-config
since our project doesn't use it directly.
  • Loading branch information
saghul authored and Calinteodor committed Dec 16, 2024
1 parent 4aa4382 commit aabc50d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
1 change: 0 additions & 1 deletion react-native-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
22 changes: 16 additions & 6 deletions react-native-sdk/update_sdk_dependencies.js
Original file line number Diff line number Diff line change
@@ -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.
*/
Expand All @@ -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)) {
Expand Down

0 comments on commit aabc50d

Please sign in to comment.