WXL
3 天以前 9bce51f651aad297ef9eb6df832bfdaf1de05d84
node_modules/webpack/lib/stats/DefaultStatsFactoryPlugin.js
@@ -49,20 +49,25 @@
/** @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
@@ -93,6 +98,7 @@
/** @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
@@ -101,6 +107,7 @@
/** @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
@@ -113,6 +120,7 @@
/** @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
@@ -134,6 +142,7 @@
/** @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
@@ -151,6 +160,7 @@
/** @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
@@ -195,6 +205,7 @@
/** @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
@@ -210,6 +221,7 @@
/** @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
@@ -219,6 +231,7 @@
/** @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
@@ -236,6 +249,7 @@
/** @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
@@ -262,6 +276,7 @@
/** @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
@@ -273,6 +288,7 @@
/** @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
@@ -285,12 +301,14 @@
/** @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
@@ -313,6 +331,7 @@
/** @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
@@ -322,6 +341,7 @@
/** @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
@@ -342,6 +362,7 @@
 */
/**
 * Returns array of values.
 * @template T
 * @template I
 * @param {Iterable<T>} items items to select from
@@ -360,6 +381,7 @@
};
/**
 * Unique ordered array.
 * @template T
 * @template I
 * @param {Iterable<T>} items items to select from
@@ -370,27 +392,32 @@
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
@@ -405,9 +432,6 @@
   }
   return count;
};
/** @typedef {Error & { cause?: unknown }} ErrorWithCause */
/** @typedef {Error & { errors: EXPECTED_ANY[] }} AggregateError */
/** @type {ExtractorsByOption<string | ErrorWithCause | AggregateError | WebpackError, StatsError>} */
const EXTRACT_ERROR = {
@@ -504,8 +528,8 @@
         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;
      }
   },
