Enable jqhtml data caching with automatic ES6 class registration
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
333
node_modules/terser-webpack-plugin/dist/index.js
generated
vendored
Executable file → Normal file
333
node_modules/terser-webpack-plugin/dist/index.js
generated
vendored
Executable file → Normal file
@@ -1,46 +1,49 @@
|
||||
"use strict";
|
||||
|
||||
const path = require("path");
|
||||
const os = require("os");
|
||||
const path = require("path");
|
||||
const {
|
||||
validate
|
||||
} = require("schema-utils");
|
||||
const {
|
||||
throttleAll,
|
||||
memoize,
|
||||
terserMinify,
|
||||
uglifyJsMinify,
|
||||
swcMinify,
|
||||
esbuildMinify
|
||||
} = require("./utils");
|
||||
const schema = require("./options.json");
|
||||
const {
|
||||
minify
|
||||
} = require("./minify");
|
||||
const schema = require("./options.json");
|
||||
const {
|
||||
esbuildMinify,
|
||||
memoize,
|
||||
swcMinify,
|
||||
terserMinify,
|
||||
throttleAll,
|
||||
uglifyJsMinify
|
||||
} = require("./utils");
|
||||
|
||||
/** @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").Configuration} Configuration */
|
||||
/** @typedef {import("webpack").Asset} Asset */
|
||||
/** @typedef {import("webpack").AssetInfo} AssetInfo */
|
||||
/** @typedef {import("jest-worker").Worker} JestWorker */
|
||||
/** @typedef {import("@jridgewell/trace-mapping").SourceMapInput} SourceMapInput */
|
||||
/** @typedef {import("@jridgewell/trace-mapping").EncodedSourceMap & { sources: string[], sourcesContent?: string[], file: string }} RawSourceMap */
|
||||
/** @typedef {import("@jridgewell/trace-mapping").TraceMap} TraceMap */
|
||||
|
||||
/** @typedef {RegExp | string} Rule */
|
||||
/** @typedef {Rule[] | Rule} Rules */
|
||||
|
||||
// eslint-disable-next-line jsdoc/no-restricted-syntax
|
||||
/**
|
||||
* @callback ExtractCommentsFunction
|
||||
* @param {any} astNode
|
||||
* @param {{ value: string, type: 'comment1' | 'comment2' | 'comment3' | 'comment4', pos: number, line: number, col: number }} comment
|
||||
* @returns {boolean}
|
||||
* @param {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
|
||||
*/
|
||||
|
||||
// eslint-disable-next-line jsdoc/no-restricted-syntax
|
||||
/**
|
||||
* @typedef {string | ((fileData: any) => string)} ExtractCommentsFilename
|
||||
*/
|
||||
@@ -50,10 +53,10 @@ const {
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ExtractCommentsObject
|
||||
* @property {ExtractCommentsCondition} [condition]
|
||||
* @property {ExtractCommentsFilename} [filename]
|
||||
* @property {ExtractCommentsBanner} [banner]
|
||||
* @typedef {object} ExtractCommentsObject
|
||||
* @property {ExtractCommentsCondition=} condition condition which comments need to be expected
|
||||
* @property {ExtractCommentsFilename=} filename filename for extracted comments
|
||||
* @property {ExtractCommentsBanner=} banner banner in filename for extracted comments
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -61,18 +64,27 @@ const {
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} MinimizedResult
|
||||
* @property {string} code
|
||||
* @property {SourceMapInput} [map]
|
||||
* @property {Array<Error | string>} [errors]
|
||||
* @property {Array<Error | string>} [warnings]
|
||||
* @property {Array<string>} [extractedComments]
|
||||
* @typedef {object} ErrorObject
|
||||
* @property {string} message message
|
||||
* @property {number=} line line number
|
||||
* @property {number=} column column number
|
||||
* @property {string=} stack error stack trace
|
||||
*/
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {{ [file: string]: string }} Input
|
||||
*/
|
||||
|
||||
// eslint-disable-next-line jsdoc/no-restricted-syntax
|
||||
/**
|
||||
* @typedef {{ [key: string]: any }} CustomOptions
|
||||
*/
|
||||
@@ -84,9 +96,9 @@ const {
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @typedef {Object} PredefinedOptions
|
||||
* @property {T extends { module?: infer P } ? P : boolean | string} [module]
|
||||
* @property {T extends { ecma?: infer P } ? P : number | string} [ecma]
|
||||
* @typedef {object} PredefinedOptions
|
||||
* @property {T extends { module?: infer P } ? P : boolean | string=} module true when code is a EC module, otherwise false
|
||||
* @property {T extends { ecma?: infer P } ? P : number | string=} ecma ecma version
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -98,16 +110,16 @@ const {
|
||||
* @template T
|
||||
* @callback BasicMinimizerImplementation
|
||||
* @param {Input} input
|
||||
* @param {SourceMapInput | undefined} sourceMap
|
||||
* @param {RawSourceMap | undefined} sourceMap
|
||||
* @param {MinimizerOptions<T>} minifyOptions
|
||||
* @param {ExtractCommentsOptions | undefined} extractComments
|
||||
* @returns {Promise<MinimizedResult>}
|
||||
* @returns {Promise<MinimizedResult> | MinimizedResult}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {object} MinimizeFunctionHelpers
|
||||
* @property {() => string | undefined} [getMinimizerVersion]
|
||||
* @property {() => boolean | undefined} [supportsWorkerThreads]
|
||||
* @property {() => string | undefined=} getMinimizerVersion function that returns version of minimizer
|
||||
* @property {() => boolean | undefined=} supportsWorkerThreads true when minimizer support worker threads, otherwise false
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -117,17 +129,17 @@ const {
|
||||
|
||||
/**
|
||||
* @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
|
||||
* @typedef {object} InternalOptions
|
||||
* @property {string} name name
|
||||
* @property {string} input input
|
||||
* @property {RawSourceMap | undefined} inputSourceMap input source map
|
||||
* @property {ExtractCommentsOptions | undefined} extractComments extract comments option
|
||||
* @property {{ implementation: MinimizerImplementation<T>, options: MinimizerOptions<T> }} minimizer minimizer
|
||||
*/
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @typedef {JestWorker & { transform: (options: string) => MinimizedResult, minify: (options: InternalOptions<T>) => MinimizedResult }} MinimizerWorker
|
||||
* @typedef {JestWorker & { transform: (options: string) => Promise<MinimizedResult>, minify: (options: InternalOptions<T>) => Promise<MinimizedResult> }} MinimizerWorker
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -135,12 +147,12 @@ const {
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} BasePluginOptions
|
||||
* @property {Rules} [test]
|
||||
* @property {Rules} [include]
|
||||
* @property {Rules} [exclude]
|
||||
* @property {ExtractCommentsOptions} [extractComments]
|
||||
* @property {Parallel} [parallel]
|
||||
* @typedef {object} BasePluginOptions
|
||||
* @property {Rules=} test test rule
|
||||
* @property {Rules=} include include rile
|
||||
* @property {Rules=} exclude exclude rule
|
||||
* @property {ExtractCommentsOptions=} extractComments extract comments options
|
||||
* @property {Parallel=} parallel parallel option
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -153,19 +165,15 @@ const {
|
||||
* @typedef {BasePluginOptions & { minimizer: { implementation: MinimizerImplementation<T>, options: MinimizerOptions<T> } }} InternalPluginOptions
|
||||
*/
|
||||
|
||||
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"));
|
||||
const getTraceMapping = memoize(() => require("@jridgewell/trace-mapping"));
|
||||
const getSerializeJavascript = memoize(() => require("serialize-javascript"));
|
||||
|
||||
/**
|
||||
* @template [T=import("terser").MinifyOptions]
|
||||
*/
|
||||
class TerserPlugin {
|
||||
/**
|
||||
* @param {BasePluginOptions & DefinedDefaultMinimizerAndOptions<T>} [options]
|
||||
* @param {BasePluginOptions & DefinedDefaultMinimizerAndOptions<T>=} options options
|
||||
*/
|
||||
constructor(options) {
|
||||
validate( /** @type {Schema} */schema, options || {}, {
|
||||
@@ -203,26 +211,26 @@ class TerserPlugin {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {any} input
|
||||
* @returns {boolean}
|
||||
* @param {unknown} input Input to check
|
||||
* @returns {boolean} Whether input is a source map
|
||||
*/
|
||||
static isSourceMap(input) {
|
||||
// All required options for `new TraceMap(...options)`
|
||||
// https://github.com/jridgewell/trace-mapping#usage
|
||||
return Boolean(input && input.version && input.sources && Array.isArray(input.sources) && typeof input.mappings === "string");
|
||||
return Boolean(input && typeof input === "object" && input !== null && "version" in input && "sources" in input && Array.isArray(input.sources) && "mappings" in input && typeof input.mappings === "string");
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {unknown} warning
|
||||
* @param {string} file
|
||||
* @returns {Error}
|
||||
* @param {unknown} warning warning
|
||||
* @param {string} file file
|
||||
* @returns {Error} built warning
|
||||
*/
|
||||
static buildWarning(warning, file) {
|
||||
/**
|
||||
* @type {Error & { hideStack: true, file: string }}
|
||||
*/
|
||||
// @ts-ignore
|
||||
// @ts-expect-error
|
||||
const builtWarning = new Error(warning.toString());
|
||||
builtWarning.name = "Warning";
|
||||
builtWarning.hideStack = true;
|
||||
@@ -232,11 +240,11 @@ class TerserPlugin {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {any} error
|
||||
* @param {string} file
|
||||
* @param {TraceMap} [sourceMap]
|
||||
* @param {Compilation["requestShortener"]} [requestShortener]
|
||||
* @returns {Error}
|
||||
* @param {Error | ErrorObject | string} error error
|
||||
* @param {string} file file
|
||||
* @param {TraceMap=} sourceMap source map
|
||||
* @param {Compilation["requestShortener"]=} requestShortener request shortener
|
||||
* @returns {Error} built error
|
||||
*/
|
||||
static buildError(error, file, sourceMap, requestShortener) {
|
||||
/**
|
||||
@@ -248,17 +256,21 @@ class TerserPlugin {
|
||||
builtError.file = file;
|
||||
return builtError;
|
||||
}
|
||||
if (error.line) {
|
||||
if ( /** @type {ErrorObject} */error.line) {
|
||||
const {
|
||||
line,
|
||||
column
|
||||
} = /** @type {ErrorObject & { line: number, column: number }} */error;
|
||||
const original = sourceMap && getTraceMapping().originalPositionFor(sourceMap, {
|
||||
line: error.line,
|
||||
column: error.col
|
||||
line,
|
||||
column
|
||||
});
|
||||
if (original && original.source && requestShortener) {
|
||||
builtError = new Error(`${file} from Terser plugin\n${error.message} [${requestShortener.shorten(original.source)}:${original.line},${original.column}][${file}:${error.line},${error.col}]${error.stack ? `\n${error.stack.split("\n").slice(1).join("\n")}` : ""}`);
|
||||
builtError = new Error(`${file} from Terser plugin\n${error.message} [${requestShortener.shorten(original.source)}:${original.line},${original.column}][${file}:${line},${column}]${error.stack ? `\n${error.stack.split("\n").slice(1).join("\n")}` : ""}`);
|
||||
builtError.file = file;
|
||||
return builtError;
|
||||
}
|
||||
builtError = new Error(`${file} from Terser plugin\n${error.message} [${file}:${error.line},${error.col}]${error.stack ? `\n${error.stack.split("\n").slice(1).join("\n")}` : ""}`);
|
||||
builtError = new Error(`${file} from Terser plugin\n${error.message} [${file}:${line},${column}]${error.stack ? `\n${error.stack.split("\n").slice(1).join("\n")}` : ""}`);
|
||||
builtError.file = file;
|
||||
return builtError;
|
||||
}
|
||||
@@ -274,13 +286,17 @@ class TerserPlugin {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {Parallel} parallel
|
||||
* @returns {number}
|
||||
* @param {Parallel} parallel value of the `parallel` option
|
||||
* @returns {number} number of cores for parallelism
|
||||
*/
|
||||
static getAvailableNumberOfCores(parallel) {
|
||||
// In some cases cpus() returns undefined
|
||||
// https://github.com/nodejs/node/issues/19022
|
||||
const cpus = typeof os.availableParallelism === "function" ? {
|
||||
const cpus =
|
||||
// eslint-disable-next-line n/no-unsupported-features/node-builtins
|
||||
typeof os.availableParallelism === "function" ?
|
||||
// eslint-disable-next-line n/no-unsupported-features/node-builtins
|
||||
{
|
||||
length: os.availableParallelism()
|
||||
} : os.cpus() || {
|
||||
length: 1
|
||||
@@ -290,10 +306,10 @@ class TerserPlugin {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {Compiler} compiler
|
||||
* @param {Compilation} compilation
|
||||
* @param {Record<string, import("webpack").sources.Source>} assets
|
||||
* @param {{availableNumberOfCores: number}} optimizeOptions
|
||||
* @param {Compiler} compiler compiler
|
||||
* @param {Compilation} compilation compilation
|
||||
* @param {Record<string, import("webpack").sources.Source>} assets assets
|
||||
* @param {{ availableNumberOfCores: number }} optimizeOptions optimize options
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async optimize(compiler, compilation, assets, optimizeOptions) {
|
||||
@@ -310,9 +326,7 @@ class TerserPlugin {
|
||||
info.extractedComments) {
|
||||
return false;
|
||||
}
|
||||
if (!compiler.webpack.ModuleFilenameHelpers.matchObject.bind(
|
||||
// eslint-disable-next-line no-undefined
|
||||
undefined, this.options)(name)) {
|
||||
if (!compiler.webpack.ModuleFilenameHelpers.matchObject.bind(undefined, this.options)(name)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -349,13 +363,10 @@ class TerserPlugin {
|
||||
if (optimizeOptions.availableNumberOfCores > 0) {
|
||||
// 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);
|
||||
// eslint-disable-next-line consistent-return
|
||||
getWorker = () => {
|
||||
if (initializedWorker) {
|
||||
return initializedWorker;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line global-require
|
||||
const {
|
||||
Worker
|
||||
} = require("jest-worker");
|
||||
@@ -401,7 +412,7 @@ class TerserPlugin {
|
||||
} = asset;
|
||||
if (!output) {
|
||||
let input;
|
||||
/** @type {SourceMapInput | undefined} */
|
||||
/** @type {RawSourceMap | undefined} */
|
||||
let inputSourceMap;
|
||||
const {
|
||||
source: sourceFromInputSource,
|
||||
@@ -410,10 +421,9 @@ class TerserPlugin {
|
||||
input = sourceFromInputSource;
|
||||
if (map) {
|
||||
if (!TerserPlugin.isSourceMap(map)) {
|
||||
compilation.warnings.push( /** @type {WebpackError} */
|
||||
new Error(`${name} contains invalid source map`));
|
||||
compilation.warnings.push(new Error(`${name} contains invalid source map`));
|
||||
} else {
|
||||
inputSourceMap = /** @type {SourceMapInput} */map;
|
||||
inputSourceMap = /** @type {RawSourceMap} */map;
|
||||
}
|
||||
}
|
||||
if (Buffer.isBuffer(input)) {
|
||||
@@ -429,7 +439,6 @@ class TerserPlugin {
|
||||
inputSourceMap,
|
||||
minimizer: {
|
||||
implementation: this.options.minimizer.implementation,
|
||||
// @ts-ignore https://github.com/Microsoft/TypeScript/issues/10727
|
||||
options: {
|
||||
...this.options.minimizer.options
|
||||
}
|
||||
@@ -455,25 +464,19 @@ class TerserPlugin {
|
||||
output = await (getWorker ? getWorker().transform(getSerializeJavascript()(options)) : minify(options));
|
||||
} catch (error) {
|
||||
const hasSourceMap = inputSourceMap && TerserPlugin.isSourceMap(inputSourceMap);
|
||||
compilation.errors.push( /** @type {WebpackError} */
|
||||
|
||||
TerserPlugin.buildError(error, name, hasSourceMap ? new (getTraceMapping().TraceMap)( /** @type {SourceMapInput} */inputSourceMap) :
|
||||
// eslint-disable-next-line no-undefined
|
||||
undefined,
|
||||
// eslint-disable-next-line no-undefined
|
||||
hasSourceMap ? compilation.requestShortener : undefined));
|
||||
compilation.errors.push(TerserPlugin.buildError( /** @type {Error | ErrorObject | string} */
|
||||
error, name, hasSourceMap ? new (getTraceMapping().TraceMap)( /** @type {RawSourceMap} */
|
||||
inputSourceMap) : undefined, hasSourceMap ? compilation.requestShortener : undefined));
|
||||
return;
|
||||
}
|
||||
if (typeof output.code === "undefined") {
|
||||
compilation.errors.push( /** @type {WebpackError} */
|
||||
|
||||
new Error(`${name} from Terser plugin\nMinimizer doesn't return result`));
|
||||
return;
|
||||
compilation.errors.push(new Error(`${name} from Terser plugin\nMinimizer doesn't return result`));
|
||||
}
|
||||
if (output.warnings && output.warnings.length > 0) {
|
||||
output.warnings = output.warnings.map(
|
||||
/**
|
||||
* @param {Error | string} item
|
||||
* @param {Error | string} item a warning
|
||||
* @returns {Error} built warning with extra info
|
||||
*/
|
||||
item => TerserPlugin.buildWarning(item, name));
|
||||
}
|
||||
@@ -481,60 +484,61 @@ class TerserPlugin {
|
||||
const hasSourceMap = inputSourceMap && TerserPlugin.isSourceMap(inputSourceMap);
|
||||
output.errors = output.errors.map(
|
||||
/**
|
||||
* @param {Error | string} item
|
||||
* @param {Error | string} item an error
|
||||
* @returns {Error} built error with extra info
|
||||
*/
|
||||
item => TerserPlugin.buildError(item, name, hasSourceMap ? new (getTraceMapping().TraceMap)( /** @type {SourceMapInput} */inputSourceMap) :
|
||||
// eslint-disable-next-line no-undefined
|
||||
undefined,
|
||||
// eslint-disable-next-line no-undefined
|
||||
hasSourceMap ? compilation.requestShortener : undefined));
|
||||
item => TerserPlugin.buildError(item, name, hasSourceMap ? new (getTraceMapping().TraceMap)( /** @type {RawSourceMap} */
|
||||
inputSourceMap) : undefined, hasSourceMap ? compilation.requestShortener : undefined));
|
||||
}
|
||||
let shebang;
|
||||
if ( /** @type {ExtractCommentsObject} */
|
||||
this.options.extractComments.banner !== false && output.extractedComments && output.extractedComments.length > 0 && output.code.startsWith("#!")) {
|
||||
const firstNewlinePosition = output.code.indexOf("\n");
|
||||
shebang = output.code.substring(0, firstNewlinePosition);
|
||||
output.code = output.code.substring(firstNewlinePosition + 1);
|
||||
}
|
||||
if (output.map) {
|
||||
output.source = new SourceMapSource(output.code, name, output.map, input, /** @type {SourceMapInput} */inputSourceMap, true);
|
||||
} else {
|
||||
output.source = new RawSource(output.code);
|
||||
}
|
||||
if (output.extractedComments && output.extractedComments.length > 0) {
|
||||
const commentsFilename = /** @type {ExtractCommentsObject} */
|
||||
this.options.extractComments.filename || "[file].LICENSE.txt[query]";
|
||||
let query = "";
|
||||
let filename = name;
|
||||
const querySplit = filename.indexOf("?");
|
||||
if (querySplit >= 0) {
|
||||
query = filename.slice(querySplit);
|
||||
filename = filename.slice(0, querySplit);
|
||||
}
|
||||
const lastSlashIndex = filename.lastIndexOf("/");
|
||||
const basename = lastSlashIndex === -1 ? filename : filename.slice(lastSlashIndex + 1);
|
||||
const data = {
|
||||
filename,
|
||||
basename,
|
||||
query
|
||||
};
|
||||
output.commentsFilename = compilation.getPath(commentsFilename, data);
|
||||
let banner;
|
||||
|
||||
// Add a banner to the original file
|
||||
if (output.code) {
|
||||
let shebang;
|
||||
if ( /** @type {ExtractCommentsObject} */
|
||||
this.options.extractComments.banner !== false) {
|
||||
banner = /** @type {ExtractCommentsObject} */
|
||||
this.options.extractComments.banner || `For license information please see ${path.relative(path.dirname(name), output.commentsFilename).replace(/\\/g, "/")}`;
|
||||
if (typeof banner === "function") {
|
||||
banner = banner(output.commentsFilename);
|
||||
}
|
||||
if (banner) {
|
||||
output.source = new ConcatSource(shebang ? `${shebang}\n` : "", `/*! ${banner} */\n`, output.source);
|
||||
}
|
||||
this.options.extractComments.banner !== false && output.extractedComments && output.extractedComments.length > 0 && output.code.startsWith("#!")) {
|
||||
const firstNewlinePosition = output.code.indexOf("\n");
|
||||
shebang = output.code.slice(0, Math.max(0, firstNewlinePosition));
|
||||
output.code = output.code.slice(Math.max(0, firstNewlinePosition + 1));
|
||||
}
|
||||
if (output.map) {
|
||||
output.source = new SourceMapSource(output.code, name, output.map, input, /** @type {RawSourceMap} */
|
||||
inputSourceMap, true);
|
||||
} else {
|
||||
output.source = new RawSource(output.code);
|
||||
}
|
||||
if (output.extractedComments && output.extractedComments.length > 0) {
|
||||
const commentsFilename = /** @type {ExtractCommentsObject} */
|
||||
this.options.extractComments.filename || "[file].LICENSE.txt[query]";
|
||||
let query = "";
|
||||
let filename = name;
|
||||
const querySplit = filename.indexOf("?");
|
||||
if (querySplit >= 0) {
|
||||
query = filename.slice(querySplit);
|
||||
filename = filename.slice(0, querySplit);
|
||||
}
|
||||
const lastSlashIndex = filename.lastIndexOf("/");
|
||||
const basename = lastSlashIndex === -1 ? filename : filename.slice(lastSlashIndex + 1);
|
||||
const data = {
|
||||
filename,
|
||||
basename,
|
||||
query
|
||||
};
|
||||
output.commentsFilename = compilation.getPath(commentsFilename, data);
|
||||
let banner;
|
||||
|
||||
// Add a banner to the original file
|
||||
if ( /** @type {ExtractCommentsObject} */
|
||||
this.options.extractComments.banner !== false) {
|
||||
banner = /** @type {ExtractCommentsObject} */
|
||||
this.options.extractComments.banner || `For license information please see ${path.relative(path.dirname(name), output.commentsFilename).replace(/\\/g, "/")}`;
|
||||
if (typeof banner === "function") {
|
||||
banner = banner(output.commentsFilename);
|
||||
}
|
||||
if (banner) {
|
||||
output.source = new ConcatSource(shebang ? `${shebang}\n` : "", `/*! ${banner} */\n`, output.source);
|
||||
}
|
||||
}
|
||||
const extractedCommentsString = output.extractedComments.sort().join("\n\n");
|
||||
output.extractedCommentsSource = new RawSource(`${extractedCommentsString}\n`);
|
||||
}
|
||||
const extractedCommentsString = output.extractedComments.sort().join("\n\n");
|
||||
output.extractedCommentsSource = new RawSource(`${extractedCommentsString}\n`);
|
||||
}
|
||||
await cacheItem.storePromise({
|
||||
source: output.source,
|
||||
@@ -546,16 +550,19 @@ class TerserPlugin {
|
||||
}
|
||||
if (output.warnings && output.warnings.length > 0) {
|
||||
for (const warning of output.warnings) {
|
||||
compilation.warnings.push( /** @type {WebpackError} */warning);
|
||||
compilation.warnings.push(warning);
|
||||
}
|
||||
}
|
||||
if (output.errors && output.errors.length > 0) {
|
||||
for (const error of output.errors) {
|
||||
compilation.errors.push( /** @type {WebpackError} */error);
|
||||
compilation.errors.push(error);
|
||||
}
|
||||
}
|
||||
if (!output.source) {
|
||||
return;
|
||||
}
|
||||
|
||||
/** @type {Record<string, any>} */
|
||||
/** @type {AssetInfo} */
|
||||
const newInfo = {
|
||||
minimized: true
|
||||
};
|
||||
@@ -586,15 +593,15 @@ class TerserPlugin {
|
||||
await initializedWorker.end();
|
||||
}
|
||||
|
||||
/** @typedef {{ source: import("webpack").sources.Source, commentsFilename: string, from: string }} ExtractedCommentsInfoWIthFrom */
|
||||
await Array.from(allExtractedComments).sort().reduce(
|
||||
/** @typedef {{ source: import("webpack").sources.Source, commentsFilename: string, from: string }} ExtractedCommentsInfoWithFrom */
|
||||
await [...allExtractedComments].sort().reduce(
|
||||
/**
|
||||
* @param {Promise<unknown>} previousPromise
|
||||
* @param {[string, ExtractedCommentsInfo]} extractedComments
|
||||
* @returns {Promise<ExtractedCommentsInfoWIthFrom>}
|
||||
* @param {Promise<unknown>} previousPromise previous result
|
||||
* @param {[string, ExtractedCommentsInfo]} extractedComments extracted comments
|
||||
* @returns {Promise<ExtractedCommentsInfoWithFrom>} extract comments with info
|
||||
*/
|
||||
async (previousPromise, [from, value]) => {
|
||||
const previous = /** @type {ExtractedCommentsInfoWIthFrom | undefined} **/
|
||||
const previous = /** @type {ExtractedCommentsInfoWithFrom | undefined} * */
|
||||
await previousPromise;
|
||||
const {
|
||||
commentsFilename,
|
||||
@@ -610,7 +617,7 @@ class TerserPlugin {
|
||||
const eTag = [prevSource, extractedCommentsSource].map(item => cache.getLazyHashedEtag(item)).reduce((previousValue, currentValue) => cache.mergeEtags(previousValue, currentValue));
|
||||
let source = await cache.getPromise(name, eTag);
|
||||
if (!source) {
|
||||
source = new ConcatSource(Array.from(new Set([... /** @type {string}*/prevSource.source().split("\n\n"), ... /** @type {string}*/extractedCommentsSource.source().split("\n\n")])).join("\n\n"));
|
||||
source = new ConcatSource([...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);
|
||||
}
|
||||
compilation.updateAsset(commentsFilename, source);
|
||||
@@ -641,8 +648,8 @@ class TerserPlugin {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {any} environment
|
||||
* @returns {number}
|
||||
* @param {NonNullable<NonNullable<Configuration["output"]>["environment"]>} environment environment
|
||||
* @returns {number} ecma version
|
||||
*/
|
||||
static getEcmaVersion(environment) {
|
||||
// ES 6th
|
||||
@@ -658,7 +665,7 @@ class TerserPlugin {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Compiler} compiler
|
||||
* @param {Compiler} compiler compiler
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
@@ -685,7 +692,7 @@ class TerserPlugin {
|
||||
stats.hooks.print.for("asset.info.minimized").tap("terser-webpack-plugin", (minimized, {
|
||||
green,
|
||||
formatFlag
|
||||
}) => minimized ? /** @type {Function} */green( /** @type {Function} */formatFlag("minimized")) : "");
|
||||
}) => minimized ? /** @type {(text: string) => string} */green( /** @type {(flag: string) => string} */formatFlag("minimized")) : "");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user