|
| 1 | +--- |
| 2 | +title: Extract CLI from Core |
| 3 | +author: |
| 4 | +- Mike Grabowski |
| 5 | +date: 2018-08-10 |
| 6 | +--- |
| 7 | + |
| 8 | +# RFC0000: Extract CLI from Core |
| 9 | + |
| 10 | +## Summary |
| 11 | + |
| 12 | +Extract the current CLI implementation from React Native Core and move it into a third party package. |
| 13 | + |
| 14 | +## Basic example |
| 15 | + |
| 16 | +Command line tools in React Native are split into two, separate pieces. |
| 17 | + |
| 18 | +First one is the `react-native-cli` package that we prompt users to install globally, for the first time they actually interact with the framework. This package, by the design, is not meant to be frequently updated, which eliminates many annoying issues that global packages are infamous for. |
| 19 | + |
| 20 | +The second one is `local-cli` package which is the actual source code of the CLI. It is a set of multiple commands, each of them grouped into a standalone module, that are loaded altogether when the CLI is spawned. |
| 21 | + |
| 22 | +The biggest part of the `local-cli` is its `core`, which is capable of analyzing your source code. It provides a context object for all the commands, that contains necessary information about the location of your source files, available platforms and more. Commands such as `link`, `unlink` or `run-ios` use that information to perform their work. |
| 23 | + |
| 24 | +This proposal suggests no changes to the end user in its first iteration. We would simply couple new package with React Native version, just like we do with Metro. That makes it possible to still make React Native version specific changes to the CLI itself. |
| 25 | + |
| 26 | +## Motivation |
| 27 | + |
| 28 | +Facebook does not use CLI provided with React Native, which makes it hard to maintain the project. There is no clear owner and issues / pull requests get stack in the sea of other, non-CLI related reports. |
| 29 | + |
| 30 | +It is also hard to keep moving on the CLI as every additional dependency or code change is subject to the heavy review process and sync. |
| 31 | + |
| 32 | +Having a separate package with me (and Callstack) being strategic maintainers would allow us to iterate on the design of CLI even more and make sure we have the best tooling out there. |
| 33 | + |
| 34 | +Now, if you have been following React Native development for a few years, you know I have been always super excited about CLI in general. I did many talks in that field and lead efforts of creating RNPM and then, merging it to the core as `react-native link` together with Alexey Kureev. Link, and RNPM, in general, was just the first step on our way to meet that high expectation of high-quality tools. Unfortunately, due to the aforementioned constraints and lack of time we were never able to complete our long-term strategy. |
| 35 | + |
| 36 | +I would like to take the slimmering process as an opportunity to revisit that effort and start working on it once again, together with the community. |
| 37 | + |
| 38 | +## Detailed design |
| 39 | + |
| 40 | +For the first release, the goal is to just extract out the CLI into a separate package. Since every command is a standalone module, we would like to use Yarn workspaces to build a modular architecture around it. |
| 41 | + |
| 42 | +Not many people know, but not only CLI allows you to provide your custom commands but also to override the built-in ones. That makes it even more obvious to create a package-oriented setup. The similar setup is already followed by React and Metro and we would take learnings from there. |
| 43 | + |
| 44 | +Apart from reorganizing the architecture, we would like to create a website that describes the features present in the CLI - many of them, making it much easier to work at a scale. Things like support for different locations of iOS/Android projects, linking assets from 3rd party modules are great features that only selected people were fortunate to learn about. |
| 45 | + |
| 46 | +As a next step, we would like to focus on reinvestigating every single piece of CLI to see what we can do better these days. That includes looking once again into the design of the scaffolding system (that is great, but has its limitations), lock-in to Metro (because why it should be the forced default?) and rewriting link to support modern languages and new module system. |
| 47 | + |
| 48 | +The list of features is much longer and as a someone who believes tools are to give framework success on the market, I want to make sure we get the best tooling possible. |
| 49 | + |
| 50 | +## Drawbacks |
| 51 | + |
| 52 | +There are no drawbacks, the whole migration process happens as a part of one of the future React Native versions w/o users noticing. The separate Github repository is just for better tracking of issues. |
| 53 | + |
| 54 | +In the future, we might consider decoupling these two, but at the time of writing this document, I do not have answers to many questions arising from such a move. |
| 55 | + |
| 56 | +The CLI would still remain official, to go, solution that would end up living under `react-native-community` with a note, that Callstack team is working on it as a part of their OSS programme and we invite everyone to join our planning meetings. |
| 57 | + |
| 58 | +## Alternatives |
| 59 | + |
| 60 | +This is the standard and default tool for developing React Native apps that many other tools, like CRNA and Ignite depend on. We do not plan on competing with anyone, but providing a good set of built-ins |
| 61 | +that makes it easy for others to innovate on top. |
| 62 | + |
| 63 | +## Adoption strategy |
| 64 | + |
| 65 | +Rolls out automatically as a part of one of the future RN releases, when ready. |
| 66 | + |
| 67 | +## How we teach this |
| 68 | + |
| 69 | +We will need to point to new CLI documentation which describes all additional features. Rather than that, it's not needed. |
0 commit comments