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