MCPcopy
hub / github.com/webpack/webpack / replaceModule

Method replaceModule

lib/ChunkGraph.js:493–557  ·  view source on GitHub ↗

* Processes the provided old module. * @param {Module} oldModule the replaced module * @param {Module} newModule the replacing module * @returns {void}

(oldModule, newModule)

Source from the content-addressed store, hash-verified

491 * @returns {void}
492 */
493 replaceModule(oldModule, newModule) {
494 const oldCgm = this._getChunkGraphModule(oldModule);
495 const newCgm = this._getChunkGraphModule(newModule);
496
497 for (const chunk of oldCgm.chunks) {
498 const cgc = this._getChunkGraphChunk(chunk);
499 cgc.modules.delete(oldModule);
500 cgc.modules.add(newModule);
501 newCgm.chunks.add(chunk);
502 }
503 oldCgm.chunks.clear();
504
505 if (oldCgm.entryInChunks !== undefined) {
506 if (newCgm.entryInChunks === undefined) {
507 newCgm.entryInChunks = new Set();
508 }
509 for (const chunk of oldCgm.entryInChunks) {
510 const cgc = this._getChunkGraphChunk(chunk);
511 const old = /** @type {Entrypoint} */ (cgc.entryModules.get(oldModule));
512 /** @type {EntryModules} */
513 const newEntryModules = new Map();
514 for (const [m, cg] of cgc.entryModules) {
515 if (m === oldModule) {
516 newEntryModules.set(newModule, old);
517 } else {
518 newEntryModules.set(m, cg);
519 }
520 }
521 cgc.entryModules = newEntryModules;
522 newCgm.entryInChunks.add(chunk);
523 }
524 oldCgm.entryInChunks = undefined;
525 }
526
527 if (oldCgm.runtimeInChunks !== undefined) {
528 if (newCgm.runtimeInChunks === undefined) {
529 newCgm.runtimeInChunks = new Set();
530 }
531 for (const chunk of oldCgm.runtimeInChunks) {
532 const cgc = this._getChunkGraphChunk(chunk);
533 cgc.runtimeModules.delete(/** @type {RuntimeModule} */ (oldModule));
534 cgc.runtimeModules.add(/** @type {RuntimeModule} */ (newModule));
535 newCgm.runtimeInChunks.add(chunk);
536 if (
537 cgc.fullHashModules !== undefined &&
538 cgc.fullHashModules.has(/** @type {RuntimeModule} */ (oldModule))
539 ) {
540 cgc.fullHashModules.delete(/** @type {RuntimeModule} */ (oldModule));
541 cgc.fullHashModules.add(/** @type {RuntimeModule} */ (newModule));
542 }
543 if (
544 cgc.dependentHashModules !== undefined &&
545 cgc.dependentHashModules.has(/** @type {RuntimeModule} */ (oldModule))
546 ) {
547 cgc.dependentHashModules.delete(
548 /** @type {RuntimeModule} */ (oldModule)
549 );
550 cgc.dependentHashModules.add(

Callers 2

integrateMethod · 0.80
webpack.config.jsFile · 0.80

Calls 8

_getChunkGraphModuleMethod · 0.95
_getChunkGraphChunkMethod · 0.95
deleteMethod · 0.45
addMethod · 0.45
clearMethod · 0.45
getMethod · 0.45
setMethod · 0.45
hasMethod · 0.45

Tested by

no test coverage detected