Skip to content

Commit

Permalink
Fix: use NODE_BINARY when starting packager (facebook#24156)
Browse files Browse the repository at this point in the history
Summary:
Fix packager script to use `NODE_BINARY` env variable.

Should fix facebook#22868

[iOS] [Fixed] - Use `NODE_BINARY` env variable in `packager.sh` script
Pull Request resolved: facebook#24156

Differential Revision: D14870783

Pulled By: cpojer

fbshipit-source-id: 27ecf8bf59883920ab51478b8a4d8f0780e34664
  • Loading branch information
Esemesek authored and dsyang committed Apr 12, 2019
1 parent 9b6ae6b commit 27a7e20
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"scripts/launchPackager.command",
"scripts/packager.sh",
"scripts/react-native-xcode.sh",
"scripts/node-binary.sh",
"jest-preset.js",
"jest",
"lib",
Expand Down
18 changes: 18 additions & 0 deletions scripts/node-binary.sh
Original file line number Diff line number Diff line change
@@ -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
6 changes: 5 additions & 1 deletion scripts/packager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ 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
PROJECT_ROOT="$THIS_DIR/.."
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 "$@"
16 changes: 3 additions & 13 deletions scripts/react-native-xcode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=""

Expand All @@ -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 \
Expand Down

0 comments on commit 27a7e20

Please sign in to comment.