From 33ba5e8fa26a3e8f32e386f377107a7a03743360 Mon Sep 17 00:00:00 2001 From: Rafael Oleza Date: Fri, 22 Jun 2018 08:09:48 -0700 Subject: [PATCH] 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: https://github.com/facebook/react-native/commit/c5ce7626977a7650e8dce335f2ce78b94839a2a8#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 --- local-cli/server/runServer.js | 6 +++--- local-cli/server/server.js | 22 +++++++++------------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/local-cli/server/runServer.js b/local-cli/server/runServer.js index e2a0b10bf..e2d57d4b1 100644 --- a/local-cli/server/runServer.js +++ b/local-cli/server/runServer.js @@ -56,7 +56,7 @@ export type Args = {| +nonPersistent: boolean, +platforms: $ReadOnlyArray, +port: number, - +projectRoots: $ReadOnlyArray, + +projectRoot: string, +resetCache: boolean, +sourceExts: $ReadOnlyArray, +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(), }); } diff --git a/local-cli/server/server.js b/local-cli/server/server.js index d4d977a61..f74f7f16a 100644 --- a/local-cli/server/server.js +++ b/local-cli/server/server.js @@ -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(); }, }, {