Socket
Socket
Sign inDemoInstall

terser-webpack-plugin

Package Overview
Dependencies
76
Maintainers
3
Versions
77
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 5.3.7 to 5.3.8

57

dist/index.js

@@ -6,13 +6,5 @@ "use strict";

const {
TraceMap,
originalPositionFor
} = require("@jridgewell/trace-mapping");
const {
validate
} = require("schema-utils");
const serialize = require("serialize-javascript");
const {
Worker
} = require("jest-worker");
const {
throttleAll,

@@ -38,7 +30,6 @@ terserMinify,

/** @typedef {import("@jridgewell/trace-mapping").SourceMapInput} SourceMapInput */
/** @typedef {import("@jridgewell/trace-mapping").TraceMap} TraceMap */
/** @typedef {RegExp | string} Rule */
/** @typedef {string | string[] | RegExp | RegExp[]} Rules */
/** @typedef {Rule[] | Rule} Rules */
/**

@@ -166,2 +157,31 @@ * @callback ExtractCommentsFunction

/**
* @template T
* @param fn {(function(): any) | undefined}
* @returns {function(): T}
*/
const memoize = fn => {
let cache = false;
/** @type {T} */
let result;
return () => {
if (cache) {
return result;
}
result = /** @type {function(): any} */fn();
cache = true;
// Allow to clean up memory for fn
// and all dependent resources
// eslint-disable-next-line no-undefined, no-param-reassign
fn = undefined;
return result;
};
};
const getTraceMapping = memoize(() =>
// eslint-disable-next-line global-require
require("@jridgewell/trace-mapping"));
const getSerializeJavascript = memoize(() =>
// eslint-disable-next-line global-require
require("serialize-javascript"));
/**
* @template [T=TerserOptions]

@@ -255,3 +275,3 @@ */

if (error.line) {
const original = sourceMap && originalPositionFor(sourceMap, {
const original = sourceMap && getTraceMapping().originalPositionFor(sourceMap, {
line: error.line,

@@ -359,2 +379,7 @@ column: error.col

}
// eslint-disable-next-line global-require
const {
Worker
} = require("jest-worker");
initializedWorker = /** @type {MinimizerWorker<T>} */

@@ -450,3 +475,3 @@

try {
output = await (getWorker ? getWorker().transform(serialize(options)) : minify(options));
output = await (getWorker ? getWorker().transform(getSerializeJavascript()(options)) : minify(options));
} catch (error) {

@@ -456,3 +481,3 @@ const hasSourceMap = inputSourceMap && TerserPlugin.isSourceMap(inputSourceMap);

TerserPlugin.buildError(error, name, hasSourceMap ? new TraceMap( /** @type {SourceMapInput} */inputSourceMap) :
TerserPlugin.buildError(error, name, hasSourceMap ? new (getTraceMapping().TraceMap)( /** @type {SourceMapInput} */inputSourceMap) :
// eslint-disable-next-line no-undefined

@@ -483,3 +508,3 @@ undefined,

*/
item => TerserPlugin.buildError(item, name, hasSourceMap ? new TraceMap( /** @type {SourceMapInput} */inputSourceMap) :
item => TerserPlugin.buildError(item, name, hasSourceMap ? new (getTraceMapping().TraceMap)( /** @type {SourceMapInput} */inputSourceMap) :
// eslint-disable-next-line no-undefined

@@ -667,3 +692,3 @@ undefined,

const hooks = compiler.webpack.javascript.JavascriptModulesPlugin.getCompilationHooks(compilation);
const data = serialize({
const data = getSerializeJavascript()({
minimizer: typeof this.options.minimizer.implementation.getMinimizerVersion !== "undefined" ? this.options.minimizer.implementation.getMinimizerVersion() || "0.0.0" : "0.0.0",

@@ -670,0 +695,0 @@ options: this.options.minimizer.options

{
"name": "terser-webpack-plugin",
"version": "5.3.7",
"version": "5.3.8",
"description": "Terser plugin for webpack",

@@ -32,2 +32,5 @@ "license": "MIT",

"lint": "npm-run-all -l -p \"lint:**\"",
"fix:js": "npm run lint:js -- --fix",
"fix:prettier": "npm run lint:prettier -- --write",
"fix": "npm-run-all -l fix:js fix:prettier",
"test:only": "cross-env NODE_ENV=test jest",

@@ -64,12 +67,12 @@ "test:watch": "npm run test:only -- --watch",

"serialize-javascript": "^6.0.1",
"terser": "^5.16.5"
"terser": "^5.16.8"
},
"devDependencies": {
"@babel/cli": "^7.21.0",
"@babel/core": "^7.21.0",
"@babel/preset-env": "^7.20.2",
"@commitlint/cli": "^17.4.4",
"@babel/core": "^7.21.4",
"@babel/preset-env": "^7.21.4",
"@commitlint/cli": "^17.5.1",
"@commitlint/config-conventional": "^17.4.4",
"@swc/core": "^1.3.37",
"@types/node": "^18.14.4",
"@swc/core": "^1.3.44",
"@types/node": "^18.15.11",
"@types/serialize-javascript": "^5.0.2",

@@ -81,3 +84,3 @@ "@types/uglify-js": "^3.17.1",

"cross-env": "^7.0.3",
"cspell": "^6.27.0",
"cspell": "^6.31.1",
"del": "^6.0.0",

@@ -87,3 +90,3 @@ "del-cli": "^3.0.1",

"eslint": "^7.32.0",
"eslint-config-prettier": "^8.6.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-import": "^2.27.5",

@@ -93,10 +96,10 @@ "file-loader": "^6.2.0",

"jest": "^27.5.1",
"lint-staged": "^13.1.2",
"lint-staged": "^13.2.0",
"memfs": "^3.4.13",
"npm-run-all": "^4.1.5",
"prettier": "^2.8.4",
"prettier": "^2.8.7",
"standard-version": "^9.3.1",
"typescript": "^4.9.5",
"uglify-js": "^3.17.4",
"webpack": "^5.75.0",
"webpack": "^5.77.0",
"webpack-cli": "^4.10.0",

@@ -103,0 +106,0 @@ "worker-loader": "^3.0.8"

export = TerserPlugin;
/** @typedef {import("schema-utils/declarations/validate").Schema} Schema */
/** @typedef {import("webpack").Compiler} Compiler */
/** @typedef {import("webpack").Compilation} Compilation */
/** @typedef {import("webpack").WebpackError} WebpackError */
/** @typedef {import("webpack").Asset} Asset */
/** @typedef {import("./utils.js").TerserECMA} TerserECMA */
/** @typedef {import("./utils.js").TerserOptions} TerserOptions */
/** @typedef {import("jest-worker").Worker} JestWorker */
/** @typedef {import("@jridgewell/trace-mapping").SourceMapInput} SourceMapInput */
/** @typedef {RegExp | string} Rule */
/** @typedef {Rule[] | Rule} Rules */
/**
* @callback ExtractCommentsFunction
* @param {any} astNode
* @param {{ value: string, type: 'comment1' | 'comment2' | 'comment3' | 'comment4', pos: number, line: number, col: number }} comment
* @returns {boolean}
*/
/**
* @typedef {boolean | 'all' | 'some' | RegExp | ExtractCommentsFunction} ExtractCommentsCondition
*/
/**
* @typedef {string | ((fileData: any) => string)} ExtractCommentsFilename
*/
/**
* @typedef {boolean | string | ((commentsFile: string) => string)} ExtractCommentsBanner
*/
/**
* @typedef {Object} ExtractCommentsObject
* @property {ExtractCommentsCondition} [condition]
* @property {ExtractCommentsFilename} [filename]
* @property {ExtractCommentsBanner} [banner]
*/
/**
* @typedef {ExtractCommentsCondition | ExtractCommentsObject} ExtractCommentsOptions
*/
/**
* @typedef {Object} MinimizedResult
* @property {string} code
* @property {SourceMapInput} [map]
* @property {Array<Error | string>} [errors]
* @property {Array<Error | string>} [warnings]
* @property {Array<string>} [extractedComments]
*/
/**
* @typedef {{ [file: string]: string }} Input
*/
/**
* @typedef {{ [key: string]: any }} CustomOptions
*/
/**
* @template T
* @typedef {T extends infer U ? U : CustomOptions} InferDefaultType
*/
/**
* @typedef {Object} PredefinedOptions
* @property {boolean} [module]
* @property {TerserECMA} [ecma]
*/
/**
* @template T
* @typedef {PredefinedOptions & InferDefaultType<T>} MinimizerOptions
*/
/**
* @template T
* @callback BasicMinimizerImplementation
* @param {Input} input
* @param {SourceMapInput | undefined} sourceMap
* @param {MinimizerOptions<T>} minifyOptions
* @param {ExtractCommentsOptions | undefined} extractComments
* @returns {Promise<MinimizedResult>}
*/
/**
* @typedef {object} MinimizeFunctionHelpers
* @property {() => string | undefined} [getMinimizerVersion]
*/
/**
* @template T
* @typedef {BasicMinimizerImplementation<T> & MinimizeFunctionHelpers} MinimizerImplementation
*/
/**
* @template T
* @typedef {Object} InternalOptions
* @property {string} name
* @property {string} input
* @property {SourceMapInput | undefined} inputSourceMap
* @property {ExtractCommentsOptions | undefined} extractComments
* @property {{ implementation: MinimizerImplementation<T>, options: MinimizerOptions<T> }} minimizer
*/
/**
* @template T
* @typedef {JestWorker & { transform: (options: string) => MinimizedResult, minify: (options: InternalOptions<T>) => MinimizedResult }} MinimizerWorker
*/
/**
* @typedef {undefined | boolean | number} Parallel
*/
/**
* @typedef {Object} BasePluginOptions
* @property {Rules} [test]
* @property {Rules} [include]
* @property {Rules} [exclude]
* @property {ExtractCommentsOptions} [extractComments]
* @property {Parallel} [parallel]
*/
/**
* @template T
* @typedef {T extends TerserOptions ? { minify?: MinimizerImplementation<T> | undefined, terserOptions?: MinimizerOptions<T> | undefined } : { minify: MinimizerImplementation<T>, terserOptions?: MinimizerOptions<T> | undefined }} DefinedDefaultMinimizerAndOptions
*/
/**
* @template T
* @typedef {BasePluginOptions & { minimizer: { implementation: MinimizerImplementation<T>, options: MinimizerOptions<T> } }} InternalPluginOptions
*/
/**
* @template [T=TerserOptions]

@@ -194,3 +83,3 @@ */

SourceMapInput,
Rule,
TraceMap,
Rules,

@@ -249,4 +138,4 @@ ExtractCommentsFunction,

type SourceMapInput = import("@jridgewell/trace-mapping").SourceMapInput;
type Rule = RegExp | string;
type Rules = Rule[] | Rule;
type TraceMap = import("@jridgewell/trace-mapping").TraceMap;
type Rules = string | string[] | RegExp | RegExp[];
type ExtractCommentsFunction = (

@@ -319,3 +208,3 @@ astNode: any,

};
type MinimizerWorker<T> = Worker & {
type MinimizerWorker<T> = import("jest-worker").Worker & {
transform: (options: string) => MinimizedResult;

@@ -332,2 +221,1 @@ minify: (options: InternalOptions<T>) => MinimizedResult;

import { minify } from "./minify";
import { Worker } from "jest-worker";
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc