UNPKG

2.99 kBapplication/x-shView Raw
1#!/bin/bash
2# Copyright (c) Meta Platforms, Inc. and 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
7set -e
8
9# WHY WE NEED THIS:
10# This script is used to find a valid instance of `node` installed in the machine.
11# This script is sourced by other scripts to get access to node.
12# Specifically, it is used by the `react-native-xcode.sh` script, invoked by a
13# post-build phase in Xcode, to build the js files required by React Native.
14#
15# DEPRECATION NOTE:
16# React Native should not make assumptions on your current node environment.
17# This file is deprecated and will be removed in a future release in favor of something
18# node-agnostic and configurable by the developers.
19
20# remove global prefix if it's already set
21# the running shell process will choose a node binary and a global package directory breaks version managers
22unset PREFIX
23
24# Support Homebrew on Apple Silicon
25HOMEBREW_APPLE_SILICON_BIN=/opt/homebrew/bin
26if [[ -d $HOMEBREW_APPLE_SILICON_BIN && ! $PATH =~ $HOMEBREW_APPLE_SILICON_BIN ]]; then
27 export PATH="$HOMEBREW_APPLE_SILICON_BIN:$PATH"
28fi
29
30# Define NVM_DIR and source the nvm.sh setup script
31[ -z "$NVM_DIR" ] && export NVM_DIR="$HOME/.nvm"
32
33# Source nvm with '--no-use' and then `nvm use` to respect .nvmrc
34# See: https://github.com/nvm-sh/nvm/issues/2053
35if [[ -s "$HOME/.nvm/nvm.sh" ]]; then
36 # shellcheck source=/dev/null
37 . "$HOME/.nvm/nvm.sh" --no-use
38 nvm use 2> /dev/null || nvm use default
39elif [[ -x "$(command -v brew)" && -s "$(brew --prefix nvm)/nvm.sh" ]]; then
40 # shellcheck source=/dev/null
41 . "$(brew --prefix nvm)/nvm.sh" --no-use
42 nvm use 2> /dev/null || nvm use default
43fi
44
45# Set up the nodenv node version manager if present
46if [[ -x "$HOME/.nodenv/bin/nodenv" ]]; then
47 eval "$("$HOME/.nodenv/bin/nodenv" init -)"
48elif [[ -x "$(command -v brew)" && -x "$(brew --prefix nodenv)/bin/nodenv" ]]; then
49 eval "$("$(brew --prefix nodenv)/bin/nodenv" init -)"
50fi
51
52# Set up the ndenv of anyenv if preset
53if [[ ! -x node && -d ${HOME}/.anyenv/bin ]]; then
54 export PATH=${HOME}/.anyenv/bin:${PATH}
55 if [[ "$(anyenv envs | grep -c ndenv )" -eq 1 ]]; then
56 eval "$(anyenv init -)"
57 fi
58fi
59
60# Set up asdf-vm if present
61if [[ -f "$ASDF_DIR/asdf.sh" ]]; then
62 # shellcheck source=/dev/null
63 . "$ASDF_DIR/asdf.sh"
64elif [[ -f "$HOME/.asdf/asdf.sh" ]]; then
65 # shellcheck source=/dev/null
66 . "$HOME/.asdf/asdf.sh"
67elif [[ -x "$(command -v brew)" && -f "$(brew --prefix asdf)/asdf.sh" ]]; then
68 # shellcheck source=/dev/null
69 . "$(brew --prefix asdf)/asdf.sh"
70fi
71
72# Set up volta if present
73if [[ -x "$HOME/.volta/bin/node" ]]; then
74 export VOLTA_HOME="$HOME/.volta"
75 export PATH="$VOLTA_HOME/bin:$PATH"
76fi
77
78# Set up the fnm node version manager if present
79if [[ -x "$HOME/.fnm/fnm" ]]; then
80 eval "$("$HOME/.fnm/fnm" env)"
81elif [[ -x "$(command -v brew)" && -x "$(brew --prefix fnm)/bin/fnm" ]]; then
82 eval "$("$(brew --prefix fnm)/bin/fnm" env)"
83fi
84
\No newline at end of file