From dc6845739e29ea8cf63583d530f67c2498286a3e Mon Sep 17 00:00:00 2001 From: Alex Hunt Date: Mon, 10 Jul 2023 05:49:00 -0700 Subject: [PATCH] Remove run Metro hook from Xcode build, remove launchPackager scripts (#38242) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/38242 See proposal: https://github.com/react-native-community/discussions-and-proposals/discussions/681 **Removed script files** I searched GitHub (and specifically `react-native-windows/macos`) to confirm these files are not referenced: - `scripts/launchPackager.bat` - `scripts/launchPackager.command` - `scripts/.packager.env` Interestingly, React Native CLI refers to a `.packager.env` at a different location (`node_modules/.bin/`), and includes modified copies of `launchPackager.command/bat`. This PR removes duplication with these. Changelog: [iOS][Breaking] Metro will no longer be started when running builds via Xcode Reviewed By: cortinico Differential Revision: D47297469 fbshipit-source-id: 06c3602d58b21ed693c3daa763d99947a70bfc5a --- packages/react-native/package.json | 2 -- packages/react-native/scripts/.packager.env | 1 - .../react-native/scripts/launchPackager.bat | 12 ------- .../scripts/launchPackager.command | 34 ------------------- .../ios/HelloWorld.xcodeproj/project.pbxproj | 20 ----------- .../RNTesterPods.xcodeproj/project.pbxproj | 16 --------- 6 files changed, 85 deletions(-) delete mode 100644 packages/react-native/scripts/.packager.env delete mode 100644 packages/react-native/scripts/launchPackager.bat delete mode 100755 packages/react-native/scripts/launchPackager.command diff --git a/packages/react-native/package.json b/packages/react-native/package.json index 79a2723e276e12..73daf6a064c3a9 100644 --- a/packages/react-native/package.json +++ b/packages/react-native/package.json @@ -62,8 +62,6 @@ "scripts/hermes/prepare-hermes-for-build.js", "scripts/ios-configure-glog.sh", "scripts/xcode/with-environment.sh", - "scripts/launchPackager.bat", - "scripts/launchPackager.command", "scripts/native_modules.rb", "scripts/node-binary.sh", "scripts/packager.sh", diff --git a/packages/react-native/scripts/.packager.env b/packages/react-native/scripts/.packager.env deleted file mode 100644 index 361f5fb47d34ac..00000000000000 --- a/packages/react-native/scripts/.packager.env +++ /dev/null @@ -1 +0,0 @@ -export RCT_METRO_PORT=8081 diff --git a/packages/react-native/scripts/launchPackager.bat b/packages/react-native/scripts/launchPackager.bat deleted file mode 100644 index 5060dcd9a275b8..00000000000000 --- a/packages/react-native/scripts/launchPackager.bat +++ /dev/null @@ -1,12 +0,0 @@ -:: Copyright (c) Meta Platforms, Inc. and affiliates. -:: -:: This source code is licensed under the MIT license found in the -:: LICENSE file in the root directory of this source tree. - -@echo off -title Metro -call .packager.bat -cd ../../../ -node "%~dp0..\cli.js" start -pause -exit diff --git a/packages/react-native/scripts/launchPackager.command b/packages/react-native/scripts/launchPackager.command deleted file mode 100755 index efd1f2e4eed160..00000000000000 --- a/packages/react-native/scripts/launchPackager.command +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash -# Copyright (c) Meta Platforms, Inc. and affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - -# Set terminal title -echo -en "\\033]0;Metro\\a" -clear - -THIS_DIR=$(cd -P "$(dirname "$(readlink "${BASH_SOURCE[0]}" || echo "${BASH_SOURCE[0]}")")" && pwd) - -export PODS_ROOT="$THIS_DIR/../../../ios/Pods" -WITH_ENVIRONMENT="$THIS_DIR/xcode/with-environment.sh" -source $WITH_ENVIRONMENT - -# export packager environment variables -source "$THIS_DIR/.packager.env" - -if [ -n "${RCT_PACKAGER_LOGS_DIR}" ] ; then - echo "Writing logs to $RCT_PACKAGER_LOGS_DIR" - # shellcheck source=/dev/null - RCT_PACKAGER_LOG_PATH="$RCT_PACKAGER_LOGS_DIR/metro.log" \ - . "$THIS_DIR/packager.sh" \ - > "$RCT_PACKAGER_LOGS_DIR/packager.stdout.log" \ - 2> "$RCT_PACKAGER_LOGS_DIR/packager.stderr.log" -else - # shellcheck source=/dev/null - . "$THIS_DIR/packager.sh" -fi -if [[ -z "$CI" ]]; then - echo "Process terminated. Press to close the window" - read -r -fi diff --git a/packages/react-native/template/ios/HelloWorld.xcodeproj/project.pbxproj b/packages/react-native/template/ios/HelloWorld.xcodeproj/project.pbxproj index afc51486e318f7..6390f4b55591c0 100644 --- a/packages/react-native/template/ios/HelloWorld.xcodeproj/project.pbxproj +++ b/packages/react-native/template/ios/HelloWorld.xcodeproj/project.pbxproj @@ -177,7 +177,6 @@ buildConfigurationList = 13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "HelloWorld" */; buildPhases = ( C38B50BA6285516D6DCD4F65 /* [CP] Check Pods Manifest.lock */, - FD10A7F022414F080027D42C /* Start Packager */, 13B07F871A680F5B00A75B9A /* Sources */, 13B07F8C1A680F5B00A75B9A /* Frameworks */, 13B07F8E1A680F5B00A75B9A /* Resources */, @@ -378,25 +377,6 @@ shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-HelloWorld-HelloWorldTests/Pods-HelloWorld-HelloWorldTests-resources.sh\"\n"; showEnvVarsInLog = 0; }; - FD10A7F022414F080027D42C /* Start Packager */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputFileListPaths = ( - ); - inputPaths = ( - ); - name = "Start Packager"; - outputFileListPaths = ( - ); - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "export RCT_METRO_PORT=\"${RCT_METRO_PORT:=8081}\"\necho \"export RCT_METRO_PORT=${RCT_METRO_PORT}\" > \"${SRCROOT}/../node_modules/react-native/scripts/.packager.env\"\nif [ -z \"${RCT_NO_LAUNCH_PACKAGER+xxx}\" ] ; then\n if nc -w 5 -z localhost ${RCT_METRO_PORT} ; then\n if ! curl -s \"http://localhost:${RCT_METRO_PORT}/status\" | grep -q \"packager-status:running\" ; then\n echo \"Port ${RCT_METRO_PORT} already in use, packager is either not running or not running correctly\"\n exit 2\n fi\n else\n open \"$SRCROOT/../node_modules/react-native/scripts/launchPackager.command\" || echo \"Can't start packager automatically\"\n fi\nfi\n"; - showEnvVarsInLog = 0; - }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ diff --git a/packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj b/packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj index 01af6ae1065c2d..3db35a22d66846 100644 --- a/packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj +++ b/packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj @@ -409,7 +409,6 @@ 13B07F8C1A680F5B00A75B9A /* Frameworks */, 13B07F8E1A680F5B00A75B9A /* Resources */, 68CD48B71D2BCB2C007E06A9 /* Build JS Bundle */, - 5CF0FD27207FC6EC00C13D65 /* Start Metro */, 79E8BE2B119D4C5CCD2F04B3 /* [RN] Copy Hermes Framework */, 4E5A5A192F46F13B14A915AF /* [CP] Embed Pods Frameworks */, 4E2AB2EE08A8E6F86E659152 /* [CP] Copy Pods Resources */, @@ -627,21 +626,6 @@ shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-RNTesterIntegrationTests/Pods-RNTesterIntegrationTests-frameworks.sh\"\n"; showEnvVarsInLog = 0; }; - 5CF0FD27207FC6EC00C13D65 /* Start Metro */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "Start Metro"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "set -x\n\n# RN-Tester does not have an iOS directory. The PROJECT_ROOT should \n# point to the folder where the `metro.config.js` file lives.\nexport PROJECT_ROOT=$(pwd)\nexport RCT_METRO_PORT=\"${RCT_METRO_PORT:=8081}\"\necho \"export RCT_METRO_PORT=${RCT_METRO_PORT}\" > \"${SRCROOT}/../react-native/scripts/.packager.env\"\nif [ -z \"${RCT_NO_LAUNCH_PACKAGER+xxx}\" ] ; then\n if nc -w 5 -z localhost ${RCT_METRO_PORT} ; then\n if ! curl -s \"http://localhost:${RCT_METRO_PORT}/status\" | grep -q \"packager-status:running\" ; then\n echo \"Port ${RCT_METRO_PORT} already in use, packager is either not running or not running correctly\"\n exit 2\n fi\n else\n open -n \"$SRCROOT/../react-native/scripts/launchPackager.command\" || echo \"Can't start packager automatically\"\n fi\nfi\n"; - showEnvVarsInLog = 0; - }; 68CD48B71D2BCB2C007E06A9 /* Build JS Bundle */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647;