forked from react-native-community/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Standardise configuration mechanism (react-native-community#254)
Summary: --------- This pull requests brings a new way of configuring the CLI and drops never properly standardised and documented "rnpm" configuration. This is done in order to support new "auto-linking" feature and consolidate the configuration into a single place, that is easy to customise by developers. ### Highlights Given the scope of this PR, it's hard to write down every tiny detail. I've tried to leave as many comments as possible throughout the code to make it easier for you to navigate and understand some of the code patterns. Please see the highlighted changes below: - We now use `cosmiconfig` to load user preferences. We do that by taking "react-native" out of "package.json" and reading "react-native.config.js". We still read "rnpm" for legacy purposes and print appropriate deprecation messages along the instructions on what to do in order to upgrade. Jest validation library makes this kind of things super easy. - We validate the provided configuration by user using Jest validation library. This gives instant feedback whether the configuration is correct or not. - We now read configuration in a single place (happens in main CLI file) and pass it down to commands. Previously, we used to call `findPlugins` multiple times w/o cache, causing expensive globs to be performed. - Project configuration is lazy. We won't glob node_modules and/or look for native files unless you explicitly read for that package configuration. - Better support for out-of-tree-platforms - no need to define "haste" yourself, we are able to infer it from other properties. The files are also better organised now, causing less of maintenance pain with "linkConfig" - We consider our automatically generated configuration a set of defaults. Users can override settings for the project and each of the dependencies. Useful, especially with auto-linking feature to disable certain packages from it or when you don't want to link particular platform automatically. This has been historically really hard to implement - Global flags (e.g. "reactNativePath") can now be defined in configuration, instead of passing every time around. This fixes issues with "packager.sh" script (starting automatically Metro when running from Xcode) when run from RNTester.xcodeproj ### Next steps Once this PR is merged, we can concurrently start working/merging other "auto-linking" PRs. In the meantime, I'll submit a PR to move regular "link" (soon to be considered a legacy) to use the new configuration format as well. The new configuration has been designed in the way to still include previous configuration keys to support "link" and other community packages. For now, we print handy deprecation messages to help migrate the community from "rnpm" to "react-native" configuration. When "link" gets deprecated/removed forever in favour of "auto-linking", we should revisit the configuration and eventually, remove extraneous keys out of it. With "auto-linking", we don't need majority of it. Test Plan: ---------- Run `react-native config` to output the configuration.
- Loading branch information
Showing
22 changed files
with
984 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* @flow | ||
*/ | ||
import {type ContextT} from '../../tools/types.flow'; | ||
export default { | ||
name: 'config', | ||
description: 'Print CLI configuration', | ||
func: async (argv: string[], ctx: ContextT) => { | ||
console.log(JSON.stringify(ctx, null, 2)); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.