Skip to content

Commit

Permalink
Fix symlink resolving for examples in the repo
Browse files Browse the repository at this point in the history
  • Loading branch information
Kureev committed Feb 27, 2017
1 parent 84a681c commit 316f9ae
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions local-cli/core/default.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || {};
Expand All @@ -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.
Expand Down Expand Up @@ -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()]);
},
};

Expand Down

0 comments on commit 316f9ae

Please sign in to comment.