@@ -541,6 +565,8 @@
      }
   }
};
/** @typedef {((value: string) => boolean)} FilterItemTypeFn */
/** @type {SimpleExtractors} */
const SIMPLE_EXTRACTORS = {
@@ -584,6 +610,7 @@
            const util = require("util");
            object.logging = {};
            /** @type {Set<keyof LogType>} */
            let acceptedTypes;
            let collapsedGroups = false;
            switch (logging) {
@@ -674,6 +701,7 @@
                     if (depthInCollapsedGroup > 0) depthInCollapsedGroup--;
                     continue;
                  }
                  /** @type {undefined | string} */
                  let message;
                  if (entry.type === LogType.time) {
                     const [label, first, second] =
@@ -993,6 +1021,7 @@
               .create(`${type}${childType}.warnings`, cachedGetWarnings(c), context)
               .filter(
                  /**
                   * Handles the warnings count callback for this hook.
                   * @param {StatsError} warning warning
                   * @returns {boolean} result
                   */
@@ -1117,6 +1146,7 @@
            chunkGroupChildren &&
            chunkGroup.getChildrenByOrders(moduleGraph, chunkGraph);
         /**
          * Returns } Asset object.
          * @param {string} name Name
          * @returns {{ name: string, size: number }} Asset object
          */
@@ -1226,7 +1256,7 @@
         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);
@@ -1738,6 +1768,7 @@
               concatComparators(
                  compareSelect(
                     /**
                      * Handles the  callback for this hook.
                      * @param {Dependency} x dependency
                      * @returns {DependencyLocation} location
                      */
@@ -1766,11 +1797,13 @@
};
/**
 * 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
@@ -1786,6 +1819,7 @@
         : 1 + getTotalSize(item.children);
/**
 * Returns total size.
 * @template T
 * @param {Children<T>[]} children children
 * @returns {number} total size
@@ -1799,6 +1833,7 @@
};
/**
 * Returns total items.
 * @template T
 * @param {Children<T>[]} children children
 * @returns {number} total items
@@ -1817,12 +1852,14 @@
};
/**
 * 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) {
@@ -1841,6 +1878,7 @@
};
/**
 * Returns result.
 * @template T
 * @param {Children<T>[]} itemsAndGroups item and groups
 * @param {number} max max
@@ -1869,6 +1907,7 @@
   /** @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;
@@ -1904,6 +1943,7 @@
      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
@@ -1968,6 +2008,7 @@
};
/**
 * Errors space limit.
 * @param {StatsError[]} errors errors
 * @param {number} max max
 * @returns {[StatsError[], number]} error space limit
@@ -2031,6 +2072,7 @@
};
/**
 * Returns } asset size.
 * @template {{ size: number }} T
 * @param {T[]} children children
 * @param {T[]} assets assets
@@ -2047,6 +2089,7 @@
/** @typedef {{ size: number, sizes: Record<string, number> }} ModuleGroupBySizeResult */
/**
 * Returns size and sizes.
 * @template {ModuleGroupBySizeResult} T
 * @param {Children<T>[]} children children
 * @param {KnownStatsModule[]} modules modules
@@ -2069,6 +2112,7 @@
};
/**
 * Returns } reason group.
 * @template {{ active: boolean }} T
 * @param {Children<T>[]} children children
 * @param {KnownStatsModuleReason[]} reasons reasons
@@ -2090,11 +2134,15 @@
/** @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,
@@ -2107,6 +2155,7 @@
const ASSETS_GROUPERS = {
   _: (groupConfigs, context, options) => {
      /**
       * Processes the provided name.
       * @param {keyof KnownStatsAsset} name name
       * @param {boolean=} exclude need exclude?
       */
@@ -2186,6 +2235,7 @@
   },
   groupAssetsByInfo: (groupConfigs, _context, _options) => {
      /**
       * Group by asset info flag.
       * @param {string} name name
       */
      const groupByAssetInfoFlag = (name) => {
@@ -2208,6 +2258,7 @@
   },
   groupAssetsByChunk: (groupConfigs, _context, _options) => {
      /**
       * Processes the provided name.
       * @param {keyof KnownStatsAsset} name name
       */
      const groupByNames = (name) => {
@@ -2247,11 +2298,14 @@
};
/**
 * 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}
@@ -2259,6 +2313,7 @@
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?
@@ -2374,6 +2429,7 @@
               const pathMatch =
                  groupModulesByPath && GROUP_PATH_REGEXP.exec(resource);
               const path = pathMatch ? pathMatch[1].split(/[/\\]/) : [];
               /** @type {string[]} */
               const keys = [];
               if (groupModulesByPath) {
                  if (extension) {
@@ -2439,9 +2495,8 @@
});
/**
 * @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} */
@@ -2482,6 +2537,7 @@
// remove a prefixed "!" that can be specified to reverse sort order
/**
 * Normalizes field key.
 * @param {string} field a field name
 * @returns {field} normalized field
 */
@@ -2494,6 +2550,7 @@
// if a field is prefixed by a "!" reverse sort order
/**
 * Sorts order regular.
 * @param {string} field a field name
 * @returns {boolean} result
 */
@@ -2505,6 +2562,7 @@
};
/**
 * Returns comparators.
 * @template T
 * @param {string | false} field field name
 * @returns {(a: T, b: T) => 0 | 1 | -1} comparators
@@ -2512,6 +2570,7 @@
const sortByField = (field) => {
   if (!field) {
      /**
       * Returns zero.
       * @param {T} a first
       * @param {T} b second
       * @returns {-1 | 0 | 1} zero
@@ -2536,9 +2595,10 @@
};
/**
 * 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
 */
@@ -2588,11 +2648,13 @@
};
/**
 * 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
@@ -2647,11 +2709,13 @@
};
/**
 * 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
@@ -2677,7 +2741,7 @@
class DefaultStatsFactoryPlugin {
   /**
    * Apply the plugin
    * Applies the plugin by registering its hooks on the compiler.
    * @param {Compiler} compiler the compiler instance
    * @returns {void}
    */
@@ -2686,6 +2750,7 @@
         compilation.hooks.statsFactory.tap(
            PLUGIN_NAME,
            /**
             * Handles the callback logic for this hook.
             * @param {StatsFactory} stats stats factory
             * @param {NormalizedStatsOptions} options stats options
             */
@@ -2747,6 +2812,7 @@
                        .tap(
                           PLUGIN_NAME,
                           /**
                            * Handles the callback logic for this hook.
                            * @param {Compilation} comp compilation
                            * @param {StatsFactoryContext} options options
                            * @returns {StatsFactory | undefined} stats factory