WXL
4 天以前 3bd962a6d7f61239c020e2dbbeb7341e5b842dd1
node_modules/terser-webpack-plugin/dist/index.js
@@ -11,6 +11,7 @@
const schema = require("./options.json");
const {
  esbuildMinify,
  jsonMinify,
  memoize,
  swcMinify,
  terserMinify,
@@ -24,6 +25,7 @@
/** @typedef {import("webpack").Configuration} Configuration */
/** @typedef {import("webpack").Asset} Asset */
/** @typedef {import("webpack").AssetInfo} AssetInfo */
/** @typedef {import("webpack").TemplatePath} TemplatePath */
/** @typedef {import("jest-worker").Worker} JestWorker */
/** @typedef {import("@jridgewell/trace-mapping").EncodedSourceMap & { sources: string[], sourcesContent?: string[], file: string }} RawSourceMap */
/** @typedef {import("@jridgewell/trace-mapping").TraceMap} TraceMap */
@@ -31,21 +33,22 @@
/** @typedef {RegExp | string} Rule */
/** @typedef {Rule[] | Rule} Rules */
// eslint-disable-next-line jsdoc/no-restricted-syntax
// eslint-disable-next-line jsdoc/reject-any-type
/** @typedef {any} EXPECTED_ANY */
/**
 * @callback ExtractCommentsFunction
 * @param {any} astNode ast Node
 * @param {{ value: string, type: 'comment1' | 'comment2' | 'comment3' | 'comment4', pos: number, line: number, col: number }} comment comment node
 * @param {EXPECTED_ANY} astNode ast Node
 * @param {{ value: string, type: "comment1" | "comment2" | "comment3" | "comment4", pos: number, line: number, col: number }} comment comment node
 * @returns {boolean} true when need to extract comment, otherwise false
 */
/**
 * @typedef {boolean | 'all' | 'some' | RegExp | ExtractCommentsFunction} ExtractCommentsCondition
 * @typedef {boolean | "all" | "some" | RegExp | ExtractCommentsFunction} ExtractCommentsCondition
 */
// eslint-disable-next-line jsdoc/no-restricted-syntax
/**
 * @typedef {string | ((fileData: any) => string)} ExtractCommentsFilename
 * @typedef {TemplatePath} ExtractCommentsFilename
 */
/**
@@ -75,18 +78,17 @@
 * @typedef {object} MinimizedResult
 * @property {string=} code code
 * @property {RawSourceMap=} map source map
 * @property {Array<Error | string>=} errors errors
 * @property {Array<Error | string>=} warnings warnings
 * @property {Array<string>=} extractedComments extracted comments
 * @property {(Error | string)[]=} errors errors
 * @property {(Error | string)[]=} warnings warnings
 * @property {string[]=} extractedComments extracted comments
 */
/**
 * @typedef {{ [file: string]: string }} Input
 */
// eslint-disable-next-line jsdoc/no-restricted-syntax
/**
 * @typedef {{ [key: string]: any }} CustomOptions
 * @typedef {{ [key: string]: EXPECTED_ANY }} CustomOptions
 */
/**
@@ -120,6 +122,7 @@
 * @typedef {object} MinimizeFunctionHelpers
 * @property {() => string | undefined=} getMinimizerVersion function that returns version of minimizer
 * @property {() => boolean | undefined=} supportsWorkerThreads true when minimizer support worker threads, otherwise false
 * @property {() => boolean | undefined=} supportsWorker true when minimizer support worker, otherwise false
 */
/**
@@ -166,7 +169,7 @@
 */
const getTraceMapping = memoize(() => require("@jridgewell/trace-mapping"));
const getSerializeJavascript = memoize(() => require("serialize-javascript"));
const getSerializeJavascript = memoize(() => require("./serialize-javascript"));
/**
 * @template [T=import("terser").MinifyOptions]
@@ -181,6 +184,7 @@
      baseDataPath: "options"
    });
    // TODO handle json and etc in the next major release
    // TODO make `minimizer` option instead `minify` and `terserOptions` in the next major release, also rename `terserMinify` to `terserMinimize`
    const {
      minify = ( /** @type {MinimizerImplementation<T>} */terserMinify),
@@ -360,7 +364,8 @@
    let initializedWorker;
    /** @type {undefined | number} */
    let numberOfWorkers;
    if (optimizeOptions.availableNumberOfCores > 0) {
    const needCreateWorker = optimizeOptions.availableNumberOfCores > 0 && (typeof this.options.minimizer.implementation.supportsWorker === "undefined" || typeof this.options.minimizer.implementation.supportsWorker === "function" && this.options.minimizer.implementation.supportsWorker());
    if (needCreateWorker) {
      // Do not create unnecessary workers when the number of files is less than the available cores, it saves memory
      numberOfWorkers = Math.min(numberOfAssets, optimizeOptions.availableNumberOfCores);
      getWorker = () => {
@@ -703,4 +708,5 @@
TerserPlugin.uglifyJsMinify = uglifyJsMinify;
TerserPlugin.swcMinify = swcMinify;
TerserPlugin.esbuildMinify = esbuildMinify;
TerserPlugin.jsonMinify = jsonMinify;
module.exports = TerserPlugin;