Skip to content

Commit 35bcf93

Browse files
igraysonfacebook-github-bot
authored andcommitted
fix: find-node.sh now respects .nvmrc (#32712)
Summary: React-native Xcode build steps (such as "Build JS Bundle") rely on `find.node-sh` to find the correct node binary, using nvm if present. We do this because Xcode may run build steps in a fresh shell environment, presumably for repeatable builds. This PR fixes `find-node.sh`, to respect any `.nvmrc` file that may be present in the build environment. Today: `find-node.sh` will set the shell environment to the system node version, and ignores any `.nvmrc` the project may provide to pin node for repeatable builds. By ignoring `.nvmrc`, node versions may differ depending on system environment — between developer laptops, or between developer and CI environments. 😞 This problem has been been noticed before in #8887 ### Should this fix happen upstream? Unfortunately this nvm behavior [is intended](nvm-sh/nvm#2053), for backwards compatibility ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://github.com/facebook/react-native/wiki/Changelog --> [iOS] [Fixed] - find-node.sh now respects .nvmrc Pull Request resolved: #32712 Test Plan: Before: ```bash # nvm isn't loaded $ which nvm # we're on default system node $ which node && node --version /usr/local/bin/node v17.0.1 $ echo v16.13.0 > .nvmrc $ source ./scripts/find-node.sh # Expected: v16.13.0 $ node --version v17.0.1 ``` After: ```bash # we're on default system node $ which node && node --version /usr/local/bin/node v17.0.1 $ echo v16.13.0 > .nvmrc $ source ./scripts/find-node.sh # Expected: v16.13.0 $ node --version v16.13.0 ``` After (no .nvmrc, should preserve previous behavior): ```bash # we're on default system node $ which node && node --version /usr/local/bin/node v17.0.1 $ source ./scripts/find-node.sh $ nvm ls|grep default default -> v14.17.1 # Expected: v14.17.1 $ node --version v14.17.1 ``` Reviewed By: sota000 Differential Revision: D32889629 Pulled By: ShikaSD fbshipit-source-id: 527384055e303a87bad43413fb66a7fd117d1a63
1 parent 49a1460 commit 35bcf93

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

scripts/find-node.sh

+6-2
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,16 @@ fi
1919
# Define NVM_DIR and source the nvm.sh setup script
2020
[ -z "$NVM_DIR" ] && export NVM_DIR="$HOME/.nvm"
2121

22+
# Source nvm with '--no-use' and then `nvm use` to respect .nvmrc
23+
# See: https://github.com/nvm-sh/nvm/issues/2053
2224
if [[ -s "$HOME/.nvm/nvm.sh" ]]; then
2325
# shellcheck source=/dev/null
24-
. "$HOME/.nvm/nvm.sh"
26+
. "$HOME/.nvm/nvm.sh" --no-use
27+
nvm use 2> /dev/null || nvm use default
2528
elif [[ -x "$(command -v brew)" && -s "$(brew --prefix nvm)/nvm.sh" ]]; then
2629
# shellcheck source=/dev/null
27-
. "$(brew --prefix nvm)/nvm.sh"
30+
. "$(brew --prefix nvm)/nvm.sh" --no-use
31+
nvm use 2> /dev/null || nvm use default
2832
fi
2933

3034
# Set up the nodenv node version manager if present

0 commit comments

Comments
 (0)