Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract CLI from core #13

Merged
merged 3 commits into from
Sep 24, 2018
Merged
Changes from 1 commit
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
69 changes: 69 additions & 0 deletions proposals/0002-Extracted-Command-Line-Tools.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
title: Extract CLI from Core
author:
- Mike Grabowski
date: 2018-08-10
---

# RFC0000: Extract CLI from Core
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe this is RFC0003.


## Summary

Extract the current CLI implementation from React Native Core and move it into a third party package.

## Basic example
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we just call this section "Background", even in the template ? Looks like almost all proposals seem to need a background section, talking about the state of the world.


Command line tools in React Native are split into two, separate pieces.

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.

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.

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.

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.

Choose a reason for hiding this comment

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

I feel like we’ve often run into problems with metro versions being so tightly coupled to RN releases. Will that not be a problem here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not really - we will still bundle the CLI with React Native to start with (just like we bundle Metro as a dependency). In reality, there are less and less features that need to be updated for new React Native releases. In most cases, it's due to Metro changing the interface, which we can track here as well.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we need to define what the features of "first iteration" really are, before declaring that there would be no changes. Maybe more this sentence to later ?


## Motivation

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.
Copy link
Member

Choose a reason for hiding this comment

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

s/stack/stuck

Choose a reason for hiding this comment

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

s/use CLI/use the CLI


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.

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.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This sounds more like a pitch to take over the CLI. Also, if this happens, why would this be any different from any of the other CLIs for RN that exist out there. How would this help ?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not - sorry if it reads that way. The whole point of this paragraph was to emphasize the fact that having CLI as a separate package will make it easier to consolidate work in a more focused repository without all the Facebook sync infrastructure.


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.

Choose a reason for hiding this comment

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

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 think it might be best to keep anecdotal things out of the context of these proposals, so that folks don't need a history lesson or feel they need to know someone in the industry to participate.

While I appreciate you're excited by this (and I know you'll be a great maintainer!), I'm not sure your personality contributes to the technical impact that this will have. 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, thanks for leaving this feedback. I guess it's due to my understanding of "motivation" that I took a bit personal as well, rather than focusing on "technical motivation" in the first place.


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.

## Detailed design

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.

Choose a reason for hiding this comment

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

Can you elaborate on this? I’m not very familiar with how the cli works so this section isn’t very clear to me.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not sure if it makes sense to have every command in a stand alone module - may main maintenance hard. I would also encourage taking a look at the CLIs for Cordova and NativeScript - which have a similar modular story, but not necessary in separate modules.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, right now, commands are standalone packages anyway, it's just that we don't expose it elsewhere. I don't think it would be useful to do it anyway. I was initially thinking about an internal structure to manage dependencies. Can do it with single package.json anyway, but was thinking Yarn workspaces are a very light-weight addition.


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.

Choose a reason for hiding this comment

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

What is an example of a command that overrides built in ones? Is this something specifically for supporting additional platforms?

Copy link
Collaborator

Choose a reason for hiding this comment

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

react-native-windows. I am not sure if that was the right approach in the first place. We probably should have had something like react-native add platform react-native-windows.

Also, what is the advantage of making the CLI pluggable, when you could technically just add node_modules and run those !!

Copy link
Member Author

Choose a reason for hiding this comment

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

It's easier to set up and works out of the box - no point in worrying about some common things as error handling, params, and cross-platform capability. Also, most importantly, CLI is equipped with "config" object (referred to as "context" in the scope of every command) that gets passed to every command as a first argument. It contains an information about the source files of React Native project, available platforms etc. so that users that want to write their own plugin to perform native work don't have to guess things on their own. React Native link command uses that object to do all its work.

Copy link
Member Author

Choose a reason for hiding this comment

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

This part needs some love and definitely to be discussed. The pluggable architecture is an internal implementation detail, but I've found it very easy and cheap to open to the public.


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.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be done, regardless of this current effort. Not sure if it makes sense to keep it here.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's certainly one of the features on the roadmap to take right away once the cut is done. I didn't have a better place to track that. Will remove it for now and keep it under a separate issue.


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.

Choose a reason for hiding this comment

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

rewriting link to support modern languages and new module system.

This seems like it could be its whole own proposal... 😨

What do you think about keeping the proposal limited to just the extraction of the CLI for now?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I gone too deep with my plans for the CLI in general. I will discuss them today on the meeting and get some initial ideas, but for now, I am going to remove 50% of this proposal and just make it about extracting from the repository itself.


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.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is also an abstract statement. Does it make sense to define what exactly we do here ?


## Drawbacks

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.

Choose a reason for hiding this comment

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

One drawback I can think of is the separation of code, and thus repositories, leading to folks not know where something lives or is implemented. While it will be good to track issues in two places, how will developers know which repo to file issues on? It may require some informing of developers to better understand the architecture.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We've definitely felt this pain as a result of our CLI (https://github.com/infinitered/ignite) and boilerplate (https://github.com/infinitered/ignite-ir-boilerplate-bowser) being separated.

Copy link
Collaborator

Choose a reason for hiding this comment

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

(This isn't a reason not to separate them, though. It's been helpful overall!)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I guess we should better communicate that react-native-cli is a separate package. I can think of an automated message printed after every failure in CLI educating that this "error report" can be submitted to this repository in particular.


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.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This also should be separate, no point adding it here.


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.

## Alternatives

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
that makes it easy for others to innovate on top.

## Adoption strategy

Rolls out automatically as a part of one of the future RN releases, when ready.

## How we teach this

We will need to point to new CLI documentation which describes all additional features. Rather than that, it's not needed.