From 9a77ff593bf83a3326e6237bb877e7abc437da96 Mon Sep 17 00:00:00 2001 From: Rafael Oleza Date: Wed, 22 Aug 2018 20:23:11 -0700 Subject: [PATCH] Fix default projectRoot + watchFolders computation Summary: @public This diff fixes the `projectRoot` calculation on React Native when the app does not have a config file. This should fix the issues reported in https://github.com/facebook/react-native/issues/20712 Reviewed By: hramos Differential Revision: D9444982 fbshipit-source-id: 4cb41fa5224d2addf92976cc119e49dea6a6346b --- local-cli/util/Config.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/local-cli/util/Config.js b/local-cli/util/Config.js index b55b061ec..d6d0134d1 100644 --- a/local-cli/util/Config.js +++ b/local-cli/util/Config.js @@ -21,7 +21,7 @@ const {loadConfig} = require('metro-config'); */ import type {ConfigT} from 'metro-config/src/configTypes.flow'; -function getProjectPath() { +function getProjectRoot() { if ( __dirname.match(/node_modules[\/\\]react-native[\/\\]local-cli[\/\\]util$/) ) { @@ -44,12 +44,12 @@ const resolveSymlinksForRoots = roots => [...roots], ); -const getProjectRoots = () => { +const getWatchFolders = () => { const root = process.env.REACT_NATIVE_APP_ROOT; if (root) { return resolveSymlinksForRoots([path.resolve(root)]); } - return resolveSymlinksForRoots([getProjectPath()]); + return []; }; const getBlacklistRE = () => { @@ -76,17 +76,15 @@ const Config = { ], getPolyfills, }, - - watchFolders: [getProjectPath(), ...getProjectRoots()], + watchFolders: getWatchFolders(), transformModulePath: require.resolve('metro/src/reactNativeTransformer'), }, - getProjectPath, - getProjectRoots, - async load(configFile: ?string): Promise { + const argv = {cwd: getProjectRoot()}; + return await loadConfig( - configFile ? {config: configFile} : {}, + configFile ? {...argv, config: configFile} : argv, this.DEFAULT, ); },