1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const tslib_1 = require("tslib");
|
4 | const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
5 | const friendlySyntaxErrorLabel = 'Syntax error:';
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | function formatMessage(message) {
|
13 | let lines = message.split('\n');
|
14 |
|
15 | lines = lines.filter(line => !/Module [A-z ]+\(from/.test(line));
|
16 |
|
17 |
|
18 |
|
19 | if (lines.length > 2 && ~lines[0].indexOf(lines[1].slice(2))) {
|
20 | lines.splice(1, 1);
|
21 | }
|
22 |
|
23 | lines = lines.filter(line => line.indexOf(' @ ') !== 0);
|
24 |
|
25 | lines = lines.map(line => {
|
26 | const parseError = /Line (\d+):(?:(\d+):)?\s*Parsing error: (.+)$/.exec(line);
|
27 | if (!parseError) {
|
28 | return line;
|
29 | }
|
30 | const [, errorLine, errorColumn, errorMessage] = parseError;
|
31 | return `${friendlySyntaxErrorLabel} ${errorMessage} (${errorLine}:${errorColumn})`;
|
32 | });
|
33 |
|
34 | if (lines.length > 2 && lines[1].trim() === '') {
|
35 | lines.splice(1, 1);
|
36 | }
|
37 |
|
38 | if (lines[1] && lines[1].indexOf('Module not found: ') === 0) {
|
39 | lines = [
|
40 | lines[0],
|
41 | lines[1]
|
42 | .replace('Error: ', '')
|
43 | .replace('Module not found: Cannot find file:', 'Cannot find file:'),
|
44 | ];
|
45 | }
|
46 |
|
47 | if (lines[0]) {
|
48 | lines[0] = chalk_1.default.underline.bold(lines[0]);
|
49 | }
|
50 | message = lines.join('\n');
|
51 |
|
52 |
|
53 |
|
54 |
|
55 | message = message.replace(/^\s*at\s((?!webpack:).)*:\d+:\d+[\s)]*(\n|$)/gm, '');
|
56 | message = message.replace(/^\s*at\s<anonymous>(\n|$)/gm, '');
|
57 | lines = message.split('\n');
|
58 |
|
59 | lines = lines.filter((line, index, arr) => index === 0 || line.trim() !== '' || line.trim() !== arr[index - 1].trim());
|
60 |
|
61 | message = lines.join('\n');
|
62 | return message.trim();
|
63 | }
|
64 | function formatWebpackMessages(json // Webpack's stat output is typed as any
|
65 | ) {
|
66 | const errors = json.errors
|
67 | .map((message) => formatMessage(message))
|
68 | .filter(message => message !== '');
|
69 | const warnings = json.warnings
|
70 | .map((message) => formatMessage(message))
|
71 | .filter(message => message !== '');
|
72 | return {
|
73 | errors,
|
74 | warnings,
|
75 | };
|
76 | }
|
77 | exports.formatWebpackMessages = formatWebpackMessages;
|
78 |
|
\ | No newline at end of file |