source: trip-planner-front/node_modules/webpack/lib/CaseSensitiveModulesWarning.js@ ceaed42

Last change on this file since ceaed42 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.1 KB
Line 
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5
6"use strict";
7
8const WebpackError = require("./WebpackError");
9
10/** @typedef {import("./Module")} Module */
11/** @typedef {import("./ModuleGraph")} ModuleGraph */
12
13/**
14 * @param {Module[]} modules the modules to be sorted
15 * @returns {Module[]} sorted version of original modules
16 */
17const sortModules = modules => {
18 return modules.sort((a, b) => {
19 const aIdent = a.identifier();
20 const bIdent = b.identifier();
21 /* istanbul ignore next */
22 if (aIdent < bIdent) return -1;
23 /* istanbul ignore next */
24 if (aIdent > bIdent) return 1;
25 /* istanbul ignore next */
26 return 0;
27 });
28};
29
30/**
31 * @param {Module[]} modules each module from throw
32 * @param {ModuleGraph} moduleGraph the module graph
33 * @returns {string} each message from provided modules
34 */
35const createModulesListMessage = (modules, moduleGraph) => {
36 return modules
37 .map(m => {
38 let message = `* ${m.identifier()}`;
39 const validReasons = Array.from(
40 moduleGraph.getIncomingConnectionsByOriginModule(m).keys()
41 ).filter(x => x);
42
43 if (validReasons.length > 0) {
44 message += `\n Used by ${validReasons.length} module(s), i. e.`;
45 message += `\n ${validReasons[0].identifier()}`;
46 }
47 return message;
48 })
49 .join("\n");
50};
51
52class CaseSensitiveModulesWarning extends WebpackError {
53 /**
54 * Creates an instance of CaseSensitiveModulesWarning.
55 * @param {Iterable<Module>} modules modules that were detected
56 * @param {ModuleGraph} moduleGraph the module graph
57 */
58 constructor(modules, moduleGraph) {
59 const sortedModules = sortModules(Array.from(modules));
60 const modulesList = createModulesListMessage(sortedModules, moduleGraph);
61 super(`There are multiple modules with names that only differ in casing.
62This can lead to unexpected behavior when compiling on a filesystem with other case-semantic.
63Use equal casing. Compare these module identifiers:
64${modulesList}`);
65
66 this.name = "CaseSensitiveModulesWarning";
67 this.module = sortedModules[0];
68 }
69}
70
71module.exports = CaseSensitiveModulesWarning;
Note: See TracBrowser for help on using the repository browser.