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

View File

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