From 333bbb11e2d499b85efa90c9fd685f1e7b7d7120 Mon Sep 17 00:00:00 2001 From: Davide Iadeluca <146922689+DavideIadeluca@users.noreply.github.com> Date: Sat, 8 Feb 2025 17:50:12 +0100 Subject: [PATCH] fix(webpack): chunk module path checking fails with dotted directories (#4179) Resolves issues when the path contains unexpected periods --- .../src/RegisterAsyncChunksPlugin.cjs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/js-packages/webpack-config/src/RegisterAsyncChunksPlugin.cjs b/js-packages/webpack-config/src/RegisterAsyncChunksPlugin.cjs index 72c8fdd28..118c795e8 100644 --- a/js-packages/webpack-config/src/RegisterAsyncChunksPlugin.cjs +++ b/js-packages/webpack-config/src/RegisterAsyncChunksPlugin.cjs @@ -81,10 +81,13 @@ class RegisterAsyncChunksPlugin { const chunkModules = (c) => Array.from(compilation.chunkGraph.getChunkModulesIterable(c)); const relevantChunk = chunks.find((chunk) => - chunkModules(chunk)?.find( - (module) => - module.resource?.split('.')[0] === importPathResolved || module.rootModule?.resource?.split('.')[0] === importPathResolved - ) + chunkModules(chunk)?.find((module) => { + const resourceWithoutExt = module.resource ? module.resource.replace(path.extname(module.resource), '') : ''; + const rootResourceWithoutExt = module.rootModule?.resource + ? module.rootModule.resource.replace(path.extname(module.rootModule.resource), '') + : ''; + return resourceWithoutExt === importPathResolved || rootResourceWithoutExt === importPathResolved; + }) ); if (!relevantChunk) { @@ -94,7 +97,11 @@ class RegisterAsyncChunksPlugin { const relevantChunkModules = chunkModules(relevantChunk); const mainModule = relevantChunkModules.filter((m) => { - return m.resource?.split('.')[0] === importPathResolved || m.rootModule?.resource?.split('.')[0] === importPathResolved; + const resourceWithoutExt = m.resource ? m.resource.replace(path.extname(m.resource), '') : ''; + const rootResourceWithoutExt = m.rootModule?.resource + ? m.rootModule.resource.replace(path.extname(m.rootModule.resource), '') + : ''; + return resourceWithoutExt === importPathResolved || rootResourceWithoutExt === importPathResolved; })[0]; const otherRelevantChunkModules = relevantChunkModules.filter((m) => m !== mainModule);