diff --git a/package.json b/package.json index d058c1fece8ce9..c9600193565d62 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "scripts/launchPackager.command", "scripts/packager.sh", "scripts/react-native-xcode.sh", + "scripts/node-binary.sh", "jest-preset.js", "jest", "lib", diff --git a/scripts/node-binary.sh b/scripts/node-binary.sh new file mode 100644 index 00000000000000..7a0f657e9ff7e5 --- /dev/null +++ b/scripts/node-binary.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +[ -z "$NODE_BINARY" ] && export NODE_BINARY="node" + +nodejs_not_found() +{ + echo "error: Can't find the '$NODE_BINARY' binary to build the React Native bundle. " \ + "If you have a non-standard Node.js installation, select your project in Xcode, find " \ + "'Build Phases' - 'Bundle React Native code and images' and change NODE_BINARY to an " \ + "absolute path to your node executable. You can find it by invoking 'which node' in the terminal." >&2 + exit 2 +} + +type "$NODE_BINARY" >/dev/null 2>&1 || nodejs_not_found diff --git a/scripts/packager.sh b/scripts/packager.sh index e5bb1e903f0282..1df530fe407a58 100755 --- a/scripts/packager.sh +++ b/scripts/packager.sh @@ -13,6 +13,10 @@ PROJECT_ROOT="$THIS_DIR/../../.." # shellcheck source=/dev/null source "${THIS_DIR}/.packager.env" +# check and assign NODE_BINARY env +# shellcheck disable=SC1091 +source "${THIS_DIR}/node-binary.sh" + # When running react-native tests, react-native doesn't live in node_modules but in the PROJECT_ROOT if [ ! -d "$PROJECT_ROOT/node_modules/react-native" ]; then @@ -20,4 +24,4 @@ then fi # Start packager from PROJECT_ROOT cd "$PROJECT_ROOT" || exit -node "$REACT_NATIVE_ROOT/cli.js" start "$@" +"$NODE_BINARY" "$REACT_NATIVE_ROOT/cli.js" start "$@" diff --git a/scripts/react-native-xcode.sh b/scripts/react-native-xcode.sh index 3848f0624cdcea..e4d871c7f8f817 100755 --- a/scripts/react-native-xcode.sh +++ b/scripts/react-native-xcode.sh @@ -93,7 +93,9 @@ if [[ ! -x node && -d ${HOME}/.anyenv/bin ]]; then fi fi -[ -z "$NODE_BINARY" ] && export NODE_BINARY="node" +# check and assign NODE_BINARY env +# shellcheck disable=SC1091 +source './node-binary.sh' [ -z "$NODE_ARGS" ] && export NODE_ARGS="" @@ -107,18 +109,6 @@ else CONFIG_ARG="--config $BUNDLE_CONFIG" fi -nodejs_not_found() -{ - echo "error: Can't find '$NODE_BINARY' binary to build React Native bundle" >&2 - echo "If you have non-standard nodejs installation, select your project in Xcode," >&2 - echo "find 'Build Phases' - 'Bundle React Native code and images'" >&2 - echo "and change NODE_BINARY to absolute path to your node executable" >&2 - echo "(you can find it by invoking 'which node' in the terminal)" >&2 - exit 2 -} - -type "$NODE_BINARY" >/dev/null 2>&1 || nodejs_not_found - BUNDLE_FILE="$DEST/main.jsbundle" "$NODE_BINARY" $NODE_ARGS "$CLI_PATH" $BUNDLE_COMMAND \