@@ -10,155 +10,13 @@ import {
1010import { formatStatsMessages } from '../helpers/format' ;
1111import { logger } from '../logger' ;
1212import type { DevConfig , Rspack } from '../types' ;
13- import ansiHTML from './ansiHTML ' ;
14- import { escapeHtml , getCompilationId } from './helper ' ;
13+ import { getCompilationId } from './helper ' ;
14+ import { genOverlayHTML } from './overlay ' ;
1515
1616interface ExtWebSocket extends Ws {
1717 isAlive : boolean ;
1818}
1919
20- function convertLinksInHtml ( text : string ) : string {
21- const fileRegex = / (?: [ a - z A - Z ] : \\ | \/ ) .* ?: \d + : \d + / g;
22-
23- return text . replace ( fileRegex , ( file ) => {
24- // If the file contains `</span>`, it means the file path contains ANSI codes.
25- // We need to move the `</span>` to the end of the file path.
26- const hasClosingSpan = file . includes ( '</span>' ) && ! file . includes ( '<span' ) ;
27- const filePath = hasClosingSpan ? file . replace ( '</span>' , '' ) : file ;
28-
29- return `<a class="file-link" data-file="${ filePath } ">${ filePath } </a>${
30- hasClosingSpan ? '</span>' : ''
31- } `;
32- } ) ;
33- }
34-
35- // HTML template for error overlay
36- function genOverlayHTML ( errors : string [ ] ) {
37- const htmlItems = errors . map ( ( item ) =>
38- convertLinksInHtml ( ansiHTML ( escapeHtml ( item ) ) ) ,
39- ) ;
40- return `
41- <style>
42- .root {
43- position: fixed;
44- z-index: 9999;
45- top: 0;
46- left: 0;
47- width: 100%;
48- height: 100%;
49- overflow-y: scroll;
50- margin: 0;
51- background: rgba(0, 0, 0, 0.66);
52- cursor: pointer;
53- }
54- .container {
55- font-family: Menlo, Consolas, monospace;
56- line-height: 1.6;
57- width: 960px;
58- max-width: 85%;
59- color: #d8d8d8;
60- margin: 32px auto;
61- padding: 32px 40px;
62- position: relative;
63- background: #181818;
64- border-radius: 24px;
65- box-shadow: 0 19px 38px rgba(0,0,0,0.30), 0 15px 12px rgba(0,0,0,0.22);
66- overflow: hidden;
67- direction: ltr;
68- text-align: left;
69- box-sizing: border-box;
70- cursor: default;
71- }
72- .title {
73- margin: 0 0 20px;
74- padding-bottom: 12px;
75- font-size: 17px;
76- font-weight: 600;
77- color: #fb6a6a;
78- border-bottom: 2px solid rgba(252,94,94,.66);
79- }
80- .content {
81- margin: 0;
82- font-size: 14px;
83- font-family: inherit;
84- overflow-x: scroll;
85- scrollbar-width: none;
86- }
87- .content::-webkit-scrollbar {
88- display: none;
89- }
90- .file-link {
91- cursor: pointer;
92- color: #6eecf7;
93- text-decoration: underline;
94- text-underline-offset: 3px;
95- &:hover {
96- opacity: 0.8;
97- }
98- &:active {
99- opacity: 0.6;
100- }
101- }
102- .close {
103- position: absolute;
104- top: 27px;
105- right: 32px;
106- width: 32px;
107- height: 32px;
108- cursor: pointer;
109- }
110- .close:hover {
111- opacity: 0.8;
112- }
113- .close:active {
114- opacity: 0.6;
115- }
116- .close:before,
117- .close:after {
118- position: absolute;
119- left: 16px;
120- top: 8px;
121- content: ' ';
122- height: 18px;
123- width: 2px;
124- border-radius: 4px;
125- background-color: #b8b8b8;
126- }
127- .close:before {
128- transform: rotate(45deg);
129- }
130- .close:after {
131- transform: rotate(-45deg);
132- }
133- .footer {
134- font-size: 12px;
135- color: #7e6a92;
136- margin-top: 20px;
137- padding-top: 12px;
138- border-top: 2px solid rgba(126,106,146,.6);
139- }
140- .footer p {
141- margin: 4px 0 0;
142- }
143- .footer span {
144- color: #a88dc3;
145- }
146- </style>
147-
148- <div class="root">
149- <div class="container">
150- <div class="close"></div>
151- <p class="title">Build failed</p>
152- <pre class="content">${ htmlItems . join ( '\n\n' ) . trim ( ) } </pre>
153- <footer class="footer">
154- <p><span>Fix error</span>, click outside, or press Esc to close the overlay.</p>
155- <p>Disable overlay by setting Rsbuild's <span>dev.client.overlay</span> config to false.<p>
156- </footer>
157- </div>
158- </div>
159- ` ;
160- }
161-
16220function isEqualSet ( a : Set < string > , b : Set < string > ) : boolean {
16321 return a . size === b . size && [ ...a ] . every ( ( value ) => b . has ( value ) ) ;
16422}
0 commit comments