Skip to content

Commit

Permalink
Re-use Node path resolution script
Browse files Browse the repository at this point in the history
Summary:
This fix is ported from 0.64-stable. It moves the Node resolution script from react-native-xcode.sh to find-node.sh for re-use in the codegen.

Changelog: [Codegen][Internal]

Reviewed By: fkgozali

Differential Revision: D27437216

fbshipit-source-id: ecb8a7a30411a709c095a0a34115b6dc48b99f1e
  • Loading branch information
hramos authored and facebook-github-bot committed Apr 2, 2021
1 parent a782b6f commit 322e8f7
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 29 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"README.md",
"rn-get-polyfills.js",
"scripts/compose-source-maps.js",
"scripts/find-node.sh",
"scripts/generate-specs.sh",
"scripts/generate-specs-cli.js",
"scripts/ios-configure-glog.sh",
Expand Down
33 changes: 33 additions & 0 deletions scripts/find-node.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/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.

set -e

# Define NVM_DIR and source the nvm.sh setup script
[ -z "$NVM_DIR" ] && export NVM_DIR="$HOME/.nvm"

if [[ -s "$HOME/.nvm/nvm.sh" ]]; then
# shellcheck source=/dev/null
. "$HOME/.nvm/nvm.sh"
elif [[ -x "$(command -v brew)" && -s "$(brew --prefix nvm)/nvm.sh" ]]; then
# shellcheck source=/dev/null
. "$(brew --prefix nvm)/nvm.sh"
fi

# Set up the nodenv node version manager if present
if [[ -x "$HOME/.nodenv/bin/nodenv" ]]; then
eval "$("$HOME/.nodenv/bin/nodenv" init -)"
elif [[ -x "$(command -v brew)" && -x "$(brew --prefix nodenv)/bin/nodenv" ]]; then
eval "$("$(brew --prefix nodenv)/bin/nodenv" init -)"
fi

# Set up the ndenv of anyenv if preset
if [[ ! -x node && -d ${HOME}/.anyenv/bin ]]; then
export PATH=${HOME}/.anyenv/bin:${PATH}
if [[ "$(anyenv envs | grep -c ndenv )" -eq 1 ]]; then
eval "$(anyenv init -)"
fi
fi
11 changes: 5 additions & 6 deletions scripts/generate-specs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ RN_DIR=$(cd "$THIS_DIR/.." && pwd)
NODE_BINARY="${NODE_BINARY:-$(command -v node || true)}"
USE_FABRIC="${USE_FABRIC:-0}"

# Find path to Node
# shellcheck source=/dev/null
source "$RN_DIR/scripts/find-node.sh"

cleanup () {
set +e
rm -rf "$TEMP_DIR"
Expand All @@ -56,7 +60,7 @@ main() {
CODEGEN_REPO_PATH="$RN_DIR/packages/react-native-codegen"
CODEGEN_NPM_PATH="$RN_DIR/../react-native-codegen"

if [ -z "$NODE_BINARY" ]; then
if [ -z "$NODE_BINARY" ]; then
echo "Error: Could not find node. Make sure it is in bash PATH or set the NODE_BINARY environment variable." 1>&2
exit 1
fi
Expand All @@ -75,11 +79,6 @@ if [ -z "$NODE_BINARY" ]; then
bash "$CODEGEN_PATH/scripts/oss/build.sh"
fi

if [ -z "$NODE_BINARY" ]; then
echo "Error: Could not find node. Make sure it is in bash PATH or set the NODE_BINARY environment variable." 1>&2
exit 1
fi

describe "Generating schema from flow types"
"$NODE_BINARY" "$CODEGEN_PATH/lib/cli/combine/combine-js-to-schema-cli.js" "$SCHEMA_FILE" "$SRCS_DIR"

Expand Down
26 changes: 3 additions & 23 deletions scripts/react-native-xcode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ PROJECT_ROOT=${PROJECT_ROOT:-"$REACT_NATIVE_DIR/../.."}

cd "$PROJECT_ROOT" || exit

# Define NVM_DIR and source the nvm.sh setup script
[ -z "$NVM_DIR" ] && export NVM_DIR="$HOME/.nvm"

# Define entry file
if [[ "$ENTRY_FILE" ]]; then
# Use ENTRY_FILE defined by user
Expand All @@ -82,26 +79,9 @@ if [[ $DEV != true && ! -f "$ENTRY_FILE" ]]; then
exit 2
fi

if [[ -s "$HOME/.nvm/nvm.sh" ]]; then
. "$HOME/.nvm/nvm.sh"
elif [[ -x "$(command -v brew)" && -s "$(brew --prefix nvm)/nvm.sh" ]]; then
. "$(brew --prefix nvm)/nvm.sh"
fi

# Set up the nodenv node version manager if present
if [[ -x "$HOME/.nodenv/bin/nodenv" ]]; then
eval "$("$HOME/.nodenv/bin/nodenv" init -)"
elif [[ -x "$(command -v brew)" && -x "$(brew --prefix nodenv)/bin/nodenv" ]]; then
eval "$("$(brew --prefix nodenv)/bin/nodenv" init -)"
fi

# Set up the ndenv of anyenv if preset
if [[ ! -x node && -d ${HOME}/.anyenv/bin ]]; then
export PATH=${HOME}/.anyenv/bin:${PATH}
if [[ "$(anyenv envs | grep -c ndenv )" -eq 1 ]]; then
eval "$(anyenv init -)"
fi
fi
# Find path to Node
# shellcheck source=/dev/null
source "$RN_DIR/scripts/find-node.sh"

This comment has been minimized.

Copy link
@devoto13

devoto13 Oct 6, 2021

@hramos There is no $RN_DIR variable defined in this script, which breaks build run from Xcode app. I assume you wanted to change it to $REACT_NATIVE_DIR here?

Ah, never mind, noticed that it was fixed in the latter commit.


# check and assign NODE_BINARY env
# shellcheck source=/dev/null
Expand Down

0 comments on commit 322e8f7

Please sign in to comment.