Skip to content

Contributing to the CLI

Andrew Coates edited this page May 5, 2020 · 34 revisions

Where stuff lives

Parts of the CLI:

  1. Code to identify the correct version of react-native-windows to install, and install it:
    [Root]\packages\react-native-windows-init
  2. Template code: The code that actually creates the files needed to to run a create and run react-native-windows app here:
    [Root]\vnext\local-cli
  3. Code for run-windows and other commands run through react-native <foo>

How to test local changes to the project init CLI:

  1. If you are making changes to the react-native-windows-init code, you can build the code locally using yarn build, then manually call into the CLI by using node <root>\packages\react-native-windows-init\lib-commonjs\Cli.js -- You can pass parameters to that as usual, or use node --inspect-brk ... to allow you to attach to the call using VSCode.
  2. If you are making changes to the vnext part of the CLI, you can install RNW from your local enlistment by supplying the --version parameter to the react-native-windows-init command. For example:
    npx react-native-windows-init --version file:d:\rnw\vnext

Note: that yarn does a copy of all the files under vnext to install react-native-windows. Unlike when the package has been published, this will include all the native built files which would normally be excluded by npmignore. You should delete the build, target and packages folder from vnext. Otherwise the command will have to copy GBs of data to install react-native-windows from your local path

How to debug other CLI commands:

The easiest way to to debug is using VS Code. You just need to create a configuration within your template app directory that tells VS Code to launch the CLI in an instance of node and debug node on startup. Here's an example launch.json with a single configuration:

{
  "version": "0.2.0",
  "configurations"[
    {
      "type""node",
      "request""launch",
      "name""react-native windows",
      "program""${workspaceRoot}/node_modules/react-native/cli.js",
      "args"["run-windows"],
      "stopOnEntry"true
    }
  ],
  "compounds"[]
}
Clone this wiki locally