source: frontend/node_modules/@pmmmwh/react-refresh-webpack-plugin/overlay/components/CompileErrorTrace.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.6 KB
Line 
1const ansiHTML = require('ansi-html');
2const entities = require('html-entities');
3const theme = require('../theme.js');
4const utils = require('../utils.js');
5
6ansiHTML.setColors(theme);
7
8/**
9 * @typedef {Object} CompileErrorTraceProps
10 * @property {string} errorMessage
11 */
12
13/**
14 * A formatter that turns Webpack compile error messages into highlighted HTML source traces.
15 * @param {Document} document
16 * @param {HTMLElement} root
17 * @param {CompileErrorTraceProps} props
18 * @returns {void}
19 */
20function CompileErrorTrace(document, root, props) {
21 const errorParts = props.errorMessage.split('\n');
22 if (errorParts.length) {
23 if (errorParts[0]) {
24 errorParts[0] = utils.formatFilename(errorParts[0]);
25 }
26
27 const errorMessage = errorParts.splice(1, 1)[0];
28 if (errorMessage) {
29 // Strip filename from the error message
30 errorParts.unshift(errorMessage.replace(/^(.*:)\s.*:(\s.*)$/, '$1$2'));
31 }
32 }
33
34 const stackContainer = document.createElement('pre');
35 stackContainer.innerHTML = entities.decode(
36 ansiHTML(entities.encode(errorParts.join('\n'), { level: 'html5', mode: 'nonAscii' })),
37 { level: 'html5' }
38 );
39 stackContainer.style.fontFamily = [
40 '"Operator Mono SSm"',
41 '"Operator Mono"',
42 '"Fira Code Retina"',
43 '"Fira Code"',
44 '"FiraCode-Retina"',
45 '"Andale Mono"',
46 '"Lucida Console"',
47 'Menlo',
48 'Consolas',
49 'Monaco',
50 'monospace',
51 ].join(', ');
52 stackContainer.style.margin = '0';
53 stackContainer.style.whiteSpace = 'pre-wrap';
54
55 root.appendChild(stackContainer);
56}
57
58module.exports = CompileErrorTrace;
Note: See TracBrowser for help on using the repository browser.