| | |
| | | /** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */ |
| | | /** @typedef {import("../ModuleProfile")} ModuleProfile */ |
| | | /** @typedef {import("../WebpackError")} WebpackError */ |
| | | /** @typedef {import("../serialization/AggregateErrorSerializer").AggregateError} AggregateError */ |
| | | /** @typedef {import("../serialization/ErrorObjectSerializer").ErrorWithCause} ErrorWithCause */ |
| | | /** @typedef {import("../ExportsInfo").ExportInfoName} ExportInfoName */ |
| | | |
| | | /** |
| | | * Defines the shared type used by this module. |
| | | * @template T |
| | | * @typedef {import("../util/comparators").Comparator<T>} Comparator<T> |
| | | */ |
| | | |
| | | /** |
| | | * Defines the group config type used by this module. |
| | | * @template I, G |
| | | * @typedef {import("../util/smartGrouping").GroupConfig<I, G>} GroupConfig |
| | | */ |
| | | |
| | | /** @typedef {KnownStatsCompilation & Record<string, EXPECTED_ANY>} StatsCompilation */ |
| | | /** |
| | | * Defines the known stats compilation type used by this module. |
| | | * @typedef {object} KnownStatsCompilation |
| | | * @property {EXPECTED_ANY=} env |
| | | * @property {string=} name |
| | |
| | | |
| | | /** @typedef {KnownStatsLogging & Record<string, EXPECTED_ANY>} StatsLogging */ |
| | | /** |
| | | * Defines the known stats logging type used by this module. |
| | | * @typedef {object} KnownStatsLogging |
| | | * @property {StatsLoggingEntry[]} entries |
| | | * @property {number} filteredEntries |
| | |
| | | |
| | | /** @typedef {KnownStatsLoggingEntry & Record<string, EXPECTED_ANY>} StatsLoggingEntry */ |
| | | /** |
| | | * Defines the known stats logging entry type used by this module. |
| | | * @typedef {object} KnownStatsLoggingEntry |
| | | * @property {string} type |
| | | * @property {string=} message |
| | |
| | | /** @typedef {KnownStatsAsset & Record<string, EXPECTED_ANY>} StatsAsset */ |
| | | /** @typedef {string[]} ChunkIdHints */ |
| | | /** |
| | | * Defines the known stats asset type used by this module. |
| | | * @typedef {object} KnownStatsAsset |
| | | * @property {string} type |
| | | * @property {string} name |
| | |
| | | |
| | | /** @typedef {KnownStatsChunkGroup & Record<string, EXPECTED_ANY>} StatsChunkGroup */ |
| | | /** |
| | | * Defines the known stats chunk group type used by this module. |
| | | * @typedef {object} KnownStatsChunkGroup |
| | | * @property {ChunkName=} name |
| | | * @property {ChunkId[]=} chunks |
| | |
| | | /** @typedef {Module[]} ModuleIssuerPath */ |
| | | /** @typedef {KnownStatsModule & Record<string, EXPECTED_ANY>} StatsModule */ |
| | | /** |
| | | * Defines the known stats module type used by this module. |
| | | * @typedef {object} KnownStatsModule |
| | | * @property {string=} type |
| | | * @property {string=} moduleType |
| | |
| | | |
| | | /** @typedef {KnownStatsProfile & Record<string, EXPECTED_ANY>} StatsProfile */ |
| | | /** |
| | | * Defines the known stats profile type used by this module. |
| | | * @typedef {object} KnownStatsProfile |
| | | * @property {number} total |
| | | * @property {number} resolving |
| | |
| | | |
| | | /** @typedef {KnownStatsModuleIssuer & Record<string, EXPECTED_ANY>} StatsModuleIssuer */ |
| | | /** |
| | | * Defines the known stats module issuer type used by this module. |
| | | * @typedef {object} KnownStatsModuleIssuer |
| | | * @property {string} identifier |
| | | * @property {string} name |
| | |
| | | |
| | | /** @typedef {KnownStatsModuleReason & Record<string, EXPECTED_ANY>} StatsModuleReason */ |
| | | /** |
| | | * Defines the known stats module reason type used by this module. |
| | | * @typedef {object} KnownStatsModuleReason |
| | | * @property {string | null} moduleIdentifier |
| | | * @property {string | null} module |
| | |
| | | |
| | | /** @typedef {KnownStatsChunk & Record<string, EXPECTED_ANY>} StatsChunk */ |
| | | /** |
| | | * Defines the known stats chunk type used by this module. |
| | | * @typedef {object} KnownStatsChunk |
| | | * @property {boolean} rendered |
| | | * @property {boolean} initial |
| | |
| | | |
| | | /** @typedef {KnownStatsChunkOrigin & Record<string, EXPECTED_ANY>} StatsChunkOrigin */ |
| | | /** |
| | | * Defines the known stats chunk origin type used by this module. |
| | | * @typedef {object} KnownStatsChunkOrigin |
| | | * @property {string} module |
| | | * @property {string} moduleIdentifier |
| | |
| | | |
| | | /** @typedef {KnownStatsModuleTraceItem & Record<string, EXPECTED_ANY>} StatsModuleTraceItem */ |
| | | /** |
| | | * Defines the known stats module trace item type used by this module. |
| | | * @typedef {object} KnownStatsModuleTraceItem |
| | | * @property {string=} originIdentifier |
| | | * @property {string=} originName |
| | |
| | | |
| | | /** @typedef {KnownStatsModuleTraceDependency & Record<string, EXPECTED_ANY>} StatsModuleTraceDependency */ |
| | | /** |
| | | * Defines the known stats module trace dependency type used by this module. |
| | | * @typedef {object} KnownStatsModuleTraceDependency |
| | | * @property {string=} loc |
| | | */ |
| | | |
| | | /** @typedef {KnownStatsError & Record<string, EXPECTED_ANY>} StatsError */ |
| | | /** |
| | | * Defines the known stats error type used by this module. |
| | | * @typedef {object} KnownStatsError |
| | | * @property {string} message |
| | | * @property {string=} chunkName |
| | |
| | | /** @typedef {Asset & { type: string, related: PreprocessedAsset[] | undefined }} PreprocessedAsset */ |
| | | |
| | | /** |
| | | * Defines the extractors by option type used by this module. |
| | | * @template T |
| | | * @template O |
| | | * @typedef {Record<string, (object: O, data: T, context: StatsFactoryContext, options: NormalizedStatsOptions, factory: StatsFactory) => void>} ExtractorsByOption |
| | |
| | | /** @typedef {{ origin: Module, module: Module }} ModuleTrace */ |
| | | |
| | | /** |
| | | * Defines the simple extractors type used by this module. |
| | | * @typedef {object} SimpleExtractors |
| | | * @property {ExtractorsByOption<Compilation, StatsCompilation>} compilation |
| | | * @property {ExtractorsByOption<PreprocessedAsset, StatsAsset>} asset |
| | |
| | | */ |
| | | |
| | | /** |
| | | * Returns array of values. |
| | | * @template T |
| | | * @template I |
| | | * @param {Iterable<T>} items items to select from |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Unique ordered array. |
| | | * @template T |
| | | * @template I |
| | | * @param {Iterable<T>} items items to select from |
| | |
| | | const uniqueOrderedArray = (items, selector, comparator) => |
| | | uniqueArray(items, selector).sort(comparator); |
| | | |
| | | /** @template T @template R @typedef {{ [P in keyof T]: R }} MappedValues<T, R> */ |
| | | /** |
| | | * Defines the shared type used by this module. |
| | | * @template T |
| | | * @template R |
| | | * @typedef {{ [P in keyof T]: R }} MappedValues<T, R> |
| | | */ |
| | | |
| | | /** |
| | | * Returns mapped object. |
| | | * @template {object} T |
| | | * @template {object} R |
| | | * @param {T} obj object to be mapped |
| | | * @param {function(T[keyof T], keyof T): R} fn mapping function |
| | | * @param {(value: T[keyof T], key: keyof T) => R} fn mapping function |
| | | * @returns {MappedValues<T, R>} mapped object |
| | | */ |
| | | const mapObject = (obj, fn) => { |
| | | /** @type {MappedValues<T, R>} */ |
| | | const newObj = Object.create(null); |
| | | for (const key of Object.keys(obj)) { |
| | | newObj[key] = fn( |
| | | obj[/** @type {keyof T} */ (key)], |
| | | /** @type {keyof T} */ (key) |
| | | ); |
| | | for (const key of /** @type {(keyof T)[]} */ (Object.keys(obj))) { |
| | | newObj[key] = fn(obj[key], key); |
| | | } |
| | | return newObj; |
| | | }; |
| | | |
| | | /** |
| | | * Count with children. |
| | | * @template T |
| | | * @param {Compilation} compilation the compilation |
| | | * @param {(compilation: Compilation, name: string) => T[]} getItems get items |
| | |
| | | } |
| | | return count; |
| | | }; |
| | | |
| | | /** @typedef {Error & { cause?: unknown }} ErrorWithCause */ |
| | | /** @typedef {Error & { errors: EXPECTED_ANY[] }} AggregateError */ |
| | | |
| | | /** @type {ExtractorsByOption<string | ErrorWithCause | AggregateError | WebpackError, StatsError>} */ |
| | | const EXTRACT_ERROR = { |
| | |
| | | object.details = /** @type {WebpackError} */ (error).details; |
| | | } |
| | | }, |
| | | errorStack: (object, error) => { |
| | | if (typeof error !== "string") { |
| | | errorStack: (object, error, _context, { errorStack }) => { |
| | | if (typeof error !== "string" && errorStack) { |
| | | object.stack = error.stack; |
| | | } |
| | | }, |
| | |
| | | } |
| | | } |
| | | }; |
| | | |
| | | /** @typedef {((value: string) => boolean)} FilterItemTypeFn */ |
| | | |
| | | /** @type {SimpleExtractors} */ |
| | | const SIMPLE_EXTRACTORS = { |
| | |
| | | const util = require("util"); |
| | | |
| | | object.logging = {}; |
| | | /** @type {Set<keyof LogType>} */ |
| | | let acceptedTypes; |
| | | let collapsedGroups = false; |
| | | switch (logging) { |
| | |
| | | if (depthInCollapsedGroup > 0) depthInCollapsedGroup--; |
| | | continue; |
| | | } |
| | | /** @type {undefined | string} */ |
| | | let message; |
| | | if (entry.type === LogType.time) { |
| | | const [label, first, second] = |
| | |
| | | .create(`${type}${childType}.warnings`, cachedGetWarnings(c), context) |
| | | .filter( |
| | | /** |
| | | * Handles the warnings count callback for this hook. |
| | | * @param {StatsError} warning warning |
| | | * @returns {boolean} result |
| | | */ |
| | |
| | | chunkGroupChildren && |
| | | chunkGroup.getChildrenByOrders(moduleGraph, chunkGraph); |
| | | /** |
| | | * Returns } Asset object. |
| | | * @param {string} name Name |
| | | * @returns {{ name: string, size: number }} Asset object |
| | | */ |
| | |
| | | const codeGenerated = compilation.codeGeneratedModules.has(module); |
| | | const buildTimeExecuted = |
| | | compilation.buildTimeExecutedModules.has(module); |
| | | /** @type {{[x: string]: number}} */ |
| | | /** @type {{ [x: string]: number }} */ |
| | | const sizes = {}; |
| | | for (const sourceType of module.getSourceTypes()) { |
| | | sizes[sourceType] = module.size(sourceType); |
| | |
| | | concatComparators( |
| | | compareSelect( |
| | | /** |
| | | * Handles the callback for this hook. |
| | | * @param {Dependency} x dependency |
| | | * @returns {DependencyLocation} location |
| | | */ |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Defines the children type used by this module. |
| | | * @template T |
| | | * @typedef {T & { children?: Children<T>[] | undefined, filteredChildren?: number }} Children |
| | | */ |
| | | |
| | | /** |
| | | * Returns item size. |
| | | * @template T |
| | | * @param {Children<T>} item item |
| | | * @returns {number} item size |
| | |
| | | : 1 + getTotalSize(item.children); |
| | | |
| | | /** |
| | | * Returns total size. |
| | | * @template T |
| | | * @param {Children<T>[]} children children |
| | | * @returns {number} total size |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Returns total items. |
| | | * @template T |
| | | * @param {Children<T>[]} children children |
| | | * @returns {number} total items |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Returns collapsed children. |
| | | * @template T |
| | | * @param {Children<T>[]} children children |
| | | * @returns {Children<T>[]} collapsed children |
| | | */ |
| | | const collapse = (children) => { |
| | | // After collapse each child must take exactly one line |
| | | /** @type {Children<T>[]} */ |
| | | const newChildren = []; |
| | | for (const child of children) { |
| | | if (child.children) { |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Returns result. |
| | | * @template T |
| | | * @param {Children<T>[]} itemsAndGroups item and groups |
| | | * @param {number} max max |
| | |
| | | /** @type {number[]} */ |
| | | const groupSizes = []; |
| | | // This are the items, which take 1 line each |
| | | /** @type {Children<T>[]} */ |
| | | const items = []; |
| | | // The total of group sizes |
| | | let groupsSize = 0; |
| | |
| | | if (limit < max) { |
| | | // calculate how much we are over the size limit |
| | | // this allows to approach the limit faster |
| | | /** @type {number} */ |
| | | let oversize; |
| | | // If each group would take 1 line the total would be below the maximum |
| | | // collapse some groups, keep items |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Errors space limit. |
| | | * @param {StatsError[]} errors errors |
| | | * @param {number} max max |
| | | * @returns {[StatsError[], number]} error space limit |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Returns } asset size. |
| | | * @template {{ size: number }} T |
| | | * @param {T[]} children children |
| | | * @param {T[]} assets assets |
| | |
| | | /** @typedef {{ size: number, sizes: Record<string, number> }} ModuleGroupBySizeResult */ |
| | | |
| | | /** |
| | | * Returns size and sizes. |
| | | * @template {ModuleGroupBySizeResult} T |
| | | * @param {Children<T>[]} children children |
| | | * @param {KnownStatsModule[]} modules modules |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Returns } reason group. |
| | | * @template {{ active: boolean }} T |
| | | * @param {Children<T>[]} children children |
| | | * @param {KnownStatsModuleReason[]} reasons reasons |
| | |
| | | /** @typedef {{ type: string }} BaseGroup */ |
| | | |
| | | /** |
| | | * Defines the base group with children type used by this module. |
| | | * @template T |
| | | * @typedef {BaseGroup & { children: T[], size: number }} BaseGroupWithChildren |
| | | */ |
| | | |
| | | /** @typedef {(name: string, asset: StatsAsset) => boolean} AssetFilterItemFn */ |
| | | |
| | | /** |
| | | * Describes the assets groupers shape. |
| | | * @typedef {{ |
| | | * _: (groupConfigs: GroupConfig<KnownStatsAsset, BaseGroup & { filteredChildren: number, size: number } | BaseGroupWithChildren<KnownStatsAsset>>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void, |
| | | * groupAssetsByInfo: (groupConfigs: GroupConfig<KnownStatsAsset, BaseGroupWithChildren<KnownStatsAsset>>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void, |
| | |
| | | const ASSETS_GROUPERS = { |
| | | _: (groupConfigs, context, options) => { |
| | | /** |
| | | * Processes the provided name. |
| | | * @param {keyof KnownStatsAsset} name name |
| | | * @param {boolean=} exclude need exclude? |
| | | */ |
| | |
| | | }, |
| | | groupAssetsByInfo: (groupConfigs, _context, _options) => { |
| | | /** |
| | | * Group by asset info flag. |
| | | * @param {string} name name |
| | | */ |
| | | const groupByAssetInfoFlag = (name) => { |
| | |
| | | }, |
| | | groupAssetsByChunk: (groupConfigs, _context, _options) => { |
| | | /** |
| | | * Processes the provided name. |
| | | * @param {keyof KnownStatsAsset} name name |
| | | */ |
| | | const groupByNames = (name) => { |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Describes the modules groupers shape. |
| | | * @typedef {{ |
| | | * _: (groupConfigs: GroupConfig<KnownStatsModule, BaseGroup & { filteredChildren?: number, children?: KnownStatsModule[], size: number, sizes: Record<string, number> }>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void, |
| | | * excludeModules: (groupConfigs: GroupConfig<KnownStatsModule, BaseGroup & { filteredChildren: number, size: number, sizes: Record<string, number> }>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void, |
| | | * }} ModulesGroupers |
| | | */ |
| | | |
| | | /** @typedef {(name: string, module: StatsModule, type: "module" | "chunk" | "root-of-chunk" | "nested") => boolean} ModuleFilterItemTypeFn */ |
| | | |
| | | /** |
| | | * @type {(type: ExcludeModulesType) => ModulesGroupers} |
| | |
| | | const MODULES_GROUPERS = (type) => ({ |
| | | _: (groupConfigs, context, options) => { |
| | | /** |
| | | * Processes the provided name. |
| | | * @param {keyof KnownStatsModule} name name |
| | | * @param {string} type type |
| | | * @param {boolean=} exclude need exclude? |
| | |
| | | const pathMatch = |
| | | groupModulesByPath && GROUP_PATH_REGEXP.exec(resource); |
| | | const path = pathMatch ? pathMatch[1].split(/[/\\]/) : []; |
| | | /** @type {string[]} */ |
| | | const keys = []; |
| | | if (groupModulesByPath) { |
| | | if (extension) { |
| | |
| | | }); |
| | | |
| | | /** |
| | | * @typedef {{ |
| | | * groupReasonsByOrigin: (groupConfigs: GroupConfig<KnownStatsModuleReason, BaseGroup & { module: string, children: KnownStatsModuleReason[], active: boolean }>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void |
| | | * }} ModuleReasonsGroupers |
| | | * Defines the module reasons groupers type used by this module. |
| | | * @typedef {{ groupReasonsByOrigin: (groupConfigs: GroupConfig<KnownStatsModuleReason, BaseGroup & { module: string, children: KnownStatsModuleReason[], active: boolean }>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void }} ModuleReasonsGroupers |
| | | */ |
| | | |
| | | /** @type {ModuleReasonsGroupers} */ |
| | |
| | | |
| | | // remove a prefixed "!" that can be specified to reverse sort order |
| | | /** |
| | | * Normalizes field key. |
| | | * @param {string} field a field name |
| | | * @returns {field} normalized field |
| | | */ |
| | |
| | | |
| | | // if a field is prefixed by a "!" reverse sort order |
| | | /** |
| | | * Sorts order regular. |
| | | * @param {string} field a field name |
| | | * @returns {boolean} result |
| | | */ |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Returns comparators. |
| | | * @template T |
| | | * @param {string | false} field field name |
| | | * @returns {(a: T, b: T) => 0 | 1 | -1} comparators |
| | |
| | | const sortByField = (field) => { |
| | | if (!field) { |
| | | /** |
| | | * Returns zero. |
| | | * @param {T} a first |
| | | * @param {T} b second |
| | | * @returns {-1 | 0 | 1} zero |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Describes the asset sorters shape. |
| | | * @typedef {{ |
| | | * assetsSort: (comparators: Comparator<Asset>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void, |
| | | * _: (comparators: Comparator<Asset>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void |
| | | * _: (comparators: Comparator<Asset>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void, |
| | | * }} AssetSorters |
| | | */ |
| | | |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Defines the extract function type used by this module. |
| | | * @template T |
| | | * @typedef {T extends Record<string, Record<string, infer F>> ? F : never} ExtractFunction |
| | | */ |
| | | |
| | | /** |
| | | * Processes the provided config. |
| | | * @template {Record<string, Record<string, EXPECTED_ANY>>} T |
| | | * @param {T} config the config see above |
| | | * @param {NormalizedStatsOptions} options stats options |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Defines the named object type used by this module. |
| | | * @template T |
| | | * @typedef {{ name: T }} NamedObject |
| | | */ |
| | | |
| | | /** |
| | | * Merges the provided values into a single result. |
| | | * @template {{ name: string }} T |
| | | * @param {T[]} items items to be merged |
| | | * @returns {NamedObject<T>} an object |
| | |
| | | |
| | | class DefaultStatsFactoryPlugin { |
| | | /** |
| | | * Apply the plugin |
| | | * Applies the plugin by registering its hooks on the compiler. |
| | | * @param {Compiler} compiler the compiler instance |
| | | * @returns {void} |
| | | */ |
| | |
| | | compilation.hooks.statsFactory.tap( |
| | | PLUGIN_NAME, |
| | | /** |
| | | * Handles the callback logic for this hook. |
| | | * @param {StatsFactory} stats stats factory |
| | | * @param {NormalizedStatsOptions} options stats options |
| | | */ |
| | |
| | | .tap( |
| | | PLUGIN_NAME, |
| | | /** |
| | | * Handles the callback logic for this hook. |
| | | * @param {Compilation} comp compilation |
| | | * @param {StatsFactoryContext} options options |
| | | * @returns {StatsFactory | undefined} stats factory |