webpack-dev-service 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +17 -0
  3. package/client/cjs/client.cjs +128 -0
  4. package/client/cjs/events.cjs +64 -0
  5. package/client/cjs/hot.cjs +111 -0
  6. package/client/cjs/index.cjs +15 -0
  7. package/client/cjs/main.cjs +53 -0
  8. package/client/cjs/ui/overlay.cjs +236 -0
  9. package/client/cjs/ui/progress.cjs +94 -0
  10. package/client/cjs/ui/utils/ansi/index.cjs +443 -0
  11. package/client/cjs/ui/utils/ansi/regx.cjs +70 -0
  12. package/client/cjs/ui/utils/ansi/utils.cjs +27 -0
  13. package/client/cjs/ui/utils/index.cjs +126 -0
  14. package/client/esm/client.js +126 -0
  15. package/client/esm/events.js +60 -0
  16. package/client/esm/hot.js +106 -0
  17. package/client/esm/index.js +10 -0
  18. package/client/esm/main.js +51 -0
  19. package/client/esm/ui/overlay.js +234 -0
  20. package/client/esm/ui/progress.js +92 -0
  21. package/client/esm/ui/utils/ansi/index.js +441 -0
  22. package/client/esm/ui/utils/ansi/regx.js +66 -0
  23. package/client/esm/ui/utils/ansi/utils.js +24 -0
  24. package/client/esm/ui/utils/index.js +120 -0
  25. package/global.d.ts +14 -0
  26. package/package.json +121 -0
  27. package/server/cjs/dev.cjs +50 -0
  28. package/server/cjs/hot.cjs +216 -0
  29. package/server/cjs/index.cjs +33 -0
  30. package/server/esm/dev.js +42 -0
  31. package/server/esm/hot.js +207 -0
  32. package/server/esm/index.js +25 -0
  33. package/types/client/client.d.ts +13 -0
  34. package/types/client/events.d.ts +35 -0
  35. package/types/client/hot.d.ts +27 -0
  36. package/types/client/index.d.ts +4 -0
  37. package/types/client/main.d.ts +4 -0
  38. package/types/client/message.d.ts +39 -0
  39. package/types/client/ui/overlay.d.ts +19 -0
  40. package/types/client/ui/progress.d.ts +15 -0
  41. package/types/client/ui/utils/ansi/enum.d.ts +12 -0
  42. package/types/client/ui/utils/ansi/index.d.ts +18 -0
  43. package/types/client/ui/utils/ansi/interface.d.ts +68 -0
  44. package/types/client/ui/utils/ansi/regx.d.ts +6 -0
  45. package/types/client/ui/utils/ansi/utils.d.ts +6 -0
  46. package/types/client/ui/utils/index.d.ts +9 -0
  47. package/types/server/dev.d.ts +17 -0
  48. package/types/server/hot.d.ts +16 -0
  49. package/types/server/index.d.ts +42 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 nuintun
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # webpack-dev-service
2
+
3
+ <!-- prettier-ignore -->
4
+ > A koa 2 middleware for webpack development and hot reloading.
5
+ >
6
+ > [![NPM Version][npm-image]][npm-url]
7
+ > [![Download Status][download-image]][npm-url]
8
+ > [![Snyk Vulnerabilities][snyk-image]][snyk-url]
9
+ > [![License][license-image]][license-url]
10
+
11
+ [npm-image]: https://img.shields.io/npm/v/webpack-dev-service?style=flat-square
12
+ [npm-url]: https://www.npmjs.org/package/webpack-dev-service
13
+ [download-image]: https://img.shields.io/npm/dm/webpack-dev-service?style=flat-square
14
+ [snyk-image]: https://img.shields.io/snyk/vulnerabilities/github/nuintun/webpack-dev-service?style=flat-square
15
+ [snyk-url]: https://snyk.io/test/github/nuintun/webpack-dev-service
16
+ [license-image]: https://img.shields.io/github/license/nuintun/webpack-dev-service?style=flat-square
17
+ [license-url]: https://github.com/nuintun/webpack-dev-service/blob/master/LICENSE
@@ -0,0 +1,128 @@
1
+ /**
2
+ * @package webpack-dev-service
3
+ * @license MIT
4
+ * @version 0.1.0
5
+ * @author nuintun <nuintun@qq.com>
6
+ * @description A koa 2 middleware for webpack development and hot reloading.
7
+ * @see https://github.com/nuintun/webpack-dev-service#readme
8
+ */
9
+
10
+ 'use strict';
11
+
12
+ const events = require('./events.cjs');
13
+ const overlay = require('./ui/overlay.cjs');
14
+ const progress = require('./ui/progress.cjs');
15
+ const hot = require('./hot.cjs');
16
+
17
+ /**
18
+ * @module client
19
+ */
20
+ function createClient(options) {
21
+ let updateTimer;
22
+ const UPDATE_DELAY = 128;
23
+ const RETRY_INTERVAL = 3000;
24
+ const progress$1 = new progress();
25
+ const overlay$1 = new overlay(options.name);
26
+ const fallback = error => {
27
+ if (options.live) {
28
+ self.location.reload();
29
+ } else if (error) {
30
+ console.error(error);
31
+ console.warn('Use fallback update but you turn off live reload, please reload by yourself.');
32
+ }
33
+ };
34
+ const applyUpdateAsync = () => {
35
+ updateTimer = self.setTimeout(() => {
36
+ hot.applyUpdate(options.hmr, fallback);
37
+ }, UPDATE_DELAY);
38
+ };
39
+ const onInvalid = () => {
40
+ clearTimeout(updateTimer);
41
+ if (options.progress) {
42
+ progress$1.update(0);
43
+ progress$1.show();
44
+ }
45
+ };
46
+ const onProgress = ({ value }) => {
47
+ if (options.progress) {
48
+ progress$1.update(value);
49
+ }
50
+ };
51
+ const onHash = ({ hash }) => {
52
+ hot.setHash(hash);
53
+ };
54
+ const setProblems = (type, problems) => {
55
+ const maps = {
56
+ errors: ['Error', 'error'],
57
+ warnings: ['Warning', 'warn']
58
+ };
59
+ if (options.overlay) {
60
+ overlay$1.setProblems(type, problems);
61
+ }
62
+ const [name, method] = maps[type];
63
+ const debug = console[method];
64
+ for (const { moduleName, message } of problems) {
65
+ debug(`\x1b[0m${name} in ${moduleName}\r\n\x1b[0m${message}`);
66
+ }
67
+ };
68
+ const onProblems = ({ errors, warnings }) => {
69
+ progress$1.hide();
70
+ setProblems('errors', errors);
71
+ setProblems('warnings', warnings);
72
+ if (options.overlay) {
73
+ overlay$1.show();
74
+ }
75
+ if (errors.length <= 0) {
76
+ applyUpdateAsync();
77
+ }
78
+ };
79
+ const onSuccess = () => {
80
+ overlay$1.hide();
81
+ progress$1.hide();
82
+ applyUpdateAsync();
83
+ };
84
+ const parseMessage = message => {
85
+ try {
86
+ return JSON.parse(message.data);
87
+ } catch {
88
+ return null;
89
+ }
90
+ };
91
+ const createWebSocket = url => {
92
+ const ws = new WebSocket(url);
93
+ ws.onmessage = message => {
94
+ const parsed = parseMessage(message);
95
+ if (parsed) {
96
+ const { action, payload } = parsed;
97
+ switch (action) {
98
+ case 'invalid':
99
+ onInvalid();
100
+ break;
101
+ case 'progress':
102
+ onProgress(payload);
103
+ break;
104
+ case 'hash':
105
+ onHash(payload);
106
+ break;
107
+ case 'problems':
108
+ onProblems(payload);
109
+ break;
110
+ case 'ok':
111
+ onSuccess();
112
+ break;
113
+ }
114
+ events.emit(action, payload, options);
115
+ }
116
+ };
117
+ ws.onclose = () => {
118
+ overlay$1.hide();
119
+ progress$1.hide();
120
+ setTimeout(() => {
121
+ createWebSocket(url);
122
+ }, RETRY_INTERVAL);
123
+ };
124
+ };
125
+ createWebSocket(options.host + options.path);
126
+ }
127
+
128
+ module.exports = createClient;
@@ -0,0 +1,64 @@
1
+ /**
2
+ * @package webpack-dev-service
3
+ * @license MIT
4
+ * @version 0.1.0
5
+ * @author nuintun <nuintun@qq.com>
6
+ * @description A koa 2 middleware for webpack development and hot reloading.
7
+ * @see https://github.com/nuintun/webpack-dev-service#readme
8
+ */
9
+
10
+ 'use strict';
11
+
12
+ /**
13
+ * @module events
14
+ */
15
+ const events = {
16
+ ok: [],
17
+ hash: [],
18
+ invalid: [],
19
+ problems: [],
20
+ progress: []
21
+ };
22
+ /**
23
+ * @function on
24
+ * @description Add an event listener callback.
25
+ * @param event Event name.
26
+ * @param callback Event listener callback.
27
+ */
28
+ function on(event, callback) {
29
+ const callbacks = events[event];
30
+ if (callbacks) {
31
+ callbacks.push(callback);
32
+ }
33
+ }
34
+ /**
35
+ * @function off
36
+ * @description Remove an event listener callback.
37
+ * @param event Event name.
38
+ * @param callback Event listener callback.
39
+ */
40
+ function off(event, callback) {
41
+ const callbacks = events[event];
42
+ if (callbacks) {
43
+ if (callback) {
44
+ const index = callbacks.indexOf(callback);
45
+ if (index >= 0) {
46
+ callbacks.splice(index, 1);
47
+ }
48
+ } else {
49
+ events[event] = [];
50
+ }
51
+ }
52
+ }
53
+ function emit(event, message, options) {
54
+ const callbacks = events[event];
55
+ if (callbacks && callbacks.length > 0) {
56
+ for (const callback of callbacks) {
57
+ callback(message, options);
58
+ }
59
+ }
60
+ }
61
+
62
+ exports.emit = emit;
63
+ exports.off = off;
64
+ exports.on = on;
@@ -0,0 +1,111 @@
1
+ /**
2
+ * @package webpack-dev-service
3
+ * @license MIT
4
+ * @version 0.1.0
5
+ * @author nuintun <nuintun@qq.com>
6
+ * @description A koa 2 middleware for webpack development and hot reloading.
7
+ * @see https://github.com/nuintun/webpack-dev-service#readme
8
+ */
9
+
10
+ 'use strict';
11
+
12
+ /**
13
+ * @module hot
14
+ */
15
+ // Last error.
16
+ let error;
17
+ // Last update hash.
18
+ let hash = __webpack_hash__;
19
+ // HMR status.
20
+ let status = 'idle';
21
+ /**
22
+ * @function isUpdateAvailable
23
+ * @description Is there a newer version of this code available.
24
+ */
25
+ function isUpdateAvailable() {
26
+ // __webpack_hash__ is the hash of the current compilation.
27
+ // It's a global variable injected by webpack.
28
+ return hash !== __webpack_hash__;
29
+ }
30
+ /**
31
+ * @function setHash
32
+ * @description Set webpack hash.
33
+ * @param value - The new hash value.
34
+ */
35
+ function setHash(value) {
36
+ hash = value;
37
+ }
38
+ /**
39
+ * @function setStatus
40
+ * @description Set hot status.
41
+ * @param value The new status of the hot update.
42
+ */
43
+ function setStatus(value) {
44
+ status = value;
45
+ }
46
+ // Initialize status.
47
+ if (undefined) {
48
+ setStatus(undefined.status());
49
+ }
50
+ /**
51
+ * @function applyUpdate
52
+ * @description Apply update.
53
+ * @param hmr Whether to enable HMR.
54
+ * @param fallback Fallback function when HMR fail.
55
+ */
56
+ function applyUpdate(hmr, fallback) {
57
+ // Update available.
58
+ if (isUpdateAvailable()) {
59
+ // HMR enabled.
60
+ if (hmr && undefined) {
61
+ switch (status) {
62
+ case 'idle':
63
+ // Set status.
64
+ setStatus('check');
65
+ // Auto check and apply updates.
66
+ undefined
67
+ .check(true)
68
+ .then(updated => {
69
+ // Update status.
70
+ setStatus(undefined.status());
71
+ // When updated modules is available,
72
+ // it indicates server is ready to serve new bundle.
73
+ if (updated) {
74
+ // While update completed, do it again until no update available.
75
+ applyUpdate(hmr, fallback);
76
+ }
77
+ })
78
+ .catch(exception => {
79
+ // Get status.
80
+ const status = undefined.status();
81
+ // Update status.
82
+ switch (status) {
83
+ case 'fail':
84
+ case 'abort':
85
+ setStatus(status);
86
+ default:
87
+ setStatus('fail');
88
+ }
89
+ // Cache error.
90
+ error = exception;
91
+ // Call fallback.
92
+ fallback(error);
93
+ });
94
+ break;
95
+ case 'fail':
96
+ case 'abort':
97
+ // Call fallback.
98
+ fallback(error);
99
+ break;
100
+ }
101
+ } else {
102
+ // HMR disabled.
103
+ fallback();
104
+ }
105
+ }
106
+ }
107
+
108
+ exports.applyUpdate = applyUpdate;
109
+ exports.isUpdateAvailable = isUpdateAvailable;
110
+ exports.setHash = setHash;
111
+ exports.setStatus = setStatus;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @package webpack-dev-service
3
+ * @license MIT
4
+ * @version 0.1.0
5
+ * @author nuintun <nuintun@qq.com>
6
+ * @description A koa 2 middleware for webpack development and hot reloading.
7
+ * @see https://github.com/nuintun/webpack-dev-service#readme
8
+ */
9
+
10
+ 'use strict';
11
+
12
+ const events = require('./events.cjs');
13
+
14
+ exports.off = events.off;
15
+ exports.on = events.on;
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @package webpack-dev-service
3
+ * @license MIT
4
+ * @version 0.1.0
5
+ * @author nuintun <nuintun@qq.com>
6
+ * @description A koa 2 middleware for webpack development and hot reloading.
7
+ * @see https://github.com/nuintun/webpack-dev-service#readme
8
+ */
9
+
10
+ 'use strict';
11
+
12
+ const client = require('./client.cjs');
13
+
14
+ /**
15
+ * @module main
16
+ */
17
+ const isTLS = protocol => {
18
+ return protocol === 'https:';
19
+ };
20
+ const getCurrentScript = () => {
21
+ const { currentScript } = document;
22
+ if (currentScript) {
23
+ return currentScript;
24
+ }
25
+ };
26
+ const resolveHost = params => {
27
+ let host = params.get('host');
28
+ let tls = params.get('tls') || isTLS(self.location.protocol);
29
+ if (!host) {
30
+ const script = getCurrentScript();
31
+ if (script) {
32
+ const { src } = script;
33
+ const url = new URL(src);
34
+ host = url.host;
35
+ tls = isTLS(url.protocol) || tls;
36
+ } else {
37
+ host = self.location.host;
38
+ }
39
+ }
40
+ return `${tls ? 'wss' : 'ws'}://${host}`;
41
+ };
42
+ const resolveOptions = () => {
43
+ const params = new URLSearchParams(__resourceQuery);
44
+ const host = resolveHost(params);
45
+ const live = params.get('live') !== 'false';
46
+ const overlay = params.get('overlay') !== 'false';
47
+ try {
48
+ return { ...__WDS_HOT_OPTIONS__, host, live, overlay };
49
+ } catch {
50
+ throw new Error('Imported the hot client but the hot server is not enabled.');
51
+ }
52
+ };
53
+ client(resolveOptions());
@@ -0,0 +1,236 @@
1
+ /**
2
+ * @package webpack-dev-service
3
+ * @license MIT
4
+ * @version 0.1.0
5
+ * @author nuintun <nuintun@qq.com>
6
+ * @description A koa 2 middleware for webpack development and hot reloading.
7
+ * @see https://github.com/nuintun/webpack-dev-service#readme
8
+ */
9
+
10
+ 'use strict';
11
+
12
+ const index = require('./utils/index.cjs');
13
+
14
+ /**
15
+ * @module overlay
16
+ * @see https://github.com/shellscape/webpack-plugin-serve
17
+ */
18
+ const OVERLAY = 'wds-overlay';
19
+ const CSS = `
20
+ .${OVERLAY} {
21
+ top:0;
22
+ left: 0;
23
+ right: 0;
24
+ bottom: 0;
25
+ display: flex;
26
+ position: fixed;
27
+ font-size: 16px;
28
+ overflow: hidden;
29
+ font-style: normal;
30
+ font-weight: normal;
31
+ z-index: 2147483646;
32
+ flex-direction: column;
33
+ box-sizing: border-box;
34
+ transform-origin: center;
35
+ background: rgba(0, 0, 0, .85);
36
+ transform: scale(0) translateZ(0);
37
+ transition: transform .25s ease-out;
38
+ font-family: Consolas, "Lucida Console", monospace;
39
+ }
40
+ .${OVERLAY}-show {
41
+ transform: scale(1) translateZ(0);
42
+ }
43
+ .${OVERLAY}-close {
44
+ top: 16px;
45
+ right: 16px;
46
+ width: 16px;
47
+ height: 16px;
48
+ cursor: pointer;
49
+ position: absolute;
50
+ border-radius: 16px;
51
+ background: #ff5f58;
52
+ display: inline-block;
53
+ transform-origin: center;
54
+ box-shadow: #ff5f58 0 0 6px;
55
+ transform: rotate(0) translateZ(0);
56
+ transition: transform .25s ease-in-out;
57
+ }
58
+ .${OVERLAY}-close:before,
59
+ .${OVERLAY}-close:after {
60
+ top: 7px;
61
+ left: 3px;
62
+ content: "";
63
+ width: 10px;
64
+ height: 2px;
65
+ position: absolute;
66
+ background-color: white;
67
+ transform-origin: center;
68
+ }
69
+ .${OVERLAY}-close:before {
70
+ transform: rotate(45deg);
71
+ }
72
+ .${OVERLAY}-close:after {
73
+ transform: rotate(-45deg);
74
+ }
75
+ .${OVERLAY}-close:hover {
76
+ transform: rotate(180deg) translateZ(0);
77
+ }
78
+ .${OVERLAY}-title {
79
+ margin: 0;
80
+ color: #fff;
81
+ line-height: 16px;
82
+ text-align: center;
83
+ background: #282d35;
84
+ overflow-wrap: break-word;
85
+ border-radius: 0 0 4px 4px;
86
+ padding: 16px 48px 16px 16px;
87
+ }
88
+ .${OVERLAY}-name {
89
+ font-weight: bold;
90
+ font-style: normal;
91
+ text-transform: uppercase;
92
+ }
93
+ .${OVERLAY}-errors-title,
94
+ .${OVERLAY}-warnings-title {
95
+ color: #ff5f58;
96
+ padding-left: 8px;
97
+ font-style: normal;
98
+ }
99
+ .${OVERLAY}-warnings-title {
100
+ color: #ffbd2e;
101
+ }
102
+ .${OVERLAY}-problems {
103
+ padding: 0 16px;
104
+ overflow-y: auto;
105
+ scrollbar-width: none;
106
+ -ms-overflow-style: none;
107
+ -ms-scroll-chaining: none;
108
+ overscroll-behavior: contain;
109
+ -webkit-overflow-scrolling: touch;
110
+ }
111
+ .${OVERLAY}-problems::-webkit-scrollbar {
112
+ display: none;
113
+ }
114
+ .${OVERLAY}-errors,
115
+ .${OVERLAY}-warnings {
116
+ color: #ddd;
117
+ padding: 16px;
118
+ margin: 16px 0;
119
+ display: block;
120
+ line-height: 1.2;
121
+ border-radius: 4px;
122
+ background: #282d35;
123
+ white-space: pre-wrap;
124
+ font-family: Consolas, "Lucida Console", monospace;
125
+ }
126
+ .${OVERLAY}-errors > div,
127
+ .${OVERLAY}-warnings > div {
128
+ overflow-wrap: break-word;
129
+ }
130
+ .${OVERLAY}-errors > div + div,
131
+ .${OVERLAY}-warnings > div + div {
132
+ margin: 16px 0 0;
133
+ }
134
+ .${OVERLAY}-errors > div > em,
135
+ .${OVERLAY}-warnings > div > em {
136
+ line-height: 1;
137
+ color: #641e16;
138
+ padding: 4px 8px;
139
+ font-style: normal;
140
+ border-radius: 4px;
141
+ font-weight: normal;
142
+ background: #ff5f58;
143
+ display: inline-block;
144
+ text-transform: uppercase;
145
+ }
146
+ .${OVERLAY}-warnings > div > em {
147
+ color: #3e2723;
148
+ background: #ffbd2e;
149
+ }
150
+ .${OVERLAY}-errors > div > div,
151
+ .${OVERLAY}-warnings > div > div {
152
+ font-size: 14px;
153
+ padding: 8px 0 0 16px;
154
+ overflow-wrap: break-word;
155
+ }
156
+ .${OVERLAY}-hidden {
157
+ display: none;
158
+ }
159
+ `;
160
+ const DEFAULT_NAME = 'webpack';
161
+ const HTML = `
162
+ <aside class="${OVERLAY}">
163
+ <i class="${OVERLAY}-close"></i>
164
+ <div class="${OVERLAY}-title">
165
+ <em class="${OVERLAY}-name"></em>
166
+ <em class="${OVERLAY}-errors-title"></em>
167
+ <em class="${OVERLAY}-warnings-title"></em>
168
+ </div>
169
+ <article class="${OVERLAY}-problems">
170
+ <pre class="${OVERLAY}-errors ${OVERLAY}-hidden"></pre>
171
+ <pre class="${OVERLAY}-warnings ${OVERLAY}-hidden"></pre>
172
+ </article>
173
+ </aside>
174
+ `;
175
+ class Overlay {
176
+ hidden = true;
177
+ name;
178
+ close;
179
+ aside;
180
+ errorsList;
181
+ errorsTitle;
182
+ warningsList;
183
+ warningsTitle;
184
+ constructor(name) {
185
+ index.injectCSS(CSS);
186
+ [this.aside] = index.appendHTML(HTML);
187
+ this.name = this.aside.querySelector(`.${OVERLAY}-name`);
188
+ this.close = this.aside.querySelector(`.${OVERLAY}-close`);
189
+ this.errorsList = this.aside.querySelector(`.${OVERLAY}-errors`);
190
+ this.warningsList = this.aside.querySelector(`.${OVERLAY}-warnings`);
191
+ this.errorsTitle = this.aside.querySelector(`.${OVERLAY}-errors-title`);
192
+ this.warningsTitle = this.aside.querySelector(`.${OVERLAY}-warnings-title`);
193
+ this.name.innerHTML = `⭕ ${name || DEFAULT_NAME}`;
194
+ this.close.addEventListener('click', () => {
195
+ this.hide();
196
+ });
197
+ }
198
+ setProblems(type, problems) {
199
+ const count = problems.length;
200
+ const hidden = `${OVERLAY}-hidden`;
201
+ const problemMaps = {
202
+ errors: ['Error', this.errorsTitle, this.errorsList],
203
+ warnings: ['Warning', this.warningsTitle, this.warningsList]
204
+ };
205
+ const [name, problemTitle, problemList] = problemMaps[type];
206
+ if (count > 0) {
207
+ let html = '';
208
+ problemTitle.innerText = `${count} ${name}(s)`;
209
+ for (const { moduleName = 'unknown', message } of problems) {
210
+ const src = index.ansiToHTML(moduleName);
211
+ const details = index.ansiToHTML(message);
212
+ html += `<div><em>${name}</em> in ${src}<div>${details}</div></div>`;
213
+ }
214
+ problemList.innerHTML = html;
215
+ problemList.classList.remove(hidden);
216
+ problemTitle.classList.remove(hidden);
217
+ } else {
218
+ problemList.classList.add(hidden);
219
+ problemTitle.classList.add(hidden);
220
+ }
221
+ }
222
+ show() {
223
+ if (this.hidden) {
224
+ this.hidden = false;
225
+ this.aside.classList.add(`${OVERLAY}-show`);
226
+ }
227
+ }
228
+ hide() {
229
+ if (!this.hidden) {
230
+ this.hidden = true;
231
+ this.aside.classList.remove(`${OVERLAY}-show`);
232
+ }
233
+ }
234
+ }
235
+
236
+ module.exports = Overlay;