mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
react-native.config.js handle optional @react-native-community dependencies
Summary: As part of decoupling our dependency on the react-native-community/cli, the `react-native.config.js` which is a part of the community's config ecosystem should probably be entirely removed from the react-native package. As part of this, we're making the config fail gracefully if these dependencies aren't available in a user's project: - react-native-community/cli-platform-android - react-native-community/cli-platform-ios Changelog: [Internal] This isn't going to be a visible change to any users. bypass-github-export-checks Reviewed By: cortinico Differential Revision: D56137820 fbshipit-source-id: 528e25809a83b90e79b806a875001fc0f06db1cf
This commit is contained in:
committed by
Facebook GitHub Bot
parent
8afa8beac2
commit
b71cebbd37
@@ -9,8 +9,39 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const android = require('@react-native-community/cli-platform-android');
|
||||
const ios = require('@react-native-community/cli-platform-ios');
|
||||
// React Native shouldn't be exporting itself like this, the Community Template should be be directly
|
||||
// depending on and injecting:
|
||||
// - @react-native-community/cli-platform-android
|
||||
// - @react-native-community/cli-platform-ios
|
||||
// - @react-native/community-cli-plugin (via the @react-native/core-cli-utils package)
|
||||
// - codegen command should be inhoused into @react-native-community/cli
|
||||
//
|
||||
// This is a temporary workaround.
|
||||
|
||||
const verbose = process.env.DEBUG && process.env.DEBUG.includes('react-native');
|
||||
|
||||
let android;
|
||||
try {
|
||||
android = require('@react-native-community/cli-platform-android');
|
||||
} catch {
|
||||
if (verbose) {
|
||||
console.warn(
|
||||
'@react-native-community/cli-platform-android not found, the react-native.config.js may be unusable.',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
let ios;
|
||||
try {
|
||||
ios = require('@react-native-community/cli-platform-ios');
|
||||
} catch {
|
||||
if (verbose) {
|
||||
console.warn(
|
||||
'@react-native-community/cli-platform-ios not found, the react-native.config.js may be unusable.',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const {
|
||||
bundleCommand,
|
||||
startCommand,
|
||||
@@ -43,22 +74,25 @@ const codegenCommand = {
|
||||
),
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
commands: [
|
||||
...ios.commands,
|
||||
...android.commands,
|
||||
bundleCommand,
|
||||
startCommand,
|
||||
codegenCommand,
|
||||
],
|
||||
platforms: {
|
||||
ios: {
|
||||
projectConfig: ios.projectConfig,
|
||||
dependencyConfig: ios.dependencyConfig,
|
||||
},
|
||||
android: {
|
||||
projectConfig: android.projectConfig,
|
||||
dependencyConfig: android.dependencyConfig,
|
||||
},
|
||||
},
|
||||
const config = {
|
||||
commands: [bundleCommand, startCommand, codegenCommand],
|
||||
platforms: {},
|
||||
};
|
||||
|
||||
if (ios != null) {
|
||||
config.commands.push(...ios.commands);
|
||||
config.platforms.ios = {
|
||||
projectConfig: ios.projectConfig,
|
||||
dependencyConfig: ios.dependencyConfig,
|
||||
};
|
||||
}
|
||||
|
||||
if (android != null) {
|
||||
config.commands.push(...android.commands);
|
||||
config.platforms.android = {
|
||||
projectConfig: android.projectConfig,
|
||||
dependencyConfig: android.dependencyConfig,
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = config;
|
||||
|
||||
Reference in New Issue
Block a user