Stop using projectRoots from RN cli

Summary:
This diff tries to fix an issue that started appearing in RN master when the latest metro version is used (more info here: c5ce762697 (commitcomment-29443117)).

The problem is that RN is still reading `projectRoots` from the Metro config and trying to call `concat()` on them. Latest Metro sets the default `projectRoots` to null, so this fails.

Also, a couple other things have been done:

* Make sure that the `projectRoot` and `watchFolder` objects from args are passed to Metro (so they contain the overrides from the CLI arguments).
* Add a `--projectRoot` CLI arg, replacing the `--root` one (this is not actually needed, since it does the same as `--watchFolders`

Differential Revision: D8567229

fbshipit-source-id: 3b76fd8e23d201a4097e9dfba3a512d64f348cb0
This commit is contained in:
Rafael Oleza 2018-06-22 08:09:48 -07:00 committed by Facebook Github Bot
parent 8ef539e0c2
commit 33ba5e8fa2
2 changed files with 12 additions and 16 deletions

View File

@ -56,7 +56,7 @@ export type Args = {|
+nonPersistent: boolean,
+platforms: $ReadOnlyArray<string>,
+port: number,
+projectRoots: $ReadOnlyArray<string>,
+projectRoot: string,
+resetCache: boolean,
+sourceExts: $ReadOnlyArray<string>,
+verbose: boolean,
@ -197,7 +197,7 @@ function getPackagerServer(args, config, reporter) {
polyfillModuleNames: config.getPolyfillModuleNames(),
postMinifyProcess: config.postMinifyProcess,
postProcessBundleSourcemap: config.postProcessBundleSourcemap,
projectRoot: config.getProjectRoot(),
projectRoot: args.projectRoot,
providesModuleNodeModules: providesModuleNodeModules,
reporter,
resetCache: args.resetCache,
@ -206,7 +206,7 @@ function getPackagerServer(args, config, reporter) {
transformModulePath: transformModulePath,
verbose: args.verbose,
watch: !args.nonPersistent,
watchFolders: config.getWatchFolders(),
watchFolders: args.watchFolders,
workerPath: config.getWorkerPath(),
});
}

View File

@ -10,7 +10,6 @@
'use strict';
const path = require('path');
const runServer = require('./runServer');
import type {RNConfig} from '../core';
@ -20,15 +19,12 @@ import type {Args as RunServerArgs} from './runServer';
/**
* Starts the React Native Packager Server.
*/
function server(argv: mixed, config: RNConfig, allArgs: Object) {
const {root, ...args} = allArgs;
args.projectRoots = args.projectRoots.concat(root);
function server(argv: mixed, config: RNConfig, args: Object) {
const startedCallback = logReporter => {
logReporter.update({
type: 'initialize_started',
port: args.port,
projectRoots: args.projectRoots,
projectRoots: args.watchFolders,
});
process.on('uncaughtException', error => {
@ -68,19 +64,19 @@ module.exports = {
default: '',
},
{
command: '--root [list]',
description:
'add another root(s) to be used by the packager in this project',
parse: (val: string) => val.split(',').map(root => path.resolve(root)),
default: [],
command: '--projectRoot [string]',
description: 'Specify the main project root',
default: (config: ConfigT) => {
return config.getProjectRoot();
},
},
{
command: '--watchFolders [list]',
description:
'Sepcify any additional folders to be added to the watch list',
'Specify any additional folders to be added to the watch list',
parse: (val: string) => val.split(','),
default: (config: ConfigT) => {
return config.getProjectRoots ? config.getProjectRoots() : undefined;
return config.getWatchFolders();
},
},
{