diff --git a/local-cli/core/default.config.js b/local-cli/core/default.config.js index c3fb67a4eb8462..d01bde26265784 100644 --- a/local-cli/core/default.config.js +++ b/local-cli/core/default.config.js @@ -12,21 +12,29 @@ const path = require('path'); const flatten = require('lodash').flatten; - const blacklist = require('../../packager/blacklist'); - const android = require('./android'); const findAssets = require('./findAssets'); const ios = require('./ios'); const windows = require('./windows'); const wrapCommands = require('./wrapCommands'); const findPlugins = require('./findPlugins'); - const findSymlinksPaths = require('../util/findSymlinksPaths'); -const NODE_MODULES = path.resolve(__dirname, '..', '..', '..'); import type {ConfigT} from './index'; +function getProjectPath() { + if (__dirname.match(/node_modules[\/\\]react-native[\/\\]local-cli[\/\\]core$/)) { + // 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 getRNPMConfig = (folder) => // $FlowFixMe non-literal require require(path.join(folder, './package.json')).rnpm || {}; @@ -35,8 +43,13 @@ const attachPackage = (command, pkg) => Array.isArray(command) ? command.map(cmd => attachPackage(cmd, pkg)) : { ...command, pkg }; -const addSymlinkToRoots = (roots) => - roots.concat(findSymlinksPaths(NODE_MODULES, roots)); +const resolveSymlink = (roots) => + roots.concat( + findSymlinksPaths( + path.join(getProjectPath(), 'node_modules'), + roots + ) + ); /** * Default configuration for the CLI. @@ -103,21 +116,10 @@ const config: ConfigT = { getProjectRoots() { const root = process.env.REACT_NATIVE_APP_ROOT; if (root) { - return addSymlinkToRoots([path.resolve(root)]); + return resolveSymlink([path.resolve(root)]); } - var roots; - if (__dirname.match(/node_modules[\/\\]react-native[\/\\]local-cli[\/\\]core$/)) { - // Packager is running from node_modules. - // This is the default case for all projects created using 'react-native init'. - roots = [path.resolve(__dirname, '../../../..')]; - } else if (__dirname.match(/Pods[\/\\]React[\/\\]packager$/)) { - // React Native was installed using CocoaPods. - roots = [path.resolve(__dirname, '../../../..')]; - } else { - roots = [path.resolve(__dirname, '../..')]; - } - return addSymlinkToRoots(roots); + return resolveSymlink([getProjectPath()]); }, };