Skip to content

Commit 33ba5e8

Browse files
rafecafacebook-github-bot
authored andcommitted
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: c5ce762#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
1 parent 8ef539e commit 33ba5e8

2 files changed

Lines changed: 12 additions & 16 deletions

File tree

local-cli/server/runServer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export type Args = {|
5656
+nonPersistent: boolean,
5757
+platforms: $ReadOnlyArray<string>,
5858
+port: number,
59-
+projectRoots: $ReadOnlyArray<string>,
59+
+projectRoot: string,
6060
+resetCache: boolean,
6161
+sourceExts: $ReadOnlyArray<string>,
6262
+verbose: boolean,
@@ -197,7 +197,7 @@ function getPackagerServer(args, config, reporter) {
197197
polyfillModuleNames: config.getPolyfillModuleNames(),
198198
postMinifyProcess: config.postMinifyProcess,
199199
postProcessBundleSourcemap: config.postProcessBundleSourcemap,
200-
projectRoot: config.getProjectRoot(),
200+
projectRoot: args.projectRoot,
201201
providesModuleNodeModules: providesModuleNodeModules,
202202
reporter,
203203
resetCache: args.resetCache,
@@ -206,7 +206,7 @@ function getPackagerServer(args, config, reporter) {
206206
transformModulePath: transformModulePath,
207207
verbose: args.verbose,
208208
watch: !args.nonPersistent,
209-
watchFolders: config.getWatchFolders(),
209+
watchFolders: args.watchFolders,
210210
workerPath: config.getWorkerPath(),
211211
});
212212
}

local-cli/server/server.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
'use strict';
1212

13-
const path = require('path');
1413
const runServer = require('./runServer');
1514

1615
import type {RNConfig} from '../core';
@@ -20,15 +19,12 @@ import type {Args as RunServerArgs} from './runServer';
2019
/**
2120
* Starts the React Native Packager Server.
2221
*/
23-
function server(argv: mixed, config: RNConfig, allArgs: Object) {
24-
const {root, ...args} = allArgs;
25-
args.projectRoots = args.projectRoots.concat(root);
26-
22+
function server(argv: mixed, config: RNConfig, args: Object) {
2723
const startedCallback = logReporter => {
2824
logReporter.update({
2925
type: 'initialize_started',
3026
port: args.port,
31-
projectRoots: args.projectRoots,
27+
projectRoots: args.watchFolders,
3228
});
3329

3430
process.on('uncaughtException', error => {
@@ -68,19 +64,19 @@ module.exports = {
6864
default: '',
6965
},
7066
{
71-
command: '--root [list]',
72-
description:
73-
'add another root(s) to be used by the packager in this project',
74-
parse: (val: string) => val.split(',').map(root => path.resolve(root)),
75-
default: [],
67+
command: '--projectRoot [string]',
68+
description: 'Specify the main project root',
69+
default: (config: ConfigT) => {
70+
return config.getProjectRoot();
71+
},
7672
},
7773
{
7874
command: '--watchFolders [list]',
7975
description:
80-
'Sepcify any additional folders to be added to the watch list',
76+
'Specify any additional folders to be added to the watch list',
8177
parse: (val: string) => val.split(','),
8278
default: (config: ConfigT) => {
83-
return config.getProjectRoots ? config.getProjectRoots() : undefined;
79+
return config.getWatchFolders();
8480
},
8581
},
8682
{

0 commit comments

Comments
 (0)