mirror of
https://github.com/swc-project/swc.git
synced 2024-12-24 14:16:12 +03:00
chore(es/minifier): Add scripts to extract tests automatically (#3212)
This commit is contained in:
parent
db71f7a42d
commit
057fca4196
3
crates/swc_ecma_minifier/.gitignore
vendored
3
crates/swc_ecma_minifier/.gitignore
vendored
@ -7,3 +7,6 @@ private/
|
|||||||
/input.js
|
/input.js
|
||||||
/output.js
|
/output.js
|
||||||
*.orig
|
*.orig
|
||||||
|
|
||||||
|
|
||||||
|
creduce_bug_*
|
@ -8,7 +8,7 @@ let [ast1, ast2] =
|
|||||||
process.argv.slice(2) // skip node executable and script filename
|
process.argv.slice(2) // skip node executable and script filename
|
||||||
.map(file => readFileSync(file, 'utf-8')) // read given files as strings
|
.map(file => readFileSync(file, 'utf-8')) // read given files as strings
|
||||||
.map(code => {
|
.map(code => {
|
||||||
console.log(code);
|
// console.log(code);
|
||||||
return parseModule(code)
|
return parseModule(code)
|
||||||
}); // parse into ASTs
|
}); // parse into ASTs
|
||||||
|
|
||||||
|
9
crates/swc_ecma_minifier/scripts/cdnjs/download-all.sh
Executable file
9
crates/swc_ecma_minifier/scripts/cdnjs/download-all.sh
Executable file
@ -0,0 +1,9 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
# Work in .data directory
|
||||||
|
cd .data
|
||||||
|
|
||||||
|
git clone https://github.com/cdnjs/cdnjs.git --depth 1 || true
|
||||||
|
|
||||||
|
cd cdnjs
|
56
crates/swc_ecma_minifier/scripts/inputs/remove-useless.sh
Executable file
56
crates/swc_ecma_minifier/scripts/inputs/remove-useless.sh
Executable file
@ -0,0 +1,56 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
dir="${1-"./inputs/"}"
|
||||||
|
|
||||||
|
echo "Removing useless files in $dir"
|
||||||
|
find $dir -type f \( \
|
||||||
|
-name "*.html" -o \
|
||||||
|
-name "*.xml" -o \
|
||||||
|
-name "*.aac" -o \
|
||||||
|
-name "*.avif" -o \
|
||||||
|
-name "*.ogg" -o \
|
||||||
|
-name "*.mp3" -o \
|
||||||
|
-name "*.mp4" -o \
|
||||||
|
-name "*.wav" -o \
|
||||||
|
-name "*.bat" -o \
|
||||||
|
-name "*.cur" -o \
|
||||||
|
-name "*.db" -o \
|
||||||
|
-name "*.diff" -o \
|
||||||
|
-name "*.donotoptimizepng" -o \
|
||||||
|
-name "*.gif" -o \
|
||||||
|
-name "*.svg" -o \
|
||||||
|
-name "*.css" -o \
|
||||||
|
-name "*.png" -o \
|
||||||
|
-name "*.json" -o \
|
||||||
|
-name "*.woff" -o \
|
||||||
|
-name "*.woff2" -o \
|
||||||
|
-name "*.otf" -o \
|
||||||
|
-name "*.ttf" -o \
|
||||||
|
-name "*.eot" -o \
|
||||||
|
-name "*.flow" -o \
|
||||||
|
-name "*.md" -o \
|
||||||
|
-name "*.less" -o \
|
||||||
|
-name "*.sass" -o \
|
||||||
|
-name "*.scss" -o \
|
||||||
|
-name "*.ico" -o \
|
||||||
|
-name "*.sh" -o \
|
||||||
|
-name "*.jpg" -o \
|
||||||
|
-name "*.webp" -o \
|
||||||
|
-name "*.jpeg" -o \
|
||||||
|
-name "*.gz" -o \
|
||||||
|
-name "*.gzip" -o \
|
||||||
|
-name "*.zip" -o \
|
||||||
|
-name "*.woff" -o \
|
||||||
|
-name "*.wasm" -o \
|
||||||
|
-name "*.wast" -o \
|
||||||
|
-name "*.tsbuildinfo" \
|
||||||
|
\) \
|
||||||
|
-delete
|
||||||
|
|
||||||
|
|
||||||
|
echo "Removing empty directories in $dir"
|
||||||
|
|
||||||
|
find $dir -type d -empty -delete
|
||||||
|
|
||||||
|
echo "Reducing js files in $dir"
|
@ -1,7 +1,20 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# Usage: ./scrtips/reduce-all.sh path/to/minifier-tasklist
|
||||||
|
#
|
||||||
|
# e.g:
|
||||||
|
# - ./scrtips/reduce-all.sh ~/projects/minifier-tasklist
|
||||||
|
# - ./scrtips/reduce-all.sh ~/projects/minifier-tasklist/react
|
||||||
|
#
|
||||||
|
#
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
|
dir="$1"
|
||||||
|
|
||||||
find ./inputs/ -type f -name '*.js' -print0 | xargs -0 -I {} sh -c '\
|
echo "Reducing javascript files in $dir"
|
||||||
echo "Processing {}"
|
|
||||||
./scripts/reduce.sh {}'
|
find $dir -type f -name '*.js' -print0 | xargs -0 -P 4 -I {} sh -c './scripts/reduce.sh {}' || true
|
||||||
|
|
||||||
|
echo "Removing empty directories in $dir"
|
||||||
|
|
||||||
|
find $dir -type d -empty -delete
|
||||||
|
@ -8,32 +8,38 @@ then
|
|||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cp $1 input.js
|
|
||||||
|
|
||||||
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
||||||
|
|
||||||
# Build swc minifier
|
echo "Reducing $1"
|
||||||
export MINIFY=$(cargo profile bin-path --example minifier)
|
ls -al $1
|
||||||
|
|
||||||
echo "Using $MINIFY"
|
# Build swc minifier
|
||||||
|
export MINIFY=$(cargo profile bin-path --release --example minifier)
|
||||||
|
|
||||||
|
wd="$(mktemp -d)"
|
||||||
|
echo "Using $MINIFY; dir = $wd"
|
||||||
|
|
||||||
|
cp $1 "$wd/input.js"
|
||||||
|
dir="$(dirname $1)"
|
||||||
|
|
||||||
# Verify that we can run `creduce`
|
# Verify that we can run `creduce`
|
||||||
$SCRIPT_DIR/_/reduce/compare.sh
|
$SCRIPT_DIR/_/reduce/compare.sh
|
||||||
|
|
||||||
creduce "$SCRIPT_DIR/_/reduce/compare.sh" input.js
|
(cd $wd && creduce "$SCRIPT_DIR/_/reduce/compare.sh" "$wd/input.js")
|
||||||
|
|
||||||
REDUCED_SIZE=$(wc -c <"input.js")
|
REDUCED_SIZE=$(wc -c <"$wd/input.js")
|
||||||
|
hash=$(sha1sum < "$wd/input.js")
|
||||||
|
echo "Hash is $hash"
|
||||||
|
|
||||||
echo "Reduced size is $REDUCED_SIZE bytes"
|
echo "Reduced size is $REDUCED_SIZE bytes"
|
||||||
|
|
||||||
if [[ "$1" == *"inputs"* && $REDUCED_SIZE -le 3 ]]; then
|
if [[ $REDUCED_SIZE -le 3 ]]; then
|
||||||
echo "Removing $1"
|
echo "Removing $1"
|
||||||
git rm --force $1
|
rm -rf $1
|
||||||
git commit -m 'Remove useless input'
|
|
||||||
|
|
||||||
find ./inputs -type d -empty -delete
|
|
||||||
|
|
||||||
./scripts/_/notify.sh "Removed $1"
|
./scripts/_/notify.sh "Removed $1"
|
||||||
|
(cd $dir && git commit -m "Remove a file as it didn't break anything" $1)
|
||||||
else
|
else
|
||||||
|
# mkdir -p "$SCRIPT_DIR/../tests/compress/fixture/reduced/$hash"
|
||||||
|
# cp "$wd/input.js" "$SCRIPT_DIR/../tests/compress/fixture/reduced/$hash/input.js"
|
||||||
./scripts/_/notify.sh "Found errornous input"
|
./scripts/_/notify.sh "Found errornous input"
|
||||||
fi
|
fi
|
||||||
|
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"defaults": true,
|
||||||
|
"toplevel": false
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user