MCPcopy
hub / github.com/webpack/webpack / _handleModuleBuildAndDependencies

Method _handleModuleBuildAndDependencies

lib/Compilation.js:2471–2591  ·  view source on GitHub ↗

* Handle module build and dependencies. * @private * @param {Module | null} originModule original module * @param {Module} module module * @param {boolean} recursive true if make it recursive, otherwise false * @param {boolean} checkCycle true if need to check cycle, otherwise false * @p

(
		originModule,
		module,
		recursive,
		checkCycle,
		dependencies,
		callback
	)

Source from the content-addressed store, hash-verified

2469 * @returns {void}
2470 */
2471 _handleModuleBuildAndDependencies(
2472 originModule,
2473 module,
2474 recursive,
2475 checkCycle,
2476 dependencies,
2477 callback
2478 ) {
2479 // Check for cycles when build is trigger inside another build
2480 /** @type {Set<Module> | undefined} */
2481 let creatingModuleDuringBuildSet;
2482 if (
2483 checkCycle &&
2484 this.buildQueue.isProcessing(/** @type {Module} */ (originModule))
2485 ) {
2486 // Track build dependency
2487 creatingModuleDuringBuildSet = this.creatingModuleDuringBuild.get(
2488 /** @type {Module} */
2489 (originModule)
2490 );
2491 if (creatingModuleDuringBuildSet === undefined) {
2492 /** @type {Set<Module>} */
2493 creatingModuleDuringBuildSet = new Set();
2494 this.creatingModuleDuringBuild.set(
2495 /** @type {Module} */
2496 (originModule),
2497 creatingModuleDuringBuildSet
2498 );
2499 }
2500 creatingModuleDuringBuildSet.add(module);
2501
2502 // When building is blocked by another module
2503 // search for a cycle, cancel the cycle by throwing
2504 // an error (otherwise this would deadlock)
2505 const blockReasons = this.creatingModuleDuringBuild.get(module);
2506 if (blockReasons !== undefined) {
2507 const set = new Set(blockReasons);
2508 for (const item of set) {
2509 const blockReasons = this.creatingModuleDuringBuild.get(item);
2510 if (blockReasons !== undefined) {
2511 for (const m of blockReasons) {
2512 if (m === module) {
2513 return callback(new BuildCycleError(module));
2514 }
2515 set.add(m);
2516 }
2517 }
2518 }
2519 }
2520 }
2521
2522 this.buildModule(module, (err) => {
2523 if (creatingModuleDuringBuildSet !== undefined) {
2524 creatingModuleDuringBuildSet.delete(module);
2525 }
2526 if (err) {
2527 if (!err.module) {
2528 err.module = module;

Callers 2

handleModuleCreationMethod · 0.95

Calls 12

buildModuleMethod · 0.95
handleModuleCreationMethod · 0.95
isProcessingMethod · 0.80
callbackFunction · 0.50
getMethod · 0.45
setMethod · 0.45
addMethod · 0.45
deleteMethod · 0.45
pushMethod · 0.45
requestMethod · 0.45

Tested by

no test coverage detected