Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
"peerDependencies": {
"@callstack/react-native-visionos": "0.76 - 0.79",
"@expo/config-plugins": ">=5.0",
"react": "18.2 - 19.2",
"react": "18.2 - 19.3",
"react-native": "0.76 - 0.88 || >=0.89.0-0 <0.89.0",
"react-native-macos": "^0.0.0-0 || 0.76 - 0.81",
"react-native-windows": "^0.0.0-0 || 0.76 - 0.83"
Expand Down
29 changes: 26 additions & 3 deletions packages/app/scripts/internal/set-react-version.mts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as fs from "node:fs";
import * as path from "node:path";
import * as util from "node:util";
import manifest from "../../package.json" with { type: "json" };
import { isMain, readJSONFile } from "../helpers.js";
import { isMain, readJSONFile, toVersionNumber, v } from "../helpers.js";
import type { Manifest } from "../types.ts";
import { writeJSONFile } from "../utils/filesystem.mjs";
import { fetchPackageMetadata, npmRegistryBaseURL } from "../utils/npm.mjs";
Expand Down Expand Up @@ -152,6 +152,26 @@ function fetchReactNativeWindowsCanaryInfoViaNuGet(): Promise<Manifest> {
.then((version) => fetchPackageInfo("react-native-windows", version));
}

/**
* Throws if the React version required by React Native is not covered by our
* `react` peer range.
*/
function assertReactPeerRange(reactVersion: string): void {
const range = manifest.peerDependencies["react"];
const m = range.match(/ - (\d+)\.(\d+)$/);
if (!m) {
throw new Error(`Unexpected 'react' peer range: ${range}`);
}

const [, maxMajor, maxMinor] = m.map(Number);
if (toVersionNumber(reactVersion) >= v(maxMajor, maxMinor + 1, 0)) {
throw new Error(
`react@${reactVersion} is not covered by the 'react' peer range ` +
`(${range}); please update 'peerDependencies' in 'package.json'`
);
}
}

/**
* Returns an object with common dependencies.
*/
Expand Down Expand Up @@ -189,14 +209,17 @@ async function resolveCommonDependencies(
const rncliIOS =
devDependencies["@react-native-community/cli-platform-ios"] ?? rncli;

// Replace range to avoid React version mismatch
const react = peerDependencies["react"].replace(/^\^/, "");
assertReactPeerRange(react);

return {
"@react-native-community/cli": rncli,
"@react-native-community/cli-platform-android": rncliAndroid,
"@react-native-community/cli-platform-ios": rncliIOS,
"@react-native/babel-preset": rnBabelPresetVersion,
"@react-native/metro-config": rnMetroConfigVersion,
// Replace range to avoid React version mismatch
react: peerDependencies["react"].replace(/^\^/, ""),
react,
};
}

Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12991,7 +12991,7 @@ __metadata:
peerDependencies:
"@callstack/react-native-visionos": 0.76 - 0.79
"@expo/config-plugins": ">=5.0"
react: 18.2 - 19.2
react: 18.2 - 19.3
react-native: 0.76 - 0.88 || >=0.89.0-0 <0.89.0
react-native-macos: ^0.0.0-0 || 0.76 - 0.81
react-native-windows: ^0.0.0-0 || 0.76 - 0.83
Expand Down
Loading