mirror of
https://github.com/status-im/react-native.git
synced 2025-02-24 15:18:10 +00:00
Fix symlink resolving for examples in the repo
Summary:
Motivation:
Few days ago gaearon [filed an issue](https://github.com/facebook/react-native/issues/12406) that examples in the react-native repo doesn't work after the [recent changes in local-cli](bce6ece5f6
). This PR fixes reported bug.
**Test plan (required)**
- No UI changes
- [x] Run UIExplorer from XCode (no package.json in the folder) and check if packager/application runs correctly
cc davidaurelio satya164 grabbou
Closes https://github.com/facebook/react-native/pull/12435
Differential Revision: D4657370
Pulled By: ericvicenti
fbshipit-source-id: 72ee4b96cae37c7ed2794ed4490ce7b4fbbd66c3
This commit is contained in:
parent
5353d39172
commit
c97c1e5516
@ -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()]);
|
||||
},
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user