/**
 * Copyright (c) 2015-present, Facebook, Inc.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @format
 * @flow
 */
'use strict';

const findSymlinkedModules = require('./findSymlinkedModules');
const getPolyfills = require('../../rn-get-polyfills');
const path = require('path');

const {createBlacklist} = require('metro');
const {loadConfig} = require('metro-config');

/**
 * Configuration file of the CLI.
 */
import type {ConfigT} from 'metro-config/src/configTypes.flow';

function getProjectPath() {
  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, '../../../..');
  } else if (__dirname.match(/Pods[\/\\]React[\/\\]packager$/)) {
    // React Native was installed using CocoaPods.
    return path.resolve(__dirname, '../../../..');
  }
  return path.resolve(__dirname, '../..');
}

const resolveSymlinksForRoots = roots =>
  roots.reduce(
    /* $FlowFixMe(>=0.70.0 site=react_native_fb) This comment suppresses an
     * error found when Flow v0.70 was deployed. To see the error delete this
     * comment and run Flow. */
    (arr, rootPath) => arr.concat(findSymlinkedModules(rootPath, roots)),
    [...roots],
  );

const getProjectRoots = () => {
  const root = process.env.REACT_NATIVE_APP_ROOT;
  if (root) {
    return resolveSymlinksForRoots([path.resolve(root)]);
  }
  return resolveSymlinksForRoots([getProjectPath()]);
};

const getBlacklistRE = () => {
  return createBlacklist([/.*\/__fixtures__\/.*/]);
};

/**
 * Module capable of getting the configuration out of a given file.
 *
 * The function will return all the default configuration, as specified by the
 * `DEFAULT` param overriden by those found on `rn-cli.config.js` files, if any. If no
 * default config is provided and no configuration can be found in the directory
 * hierarchy, an error will be thrown.
 */
const Config = {
  DEFAULT: {
    resolver: {
      resolverMainFields: ['react-native', 'browser', 'main'],
      blacklistRE: getBlacklistRE(),
    },
    serializer: {
      getModulesRunBeforeMainModule: () => [
        require.resolve('../../Libraries/Core/InitializeCore'),
      ],
      getPolyfills,
    },

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

  getProjectPath,
  getProjectRoots,

  async load(configFile: ?string): Promise<ConfigT> {
    return await loadConfig(
      configFile ? {config: configFile} : {},
      this.DEFAULT,
    );
  },
};

module.exports = Config;

@@ -582,20 +582,20 @@
 tProject
-Path
+Root
 () %7B%0A  i
@@ -1431,27 +1431,27 @@
 onst get
-ProjectRoot
+WatchFolder
 s = () =
@@ -1593,51 +1593,10 @@
 urn 
-resolveSymlinksForRoots(%5BgetProjectPath()%5D)
+%5B%5D
 ;%0A%7D;
@@ -2365,17 +2365,16 @@
 %0A    %7D,%0A
-%0A
     watc
@@ -2387,48 +2387,25 @@
 rs: 
-%5B
 get
-ProjectPath(), ...getProjectRoot
+WatchFolder
 s()
-%5D
 ,%0A  
@@ -2490,46 +2490,8 @@
 %7D,%0A%0A
-  getProjectPath,%0A  getProjectRoots,%0A%0A
   as
@@ -2540,16 +2540,59 @@
 figT%3E %7B%0A
+    const argv = %7Bcwd: getProjectRoot()%7D;%0A%0A
     retu
@@ -2632,16 +2632,25 @@
 File ? %7B
+...argv, 
 config: 
@@ -2667,10 +2667,12 @@
 %7D : 
-%7B%7D
+argv
 ,%0A  

Fix default projectRoot + watchFolders computation