diff options
-rw-r--r-- | .github/workflows/build.yml | 53 | ||||
-rw-r--r-- | README.md | 14 | ||||
-rwxr-xr-x | test/release/acorn.sh | 97 | ||||
-rwxr-xr-x | test/release/buble.sh | 44 | ||||
-rwxr-xr-x | test/release/butternut.sh | 44 | ||||
-rwxr-xr-x | test/release/rollup-es.sh | 83 | ||||
-rwxr-xr-x | test/release/rollup-ts.sh | 45 | ||||
-rwxr-xr-x | test/release/sucrase.sh | 90 |
8 files changed, 461 insertions, 9 deletions
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 @@ -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 <<EOF +diff --git a/acorn-loose/rollup.config.js b/acorn-loose/rollup.config.js +index d2389b2..c37882b 100644 +--- a/acorn-loose/rollup.config.js ++++ b/acorn-loose/rollup.config.js +@@ -1,2 +0,0 @@ +-import buble from "rollup-plugin-buble" +- +@@ -23 +20,0 @@ export default { +- buble({transforms: {dangerousForOf: true}}) +diff --git a/acorn-walk/rollup.config.js b/acorn-walk/rollup.config.js +index 67dd613..8c28807 100644 +--- a/acorn-walk/rollup.config.js ++++ b/acorn-walk/rollup.config.js +@@ -1,2 +0,0 @@ +-import buble from "rollup-plugin-buble" +- +@@ -19 +16,0 @@ export default { +- buble({transforms: {dangerousForOf: true}}) +diff --git a/acorn/rollup.config.bin.js b/acorn/rollup.config.bin.js +index 8a082b0..b3eda60 100644 +--- a/acorn/rollup.config.bin.js ++++ b/acorn/rollup.config.bin.js +@@ -1,2 +0,0 @@ +-import buble from "rollup-plugin-buble" +- +@@ -11 +9 @@ export default { +- plugins: [buble()] ++ plugins: [] +diff --git a/acorn/rollup.config.js b/acorn/rollup.config.js +index c775a0c..cfd4c68 100644 +--- a/acorn/rollup.config.js ++++ b/acorn/rollup.config.js +@@ -1,2 +0,0 @@ +-import buble from "rollup-plugin-buble" +- +@@ -19 +16,0 @@ export default { +- buble({transforms: {dangerousForOf: true}}) +diff --git a/package.json b/package.json +index 382f59e..4612a75 100644 +--- a/package.json ++++ b/package.json +@@ -24,4 +24 @@ +- "prepare": "npm run test", +- "test": "node test/run.js && node test/lint.js", +- "pretest": "npm run build:main && npm run build:loose", +- "test:test262": "node bin/run_test262.js", ++ "test": "node test/run.js", +@@ -32,2 +29 @@ +- "build:bin": "rollup -c acorn/rollup.config.bin.js", +- "lint": "eslint acorn/src/ acorn-walk/src/ acorn-loose/src/" ++ "build:bin": "rollup -c acorn/rollup.config.bin.js" +@@ -36,6 +31,0 @@ +- "eslint": "^4.10.0", +- "eslint-config-standard": "^10.2.1", +- "eslint-plugin-import": "^2.2.0", +- "eslint-plugin-node": "^5.2.1", +- "eslint-plugin-promise": "^3.5.0", +- "eslint-plugin-standard": "^3.0.1", +@@ -43,4 +32,0 @@ +- "rollup-plugin-buble": "^0.19.0", +- "test262": "git+https://github.com/tc39/test262.git#a6c819ad0f049f23f1a37af6b89dbb79fe3b9216", +- "test262-parser-runner": "^0.5.0", +- "test262-stream": "^1.2.1", +EOF +ERR=$?; if [ "$ERR" != "0" ]; then echo "Error: $ERR"; exit $ERR; fi +minify_in_situ "acorn/src" \ +&& minify_in_situ "acorn-loose/src" \ +&& minify_in_situ "acorn-walk/src" \ +&& rm -rf node_modules \ +&& npm install \ +&& rm -rf acorn/dist acorn-loose/dist acorn-walk/dist \ +&& npm run build \ +&& minify_in_situ "acorn/dist" \ +&& minify_in_situ "acorn-loose/dist" \ +&& minify_in_situ "acorn-walk/dist" \ +&& npm test diff --git a/test/release/buble.sh b/test/release/buble.sh new file mode 100755 index 00000000..6a14ecad --- /dev/null +++ b/test/release/buble.sh @@ -0,0 +1,44 @@ +#!/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/buble \ +&& git clone https://github.com/bublejs/buble.git tmp/buble \ +&& cd tmp/buble \ +&& rm -rf .git/hooks \ +&& git checkout dcc5ab02c9af6ddaad94e587c4911677340ec100 \ +&& patch -l -p1 <<EOF +--- a/package.json ++++ b/package.json +@@ -29 +28,0 @@ +- "prepublish": "npm test", +@@ -67,3 +66 @@ +- "source-map-support": "^0.5.16", +- "test262": "git+https://github.com/tc39/test262.git#4f1155c566a222238fd86f179c6635ecb4c289bb", +- "test262-stream": "^1.3.0" ++ "source-map-support": "^0.5.16" +--- a/src/program/BlockStatement.js ++++ b/src/program/BlockStatement.js +@@ -309 +309 @@ export default class BlockStatement extends Node { +- let cont = false; // TODO implement proper continue... ++ let cont = !declarations; // TODO implement proper continue... +EOF +ERR=$?; if [ "$ERR" != "0" ]; then echo "Error: $ERR"; exit $ERR; fi +minify_in_situ "src" \ +&& rm -rf node_modules \ +&& npm ci \ +&& rm -rf dist \ +&& npm run build \ +&& minify_in_situ "dist" \ +&& node_modules/.bin/mocha diff --git a/test/release/butternut.sh b/test/release/butternut.sh new file mode 100755 index 00000000..b62c9371 --- /dev/null +++ b/test/release/butternut.sh @@ -0,0 +1,44 @@ +#!/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/butternut \ +&& git clone https://github.com/Rich-Harris/butternut.git tmp/butternut \ +&& cd tmp/butternut \ +&& rm -rf .git/hooks \ +&& patch -l -p1 <<EOF +--- a/package.json ++++ b/package.json +@@ -25 +24,0 @@ +- "prepublish": "npm run test:min", +--- a/rollup.config.js ++++ b/rollup.config.js +@@ -1 +0,0 @@ +-import buble from 'rollup-plugin-buble'; +@@ -28,6 +26,0 @@ const config = { +- buble({ +- include: ['src/**', 'node_modules/acorn/**'], +- transforms: { +- dangerousForOf: true +- } +- }), +EOF +ERR=$?; if [ "$ERR" != "0" ]; then echo "Error: $ERR"; exit $ERR; fi +minify_in_situ "src" \ +&& rm -rf node_modules \ +&& npm install \ +&& rm -rf dist \ +&& npm run build \ +&& minify_in_situ "dist" \ +&& node_modules/.bin/mocha test/test.js diff --git a/test/release/rollup-es.sh b/test/release/rollup-es.sh new file mode 100755 index 00000000..f9443ff8 --- /dev/null +++ b/test/release/rollup-es.sh @@ -0,0 +1,83 @@ +#!/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/rollup \ +&& git clone https://github.com/rollup/rollup.git tmp/rollup \ +&& cd tmp/rollup \ +&& rm -rf .git/hooks \ +&& git checkout 3d80c06f895eab41e648ee99786fa68c72458b80 \ +&& patch -l -p1 <<EOF +--- a/package.json ++++ b/package.json +@@ -23 +22,0 @@ +- "prepublishOnly": "npm run lint && npm run test:only && npm run test:leak", +--- a/rollup.config.js ++++ b/rollup.config.js +@@ -1,5 +1,4 @@ + import { readFileSync } from 'fs'; +-import buble from 'rollup-plugin-buble'; + import resolve from 'rollup-plugin-node-resolve'; + import commonjs from 'rollup-plugin-commonjs'; + import json from 'rollup-plugin-json'; +@@ -25,12 +24,6 @@ export default [ + input: 'src/node-entry.js', + plugins: [ + json(), +- buble({ +- include: ['src/**', 'node_modules/acorn/**'], +- target: { +- node: '4' +- } +- }), + resolve(), + commonjs() + ], +@@ -48,12 +41,6 @@ export default [ + input: 'src/browser-entry.js', + plugins: [ + json(), +- buble({ +- include: ['src/**', 'node_modules/acorn/**'], +- target: { +- node: '4' +- } +- }), + resolve(), + commonjs(), + { +@@ -80,7 +67,6 @@ export default [ + plugins: [ + string({ include: '**/*.md' }), + json(), +- buble({ target: { node: 4 } }), + commonjs({ + include: 'node_modules/**' + }), +--- a/test/mocha.opts ++++ b/test/mocha.opts +@@ -1,2 +1 @@ +---require buble/register + test/test.js +EOF +ERR=$?; if [ "$ERR" != "0" ]; then echo "Error: $ERR"; exit $ERR; fi +minify_in_situ "bin" \ +&& minify_in_situ "browser" \ +&& minify_in_situ "src" \ +&& rm -rf node_modules \ +&& npm ci \ +&& rm -rf dist \ +&& npm run build \ +&& minify_in_situ "dist" \ +&& node_modules/.bin/mocha diff --git a/test/release/rollup-ts.sh b/test/release/rollup-ts.sh new file mode 100755 index 00000000..d1888a5c --- /dev/null +++ b/test/release/rollup-ts.sh @@ -0,0 +1,45 @@ +#!/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 + 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 <<EOF +--- a/package.json ++++ b/package.json +@@ -27,4 +26,0 @@ +- "postinstall": "husky install", +- "postpublish": "pinst --enable", +- "prepare": "npm run build", +- "prepublishOnly": "pinst --disable && npm ci && npm run lint:nofix && npm run security && npm run build:bootstrap && npm run test:all", +EOF +ERR=$?; if [ "$ERR" != "0" ]; then echo "Error: $ERR"; exit $ERR; fi +npm install esbuild-wasm@0.8.56 \ +&& minify_in_situ "cli" \ +&& minify_in_situ "src" \ +&& rm -rf node_modules \ +&& npm ci \ +&& rm -rf dist \ +&& npm run build \ +&& minify_in_situ "dist" \ +&& node_modules/.bin/mocha test/test.js \ +&& node_modules/.bin/mocha test/browser/index.js diff --git a/test/release/sucrase.sh b/test/release/sucrase.sh new file mode 100755 index 00000000..4ac04d9d --- /dev/null +++ b/test/release/sucrase.sh @@ -0,0 +1,90 @@ +#!/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 + 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 <<EOF +--- a/package.json ++++ b/package.json +@@ -25 +24,0 @@ +- "prepublishOnly": "yarn clean && yarn build", +@@ -65 +63,0 @@ +- "test262-harness": "^6.5.0", +--- a/script/build.ts ++++ b/script/build.ts +@@ -16 +15,0 @@ async function main(): Promise<void> { +- () => buildBenchmark(), +@@ -18,5 +16,0 @@ async function main(): Promise<void> { +- () => 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<void> { +- // 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<void> { +- 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 |