| | |
| | | /** @typedef {import("../ChunkGraph")} ChunkGraph */ |
| | | /** @typedef {import("../Compilation")} Compilation */ |
| | | /** @typedef {import("../Module")} Module */ |
| | | /** @typedef {typeof import("../util/Hash")} Hash */ |
| | | /** @typedef {import("../util/Hash").HashFunction} HashFunction */ |
| | | /** @typedef {import("../util/identifier").AssociatedObjectForCache} AssociatedObjectForCache */ |
| | | /** @typedef {import("../Module").BuildMeta} BuildMeta */ |
| | | |
| | | /** |
| | | * Returns hash. |
| | | * @param {string} str string to hash |
| | | * @param {number} len max length of the hash |
| | | * @param {string | Hash} hashFunction hash function to use |
| | | * @param {HashFunction} hashFunction hash function to use |
| | | * @returns {string} hash |
| | | */ |
| | | const getHash = (str, len, hashFunction) => { |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Returns string prefixed by an underscore if it is a number. |
| | | * @param {string} str the string |
| | | * @returns {string} string prefixed by an underscore if it is a number |
| | | */ |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Returns id representation. |
| | | * @param {string} request the request |
| | | * @returns {string} id representation |
| | | */ |
| | | const requestToId = (request) => |
| | | request.replace(/^(\.\.?\/)+/, "").replace(/(^[.-]|[^a-zA-Z0-9_-])+/g, "_"); |
| | | request.replace(/^(\.\.?\/)+/, "").replace(/(^[.-]|[^a-z0-9_-])+/gi, "_"); |
| | | |
| | | /** |
| | | * Shorten long string. |
| | | * @param {string} string the string |
| | | * @param {string} delimiter separator for string and hash |
| | | * @param {string | Hash} hashFunction hash function to use |
| | | * @param {HashFunction} hashFunction hash function to use |
| | | * @returns {string} string with limited max length to 100 chars |
| | | */ |
| | | const shortenLongString = (string, delimiter, hashFunction) => { |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Gets short module name. |
| | | * @param {Module} module the module |
| | | * @param {string} context context directory |
| | | * @param {AssociatedObjectForCache=} associatedObjectForCache an object to which the cache will be attached |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Gets long module name. |
| | | * @param {string} shortName the short name |
| | | * @param {Module} module the module |
| | | * @param {string} context context directory |
| | | * @param {string | Hash} hashFunction hash function to use |
| | | * @param {HashFunction} hashFunction hash function to use |
| | | * @param {AssociatedObjectForCache=} associatedObjectForCache an object to which the cache will be attached |
| | | * @returns {string} long module name |
| | | */ |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Gets full module name. |
| | | * @param {Module} module the module |
| | | * @param {string} context context directory |
| | | * @param {AssociatedObjectForCache=} associatedObjectForCache an object to which the cache will be attached |
| | |
| | | makePathsRelative(context, module.identifier(), associatedObjectForCache); |
| | | |
| | | /** |
| | | * Gets short chunk name. |
| | | * @param {Chunk} chunk the chunk |
| | | * @param {ChunkGraph} chunkGraph the chunk graph |
| | | * @param {string} context context directory |
| | | * @param {string} delimiter delimiter for names |
| | | * @param {string | Hash} hashFunction hash function to use |
| | | * @param {HashFunction} hashFunction hash function to use |
| | | * @param {AssociatedObjectForCache=} associatedObjectForCache an object to which the cache will be attached |
| | | * @returns {string} short chunk name |
| | | */ |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Gets long chunk name. |
| | | * @param {Chunk} chunk the chunk |
| | | * @param {ChunkGraph} chunkGraph the chunk graph |
| | | * @param {string} context context directory |
| | | * @param {string} delimiter delimiter for names |
| | | * @param {string | Hash} hashFunction hash function to use |
| | | * @param {HashFunction} hashFunction hash function to use |
| | | * @param {AssociatedObjectForCache=} associatedObjectForCache an object to which the cache will be attached |
| | | * @returns {string} short chunk name |
| | | */ |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Gets full chunk name. |
| | | * @param {Chunk} chunk the chunk |
| | | * @param {ChunkGraph} chunkGraph the chunk graph |
| | | * @param {string} context context directory |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Adds to map of items. |
| | | * @template K |
| | | * @template V |
| | | * @param {Map<K, V[]>} map a map from key to values |
| | |
| | | array.push(value); |
| | | }; |
| | | |
| | | /** @typedef {Set<string>} UsedModuleIds */ |
| | | |
| | | /** |
| | | * Gets used module ids and modules. |
| | | * @param {Compilation} compilation the compilation |
| | | * @param {((module: Module) => boolean)=} filter filter modules |
| | | * @returns {[Set<string>, Module[]]} used module ids as strings and modules without id matching the filter |
| | | * @returns {[UsedModuleIds, Module[]]} used module ids as strings and modules without id matching the filter |
| | | */ |
| | | const getUsedModuleIdsAndModules = (compilation, filter) => { |
| | | const chunkGraph = compilation.chunkGraph; |
| | | |
| | | /** @type {Module[]} */ |
| | | const modules = []; |
| | | |
| | | /** @type {Set<string>} */ |
| | | /** @type {UsedModuleIds} */ |
| | | const usedIds = new Set(); |
| | | if (compilation.usedModuleIds) { |
| | | for (const id of compilation.usedModuleIds) { |
| | |
| | | return [usedIds, modules]; |
| | | }; |
| | | |
| | | /** @typedef {Set<string>} UsedChunkIds */ |
| | | |
| | | /** |
| | | * Gets used chunk ids. |
| | | * @param {Compilation} compilation the compilation |
| | | * @returns {Set<string>} used chunk ids as strings |
| | | * @returns {UsedChunkIds} used chunk ids as strings |
| | | */ |
| | | const getUsedChunkIds = (compilation) => { |
| | | /** @type {Set<string>} */ |
| | | /** @type {UsedChunkIds} */ |
| | | const usedIds = new Set(); |
| | | if (compilation.usedChunkIds) { |
| | | for (const id of compilation.usedChunkIds) { |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Returns list of items without a name. |
| | | * @template T |
| | | * @param {Iterable<T>} items list of items to be named |
| | | * @param {(item: T) => string} getShortName get a short name for an item |
| | |
| | | usedIds, |
| | | assignName |
| | | ) => { |
| | | /** @type {Map<string, T[]>} */ |
| | | /** |
| | | * Defines the map to item type used by this module. |
| | | * @template T |
| | | * @typedef {Map<string, T[]>} MapToItem |
| | | */ |
| | | |
| | | /** @type {MapToItem<T>} */ |
| | | const nameToItems = new Map(); |
| | | |
| | | for (const item of items) { |
| | |
| | | addToMapOfItems(nameToItems, name, item); |
| | | } |
| | | |
| | | /** @type {Map<string, T[]>} */ |
| | | /** @type {MapToItem<T>} */ |
| | | const nameToItems2 = new Map(); |
| | | |
| | | for (const [name, items] of nameToItems) { |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Assign deterministic ids. |
| | | * @template T |
| | | * @param {T[]} items list of items to be named |
| | | * @param {(item: T) => string} getName get a name for an item |
| | |
| | | |
| | | for (const item of items) { |
| | | const ident = getName(item); |
| | | /** @type {number} */ |
| | | let id; |
| | | let i = salt; |
| | | do { |
| | |
| | | }; |
| | | |
| | | /** |
| | | * @param {Set<string>} usedIds used ids |
| | | * Assign ascending module ids. |
| | | * @param {UsedModuleIds} usedIds used ids |
| | | * @param {Iterable<Module>} modules the modules |
| | | * @param {Compilation} compilation the compilation |
| | | * @returns {void} |
| | |
| | | const chunkGraph = compilation.chunkGraph; |
| | | |
| | | let nextId = 0; |
| | | /** @type {(mod: Module) => void} */ |
| | | let assignId; |
| | | if (usedIds.size > 0) { |
| | | /** |
| | | * Processes the provided module. |
| | | * @param {Module} module the module |
| | | */ |
| | | assignId = (module) => { |
| | |
| | | }; |
| | | } else { |
| | | /** |
| | | * Processes the provided module. |
| | | * @param {Module} module the module |
| | | */ |
| | | assignId = (module) => { |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Assign ascending chunk ids. |
| | | * @param {Iterable<Chunk>} chunks the chunks |
| | | * @param {Compilation} compilation the compilation |
| | | * @returns {void} |