Skip to content

Commit ae38ffe

Browse files
Riccardo Cipolleschifacebook-github-bot
Riccardo Cipolleschi
authored andcommitted
Introduce .xcode.env configuration file to source node
Summary: This Diff does 2 things: 1. Removes all the remnant of the `find-node.sh` script. This allows React Native to stay agnostic from any other node manager 2. Introduces a way for the developers to specify which `node` executable they want to use, through a simple `.env` file. ## Changelog [iOS][Changed] - This PR removes the `find-node.sh` scripts and replaces it with an `.xcode.env` file that is sourced by the script phases that needs it. The `.xcode.env` file is versioned: to customize a local environment, an unversioned `.xcode.local.env` can be used. Differential Revision: D35317070 fbshipit-source-id: 6ca01077cb61f7fa04bcc50cb8b365fe4dd696d4
1 parent 124826a commit ae38ffe

File tree

14 files changed

+31
-101
lines changed

14 files changed

+31
-101
lines changed

.circleci/config.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -415,12 +415,6 @@ jobs:
415415
- brew_install:
416416
package: applesimutils
417417

418-
- run:
419-
name: Configure Node
420-
# Sourcing find-node.sh will ensure nvm is set up.
421-
# It also helps future invocation of find-node.sh prevent permission issue with nvm.sh.
422-
command: source scripts/find-node-for-xcode.sh && nvm install 16 && nvm alias default 16
423-
424418
- run:
425419
name: Configure Watchman
426420
command: echo "{}" > .watchmanconfig

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ DerivedData
2020
*.ipa
2121
*.xcuserstate
2222
project.xcworkspace
23+
packages/rn-tester/.xcode.local.env
2324

2425
# Gradle
2526
/build/

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
"README.md",
3939
"rn-get-polyfills.js",
4040
"scripts/compose-source-maps.js",
41-
"scripts/find-node-for-xcode.sh",
4241
"scripts/generate-artifacts.js",
4342
"scripts/generate-provider-cli.js",
4443
"scripts/generate-specs-cli.js",

packages/rn-tester/.xcode.env

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# PATH to the node executable. You can use the `command -v node` to check what value make sense for your set up
2+
# This `.xcode.env` file is versioned. To customize your local environment, you can create an `.xcode.local.env`
3+
# file that is not versioned.
4+
export NODE_BINARY=/usr/local/bin/node

packages/rn-tester/Podfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ SPEC CHECKSUMS:
891891
CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99
892892
DoubleConversion: 5189b271737e1565bdce30deb4a08d647e3f5f54
893893
FBLazyVector: 19e408e76fa9258dd32191a50d60c41444f52d29
894-
FBReactNativeSpec: fc6b3c34276fb05bb3e0f6bccc50e21dd38de5bf
894+
FBReactNativeSpec: e68b48bb704799479631b7dd7b9d6401c5c97089
895895
Flipper: 26fc4b7382499f1281eb8cb921e5c3ad6de91fe0
896896
Flipper-Boost-iOSX: fd1e2b8cbef7e662a122412d7ac5f5bea715403c
897897
Flipper-DoubleConversion: 3d3d04a078d4f3a1b6c6916587f159dc11f232c4
@@ -934,10 +934,10 @@ SPEC CHECKSUMS:
934934
React-RCTTest: 451f186880271c249a3ff65761f569592a7765e1
935935
React-RCTText: a861fbf2835299d3cc4189697cddd8bd8602afb9
936936
React-RCTVibration: 00dbb5e9451af741c77be12978281ded80046f3d
937-
React-rncore: ed4c24b136f613ebbcfc780a33e2bc23021f3eae
937+
React-rncore: d1eb68f86013f765b075c1e7c2cb07ecedb135ab
938938
React-runtimeexecutor: 97dca9247f4d3cfe0733384b189c6930fbd402b7
939939
ReactCommon: 4a2e9e61ef59dc6f7b92f05a6b9e37a0013ee854
940-
ScreenshotManager: 8baf7f62c6b602ba59ea979d9ed294c98ee3019e
940+
ScreenshotManager: 1ada1f2bd91e08e4790d63bc5e8f537cb90f901c
941941
SocketRocket: fccef3f9c5cedea1353a9ef6ada904fde10d6608
942942
Yoga: cdc7a2377fc03a2d44322b7784a2461b4c17da09
943943
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a

packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,13 +633,15 @@
633633
files = (
634634
);
635635
inputPaths = (
636+
"$(SRCROOT)/.xcode.local.env",
637+
"$(SRCROOT)/.xcode.env",
636638
);
637639
name = "Build JS Bundle";
638640
outputPaths = (
639641
);
640642
runOnlyForDeploymentPostprocessing = 0;
641643
shellPath = /bin/sh;
642-
shellScript = "set -e\n\nexport NODE_BINARY=node\nexport PROJECT_ROOT=\"$SRCROOT/../../\"\nexport ENTRY_FILE=\"$SRCROOT/js/RNTesterApp.ios.js\"\nexport SOURCEMAP_FILE=../sourcemap.ios.map\n# export FORCE_BUNDLING=true\n\"$SRCROOT/../../scripts/react-native-xcode.sh\"\n";
644+
shellScript = "set -e\n\nexport PROJECT_ROOT=\"$SRCROOT/../../\"\nexport ENTRY_FILE=\"$SRCROOT/js/RNTesterApp.ios.js\"\nexport SOURCEMAP_FILE=../sourcemap.ios.map\n# export FORCE_BUNDLING=true \n\nif [ -f $SCRIPT_INPUT_FILE_0 ]; then\n source $SCRIPT_INPUT_FILE_0\nelif [ -f $SCRIPT_INPUT_FILE_1 ]; then\n source $SCRIPT_INPUT_FILE_1\nfi\n\n\"$SRCROOT/../../scripts/react-native-xcode.sh\"\n";
643645
};
644646
98E057AC8860597818FB485A /* [CP] Copy Pods Resources */ = {
645647
isa = PBXShellScriptBuildPhase;

scripts/find-node-for-xcode.sh

Lines changed: 0 additions & 80 deletions
This file was deleted.

scripts/react-native-xcode.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,6 @@ if [[ $DEV != true && ! -f "$ENTRY_FILE" ]]; then
7979
exit 2
8080
fi
8181

82-
# Find path to Node
83-
# shellcheck source=/dev/null
84-
source "$REACT_NATIVE_DIR/scripts/find-node-for-xcode.sh"
85-
8682
# check and assign NODE_BINARY env
8783
# shellcheck source=/dev/null
8884
source "$REACT_NATIVE_DIR/scripts/node-binary.sh"

scripts/react_native_pods.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,9 +628,11 @@ def use_react_native_codegen!(spec, options={})
628628
system(prepare_command) # Always run prepare_command when a podspec uses the codegen, as CocoaPods may skip invoking this command in certain scenarios. Replace with pre_integrate_hook after updating to CocoaPods 1.11
629629
spec.prepare_command = prepare_command
630630

631+
env_files = ["$PODS_ROOT/../.xcode.local.env", "$PODS_ROOT/../.xcode.env"]
632+
631633
spec.script_phase = {
632634
:name => 'Generate Specs',
633-
:input_files => input_files, # This also needs to be relative to Xcode
635+
:input_files => input_files + env_files, # This also needs to be relative to Xcode
634636
:output_files => ["${DERIVED_FILE_DIR}/codegen-#{library_name}.log"].concat(generated_files.map { |filename| "${PODS_TARGET_SRCROOT}/#{filename}"} ),
635637
# The final generated files will be created when this script is invoked at Xcode build time.
636638
:script => get_script_phases_no_codegen_discovery(

scripts/react_native_pods_utils/script_phases.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,18 @@ def get_script_template(react_native_path, export_vars={})
4444
export <%= varname -%>=<%= value -%>
4545
<% end %>
4646
47+
LOCAL_ENV_PATH="$PODS_ROOT/../.xcode.local.env"
48+
ENV_PATH="$PODS_ROOT/../.xcode.env"
49+
50+
if [ -f $LOCAL_ENV_PATH ]; then
51+
source $LOCAL_ENV_PATH
52+
elif [ -f $ENV_PATH ]; then
53+
source $ENV_PATH
54+
fi
55+
4756
SCRIPT_PHASES_SCRIPT="$RCT_SCRIPT_RN_DIR/scripts/react_native_pods_utils/script_phases.sh"
4857
/bin/sh -c "$SCRIPT_PHASES_SCRIPT"
4958
EOS
5059
result = ERB.new(template, 0, '->').result(binding)
51-
# puts result
5260
return result
5361
end

scripts/react_native_pods_utils/script_phases.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ else
3333
fi
3434

3535
find_node () {
36-
# shellcheck disable=SC1091
37-
source "$RCT_SCRIPT_RN_DIR/scripts/find-node-for-xcode.sh"
38-
3936
NODE_BINARY="${NODE_BINARY:-$(command -v node || true)}"
4037
if [ -z "$NODE_BINARY" ]; then
4138
error "error: Could not find node. Make sure it is in bash PATH or set the NODE_BINARY environment variable."

template/_gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ DerivedData
2020
*.hmap
2121
*.ipa
2222
*.xcuserstate
23+
ios/.xcode.local.env
2324

2425
# Android/IntelliJ
2526
#

template/ios/.xcode.env

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# PATH to the node executable. You can use the `command -v node` to check what value make sense for your set up
2+
# This `.xcode.env` file is versioned. To customize your local environment, you can create an `.xcode.local.env`
3+
# file that is not versioned.
4+
export NODE_BINARY=/usr/local/bin/node

template/ios/HelloWorld.xcodeproj/project.pbxproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,15 @@
256256
files = (
257257
);
258258
inputPaths = (
259+
"$(SRCROOT)/.xcode.local.env",
260+
"$(SRCROOT)/.xcode.env",
259261
);
260262
name = "Bundle React Native code and images";
261263
outputPaths = (
262264
);
263265
runOnlyForDeploymentPostprocessing = 0;
264266
shellPath = /bin/sh;
265-
shellScript = "set -e\n\nexport NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh\n";
267+
shellScript = "set -e\n\nif [ -f $SCRIPT_INPUT_FILE_0 ]; then\n source $SCRIPT_INPUT_FILE_0\nelif [ -f $SCRIPT_INPUT_FILE_1 ]; then\n source $SCRIPT_INPUT_FILE_1\nfi\n\n../node_modules/react-native/scripts/react-native-xcode.sh\n";
266268
};
267269
00EEFC60759A1932668264C0 /* [CP] Embed Pods Frameworks */ = {
268270
isa = PBXShellScriptBuildPhase;

0 commit comments

Comments
 (0)