Skip to content

Commit 265ae58

Browse files
Esemesekfacebook-github-bot
authored andcommitted
Fix: use NODE_BINARY when starting packager (#24156)
Summary: Fix packager script to use `NODE_BINARY` env variable. Should fix #22868 [iOS] [Fixed] - Use `NODE_BINARY` env variable in `packager.sh` script Pull Request resolved: #24156 Differential Revision: D14870783 Pulled By: cpojer fbshipit-source-id: 27ecf8bf59883920ab51478b8a4d8f0780e34664
1 parent a05b409 commit 265ae58

File tree

4 files changed

+27
-14
lines changed

4 files changed

+27
-14
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"scripts/launchPackager.command",
3737
"scripts/packager.sh",
3838
"scripts/react-native-xcode.sh",
39+
"scripts/node-binary.sh",
3940
"jest-preset.js",
4041
"jest",
4142
"lib",

scripts/node-binary.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
# Copyright (c) Facebook, Inc. and its affiliates.
3+
#
4+
# This source code is licensed under the MIT license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
[ -z "$NODE_BINARY" ] && export NODE_BINARY="node"
8+
9+
nodejs_not_found()
10+
{
11+
echo "error: Can't find the '$NODE_BINARY' binary to build the React Native bundle. " \
12+
"If you have a non-standard Node.js installation, select your project in Xcode, find " \
13+
"'Build Phases' - 'Bundle React Native code and images' and change NODE_BINARY to an " \
14+
"absolute path to your node executable. You can find it by invoking 'which node' in the terminal." >&2
15+
exit 2
16+
}
17+
18+
type "$NODE_BINARY" >/dev/null 2>&1 || nodejs_not_found

scripts/packager.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@ PROJECT_ROOT="$THIS_DIR/../../.."
1313
# shellcheck source=/dev/null
1414
source "${THIS_DIR}/.packager.env"
1515

16+
# check and assign NODE_BINARY env
17+
# shellcheck disable=SC1091
18+
source "${THIS_DIR}/node-binary.sh"
19+
1620
# When running react-native tests, react-native doesn't live in node_modules but in the PROJECT_ROOT
1721
if [ ! -d "$PROJECT_ROOT/node_modules/react-native" ];
1822
then
1923
PROJECT_ROOT="$THIS_DIR/.."
2024
fi
2125
# Start packager from PROJECT_ROOT
2226
cd "$PROJECT_ROOT" || exit
23-
node "$REACT_NATIVE_ROOT/cli.js" start "$@"
27+
"$NODE_BINARY" "$REACT_NATIVE_ROOT/cli.js" start "$@"

scripts/react-native-xcode.sh

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ if [[ ! -x node && -d ${HOME}/.anyenv/bin ]]; then
9393
fi
9494
fi
9595

96-
[ -z "$NODE_BINARY" ] && export NODE_BINARY="node"
96+
# check and assign NODE_BINARY env
97+
# shellcheck disable=SC1091
98+
source './node-binary.sh'
9799

98100
[ -z "$NODE_ARGS" ] && export NODE_ARGS=""
99101

@@ -107,18 +109,6 @@ else
107109
CONFIG_ARG="--config $BUNDLE_CONFIG"
108110
fi
109111

110-
nodejs_not_found()
111-
{
112-
echo "error: Can't find '$NODE_BINARY' binary to build React Native bundle" >&2
113-
echo "If you have non-standard nodejs installation, select your project in Xcode," >&2
114-
echo "find 'Build Phases' - 'Bundle React Native code and images'" >&2
115-
echo "and change NODE_BINARY to absolute path to your node executable" >&2
116-
echo "(you can find it by invoking 'which node' in the terminal)" >&2
117-
exit 2
118-
}
119-
120-
type "$NODE_BINARY" >/dev/null 2>&1 || nodejs_not_found
121-
122112
BUNDLE_FILE="$DEST/main.jsbundle"
123113

124114
"$NODE_BINARY" $NODE_ARGS "$CLI_PATH" $BUNDLE_COMMAND \

0 commit comments

Comments
 (0)