MCPcopy
hub / github.com/webpack/webpack / getUsedModuleIdsAndModules

Function getUsedModuleIdsAndModules

lib/ids/IdHelpers.js:245–276  ·  view source on GitHub ↗
(compilation, filter)

Source from the content-addressed store, hash-verified

243 * @returns {[UsedModuleIds, Module[]]} used module ids as strings and modules without id matching the filter
244 */
245const getUsedModuleIdsAndModules = (compilation, filter) => {
246 const chunkGraph = compilation.chunkGraph;
247 /** @type {Module[]} */
248 const modules = [];
249
250 /** @type {UsedModuleIds} */
251 const usedIds = new Set();
252 if (compilation.usedModuleIds) {
253 for (const id of compilation.usedModuleIds) {
254 usedIds.add(String(id));
255 }
256 }
257
258 for (const module of compilation.modules) {
259 if (!module.needId) continue;
260 const moduleId = chunkGraph.getModuleId(module);
261 if (moduleId !== null) {
262 usedIds.add(String(moduleId));
263 } else if (
264 (!filter || filter(module)) &&
265 (chunkGraph.getNumberOfModuleChunks(module) !== 0 ||
266 // CSS modules need IDs even when not in chunks, for generating CSS class names(i.e. [id]-[local])
267 /** @type {CssModuleBuildMeta} */ (module.buildMeta).isCssModule ||
268 /** @type {CssModuleBuildMeta} */ (module.buildMeta)
269 .needIdInConcatenation)
270 ) {
271 modules.push(module);
272 }
273 }
274
275 return [usedIds, modules];
276};
277
278/** @typedef {Set<string>} UsedChunkIds */
279

Callers 6

applyMethod · 0.85
applyMethod · 0.85
applyMethod · 0.85
applyMethod · 0.85
applyMethod · 0.85
applyMethod · 0.85

Calls 5

getModuleIdMethod · 0.80
filterFunction · 0.50
addMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected