Fix usage of react-native cli inside package.json scripts

Summary:
IIRC we made `wrong-react-native` to warn people in case they installed `react-native` globally (instead of `react-native-cli` what the guide suggests). To do that we added `bin` entry to React Native's `package.json` that points to `local-cli/wrong-react-native.js`

However, this means that if we have a project that uses `react-native` package and has call to `react-native` CLI inside its package.json, npm will execute *local* override (which just prints a confusing in this context error message).

In fact, the template we generate with `react-native init` has `react-native start` as `start` script, which makes it useless. Let's fix it by making `wrong-react-native` script smarter – it can detect that it has been executed from local `node_modules` and run the actual CLI.

cc vjeux ide
Closes https://github.com/facebook/react-native/pull/7243

Differential Revision: D3226645

Pulled By: frantic

fb-gh-sync-id: be094eb0e70e491da4ebefc2abf11cff56c4c5b7
fbshipit-source-id: be094eb0e70e491da4ebefc2abf11cff56c4c5b7
This commit is contained in:
Alex Kotliarskyi 2016-04-26 15:40:23 -07:00 committed by Facebook Github Bot 7
parent b5d9bf0fb2
commit 8295d27a90
1 changed files with 13 additions and 7 deletions

View File

@ -9,11 +9,17 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
console.error([
'\033[31mLooks like you installed react-native globally, maybe you meant react-native-cli?',
'To fix the issue, run:\033[0m',
'npm uninstall -g react-native',
'npm install -g react-native-cli'
].join('\n'));
var script = process.argv[1];
var installedGlobally = script.indexOf('node_modules/.bin/react-native') === -1;
process.exit(1);
if (installedGlobally) {
console.error([
'\033[31mLooks like you installed react-native globally, maybe you meant react-native-cli?',
'To fix the issue, run:\033[0m',
'npm uninstall -g react-native',
'npm install -g react-native-cli'
].join('\n'));
process.exit(1);
} else {
require('./cli').run();
}