From bc7d13e7267c64c5ac10ffa164e570844a873f90 Mon Sep 17 00:00:00 2001 From: rory Date: Mon, 8 Jul 2024 10:33:43 -0400 Subject: [PATCH 1/7] Add applyPatches script --- scripts/applyPatches.sh | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 scripts/applyPatches.sh diff --git a/scripts/applyPatches.sh b/scripts/applyPatches.sh new file mode 100755 index 000000000000..31e1b7f50e6a --- /dev/null +++ b/scripts/applyPatches.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +# This script is a simple wrapper around patch-package that fails if any errors or warnings are detected. +# This is useful because patch-package does not fail on errors or warnings by default, +# which means that broken patches are easy to miss, and leads to developer frustration and wasted time. + +SCRIPTS_DIR=$(dirname "${BASH_SOURCE[0]}") +source "$SCRIPTS_DIR/shellUtils.sh" + +# Run patch-package and capture its output and exit code, while still displaying the original output to the terminal +# (we use `script -q /dev/null` to preserve colorization in the output) +TEMP_OUTPUT="$(mktemp)" +script -q /dev/null npx patch-package --error-on-fail 2>&1 | tee "$TEMP_OUTPUT" +EXIT_CODE=${PIPESTATUS[0]} +OUTPUT="$(cat "$TEMP_OUTPUT")" +rm -f "$TEMP_OUTPUT" + +# Check if the output contains a warning message +echo "$OUTPUT" | grep -q "Warning:" +WARNING_FOUND=$? + +printf "\n"; + +# Determine the final exit code +if [ "$EXIT_CODE" -eq 0 ]; then + if [ $WARNING_FOUND -eq 0 ]; then + # patch-package succeeded but warning was found + error "It looks like you upgraded a dependency without upgrading the patch. Please review the patch, determine if it's still needed, and port it to the new version of the dependency." + exit 1 + else + # patch-package succeeded and no warning was found + success "patch-package succeeded without errors or warnings" + exit 0 + fi +else + # patch-package failed + error "patch-package failed to apply a patch" + exit "$EXIT_CODE" +fi From 9d66b1be91942bf3cb9d6ac55570dd8a65e2eb2a Mon Sep 17 00:00:00 2001 From: rory Date: Mon, 8 Jul 2024 10:34:41 -0400 Subject: [PATCH 2/7] Add to postinstall --- scripts/postInstall.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/postInstall.sh b/scripts/postInstall.sh index 339fdf25cb10..782c8ef5822c 100755 --- a/scripts/postInstall.sh +++ b/scripts/postInstall.sh @@ -1,11 +1,14 @@ #!/bin/bash +# Exit immediately if any command exits with a non-zero status +set -e + # Go to project root ROOT_DIR=$(dirname "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)") cd "$ROOT_DIR" || exit 1 -# Run patch-package -npx patch-package +# Apply packages using patch-package +scripts/applyPatches.sh # Install node_modules in subpackages, unless we're in a CI/CD environment, # where the node_modules for subpackages are cached separately. From f4ac975ab3b5ceef36eca3a7ddc612bdfca07f91 Mon Sep 17 00:00:00 2001 From: rory Date: Mon, 8 Jul 2024 10:41:07 -0400 Subject: [PATCH 3/7] Rename react-native-live-markdown and react-native-keyboard-controller patches --- ...5.patch => @expensify+react-native-live-markdown+0.1.88.patch} | 0 ....patch.patch => react-native-keyboard-controller+1.12.2.patch} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename patches/{@expensify+react-native-live-markdown+0.1.85.patch => @expensify+react-native-live-markdown+0.1.88.patch} (100%) rename patches/{react-native-keyboard-controller+1.12.2.patch.patch => react-native-keyboard-controller+1.12.2.patch} (100%) diff --git a/patches/@expensify+react-native-live-markdown+0.1.85.patch b/patches/@expensify+react-native-live-markdown+0.1.88.patch similarity index 100% rename from patches/@expensify+react-native-live-markdown+0.1.85.patch rename to patches/@expensify+react-native-live-markdown+0.1.88.patch diff --git a/patches/react-native-keyboard-controller+1.12.2.patch.patch b/patches/react-native-keyboard-controller+1.12.2.patch similarity index 100% rename from patches/react-native-keyboard-controller+1.12.2.patch.patch rename to patches/react-native-keyboard-controller+1.12.2.patch From c7f5131244cc0fc79e6726a7660b4869e7d91872 Mon Sep 17 00:00:00 2001 From: rory Date: Mon, 8 Jul 2024 10:53:31 -0400 Subject: [PATCH 4/7] Rename reanimated patches --- ... react-native-reanimated+3.8.1+001+fix-boost-dependency.patch} | 0 ...e.patch => react-native-reanimated+3.8.1+002+copy-state.patch} | 0 ...reanimated+3.7.2.patch => react-native-reanimated+3.8.1.patch} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename patches/{react-native-reanimated+3.7.2+001+fix-boost-dependency.patch => react-native-reanimated+3.8.1+001+fix-boost-dependency.patch} (100%) rename patches/{react-native-reanimated+3.7.2+002+copy-state.patch => react-native-reanimated+3.8.1+002+copy-state.patch} (100%) rename patches/{react-native-reanimated+3.7.2.patch => react-native-reanimated+3.8.1.patch} (100%) diff --git a/patches/react-native-reanimated+3.7.2+001+fix-boost-dependency.patch b/patches/react-native-reanimated+3.8.1+001+fix-boost-dependency.patch similarity index 100% rename from patches/react-native-reanimated+3.7.2+001+fix-boost-dependency.patch rename to patches/react-native-reanimated+3.8.1+001+fix-boost-dependency.patch diff --git a/patches/react-native-reanimated+3.7.2+002+copy-state.patch b/patches/react-native-reanimated+3.8.1+002+copy-state.patch similarity index 100% rename from patches/react-native-reanimated+3.7.2+002+copy-state.patch rename to patches/react-native-reanimated+3.8.1+002+copy-state.patch diff --git a/patches/react-native-reanimated+3.7.2.patch b/patches/react-native-reanimated+3.8.1.patch similarity index 100% rename from patches/react-native-reanimated+3.7.2.patch rename to patches/react-native-reanimated+3.8.1.patch From eaca18bece56795e3aa08b30a2abe71e465005a4 Mon Sep 17 00:00:00 2001 From: rory Date: Mon, 8 Jul 2024 12:45:52 -0400 Subject: [PATCH 5/7] Only preserve colorization on macOS --- scripts/applyPatches.sh | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/scripts/applyPatches.sh b/scripts/applyPatches.sh index 31e1b7f50e6a..bedc905f5f37 100755 --- a/scripts/applyPatches.sh +++ b/scripts/applyPatches.sh @@ -7,10 +7,24 @@ SCRIPTS_DIR=$(dirname "${BASH_SOURCE[0]}") source "$SCRIPTS_DIR/shellUtils.sh" +function patchPackage { + OS="$(uname)" + if [[ "$OS" == "Darwin" ]]; then + # macOS + # We use script to preserve colorization when the output of patch-package is piped to tee + script -q /dev/null npx patch-package --error-on-fail + elif [[ "$OS" == "Linux" ]]; then + # Ubuntu/Linux + npx patch-package --error-on-fail + else + error "Unsupported OS: $OS" + fi +} + # Run patch-package and capture its output and exit code, while still displaying the original output to the terminal # (we use `script -q /dev/null` to preserve colorization in the output) TEMP_OUTPUT="$(mktemp)" -script -q /dev/null npx patch-package --error-on-fail 2>&1 | tee "$TEMP_OUTPUT" +patchPackage 2>&1 | tee "$TEMP_OUTPUT" EXIT_CODE=${PIPESTATUS[0]} OUTPUT="$(cat "$TEMP_OUTPUT")" rm -f "$TEMP_OUTPUT" From 331bc7e9cdff6a993cbc5f32aed501d4e9322a32 Mon Sep 17 00:00:00 2001 From: rory Date: Tue, 9 Jul 2024 09:20:39 -0700 Subject: [PATCH 6/7] Attempt script on linux too --- scripts/applyPatches.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/applyPatches.sh b/scripts/applyPatches.sh index bedc905f5f37..4345863d13b7 100755 --- a/scripts/applyPatches.sh +++ b/scripts/applyPatches.sh @@ -15,7 +15,7 @@ function patchPackage { script -q /dev/null npx patch-package --error-on-fail elif [[ "$OS" == "Linux" ]]; then # Ubuntu/Linux - npx patch-package --error-on-fail + script -q -c "npx patch-package --error-on-fail" /dev/null else error "Unsupported OS: $OS" fi From 589b3e5978d38db0c46c923bf71c4d8beac8aa1c Mon Sep 17 00:00:00 2001 From: rory Date: Tue, 9 Jul 2024 09:27:17 -0700 Subject: [PATCH 7/7] Improve comment on patchPackage wrapper function --- scripts/applyPatches.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/applyPatches.sh b/scripts/applyPatches.sh index 4345863d13b7..a4be88984561 100755 --- a/scripts/applyPatches.sh +++ b/scripts/applyPatches.sh @@ -7,11 +7,14 @@ SCRIPTS_DIR=$(dirname "${BASH_SOURCE[0]}") source "$SCRIPTS_DIR/shellUtils.sh" +# Wrapper to run patch-package. +# We use `script` to preserve colorization when the output of patch-package is piped to tee +# and we provide /dev/null to discard the output rather than sending it to a file +# `script` has different syntax on macOS vs linux, so that's why we need a wrapper function function patchPackage { OS="$(uname)" if [[ "$OS" == "Darwin" ]]; then # macOS - # We use script to preserve colorization when the output of patch-package is piped to tee script -q /dev/null npx patch-package --error-on-fail elif [[ "$OS" == "Linux" ]]; then # Ubuntu/Linux