diff --git a/local-cli/core/default.config.js b/local-cli/core/default.config.js index 1c4d01a6901cf6..c3fb67a4eb8462 100644 --- a/local-cli/core/default.config.js +++ b/local-cli/core/default.config.js @@ -22,6 +22,9 @@ 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'; const getRNPMConfig = (folder) => @@ -32,6 +35,9 @@ const attachPackage = (command, pkg) => Array.isArray(command) ? command.map(cmd => attachPackage(cmd, pkg)) : { ...command, pkg }; +const addSymlinkToRoots = (roots) => + roots.concat(findSymlinksPaths(NODE_MODULES, roots)); + /** * Default configuration for the CLI. * @@ -97,18 +103,21 @@ const config: ConfigT = { getProjectRoots() { const root = process.env.REACT_NATIVE_APP_ROOT; if (root) { - return [path.resolve(root)]; + return addSymlinkToRoots([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'. - return [path.resolve(__dirname, '../../../..')]; + roots = [path.resolve(__dirname, '../../../..')]; } else if (__dirname.match(/Pods[\/\\]React[\/\\]packager$/)) { // React Native was installed using CocoaPods. - return [path.resolve(__dirname, '../../../..')]; + roots = [path.resolve(__dirname, '../../../..')]; } else { - return [path.resolve(__dirname, '../..')]; + roots = [path.resolve(__dirname, '../..')]; } + return addSymlinkToRoots(roots); }, }; diff --git a/local-cli/server/server.js b/local-cli/server/server.js index 72e9a017b96e92..879c5995f407ad 100644 --- a/local-cli/server/server.js +++ b/local-cli/server/server.js @@ -9,20 +9,15 @@ 'use strict'; const chalk = require('chalk'); -const findSymlinksPaths = require('./findSymlinksPaths'); const formatBanner = require('./formatBanner'); const path = require('path'); const runServer = require('./runServer'); -const NODE_MODULES = path.resolve(__dirname, '..', '..', '..'); /** * Starts the React Native Packager Server. */ function server(argv, config, args) { - const roots = args.projectRoots.concat(args.root); - args.projectRoots = roots.concat( - findSymlinksPaths(NODE_MODULES, roots) - ); + args.projectRoots.concat(args.root); console.log(formatBanner( 'Running packager on port ' + args.port + '.\n\n' + diff --git a/local-cli/server/findSymlinksPaths.js b/local-cli/util/findSymlinksPaths.js similarity index 100% rename from local-cli/server/findSymlinksPaths.js rename to local-cli/util/findSymlinksPaths.js