Skip to content

Commit 9a77ff5

Browse files
rafecafacebook-github-bot
authored andcommitted
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 #20712 Reviewed By: hramos Differential Revision: D9444982 fbshipit-source-id: 4cb41fa5224d2addf92976cc119e49dea6a6346b
1 parent b620cca commit 9a77ff5

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

local-cli/util/Config.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const {loadConfig} = require('metro-config');
2121
*/
2222
import type {ConfigT} from 'metro-config/src/configTypes.flow';
2323

24-
function getProjectPath() {
24+
function getProjectRoot() {
2525
if (
2626
__dirname.match(/node_modules[\/\\]react-native[\/\\]local-cli[\/\\]util$/)
2727
) {
@@ -44,12 +44,12 @@ const resolveSymlinksForRoots = roots =>
4444
[...roots],
4545
);
4646

47-
const getProjectRoots = () => {
47+
const getWatchFolders = () => {
4848
const root = process.env.REACT_NATIVE_APP_ROOT;
4949
if (root) {
5050
return resolveSymlinksForRoots([path.resolve(root)]);
5151
}
52-
return resolveSymlinksForRoots([getProjectPath()]);
52+
return [];
5353
};
5454

5555
const getBlacklistRE = () => {
@@ -76,17 +76,15 @@ const Config = {
7676
],
7777
getPolyfills,
7878
},
79-
80-
watchFolders: [getProjectPath(), ...getProjectRoots()],
79+
watchFolders: getWatchFolders(),
8180
transformModulePath: require.resolve('metro/src/reactNativeTransformer'),
8281
},
8382

84-
getProjectPath,
85-
getProjectRoots,
86-
8783
async load(configFile: ?string): Promise<ConfigT> {
84+
const argv = {cwd: getProjectRoot()};
85+
8886
return await loadConfig(
89-
configFile ? {config: configFile} : {},
87+
configFile ? {...argv, config: configFile} : argv,
9088
this.DEFAULT,
9189
);
9290
},

0 commit comments

Comments
 (0)