Skip to content

Commit b88220c

Browse files
authored
Merge pull request webpack#4191 from webpack/refactor/WarnCaseSensitiveModulesPlugin
Refactor/warn case sensitive modules plugin
2 parents 157a194 + 33b8328 commit b88220c

2 files changed

Lines changed: 24 additions & 93 deletions

File tree

lib/WarnCaseSensitiveModulesPlugin.js

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,30 @@
22
MIT License http://www.opensource.org/licenses/mit-license.php
33
Author Tobias Koppers @sokra
44
*/
5-
var CaseSensitiveModulesWarning = require("./CaseSensitiveModulesWarning");
5+
"use strict";
66

7-
function WarnCaseSensitiveModulesPlugin() {}
8-
module.exports = WarnCaseSensitiveModulesPlugin;
7+
const CaseSensitiveModulesWarning = require("./CaseSensitiveModulesWarning");
98

10-
WarnCaseSensitiveModulesPlugin.prototype.apply = function(compiler) {
11-
compiler.plugin("compilation", function(compilation) {
12-
compilation.plugin("seal", function() {
13-
var moduleWithoutCase = {};
14-
this.modules.forEach(function(module) {
15-
var ident = module.identifier().toLowerCase();
16-
if(moduleWithoutCase["$" + ident]) {
17-
moduleWithoutCase["$" + ident].push(module);
18-
} else {
19-
moduleWithoutCase["$" + ident] = [module];
20-
}
21-
}, this);
22-
Object.keys(moduleWithoutCase).forEach(function(key) {
23-
if(moduleWithoutCase[key].length > 1)
24-
this.warnings.push(new CaseSensitiveModulesWarning(moduleWithoutCase[key]));
25-
}, this);
9+
class WarnCaseSensitiveModulesPlugin {
10+
apply(compiler) {
11+
compiler.plugin("compilation", compilation => {
12+
compilation.plugin("seal", () => {
13+
const moduleWithoutCase = Object.create(null);
14+
compilation.modules.forEach(module => {
15+
const identifier = module.identifier().toLowerCase();
16+
if(moduleWithoutCase[identifier]) {
17+
moduleWithoutCase[identifier].push(module);
18+
} else {
19+
moduleWithoutCase[identifier] = [module];
20+
}
21+
});
22+
Object.keys(moduleWithoutCase).forEach(key => {
23+
if(moduleWithoutCase[key].length > 1)
24+
compilation.warnings.push(new CaseSensitiveModulesWarning(moduleWithoutCase[key]));
25+
});
26+
});
2627
});
27-
});
28-
};
28+
}
29+
}
30+
31+
module.exports = WarnCaseSensitiveModulesPlugin;

test/WarnCaseSensitiveModulesPlugin.test.js

Lines changed: 0 additions & 72 deletions
This file was deleted.

0 commit comments

Comments
 (0)