Skip to content

Commit 217a24d

Browse files
committed
feat: improve warning of conflict order
1 parent 50434b5 commit 217a24d

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

src/index.js

+27-15
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,7 @@ class CssModule extends webpack.Module {
9090
}
9191

9292
class CssModuleFactory {
93-
create(
94-
{
95-
dependencies: [dependency],
96-
},
97-
callback
98-
) {
93+
create({ dependencies: [dependency] }, callback) {
9994
callback(null, new CssModule(dependency));
10095
}
10196
}
@@ -416,6 +411,9 @@ class MiniCssExtractPlugin {
416411
if (typeof chunkGroup.getModuleIndex2 === 'function') {
417412
// Store dependencies for modules
418413
const moduleDependencies = new Map(modules.map((m) => [m, new Set()]));
414+
const moduleDependenciesReasons = new Map(
415+
modules.map((m) => [m, new Map()])
416+
);
419417

420418
// Get ordered list of modules per chunk group
421419
// This loop also gathers dependencies from the ordered lists
@@ -435,9 +433,14 @@ class MiniCssExtractPlugin {
435433

436434
for (let i = 0; i < sortedModules.length; i++) {
437435
const set = moduleDependencies.get(sortedModules[i]);
436+
const reasons = moduleDependenciesReasons.get(sortedModules[i]);
438437

439438
for (let j = i + 1; j < sortedModules.length; j++) {
440-
set.add(sortedModules[j]);
439+
const module = sortedModules[j];
440+
set.add(module);
441+
const reason = reasons.get(module) || new Set();
442+
reason.add(cg);
443+
reasons.set(module, reason);
441444
}
442445
}
443446

@@ -453,6 +456,7 @@ class MiniCssExtractPlugin {
453456
let success = false;
454457
let bestMatch;
455458
let bestMatchDeps;
459+
let bestMatchDepsReasons;
456460

457461
// get first module where dependencies are fulfilled
458462
for (const list of modulesByChunkGroup) {
@@ -472,6 +476,7 @@ class MiniCssExtractPlugin {
472476
if (!bestMatchDeps || bestMatchDeps.length > failedDeps.length) {
473477
bestMatch = list;
474478
bestMatchDeps = failedDeps;
479+
bestMatchDepsReasons = moduleDependenciesReasons.get(module);
475480
}
476481

477482
if (failedDeps.length === 0) {
@@ -491,14 +496,21 @@ class MiniCssExtractPlugin {
491496
if (!this.options.ignoreOrder) {
492497
compilation.warnings.push(
493498
new Error(
494-
`chunk ${chunk.name || chunk.id} [${pluginName}]\n` +
495-
'Conflicting order between:\n' +
496-
` * ${fallbackModule.readableIdentifier(
497-
requestShortener
498-
)}\n` +
499-
`${bestMatchDeps
500-
.map((m) => ` * ${m.readableIdentifier(requestShortener)}`)
501-
.join('\n')}`
499+
[
500+
`chunk ${chunk.name || chunk.id} [${pluginName}]`,
501+
'Following module has been added:',
502+
` * ${fallbackModule.readableIdentifier(requestShortener)}`,
503+
"while this module as dependencies that haven't been added before:",
504+
...bestMatchDeps.map((m) =>
505+
[
506+
` * ${m.readableIdentifier(requestShortener)}`,
507+
`which is used before added module in chunk: ${Array.from(
508+
bestMatchDepsReasons.get(m),
509+
(cg) => cg.name
510+
).join(',')}`,
511+
].join(', ')
512+
),
513+
].join('\n')
502514
)
503515
);
504516
}

0 commit comments

Comments
 (0)