Skip to content
Closed
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