diff --git a/.eslintignore b/.eslintignore index c52afd1..45f769f 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,4 +1,5 @@ /coverage /dist /node_modules -/test/fixtures \ No newline at end of file +/test/fixtures +/test/outputs diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 667b4a8..3643530 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -43,8 +43,8 @@ jobs: - name: Lint run: npm run lint - # - name: Security audit - # run: npm run security + - name: Security audit + run: npm run security - name: Check commit message uses: wagoid/commitlint-github-action@v1 diff --git a/.gitignore b/.gitignore index 8896fc0..047b679 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ npm-debug.log* /local /reports /node_modules +/test/outputs .DS_Store Thumbs.db .idea diff --git a/.prettierignore b/.prettierignore index f8f1e31..b1dc5fc 100644 --- a/.prettierignore +++ b/.prettierignore @@ -2,4 +2,5 @@ /dist /node_modules /test/fixtures -CHANGELOG.md \ No newline at end of file +/test/outputs +CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 8af4ef5..6fe8ced 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,23 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [5.0.0](https://github.com/webpack-contrib/compression-webpack-plugin/compare/v4.0.1...v5.0.0) (2020-08-17) + + +### ⚠ BREAKING CHANGES + +* default value of the `filename` option is `'[path].gz'` +* use `processAssets` hook for `webpack@5` compatibility, it can create incompatibility with plugins that do not support `webpack@5`, please open an issue in their repositories + +### Features + +* improve compatibility with `webpack@5` ([1f9674e](https://github.com/webpack-contrib/compression-webpack-plugin/commit/1f9674e7573a2b30822c08d4c719fc4849cce793)) +* improve stats output for `webpack@5` + +### Bug Fixes + +* fix persistent cache between builds + ### [4.0.1](https://github.com/webpack-contrib/compression-webpack-plugin/compare/v4.0.0...v4.0.1) (2020-08-12) diff --git a/README.md b/README.md index f88b303..b269022 100644 --- a/README.md +++ b/README.md @@ -40,17 +40,17 @@ And run `webpack` via your preferred method. ## Options -| Name | Type | Default | Description | -| :---------------------------------------------: | :---------------------------------------: | :----------------: | :------------------------------------------------------------------------------------------------------------ | -| **[`test`](#test)** | `{String\|RegExp\|Array}` | `undefined` | Include all assets that pass test assertion | -| **[`include`](#include)** | `{String\|RegExp\|Array}` | `undefined` | Include all assets matching any of these conditions | -| **[`exclude`](#exclude)** | `{String\|RegExp\|Array}` | `undefined` | Exclude all assets matching any of these conditions | -| **[`algorithm`](#algorithm)** | `{String\|Function}` | `gzip` | The compression algorithm/function | -| **[`compressionOptions`](#compressionoptions)** | `{Object}` | `{ level: 9 }` | Compression options for `algorithm` | -| **[`threshold`](#threshold)** | `{Number}` | `0` | Only assets bigger than this size are processed (in bytes) | -| **[`minRatio`](#minratio)** | `{Number}` | `0.8` | Only assets that compress better than this ratio are processed (`minRatio = Compressed Size / Original Size`) | -| **[`filename`](#filename)** | `{String\|Function}` | `[path].gz[query]` | The target asset filename. | -| **[`cache`](#cache)** | `{Boolean}` | `true` | Enable file caching | +| Name | Type | Default | Description | +| :---------------------------------------------: | :---------------------------------------: | :------------: | :------------------------------------------------------------------------------------------------------------ | +| **[`test`](#test)** | `{String\|RegExp\|Array}` | `undefined` | Include all assets that pass test assertion | +| **[`include`](#include)** | `{String\|RegExp\|Array}` | `undefined` | Include all assets matching any of these conditions | +| **[`exclude`](#exclude)** | `{String\|RegExp\|Array}` | `undefined` | Exclude all assets matching any of these conditions | +| **[`algorithm`](#algorithm)** | `{String\|Function}` | `gzip` | The compression algorithm/function | +| **[`compressionOptions`](#compressionoptions)** | `{Object}` | `{ level: 9 }` | Compression options for `algorithm` | +| **[`threshold`](#threshold)** | `{Number}` | `0` | Only assets bigger than this size are processed (in bytes) | +| **[`minRatio`](#minratio)** | `{Number}` | `0.8` | Only assets that compress better than this ratio are processed (`minRatio = Compressed Size / Original Size`) | +| **[`filename`](#filename)** | `{String\|Function}` | `[path].gz` | The target asset filename. | +| **[`cache`](#cache)** | `{Boolean}` | `true` | Enable file caching | ### `test` @@ -116,6 +116,8 @@ Default: `gzip` The compression algorithm/function. +> ℹ️ If you use custom function for the `algorithm` option, the default value of the `compressionOptions` option is `{}`. + #### `String` The algorithm is taken from [zlib](https://nodejs.org/api/zlib.html). @@ -157,10 +159,10 @@ Default: `{ level: 9 }` Compression options for `algorithm`. -If you use custom function for the `algorithm` option, the default value is `{}`. - You can find all options here [zlib](https://nodejs.org/api/zlib.html#zlib_class_options). +> ℹ️ If you use custom function for the `algorithm` option, the default value is `{}`. + **webpack.config.js** ```js @@ -200,7 +202,12 @@ Default: `0.8` Only assets that compress better than this ratio are processed (`minRatio = Compressed Size / Original Size`). Example: you have `image.png` file with 1024b size, compressed version of file has 768b size, so `minRatio` equal `0.75`. In other words assets will be processed when the `Compressed Size / Original Size` value less `minRatio` value. -You can use `1` value to process assets that are smaller than the original. Use a value of Number.MAX_SAFE_INTEGER to process all assets even if they are larger than the original (useful when you are pre-zipping all assets for AWS) + +You can use `1` value to process assets that are smaller than the original. + +Use a value of `Infinity` to process all assets even if they are larger than the original size or their original size is `0` bytes (useful when you are pre-zipping all assets for AWS). + +Use a value of `Number.MAX_SAFE_INTEGER` to process all assets even if they are larger than the original size, excluding assets with their original size is `0` bytes. **webpack.config.js** @@ -208,6 +215,12 @@ You can use `1` value to process assets that are smaller than the original. Use module.exports = { plugins: [ new CompressionPlugin({ + // Compress all assets, including files with `0` bytes size + // minRatio: Infinity + + // Compress all assets, excluding files with `0` bytes size + // minRatio: Number.MAX_SAFE_INTEGER + minRatio: 0.8, }), ], @@ -236,7 +249,7 @@ The target asset filename. module.exports = { plugins: [ new CompressionPlugin({ - filename: '[path].gz[query]', + filename: '[path].gz', }), ], }; @@ -371,7 +384,7 @@ const zlib = require('zlib'); module.exports = { plugins: [ new CompressionPlugin({ - filename: '[path].br[query]', + filename: '[path].br', algorithm: 'brotliCompress', test: /\.(js|css|html|svg)$/, compressionOptions: { @@ -398,14 +411,14 @@ const zlib = require('zlib'); module.exports = { plugins: [ new CompressionPlugin({ - filename: '[path].gz[query]', + filename: '[path].gz', algorithm: 'gzip', test: /\.js$|\.css$|\.html$/, threshold: 10240, minRatio: 0.8, }), new CompressionPlugin({ - filename: '[path].br[query]', + filename: '[path].br', algorithm: 'brotliCompress', test: /\.(js|css|html|svg)$/, compressionOptions: { diff --git a/package-lock.json b/package-lock.json index 867f86b..a54aa72 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "compression-webpack-plugin", - "version": "4.0.1", + "version": "5.0.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -1241,12 +1241,12 @@ } }, "@commitlint/config-conventional": { - "version": "9.1.1", - "resolved": "https://registry.npmjs.org/@commitlint/config-conventional/-/config-conventional-9.1.1.tgz", - "integrity": "sha512-t/bvv8ofjj7V4W99eVDyuACaC7Ch4SYaukglBYt/K1Y9Ixg8mCBuFDMGRMhyZn4upUe1ls8l4SO3rjaVbYIjlg==", + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/@commitlint/config-conventional/-/config-conventional-10.0.0.tgz", + "integrity": "sha512-M9l7hh2a1GB9nQ/Gm+aDLGPmzGdpgxqJoSmrbTxDlapJDyaL7FPe5aQf66F50Eq3j0bmaRaJihFCA6mIUBQAag==", "dev": true, "requires": { - "conventional-changelog-conventionalcommits": "4.3.0" + "conventional-changelog-conventionalcommits": "^4.3.1" } }, "@commitlint/ensure": { @@ -1597,13 +1597,13 @@ } }, "@jest/core": { - "version": "26.3.0", - "resolved": "https://registry.npmjs.org/@jest/core/-/core-26.3.0.tgz", - "integrity": "sha512-WAAqGMpc+U+GS0oSr/ikI1JdRyPQyTZSVOr1xjnVcfvfUTZCK+wGoN0Cb7dm7HVdpbMQr/NvtM6vBVChctmzHA==", + "version": "26.4.0", + "resolved": "https://registry.npmjs.org/@jest/core/-/core-26.4.0.tgz", + "integrity": "sha512-mpXm4OjWQbz7qbzGIiSqvfNZ1FxX6ywWgLtdSD2luPORt5zKPtqcdDnX7L8RdfMaj1znDBgN2+gB094ZIr7vnA==", "dev": true, "requires": { "@jest/console": "^26.3.0", - "@jest/reporters": "^26.3.0", + "@jest/reporters": "^26.4.0", "@jest/test-result": "^26.3.0", "@jest/transform": "^26.3.0", "@jest/types": "^26.3.0", @@ -1613,17 +1613,17 @@ "exit": "^0.1.2", "graceful-fs": "^4.2.4", "jest-changed-files": "^26.3.0", - "jest-config": "^26.3.0", + "jest-config": "^26.4.0", "jest-haste-map": "^26.3.0", "jest-message-util": "^26.3.0", "jest-regex-util": "^26.0.0", - "jest-resolve": "^26.3.0", - "jest-resolve-dependencies": "^26.3.0", - "jest-runner": "^26.3.0", - "jest-runtime": "^26.3.0", - "jest-snapshot": "^26.3.0", + "jest-resolve": "^26.4.0", + "jest-resolve-dependencies": "^26.4.0", + "jest-runner": "^26.4.0", + "jest-runtime": "^26.4.0", + "jest-snapshot": "^26.4.0", "jest-util": "^26.3.0", - "jest-validate": "^26.3.0", + "jest-validate": "^26.4.0", "jest-watcher": "^26.3.0", "micromatch": "^4.0.2", "p-each-series": "^2.1.0", @@ -1760,20 +1760,20 @@ } }, "@jest/globals": { - "version": "26.3.0", - "resolved": "https://registry.npmjs.org/@jest/globals/-/globals-26.3.0.tgz", - "integrity": "sha512-oPe30VG9zor2U3Ev7khCM2LkjO3D+mgAv6s5D3Ed0sxfELxoRZwR8d1VgYWVQljcpumMwe9tDrKNuzgVjbEt7g==", + "version": "26.4.0", + "resolved": "https://registry.npmjs.org/@jest/globals/-/globals-26.4.0.tgz", + "integrity": "sha512-QKwoVAeL9d0xaEM9ebPvfc+bolN04F+o3zM2jswGDBiiNjCogZ3LvOaqumRdDyz6kLmbx+UhgMBAVuLunbXZ2A==", "dev": true, "requires": { "@jest/environment": "^26.3.0", "@jest/types": "^26.3.0", - "expect": "^26.3.0" + "expect": "^26.4.0" } }, "@jest/reporters": { - "version": "26.3.0", - "resolved": "https://registry.npmjs.org/@jest/reporters/-/reporters-26.3.0.tgz", - "integrity": "sha512-MfLJOUPxhGb3sRT/wFjHXd6gyVQ1Fb1XxbEwY+gqdDBpg3pq5qAB5eiBUvcTheFRHmhu3gOv3UZ/gtxmqGBA+Q==", + "version": "26.4.0", + "resolved": "https://registry.npmjs.org/@jest/reporters/-/reporters-26.4.0.tgz", + "integrity": "sha512-14OPAAuYhgRBSNxAocVluX6ksdMdK/EuP9NmtBXU9g1uKaVBrPnohn/CVm6iMot1a9iU8BCxa5715YRf8FEg/A==", "dev": true, "requires": { "@bcoe/v8-coverage": "^0.2.3", @@ -1792,7 +1792,7 @@ "istanbul-lib-source-maps": "^4.0.0", "istanbul-reports": "^3.0.2", "jest-haste-map": "^26.3.0", - "jest-resolve": "^26.3.0", + "jest-resolve": "^26.4.0", "jest-util": "^26.3.0", "jest-worker": "^26.3.0", "node-notifier": "^7.0.0", @@ -1885,16 +1885,16 @@ } }, "@jest/test-sequencer": { - "version": "26.3.0", - "resolved": "https://registry.npmjs.org/@jest/test-sequencer/-/test-sequencer-26.3.0.tgz", - "integrity": "sha512-G7TA0Z85uj5l1m9UKZ/nXbArn0y+MeLKbojNLDHgjb1PpNNFDAOO6FJhk9We34m/hadcciMcJFnxV94dV2TX+w==", + "version": "26.4.0", + "resolved": "https://registry.npmjs.org/@jest/test-sequencer/-/test-sequencer-26.4.0.tgz", + "integrity": "sha512-9Z7lCShS7vERp+DRwIVNH/6sHMWwJK1DPnGCpGeVLGJJWJ4Y08sQI3vIKdmKHu2KmwlUBpRM+BFf7NlVUkl5XA==", "dev": true, "requires": { "@jest/test-result": "^26.3.0", "graceful-fs": "^4.2.4", "jest-haste-map": "^26.3.0", - "jest-runner": "^26.3.0", - "jest-runtime": "^26.3.0" + "jest-runner": "^26.4.0", + "jest-runtime": "^26.4.0" } }, "@jest/transform": { @@ -2252,9 +2252,9 @@ "dev": true }, "@types/node": { - "version": "14.0.27", - "resolved": "https://registry.npmjs.org/@types/node/-/node-14.0.27.tgz", - "integrity": "sha512-kVrqXhbclHNHGu9ztnAwSncIgJv/FaxmzXJvGXNdcCpV1b8u1/Mi6z6m0vwy0LzKeXFTPLH0NzwmoJ3fNCIq0g==", + "version": "14.6.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.6.0.tgz", + "integrity": "sha512-mikldZQitV94akrc4sCcSjtJfsTKt4p+e/s0AGscVA6XArQ9kFclP+ZiYUMnq987rc6QlYxXv/EivqlfSLxpKA==", "dev": true }, "@types/normalize-package-data": { @@ -2528,9 +2528,9 @@ } }, "abab": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/abab/-/abab-2.0.3.tgz", - "integrity": "sha512-tsFzPpcttalNjFBCFMqsKYQcWxxen1pgJR56by//QwvJc4/OUS3kPOOttx2tSIfjsylB0pYu7f5D3K1RCxUnUg==", + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/abab/-/abab-2.0.4.tgz", + "integrity": "sha512-Eu9ELJWCz/c1e9gTiCY+FceWxcqzjYEbqMgtndnuSqZSUCOL73TWNK2mHfIj4Cw2E/ongOp+JISVNCmovt2KYQ==", "dev": true }, "acorn": { @@ -2577,9 +2577,9 @@ } }, "ajv": { - "version": "6.12.3", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.3.tgz", - "integrity": "sha512-4K0cK3L1hsqk9xIb2z9vs/XU+PGJZ9PNpJRDS9YLzmNdX6jmVPfamLvTJr0aDAusnHyCHO6MjzlkAsgtqp9teA==", + "version": "6.12.4", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.4.tgz", + "integrity": "sha512-eienB2c9qVQs2KWexhkrdMLVDoIQCz5KSeLxwg9Lzk4DOfBtIK9PQwwufcsn1jjGuf9WZmqPMbGxOzfcuphJCQ==", "requires": { "fast-deep-equal": "^3.1.1", "fast-json-stable-stringify": "^2.0.0", @@ -2751,14 +2751,15 @@ } }, "asn1.js": { - "version": "4.10.1", - "resolved": "https://registry.npmjs.org/asn1.js/-/asn1.js-4.10.1.tgz", - "integrity": "sha512-p32cOF5q0Zqs9uBiONKYLm6BClCoBCM5O9JfeUSlnQLBTxYdTK+pW+nXflm8UkKd2UYlEbYz5qEi0JuZR9ckSw==", + "version": "5.4.1", + "resolved": "https://registry.npmjs.org/asn1.js/-/asn1.js-5.4.1.tgz", + "integrity": "sha512-+I//4cYPccV8LdmBLiX8CYvf9Sp3vQsrqu2QNXRcrbiWvcx/UdlFiqUJJzxRQxgsZmvhXhn4cSKeSmoFjVdupA==", "dev": true, "requires": { "bn.js": "^4.0.0", "inherits": "^2.0.1", - "minimalistic-assert": "^1.0.0" + "minimalistic-assert": "^1.0.0", + "safer-buffer": "^2.1.0" }, "dependencies": { "bn.js": { @@ -2840,9 +2841,9 @@ "dev": true }, "aws4": { - "version": "1.10.0", - "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.10.0.tgz", - "integrity": "sha512-3YDiu347mtVtjpyV3u5kVqQLP242c06zwDOgpeRnybmXlYYsLbtTrUBUm8i8srONt+FWobl5aibnU1030PeeuA==", + "version": "1.10.1", + "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.10.1.tgz", + "integrity": "sha512-zg7Hz2k5lI8kb7U32998pRRFin7zJlkfezGJjUc2heaD4Pw2wObakCDVzkKztTm/Ln7eiVvYsjqak0Ed4LkMDA==", "dev": true }, "babel-code-frame": { @@ -3146,9 +3147,9 @@ "dev": true }, "bn.js": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-5.1.2.tgz", - "integrity": "sha512-40rZaf3bUNKTVYu9sIeeEGOg7g14Yvnj9kH7b50EiwX0Q7A6umbvfI5tvHaOERH0XigqKkfLkFQxzb4e6CIXnA==", + "version": "5.1.3", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-5.1.3.tgz", + "integrity": "sha512-GkTiFpjFtUzU9CbMeJ5iazkCzGL3jrhzerzZIuqLABjbwRaFt33I9tUdSNryIptM+RxDet6OKm2WnLXzW51KsQ==", "dev": true }, "brace-expansion": { @@ -3410,9 +3411,9 @@ } }, "caniuse-lite": { - "version": "1.0.30001113", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001113.tgz", - "integrity": "sha512-qMvjHiKH21zzM/VDZr6oosO6Ri3U0V2tC015jRXjOecwQCJtsU5zklTNTk31jQbIOP8gha0h1ccM/g0ECP+4BA==", + "version": "1.0.30001114", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001114.tgz", + "integrity": "sha512-ml/zTsfNBM+T1+mjglWRPgVsu2L76GAaADKX5f4t0pbhttEp0WMawJsHDYlFkVZkoA+89uvBRrVrEE4oqenzXQ==", "dev": true }, "capture-exit": { @@ -3737,21 +3738,21 @@ "dev": true }, "conventional-changelog": { - "version": "3.1.21", - "resolved": "https://registry.npmjs.org/conventional-changelog/-/conventional-changelog-3.1.21.tgz", - "integrity": "sha512-ZGecVZPEo3aC75VVE4nu85589dDhpMyqfqgUM5Myq6wfKWiNqhDJLSDMsc8qKXshZoY7dqs1hR0H/15kI/G2jQ==", + "version": "3.1.23", + "resolved": "https://registry.npmjs.org/conventional-changelog/-/conventional-changelog-3.1.23.tgz", + "integrity": "sha512-sScUu2NHusjRC1dPc5p8/b3kT78OYr95/Bx7Vl8CPB8tF2mG1xei5iylDTRjONV5hTlzt+Cn/tBWrKdd299b7A==", "dev": true, "requires": { - "conventional-changelog-angular": "^5.0.10", + "conventional-changelog-angular": "^5.0.11", "conventional-changelog-atom": "^2.0.7", "conventional-changelog-codemirror": "^2.0.7", - "conventional-changelog-conventionalcommits": "^4.3.0", - "conventional-changelog-core": "^4.1.7", + "conventional-changelog-conventionalcommits": "^4.4.0", + "conventional-changelog-core": "^4.2.0", "conventional-changelog-ember": "^2.0.8", "conventional-changelog-eslint": "^3.0.8", "conventional-changelog-express": "^2.0.5", "conventional-changelog-jquery": "^3.0.10", - "conventional-changelog-jshint": "^2.0.7", + "conventional-changelog-jshint": "^2.0.8", "conventional-changelog-preset-loader": "^2.3.4" } }, @@ -3790,41 +3791,14 @@ "dev": true }, "conventional-changelog-conventionalcommits": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/conventional-changelog-conventionalcommits/-/conventional-changelog-conventionalcommits-4.3.0.tgz", - "integrity": "sha512-oYHydvZKU+bS8LnGqTMlNrrd7769EsuEHKy4fh1oMdvvDi7fem8U+nvfresJ1IDB8K00Mn4LpiA/lR+7Gs6rgg==", + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/conventional-changelog-conventionalcommits/-/conventional-changelog-conventionalcommits-4.4.0.tgz", + "integrity": "sha512-ybvx76jTh08tpaYrYn/yd0uJNLt5yMrb1BphDe4WBredMlvPisvMghfpnJb6RmRNcqXeuhR6LfGZGewbkRm9yA==", "dev": true, "requires": { - "compare-func": "^1.3.1", + "compare-func": "^2.0.0", "lodash": "^4.17.15", "q": "^1.5.1" - }, - "dependencies": { - "compare-func": { - "version": "1.3.4", - "resolved": "https://registry.npmjs.org/compare-func/-/compare-func-1.3.4.tgz", - "integrity": "sha512-sq2sWtrqKPkEXAC8tEJA1+BqAH9GbFkGBtUOqrUX57VSfwp8xyktctk+uLoRy5eccTdxzDcVIztlYDpKs3Jv1Q==", - "dev": true, - "requires": { - "array-ify": "^1.0.0", - "dot-prop": "^3.0.0" - } - }, - "dot-prop": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-3.0.0.tgz", - "integrity": "sha1-G3CK8JSknJoOfbyteQq6U52sEXc=", - "dev": true, - "requires": { - "is-obj": "^1.0.0" - } - }, - "is-obj": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/is-obj/-/is-obj-1.0.1.tgz", - "integrity": "sha1-PkcprB9f3gJc19g6iW2rn09n2w8=", - "dev": true - } } }, "conventional-changelog-core": { @@ -4173,9 +4147,9 @@ } }, "conventional-recommended-bump": { - "version": "6.0.9", - "resolved": "https://registry.npmjs.org/conventional-recommended-bump/-/conventional-recommended-bump-6.0.9.tgz", - "integrity": "sha512-DpRmW1k8CpRrcsXHOPGgHgOd4BMGiq2gtXAveGM8B9pSd9b4r4WKnqp1Fd0vkDtk8l973mIk8KKKUYnKRr9SFw==", + "version": "6.0.10", + "resolved": "https://registry.npmjs.org/conventional-recommended-bump/-/conventional-recommended-bump-6.0.10.tgz", + "integrity": "sha512-2ibrqAFMN3ZA369JgVoSbajdD/BHN6zjY7DZFKTHzyzuQejDUCjQ85S5KHxCRxNwsbDJhTPD5hOKcis/jQhRgg==", "dev": true, "requires": { "concat-stream": "^2.0.0", @@ -4183,7 +4157,7 @@ "conventional-commits-filter": "^2.0.6", "conventional-commits-parser": "^3.1.0", "git-raw-commits": "2.0.0", - "git-semver-tags": "^4.0.0", + "git-semver-tags": "^4.1.0", "meow": "^7.0.0", "q": "^1.5.1" }, @@ -4516,13 +4490,13 @@ } }, "create-ecdh": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/create-ecdh/-/create-ecdh-4.0.3.tgz", - "integrity": "sha512-GbEHQPMOswGpKXM9kCWVrremUcBmjteUaQ01T9rkKCPDXfUHX0IoP9LpHYo2NPFampa4e+/pFDc3jQdxrxQLaw==", + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/create-ecdh/-/create-ecdh-4.0.4.tgz", + "integrity": "sha512-mf+TCx8wWc9VpuxfP2ht0iSISLZnt0JgWlrOKZiNqyUZWnjIaCIVNQArMHnCZKfEYRg6IM7A+NeJoN8gf/Ws0A==", "dev": true, "requires": { "bn.js": "^4.1.0", - "elliptic": "^6.0.0" + "elliptic": "^6.5.3" }, "dependencies": { "bn.js": { @@ -5119,9 +5093,9 @@ } }, "electron-to-chromium": { - "version": "1.3.530", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.530.tgz", - "integrity": "sha512-jnKBqvkXyxo6Tr245YyghzSMjmrA+uzQn+rwLjd3n+Y3sad0eWPzAXfa2lDwSikQu0I5reYacZjmQjCRH9VQdg==", + "version": "1.3.533", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.533.tgz", + "integrity": "sha512-YqAL+NXOzjBnpY+dcOKDlZybJDCOzgsq4koW3fvyty/ldTmsb4QazZpOWmVvZ2m0t5jbBf7L0lIGU3BUipwG+A==", "dev": true }, "elliptic": { @@ -5327,9 +5301,9 @@ } }, "eslint": { - "version": "7.6.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-7.6.0.tgz", - "integrity": "sha512-QlAManNtqr7sozWm5TF4wIH9gmUm2hE3vNRUvyoYAa4y1l5/jxD/PQStEjBMQtCqZmSep8UxrcecI60hOpe61w==", + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-7.7.0.tgz", + "integrity": "sha512-1KUxLzos0ZVsyL81PnRN335nDtQ8/vZUD6uMtWbF+5zDtjKcsklIi78XoE0MVL93QvWTu+E5y44VyyCsOMBrIg==", "dev": true, "requires": { "@babel/code-frame": "^7.0.0", @@ -5894,15 +5868,15 @@ } }, "expect": { - "version": "26.3.0", - "resolved": "https://registry.npmjs.org/expect/-/expect-26.3.0.tgz", - "integrity": "sha512-3tC0dpPgkTGkycM9H+mMjzIhm8I3ZAOV+y1Cj3xmF9iKxDeHBCAB64hf1OY//bMzQ/AftfodNy2pQWMKpTIV8Q==", + "version": "26.4.0", + "resolved": "https://registry.npmjs.org/expect/-/expect-26.4.0.tgz", + "integrity": "sha512-dbYDJhFcqQsamlos6nEwAMe+ahdckJBk5fmw1DYGLQGabGSlUuT+Fm2jHYw5119zG3uIhP+lCQbjJhFEdZMJtg==", "dev": true, "requires": { "@jest/types": "^26.3.0", "ansi-styles": "^4.0.0", "jest-get-type": "^26.3.0", - "jest-matcher-utils": "^26.3.0", + "jest-matcher-utils": "^26.4.0", "jest-message-util": "^26.3.0", "jest-regex-util": "^26.0.0" }, @@ -7315,9 +7289,9 @@ } }, "is-docker": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/is-docker/-/is-docker-2.0.0.tgz", - "integrity": "sha512-pJEdRugimx4fBMra5z2/5iRdZ63OhYV0vr0Dwm5+xtW4D1FvRkB8hamMIhnWfyJeDdyr/aa7BDyNbtG38VxgoQ==", + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/is-docker/-/is-docker-2.1.1.tgz", + "integrity": "sha512-ZOoqiXfEwtGknTiuDEy8pN2CfE3TxMHprvNer1mXiqwkOT77Rw3YVrUQ52EqAOU3QAWDQ+bQdx7HJzrv7LS2Hw==", "dev": true, "optional": true }, @@ -7601,14 +7575,14 @@ } }, "jest": { - "version": "26.3.0", - "resolved": "https://registry.npmjs.org/jest/-/jest-26.3.0.tgz", - "integrity": "sha512-LFCry7NS6bTa4BUGUHC+NvZ3B9WG7Jv8F+Lb96dAJFM23LMwSsL5RiJcw9S+nejsh8lS1VxHq+RSH4Xa9tujpA==", + "version": "26.4.0", + "resolved": "https://registry.npmjs.org/jest/-/jest-26.4.0.tgz", + "integrity": "sha512-lNCOS+ckRHE1wFyVtQClBmbsOVuH2GWUTJMDL3vunp9DXcah+V8vfvVVApngClcdoc3rgZpqOfCNKLjxjj2l4g==", "dev": true, "requires": { - "@jest/core": "^26.3.0", + "@jest/core": "^26.4.0", "import-local": "^3.0.2", - "jest-cli": "^26.3.0" + "jest-cli": "^26.4.0" }, "dependencies": { "ansi-styles": { @@ -7653,12 +7627,12 @@ "dev": true }, "jest-cli": { - "version": "26.3.0", - "resolved": "https://registry.npmjs.org/jest-cli/-/jest-cli-26.3.0.tgz", - "integrity": "sha512-vrlDluEjnNTJNpmw+lJ1Dvjhc+2o7QG0dG8n+iDu3NaoQ9OzqNeZsZZ0a9KP7SdtD5BXgvGSpCWTlLH5SqtxcA==", + "version": "26.4.0", + "resolved": "https://registry.npmjs.org/jest-cli/-/jest-cli-26.4.0.tgz", + "integrity": "sha512-kw2Pr3V2x9/WzSDGsbz/MJBNlCoPMxMudrIavft4bqRlv5tASjU51tyO+1Os1LdW2dAnLQZYsxFUZ8oWPyssGQ==", "dev": true, "requires": { - "@jest/core": "^26.3.0", + "@jest/core": "^26.4.0", "@jest/test-result": "^26.3.0", "@jest/types": "^26.3.0", "chalk": "^4.0.0", @@ -7666,9 +7640,9 @@ "graceful-fs": "^4.2.4", "import-local": "^3.0.2", "is-ci": "^2.0.0", - "jest-config": "^26.3.0", + "jest-config": "^26.4.0", "jest-util": "^26.3.0", - "jest-validate": "^26.3.0", + "jest-validate": "^26.4.0", "prompts": "^2.0.1", "yargs": "^15.3.1" } @@ -7724,9 +7698,9 @@ } }, "get-stream": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.1.0.tgz", - "integrity": "sha512-EXr1FOzrzTfGeL0gQdeFEvOMm2mzMOglyiOXSTpPC+iAjAKftbr3jpCMWynogwYnM+eSj9sHGc6wjIcDvYiygw==", + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.2.0.tgz", + "integrity": "sha512-nBF+F1rAZVCu/p7rjzgA+Yb4lfYXrpl7a6VmJrU8wF9I1CKvP/QwPNZHnOlwbTkY6dvtFIzFMSyQXbLoTQPRpA==", "dev": true, "requires": { "pump": "^3.0.0" @@ -7780,13 +7754,13 @@ } }, "jest-config": { - "version": "26.3.0", - "resolved": "https://registry.npmjs.org/jest-config/-/jest-config-26.3.0.tgz", - "integrity": "sha512-xzvmhKYOXOc/JjGabUUXoi7Nxu6QpY5zJxND85wdqFrdP7raJT5wqlrVJbp6Bv4Sj1e83Z8bkxjsZCpwPASaPw==", + "version": "26.4.0", + "resolved": "https://registry.npmjs.org/jest-config/-/jest-config-26.4.0.tgz", + "integrity": "sha512-MxsvrBug8YY+C4QcUBtmgnHyFeW7w3Ouk/w9eplCDN8VJGVyBEZFe8Lxzfp2pSqh0Dqurqv8Oik2YkbekGUlxg==", "dev": true, "requires": { "@babel/core": "^7.1.0", - "@jest/test-sequencer": "^26.3.0", + "@jest/test-sequencer": "^26.4.0", "@jest/types": "^26.3.0", "babel-jest": "^26.3.0", "chalk": "^4.0.0", @@ -7796,13 +7770,13 @@ "jest-environment-jsdom": "^26.3.0", "jest-environment-node": "^26.3.0", "jest-get-type": "^26.3.0", - "jest-jasmine2": "^26.3.0", + "jest-jasmine2": "^26.4.0", "jest-regex-util": "^26.0.0", - "jest-resolve": "^26.3.0", + "jest-resolve": "^26.4.0", "jest-util": "^26.3.0", - "jest-validate": "^26.3.0", + "jest-validate": "^26.4.0", "micromatch": "^4.0.2", - "pretty-format": "^26.3.0" + "pretty-format": "^26.4.0" }, "dependencies": { "ansi-styles": { @@ -7901,15 +7875,15 @@ } }, "jest-diff": { - "version": "26.3.0", - "resolved": "https://registry.npmjs.org/jest-diff/-/jest-diff-26.3.0.tgz", - "integrity": "sha512-q5OZAtnr5CbHzrhjANzc3wvROk7+rcjCUI5uqM4cjOjtscNKfbJKBs3YhsWWhsdsIZzI3gc6wOpm49r6S61beg==", + "version": "26.4.0", + "resolved": "https://registry.npmjs.org/jest-diff/-/jest-diff-26.4.0.tgz", + "integrity": "sha512-wwC38HlOW+iTq6j5tkj/ZamHn6/nrdcEOc/fKaVILNtN2NLWGdkfRaHWwfNYr5ehaLvuoG2LfCZIcWByVj0gjg==", "dev": true, "requires": { "chalk": "^4.0.0", "diff-sequences": "^26.3.0", "jest-get-type": "^26.3.0", - "pretty-format": "^26.3.0" + "pretty-format": "^26.4.0" }, "dependencies": { "ansi-styles": { @@ -7974,16 +7948,16 @@ } }, "jest-each": { - "version": "26.3.0", - "resolved": "https://registry.npmjs.org/jest-each/-/jest-each-26.3.0.tgz", - "integrity": "sha512-OSAnLv0Eo/sDVhV0ifT2u6Q4aYUBoZ97R4k9cQshUFLTco0iRDbViJiW3Y6ySZjW95Tb83/xMYCppBih/7sW/A==", + "version": "26.4.0", + "resolved": "https://registry.npmjs.org/jest-each/-/jest-each-26.4.0.tgz", + "integrity": "sha512-+cyBh1ehs6thVT/bsZVG+WwmRn2ix4Q4noS9yLZgM10yGWPW12/TDvwuOV2VZXn1gi09/ZwJKJWql6YW1C9zNw==", "dev": true, "requires": { "@jest/types": "^26.3.0", "chalk": "^4.0.0", "jest-get-type": "^26.3.0", "jest-util": "^26.3.0", - "pretty-format": "^26.3.0" + "pretty-format": "^26.4.0" }, "dependencies": { "ansi-styles": { @@ -8158,9 +8132,9 @@ } }, "jest-jasmine2": { - "version": "26.3.0", - "resolved": "https://registry.npmjs.org/jest-jasmine2/-/jest-jasmine2-26.3.0.tgz", - "integrity": "sha512-ZPkkA2XfH/fcLOp0SjeR4uDrMoNFilcwxLHORpjfMrcU0BFHNNRaF3DnslCdmewzqaERqtmHpYo8jj34RT+m2g==", + "version": "26.4.0", + "resolved": "https://registry.npmjs.org/jest-jasmine2/-/jest-jasmine2-26.4.0.tgz", + "integrity": "sha512-cGBxwzDDKB09EPJ4pE69BMDv+2lO442IB1xQd+vL3cua2OKdeXQK6iDlQKoRX/iP0RgU5T8sn9yahLcx/+ox8Q==", "dev": true, "requires": { "@babel/traverse": "^7.1.0", @@ -8171,15 +8145,15 @@ "@types/node": "*", "chalk": "^4.0.0", "co": "^4.6.0", - "expect": "^26.3.0", + "expect": "^26.4.0", "is-generator-fn": "^2.0.0", - "jest-each": "^26.3.0", - "jest-matcher-utils": "^26.3.0", + "jest-each": "^26.4.0", + "jest-matcher-utils": "^26.4.0", "jest-message-util": "^26.3.0", - "jest-runtime": "^26.3.0", - "jest-snapshot": "^26.3.0", + "jest-runtime": "^26.4.0", + "jest-snapshot": "^26.4.0", "jest-util": "^26.3.0", - "pretty-format": "^26.3.0", + "pretty-format": "^26.4.0", "throat": "^5.0.0" }, "dependencies": { @@ -8236,25 +8210,25 @@ } }, "jest-leak-detector": { - "version": "26.3.0", - "resolved": "https://registry.npmjs.org/jest-leak-detector/-/jest-leak-detector-26.3.0.tgz", - "integrity": "sha512-8C2Bur0S6n2xgW5kx22bDbe+Jjz9sM7/abr7DRQ48ww6q4w7vVzEpDEZiY7KatjTHtUloLTAqwTXEXg+tuETTg==", + "version": "26.4.0", + "resolved": "https://registry.npmjs.org/jest-leak-detector/-/jest-leak-detector-26.4.0.tgz", + "integrity": "sha512-7EXKKEKnAWUPyiVtGZzJflbPOtYUdlNoevNVOkAcPpdR8xWiYKPGNGA6sz25S+8YhZq3rmkQJYAh3/P0VnoRwA==", "dev": true, "requires": { "jest-get-type": "^26.3.0", - "pretty-format": "^26.3.0" + "pretty-format": "^26.4.0" } }, "jest-matcher-utils": { - "version": "26.3.0", - "resolved": "https://registry.npmjs.org/jest-matcher-utils/-/jest-matcher-utils-26.3.0.tgz", - "integrity": "sha512-M5ZRSp6qpyzZyrLwXD2Sop7xaxm6qu/mKvqWU+BOSPTa4Y0ZEoKUYBzus/emg6kaVt7Ov9xMDLLZR1SrC8FxCw==", + "version": "26.4.0", + "resolved": "https://registry.npmjs.org/jest-matcher-utils/-/jest-matcher-utils-26.4.0.tgz", + "integrity": "sha512-u+xdCdq+F262DH+PutJKXLGr2H5P3DImdJCir51PGSfi3TtbLQ5tbzKaN8BkXbiTIU6ayuAYBWTlU1nyckVdzA==", "dev": true, "requires": { "chalk": "^4.0.0", - "jest-diff": "^26.3.0", + "jest-diff": "^26.4.0", "jest-get-type": "^26.3.0", - "pretty-format": "^26.3.0" + "pretty-format": "^26.4.0" }, "dependencies": { "ansi-styles": { @@ -8449,9 +8423,9 @@ "dev": true }, "jest-resolve": { - "version": "26.3.0", - "resolved": "https://registry.npmjs.org/jest-resolve/-/jest-resolve-26.3.0.tgz", - "integrity": "sha512-+oKVWDkXjdZ4Xciuxv+M5e5v/Z3RLjrKIzen9tq3IO6HpzsLf9Mk3rET5du1uU8iVUCvz4/1PmjzNF50Uc7l2A==", + "version": "26.4.0", + "resolved": "https://registry.npmjs.org/jest-resolve/-/jest-resolve-26.4.0.tgz", + "integrity": "sha512-bn/JoZTEXRSlEx3+SfgZcJAVuTMOksYq9xe9O6s4Ekg84aKBObEaVXKOEilULRqviSLAYJldnoWV9c07kwtiCg==", "dev": true, "requires": { "@jest/types": "^26.3.0", @@ -8523,20 +8497,20 @@ } }, "jest-resolve-dependencies": { - "version": "26.3.0", - "resolved": "https://registry.npmjs.org/jest-resolve-dependencies/-/jest-resolve-dependencies-26.3.0.tgz", - "integrity": "sha512-j5rZ2BUh8vVjJZ7bpgCre0t6mbFLm5BWfVhYb1H35A3nbPN3kepzMqkMnKXPhwyLIVwn25uYkv6LHc2/Xa1sGw==", + "version": "26.4.0", + "resolved": "https://registry.npmjs.org/jest-resolve-dependencies/-/jest-resolve-dependencies-26.4.0.tgz", + "integrity": "sha512-hznK/hlrlhu8hwdbieRdHFKmcV83GW8t30libt/v6j1L3IEzb8iN21SaWzV8KRAAK4ijiU0kuge0wnHn+0rytQ==", "dev": true, "requires": { "@jest/types": "^26.3.0", "jest-regex-util": "^26.0.0", - "jest-snapshot": "^26.3.0" + "jest-snapshot": "^26.4.0" } }, "jest-runner": { - "version": "26.3.0", - "resolved": "https://registry.npmjs.org/jest-runner/-/jest-runner-26.3.0.tgz", - "integrity": "sha512-eiPKgbhTM4q6A7RBh4qzKf6hwFDJMfqoFJubFvWSrHdZUsvSiBWYDqQI+FUXDFxDAOn/AfZjKURACAH3fUDjwA==", + "version": "26.4.0", + "resolved": "https://registry.npmjs.org/jest-runner/-/jest-runner-26.4.0.tgz", + "integrity": "sha512-XF+tnUGolnPriu6Gg+HHWftspMjD5NkTV2mQppQnpZe39GcUangJ0al7aBGtA3GbVAcRd048DQiJPmsQRdugjw==", "dev": true, "requires": { "@jest/console": "^26.3.0", @@ -8548,13 +8522,13 @@ "emittery": "^0.7.1", "exit": "^0.1.2", "graceful-fs": "^4.2.4", - "jest-config": "^26.3.0", + "jest-config": "^26.4.0", "jest-docblock": "^26.0.0", "jest-haste-map": "^26.3.0", - "jest-leak-detector": "^26.3.0", + "jest-leak-detector": "^26.4.0", "jest-message-util": "^26.3.0", - "jest-resolve": "^26.3.0", - "jest-runtime": "^26.3.0", + "jest-resolve": "^26.4.0", + "jest-runtime": "^26.4.0", "jest-util": "^26.3.0", "jest-worker": "^26.3.0", "source-map-support": "^0.5.6", @@ -8614,15 +8588,15 @@ } }, "jest-runtime": { - "version": "26.3.0", - "resolved": "https://registry.npmjs.org/jest-runtime/-/jest-runtime-26.3.0.tgz", - "integrity": "sha512-cqCz+S76qwZcPnddkLCjuNw9O8/lB+i1odjz2hpvpDogXLp0qSMs+Slh1gBjB5V4feUyBHav/550Mr3FeTdmnA==", + "version": "26.4.0", + "resolved": "https://registry.npmjs.org/jest-runtime/-/jest-runtime-26.4.0.tgz", + "integrity": "sha512-1fjZgGpkyQBUTo59Vi19I4IcsBwzY6uwVFNjUmR06iIi3XRErkY28yimi4IUDRrofQErqcDEw2n3DF9WmQ6vEg==", "dev": true, "requires": { "@jest/console": "^26.3.0", "@jest/environment": "^26.3.0", "@jest/fake-timers": "^26.3.0", - "@jest/globals": "^26.3.0", + "@jest/globals": "^26.4.0", "@jest/source-map": "^26.3.0", "@jest/test-result": "^26.3.0", "@jest/transform": "^26.3.0", @@ -8633,15 +8607,15 @@ "exit": "^0.1.2", "glob": "^7.1.3", "graceful-fs": "^4.2.4", - "jest-config": "^26.3.0", + "jest-config": "^26.4.0", "jest-haste-map": "^26.3.0", "jest-message-util": "^26.3.0", "jest-mock": "^26.3.0", "jest-regex-util": "^26.0.0", - "jest-resolve": "^26.3.0", - "jest-snapshot": "^26.3.0", + "jest-resolve": "^26.4.0", + "jest-snapshot": "^26.4.0", "jest-util": "^26.3.0", - "jest-validate": "^26.3.0", + "jest-validate": "^26.4.0", "slash": "^3.0.0", "strip-bom": "^4.0.0", "yargs": "^15.3.1" @@ -8722,25 +8696,25 @@ } }, "jest-snapshot": { - "version": "26.3.0", - "resolved": "https://registry.npmjs.org/jest-snapshot/-/jest-snapshot-26.3.0.tgz", - "integrity": "sha512-tHVUIeOTN/0SZN2ZjBZHzPG5txs/6uEQx2mwjxIT7QRE7pddPLd8jktXthyIz6bV+3GKetWXSV4YAoPUQwrfMA==", + "version": "26.4.0", + "resolved": "https://registry.npmjs.org/jest-snapshot/-/jest-snapshot-26.4.0.tgz", + "integrity": "sha512-vFGmNGWHMBomrlOpheTMoqihymovuH3GqfmaEIWoPpsxUXyxT3IlbxI5I4m2vg0uv3HUJYg5JoGrkgMzVsAwCg==", "dev": true, "requires": { "@babel/types": "^7.0.0", "@jest/types": "^26.3.0", "@types/prettier": "^2.0.0", "chalk": "^4.0.0", - "expect": "^26.3.0", + "expect": "^26.4.0", "graceful-fs": "^4.2.4", - "jest-diff": "^26.3.0", + "jest-diff": "^26.4.0", "jest-get-type": "^26.3.0", "jest-haste-map": "^26.3.0", - "jest-matcher-utils": "^26.3.0", + "jest-matcher-utils": "^26.4.0", "jest-message-util": "^26.3.0", - "jest-resolve": "^26.3.0", + "jest-resolve": "^26.4.0", "natural-compare": "^1.4.0", - "pretty-format": "^26.3.0", + "pretty-format": "^26.4.0", "semver": "^7.3.2" }, "dependencies": { @@ -8912,9 +8886,9 @@ } }, "jest-validate": { - "version": "26.3.0", - "resolved": "https://registry.npmjs.org/jest-validate/-/jest-validate-26.3.0.tgz", - "integrity": "sha512-oIJWqkIdgh1Q1O7ku4kDGkQoFKUOtZyDMbfYs4DsBi6r+FDY37xKTyZ30nM8F6yGZfB72qc7XB+3qKRgokwoXg==", + "version": "26.4.0", + "resolved": "https://registry.npmjs.org/jest-validate/-/jest-validate-26.4.0.tgz", + "integrity": "sha512-t56Z/FRMrLP6mpmje7/YgHy0wOzcuc6i3LBXz6kjmsUWYN62OuMdC86Vg9/dX59SvyitSqqegOrx+h7BkNXeaQ==", "dev": true, "requires": { "@jest/types": "^26.3.0", @@ -8922,7 +8896,7 @@ "chalk": "^4.0.0", "jest-get-type": "^26.3.0", "leven": "^3.1.0", - "pretty-format": "^26.3.0" + "pretty-format": "^26.4.0" }, "dependencies": { "ansi-styles": { @@ -9385,9 +9359,9 @@ } }, "get-stream": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.1.0.tgz", - "integrity": "sha512-EXr1FOzrzTfGeL0gQdeFEvOMm2mzMOglyiOXSTpPC+iAjAKftbr3jpCMWynogwYnM+eSj9sHGc6wjIcDvYiygw==", + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.2.0.tgz", + "integrity": "sha512-nBF+F1rAZVCu/p7rjzgA+Yb4lfYXrpl7a6VmJrU8wF9I1CKvP/QwPNZHnOlwbTkY6dvtFIzFMSyQXbLoTQPRpA==", "dev": true, "requires": { "pump": "^3.0.0" @@ -9493,9 +9467,9 @@ "dev": true }, "listr2": { - "version": "2.5.1", - "resolved": "https://registry.npmjs.org/listr2/-/listr2-2.5.1.tgz", - "integrity": "sha512-qkNRW70SwfwWLD/eiaTf2tfgWT/ZvjmMsnEFJOCzac0cjcc8rYHDBr1eQhRxopj6lZO7Oa5sS/pZzS6q+BsX+w==", + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/listr2/-/listr2-2.6.0.tgz", + "integrity": "sha512-nwmqTJYQQ+AsKb4fCXH/6/UmLCEDL1jkRAdSn9M6cEUzoRGrs33YD/3N86gAZQnGZ6hxV18XSdlBcJ1GTmetJA==", "dev": true, "requires": { "chalk": "^4.1.0", @@ -9626,9 +9600,9 @@ } }, "lodash": { - "version": "4.17.19", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.19.tgz", - "integrity": "sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ==", + "version": "4.17.20", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz", + "integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==", "dev": true }, "lodash._reinterpolate": { @@ -10053,9 +10027,9 @@ } }, "minizlib": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/minizlib/-/minizlib-2.1.0.tgz", - "integrity": "sha512-EzTZN/fjSvifSX0SlqUERCN39o6T40AMarPbv0MrarSFtIITCBh7bi+dU8nxGFHuqs9jdIAeoYoKuQAAASsPPA==", + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/minizlib/-/minizlib-2.1.2.tgz", + "integrity": "sha512-bAxsR8BVfj60DWXHE3u30oHzfl4G7khkSuPW+qvpd7jFRHm7dLxOjUk1EHACJ/hxLY8phGJ0YhYHZo7jil7Qdg==", "requires": { "minipass": "^3.0.0", "yallist": "^4.0.0" @@ -10615,9 +10589,9 @@ } }, "onetime": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.0.tgz", - "integrity": "sha512-5NcSkPHhwTVFIQN+TUqXoS5+dlElHXdpAWu9I0HP20YOtIi+aZ0Ct82jdlILDxjLEAWwvm+qj1m6aEtsDVmm6Q==", + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.2.tgz", + "integrity": "sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==", "dev": true, "requires": { "mimic-fn": "^2.1.0" @@ -10717,14 +10691,13 @@ } }, "parse-asn1": { - "version": "5.1.5", - "resolved": "https://registry.npmjs.org/parse-asn1/-/parse-asn1-5.1.5.tgz", - "integrity": "sha512-jkMYn1dcJqF6d5CpU689bq7w/b5ALS9ROVSpQDPrZsqqesUJii9qutvoT5ltGedNXMO2e16YUWIghG9KxaViTQ==", + "version": "5.1.6", + "resolved": "https://registry.npmjs.org/parse-asn1/-/parse-asn1-5.1.6.tgz", + "integrity": "sha512-RnZRo1EPU6JBnra2vGHj0yhp6ebyjBZpmUCLHWiFhxlzvBCCpAuZ7elsBp1PVAbQN0/04VD/19rfzlBSwLstMw==", "dev": true, "requires": { - "asn1.js": "^4.0.0", + "asn1.js": "^5.2.0", "browserify-aes": "^1.0.0", - "create-hash": "^1.1.0", "evp_bytestokey": "^1.0.0", "pbkdf2": "^3.0.3", "safe-buffer": "^5.1.1" @@ -10933,9 +10906,9 @@ "dev": true }, "pretty-format": { - "version": "26.3.0", - "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-26.3.0.tgz", - "integrity": "sha512-24kRw4C2Ok8+SHquydTZZCZPF2fvANI7rChGs8sNu784+1Jkq5jVFMvNAJSLuLy6XUcP3Fnw+SscLIQag/CG8Q==", + "version": "26.4.0", + "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-26.4.0.tgz", + "integrity": "sha512-mEEwwpCseqrUtuMbrJG4b824877pM5xald3AkilJ47Po2YLr97/siejYQHqj2oDQBeJNbu+Q0qUuekJ8F0NAPg==", "dev": true, "requires": { "@jest/types": "^26.3.0", @@ -12080,16 +12053,16 @@ } }, "standard-version": { - "version": "8.0.2", - "resolved": "https://registry.npmjs.org/standard-version/-/standard-version-8.0.2.tgz", - "integrity": "sha512-L8X9KFq2SmVmaeZgUmWHFJMOsEWpjgFAwqic6yIIoveM1kdw1vH4Io03WWxUDjypjGqGU6qUtcJoR8UvOv5w3g==", + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/standard-version/-/standard-version-9.0.0.tgz", + "integrity": "sha512-eRR04IscMP3xW9MJTykwz13HFNYs8jS33AGuDiBKgfo5YrO0qX0Nxb4rjupVwT5HDYL/aR+MBEVLjlmVFmFEDQ==", "dev": true, "requires": { "chalk": "^2.4.2", - "conventional-changelog": "3.1.21", + "conventional-changelog": "3.1.23", "conventional-changelog-config-spec": "2.1.0", - "conventional-changelog-conventionalcommits": "4.3.0", - "conventional-recommended-bump": "6.0.9", + "conventional-changelog-conventionalcommits": "4.4.0", + "conventional-recommended-bump": "6.0.10", "detect-indent": "^6.0.0", "detect-newline": "^3.1.0", "dotgitignore": "^2.1.0", @@ -12424,14 +12397,14 @@ "dev": true }, "tar": { - "version": "6.0.2", - "resolved": "https://registry.npmjs.org/tar/-/tar-6.0.2.tgz", - "integrity": "sha512-Glo3jkRtPcvpDlAs/0+hozav78yoXKFr+c4wgw62NNMO3oo4AaJdCo21Uu7lcwr55h39W2XD1LMERc64wtbItg==", + "version": "6.0.5", + "resolved": "https://registry.npmjs.org/tar/-/tar-6.0.5.tgz", + "integrity": "sha512-0b4HOimQHj9nXNEAA7zWwMM91Zhhba3pspja6sQbgTpynOJf+bkjBnfybNYzbpLbnwXnbyB4LOREvlyXLkCHSg==", "requires": { "chownr": "^2.0.0", "fs-minipass": "^2.0.0", "minipass": "^3.0.0", - "minizlib": "^2.1.0", + "minizlib": "^2.1.1", "mkdirp": "^1.0.3", "yallist": "^4.0.0" } diff --git a/package.json b/package.json index 890a30b..8550870 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "compression-webpack-plugin", - "version": "4.0.1", + "version": "5.0.0", "description": "Prepare compressed versions of assets to serve them with Content-Encoding", "license": "MIT", "repository": "webpack-contrib/compression-webpack-plugin", @@ -52,7 +52,7 @@ "@babel/core": "^7.11.1", "@babel/preset-env": "^7.11.0", "@commitlint/cli": "^9.1.2", - "@commitlint/config-conventional": "^9.1.1", + "@commitlint/config-conventional": "^10.0.0", "@gfx/zopfli": "^1.0.15", "@webpack-contrib/defaults": "^6.3.0", "@webpack-contrib/eslint-config-webpack": "^3.0.0", @@ -60,17 +60,17 @@ "cross-env": "^7.0.2", "del": "^5.1.0", "del-cli": "^3.0.1", - "eslint": "^7.6.0", + "eslint": "^7.7.0", "eslint-config-prettier": "^6.11.0", "eslint-plugin-import": "^2.22.0", "file-loader": "^6.0.0", "husky": "^4.2.5", - "jest": "^26.3.0", + "jest": "^26.4.0", "lint-staged": "^10.2.11", "memfs": "^3.2.0", "npm-run-all": "^4.1.5", "prettier": "^2.0.5", - "standard-version": "^8.0.2", + "standard-version": "^9.0.0", "webpack": "^4.44.1" }, "keywords": [ diff --git a/src/Webpack4Cache.js b/src/Webpack4Cache.js index 7d9776c..0c5b059 100644 --- a/src/Webpack4Cache.js +++ b/src/Webpack4Cache.js @@ -20,20 +20,27 @@ export default class Webpack4Cache { return Boolean(this.cacheDir); } - get(task) { + async get(task) { // eslint-disable-next-line no-param-reassign task.cacheIdent = task.cacheIdent || serialize(task.cacheKeys); - return cacache.get(this.cacheDir, task.cacheIdent).then(({ data }) => { - const result = JSON.parse(data); + let cachedResult; - result.output = Buffer.from(result.output); + try { + cachedResult = await cacache.get(this.cacheDir, task.cacheIdent); + } catch (ignoreError) { + // eslint-disable-next-line no-undefined + return undefined; + } - return result; - }); + return Buffer.from(JSON.parse(cachedResult.data).data); } - store(task, data) { - return cacache.put(this.cacheDir, task.cacheIdent, JSON.stringify(data)); + async store(task) { + return cacache.put( + this.cacheDir, + task.cacheIdent, + JSON.stringify(task.output) + ); } } diff --git a/src/Webpack5Cache.js b/src/Webpack5Cache.js index 7f3d8a6..b48ca37 100644 --- a/src/Webpack5Cache.js +++ b/src/Webpack5Cache.js @@ -1,74 +1,22 @@ -// eslint-disable-next-line import/extensions,import/no-unresolved -import getLazyHashedEtag from 'webpack/lib/cache/getLazyHashedEtag'; - -import { util } from 'webpack'; - export default class Cache { // eslint-disable-next-line no-unused-vars constructor(compilation, ignored) { - this.compilation = compilation; + this.cache = compilation.getCache('CompressionWebpackPlugin'); } + // eslint-disable-next-line class-methods-use-this isEnabled() { - return Boolean(this.compilation.cache); - } - - createCacheIdent(task) { - const { - outputOptions: { hashSalt, hashDigest, hashDigestLength, hashFunction }, - } = this.compilation; - - const hash = util.createHash(hashFunction); - - if (hashSalt) { - hash.update(hashSalt); - } - - hash.update(JSON.stringify(task.cacheKeys)); - - const digest = hash.digest(hashDigest); - const cacheKeys = digest.substr(0, hashDigestLength); - - return `${this.compilation.compilerPath}/CompressionPlugin/${cacheKeys}/${task.filename}`; + return true; } - get(task) { - // eslint-disable-next-line no-param-reassign - task.cacheIdent = task.cacheIdent || this.createCacheIdent(task); + async get(task) { // eslint-disable-next-line no-param-reassign - task.cacheETag = task.cacheETag || getLazyHashedEtag(task.assetSource); + task.eTag = task.eTag || this.cache.getLazyHashedEtag(task.assetSource); - return new Promise((resolve, reject) => { - this.compilation.cache.get( - task.cacheIdent, - task.cacheETag, - (err, result) => { - if (err) { - reject(err); - } else if (result) { - resolve(result); - } else { - reject(); - } - } - ); - }); + return this.cache.getPromise(task.assetName, task.eTag); } - store(task, data) { - return new Promise((resolve, reject) => { - this.compilation.cache.store( - task.cacheIdent, - task.cacheETag, - data, - (err) => { - if (err) { - reject(err); - } else { - resolve(data); - } - } - ); - }); + async store(task) { + return this.cache.storePromise(task.assetName, task.eTag, task.output); } } diff --git a/src/index.js b/src/index.js index 226ddee..7e6fe15 100644 --- a/src/index.js +++ b/src/index.js @@ -1,6 +1,6 @@ /* -MIT License http://www.opensource.org/licenses/mit-license.php -Author Tobias Koppers @sokra + MIT License http://www.opensource.org/licenses/mit-license.php + Author Tobias Koppers @sokra */ import crypto from 'crypto'; @@ -11,8 +11,6 @@ import RawSource from 'webpack-sources/lib/RawSource'; import { ModuleFilenameHelpers, version as webpackVersion } from 'webpack'; import validateOptions from 'schema-utils'; -import pkg from '../package.json'; - import schema from './options.json'; class CompressionPlugin { @@ -29,7 +27,7 @@ class CompressionPlugin { cache = true, algorithm = 'gzip', compressionOptions = {}, - filename = '[path].gz[query]', + filename = '[path].gz', threshold = 0, minRatio = 0.8, deleteOriginalAssets = false, @@ -59,165 +57,232 @@ class CompressionPlugin { if (!this.algorithm) { throw new Error( - `Algorithm "${this.options.algorithm}" is not found in zlib` + `Algorithm "${this.options.algorithm}" is not found in "zlib"` ); } - const defaultCompressionOptions = { level: 9 }; - - // TODO change this behaviour in the next major release this.compressionOptions = { - ...defaultCompressionOptions, + ...{ level: 9 }, ...this.compressionOptions, }; } } - *taskGenerator(compiler, compilation, assetsCache, assetName) { - const assetSource = compilation.assets[assetName]; + static interpolateName(originalFilename, filename) { + const parse = url.parse(originalFilename); + const { pathname } = parse; + const { dir, name, ext } = path.parse(pathname); + const info = { + file: originalFilename, + path: pathname, + dir: dir ? `${dir}/` : '', + name, + ext, + query: parse.query ? `?${parse.query}` : '', + }; - let input = assetSource.source(); + return typeof filename === 'function' + ? filename(info) + : filename.replace( + /\[(file|path|query|dir|name|ext)]/g, + (p0, p1) => info[p1] + ); + } - if (!Buffer.isBuffer(input)) { - input = Buffer.from(input); + // eslint-disable-next-line consistent-return + static getAsset(compilation, name) { + // New API + if (compilation.getAsset) { + return compilation.getAsset(name); } - // Do not emit cached assets in watch mode - if (assetsCache.get(assetSource)) { - yield false; + if (compilation.assets[name]) { + return { name, source: compilation.assets[name], info: {} }; } + } - const originalSize = input.length; + static emitAsset(compilation, name, source, assetInfo) { + // New API + if (compilation.emitAsset) { + compilation.emitAsset(name, source, assetInfo); + } - if (originalSize < this.options.threshold) { - yield false; + // eslint-disable-next-line no-param-reassign + compilation.assets[name] = source; + } + + static updateAsset(compilation, name, newSource, assetInfo) { + // New API + if (compilation.updateAsset) { + compilation.updateAsset(name, newSource, assetInfo); } - const callback = (taskResult) => { - if (taskResult.error) { - compilation.errors.push(taskResult.error); + // eslint-disable-next-line no-param-reassign + compilation.assets[name] = newSource; + } - return; - } + static deleteAsset(compilation, name) { + // New API + if (compilation.deleteAsset) { + compilation.deleteAsset(name); + } - const { output } = taskResult; + // eslint-disable-next-line no-param-reassign + delete compilation.assets[name]; + } - if (output.length / originalSize > this.options.minRatio) { - return; - } + compress(input) { + return new Promise((resolve, reject) => { + const { algorithm, compressionOptions } = this; - const parse = url.parse(assetName); - const { pathname } = parse; - const { dir, name, ext } = path.parse(pathname); - const info = { - file: assetName, - path: pathname, - dir: dir ? `${dir}/` : '', - name, - ext, - query: parse.query ? `?${parse.query}` : '', - }; + algorithm(input, compressionOptions, (error, result) => { + if (error) { + return reject(error); + } - const newAssetName = - typeof this.options.filename === 'function' - ? this.options.filename(info) - : this.options.filename.replace( - /\[(file|path|query|dir|name|ext)]/g, - (p0, p1) => info[p1] - ); + return resolve(result); + }); + }); + } - const compressedSource = new RawSource(output); + *getTask(compilation, assetName) { + const { source: assetSource, info: assetInfo } = CompressionPlugin.getAsset( + compilation, + assetName + ); - // eslint-disable-next-line no-param-reassign - compilation.assets[newAssetName] = compressedSource; + if (assetInfo.compressed) { + yield false; + } + + let relatedName; + + if (typeof this.options.algorithm === 'function') { + let filenameForRelatedName = this.options.filename; - assetsCache.set(assetSource, compressedSource); + const index = filenameForRelatedName.lastIndexOf('?'); - if (this.options.deleteOriginalAssets) { - // eslint-disable-next-line no-param-reassign - delete compilation.assets[assetName]; + if (index >= 0) { + filenameForRelatedName = filenameForRelatedName.substr(0, index); } - }; - const task = { - input, - filename: assetName, - // Invalidate cache after upgrade `zlib` module (built-in in `nodejs`) - cacheKeys: { node: process.version }, - callback, - }; + relatedName = `${path.extname(filenameForRelatedName).slice(1)}ed`; + } else { + relatedName = `${this.options.algorithm}ed`; + } + + if (assetInfo.related && assetInfo.related[relatedName]) { + yield false; + } + + let input = assetSource.source(); + + if (!Buffer.isBuffer(input)) { + input = Buffer.from(input); + } + + if (input.length < this.options.threshold) { + yield false; + } + + const task = { assetName, assetSource, assetInfo, input, relatedName }; if (CompressionPlugin.isWebpack4()) { task.cacheKeys = { - filename: assetName, - 'compression-webpack-plugin': pkg.version, - 'compression-webpack-plugin-options': this.options, + nodeVersion: process.version, + // eslint-disable-next-line global-require + 'compression-webpack-plugin': require('../package.json').version, + algorithm: this.algorithm, + originalAlgorithm: this.options.algorithm, + compressionOptions: this.compressionOptions, + assetName, contentHash: crypto.createHash('md4').update(input).digest('hex'), - ...task.cacheKeys, }; - } else { - task.assetSource = assetSource; } yield task; } - compress(input) { - return new Promise((resolve, reject) => { - const { algorithm, compressionOptions } = this; + afterTask(compilation, task, weakCache) { + const { output, input } = task; - algorithm(input, compressionOptions, (error, result) => { - if (error) { - return reject(error); - } + if (output.length / input.length > this.options.minRatio) { + return; + } - return resolve(result); - }); + const { assetSource, assetName } = task; + + let weakOutput = weakCache.get(assetSource); + + if (!weakOutput) { + weakOutput = new RawSource(output); + + weakCache.set(assetSource, weakOutput); + } + + const newAssetName = CompressionPlugin.interpolateName( + assetName, + this.options.filename + ); + + CompressionPlugin.emitAsset(compilation, newAssetName, weakOutput, { + compressed: true, }); + + if (this.options.deleteOriginalAssets) { + // eslint-disable-next-line no-param-reassign + CompressionPlugin.deleteAsset(compilation, assetName); + } else { + CompressionPlugin.updateAsset(compilation, assetName, assetSource, { + related: { [task.relatedName]: newAssetName }, + }); + } } - async runTasks(assetNames, getTaskForAsset, cache) { + async runTasks(compilation, assetNames, CacheEngine, weakCache) { const scheduledTasks = []; + const cache = new CacheEngine(compilation, { + cache: this.options.cache, + }); for (const assetName of assetNames) { const enqueue = async (task) => { - let taskResult; - try { - const output = await this.compress(task.input); - - taskResult = { output }; + // eslint-disable-next-line no-param-reassign + task.output = await this.compress(task.input); } catch (error) { - taskResult = { error }; - } + compilation.errors.push(error); - if (cache.isEnabled() && !taskResult.error) { - await cache.store(task, taskResult); + return; } - task.callback(taskResult); + if (cache.isEnabled()) { + await cache.store(task); + } - return taskResult; + this.afterTask(compilation, task, weakCache); }; scheduledTasks.push( (async () => { - const task = getTaskForAsset(assetName).next().value; + const task = this.getTask(compilation, assetName).next().value; if (!task) { return Promise.resolve(); } if (cache.isEnabled()) { - let taskResult; - try { - taskResult = await cache.get(task); + task.output = await cache.get(task); } catch (ignoreError) { return enqueue(task); } - task.callback(taskResult); + if (!task.output) { + return enqueue(task); + } + + this.afterTask(compilation, task, weakCache); return Promise.resolve(); } @@ -235,46 +300,64 @@ class CompressionPlugin { } apply(compiler) { + const pluginName = this.constructor.name; const matchObject = ModuleFilenameHelpers.matchObject.bind( // eslint-disable-next-line no-undefined undefined, this.options ); - const assetsCache = new WeakMap(); + const weakCache = new WeakMap(); + const compressionFn = async (compilation, CacheEngine, assets) => { + const assetNames = Object.keys( + typeof assets === 'undefined' ? compilation.assets : assets + ).filter((assetName) => matchObject(assetName)); - compiler.hooks.emit.tapPromise( - { name: 'CompressionPlugin' }, - async (compilation) => { - const { assets } = compilation; + if (assetNames.length === 0) { + return Promise.resolve(); + } - const assetNames = Object.keys(assets).filter((assetName) => - matchObject(assetName) - ); + await this.runTasks(compilation, assetNames, CacheEngine, weakCache); - if (assetNames.length === 0) { - return Promise.resolve(); - } + return Promise.resolve(); + }; - const getTaskForAsset = this.taskGenerator.bind( - this, - compiler, - compilation, - assetsCache - ); - const CacheEngine = CompressionPlugin.isWebpack4() - ? // eslint-disable-next-line global-require - require('./Webpack4Cache').default - : // eslint-disable-next-line global-require - require('./Webpack5Cache').default; - const cache = new CacheEngine(compilation, { - cache: this.options.cache, - }); + if (CompressionPlugin.isWebpack4()) { + // eslint-disable-next-line global-require + const CacheEngine = require('./Webpack4Cache').default; - await this.runTasks(assetNames, getTaskForAsset, cache); + compiler.hooks.emit.tapPromise( + { name: pluginName }, + // eslint-disable-next-line no-undefined + (compilation) => compressionFn(compilation, CacheEngine) + ); + } else { + // eslint-disable-next-line global-require + const CacheEngine = require('./Webpack5Cache').default; + + compiler.hooks.compilation.tap(pluginName, (compilation) => { + // eslint-disable-next-line global-require + const Compilation = require('webpack/lib/Compilation'); + + compilation.hooks.processAssets.tapPromise( + { + name: pluginName, + stage: Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER, + }, + (assets) => compressionFn(compilation, CacheEngine, assets) + ); - return Promise.resolve(); - } - ); + compilation.hooks.statsPrinter.tap(pluginName, (stats) => { + stats.hooks.print + .for('asset.info.compressed') + .tap( + 'compression-webpack-plugin', + (minimized, { green, formatFlag }) => + // eslint-disable-next-line no-undefined + minimized ? green(formatFlag('compressed')) : undefined + ); + }); + }); + } } } diff --git a/test/CompressionPlugin.test.js b/test/CompressionPlugin.test.js index 8f5207a..39097f7 100644 --- a/test/CompressionPlugin.test.js +++ b/test/CompressionPlugin.test.js @@ -1,11 +1,17 @@ +import zlib from 'zlib'; + +import webpack from 'webpack'; + import CompressionPlugin from '../src/index'; import { compile, + CopyPluginWithAssetInfo, getAssetsNameAndSize, getCompiler, getErrors, getWarnings, + readAsset, removeCache, } from './helpers/index'; @@ -15,6 +21,8 @@ describe('CompressionPlugin', () => { }); it('should work', async () => { + expect.assertions(6); + const compiler = getCompiler( './entry.js', {}, @@ -30,12 +38,140 @@ describe('CompressionPlugin', () => { new CompressionPlugin().apply(compiler); const stats = await compile(compiler); + const { assets, assetsInfo } = stats.compilation; + + for (const assetName of Object.keys(assets)) { + const info = assetsInfo.get(assetName); + + if (!info.related) { + // eslint-disable-next-line no-continue + continue; + } + + const originalBuffer = readAsset(assetName, compiler, stats); + const gzipedBuffer = readAsset(info.related.gziped, compiler, stats); + + expect(zlib.gunzipSync(gzipedBuffer).equals(originalBuffer)).toBe(true); + } expect(getAssetsNameAndSize(stats)).toMatchSnapshot('assets'); expect(getWarnings(stats)).toMatchSnapshot('errors'); expect(getErrors(stats)).toMatchSnapshot('warnings'); }); + it('should work with assets info', async () => { + const compiler = getCompiler( + './entry.js', + {}, + { + devtool: 'source-map', + output: { + path: `${__dirname}/dist`, + filename: '[name].js?var=[hash]', + chunkFilename: '[id].[name].js?ver=[hash]', + }, + } + ); + + new CompressionPlugin().apply(compiler); + new CopyPluginWithAssetInfo().apply(compiler); + + const stats = await compile(compiler); + + expect(getAssetsNameAndSize(stats, true)).toMatchSnapshot('assets'); + expect(getWarnings(stats)).toMatchSnapshot('errors'); + expect(getErrors(stats)).toMatchSnapshot('warnings'); + }); + + it('should work child compilations', async () => { + const gzipSpy = jest.spyOn(zlib, 'gzip'); + const compiler = getCompiler( + './entry.js', + {}, + { + output: { + path: `${__dirname}/dist`, + filename: '[name].js?var=[hash]', + chunkFilename: '[id].[name].js?ver=[hash]', + }, + module: { + rules: [ + { + test: /number\.js$/i, + rules: [ + { + loader: require.resolve( + './helpers/loader-with-child-compilation.js' + ), + }, + ], + }, + { + test: /\.(png|jpg|gif|svg)$/i, + rules: [ + { + loader: 'file-loader', + }, + ], + }, + ], + }, + } + ); + + new CompressionPlugin().apply(compiler); + + const stats = await compile(compiler); + + expect(gzipSpy).toHaveBeenCalledTimes(5); + expect(getAssetsNameAndSize(stats, true)).toMatchSnapshot('assets'); + expect(getWarnings(stats)).toMatchSnapshot('errors'); + expect(getErrors(stats)).toMatchSnapshot('warnings'); + + gzipSpy.mockRestore(); + }); + + it('should work with multiple plugins', async () => { + const compiler = getCompiler( + './entry.js', + {}, + { + output: { + path: `${__dirname}/dist`, + filename: '[name].js?var=[hash]', + chunkFilename: '[id].[name].js?ver=[hash]', + }, + } + ); + + new CompressionPlugin({ + algorithm: 'gzip', + filename: '[path].gz', + }).apply(compiler); + new CompressionPlugin({ + algorithm: 'brotliCompress', + filename: '[path].br', + }).apply(compiler); + new CompressionPlugin({ + algorithm: (input, options, callback) => { + return callback(input); + }, + filename: '[path].compress', + }).apply(compiler); + new CompressionPlugin({ + algorithm: (input, options, callback) => { + return callback(input); + }, + filename: '[path].custom?foo=bar#hash', + }).apply(compiler); + + const stats = await compile(compiler); + + expect(getAssetsNameAndSize(stats, true)).toMatchSnapshot('assets'); + expect(getWarnings(stats)).toMatchSnapshot('errors'); + expect(getErrors(stats)).toMatchSnapshot('warnings'); + }); + it('should work in watch mode', async () => { const compiler = getCompiler('./entry.js'); @@ -43,6 +179,16 @@ describe('CompressionPlugin', () => { const stats = await compile(compiler); + if (webpack.version[0] === '4') { + expect( + Object.keys(stats.compilation.assets).filter( + (assetName) => stats.compilation.assets[assetName].emitted + ).length + ).toBe(7); + } else { + expect(stats.compilation.emittedAssets.size).toBe(7); + } + expect(getAssetsNameAndSize(stats)).toMatchSnapshot('assets'); expect(getWarnings(stats)).toMatchSnapshot('errors'); expect(getErrors(stats)).toMatchSnapshot('warnings'); @@ -50,6 +196,16 @@ describe('CompressionPlugin', () => { await new Promise(async (resolve) => { const newStats = await compile(compiler); + if (webpack.version[0] === '4') { + expect( + Object.keys(newStats.compilation.assets).filter( + (assetName) => newStats.compilation.assets[assetName].emitted + ).length + ).toBe(0); + } else { + expect(newStats.compilation.emittedAssets.size).toBe(0); + } + expect(getAssetsNameAndSize(newStats)).toMatchSnapshot('assets'); expect(getWarnings(newStats)).toMatchSnapshot('errors'); expect(getErrors(newStats)).toMatchSnapshot('warnings'); diff --git a/test/__snapshots__/CompressionPlugin.test.js.snap.webpack4 b/test/__snapshots__/CompressionPlugin.test.js.snap.webpack4 index d16d425..dd586a7 100644 --- a/test/__snapshots__/CompressionPlugin.test.js.snap.webpack4 +++ b/test/__snapshots__/CompressionPlugin.test.js.snap.webpack4 @@ -1,5 +1,86 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`CompressionPlugin should work child compilations: assets 1`] = ` +Array [ + Array [ + "09a1a1112c577c2794359715edfcb5ac.png", + 78117, + Object {}, + ], + Array [ + "23fc1d3ac606d117e05a140e0de79806.svg", + 672, + Object { + "related": Object { + "gziped": "23fc1d3ac606d117e05a140e0de79806.svg.gz", + }, + }, + ], + Array [ + "23fc1d3ac606d117e05a140e0de79806.svg.gz", + 393, + Object { + "compressed": true, + }, + ], + Array [ + "async.async.js.gz", + 171, + Object { + "compressed": true, + }, + ], + Array [ + "async.async.js?ver=810493800e70254b803c", + 249, + Object { + "immutable": true, + "related": Object { + "gziped": "async.async.js.gz", + }, + }, + ], + Array [ + "copied.js", + 400, + Object { + "copied": true, + "related": Object { + "gziped": "copied.js.gz", + }, + }, + ], + Array [ + "copied.js.gz", + 29, + Object { + "compressed": true, + }, + ], + Array [ + "main.js.gz", + 3001, + Object { + "compressed": true, + }, + ], + Array [ + "main.js?var=810493800e70254b803c", + 11627, + Object { + "immutable": true, + "related": Object { + "gziped": "main.js.gz", + }, + }, + ], +] +`; + +exports[`CompressionPlugin should work child compilations: errors 1`] = `Array []`; + +exports[`CompressionPlugin should work child compilations: warnings 1`] = `Array []`; + exports[`CompressionPlugin should work in watch mode: assets 1`] = ` Array [ Array [ @@ -23,12 +104,12 @@ Array [ 171, ], Array [ - "main.8de5b7ad6e2fdef99b99.js", - 11127, + "main.82c6786e32f9c77b44ef.js", + 11645, ], Array [ - "main.8de5b7ad6e2fdef99b99.js.gz", - 2954, + "main.82c6786e32f9c77b44ef.js.gz", + 3000, ], ] `; @@ -43,13 +124,25 @@ Array [ "23fc1d3ac606d117e05a140e0de79806.svg", 672, ], + Array [ + "23fc1d3ac606d117e05a140e0de79806.svg.gz", + 393, + ], Array [ "async.async.dcbdb1dd40763448b635.js", 249, ], Array [ - "main.8de5b7ad6e2fdef99b99.js", - 11127, + "async.async.dcbdb1dd40763448b635.js.gz", + 171, + ], + Array [ + "main.82c6786e32f9c77b44ef.js", + 11645, + ], + Array [ + "main.82c6786e32f9c77b44ef.js.gz", + 3000, ], ] `; @@ -62,6 +155,213 @@ exports[`CompressionPlugin should work in watch mode: warnings 1`] = `Array []`; exports[`CompressionPlugin should work in watch mode: warnings 2`] = `Array []`; +exports[`CompressionPlugin should work with assets info: assets 1`] = ` +Array [ + Array [ + "09a1a1112c577c2794359715edfcb5ac.png", + 78117, + Object {}, + ], + Array [ + "23fc1d3ac606d117e05a140e0de79806.svg", + 672, + Object { + "related": Object { + "gziped": "23fc1d3ac606d117e05a140e0de79806.svg.gz", + }, + }, + ], + Array [ + "23fc1d3ac606d117e05a140e0de79806.svg.gz", + 393, + Object { + "compressed": true, + }, + ], + Array [ + "async.async.js.gz", + 220, + Object { + "compressed": true, + }, + ], + Array [ + "async.async.js.map?ver=dc74724f7b13a2de5a20", + 136, + Object { + "development": true, + }, + ], + Array [ + "async.async.js?ver=dc74724f7b13a2de5a20", + 314, + Object { + "immutable": true, + "related": Object { + "gziped": "async.async.js.gz", + }, + }, + ], + Array [ + "copied.js", + 400, + Object { + "copied": true, + "related": Object { + "gziped": "copied.js.gz", + }, + }, + ], + Array [ + "copied.js.gz", + 29, + Object { + "compressed": true, + }, + ], + Array [ + "main.js.gz", + 3035, + Object { + "compressed": true, + }, + ], + Array [ + "main.js.map.gz", + 3134, + Object { + "compressed": true, + }, + ], + Array [ + "main.js.map?var=dc74724f7b13a2de5a20", + 10264, + Object { + "development": true, + "related": Object { + "gziped": "main.js.map.gz", + }, + }, + ], + Array [ + "main.js?var=dc74724f7b13a2de5a20", + 11688, + Object { + "immutable": true, + "related": Object { + "gziped": "main.js.gz", + }, + }, + ], +] +`; + +exports[`CompressionPlugin should work with assets info: errors 1`] = `Array []`; + +exports[`CompressionPlugin should work with assets info: warnings 1`] = `Array []`; + +exports[`CompressionPlugin should work with multiple plugins: assets 1`] = ` +Array [ + Array [ + "09a1a1112c577c2794359715edfcb5ac.png", + 78117, + Object {}, + ], + Array [ + "23fc1d3ac606d117e05a140e0de79806.svg", + 672, + Object { + "related": Object { + "brotliCompressed": "23fc1d3ac606d117e05a140e0de79806.svg.br", + }, + }, + ], + Array [ + "23fc1d3ac606d117e05a140e0de79806.svg.br", + 363, + Object { + "compressed": true, + }, + ], + Array [ + "23fc1d3ac606d117e05a140e0de79806.svg.gz", + 393, + Object { + "compressed": true, + }, + ], + Array [ + "async.async.js.br", + 141, + Object { + "compressed": true, + }, + ], + Array [ + "async.async.js.gz", + 171, + Object { + "compressed": true, + }, + ], + Array [ + "async.async.js?ver=dc74724f7b13a2de5a20", + 249, + Object { + "immutable": true, + "related": Object { + "brotliCompressed": "async.async.js.br", + }, + }, + ], + Array [ + "main.js.br", + 2588, + Object { + "compressed": true, + }, + ], + Array [ + "main.js.gz", + 3002, + Object { + "compressed": true, + }, + ], + Array [ + "main.js?var=dc74724f7b13a2de5a20", + 11630, + Object { + "immutable": true, + "related": Object { + "brotliCompressed": "main.js.br", + }, + }, + ], +] +`; + +exports[`CompressionPlugin should work with multiple plugins: errors 1`] = `Array []`; + +exports[`CompressionPlugin should work with multiple plugins: warnings 1`] = ` +Array [ + "�PNG +", + "icon", + "(window[\\"webpackJsonp\\"] = window[\\"webpackJsonp\\"] || []).push([[\\"async\\"],{ +", + "/******/ (function(modules) { // webpackBootstrap +/******/ // install a JSONP callback for chunk loading", + "�PNG +", + "icon", + "(window[\\"webpackJsonp\\"] = window[\\"webpackJsonp\\"] || []).push([[\\"async\\"],{ +", + "/******/ (function(modules) { // webpackBootstrap +/******/ // install a JSONP callback for chunk loading", +] +`; + exports[`CompressionPlugin should work: assets 1`] = ` Array [ Array [ @@ -77,20 +377,20 @@ Array [ 393, ], Array [ - "async.async.js.gz?ver=df8e3f469c7c96726fb9", + "async.async.js.gz", 171, ], Array [ - "async.async.js?ver=df8e3f469c7c96726fb9", + "async.async.js?ver=dc74724f7b13a2de5a20", 249, ], Array [ - "main.js.gz?var=df8e3f469c7c96726fb9", - 2958, + "main.js.gz", + 3002, ], Array [ - "main.js?var=df8e3f469c7c96726fb9", - 11112, + "main.js?var=dc74724f7b13a2de5a20", + 11630, ], ] `; diff --git a/test/__snapshots__/CompressionPlugin.test.js.snap.webpack5 b/test/__snapshots__/CompressionPlugin.test.js.snap.webpack5 index fb0df45..87c2464 100644 --- a/test/__snapshots__/CompressionPlugin.test.js.snap.webpack5 +++ b/test/__snapshots__/CompressionPlugin.test.js.snap.webpack5 @@ -1,5 +1,96 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`CompressionPlugin should work child compilations: assets 1`] = ` +Array [ + Array [ + "09a1a1112c577c2794359715edfcb5ac.png", + 78117, + Object { + "size": 78117, + }, + ], + Array [ + "23fc1d3ac606d117e05a140e0de79806.svg", + 672, + Object { + "related": Object { + "gziped": "23fc1d3ac606d117e05a140e0de79806.svg.gz", + }, + "size": 672, + }, + ], + Array [ + "23fc1d3ac606d117e05a140e0de79806.svg.gz", + 393, + Object { + "compressed": true, + "size": 393, + }, + ], + Array [ + "async.async.js.gz", + 181, + Object { + "compressed": true, + "size": 181, + }, + ], + Array [ + "async.async.js?ver=73440247c3513e8f18d5", + 269, + Object { + "immutable": true, + "related": Object { + "gziped": "async.async.js.gz", + }, + "size": 269, + }, + ], + Array [ + "copied.js", + 400, + Object { + "copied": true, + "related": Object { + "gziped": "copied.js.gz", + }, + "size": 400, + }, + ], + Array [ + "copied.js.gz", + 29, + Object { + "compressed": true, + "size": 29, + }, + ], + Array [ + "main.js.gz", + 3584, + Object { + "compressed": true, + "size": 3584, + }, + ], + Array [ + "main.js?var=73440247c3513e8f18d5", + 15312, + Object { + "immutable": true, + "related": Object { + "gziped": "main.js.gz", + }, + "size": 15312, + }, + ], +] +`; + +exports[`CompressionPlugin should work child compilations: errors 1`] = `Array []`; + +exports[`CompressionPlugin should work child compilations: warnings 1`] = `Array []`; + exports[`CompressionPlugin should work in watch mode: assets 1`] = ` Array [ Array [ @@ -15,20 +106,20 @@ Array [ 393, ], Array [ - "async.async.915241b20821fb2958ef.js", + "async.async.81ea6697ed82fa2176bb.js", 269, ], Array [ - "async.async.915241b20821fb2958ef.js.gz", + "async.async.81ea6697ed82fa2176bb.js.gz", 181, ], Array [ - "main.1bf53bd04d76a915156e.js", - 14233, + "main.f1e836b35a2623bafe34.js", + 15156, ], Array [ - "main.1bf53bd04d76a915156e.js.gz", - 3500, + "main.f1e836b35a2623bafe34.js.gz", + 3556, ], ] `; @@ -44,12 +135,24 @@ Array [ 672, ], Array [ - "async.async.915241b20821fb2958ef.js", + "23fc1d3ac606d117e05a140e0de79806.svg.gz", + 393, + ], + Array [ + "async.async.81ea6697ed82fa2176bb.js", 269, ], Array [ - "main.1bf53bd04d76a915156e.js", - 14233, + "async.async.81ea6697ed82fa2176bb.js.gz", + 181, + ], + Array [ + "main.f1e836b35a2623bafe34.js", + 15156, + ], + Array [ + "main.f1e836b35a2623bafe34.js.gz", + 3556, ], ] `; @@ -62,6 +165,279 @@ exports[`CompressionPlugin should work in watch mode: warnings 1`] = `Array []`; exports[`CompressionPlugin should work in watch mode: warnings 2`] = `Array []`; +exports[`CompressionPlugin should work with assets info: assets 1`] = ` +Array [ + Array [ + "09a1a1112c577c2794359715edfcb5ac.png", + 78117, + Object { + "size": 78117, + }, + ], + Array [ + "23fc1d3ac606d117e05a140e0de79806.svg", + 672, + Object { + "related": Object { + "gziped": "23fc1d3ac606d117e05a140e0de79806.svg.gz", + }, + "size": 672, + }, + ], + Array [ + "23fc1d3ac606d117e05a140e0de79806.svg.gz", + 393, + Object { + "compressed": true, + "size": 393, + }, + ], + Array [ + "async.async.js.gz", + 234, + Object { + "compressed": true, + "size": 234, + }, + ], + Array [ + "async.async.js.map?ver=8cdf224bcea94552590b", + 116, + Object { + "development": true, + "size": 116, + }, + ], + Array [ + "async.async.js?ver=8cdf224bcea94552590b", + 334, + Object { + "immutable": true, + "related": Object { + "gziped": "async.async.js.gz", + "sourceMap": "async.async.js.map?ver=8cdf224bcea94552590b", + }, + "size": 334, + }, + ], + Array [ + "copied.js", + 400, + Object { + "copied": true, + "related": Object { + "gziped": "copied.js.gz", + }, + "size": 400, + }, + ], + Array [ + "copied.js.gz", + 29, + Object { + "compressed": true, + "size": 29, + }, + ], + Array [ + "main.js.gz", + 3618, + Object { + "compressed": true, + "size": 3618, + }, + ], + Array [ + "main.js.map.gz", + 3586, + Object { + "compressed": true, + "size": 3586, + }, + ], + Array [ + "main.js.map?var=8cdf224bcea94552590b", + 11216, + Object { + "development": true, + "related": Object { + "gziped": "main.js.map.gz", + }, + "size": 11216, + }, + ], + Array [ + "main.js?var=8cdf224bcea94552590b", + 15373, + Object { + "immutable": true, + "related": Object { + "gziped": "main.js.gz", + "sourceMap": "main.js.map?var=8cdf224bcea94552590b", + }, + "size": 15373, + }, + ], +] +`; + +exports[`CompressionPlugin should work with assets info: errors 1`] = `Array []`; + +exports[`CompressionPlugin should work with assets info: warnings 1`] = `Array []`; + +exports[`CompressionPlugin should work with multiple plugins: assets 1`] = ` +Array [ + Array [ + "09a1a1112c577c2794359715edfcb5ac.png", + 78117, + Object { + "size": 78117, + }, + ], + Array [ + "23fc1d3ac606d117e05a140e0de79806.svg", + 672, + Object { + "related": Object { + "brotliCompressed": "23fc1d3ac606d117e05a140e0de79806.svg.br", + "compressed": "23fc1d3ac606d117e05a140e0de79806.svg.compress", + "customed": "23fc1d3ac606d117e05a140e0de79806.svg.custom?foo=bar#hash", + "gziped": "23fc1d3ac606d117e05a140e0de79806.svg.gz", + }, + "size": 672, + }, + ], + Array [ + "23fc1d3ac606d117e05a140e0de79806.svg.br", + 393, + Object { + "compressed": true, + "size": 393, + }, + ], + Array [ + "23fc1d3ac606d117e05a140e0de79806.svg.compress", + 393, + Object { + "compressed": true, + "size": 393, + }, + ], + Array [ + "23fc1d3ac606d117e05a140e0de79806.svg.custom?foo=bar#hash", + 393, + Object { + "compressed": true, + "size": 393, + }, + ], + Array [ + "23fc1d3ac606d117e05a140e0de79806.svg.gz", + 393, + Object { + "compressed": true, + "size": 393, + }, + ], + Array [ + "async.async.js.br", + 181, + Object { + "compressed": true, + "size": 181, + }, + ], + Array [ + "async.async.js.compress", + 181, + Object { + "compressed": true, + "size": 181, + }, + ], + Array [ + "async.async.js.custom?foo=bar#hash", + 181, + Object { + "compressed": true, + "size": 181, + }, + ], + Array [ + "async.async.js.gz", + 181, + Object { + "compressed": true, + "size": 181, + }, + ], + Array [ + "async.async.js?ver=8cdf224bcea94552590b", + 269, + Object { + "immutable": true, + "related": Object { + "brotliCompressed": "async.async.js.br", + "compressed": "async.async.js.compress", + "customed": "async.async.js.custom?foo=bar#hash", + "gziped": "async.async.js.gz", + }, + "size": 269, + }, + ], + Array [ + "main.js.br", + 3587, + Object { + "compressed": true, + "size": 3587, + }, + ], + Array [ + "main.js.compress", + 3587, + Object { + "compressed": true, + "size": 3587, + }, + ], + Array [ + "main.js.custom?foo=bar#hash", + 3587, + Object { + "compressed": true, + "size": 3587, + }, + ], + Array [ + "main.js.gz", + 3587, + Object { + "compressed": true, + "size": 3587, + }, + ], + Array [ + "main.js?var=8cdf224bcea94552590b", + 15315, + Object { + "immutable": true, + "related": Object { + "brotliCompressed": "main.js.br", + "compressed": "main.js.compress", + "customed": "main.js.custom?foo=bar#hash", + "gziped": "main.js.gz", + }, + "size": 15315, + }, + ], +] +`; + +exports[`CompressionPlugin should work with multiple plugins: errors 1`] = `Array []`; + +exports[`CompressionPlugin should work with multiple plugins: warnings 1`] = `Array []`; + exports[`CompressionPlugin should work: assets 1`] = ` Array [ Array [ @@ -77,20 +453,20 @@ Array [ 393, ], Array [ - "async.async.js.gz?ver=309b3b3494418014badd", + "async.async.js.gz", 181, ], Array [ - "async.async.js?ver=309b3b3494418014badd", + "async.async.js?ver=8cdf224bcea94552590b", 269, ], Array [ - "main.js.gz?var=309b3b3494418014badd", - 3529, + "main.js.gz", + 3587, ], Array [ - "main.js?var=309b3b3494418014badd", - 14392, + "main.js?var=8cdf224bcea94552590b", + 15315, ], ] `; diff --git a/test/__snapshots__/algorithm.test.js.snap.webpack4 b/test/__snapshots__/algorithm.test.js.snap.webpack4 index 103a8e0..9fb1560 100644 --- a/test/__snapshots__/algorithm.test.js.snap.webpack4 +++ b/test/__snapshots__/algorithm.test.js.snap.webpack4 @@ -27,12 +27,12 @@ Array [ 171, ], Array [ - "main.8de5b7ad6e2fdef99b99.js", - 11127, + "main.82c6786e32f9c77b44ef.js", + 11645, ], Array [ - "main.8de5b7ad6e2fdef99b99.js.gz", - 2954, + "main.82c6786e32f9c77b44ef.js.gz", + 3000, ], ] `; @@ -41,7 +41,7 @@ exports[`"algorithm" option matches snapshot for \`gzip\` value ({String}): erro exports[`"algorithm" option matches snapshot for \`gzip\` value ({String}): warnings 1`] = `Array []`; -exports[`"algorithm" option matches snapshot for \`unknown\` value ({String}) 1`] = `"Algorithm \\"unknown\\" is not found in zlib"`; +exports[`"algorithm" option matches snapshot for \`unknown\` value ({String}) 1`] = `"Algorithm \\"unknown\\" is not found in \\"zlib\\""`; exports[`"algorithm" option matches snapshot for custom function ({Function}): assets 1`] = ` Array [ @@ -70,12 +70,12 @@ Array [ 249, ], Array [ - "main.8de5b7ad6e2fdef99b99.js", - 11127, + "main.82c6786e32f9c77b44ef.js", + 11645, ], Array [ - "main.8de5b7ad6e2fdef99b99.js.gz", - 11127, + "main.82c6786e32f9c77b44ef.js.gz", + 11645, ], ] `; @@ -107,8 +107,8 @@ Array [ 249, ], Array [ - "main.8de5b7ad6e2fdef99b99.js", - 11127, + "main.82c6786e32f9c77b44ef.js", + 11645, ], ] `; diff --git a/test/__snapshots__/algorithm.test.js.snap.webpack5 b/test/__snapshots__/algorithm.test.js.snap.webpack5 index 9333cc9..3d26f5e 100644 --- a/test/__snapshots__/algorithm.test.js.snap.webpack5 +++ b/test/__snapshots__/algorithm.test.js.snap.webpack5 @@ -19,20 +19,20 @@ Array [ 393, ], Array [ - "async.async.915241b20821fb2958ef.js", + "async.async.81ea6697ed82fa2176bb.js", 269, ], Array [ - "async.async.915241b20821fb2958ef.js.gz", + "async.async.81ea6697ed82fa2176bb.js.gz", 181, ], Array [ - "main.1bf53bd04d76a915156e.js", - 14233, + "main.f1e836b35a2623bafe34.js", + 15156, ], Array [ - "main.1bf53bd04d76a915156e.js.gz", - 3500, + "main.f1e836b35a2623bafe34.js.gz", + 3556, ], ] `; @@ -41,7 +41,7 @@ exports[`"algorithm" option matches snapshot for \`gzip\` value ({String}): erro exports[`"algorithm" option matches snapshot for \`gzip\` value ({String}): warnings 1`] = `Array []`; -exports[`"algorithm" option matches snapshot for \`unknown\` value ({String}) 1`] = `"Algorithm \\"unknown\\" is not found in zlib"`; +exports[`"algorithm" option matches snapshot for \`unknown\` value ({String}) 1`] = `"Algorithm \\"unknown\\" is not found in \\"zlib\\""`; exports[`"algorithm" option matches snapshot for custom function ({Function}): assets 1`] = ` Array [ @@ -62,20 +62,20 @@ Array [ 672, ], Array [ - "async.async.915241b20821fb2958ef.js", + "async.async.81ea6697ed82fa2176bb.js", 269, ], Array [ - "async.async.915241b20821fb2958ef.js.gz", + "async.async.81ea6697ed82fa2176bb.js.gz", 269, ], Array [ - "main.1bf53bd04d76a915156e.js", - 14233, + "main.f1e836b35a2623bafe34.js", + 15156, ], Array [ - "main.1bf53bd04d76a915156e.js.gz", - 14233, + "main.f1e836b35a2623bafe34.js.gz", + 15156, ], ] `; @@ -103,12 +103,12 @@ Array [ 672, ], Array [ - "async.async.915241b20821fb2958ef.js", + "async.async.81ea6697ed82fa2176bb.js", 269, ], Array [ - "main.1bf53bd04d76a915156e.js", - 14233, + "main.f1e836b35a2623bafe34.js", + 15156, ], ] `; diff --git a/test/__snapshots__/cache-option.test.js.snap.webpack4 b/test/__snapshots__/cache-option.test.js.snap.webpack4 index 0ad26bb..9586d3f 100644 --- a/test/__snapshots__/cache-option.test.js.snap.webpack4 +++ b/test/__snapshots__/cache-option.test.js.snap.webpack4 @@ -27,12 +27,12 @@ Array [ 171, ], Array [ - "main.8de5b7ad6e2fdef99b99.js", - 11127, + "main.82c6786e32f9c77b44ef.js", + 11645, ], Array [ - "main.8de5b7ad6e2fdef99b99.js.gz", - 2954, + "main.82c6786e32f9c77b44ef.js.gz", + 3000, ], ] `; @@ -82,12 +82,12 @@ Array [ 171, ], Array [ - "main.8de5b7ad6e2fdef99b99.js", - 11127, + "main.82c6786e32f9c77b44ef.js", + 11645, ], Array [ - "main.8de5b7ad6e2fdef99b99.js.gz", - 2954, + "main.82c6786e32f9c77b44ef.js.gz", + 3000, ], ] `; @@ -119,12 +119,12 @@ Array [ 171, ], Array [ - "main.8de5b7ad6e2fdef99b99.js", - 11127, + "main.82c6786e32f9c77b44ef.js", + 11645, ], Array [ - "main.8de5b7ad6e2fdef99b99.js.gz", - 2954, + "main.82c6786e32f9c77b44ef.js.gz", + 3000, ], ] `; @@ -140,10 +140,10 @@ exports[`"cache" option matches snapshot for \`other-cache-directory\` value ({S exports[`"cache" option matches snapshot for \`other-cache-directory\` value ({String}): errors 2`] = `Array []`; -exports[`"cache" option matches snapshot for \`other-cache-directory\` value ({String}): main.8de5b7ad6e2fdef99b99.js 1`] = ` +exports[`"cache" option matches snapshot for \`other-cache-directory\` value ({String}): main.82c6786e32f9c77b44ef.js 1`] = ` Array [ - "main.8de5b7ad6e2fdef99b99.js", - "bdfa0e56dbf7a3f6e97136a9d040a7e5", + "main.82c6786e32f9c77b44ef.js", + "ef0eb5cabc4295a2bbcd320c66aecd89", ] `; @@ -192,12 +192,12 @@ Array [ 171, ], Array [ - "main.8de5b7ad6e2fdef99b99.js", - 11127, + "main.82c6786e32f9c77b44ef.js", + 11645, ], Array [ - "main.8de5b7ad6e2fdef99b99.js.gz", - 2954, + "main.82c6786e32f9c77b44ef.js.gz", + 3000, ], ] `; @@ -229,12 +229,12 @@ Array [ 171, ], Array [ - "main.8de5b7ad6e2fdef99b99.js", - 11127, + "main.82c6786e32f9c77b44ef.js", + 11645, ], Array [ - "main.8de5b7ad6e2fdef99b99.js.gz", - 2954, + "main.82c6786e32f9c77b44ef.js.gz", + 3000, ], ] `; @@ -250,10 +250,10 @@ exports[`"cache" option matches snapshot for \`true\` value ({Boolean}): errors exports[`"cache" option matches snapshot for \`true\` value ({Boolean}): errors 2`] = `Array []`; -exports[`"cache" option matches snapshot for \`true\` value ({Boolean}): main.8de5b7ad6e2fdef99b99.js 1`] = ` +exports[`"cache" option matches snapshot for \`true\` value ({Boolean}): main.82c6786e32f9c77b44ef.js 1`] = ` Array [ - "main.8de5b7ad6e2fdef99b99.js", - "bdfa0e56dbf7a3f6e97136a9d040a7e5", + "main.82c6786e32f9c77b44ef.js", + "ef0eb5cabc4295a2bbcd320c66aecd89", ] `; diff --git a/test/__snapshots__/cache-option.test.js.snap.webpack5 b/test/__snapshots__/cache-option.test.js.snap.webpack5 index 46c9243..ab6a3aa 100644 --- a/test/__snapshots__/cache-option.test.js.snap.webpack5 +++ b/test/__snapshots__/cache-option.test.js.snap.webpack5 @@ -15,20 +15,20 @@ Array [ 393, ], Array [ - "async.async.915241b20821fb2958ef.js", + "async.async.81ea6697ed82fa2176bb.js", 269, ], Array [ - "async.async.915241b20821fb2958ef.js.gz", + "async.async.81ea6697ed82fa2176bb.js.gz", 181, ], Array [ - "main.1bf53bd04d76a915156e.js", - 14233, + "main.f1e836b35a2623bafe34.js", + 15156, ], Array [ - "main.1bf53bd04d76a915156e.js.gz", - 3500, + "main.f1e836b35a2623bafe34.js.gz", + 3556, ], ] `; @@ -48,20 +48,20 @@ Array [ 393, ], Array [ - "async.async.915241b20821fb2958ef.js", + "async.async.81ea6697ed82fa2176bb.js", 269, ], Array [ - "async.async.915241b20821fb2958ef.js.gz", + "async.async.81ea6697ed82fa2176bb.js.gz", 181, ], Array [ - "main.1bf53bd04d76a915156e.js", - 14233, + "main.f1e836b35a2623bafe34.js", + 15156, ], Array [ - "main.1bf53bd04d76a915156e.js.gz", - 3500, + "main.f1e836b35a2623bafe34.js.gz", + 3556, ], ] `; @@ -74,7 +74,7 @@ exports[`"cache" option should work when \`cache\` is \`false\`: warnings 1`] = exports[`"cache" option should work when \`cache\` is \`false\`: warnings 2`] = `Array []`; -exports[`"cache" option should work when \`cache\` is \`filesystem\`: assets 1`] = ` +exports[`"cache" option should work with "filesystem" value for the "cache.type" option: assets 1`] = ` Array [ Array [ "09a1a1112c577c2794359715edfcb5ac.png", @@ -89,25 +89,25 @@ Array [ 393, ], Array [ - "async.async.915241b20821fb2958ef.js", + "async.async.81ea6697ed82fa2176bb.js", 269, ], Array [ - "async.async.915241b20821fb2958ef.js.gz", + "async.async.81ea6697ed82fa2176bb.js.gz", 181, ], Array [ - "main.1bf53bd04d76a915156e.js", - 14233, + "main.f1e836b35a2623bafe34.js", + 15156, ], Array [ - "main.1bf53bd04d76a915156e.js.gz", - 3500, + "main.f1e836b35a2623bafe34.js.gz", + 3556, ], ] `; -exports[`"cache" option should work when \`cache\` is \`filesystem\`: assets 2`] = ` +exports[`"cache" option should work with "filesystem" value for the "cache.type" option: assets 2`] = ` Array [ Array [ "09a1a1112c577c2794359715edfcb5ac.png", @@ -122,33 +122,33 @@ Array [ 393, ], Array [ - "async.async.915241b20821fb2958ef.js", + "async.async.81ea6697ed82fa2176bb.js", 269, ], Array [ - "async.async.915241b20821fb2958ef.js.gz", + "async.async.81ea6697ed82fa2176bb.js.gz", 181, ], Array [ - "main.1bf53bd04d76a915156e.js", - 14233, + "main.f1e836b35a2623bafe34.js", + 15156, ], Array [ - "main.1bf53bd04d76a915156e.js.gz", - 3500, + "main.f1e836b35a2623bafe34.js.gz", + 3556, ], ] `; -exports[`"cache" option should work when \`cache\` is \`filesystem\`: errors 1`] = `Array []`; +exports[`"cache" option should work with "filesystem" value for the "cache.type" option: errors 1`] = `Array []`; -exports[`"cache" option should work when \`cache\` is \`filesystem\`: errors 2`] = `Array []`; +exports[`"cache" option should work with "filesystem" value for the "cache.type" option: errors 2`] = `Array []`; -exports[`"cache" option should work when \`cache\` is \`filesystem\`: warnings 1`] = `Array []`; +exports[`"cache" option should work with "filesystem" value for the "cache.type" option: warnings 1`] = `Array []`; -exports[`"cache" option should work when \`cache\` is \`filesystem\`: warnings 2`] = `Array []`; +exports[`"cache" option should work with "filesystem" value for the "cache.type" option: warnings 2`] = `Array []`; -exports[`"cache" option should work when \`cache\` is \`memory\`: assets 1`] = ` +exports[`"cache" option should work with "memory" value for the "cache.type" option: assets 1`] = ` Array [ Array [ "09a1a1112c577c2794359715edfcb5ac.png", @@ -163,25 +163,25 @@ Array [ 393, ], Array [ - "async.async.915241b20821fb2958ef.js", + "async.async.81ea6697ed82fa2176bb.js", 269, ], Array [ - "async.async.915241b20821fb2958ef.js.gz", + "async.async.81ea6697ed82fa2176bb.js.gz", 181, ], Array [ - "main.1bf53bd04d76a915156e.js", - 14233, + "main.f1e836b35a2623bafe34.js", + 15156, ], Array [ - "main.1bf53bd04d76a915156e.js.gz", - 3500, + "main.f1e836b35a2623bafe34.js.gz", + 3556, ], ] `; -exports[`"cache" option should work when \`cache\` is \`memory\`: assets 2`] = ` +exports[`"cache" option should work with "memory" value for the "cache.type" option: assets 2`] = ` Array [ Array [ "09a1a1112c577c2794359715edfcb5ac.png", @@ -192,20 +192,32 @@ Array [ 672, ], Array [ - "async.async.915241b20821fb2958ef.js", + "23fc1d3ac606d117e05a140e0de79806.svg.gz", + 393, + ], + Array [ + "async.async.81ea6697ed82fa2176bb.js", 269, ], Array [ - "main.1bf53bd04d76a915156e.js", - 14233, + "async.async.81ea6697ed82fa2176bb.js.gz", + 181, + ], + Array [ + "main.f1e836b35a2623bafe34.js", + 15156, + ], + Array [ + "main.f1e836b35a2623bafe34.js.gz", + 3556, ], ] `; -exports[`"cache" option should work when \`cache\` is \`memory\`: errors 1`] = `Array []`; +exports[`"cache" option should work with "memory" value for the "cache.type" option: errors 1`] = `Array []`; -exports[`"cache" option should work when \`cache\` is \`memory\`: errors 2`] = `Array []`; +exports[`"cache" option should work with "memory" value for the "cache.type" option: errors 2`] = `Array []`; -exports[`"cache" option should work when \`cache\` is \`memory\`: warnings 1`] = `Array []`; +exports[`"cache" option should work with "memory" value for the "cache.type" option: warnings 1`] = `Array []`; -exports[`"cache" option should work when \`cache\` is \`memory\`: warnings 2`] = `Array []`; +exports[`"cache" option should work with "memory" value for the "cache.type" option: warnings 2`] = `Array []`; diff --git a/test/__snapshots__/compressionOptions-option.test.js.snap.webpack4 b/test/__snapshots__/compressionOptions-option.test.js.snap.webpack4 index 96ea241..6517b00 100644 --- a/test/__snapshots__/compressionOptions-option.test.js.snap.webpack4 +++ b/test/__snapshots__/compressionOptions-option.test.js.snap.webpack4 @@ -27,12 +27,12 @@ Array [ 171, ], Array [ - "main.8de5b7ad6e2fdef99b99.js", - 11127, + "main.82c6786e32f9c77b44ef.js", + 11645, ], Array [ - "main.8de5b7ad6e2fdef99b99.js.gz", - 2954, + "main.82c6786e32f9c77b44ef.js.gz", + 3000, ], ] `; @@ -68,12 +68,12 @@ Array [ 171, ], Array [ - "main.8de5b7ad6e2fdef99b99.js", - 11127, + "main.82c6786e32f9c77b44ef.js", + 11645, ], Array [ - "main.8de5b7ad6e2fdef99b99.js.gz", - 2954, + "main.82c6786e32f9c77b44ef.js.gz", + 3000, ], ] `; diff --git a/test/__snapshots__/compressionOptions-option.test.js.snap.webpack5 b/test/__snapshots__/compressionOptions-option.test.js.snap.webpack5 index 5217089..118d415 100644 --- a/test/__snapshots__/compressionOptions-option.test.js.snap.webpack5 +++ b/test/__snapshots__/compressionOptions-option.test.js.snap.webpack5 @@ -19,20 +19,20 @@ Array [ 393, ], Array [ - "async.async.915241b20821fb2958ef.js", + "async.async.81ea6697ed82fa2176bb.js", 269, ], Array [ - "async.async.915241b20821fb2958ef.js.gz", + "async.async.81ea6697ed82fa2176bb.js.gz", 181, ], Array [ - "main.1bf53bd04d76a915156e.js", - 14233, + "main.f1e836b35a2623bafe34.js", + 15156, ], Array [ - "main.1bf53bd04d76a915156e.js.gz", - 3500, + "main.f1e836b35a2623bafe34.js.gz", + 3556, ], ] `; @@ -60,20 +60,20 @@ Array [ 393, ], Array [ - "async.async.915241b20821fb2958ef.js", + "async.async.81ea6697ed82fa2176bb.js", 269, ], Array [ - "async.async.915241b20821fb2958ef.js.gz", + "async.async.81ea6697ed82fa2176bb.js.gz", 181, ], Array [ - "main.1bf53bd04d76a915156e.js", - 14233, + "main.f1e836b35a2623bafe34.js", + 15156, ], Array [ - "main.1bf53bd04d76a915156e.js.gz", - 3500, + "main.f1e836b35a2623bafe34.js.gz", + 3556, ], ] `; diff --git a/test/__snapshots__/deleteOriginalAssets.test.js.snap.webpack4 b/test/__snapshots__/deleteOriginalAssets.test.js.snap.webpack4 index e4b2fbd..8f0ebf2 100644 --- a/test/__snapshots__/deleteOriginalAssets.test.js.snap.webpack4 +++ b/test/__snapshots__/deleteOriginalAssets.test.js.snap.webpack4 @@ -27,12 +27,12 @@ Array [ 171, ], Array [ - "main.8de5b7ad6e2fdef99b99.js", - 11127, + "main.82c6786e32f9c77b44ef.js", + 11645, ], Array [ - "main.8de5b7ad6e2fdef99b99.js.gz", - 2954, + "main.82c6786e32f9c77b44ef.js.gz", + 3000, ], ] `; @@ -56,8 +56,8 @@ Array [ 171, ], Array [ - "main.8de5b7ad6e2fdef99b99.js.gz", - 2954, + "main.82c6786e32f9c77b44ef.js.gz", + 3000, ], ] `; diff --git a/test/__snapshots__/deleteOriginalAssets.test.js.snap.webpack5 b/test/__snapshots__/deleteOriginalAssets.test.js.snap.webpack5 index 1d39748..b0fe050 100644 --- a/test/__snapshots__/deleteOriginalAssets.test.js.snap.webpack5 +++ b/test/__snapshots__/deleteOriginalAssets.test.js.snap.webpack5 @@ -19,20 +19,20 @@ Array [ 393, ], Array [ - "async.async.915241b20821fb2958ef.js", + "async.async.81ea6697ed82fa2176bb.js", 269, ], Array [ - "async.async.915241b20821fb2958ef.js.gz", + "async.async.81ea6697ed82fa2176bb.js.gz", 181, ], Array [ - "main.1bf53bd04d76a915156e.js", - 14233, + "main.f1e836b35a2623bafe34.js", + 15156, ], Array [ - "main.1bf53bd04d76a915156e.js.gz", - 3500, + "main.f1e836b35a2623bafe34.js.gz", + 3556, ], ] `; @@ -52,12 +52,12 @@ Array [ 393, ], Array [ - "async.async.915241b20821fb2958ef.js.gz", + "async.async.81ea6697ed82fa2176bb.js.gz", 181, ], Array [ - "main.1bf53bd04d76a915156e.js.gz", - 3500, + "main.f1e836b35a2623bafe34.js.gz", + 3556, ], ] `; diff --git a/test/__snapshots__/exclude-option.test.js.snap.webpack4 b/test/__snapshots__/exclude-option.test.js.snap.webpack4 index 0e2a524..1804e45 100644 --- a/test/__snapshots__/exclude-option.test.js.snap.webpack4 +++ b/test/__snapshots__/exclude-option.test.js.snap.webpack4 @@ -15,20 +15,20 @@ Array [ 672, ], Array [ - "async.async.js.gz?ver=df8e3f469c7c96726fb9", + "async.async.js.gz", 171, ], Array [ - "async.async.js?ver=df8e3f469c7c96726fb9", + "async.async.js?ver=dc74724f7b13a2de5a20", 249, ], Array [ - "main.js.gz?var=df8e3f469c7c96726fb9", - 2958, + "main.js.gz", + 3002, ], Array [ - "main.js?var=df8e3f469c7c96726fb9", - 11112, + "main.js?var=dc74724f7b13a2de5a20", + 11630, ], ] `; @@ -48,20 +48,20 @@ Array [ 672, ], Array [ - "async.async.js.gz?ver=df8e3f469c7c96726fb9", + "async.async.js.gz", 171, ], Array [ - "async.async.js?ver=df8e3f469c7c96726fb9", + "async.async.js?ver=dc74724f7b13a2de5a20", 249, ], Array [ - "main.js.gz?var=df8e3f469c7c96726fb9", - 2958, + "main.js.gz", + 3002, ], Array [ - "main.js?var=df8e3f469c7c96726fb9", - 11112, + "main.js?var=dc74724f7b13a2de5a20", + 11630, ], ] `; diff --git a/test/__snapshots__/exclude-option.test.js.snap.webpack5 b/test/__snapshots__/exclude-option.test.js.snap.webpack5 index 73f0e65..f7fc78a 100644 --- a/test/__snapshots__/exclude-option.test.js.snap.webpack5 +++ b/test/__snapshots__/exclude-option.test.js.snap.webpack5 @@ -15,20 +15,20 @@ Array [ 672, ], Array [ - "async.async.js.gz?ver=309b3b3494418014badd", + "async.async.js.gz", 181, ], Array [ - "async.async.js?ver=309b3b3494418014badd", + "async.async.js?ver=8cdf224bcea94552590b", 269, ], Array [ - "main.js.gz?var=309b3b3494418014badd", - 3529, + "main.js.gz", + 3587, ], Array [ - "main.js?var=309b3b3494418014badd", - 14392, + "main.js?var=8cdf224bcea94552590b", + 15315, ], ] `; @@ -48,20 +48,20 @@ Array [ 672, ], Array [ - "async.async.js.gz?ver=309b3b3494418014badd", + "async.async.js.gz", 181, ], Array [ - "async.async.js?ver=309b3b3494418014badd", + "async.async.js?ver=8cdf224bcea94552590b", 269, ], Array [ - "main.js.gz?var=309b3b3494418014badd", - 3529, + "main.js.gz", + 3587, ], Array [ - "main.js?var=309b3b3494418014badd", - 14392, + "main.js?var=8cdf224bcea94552590b", + 15315, ], ] `; diff --git a/test/__snapshots__/filename-option.test.js.snap.webpack4 b/test/__snapshots__/filename-option.test.js.snap.webpack4 index 0275d4e..995a2a1 100644 --- a/test/__snapshots__/filename-option.test.js.snap.webpack4 +++ b/test/__snapshots__/filename-option.test.js.snap.webpack4 @@ -19,20 +19,20 @@ Array [ 672, ], Array [ - "async.async.js?ver=df8e3f469c7c96726fb9", + "async.async.js?ver=dc74724f7b13a2de5a20", 249, ], Array [ - "async.async.super-compressed.gz.js?ver=df8e3f469c7c96726fb9", + "async.async.super-compressed.gz.js?ver=dc74724f7b13a2de5a20", 171, ], Array [ - "main.js?var=df8e3f469c7c96726fb9", - 11112, + "main.js?var=dc74724f7b13a2de5a20", + 11630, ], Array [ - "main.super-compressed.gz.js?var=df8e3f469c7c96726fb9", - 2958, + "main.super-compressed.gz.js?var=dc74724f7b13a2de5a20", + 3002, ], ] `; @@ -60,20 +60,20 @@ Array [ 393, ], Array [ - "async.async.js.super-compressed.gz?ver=df8e3f469c7c96726fb9", + "async.async.js.super-compressed.gz?ver=dc74724f7b13a2de5a20", 171, ], Array [ - "async.async.js?ver=df8e3f469c7c96726fb9", + "async.async.js?ver=dc74724f7b13a2de5a20", 249, ], Array [ - "main.js.super-compressed.gz?var=df8e3f469c7c96726fb9", - 2958, + "main.js.super-compressed.gz?var=dc74724f7b13a2de5a20", + 3002, ], Array [ - "main.js?var=df8e3f469c7c96726fb9", - 11112, + "main.js?var=dc74724f7b13a2de5a20", + 11630, ], ] `; @@ -101,20 +101,20 @@ Array [ 393, ], Array [ - "async.async.js.gz?ver=df8e3f469c7c96726fb9", + "async.async.js.gz?ver=dc74724f7b13a2de5a20", 171, ], Array [ - "async.async.js?ver=df8e3f469c7c96726fb9", + "async.async.js?ver=dc74724f7b13a2de5a20", 249, ], Array [ - "main.js.gz?var=df8e3f469c7c96726fb9", - 2958, + "main.js.gz?var=dc74724f7b13a2de5a20", + 3002, ], Array [ - "main.js?var=df8e3f469c7c96726fb9", - 11112, + "main.js?var=dc74724f7b13a2de5a20", + 11630, ], ] `; diff --git a/test/__snapshots__/filename-option.test.js.snap.webpack5 b/test/__snapshots__/filename-option.test.js.snap.webpack5 index f3e91c1..ab241c0 100644 --- a/test/__snapshots__/filename-option.test.js.snap.webpack5 +++ b/test/__snapshots__/filename-option.test.js.snap.webpack5 @@ -19,20 +19,20 @@ Array [ 672, ], Array [ - "async.async.js?ver=309b3b3494418014badd", + "async.async.js?ver=8cdf224bcea94552590b", 269, ], Array [ - "async.async.super-compressed.gz.js?ver=309b3b3494418014badd", + "async.async.super-compressed.gz.js?ver=8cdf224bcea94552590b", 181, ], Array [ - "main.js?var=309b3b3494418014badd", - 14392, + "main.js?var=8cdf224bcea94552590b", + 15315, ], Array [ - "main.super-compressed.gz.js?var=309b3b3494418014badd", - 3529, + "main.super-compressed.gz.js?var=8cdf224bcea94552590b", + 3587, ], ] `; @@ -60,20 +60,20 @@ Array [ 393, ], Array [ - "async.async.js.super-compressed.gz?ver=309b3b3494418014badd", + "async.async.js.super-compressed.gz?ver=8cdf224bcea94552590b", 181, ], Array [ - "async.async.js?ver=309b3b3494418014badd", + "async.async.js?ver=8cdf224bcea94552590b", 269, ], Array [ - "main.js.super-compressed.gz?var=309b3b3494418014badd", - 3529, + "main.js.super-compressed.gz?var=8cdf224bcea94552590b", + 3587, ], Array [ - "main.js?var=309b3b3494418014badd", - 14392, + "main.js?var=8cdf224bcea94552590b", + 15315, ], ] `; @@ -101,20 +101,20 @@ Array [ 393, ], Array [ - "async.async.js.gz?ver=309b3b3494418014badd", + "async.async.js.gz?ver=8cdf224bcea94552590b", 181, ], Array [ - "async.async.js?ver=309b3b3494418014badd", + "async.async.js?ver=8cdf224bcea94552590b", 269, ], Array [ - "main.js.gz?var=309b3b3494418014badd", - 3529, + "main.js.gz?var=8cdf224bcea94552590b", + 3587, ], Array [ - "main.js?var=309b3b3494418014badd", - 14392, + "main.js?var=8cdf224bcea94552590b", + 15315, ], ] `; diff --git a/test/__snapshots__/include-option.test.js.snap.webpack4 b/test/__snapshots__/include-option.test.js.snap.webpack4 index a48d739..089bcc9 100644 --- a/test/__snapshots__/include-option.test.js.snap.webpack4 +++ b/test/__snapshots__/include-option.test.js.snap.webpack4 @@ -11,20 +11,20 @@ Array [ 672, ], Array [ - "async.async.js.gz?ver=df8e3f469c7c96726fb9", + "async.async.js.gz", 171, ], Array [ - "async.async.js?ver=df8e3f469c7c96726fb9", + "async.async.js?ver=dc74724f7b13a2de5a20", 249, ], Array [ - "main.js.gz?var=df8e3f469c7c96726fb9", - 2958, + "main.js.gz", + 3002, ], Array [ - "main.js?var=df8e3f469c7c96726fb9", - 11112, + "main.js?var=dc74724f7b13a2de5a20", + 11630, ], ] `; @@ -48,20 +48,20 @@ Array [ 393, ], Array [ - "async.async.js.gz?ver=df8e3f469c7c96726fb9", + "async.async.js.gz", 171, ], Array [ - "async.async.js?ver=df8e3f469c7c96726fb9", + "async.async.js?ver=dc74724f7b13a2de5a20", 249, ], Array [ - "main.js.gz?var=df8e3f469c7c96726fb9", - 2958, + "main.js.gz", + 3002, ], Array [ - "main.js?var=df8e3f469c7c96726fb9", - 11112, + "main.js?var=dc74724f7b13a2de5a20", + 11630, ], ] `; diff --git a/test/__snapshots__/include-option.test.js.snap.webpack5 b/test/__snapshots__/include-option.test.js.snap.webpack5 index 798b9aa..019bf95 100644 --- a/test/__snapshots__/include-option.test.js.snap.webpack5 +++ b/test/__snapshots__/include-option.test.js.snap.webpack5 @@ -11,20 +11,20 @@ Array [ 672, ], Array [ - "async.async.js.gz?ver=309b3b3494418014badd", + "async.async.js.gz", 181, ], Array [ - "async.async.js?ver=309b3b3494418014badd", + "async.async.js?ver=8cdf224bcea94552590b", 269, ], Array [ - "main.js.gz?var=309b3b3494418014badd", - 3529, + "main.js.gz", + 3587, ], Array [ - "main.js?var=309b3b3494418014badd", - 14392, + "main.js?var=8cdf224bcea94552590b", + 15315, ], ] `; @@ -48,20 +48,20 @@ Array [ 393, ], Array [ - "async.async.js.gz?ver=309b3b3494418014badd", + "async.async.js.gz", 181, ], Array [ - "async.async.js?ver=309b3b3494418014badd", + "async.async.js?ver=8cdf224bcea94552590b", 269, ], Array [ - "main.js.gz?var=309b3b3494418014badd", - 3529, + "main.js.gz", + 3587, ], Array [ - "main.js?var=309b3b3494418014badd", - 14392, + "main.js?var=8cdf224bcea94552590b", + 15315, ], ] `; diff --git a/test/__snapshots__/minRatio-option.test.js.snap.webpack4 b/test/__snapshots__/minRatio-option.test.js.snap.webpack4 index c663457..3b3170c 100644 --- a/test/__snapshots__/minRatio-option.test.js.snap.webpack4 +++ b/test/__snapshots__/minRatio-option.test.js.snap.webpack4 @@ -15,8 +15,8 @@ Array [ 249, ], Array [ - "main.8de5b7ad6e2fdef99b99.js", - 11127, + "main.82c6786e32f9c77b44ef.js", + 11645, ], ] `; @@ -52,12 +52,12 @@ Array [ 171, ], Array [ - "main.8de5b7ad6e2fdef99b99.js", - 11127, + "main.82c6786e32f9c77b44ef.js", + 11645, ], Array [ - "main.8de5b7ad6e2fdef99b99.js.gz", - 2954, + "main.82c6786e32f9c77b44ef.js.gz", + 3000, ], ] `; diff --git a/test/__snapshots__/minRatio-option.test.js.snap.webpack5 b/test/__snapshots__/minRatio-option.test.js.snap.webpack5 index 28ad113..08a7e39 100644 --- a/test/__snapshots__/minRatio-option.test.js.snap.webpack5 +++ b/test/__snapshots__/minRatio-option.test.js.snap.webpack5 @@ -11,12 +11,12 @@ Array [ 672, ], Array [ - "async.async.915241b20821fb2958ef.js", + "async.async.81ea6697ed82fa2176bb.js", 269, ], Array [ - "main.1bf53bd04d76a915156e.js", - 14233, + "main.f1e836b35a2623bafe34.js", + 15156, ], ] `; @@ -44,20 +44,20 @@ Array [ 393, ], Array [ - "async.async.915241b20821fb2958ef.js", + "async.async.81ea6697ed82fa2176bb.js", 269, ], Array [ - "async.async.915241b20821fb2958ef.js.gz", + "async.async.81ea6697ed82fa2176bb.js.gz", 181, ], Array [ - "main.1bf53bd04d76a915156e.js", - 14233, + "main.f1e836b35a2623bafe34.js", + 15156, ], Array [ - "main.1bf53bd04d76a915156e.js.gz", - 3500, + "main.f1e836b35a2623bafe34.js.gz", + 3556, ], ] `; diff --git a/test/__snapshots__/test-option.test.js.snap.webpack4 b/test/__snapshots__/test-option.test.js.snap.webpack4 index 14c6473..550f693 100644 --- a/test/__snapshots__/test-option.test.js.snap.webpack4 +++ b/test/__snapshots__/test-option.test.js.snap.webpack4 @@ -15,12 +15,12 @@ Array [ 672, ], Array [ - "async.async.js?ver=df8e3f469c7c96726fb9", + "async.async.js?ver=dc74724f7b13a2de5a20", 249, ], Array [ - "main.js?var=df8e3f469c7c96726fb9", - 11112, + "main.js?var=dc74724f7b13a2de5a20", + 11630, ], ] `; @@ -48,12 +48,12 @@ Array [ 393, ], Array [ - "async.async.js?ver=df8e3f469c7c96726fb9", + "async.async.js?ver=dc74724f7b13a2de5a20", 249, ], Array [ - "main.js?var=df8e3f469c7c96726fb9", - 11112, + "main.js?var=dc74724f7b13a2de5a20", + 11630, ], ] `; @@ -81,20 +81,20 @@ Array [ 393, ], Array [ - "async.async.js.gz?ver=df8e3f469c7c96726fb9", + "async.async.js.gz", 171, ], Array [ - "async.async.js?ver=df8e3f469c7c96726fb9", + "async.async.js?ver=dc74724f7b13a2de5a20", 249, ], Array [ - "main.js.gz?var=df8e3f469c7c96726fb9", - 2958, + "main.js.gz", + 3002, ], Array [ - "main.js?var=df8e3f469c7c96726fb9", - 11112, + "main.js?var=dc74724f7b13a2de5a20", + 11630, ], ] `; diff --git a/test/__snapshots__/test-option.test.js.snap.webpack5 b/test/__snapshots__/test-option.test.js.snap.webpack5 index 9582a61..782405a 100644 --- a/test/__snapshots__/test-option.test.js.snap.webpack5 +++ b/test/__snapshots__/test-option.test.js.snap.webpack5 @@ -15,12 +15,12 @@ Array [ 672, ], Array [ - "async.async.js?ver=309b3b3494418014badd", + "async.async.js?ver=8cdf224bcea94552590b", 269, ], Array [ - "main.js?var=309b3b3494418014badd", - 14392, + "main.js?var=8cdf224bcea94552590b", + 15315, ], ] `; @@ -48,12 +48,12 @@ Array [ 393, ], Array [ - "async.async.js?ver=309b3b3494418014badd", + "async.async.js?ver=8cdf224bcea94552590b", 269, ], Array [ - "main.js?var=309b3b3494418014badd", - 14392, + "main.js?var=8cdf224bcea94552590b", + 15315, ], ] `; @@ -81,20 +81,20 @@ Array [ 393, ], Array [ - "async.async.js.gz?ver=309b3b3494418014badd", + "async.async.js.gz", 181, ], Array [ - "async.async.js?ver=309b3b3494418014badd", + "async.async.js?ver=8cdf224bcea94552590b", 269, ], Array [ - "main.js.gz?var=309b3b3494418014badd", - 3529, + "main.js.gz", + 3587, ], Array [ - "main.js?var=309b3b3494418014badd", - 14392, + "main.js?var=8cdf224bcea94552590b", + 15315, ], ] `; diff --git a/test/__snapshots__/threshold-option.test.js.snap.webpack4 b/test/__snapshots__/threshold-option.test.js.snap.webpack4 index 82bdf0d..142f6f7 100644 --- a/test/__snapshots__/threshold-option.test.js.snap.webpack4 +++ b/test/__snapshots__/threshold-option.test.js.snap.webpack4 @@ -27,12 +27,12 @@ Array [ 171, ], Array [ - "main.8de5b7ad6e2fdef99b99.js", - 11127, + "main.82c6786e32f9c77b44ef.js", + 11645, ], Array [ - "main.8de5b7ad6e2fdef99b99.js.gz", - 2954, + "main.82c6786e32f9c77b44ef.js.gz", + 3000, ], ] `; @@ -60,12 +60,12 @@ Array [ 249, ], Array [ - "main.8de5b7ad6e2fdef99b99.js", - 11127, + "main.82c6786e32f9c77b44ef.js", + 11645, ], Array [ - "main.8de5b7ad6e2fdef99b99.js.gz", - 2954, + "main.82c6786e32f9c77b44ef.js.gz", + 3000, ], ] `; @@ -73,3 +73,49 @@ Array [ exports[`"threshold" option matches snapshot for \`8192\` value ({Number}): errors 1`] = `Array []`; exports[`"threshold" option matches snapshot for \`8192\` value ({Number}): warnings 1`] = `Array []`; + +exports[`"threshold" option should compress all assets excluding assets with "0" bytes original size: assets 1`] = ` +Array [ + Array [ + "31d6cfe0d16ae931b73c59d7e0c089c0.txt", + 0, + ], + Array [ + "main.f8078965575fc1ebcc92.js", + 4692, + ], + Array [ + "main.f8078965575fc1ebcc92.js.gz", + 1314, + ], +] +`; + +exports[`"threshold" option should compress all assets excluding assets with "0" bytes original size: errors 1`] = `Array []`; + +exports[`"threshold" option should compress all assets excluding assets with "0" bytes original size: warnings 1`] = `Array []`; + +exports[`"threshold" option should compress all assets including assets with "0" bytes original size: assets 1`] = ` +Array [ + Array [ + "31d6cfe0d16ae931b73c59d7e0c089c0.txt", + 0, + ], + Array [ + "31d6cfe0d16ae931b73c59d7e0c089c0.txt.gz", + 20, + ], + Array [ + "main.f8078965575fc1ebcc92.js", + 4692, + ], + Array [ + "main.f8078965575fc1ebcc92.js.gz", + 1314, + ], +] +`; + +exports[`"threshold" option should compress all assets including assets with "0" bytes original size: errors 1`] = `Array []`; + +exports[`"threshold" option should compress all assets including assets with "0" bytes original size: warnings 1`] = `Array []`; diff --git a/test/__snapshots__/threshold-option.test.js.snap.webpack5 b/test/__snapshots__/threshold-option.test.js.snap.webpack5 index 09b5e3b..84434f0 100644 --- a/test/__snapshots__/threshold-option.test.js.snap.webpack5 +++ b/test/__snapshots__/threshold-option.test.js.snap.webpack5 @@ -19,20 +19,20 @@ Array [ 393, ], Array [ - "async.async.915241b20821fb2958ef.js", + "async.async.81ea6697ed82fa2176bb.js", 269, ], Array [ - "async.async.915241b20821fb2958ef.js.gz", + "async.async.81ea6697ed82fa2176bb.js.gz", 181, ], Array [ - "main.1bf53bd04d76a915156e.js", - 14233, + "main.f1e836b35a2623bafe34.js", + 15156, ], Array [ - "main.1bf53bd04d76a915156e.js.gz", - 3500, + "main.f1e836b35a2623bafe34.js.gz", + 3556, ], ] `; @@ -56,16 +56,16 @@ Array [ 672, ], Array [ - "async.async.915241b20821fb2958ef.js", + "async.async.81ea6697ed82fa2176bb.js", 269, ], Array [ - "main.1bf53bd04d76a915156e.js", - 14233, + "main.f1e836b35a2623bafe34.js", + 15156, ], Array [ - "main.1bf53bd04d76a915156e.js.gz", - 3500, + "main.f1e836b35a2623bafe34.js.gz", + 3556, ], ] `; @@ -73,3 +73,49 @@ Array [ exports[`"threshold" option matches snapshot for \`8192\` value ({Number}): errors 1`] = `Array []`; exports[`"threshold" option matches snapshot for \`8192\` value ({Number}): warnings 1`] = `Array []`; + +exports[`"threshold" option should compress all assets excluding assets with "0" bytes original size: assets 1`] = ` +Array [ + Array [ + "31d6cfe0d16ae931b73c59d7e0c089c0.txt", + 0, + ], + Array [ + "main.d6c14561219fdba42701.js", + 4496, + ], + Array [ + "main.d6c14561219fdba42701.js.gz", + 1163, + ], +] +`; + +exports[`"threshold" option should compress all assets excluding assets with "0" bytes original size: errors 1`] = `Array []`; + +exports[`"threshold" option should compress all assets excluding assets with "0" bytes original size: warnings 1`] = `Array []`; + +exports[`"threshold" option should compress all assets including assets with "0" bytes original size: assets 1`] = ` +Array [ + Array [ + "31d6cfe0d16ae931b73c59d7e0c089c0.txt", + 0, + ], + Array [ + "31d6cfe0d16ae931b73c59d7e0c089c0.txt.gz", + 20, + ], + Array [ + "main.d6c14561219fdba42701.js", + 4496, + ], + Array [ + "main.d6c14561219fdba42701.js.gz", + 1163, + ], +] +`; + +exports[`"threshold" option should compress all assets including assets with "0" bytes original size: errors 1`] = `Array []`; + +exports[`"threshold" option should compress all assets including assets with "0" bytes original size: warnings 1`] = `Array []`; diff --git a/test/cache-option.test.js b/test/cache-option.test.js index bf75edc..e2eb62f 100644 --- a/test/cache-option.test.js +++ b/test/cache-option.test.js @@ -1,5 +1,4 @@ import path from 'path'; -import zlib from 'zlib'; import cacache from 'cacache'; import findCacheDir from 'find-cache-dir'; @@ -99,7 +98,7 @@ if (getCompiler.isWebpack4()) { const cacheEntryOptions = new Function( `'use strict'\nreturn ${cacheEntry}` )(); - const basename = path.basename(cacheEntryOptions.filename); + const basename = path.basename(cacheEntryOptions.assetName); expect([basename, cacheEntryOptions.contentHash]).toMatchSnapshot( basename @@ -164,7 +163,7 @@ if (getCompiler.isWebpack4()) { const cacheEntryOptions = new Function( `'use strict'\nreturn ${cacheEntry}` )(); - const basename = path.basename(cacheEntryOptions.filename); + const basename = path.basename(cacheEntryOptions.assetName); expect([basename, cacheEntryOptions.contentHash]).toMatchSnapshot( basename @@ -195,133 +194,183 @@ if (getCompiler.isWebpack4()) { }); } else { describe('"cache" option', () => { - beforeEach(() => { - return del([path.resolve('node_modules/.cache/webpack')]); - }); + const fileSystemCacheDirectory = path.resolve( + __dirname, + './outputs/type-filesystem' + ); - afterEach(() => { - jest.clearAllMocks(); + beforeAll(() => { + return Promise.all([del(fileSystemCacheDirectory)]); }); it('should work when `cache` is `false`', async () => { - const gzipSpy = jest.spyOn(zlib, 'gzip'); - const beforeCacheCompiler = getCompiler( - './entry.js', - {}, - { cache: false } - ); + const compiler = getCompiler('./entry.js', {}, { cache: false }); - new CompressionPlugin().apply(beforeCacheCompiler); + new CompressionPlugin().apply(compiler); - const stats = await compile(beforeCacheCompiler); + let getCounter = 0; - expect(gzipSpy).toHaveBeenCalledTimes(4); - expect(getAssetsNameAndSize(stats)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('errors'); - expect(getErrors(stats)).toMatchSnapshot('warnings'); + compiler.cache.hooks.get.tap( + { name: 'TestCache', stage: -100 }, + (identifier) => { + if (identifier.indexOf('CompressionWebpackPlugin') !== -1) { + getCounter += 1; + } + } + ); - gzipSpy.mockClear(); + let storeCounter = 0; - await new Promise((resolve) => { - beforeCacheCompiler.close(async () => { - const afterCacheCompiler = getCompiler( - './entry.js', - {}, - { cache: false } - ); + compiler.cache.hooks.store.tap( + { name: 'TestCache', stage: -100 }, + (identifier) => { + if (identifier.indexOf('CompressionWebpackPlugin') !== -1) { + storeCounter += 1; + } + } + ); - new CompressionPlugin().apply(afterCacheCompiler); + const stats = await compile(compiler); - const newStats = await compile(afterCacheCompiler); + // Without cache webpack always try to get + expect(getCounter).toBe(4); + // Without cache webpack always try to store + expect(storeCounter).toBe(4); + expect(getAssetsNameAndSize(stats)).toMatchSnapshot('assets'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(gzipSpy).toHaveBeenCalledTimes(4); - expect(getAssetsNameAndSize(newStats)).toMatchSnapshot('assets'); - expect(getWarnings(newStats)).toMatchSnapshot('errors'); - expect(getErrors(newStats)).toMatchSnapshot('warnings'); + getCounter = 0; + storeCounter = 0; - gzipSpy.mockRestore(); + const newStats = await compile(compiler); - resolve(); - }); - }); + // Without cache webpack always try to get + expect(getCounter).toBe(4); + // Without cache webpack always try to store + expect(storeCounter).toBe(4); + expect(getAssetsNameAndSize(newStats)).toMatchSnapshot('assets'); + expect(getErrors(newStats)).toMatchSnapshot('errors'); + expect(getWarnings(newStats)).toMatchSnapshot('warnings'); }); - it('should work when `cache` is `memory`', async () => { - const gzipSpy = jest.spyOn(zlib, 'gzip'); + it('should work with "memory" value for the "cache.type" option', async () => { const compiler = getCompiler( './entry.js', {}, - { cache: { type: 'memory' } } + { + cache: { + type: 'memory', + }, + } ); new CompressionPlugin().apply(compiler); - const stats = await compile(compiler); + let getCounter = 0; - expect(gzipSpy).toHaveBeenCalledTimes(4); - expect(getAssetsNameAndSize(stats)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('errors'); - expect(getErrors(stats)).toMatchSnapshot('warnings'); + compiler.cache.hooks.get.tap( + { name: 'TestCache', stage: -100 }, + (identifier) => { + if (identifier.indexOf('CompressionWebpackPlugin') !== -1) { + getCounter += 1; + } + } + ); - gzipSpy.mockClear(); + let storeCounter = 0; - await new Promise((resolve) => { - compiler.close(async () => { - const newStats = await compile(compiler); + compiler.cache.hooks.store.tap( + { name: 'TestCache', stage: -100 }, + (identifier) => { + if (identifier.indexOf('CompressionWebpackPlugin') !== -1) { + storeCounter += 1; + } + } + ); - expect(gzipSpy).toHaveBeenCalledTimes(0); - expect(getAssetsNameAndSize(newStats)).toMatchSnapshot('assets'); - expect(getWarnings(newStats)).toMatchSnapshot('errors'); - expect(getErrors(newStats)).toMatchSnapshot('warnings'); + const stats = await compile(compiler); - gzipSpy.mockRestore(); + // Get cache for assets + expect(getCounter).toBe(4); + // Store cached assets + expect(storeCounter).toBe(4); + expect(getAssetsNameAndSize(stats)).toMatchSnapshot('assets'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); - resolve(); - }); - }); + getCounter = 0; + storeCounter = 0; + + const newStats = await compile(compiler); + + // Get cache for assets + expect(getCounter).toBe(4); + // No need to store, we got cached assets + expect(storeCounter).toBe(0); + expect(getAssetsNameAndSize(newStats)).toMatchSnapshot('assets'); + expect(getErrors(newStats)).toMatchSnapshot('errors'); + expect(getWarnings(newStats)).toMatchSnapshot('warnings'); }); - it('should work when `cache` is `filesystem`', async () => { - const gzipSpy = jest.spyOn(zlib, 'gzip'); - const beforeCacheCompiler = getCompiler( + it('should work with "filesystem" value for the "cache.type" option', async () => { + const compiler = getCompiler( './entry.js', {}, - { cache: { type: 'filesystem' } } + { + cache: { + type: 'filesystem', + cacheDirectory: fileSystemCacheDirectory, + }, + } ); - new CompressionPlugin().apply(beforeCacheCompiler); + new CompressionPlugin().apply(compiler); - const stats = await compile(beforeCacheCompiler); + let getCounter = 0; - expect(gzipSpy).toHaveBeenCalledTimes(4); - expect(getAssetsNameAndSize(stats)).toMatchSnapshot('assets'); - expect(getWarnings(stats)).toMatchSnapshot('errors'); - expect(getErrors(stats)).toMatchSnapshot('warnings'); + compiler.cache.hooks.get.tap( + { name: 'TestCache', stage: -100 }, + (identifier) => { + if (identifier.indexOf('CompressionWebpackPlugin') !== -1) { + getCounter += 1; + } + } + ); - gzipSpy.mockClear(); + let storeCounter = 0; - await new Promise((resolve) => { - beforeCacheCompiler.close(async () => { - const afterCacheCompiler = getCompiler( - './entry.js', - {}, - { cache: { type: 'filesystem' } } - ); + compiler.cache.hooks.store.tap( + { name: 'TestCache', stage: -100 }, + (identifier) => { + if (identifier.indexOf('CompressionWebpackPlugin') !== -1) { + storeCounter += 1; + } + } + ); - new CompressionPlugin().apply(afterCacheCompiler); + const stats = await compile(compiler); - const newStats = await compile(afterCacheCompiler); + // Get cache for assets + expect(getCounter).toBe(4); + // Store cached assets + expect(storeCounter).toBe(4); + expect(getAssetsNameAndSize(stats)).toMatchSnapshot('assets'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(gzipSpy).toHaveBeenCalledTimes(0); - expect(getAssetsNameAndSize(newStats)).toMatchSnapshot('assets'); - expect(getWarnings(newStats)).toMatchSnapshot('errors'); - expect(getErrors(newStats)).toMatchSnapshot('warnings'); + getCounter = 0; + storeCounter = 0; - gzipSpy.mockRestore(); + const newStats = await compile(compiler); - resolve(); - }); - }); + // Get cache for assets + expect(getCounter).toBe(4); + // No need to store, we got cached assets + expect(storeCounter).toBe(0); + expect(getAssetsNameAndSize(newStats)).toMatchSnapshot('assets'); + expect(getErrors(newStats)).toMatchSnapshot('errors'); + expect(getWarnings(newStats)).toMatchSnapshot('warnings'); }); }); } diff --git a/test/fixtures/empty.js b/test/fixtures/empty.js new file mode 100644 index 0000000..3cf6479 --- /dev/null +++ b/test/fixtures/empty.js @@ -0,0 +1,5 @@ +import empty from './empty.txt'; + +const foo = 'bar'; + +export { empty, foo } diff --git a/test/fixtures/empty.txt b/test/fixtures/empty.txt new file mode 100644 index 0000000..e69de29 diff --git a/test/fixtures/entry.js b/test/fixtures/entry.js index 1bca32c..2673c4b 100644 --- a/test/fixtures/entry.js +++ b/test/fixtures/entry.js @@ -1,5 +1,6 @@ import imagePNG from './icon.png'; import imageSVG from './icon.svg'; +import number from './number'; import(/* webpackChunkName: 'async' */ './async.js').then((result) => console.log(result)); @@ -12,4 +13,5 @@ module.exports = function Foo() { console.log(b); console.log(imagePNG); console.log(imageSVG); + console.log(number); }; diff --git a/test/fixtures/number.js b/test/fixtures/number.js new file mode 100644 index 0000000..5bf9337 --- /dev/null +++ b/test/fixtures/number.js @@ -0,0 +1 @@ +export default 100; diff --git a/test/helpers/CopyPluginWithAssetInfo.js b/test/helpers/CopyPluginWithAssetInfo.js new file mode 100644 index 0000000..73b8b90 --- /dev/null +++ b/test/helpers/CopyPluginWithAssetInfo.js @@ -0,0 +1,16 @@ +import { RawSource } from 'webpack-sources'; + +export default class CopyPluginWithAssetInfo { + apply(compiler) { + const plugin = { name: this.constructor.name }; + + compiler.hooks.thisCompilation.tap(plugin, (compilation) => { + compilation.hooks.additionalAssets.tap(plugin, () => { + // eslint-disable-next-line no-param-reassign + compilation.emitAsset('copied.js', new RawSource('Text'.repeat(100)), { + copied: true, + }); + }); + }); + } +} diff --git a/test/helpers/getAssetsNameAndSize.js b/test/helpers/getAssetsNameAndSize.js index 0ffc9cf..1dcbc61 100644 --- a/test/helpers/getAssetsNameAndSize.js +++ b/test/helpers/getAssetsNameAndSize.js @@ -1,10 +1,15 @@ -export default (stats, size = true) => { - const { assets } = stats.compilation; +export default (stats, withAssetInfo = false) => { + const { assets, assetsInfo } = stats.compilation; return Object.keys(assets) .sort() - .map((assetName) => [ - assetName, - size ? assets[assetName].size() : 'size was skipped by test', - ]); + .map((assetName) => { + const item = [assetName, assets[assetName].size()]; + + if (withAssetInfo) { + item.push(assetsInfo.get(assetName)); + } + + return item; + }); }; diff --git a/test/helpers/getCompiler.js b/test/helpers/getCompiler.js index 16cfc0f..c9696aa 100644 --- a/test/helpers/getCompiler.js +++ b/test/helpers/getCompiler.js @@ -17,7 +17,7 @@ export default function getCompiler(fixture, loaderOptions = {}, config = {}) { module: { rules: [ { - test: /\.(png|jpg|gif|svg)$/i, + test: /\.(png|jpg|gif|svg|txt)$/i, rules: [ { loader: 'file-loader', diff --git a/test/helpers/index.js b/test/helpers/index.js index a1b33a8..360f7f6 100644 --- a/test/helpers/index.js +++ b/test/helpers/index.js @@ -1,4 +1,5 @@ import compile from './compile'; +import CopyPluginWithAssetInfo from './CopyPluginWithAssetInfo'; import execute from './execute'; import getAssetsNameAndSize from './getAssetsNameAndSize'; import getCompiler from './getCompiler'; @@ -11,6 +12,7 @@ import removeCache from './removeCache'; export { compile, + CopyPluginWithAssetInfo, execute, getAssetsNameAndSize, getCompiler, diff --git a/test/helpers/loader-with-child-compilation.js b/test/helpers/loader-with-child-compilation.js new file mode 100644 index 0000000..77539cc --- /dev/null +++ b/test/helpers/loader-with-child-compilation.js @@ -0,0 +1,20 @@ +import CopyPluginWithAssetInfo from './CopyPluginWithAssetInfo'; + +export default function loader() { + const callback = this.async(); + + const childCompiler = this._compilation.createChildCompiler( + `preloader`, + this.options + ); + + new CopyPluginWithAssetInfo().apply(childCompiler); + + childCompiler.runAsChild((error) => { + if (error) { + return callback(error); + } + + return callback(null, 'export default 1'); + }); +} diff --git a/test/helpers/readAsset.js b/test/helpers/readAsset.js index 8f4699f..6647f5d 100644 --- a/test/helpers/readAsset.js +++ b/test/helpers/readAsset.js @@ -14,7 +14,7 @@ export default (asset, compiler, stats) => { } try { - data = usedFs.readFileSync(path.join(outputPath, targetFile)).toString(); + data = usedFs.readFileSync(path.join(outputPath, targetFile)); } catch (error) { data = error.toString(); } diff --git a/test/threshold-option.test.js b/test/threshold-option.test.js index 6f677e9..5c6e91b 100644 --- a/test/threshold-option.test.js +++ b/test/threshold-option.test.js @@ -43,4 +43,34 @@ describe('"threshold" option', () => { expect(getWarnings(stats)).toMatchSnapshot('errors'); expect(getErrors(stats)).toMatchSnapshot('warnings'); }); + + it('should compress all assets including assets with "0" bytes original size', async () => { + compiler = getCompiler('./empty.js'); + + new CompressionPlugin({ + minRatio: Infinity, + threshold: 0, + }).apply(compiler); + + const stats = await compile(compiler); + + expect(getAssetsNameAndSize(stats)).toMatchSnapshot('assets'); + expect(getWarnings(stats)).toMatchSnapshot('errors'); + expect(getErrors(stats)).toMatchSnapshot('warnings'); + }); + + it('should compress all assets excluding assets with "0" bytes original size', async () => { + compiler = getCompiler('./empty.js'); + + new CompressionPlugin({ + minRatio: Number.MAX_SAFE_INTEGER, + threshold: 0, + }).apply(compiler); + + const stats = await compile(compiler); + + expect(getAssetsNameAndSize(stats)).toMatchSnapshot('assets'); + expect(getWarnings(stats)).toMatchSnapshot('errors'); + expect(getErrors(stats)).toMatchSnapshot('warnings'); + }); });