From fad1bc1f32544f3c1613ad757394b1d4e913fe38 Mon Sep 17 00:00:00 2001 From: Mondal <137494766+krishanu717@users.noreply.github.com> Date: Mon, 22 Sep 2025 17:11:50 +0000 Subject: [PATCH] fix: resolve type and dependency issues, patch lazyCompilation/UMD interaction --- lib/hmr/LazyCompilationPlugin.js | 40 +++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/lib/hmr/LazyCompilationPlugin.js b/lib/hmr/LazyCompilationPlugin.js index a7791899b..7bdd27d90 100644 --- a/lib/hmr/LazyCompilationPlugin.js +++ b/lib/hmr/LazyCompilationPlugin.js @@ -376,28 +376,40 @@ class LazyCompilationPlugin { apply(compiler) { /** @type {BackendApi} */ let backend; - compiler.hooks.beforeCompile.tapAsync(PLUGIN_NAME, (params, callback) => { - if (backend !== undefined) return callback(); - const promise = this.backend(compiler, (err, result) => { - if (err) return callback(err); - backend = /** @type {BackendApi} */ (result); - callback(); - }); - if (promise && promise.then) { - promise.then((b) => { - backend = b; + compiler.hooks.beforeCompile.tapAsync( + PLUGIN_NAME, + (/** @type {any} */ params, /** @type {(err?: Error | null) => void} */ callback) => { + if (backend !== undefined) return callback(); + const promise = this.backend(compiler, (err, result) => { + if (err) return callback(err); + backend = /** @type {BackendApi} */ (result); callback(); - }, callback); + }); + if (promise && promise.then) { + promise.then((b) => { + backend = b; + callback(); + }, callback); + } } - }); + ); compiler.hooks.thisCompilation.tap( PLUGIN_NAME, + /** + * @param {import("../Compilation")} compilation + * @param {{ normalModuleFactory: import("../NormalModuleFactory") }} param1 + */ (compilation, { normalModuleFactory }) => { normalModuleFactory.hooks.module.tap( PLUGIN_NAME, + /** + * @param {Module} module + * @param {*} createData + * @param {*} resolveData + */ (module, createData, resolveData) => { if ( - resolveData.dependencies.every((dep) => + resolveData.dependencies.every((dep: any) => HMR_DEPENDENCY_TYPES.has(dep.type) ) ) { @@ -457,7 +469,7 @@ class LazyCompilationPlugin { ); } ); - compiler.hooks.shutdown.tapAsync(PLUGIN_NAME, (callback) => { + compiler.hooks.shutdown.tapAsync(PLUGIN_NAME, (callback: (...args: any[]) => void) => { backend.dispose(callback); }); }