Skip to content

Standardise configuration mechanism - #254

Merged
Esemesek merged 50 commits into
masterfrom
feat/config
Apr 1, 2019
Merged

Esemesek merged 50 commits into
masterfrom
feat/config

Conversation

@grabbou

@grabbou grabbou commented Mar 20, 2019 •

Copy link
Copy Markdown
Member

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.

@alloy

ghost commented Mar 20, 2019 •

Copy link
Copy Markdown
Member

I noticed that we only get configuration for direct dependencies of a user’s package.json manifest, but that means transitive dependencies with native modules wouldn’t get picked up and linked. So I think you should consider all installed packages instead.

(Ideally we wouldn’t crawl node_modules for this, but use e.g. yarn list, but that’s something that can be iterated on ofc.)

@grabbou grabbou changed the title [WIP] Better configuration [WIP] Better native modules integration Mar 20, 2019
@punksta

This comment has been minimized.

@Salakar

This comment has been minimized.

@alloy

ghost commented Mar 21, 2019

Copy link
Copy Markdown
Member

WIP on the CocoaPods integration #256

@Salakar

ghost commented Mar 21, 2019 •

Copy link
Copy Markdown
Member

EDIT: Android PR is up #258 - points to this branch.

@grabbou

ghost commented Mar 22, 2019

Copy link
Copy Markdown
Member Author

@alloy, unfortunately, this is potentially a security issue. With auto linking, users are less aware of what gets linked and crawling through the entire node_modules would be potentially dangerous and easy to include an unwanted / malicious code.

I commented about that on Discord, so let's follow up there.

@Salakar

ghost commented Mar 22, 2019

Copy link
Copy Markdown
Member

Submitted a draft PR for the template changes: react/react-native#24099 I can iterate/change as required - just gives some visibility of the changes required to the template.

@alloy

ghost commented Mar 22, 2019

Copy link
Copy Markdown
Member

@grabbou I disagree. Any dependency is a security risk, so if you already opt-in to that then I don’t think we should generate projects that are essentially broken.

Like, one of the 20 file watchers in my node_modules dir could easily inject malicious code, hijack data from my machine, etc.

@FibreFoX

ghost commented Mar 24, 2019

Copy link
Copy Markdown

If this feature gets some opt-out way, or some kind of "opt-in only" mechanism (or even to choose one), the risks should be mitigated. Maybe let's not just look from a security perspective (as @alloy mentioned that adding dependencies itself is a risk), but have it looked at via some usability- and debugging-perspective.

When having any automatic step, that does some "magic", makes it some kind of debugging hell to find out why some dependency is included.

The current way of including things explicitly, makes me as a dev able to choose what I want to have inside my native app. Especially when having some kind of nasty transitive-dependency hack I have to apply (like changing some version), how can this be done when things are getting applied without me doing the plumbing?

(sorry if this disrupts anything or is the wrong place to add my 2 cents)

@Salakar

ghost commented Mar 24, 2019

Copy link
Copy Markdown
Member

@FibreFoX all feedback is welcome - so thank you :)

Auto-linking on both platforms support opting-out (just don't include the ruby script in your Podfile or the Gradle script in your build.gradle); opt-in by default on new apps generated through react-native init - existing apps would have to manually opt-in.

@FibreFoX

ghost commented Mar 24, 2019

Copy link
Copy Markdown

@Salakar So this is some all-or-nothing thing, means as developer I can opt-in to this by adding that line inside Podfile and app/build.gradle, right?

Just as some additional idea: could you add some "show me what I would add"-command, in case I'm coming from "auto-linking" and want to (or have to) add the modules manually (in cases where I need to override some dependency as described above)? In addition to being able to "switch", it would make debugging much easier, especially for native-module developers which want to check if their module gets included.

@grabbou grabbou changed the title [WIP] New CLI configuration mechanism Standardise configuration mechanism Apr 1, 2019
@grabbou
grabbou requested review from Esemesek and thymikee April 1, 2019 11:16
Comment thread .eslintrc.js Resolved
Comment thread packages/cli/src/tools/config/index.js Resolved
Comment thread packages/cli/src/tools/config/index.js Resolved
Comment thread packages/cli/src/tools/config/index.js Resolved
}
}

type JoiErrorT = {

ghost Apr 1, 2019

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it would be easier to flow-typed install joi and use something from there?

ghost Apr 1, 2019

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that makes more sense.

ghost left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note that it would still use some docs, don't forget about it

@grabbou

ghost commented Apr 1, 2019

Copy link
Copy Markdown
Member Author

Yup. @thymikee, do we have a place for the docs right now? I am kinda bad at them, so just thinking where to start.

@thymikee

ghost commented Apr 1, 2019

Copy link
Copy Markdown
Member

ghost left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks clean 🍰

@grabbou

ghost commented Apr 1, 2019

Copy link
Copy Markdown
Member Author

Cool! Let's add docs in next PR when I integrate this into a link command and it becomes useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants