Skip to content

Commit d403c24

Browse files
franticMartin Konicek
authored andcommitted
Improve react-native-xcode.sh integration
Summary: Inspired by conversation in #5374, this PR improves `react-native-xcode.sh`: * No longer depends on global `react-native` binary * Gracefully handles missing `node` dependency and adds a new way to configure the path to `node` in non-standard installation environments This is how the error looks like: ![image](https://cloud.githubusercontent.com/assets/192222/12538882/3f9b5c3e-c29a-11e5-84fc-c7ccedf1c46a.png) Closes #5518 Reviewed By: svcscm Differential Revision: D2861116 Pulled By: frantic fb-gh-sync-id: 9a80eda6c844d066e34369b1cda503955171485b
1 parent 9f07e1f commit d403c24

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

local-cli/generator-ios/templates/xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@
525525
);
526526
runOnlyForDeploymentPostprocessing = 0;
527527
shellPath = /bin/sh;
528-
shellScript = "../node_modules/react-native/packager/react-native-xcode.sh";
528+
shellScript = "export NODE_BINARY=node\n../node_modules/react-native/packager/react-native-xcode.sh";
529529
showEnvVarsInLog = 1;
530530
};
531531
/* End PBXShellScriptBuildPhase section */

packager/react-native-xcode.sh

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ case "$CONFIGURATION" in
2323
;;
2424
esac
2525

26+
# Path to react-native folder inside node_modules
27+
REACT_NATIVE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
28+
2629
# Xcode project file for React Native apps is located in ios/ subfolder
2730
cd ..
2831

29-
set -x
30-
DEST=$CONFIGURATION_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH
31-
3232
# Define NVM_DIR and source the nvm.sh setup script
3333
[ -z "$NVM_DIR" ] && export NVM_DIR="$HOME/.nvm"
3434

@@ -43,10 +43,25 @@ if [[ -x "$HOME/.nodenv/bin/nodenv" ]]; then
4343
eval "$($HOME/.nodenv/bin/nodenv init -)"
4444
fi
4545

46-
# npm global install path may be a non-standard location
47-
PATH="$(npm prefix -g)/bin:$PATH"
46+
[ -z "$NODE_BINARY" ] && export NODE_BINARY="node"
47+
48+
nodejs_not_found()
49+
{
50+
echo "error: Can't find '$NODE_BINARY' binary to build React Native bundle" >&2
51+
echo "If you have non-standard nodejs installation, select your project in Xcode," >&2
52+
echo "find 'Build Phases' - 'Bundle React Native code and images'" >&2
53+
echo "and change NODE_BINARY to absolute path to your node executable" >&2
54+
echo "(you can find it by invoking 'which node' in the terminal)" >&2
55+
exit 2
56+
}
57+
58+
type $NODE_BINARY >/dev/null 2>&1 || nodejs_not_found
59+
60+
# Print commands before executing them (useful for troubleshooting)
61+
set -x
62+
DEST=$CONFIGURATION_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH
4863

49-
react-native bundle \
64+
$NODE_BINARY $REACT_NATIVE_DIR/local-cli/cli.js bundle \
5065
--entry-file index.ios.js \
5166
--platform ios \
5267
--dev $DEV \

0 commit comments

Comments
 (0)