Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix @react-native-community/cli-platform-* packages not being found in monorepos #47308

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
17 changes: 15 additions & 2 deletions packages/react-native/react-native.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,22 @@

const verbose = process.env.DEBUG && process.env.DEBUG.includes('react-native');

function findCommunityPlatformPackage(spec, startDir = process.cwd()) {
// In monorepos, we cannot make any assumptions on where
// `@react-native-community/*` gets installed. The safest way to find it
// (barring adding an optional peer dependency) is to start from the project
// root.
//
// Note that we're assuming that the current working directory is the project
// root. This is also what `@react-native-community/cli` assumes (see
// https://github.com/react-native-community/cli/blob/14.x/packages/cli-tools/src/findProjectRoot.ts).
const main = require.resolve(spec, { paths: [startDir] });
return require(main);
}

let android;
try {
android = require('@react-native-community/cli-platform-android');
android = findCommunityPlatformPackage('@react-native-community/cli-platform-android');
} catch {
if (verbose) {
console.warn(
Expand All @@ -33,7 +46,7 @@ try {

let ios;
try {
ios = require('@react-native-community/cli-platform-ios');
ios = findCommunityPlatformPackage('@react-native-community/cli-platform-ios');
} catch {
if (verbose) {
console.warn(
Expand Down
Loading