Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[No QA] Simplify applyPatches script #45189

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions scripts/applyPatches.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,17 @@ 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
script -q /dev/null npx patch-package --error-on-fail
elif [[ "$OS" == "Linux" ]]; then
# Ubuntu/Linux
script -q -c "npx patch-package --error-on-fail" /dev/null
if [[ "$OS" == "Darwin" || "$OS" == "Linux" ]]; then
npx patch-package --error-on-fail
else
error "Unsupported OS: $OS"
exit 1
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)"
patchPackage 2>&1 | tee "$TEMP_OUTPUT"
EXIT_CODE=${PIPESTATUS[0]}
Expand All @@ -36,7 +29,7 @@ rm -f "$TEMP_OUTPUT"
echo "$OUTPUT" | grep -q "Warning:"
WARNING_FOUND=$?

printf "\n";
printf "\n"

# Determine the final exit code
if [ "$EXIT_CODE" -eq 0 ]; then
Expand Down
Loading