Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: use NODE_BINARY when starting packager #24156

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,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"
Esemesek marked this conversation as resolved.
Show resolved Hide resolved
Esemesek marked this conversation as resolved.
Show resolved Hide resolved

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SC1090: (warning) Can't follow non-constant source. Use a directive to specify location.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SC1090: (warning) Can't follow non-constant source. Use a directive to specify location.


# 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'
Esemesek marked this conversation as resolved.
Show resolved Hide resolved
Esemesek marked this conversation as resolved.
Show resolved Hide resolved

[ -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