From 34487c059192129db07608af4eb27cfad22b2d06 Mon Sep 17 00:00:00 2001 From: Rafael Oleza Date: Tue, 26 Sep 2017 12:54:44 -0700 Subject: [PATCH] Make the runBeforeMainModule config param to RN repo and make it absolute Reviewed By: davidaurelio Differential Revision: D5880700 fbshipit-source-id: 5df6781026030395900388c561283abadefa6511 --- local-cli/bundle/buildBundle.js | 1 + local-cli/server/runServer.js | 1 + local-cli/util/Config.js | 20 +++++++++++--------- rn-cli.config.js | 3 +++ 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/local-cli/bundle/buildBundle.js b/local-cli/bundle/buildBundle.js index 07f09cde1..d04bb0e1e 100644 --- a/local-cli/bundle/buildBundle.js +++ b/local-cli/bundle/buildBundle.js @@ -125,6 +125,7 @@ function buildBundle( providesModuleNodeModules: providesModuleNodeModules, resetCache: args.resetCache, reporter: new TerminalReporter(terminal), + runBeforeMainModule: config.runBeforeMainModule, sourceExts: defaultSourceExts.concat(sourceExts), transformCache: TransformCaching.useTempDir(), transformModulePath: transformModulePath, diff --git a/local-cli/server/runServer.js b/local-cli/server/runServer.js index d9eae75b1..7b1dd4e8e 100644 --- a/local-cli/server/runServer.js +++ b/local-cli/server/runServer.js @@ -194,6 +194,7 @@ function getPackagerServer(args, config, reporter) { postProcessModules: config.postProcessModules, projectRoots: args.projectRoots, providesModuleNodeModules: providesModuleNodeModules, + runBeforeMainModule: config.runBeforeMainModule, reporter, resetCache: args.resetCache, sourceExts: defaultSourceExts.concat(args.sourceExts), diff --git a/local-cli/util/Config.js b/local-cli/util/Config.js index 5feea3d7a..91f84c8c1 100644 --- a/local-cli/util/Config.js +++ b/local-cli/util/Config.js @@ -6,6 +6,7 @@ * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. * + * @format * @flow */ 'use strict'; @@ -28,7 +29,9 @@ import type {ConfigT as MetroConfigT} from 'metro-bundler'; export type ConfigT = MetroConfigT; function getProjectPath() { - if (__dirname.match(/node_modules[\/\\]react-native[\/\\]local-cli[\/\\]util$/)) { + if ( + __dirname.match(/node_modules[\/\\]react-native[\/\\]local-cli[\/\\]util$/) + ) { // Packager is running from node_modules. // This is the default case for all projects created using 'react-native init'. return path.resolve(__dirname, '../../../..'); @@ -41,10 +44,8 @@ function getProjectPath() { const resolveSymlinksForRoots = roots => roots.reduce( - (arr, rootPath) => arr.concat( - findSymlinkedModules(rootPath, roots) - ), - [...roots] + (arr, rootPath) => arr.concat(findSymlinkedModules(rootPath, roots)), + [...roots], ); const getProjectRoots = () => { @@ -68,6 +69,9 @@ const Config = { ...MetroConfig.DEFAULT, getProjectRoots, getPolyfills, + runBeforeMainModule: [ + require.resolve('../../Libraries/Core/InitializeCore'), + ], }: ConfigT), find(startDir: string): ConfigT { @@ -86,9 +90,7 @@ const Config = { findOptional(startDir: string): ConfigT { const configPath = findConfigPath(startDir); - return configPath - ? this.load(configPath, startDir) - : {...Config.DEFAULT}; + return configPath ? this.load(configPath, startDir) : {...Config.DEFAULT}; }, load(configFile: string): ConfigT { @@ -105,7 +107,7 @@ function findConfigPath(cwd: string): ?string { // a file named `filename` function findParentDirectory(currentFullPath, filename) { const root = path.parse(currentFullPath).root; - const testDir = (parts) => { + const testDir = parts => { if (parts.length === 0) { return null; } diff --git a/rn-cli.config.js b/rn-cli.config.js index 59ac25a14..2f6f5f203 100644 --- a/rn-cli.config.js +++ b/rn-cli.config.js @@ -5,6 +5,9 @@ * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. + * + * @flow + * @format */ 'use strict';