From 12babdfe20eae91de1b60a5a3cfb7db0a5a04cb0 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Sun, 7 Mar 2021 04:41:52 +0000 Subject: [PATCH] build external projects for verification testing (#4741) --- .github/workflows/build.yml | 53 ++++++++++++++++++++ README.md | 14 ++---- test/release/acorn.sh | 97 +++++++++++++++++++++++++++++++++++++ test/release/buble.sh | 44 +++++++++++++++++ test/release/butternut.sh | 44 +++++++++++++++++ test/release/rollup-es.sh | 83 +++++++++++++++++++++++++++++++ test/release/rollup-ts.sh | 45 +++++++++++++++++ test/release/sucrase.sh | 90 ++++++++++++++++++++++++++++++++++ 8 files changed, 461 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/build.yml create mode 100755 test/release/acorn.sh create mode 100755 test/release/buble.sh create mode 100755 test/release/butternut.sh create mode 100755 test/release/rollup-es.sh create mode 100755 test/release/rollup-ts.sh create mode 100755 test/release/sucrase.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..575df5b2 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,53 @@ +name: Build testing +on: + pull_request: + push: + branches: [ master ] +jobs: + ufuzz: + strategy: + fail-fast: false + matrix: + options: [ '-mb braces', '-mc', '--toplevel -mc passes=10,pure_getters,unsafe' ] + script: [ acorn.sh, buble.sh, butternut.sh, rollup-es.sh, rollup-ts.sh, sucrase.sh ] + include: + - node: '14' + script: acorn.sh + - node: '14' + script: buble.sh + - node: '14' + script: butternut.sh + - node: '8' + script: rollup-es.sh + - node: '14' + script: rollup-ts.sh + - node: '14' + script: sucrase.sh + name: ${{ matrix.script }} ${{ matrix.options }} + runs-on: ubuntu-latest + env: + NODE: ${{ matrix.node }} + OPTIONS: ${{ matrix.options }} + SCRIPT: ${{ matrix.script }} + steps: + - uses: actions/checkout@v2 + - name: Perform uglify, build & test + shell: bash + run: | + git clone --branch v1.6.0 --depth 1 https://github.com/jasongin/nvs.git ~/.nvs + while ! timeout 60 bash -c '. ~/.nvs/nvs.sh add $NODE && nvs use $NODE'; do + cd ~/.nvs + while !(git clean -xdf); do echo "'git clean' failed - retrying..."; done + cd - + done + . ~/.nvs/nvs.sh --version + nvs use $NODE + node --version + npm config set audit false + npm config set optional false + npm config set save false + npm config set strict-ssl false + npm config set update-notifier false + npm --version + while !(npm install); do echo "'npm install' failed - retrying..."; done + ./test/release/$SCRIPT $OPTIONS diff --git a/README.md b/README.md index 53f0e734..cd564e9f 100644 --- a/README.md +++ b/README.md @@ -1141,18 +1141,14 @@ in total it's a bit more than just using UglifyJS's own parser. It's not well known, but whitespace removal and symbol mangling accounts for 95% of the size reduction in minified code for most JavaScript - not elaborate code transforms. One can simply disable `compress` to speed up -Uglify builds by 3 to 4 times. In this fast `mangle`-only mode Uglify has -comparable minify speeds and gzip sizes to -[`butternut`](https://www.npmjs.com/package/butternut): +Uglify builds by 3 to 5 times. | d3.js | minify size | gzip size | minify time (seconds) | | --- | ---: | ---: | ---: | -| original | 451,131 | 108,733 | - | -| uglify-js@3.0.24 mangle=false, compress=false | 316,600 | 85,245 | 0.70 | -| uglify-js@3.0.24 mangle=true, compress=false | 220,216 | 72,730 | 1.13 | -| butternut@0.4.6 | 217,568 | 72,738 | 1.41 | -| uglify-js@3.0.24 mangle=true, compress=true | 212,511 | 71,560 | 3.36 | -| babili@0.1.4 | 210,713 | 72,140 | 12.64 | +| original | 511,371 | 119,932 | - | +| uglify-js@3.13.0 mangle=false, compress=false | 363,988 | 95,695 | 0.56 | +| uglify-js@3.13.0 mangle=true, compress=false | 253,305 | 81,281 | 0.99 | +| uglify-js@3.13.0 mangle=true, compress=true | 244,436 | 79,854 | 5.30 | To enable fast minify mode from the CLI use: ``` diff --git a/test/release/acorn.sh b/test/release/acorn.sh new file mode 100755 index 00000000..99e5c93d --- /dev/null +++ b/test/release/acorn.sh @@ -0,0 +1,97 @@ +#!/bin/sh + +alias uglify-js=$PWD/bin/uglifyjs +UGLIFY_OPTIONS=$@ + +minify_in_situ() { + DIRS="$1" + echo '> uglify-js' $DIRS $UGLIFY_OPTIONS + for i in `find $DIRS -name '*.js'` + do + echo "$i" + uglify-js "$i" $UGLIFY_OPTIONS -o "$i" + done +} + +rm -rf tmp/acorn \ +&& git clone https://github.com/acornjs/acorn.git tmp/acorn \ +&& cd tmp/acorn \ +&& rm -rf .git/hooks \ +&& git checkout 74b59384320ced82e09da2e8fdbed16810f7379a \ +&& patch -l -p1 < uglify-js' $DIRS $UGLIFY_OPTIONS + for i in `find $DIRS -name '*.js'` + do + echo "$i" + uglify-js "$i" $UGLIFY_OPTIONS -o "$i" + done +} + +rm -rf tmp/buble \ +&& git clone https://github.com/bublejs/buble.git tmp/buble \ +&& cd tmp/buble \ +&& rm -rf .git/hooks \ +&& git checkout dcc5ab02c9af6ddaad94e587c4911677340ec100 \ +&& patch -l -p1 < uglify-js' $DIRS $UGLIFY_OPTIONS + for i in `find $DIRS -name '*.js'` + do + echo "$i" + uglify-js "$i" $UGLIFY_OPTIONS -o "$i" + done +} + +rm -rf tmp/butternut \ +&& git clone https://github.com/Rich-Harris/butternut.git tmp/butternut \ +&& cd tmp/butternut \ +&& rm -rf .git/hooks \ +&& patch -l -p1 < uglify-js' $DIRS $UGLIFY_OPTIONS + for i in `find $DIRS -name '*.js'` + do + echo "$i" + uglify-js "$i" $UGLIFY_OPTIONS -o "$i" + done +} + +rm -rf tmp/rollup \ +&& git clone https://github.com/rollup/rollup.git tmp/rollup \ +&& cd tmp/rollup \ +&& rm -rf .git/hooks \ +&& git checkout 3d80c06f895eab41e648ee99786fa68c72458b80 \ +&& patch -l -p1 < uglify-js' $DIRS $UGLIFY_OPTIONS + for i in `find $DIRS -name '*.js'` + do + echo "$i" + uglify-js "$i" $UGLIFY_OPTIONS -o "$i" + done + for i in `find $DIRS -name '*.ts' | grep -v '\.d\.ts'` + do + echo "$i" + node_modules/.bin/esbuild --loader=ts --target=node14 < "$i" \ + | uglify-js $UGLIFY_OPTIONS -o "$i" + done +} + +rm -rf tmp/rollup \ +&& git clone --depth 1 --branch v2.39.1 https://github.com/rollup/rollup.git tmp/rollup \ +&& cd tmp/rollup \ +&& rm -rf .git/hooks \ +&& patch -l -p1 < uglify-js' $DIRS $UGLIFY_OPTIONS + for i in `find $DIRS -name '*.js'` + do + echo "$i" + uglify-js "$i" $UGLIFY_OPTIONS -o "$i" + done + for i in `find $DIRS -name '*.mjs'` + do + echo "$i" + uglify-js "$i" $UGLIFY_OPTIONS -o "$i" + done + for i in `find $DIRS -name '*.ts' | grep -v '\.d\.ts'` + do + echo "$i" + node_modules/.bin/esbuild --loader=ts --target=node14 < "$i" \ + | uglify-js $UGLIFY_OPTIONS -o "$i" + done +} + +rm -rf tmp/sucrase \ +&& git clone https://github.com/alangpierce/sucrase.git tmp/sucrase \ +&& cd tmp/sucrase \ +&& rm -rf .git/hooks \ +&& git checkout 38b66f3009feb76750a799deea211adcc83574f1 \ +&& patch -l -p1 < { +- () => buildBenchmark(), +@@ -18,5 +16,0 @@ async function main(): Promise { +- () => buildIntegration("./integrations/gulp-plugin"), +- () => buildIntegration("./integrations/jest-plugin"), +- () => buildIntegration("./integrations/webpack-loader"), +- () => buildIntegration("./integrations/webpack-object-rest-spread-plugin"), +- () => buildWebsite(), +@@ -66,3 +59,0 @@ async function buildSucrase(): Promise { +- // Also add in .d.ts files from tsc, which only need to be compiled once. +- await run(\`\${TSC} --project ./src --outDir ./dist-types\`); +- await mergeDirectoryContents("./dist-types/src", "./dist"); +@@ -70 +61 @@ async function buildSucrase(): Promise { +- await run("yarn link"); ++ await run("npm link"); +--- a/src/identifyShadowedGlobals.ts ++++ b/src/identifyShadowedGlobals.ts +@@ -23,0 +24 @@ export default function identifyShadowedGlobals( ++export { identifyShadowedGlobals as HACK }; +--- a/src/parser/tokenizer/state.ts ++++ b/src/parser/tokenizer/state.ts +@@ -100,0 +101 @@ export default class State { ++export { State as HACK }; +--- a/src/transformers/JSXTransformer.ts ++++ b/src/transformers/JSXTransformer.ts +@@ -253,0 +254 @@ export default class JSXTransformer extends Transformer { ++export { JSXTransformer as HACK }; +--- a/src/util/getClassInfo.ts ++++ b/src/util/getClassInfo.ts +@@ -164,0 +165 @@ export default function getClassInfo( ++export { getClassInfo as HACK }; +--- a/src/util/getDeclarationInfo.ts ++++ b/src/util/getDeclarationInfo.ts +@@ -40,0 +41 @@ export default function getDeclarationInfo(tokens: TokenProcessor): DeclarationI ++export { getDeclarationInfo as HACK }; +--- a/src/util/getJSXPragmaInfo.ts ++++ b/src/util/getJSXPragmaInfo.ts +@@ -14,0 +15 @@ export default function getJSXPragmaInfo(options: Options): JSXPragmaInfo { ++export { getJSXPragmaInfo as HACK }; +EOF +ERR=$?; if [ "$ERR" != "0" ]; then echo "Error: $ERR"; exit $ERR; fi +npm install esbuild-wasm@0.8.56 \ +&& minify_in_situ "src" \ +&& rm -rf node_modules \ +&& npm install \ +&& npm run clean \ +&& npm run build \ +&& minify_in_situ "dist" \ +&& minify_in_situ "dist-self-build" \ +&& npm run test-only -- 2.34.1