MCPcopy
hub / github.com/webpack/webpack / getEntrypointChunksInLoadOrder

Function getEntrypointChunksInLoadOrder

lib/dependencies/HtmlEntryDependency.js:163–211  ·  view source on GitHub ↗
(entrypoint)

Source from the content-addressed store, hash-verified

161 * HTML contains tags for both the leader and the dependant entries.
162 */
163const getEntrypointChunksInLoadOrder = (entrypoint) => {
164 const entryChunk = /** @type {Chunk} */ (entrypoint.getEntrypointChunk());
165 const runtimeChunk = entrypoint.getRuntimeChunk();
166
167 /** @type {Set<Chunk>} */
168 const chunksLoadedByAncestorTags = new Set();
169 /** @type {Set<import("../ChunkGroup")>} */
170 const visitedGroups = new Set();
171 const walk = (/** @type {import("../ChunkGroup")} */ group) => {
172 if (visitedGroups.has(group)) return;
173 visitedGroups.add(group);
174 for (const parent of group.parentsIterable) {
175 if (
176 typeof (/** @type {Entrypoint} */ (parent).getEntrypointChunk) ===
177 "function"
178 ) {
179 const parentEntry =
180 /** @type {Entrypoint} */
181 (parent).getEntrypointChunk();
182 if (parentEntry) chunksLoadedByAncestorTags.add(parentEntry);
183 const parentRuntime =
184 /** @type {Entrypoint} */
185 (parent).getRuntimeChunk();
186 if (parentRuntime) chunksLoadedByAncestorTags.add(parentRuntime);
187 }
188 walk(parent);
189 }
190 };
191 walk(entrypoint);
192
193 /** @type {Chunk[]} */
194 const ordered = [];
195 /** @type {Set<Chunk>} */
196 const seen = new Set();
197 const push = (/** @type {Chunk | null | undefined} */ chunk) => {
198 if (!chunk || seen.has(chunk) || chunk === entryChunk) return;
199 if (chunksLoadedByAncestorTags.has(chunk)) return;
200 seen.add(chunk);
201 ordered.push(chunk);
202 };
203 if (runtimeChunk !== entryChunk) {
204 push(runtimeChunk);
205 }
206 for (const chunk of entrypoint.chunks) {
207 push(chunk);
208 }
209 ordered.push(entryChunk);
210 return ordered;
211};
212
213/**
214 * Whether webpack will emit a `.js` file for this chunk that must be

Callers 1

applyMethod · 0.85

Calls 5

getEntrypointChunkMethod · 0.80
getRuntimeChunkMethod · 0.80
walkFunction · 0.70
pushFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected