| | |
| | | const ChunkFilesSet = createArrayToSetDeprecationSet("chunk.files"); |
| | | |
| | | /** |
| | | * Defines the chunk maps type used by this module. |
| | | * @deprecated |
| | | * @typedef {object} ChunkMaps |
| | | * @property {Record<ChunkId, string>} hash |
| | |
| | | */ |
| | | |
| | | /** |
| | | * Defines the chunk module id map type used by this module. |
| | | * @deprecated |
| | | * @typedef {Record<ChunkId, ChunkId[]>} ChunkModuleIdMap |
| | | */ |
| | | |
| | | /** |
| | | * Defines the chunk module hash map type used by this module. |
| | | * @deprecated |
| | | * @typedef {Record<ModuleId, string>} chunkModuleHashMap |
| | | */ |
| | | |
| | | /** |
| | | * Defines the chunk module maps type used by this module. |
| | | * @deprecated |
| | | * @typedef {object} ChunkModuleMaps |
| | | * @property {ChunkModuleIdMap} id |
| | |
| | | /** @typedef {SortableSet<ChunkGroup>} SortableChunkGroups */ |
| | | /** @typedef {Record<string, ChunkId[]>} ChunkChildIdsByOrdersMap */ |
| | | /** @typedef {Record<string, ChunkChildIdsByOrdersMap>} ChunkChildIdsByOrdersMapByData */ |
| | | /** @typedef {{ onChunks: Chunk[], chunks: Chunks }} ChunkChildOfTypeInOrder */ |
| | | |
| | | let debugId = 1000; |
| | | |
| | |
| | | */ |
| | | class Chunk { |
| | | /** |
| | | * Creates an instance of Chunk. |
| | | * @param {ChunkName=} name of chunk being created, is optional (for subclasses) |
| | | * @param {boolean} backCompat enable backward-compatibility |
| | | */ |
| | |
| | | |
| | | // TODO remove in webpack 6 |
| | | // BACKWARD-COMPAT START |
| | | /** |
| | | * Returns entry module. |
| | | * @deprecated |
| | | * @returns {Module | undefined} entry module |
| | | */ |
| | | get entryModule() { |
| | | const entryModules = [ |
| | | ...ChunkGraph.getChunkGraphForChunk( |
| | |
| | | } |
| | | |
| | | /** |
| | | * Checks whether this chunk has an entry module. |
| | | * @deprecated |
| | | * @returns {boolean} true, if the chunk contains an entry module |
| | | */ |
| | | hasEntryModule() { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Adds the provided module to the chunk. |
| | | * @deprecated |
| | | * @param {Module} module the module |
| | | * @returns {boolean} true, if the chunk could be added |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Removes the provided module from the chunk. |
| | | * @deprecated |
| | | * @param {Module} module the module |
| | | * @returns {void} |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Gets the number of modules in this chunk. |
| | | * @deprecated |
| | | * @returns {number} the number of module which are contained in this chunk |
| | | */ |
| | | getNumberOfModules() { |
| | |
| | | ).getNumberOfChunkModules(this); |
| | | } |
| | | |
| | | /** |
| | | * @deprecated |
| | | * @returns {Iterable<Module>} modules |
| | | */ |
| | | get modulesIterable() { |
| | | const chunkGraph = ChunkGraph.getChunkGraphForChunk( |
| | | this, |
| | |
| | | } |
| | | |
| | | /** |
| | | * Compares this chunk with another chunk. |
| | | * @deprecated |
| | | * @param {Chunk} otherChunk the chunk to compare with |
| | | * @returns {-1|0|1} the comparison result |
| | | * @returns {-1 | 0 | 1} the comparison result |
| | | */ |
| | | compareTo(otherChunk) { |
| | | const chunkGraph = ChunkGraph.getChunkGraphForChunk( |
| | |
| | | } |
| | | |
| | | /** |
| | | * Checks whether this chunk contains the module. |
| | | * @deprecated |
| | | * @param {Module} module the module |
| | | * @returns {boolean} true, if the chunk contains the module |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns the modules for this chunk. |
| | | * @deprecated |
| | | * @returns {Module[]} the modules for this chunk |
| | | */ |
| | | getModules() { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Removes this chunk from the chunk graph and chunk groups. |
| | | * @deprecated |
| | | * @returns {void} |
| | | */ |
| | | remove() { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Moves a module from this chunk to another chunk. |
| | | * @deprecated |
| | | * @param {Module} module the module |
| | | * @param {Chunk} otherChunk the target chunk |
| | | * @returns {void} |
| | |
| | | } |
| | | |
| | | /** |
| | | * Integrates another chunk into this chunk when possible. |
| | | * @deprecated |
| | | * @param {Chunk} otherChunk the other chunk |
| | | * @returns {boolean} true, if the specified chunk has been integrated |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Checks whether this chunk can be integrated with another chunk. |
| | | * @deprecated |
| | | * @param {Chunk} otherChunk the other chunk |
| | | * @returns {boolean} true, if chunks could be integrated |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Checks whether this chunk is empty. |
| | | * @deprecated |
| | | * @returns {boolean} true, if this chunk contains no module |
| | | */ |
| | | isEmpty() { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns the total size of all modules in this chunk. |
| | | * @deprecated |
| | | * @returns {number} total size of all modules in this chunk |
| | | */ |
| | | modulesSize() { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns the estimated size for the requested source type. |
| | | * @deprecated |
| | | * @param {ChunkSizeOptions} options options object |
| | | * @returns {number} total size of this chunk |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns the integrated size with another chunk. |
| | | * @deprecated |
| | | * @param {Chunk} otherChunk the other chunk |
| | | * @param {ChunkSizeOptions} options options object |
| | | * @returns {number} total size of the chunk or false if the chunk can't be integrated |
| | |
| | | } |
| | | |
| | | /** |
| | | * Gets chunk module maps. |
| | | * @deprecated |
| | | * @param {ModuleFilterPredicate} filterFn function used to filter modules |
| | | * @returns {ChunkModuleMaps} module map information |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Checks whether this chunk contains a matching module in the graph. |
| | | * @deprecated |
| | | * @param {ModuleFilterPredicate} filterFn predicate function used to filter modules |
| | | * @param {ChunkFilterPredicate=} filterChunkFn predicate function used to filter chunks |
| | | * @returns {boolean} return true if module exists in graph |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns the chunk map information. |
| | | * @deprecated |
| | | * @param {boolean} realHash whether the full hash or the rendered hash is to be used |
| | | * @returns {ChunkMaps} the chunk map information |
| | |
| | | // BACKWARD-COMPAT END |
| | | |
| | | /** |
| | | * Checks whether this chunk has runtime. |
| | | * @returns {boolean} whether or not the Chunk will have a runtime |
| | | */ |
| | | hasRuntime() { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Checks whether it can be initial. |
| | | * @returns {boolean} whether or not this chunk can be an initial chunk |
| | | */ |
| | | canBeInitial() { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Checks whether this chunk is only initial. |
| | | * @returns {boolean} whether this chunk can only be an initial chunk |
| | | */ |
| | | isOnlyInitial() { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Gets entry options. |
| | | * @returns {EntryOptions | undefined} the entry options for this chunk |
| | | */ |
| | | getEntryOptions() { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Adds the provided chunk group to the chunk. |
| | | * @param {ChunkGroup} chunkGroup the chunkGroup the chunk is being added |
| | | * @returns {void} |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Removes the provided chunk group from the chunk. |
| | | * @param {ChunkGroup} chunkGroup the chunkGroup the chunk is being removed from |
| | | * @returns {void} |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Checks whether this chunk is in group. |
| | | * @param {ChunkGroup} chunkGroup the chunkGroup to check |
| | | * @returns {boolean} returns true if chunk has chunkGroup reference and exists in chunkGroup |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Gets number of groups. |
| | | * @returns {number} the amount of groups that the said chunk is in |
| | | */ |
| | | getNumberOfGroups() { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Gets groups iterable. |
| | | * @returns {SortableChunkGroups} the chunkGroups that the said chunk is referenced in |
| | | */ |
| | | get groupsIterable() { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Disconnects from groups. |
| | | * @returns {void} |
| | | */ |
| | | disconnectFromGroups() { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided new chunk. |
| | | * @param {Chunk} newChunk the new chunk that will be split out of |
| | | * @returns {void} |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Updates the hash with the data contributed by this instance. |
| | | * @param {Hash} hash hash (will be modified) |
| | | * @param {ChunkGraph} chunkGraph the chunk graph |
| | | * @returns {void} |
| | |
| | | } |
| | | |
| | | /** |
| | | * Gets all async chunks. |
| | | * @returns {Chunks} a set of all the async chunks |
| | | */ |
| | | getAllAsyncChunks() { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Gets all initial chunks. |
| | | * @returns {Chunks} a set of all the initial chunks (including itself) |
| | | */ |
| | | getAllInitialChunks() { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Gets all referenced chunks. |
| | | * @returns {Chunks} a set of all the referenced chunks (including itself) |
| | | */ |
| | | getAllReferencedChunks() { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Gets all referenced async entrypoints. |
| | | * @returns {Entrypoints} a set of all the referenced entrypoints |
| | | */ |
| | | getAllReferencedAsyncEntrypoints() { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Checks whether this chunk has async chunks. |
| | | * @returns {boolean} true, if the chunk references async chunks |
| | | */ |
| | | hasAsyncChunks() { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Gets child ids by orders. |
| | | * @param {ChunkGraph} chunkGraph the chunk graph |
| | | * @param {ChunkFilterPredicate=} filterFn function used to filter chunks |
| | | * @returns {Record<string, ChunkId[]>} a record object of names to lists of child ids(?) |
| | | */ |
| | | getChildIdsByOrders(chunkGraph, filterFn) { |
| | | /** @type {Map<string, {order: number, group: ChunkGroup}[]>} */ |
| | | /** @type {Map<string, { order: number, group: ChunkGroup }[]>} */ |
| | | const lists = new Map(); |
| | | for (const group of this.groupsIterable) { |
| | | if (group.chunks[group.chunks.length - 1] === this) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Gets children of type in order. |
| | | * @param {ChunkGraph} chunkGraph the chunk graph |
| | | * @param {string} type option name |
| | | * @returns {{ onChunks: Chunk[], chunks: Chunks }[] | undefined} referenced chunks for a specific type |
| | | * @returns {ChunkChildOfTypeInOrder[] | undefined} referenced chunks for a specific type |
| | | */ |
| | | getChildrenOfTypeInOrder(chunkGraph, type) { |
| | | /** @type {{ order: number, group: ChunkGroup, childGroup: ChunkGroup }[]} */ |
| | | const list = []; |
| | | for (const group of this.groupsIterable) { |
| | | for (const childGroup of group.childrenIterable) { |
| | | const order = |
| | | childGroup.options[/** @type {keyof ChunkGroupOptions} */ (type)]; |
| | | /** @type {number} */ |
| | | (childGroup.options[/** @type {keyof ChunkGroupOptions} */ (type)]); |
| | | if (order === undefined) continue; |
| | | list.push({ |
| | | order, |
| | |
| | | } |
| | | if (list.length === 0) return; |
| | | list.sort((a, b) => { |
| | | const cmp = |
| | | /** @type {number} */ (b.order) - /** @type {number} */ (a.order); |
| | | const cmp = b.order - a.order; |
| | | if (cmp !== 0) return cmp; |
| | | return a.group.compareTo(chunkGraph, b.group); |
| | | }); |
| | | /** @type {ChunkChildOfTypeInOrder[]} */ |
| | | const result = []; |
| | | /** @type {undefined | ChunkChildOfTypeInOrder} */ |
| | | let lastEntry; |
| | | for (const { group, childGroup } of list) { |
| | | if (lastEntry && lastEntry.onChunks === group.chunks) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Gets child ids by orders map. |
| | | * @param {ChunkGraph} chunkGraph the chunk graph |
| | | * @param {boolean=} includeDirectChildren include direct children (by default only children of async children are included) |
| | | * @param {ChunkFilterPredicate=} filterFn function used to filter chunks |
| | |
| | | const chunkMaps = Object.create(null); |
| | | |
| | | /** |
| | | * Adds child ids by orders to map. |
| | | * @param {Chunk} chunk a chunk |
| | | * @returns {void} |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Checks whether this chunk contains the chunk graph. |
| | | * @param {ChunkGraph} chunkGraph the chunk graph |
| | | * @param {string} type option name |
| | | * @param {boolean=} includeDirectChildren include direct children (by default only children of async children are included) |