terser-webpack-plugin
Advanced tools
Comparing version 5.1.1 to 5.1.2
@@ -5,2 +5,9 @@ # Changelog | ||
### [5.1.2](https://github.com/webpack-contrib/terser-webpack-plugin/compare/v5.1.1...v5.1.2) (2021-05-12) | ||
### Bug Fixes | ||
* don't crash in non-parallel mode ([#395](https://github.com/webpack-contrib/terser-webpack-plugin/issues/395)) ([a177425](https://github.com/webpack-contrib/terser-webpack-plugin/commit/a1774257f7ccedafa15a58aaeba6186c47daea8a)) | ||
### [5.1.1](https://github.com/webpack-contrib/terser-webpack-plugin/compare/v5.1.0...v5.1.1) (2021-01-09) | ||
@@ -7,0 +14,0 @@ |
@@ -30,5 +30,5 @@ "use strict"; | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
@@ -41,4 +41,2 @@ /** @typedef {import("schema-utils/declarations/validate").Schema} Schema */ | ||
/** @typedef {import("webpack").Rules} Rules */ | ||
/** @typedef {import("webpack").WebpackError} WebpackError */ | ||
@@ -48,4 +46,2 @@ | ||
/** @typedef {import("webpack").AssetInfo} AssetInfo */ | ||
/** @typedef {import("terser").ECMA} TerserECMA */ | ||
@@ -63,6 +59,10 @@ | ||
/** @typedef {import("./minify.js").CustomMinifyOptions} CustomMinifyOptions */ | ||
/** @typedef {RegExp | string} Rule */ | ||
/** @typedef {Rule[] | Rule} Rules */ | ||
/** @typedef {JestWorker & { transform: (options: string) => InternalMinifyResult, minify: (options: InternalMinifyOptions) => InternalMinifyResult }} MinifyWorker */ | ||
/** @typedef {Object.<any, any> | TerserMinifyOptions} MinifyOptions */ | ||
/** | ||
@@ -96,5 +96,5 @@ * @callback ExtractCommentsFunction | ||
* @callback CustomMinifyFunction | ||
* @param {Object.<string, string>} file | ||
* @param {RawSourceMap | undefined} sourceMap | ||
* @param {MinifyOptions} minifyOptions | ||
* @param {{ [file: string]: string }} fileAndCode | ||
* @param {RawSourceMap} [sourceMap] | ||
* @param {Object.<any, any>} minifyOptions | ||
*/ | ||
@@ -107,7 +107,7 @@ | ||
/** | ||
* @typedef {Object} TerserPluginOptions | ||
* @typedef {Object} PluginWithTerserOptions | ||
* @property {Rules} [test] | ||
* @property {Rules} [include] | ||
* @property {Rules} [exclude] | ||
* @property {MinifyOptions} [terserOptions] | ||
* @property {TerserMinifyOptions} [terserOptions] | ||
* @property {ExtractCommentsOptions} [extractComments] | ||
@@ -117,2 +117,17 @@ * @property {boolean} [parallel] | ||
*/ | ||
/** | ||
* @typedef {Object} PluginWithCustomMinifyOptions | ||
* @property {Rules} [test] | ||
* @property {Rules} [include] | ||
* @property {Rules} [exclude] | ||
* @property {Object.<any, any>} [terserOptions] | ||
* @property {ExtractCommentsOptions} [extractComments] | ||
* @property {boolean} [parallel] | ||
* @property {CustomMinifyFunction} [minify] | ||
*/ | ||
/** | ||
* @typedef {PluginWithTerserOptions | PluginWithCustomMinifyOptions} TerserPluginOptions | ||
*/ | ||
class TerserPlugin { | ||
@@ -166,3 +181,3 @@ /** | ||
* @param {SourceMapConsumer} [sourceMap] | ||
* @returns {WebpackError} | ||
* @returns {Error} | ||
*/ | ||
@@ -221,3 +236,5 @@ | ||
info | ||
} = compilation.getAsset(name); | ||
} = | ||
/** @type {Asset} */ | ||
compilation.getAsset(name); | ||
@@ -240,3 +257,5 @@ if ( // Skip double minimize assets from child compilation | ||
source | ||
} = compilation.getAsset(name); | ||
} = | ||
/** @type {Asset} */ | ||
compilation.getAsset(name); | ||
const eTag = cache.getLazyHashedEtag(source); | ||
@@ -308,2 +327,6 @@ const cacheItem = cache.getItemCache(name, eTag); | ||
} = compiler.webpack.sources; | ||
/** @typedef {{ extractedCommentsSource : import("webpack").sources.RawSource, commentsFilename: string }} ExtractedCommentsInfo */ | ||
/** @type {Map<string, ExtractedCommentsInfo>} */ | ||
const allExtractedComments = new Map(); | ||
@@ -380,3 +403,5 @@ const scheduledTasks = []; | ||
const hasSourceMap = inputSourceMap && TerserPlugin.isSourceMap(inputSourceMap); | ||
compilation.errors.push(TerserPlugin.buildError(error, name, // eslint-disable-next-line no-undefined | ||
compilation.errors.push( | ||
/** @type {WebpackError} */ | ||
TerserPlugin.buildError(error, name, // eslint-disable-next-line no-undefined | ||
hasSourceMap ? compilation.requestShortener : undefined, hasSourceMap ? new _sourceMap.SourceMapConsumer( | ||
@@ -456,3 +481,3 @@ /** @type {RawSourceMap} */ | ||
} | ||
/** @type {AssetInfo} */ | ||
/** @type {Record<string, any>} */ | ||
@@ -490,11 +515,15 @@ | ||
} | ||
/** @typedef {{ source: import("webpack").sources.Source, commentsFilename: string, from: string }} ExtractedCommentsInfoWIthFrom */ | ||
await Array.from(allExtractedComments).sort().reduce( | ||
/** | ||
* @param {Promise<any>} previousPromise | ||
* @param {any} extractedComments | ||
* @returns {Promise<any>} | ||
* @param {Promise<unknown>} previousPromise | ||
* @param {[string, ExtractedCommentsInfo]} extractedComments | ||
* @returns {Promise<ExtractedCommentsInfoWIthFrom>} | ||
*/ | ||
async (previousPromise, [from, value]) => { | ||
const previous = await previousPromise; | ||
const previous = | ||
/** @type {ExtractedCommentsInfoWIthFrom | undefined} **/ | ||
await previousPromise; | ||
const { | ||
@@ -516,3 +545,7 @@ commentsFilename, | ||
if (!source) { | ||
source = new ConcatSource(Array.from(new Set([...prevSource.source().split("\n\n"), ...extractedCommentsSource.source().split("\n\n")])).join("\n\n")); | ||
source = new ConcatSource(Array.from(new Set([... | ||
/** @type {string}*/ | ||
prevSource.source().split("\n\n"), ... | ||
/** @type {string}*/ | ||
extractedCommentsSource.source().split("\n\n")])).join("\n\n")); | ||
await cache.storePromise(name, eTag, source); | ||
@@ -523,5 +556,5 @@ } | ||
return { | ||
source, | ||
commentsFilename, | ||
from: mergedName, | ||
source | ||
from: mergedName | ||
}; | ||
@@ -534,5 +567,5 @@ } | ||
return { | ||
source: existingAsset.source, | ||
commentsFilename, | ||
from: commentsFilename, | ||
source: existingAsset.source | ||
from: commentsFilename | ||
}; | ||
@@ -545,7 +578,9 @@ } | ||
return { | ||
source: extractedCommentsSource, | ||
commentsFilename, | ||
from, | ||
source: extractedCommentsSource | ||
from | ||
}; | ||
}, Promise.resolve()); | ||
}, | ||
/** @type {Promise<unknown>} */ | ||
Promise.resolve()); | ||
} | ||
@@ -610,4 +645,7 @@ /** | ||
formatFlag | ||
}) => // eslint-disable-next-line no-undefined | ||
minimized ? green(formatFlag("minimized")) : undefined); | ||
}) => minimized ? | ||
/** @type {function} */ | ||
green( | ||
/** @type {function} */ | ||
formatFlag("minimized")) : ""); | ||
}); | ||
@@ -614,0 +652,0 @@ }); |
@@ -12,4 +12,2 @@ "use strict"; | ||
/** @typedef {import("./index.js").MinifyOptions} MinifyOptions */ | ||
/** @typedef {import("terser").MinifyOptions} TerserMinifyOptions */ | ||
@@ -28,9 +26,13 @@ | ||
/** | ||
* @typedef {Object.<any, any>} CustomMinifyOptions | ||
*/ | ||
/** | ||
* @typedef {Object} InternalMinifyOptions | ||
* @property {string} name | ||
* @property {string} input | ||
* @property {RawSourceMap | undefined} inputSourceMap | ||
* @property {RawSourceMap} [inputSourceMap] | ||
* @property {ExtractCommentsOptions} extractComments | ||
* @property {CustomMinifyFunction | undefined} minify | ||
* @property {MinifyOptions} minifyOptions | ||
* @property {CustomMinifyFunction} [minify] | ||
* @property {TerserMinifyOptions | CustomMinifyOptions} minifyOptions | ||
*/ | ||
@@ -57,8 +59,14 @@ | ||
function buildTerserOptions(terserOptions = {}) { | ||
// Need deep copy objects to avoid https://github.com/terser/terser/issues/366 | ||
return { ...terserOptions, | ||
compress: typeof terserOptions.compress === "boolean" ? terserOptions.compress : { ...terserOptions.compress | ||
}, | ||
// ecma: terserOptions.ecma, | ||
// ie8: terserOptions.ie8, | ||
// keep_classnames: terserOptions.keep_classnames, | ||
// keep_fnames: terserOptions.keep_fnames, | ||
mangle: terserOptions.mangle == null ? true : typeof terserOptions.mangle === "boolean" ? terserOptions.mangle : { ...terserOptions.mangle | ||
}, | ||
// Ignoring sourceMap from options | ||
// eslint-disable-next-line no-undefined | ||
sourceMap: undefined, | ||
// module: terserOptions.module, | ||
// nameCache: { ...terserOptions.toplevel }, | ||
// the `output` option is deprecated | ||
@@ -75,3 +83,10 @@ ...(terserOptions.format ? { | ||
} | ||
}) | ||
}), | ||
parse: { ...terserOptions.parse | ||
}, | ||
// safari10: terserOptions.safari10, | ||
// Ignoring sourceMap from options | ||
// eslint-disable-next-line no-undefined | ||
sourceMap: undefined // toplevel: terserOptions.toplevel | ||
}; | ||
@@ -78,0 +93,0 @@ } |
{ | ||
"name": "terser-webpack-plugin", | ||
"version": "5.1.1", | ||
"version": "5.1.2", | ||
"description": "Terser plugin for webpack", | ||
@@ -22,3 +22,3 @@ "license": "MIT", | ||
"prebuild": "npm run clean", | ||
"_build:types": "tsc --declaration --emitDeclarationOnly --outDir declarations && prettier \"declarations/**/*.ts\" --write", | ||
"_build:types": "tsc --declaration --emitDeclarationOnly --outDir types && prettier \"types/**/*.ts\" --write", | ||
"build:code": "cross-env NODE_ENV=production babel src -d dist --copy-files", | ||
@@ -30,3 +30,3 @@ "build": "npm-run-all -p \"build:**\"", | ||
"lint:js": "eslint --cache .", | ||
"_lint:types": "tsc --pretty --noEmit", | ||
"lint:types": "tsc --pretty --noEmit", | ||
"lint": "npm-run-all -l -p \"lint:**\"", | ||
@@ -38,9 +38,8 @@ "test:only": "cross-env NODE_ENV=test jest", | ||
"test": "npm run test:coverage", | ||
"prepare": "npm run build", | ||
"release": "standard-version", | ||
"defaults": "webpack-defaults" | ||
"prepare": "npm run build && husky install", | ||
"release": "standard-version" | ||
}, | ||
"files": [ | ||
"dist", | ||
"declarations" | ||
"types" | ||
], | ||
@@ -56,33 +55,32 @@ "peerDependencies": { | ||
"source-map": "^0.6.1", | ||
"terser": "^5.5.1" | ||
"terser": "^5.7.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.12.10", | ||
"@babel/core": "^7.12.10", | ||
"@babel/preset-env": "^7.12.11", | ||
"@commitlint/cli": "^11.0.0", | ||
"@commitlint/config-conventional": "^11.0.0", | ||
"@babel/cli": "^7.13.16", | ||
"@babel/core": "^7.14.0", | ||
"@babel/preset-env": "^7.14.1", | ||
"@commitlint/cli": "^12.1.3", | ||
"@commitlint/config-conventional": "^12.1.3", | ||
"@types/serialize-javascript": "^5.0.0", | ||
"@webpack-contrib/defaults": "^6.3.0", | ||
"@webpack-contrib/eslint-config-webpack": "^3.0.0", | ||
"babel-jest": "^26.6.3", | ||
"copy-webpack-plugin": "^7.0.0", | ||
"copy-webpack-plugin": "^8.1.1", | ||
"cross-env": "^7.0.3", | ||
"del": "^6.0.0", | ||
"del-cli": "^3.0.1", | ||
"eslint": "^7.17.0", | ||
"eslint-config-prettier": "^7.1.0", | ||
"eslint": "^7.26.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-import": "^2.22.1", | ||
"file-loader": "^6.2.0", | ||
"husky": "^4.3.7", | ||
"husky": "^6.0.0", | ||
"jest": "^26.6.3", | ||
"lint-staged": "^10.5.3", | ||
"memfs": "^3.2.0", | ||
"lint-staged": "^10.5.4", | ||
"memfs": "^3.2.2", | ||
"npm-run-all": "^4.1.5", | ||
"prettier": "^2.2.1", | ||
"standard-version": "^9.1.0", | ||
"typescript": "^4.1.3", | ||
"uglify-js": "^3.12.4", | ||
"webpack": "^5.12.1", | ||
"worker-loader": "^3.0.7" | ||
"prettier": "^2.3.0", | ||
"standard-version": "^9.3.0", | ||
"typescript": "^4.2.4", | ||
"uglify-js": "^3.13.6", | ||
"webpack": "^5.37.0", | ||
"worker-loader": "^3.0.8" | ||
}, | ||
@@ -89,0 +87,0 @@ "keywords": [ |
@@ -21,3 +21,3 @@ <div align="center"> | ||
If you are using webpack v5 or above you do not need to install this plugin. Webpack v5 comes with the latest `terser-webpack-plugin` out of the box. | ||
If you are using webpack v5 or above you do not need to install this plugin. Webpack v5 comes with the latest `terser-webpack-plugin` out of the box. Using Webpack v4, you have to install `terser-webpack-plugin` v4. | ||
@@ -24,0 +24,0 @@ To begin, you'll need to install `terser-webpack-plugin`: |
74230
27
906
1
+ Added@types/node@20.12.12(transitive)
+ Addedcaniuse-lite@1.0.30001620(transitive)
+ Addedelectron-to-chromium@1.4.773(transitive)
+ Addedpicocolors@1.0.1(transitive)
+ Addedupdate-browserslist-db@1.0.16(transitive)
- Removed@types/node@20.12.11(transitive)
- Removedcaniuse-lite@1.0.30001616(transitive)
- Removedelectron-to-chromium@1.4.763(transitive)
- Removedpicocolors@1.0.0(transitive)
- Removedupdate-browserslist-db@1.0.15(transitive)
Updatedterser@^5.7.0