react-native/local-cli/default.config.js
Chris Liu a1e105eea5 react app root path can be override by env var 'react_native_app_root'
Summary:This PR is to solve app build issue when node_modules is a symlink by providing an environmental variable to override the current *smart* guessing of app root path.
I met this issue when I tried to setup a shared incremental node_modules directory to speed our react-native app build speed in CI. But the build crashed in step 'bundleReleaseJsAndAssets' with error messages like:
> :app:bundleReleaseJsAndAssets
> bundle: Created ReactPackager
> uncaught error Error: NotFoundError: Cannot find entry file index.android.js in any of the roots:["/home/jenkins/shared_data"]

The build is fixed by applying this patch and adding 'export react_native_app_root=${WORKSPACE}' before './gradlew assembleRelease' in build script.

**Test plan**
1. react-native init demo # init a demo app from scratch
2. cd demo/android && ./gradlew assembleRelease # build works fine
3. mkdir ~/shared_data && mv ../node_modules ~/shared_data && cd .. && ln -s ~/shared_data/node_modules . # create symlink for node_modules in shared d
Closes https://github.com/facebook/react-native/pull/6859

Differential Revision: D3150341

fb-gh-sync-id: efbe19b7f6b3053f18d8e568deb75d24861c27ff
fbshipit-source-id: efbe19b7f6b3053f18d8e568deb75d24861c27ff
2016-04-07 07:39:22 -07:00

54 lines
1.4 KiB
JavaScript

'use strict';
var blacklist = require('../packager/blacklist');
var path = require('path');
/**
* Default configuration for the CLI.
*
* If you need to override any of this functions do so by defining the file
* `rn-cli.config.js` on the root of your project with the functions you need
* to tweak.
*/
var config = {
getProjectRoots() {
return getRoots();
},
/**
* Specify where to look for assets that are referenced using
* `image!<image_name>`. Asset directories for images referenced using
* `./<image.extension>` don't require any entry in here.
*/
getAssetRoots() {
return getRoots();
},
/**
* Returns a regular expression for modules that should be ignored by the
* packager on a given platform.
*/
getBlacklistRE(platform) {
return blacklist(platform);
}
};
function getRoots() {
var root = process.env.REACT_NATIVE_APP_ROOT;
if (root) {
return [path.resolve(root)];
}
if (__dirname.match(/node_modules[\/\\]react-native[\/\\]local-cli$/)) {
// 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, '../../..')];
} else {
return [path.resolve(__dirname, '..')];
}
}
module.exports = config;