| | |
| | | const MAX_MODULE_IDENTIFIER_LENGTH = 80; |
| | | |
| | | /** |
| | | * Returns if n is 1, singular, else plural. |
| | | * @param {number} n a number |
| | | * @param {string} singular singular |
| | | * @param {string} plural plural |
| | |
| | | const plural = (n, singular, plural) => (n === 1 ? singular : plural); |
| | | |
| | | /** |
| | | * Returns text. |
| | | * @param {Record<string, number>} sizes sizes by source type |
| | | * @param {StatsPrinterContext} options options |
| | | * @returns {string | undefined} text |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Gets resource name. |
| | | * @param {string | null} resource resource |
| | | * @returns {string} resource name for display |
| | | */ |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Returns prefix and module name. |
| | | * @param {string} name module name |
| | | * @returns {[string,string]} prefix and module name |
| | | * @returns {[string, string]} prefix and module name |
| | | */ |
| | | const getModuleName = (name) => { |
| | | const [, prefix, resource] = |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Returns joined string. |
| | | * @param {string} str string |
| | | * @param {(item: string) => string} fn function to apply to each line |
| | | * @returns {string} joined string |
| | |
| | | const mapLines = (str, fn) => str.split("\n").map(fn).join("\n"); |
| | | |
| | | /** |
| | | * Returns number as two digit string, leading 0. |
| | | * @param {number} n a number |
| | | * @returns {string} number as two digit string, leading 0 |
| | | */ |
| | | const twoDigit = (n) => (n >= 10 ? `${n}` : `0${n}`); |
| | | |
| | | /** |
| | | * Checks whether this object is valid id. |
| | | * @param {string | number | null} id an id |
| | | * @returns {id is string | number} is i |
| | | */ |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Returns string representation of list. |
| | | * @template T |
| | | * @param {T[] | undefined} list of items |
| | | * @param {number} count number of items to show |
| | |
| | | list && list.length > 0 ? `+ ${count}` : `${count}`; |
| | | |
| | | /** |
| | | * Defines the with required type used by this module. |
| | | * @template T |
| | | * @template {keyof T} K |
| | | * @typedef {{ [P in K]-?: T[P] }} WithRequired |
| | | */ |
| | | |
| | | /** |
| | | * Defines the define stats printer context type used by this module. |
| | | * @template {keyof StatsPrinterContext} RequiredStatsPrinterContextKeys |
| | | * @typedef {StatsPrinterContextWithExtra & WithRequired<StatsPrinterContext, "compilation" | RequiredStatsPrinterContextKeys>} DefineStatsPrinterContext |
| | | */ |
| | | |
| | | /** |
| | | * Defines the simple printer type used by this module. |
| | | * @template T |
| | | * @template {keyof StatsPrinterContext} RequiredStatsPrinterContextKeys |
| | | * @typedef {(thing: Exclude<T, undefined>, context: DefineStatsPrinterContext<RequiredStatsPrinterContextKeys>, printer: StatsPrinter) => string | undefined} SimplePrinter |
| | | */ |
| | | |
| | | /** |
| | | * Defines the unpacked type used by this module. |
| | | * @template T |
| | | * @typedef {T extends (infer U)[] ? U : T} Unpacked |
| | | */ |
| | | |
| | | /** |
| | | * Defines the property name type used by this module. |
| | | * @template {object} O |
| | | * @template {keyof O} K |
| | | * @template {string} B |
| | |
| | | */ |
| | | |
| | | /** |
| | | * Defines the array property name type used by this module. |
| | | * @template {object} O |
| | | * @template {keyof O} K |
| | | * @template {string} B |
| | |
| | | */ |
| | | |
| | | /** |
| | | * Defines the exclamation type used by this module. |
| | | * @template {object} O |
| | | * @template {string} K |
| | | * @template {string} E |
| | |
| | | */ |
| | | |
| | | /** |
| | | * Defines the shared type used by this module. |
| | | * @template {object} O |
| | | * @template {string} B |
| | | * @template {string} [R=B] |
| | |
| | | */ |
| | | |
| | | /** |
| | | * Defines the shared type used by this module. |
| | | * @typedef {Printers<KnownStatsCompilation, "compilation"> & |
| | | * { ["compilation.summary!"]?: SimplePrinter<KnownStatsCompilation, "compilation"> } & |
| | | * { ["compilation.errorsInChildren!"]?: SimplePrinter<KnownStatsCompilation, "compilation"> } & |
| | |
| | | nameMessage && versionMessage |
| | | ? `${nameMessage} (${versionMessage})` |
| | | : versionMessage || nameMessage || "webpack"; |
| | | /** @type {string} */ |
| | | let statusMessage; |
| | | if (errorsMessage && warningsMessage) { |
| | | statusMessage = `compiled with ${errorsMessage} and ${warningsMessage}`; |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Defines the shared type used by this module. |
| | | * @typedef {Printers<KnownStatsAsset, "asset"> & |
| | | * Printers<KnownStatsAsset["info"], "asset.info"> & |
| | | * Exclamation<KnownStatsAsset, "asset.separator", "asset"> & |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Defines the shared type used by this module. |
| | | * @typedef {Printers<KnownStatsModule, "module"> & |
| | | * Exclamation<KnownStatsModule, "module.separator", "module"> & |
| | | * { ["module.filteredChildren"]?: SimplePrinter<number, "module"> } & |
| | |
| | | }; |
| | | |
| | | /** |
| | | * @typedef {Printers<KnownStatsModuleIssuer, "moduleIssuer"> & |
| | | * Printers<KnownStatsModuleIssuer["profile"], "moduleIssuer.profile", "moduleIssuer">} ModuleIssuerPrinters |
| | | * Defines the module issuer printers type used by this module. |
| | | * @typedef {Printers<KnownStatsModuleIssuer, "moduleIssuer"> & Printers<KnownStatsModuleIssuer["profile"], "moduleIssuer.profile", "moduleIssuer">} ModuleIssuerPrinters |
| | | */ |
| | | |
| | | /** @type {ModuleIssuerPrinters} */ |
| | |
| | | }; |
| | | |
| | | /** |
| | | * @typedef {Printers<KnownStatsModuleReason, "moduleReason"> & |
| | | * { ["moduleReason.filteredChildren"]?: SimplePrinter<number, "moduleReason"> }} ModuleReasonsPrinters |
| | | * Defines the module reasons printers type used by this module. |
| | | * @typedef {Printers<KnownStatsModuleReason, "moduleReason"> & { ["moduleReason.filteredChildren"]?: SimplePrinter<number, "moduleReason"> }} ModuleReasonsPrinters |
| | | */ |
| | | |
| | | /** @type {ModuleReasonsPrinters} */ |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Defines the shared type used by this module. |
| | | * @typedef {Exclamation<KnownStatsChunkGroup, "chunkGroup.kind", "chunkGroupKind"> & |
| | | * Exclamation<KnownStatsChunkGroup, "chunkGroup.separator", "chunkGroup"> & |
| | | * Printers<KnownStatsChunkGroup, "chunkGroup"> & |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Defines the shared type used by this module. |
| | | * @typedef {Printers<KnownStatsChunk, "chunk"> & |
| | | * { ["chunk.childrenByOrder[].type"]: SimplePrinter<string, "chunk"> } & |
| | | * { ["chunk.childrenByOrder[].children[]"]: SimplePrinter<ChunkId, "chunk"> } & |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Defines the shared type used by this module. |
| | | * @typedef {Printers<KnownStatsError, "error"> & |
| | | * { ["error.filteredDetails"]?: SimplePrinter<number, "error"> } & |
| | | * Exclamation<KnownStatsError, "error.separator", "error">} ErrorPrinters |
| | |
| | | "error.file": (file, { bold }) => bold(file), |
| | | "error.moduleName": (moduleName, { bold }) => |
| | | moduleName.includes("!") |
| | | ? `${bold(moduleName.replace(/^(\s|\S)*!/, ""))} (${moduleName})` |
| | | ? `${bold(moduleName.replace(/^([\s\S])*!/, ""))} (${moduleName})` |
| | | : `${bold(moduleName)}`, |
| | | "error.loc": (loc, { green }) => green(loc), |
| | | "error.message": (message, { bold, formatError }) => |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Defines the shared type used by this module. |
| | | * @typedef {Printers<KnownStatsLoggingEntry, `loggingEntry(${LogTypeEnum}).loggingEntry`> & |
| | | * { ["loggingEntry(clear).loggingEntry"]?: SimplePrinter<KnownStatsLoggingEntry, "logging"> } & |
| | | * { ["loggingEntry.trace[]"]?: SimplePrinter<Exclude<KnownStatsLoggingEntry["trace"], undefined>[number], "logging"> } & |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Returns result. |
| | | * @param {Item[]} items items |
| | | * @returns {string} result |
| | | */ |
| | |
| | | .join(" "); |
| | | |
| | | /** |
| | | * Returns result. |
| | | * @param {Item[]} items items |
| | | * @returns {string} result |
| | | */ |
| | | const joinInBrackets = (items) => { |
| | | /** @type {string[]} */ |
| | | const res = []; |
| | | let mode = 0; |
| | | for (const item of items) { |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Returns result. |
| | | * @param {string} str a string |
| | | * @param {string} prefix prefix |
| | | * @param {boolean=} noPrefixInFirstLine need prefix in the first line? |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Join explicit new line. |
| | | * @param {(false | Item)[]} items items |
| | | * @param {string} indenter indenter |
| | | * @returns {string} result |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Returns joiner. |
| | | * @param {boolean} error is an error |
| | | * @returns {SimpleElementJoiner} joiner |
| | | */ |
| | | const joinError = |
| | | (error) => |
| | | /** |
| | | * Handles the callback logic for this hook. |
| | | * @param {Item[]} items items |
| | | * @param {StatsPrinterContextWithExtra} ctx context |
| | | * @returns {string} result |
| | |
| | | /** @type {Record<string, SimpleElementJoiner>} */ |
| | | const SIMPLE_ELEMENT_JOINERS = { |
| | | compilation: (items) => { |
| | | /** @type {string[]} */ |
| | | const result = []; |
| | | let lastNeedMore = false; |
| | | for (const item of items) { |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Defines the tail type used by this module. |
| | | * @template T |
| | | * @typedef {T extends [infer Head, ...infer Tail] ? Tail : undefined} Tail |
| | | */ |
| | | |
| | | /** |
| | | * Defines the tail parameters type used by this module. |
| | | * @template {(...args: EXPECTED_ANY[]) => EXPECTED_ANY} T |
| | | * @typedef {T extends (firstArg: EXPECTED_ANY, ...rest: infer R) => EXPECTED_ANY ? R : never} TailParameters |
| | | */ |
| | |
| | | message = message.replace( |
| | | regExp, |
| | | /** |
| | | * Handles the format callback for this hook. |
| | | * @param {string} match match |
| | | * @param {string} content content |
| | | * @returns {string} result |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Creates an order from the provided array. |
| | | * @param {string[]} array array |
| | | * @param {string[]} preferredOrder preferred order |
| | | * @returns {string[]} result |
| | |
| | | |
| | | class DefaultStatsPrinterPlugin { |
| | | /** |
| | | * Apply the plugin |
| | | * Applies the plugin by registering its hooks on the compiler. |
| | | * @param {Compiler} compiler the compiler instance |
| | | * @returns {void} |
| | | */ |
| | |
| | | }\u001B[39m\u001B[22m`; |
| | | } else { |
| | | /** |
| | | * Returns str string. |
| | | * @param {string} str string |
| | | * @returns {string} str string |
| | | */ |