Skip to content

Commit 045b574

Browse files
committed
Improve react-native-xcode.sh integration
1 parent 0998273 commit 045b574

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-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: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
# This script is supposed to be invoked as part of Xcode build process
1111
# and relies on envoronment variables (including PWD) set by Xcode
1212

13+
PACKAGER_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
14+
1315
case "$CONFIGURATION" in
1416
Debug)
1517
DEV=true
@@ -26,9 +28,6 @@ esac
2628
# Xcode project file for React Native apps is located in ios/ subfolder
2729
cd ..
2830

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

@@ -43,10 +42,25 @@ if [[ -x "$HOME/.nodenv/bin/nodenv" ]]; then
4342
eval "$($HOME/.nodenv/bin/nodenv init -)"
4443
fi
4544

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

49-
react-native bundle \
63+
$NODE_BINARY $PACKAGER_DIR/../local-cli/cli.js bundle \
5064
--entry-file index.ios.js \
5165
--platform ios \
5266
--dev $DEV \

0 commit comments

Comments
 (0)