Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix symlink resolving for examples in the repo #12435

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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