Skip to content

Commit b1bbda9

Browse files
chore(webpack): change algorithm for resolving chunks
Resolves issues when the path contains unexpected periods
1 parent 863d652 commit b1bbda9

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

js-packages/webpack-config/src/RegisterAsyncChunksPlugin.cjs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,13 @@ class RegisterAsyncChunksPlugin {
8181
const chunkModules = (c) => Array.from(compilation.chunkGraph.getChunkModulesIterable(c));
8282

8383
const relevantChunk = chunks.find((chunk) =>
84-
chunkModules(chunk)?.find(
85-
(module) =>
86-
module.resource?.split('.')[0] === importPathResolved || module.rootModule?.resource?.split('.')[0] === importPathResolved
87-
)
84+
chunkModules(chunk)?.find((module) => {
85+
const resourceWithoutExt = module.resource ? module.resource.replace(path.extname(module.resource), '') : '';
86+
const rootResourceWithoutExt = module.rootModule?.resource
87+
? module.rootModule.resource.replace(path.extname(module.rootModule.resource), '')
88+
: '';
89+
return resourceWithoutExt === importPathResolved || rootResourceWithoutExt === importPathResolved;
90+
})
8891
);
8992

9093
if (!relevantChunk) {
@@ -94,7 +97,11 @@ class RegisterAsyncChunksPlugin {
9497

9598
const relevantChunkModules = chunkModules(relevantChunk);
9699
const mainModule = relevantChunkModules.filter((m) => {
97-
return m.resource?.split('.')[0] === importPathResolved || m.rootModule?.resource?.split('.')[0] === importPathResolved;
100+
const resourceWithoutExt = m.resource ? m.resource.replace(path.extname(m.resource), '') : '';
101+
const rootResourceWithoutExt = m.rootModule?.resource
102+
? m.rootModule.resource.replace(path.extname(m.rootModule.resource), '')
103+
: '';
104+
return resourceWithoutExt === importPathResolved || rootResourceWithoutExt === importPathResolved;
98105
})[0];
99106
const otherRelevantChunkModules = relevantChunkModules.filter((m) => m !== mainModule);
100107

0 commit comments

Comments
 (0)