swc/crates/swc_ecma_minifier/scripts/reduce.sh
Donny/강동윤 1c1c9f0eae
fix(es/minifier): Fix bugs (#2955)
swc_ecma_minifier:
 - Improve the script for extracting inputs from next.js app.
 - Ensure the name is removed on inlining.
 - Respect `inline_prevented`.
2022-01-05 05:12:52 +09:00

40 lines
832 B
Bash
Executable File

#!/usr/bin/env bash
set -eu
if ! command -v creduce &> /dev/null
then
echo "creduce not found. Installing"
brew install creduce
exit
fi
cp $1 input.js
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
# Build swc minifier
export MINIFY=$(cargo profile bin-path --example minifier)
echo "Using $MINIFY"
# Verify that we can run `creduce`
$SCRIPT_DIR/_/reduce/compare.sh
creduce "$SCRIPT_DIR/_/reduce/compare.sh" input.js
REDUCED_SIZE=$(wc -c <"input.js")
echo "Reduced size is $REDUCED_SIZE bytes"
if [[ "$1" == *"inputs"* && $REDUCED_SIZE -le 3 ]]; then
echo "Removing $1"
git rm --force $1
git commit -m 'Remove useless input'
find ./inputs -type d -empty -delete
./scripts/_/notify.sh "Removed $1"
else
./scripts/_/notify.sh "Found errornous input"
fi