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

feat: add a programmatic dev server API #1118

Merged
merged 3 commits into from
Apr 24, 2020

Conversation

fson
Copy link
Contributor

@fson fson commented Apr 16, 2020

Summary:

I work on Expo CLI, which uses React Native CLI to start the development server. Previously, we've done this by starting RN CLI as a subprocess. This has had some challenges, including slower boot-up time because we need to start another Node process, possibility to end up with a killed or zombie processes if there's an unhandled error, and having to parse all logs from JSON in stdout.

This PR refactors the react-native start command and introduces a new package @react-native-community/dev-server-api, which includes a programmatic interface for starting the dev server middleware and WebSocket servers used by React Native. This allows tools like Expo CLI to interface with Metro directly and then attach the additional features provided by React Native CLI to the Metro HTTP server. (expo/expo-cli#1845 will make use of this package).

Test Plan:

I have followed the Testing your changes instructions in CONTRIBUTING.md and started the dev server with npx react-native start --watchFolders /Users/ville/Projects/react-native-cli/ --resetCache. After starting the server, I've verified the following features work:

  • Running the app on iOS simulator
  • Editing a file in the app, the app refreshed automatically
  • Refreshing the app by pressing r
  • Starting the debugger in Chrome and setting a breakpoint
  • Looking at logs in Flipper

Screen Shot 2020-04-16 at 17 51 09

Copy link
Member

@thymikee thymikee left a comment

Choose a reason for hiding this comment

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

Lovely, no Metro deps in server API!

packages/cli/src/commands/server/runServer.ts Outdated Show resolved Hide resolved
packages/tools/src/index.ts Show resolved Hide resolved
packages/dev-server-api/package.json Outdated Show resolved Hide resolved
packages/tools/package.json Show resolved Hide resolved
Copy link
Member

@thymikee thymikee left a comment

Choose a reason for hiding this comment

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

@Esemesek mind taking a look?

@fson
Copy link
Contributor Author

fson commented Apr 24, 2020

At @thymikee's suggestion, I've split this PR up so it only includes the new dev-server-api package and changes to cli-tools. The CLI will be changed to use dev-server-api in a follow up PR.

@thymikee thymikee merged commit 85b395f into react-native-community:master Apr 24, 2020
@thymikee
Copy link
Member

Published as a part of v4.8.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants