Skip to content

Commit

Permalink
Fix default projectRoot + watchFolders computation
Browse files Browse the repository at this point in the history
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 facebook#20712

Reviewed By: hramos

Differential Revision: D9444982

fbshipit-source-id: 4cb41fa5224d2addf92976cc119e49dea6a6346b
  • Loading branch information
rafeca authored and aleclarson committed Sep 15, 2018
1 parent 0af120a commit 35b50c2
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions local-cli/util/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,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$/)
) {
Expand Down Expand Up @@ -51,12 +51,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 = () => {
Expand All @@ -83,17 +83,15 @@ const Config = {
],
getPolyfills,
},

watchFolders: [getProjectPath(), ...getProjectRoots()],
watchFolders: getWatchFolders(),
transformModulePath: require.resolve('metro/src/reactNativeTransformer'),
},

getProjectPath,
getProjectRoots,

async load(configFile: ?string): Promise<ConfigT> {
const argv = {cwd: getProjectRoot()};

return await loadConfig(
configFile ? {config: configFile} : {},
configFile ? {...argv, config: configFile} : argv,
this.DEFAULT,
);
},
Expand Down

0 comments on commit 35b50c2

Please sign in to comment.