webpack-dev-service 0.9.0 → 0.10.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 (57) hide show
  1. package/{server/cjs → cjs/server}/index.cjs +1 -1
  2. package/package.json +13 -28
  3. package/client/cjs/client.cjs +0 -128
  4. package/client/cjs/events.cjs +0 -64
  5. package/client/cjs/hot.cjs +0 -111
  6. package/client/cjs/index.cjs +0 -15
  7. package/client/cjs/main.cjs +0 -59
  8. package/client/cjs/ui/overlay.cjs +0 -233
  9. package/client/cjs/ui/progress.cjs +0 -92
  10. package/client/cjs/ui/utils.cjs +0 -136
  11. package/client/esm/client.js +0 -126
  12. package/client/esm/events.js +0 -60
  13. package/client/esm/hot.js +0 -106
  14. package/client/esm/index.js +0 -10
  15. package/client/esm/main.js +0 -57
  16. package/client/esm/ui/overlay.js +0 -231
  17. package/client/esm/ui/progress.js +0 -90
  18. package/client/esm/ui/utils.js +0 -123
  19. package/server/cjs/compose.cjs +0 -56
  20. package/server/cjs/dev/Service.cjs +0 -269
  21. package/server/cjs/dev/index.cjs +0 -60
  22. package/server/cjs/dev/middleware.cjs +0 -96
  23. package/server/cjs/dev/utils/fs.cjs +0 -29
  24. package/server/cjs/dev/utils/hash.cjs +0 -46
  25. package/server/cjs/dev/utils/http.cjs +0 -227
  26. package/server/cjs/dev/utils/path.cjs +0 -46
  27. package/server/cjs/dev/utils/paths.cjs +0 -59
  28. package/server/cjs/dev/utils/ready.cjs +0 -23
  29. package/server/cjs/dev/utils/setupHooks.cjs +0 -106
  30. package/server/cjs/dev/utils/setupOutputFileSystem.cjs +0 -31
  31. package/server/cjs/dev/utils/setupWatching.cjs +0 -43
  32. package/server/cjs/dev/utils/setupWriteToDisk.cjs +0 -54
  33. package/server/cjs/hot/Socket.cjs +0 -174
  34. package/server/cjs/hot/index.cjs +0 -34
  35. package/server/cjs/hot/utils.cjs +0 -100
  36. package/server/cjs/schema.cjs +0 -127
  37. package/server/cjs/utils.cjs +0 -45
  38. package/server/esm/compose.js +0 -54
  39. package/server/esm/dev/Service.js +0 -260
  40. package/server/esm/dev/index.js +0 -58
  41. package/server/esm/dev/middleware.js +0 -94
  42. package/server/esm/dev/utils/fs.js +0 -27
  43. package/server/esm/dev/utils/hash.js +0 -44
  44. package/server/esm/dev/utils/http.js +0 -216
  45. package/server/esm/dev/utils/path.js +0 -42
  46. package/server/esm/dev/utils/paths.js +0 -57
  47. package/server/esm/dev/utils/ready.js +0 -21
  48. package/server/esm/dev/utils/setupHooks.js +0 -98
  49. package/server/esm/dev/utils/setupOutputFileSystem.js +0 -29
  50. package/server/esm/dev/utils/setupWatching.js +0 -41
  51. package/server/esm/dev/utils/setupWriteToDisk.js +0 -52
  52. package/server/esm/hot/Socket.js +0 -165
  53. package/server/esm/hot/index.js +0 -32
  54. package/server/esm/hot/utils.js +0 -93
  55. package/server/esm/index.js +0 -37
  56. package/server/esm/schema.js +0 -125
  57. package/server/esm/utils.js +0 -37
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.9.0
4
+ * @version 0.10.0
5
5
  * @author nuintun <nuintun@qq.com>
6
6
  * @description A koa 2 middleware for webpack development and hot reloading.
7
7
  * @see https://github.com/nuintun/webpack-dev-service#readme
package/package.json CHANGED
@@ -1,34 +1,24 @@
1
1
  {
2
2
  "name": "webpack-dev-service",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "description": "A koa 2 middleware for webpack development and hot reloading.",
5
5
  "type": "module",
6
6
  "sideEffects": [
7
- "client/esm/main.js",
8
- "client/cjs/main.cjs"
7
+ "esm/client/main.js",
8
+ "cjs/client/main.cjs"
9
9
  ],
10
- "main": "server/cjs/index.cjs",
11
- "module": "server/esm/index.js",
10
+ "main": "cjs/server/index.cjs",
11
+ "module": "esm/server/index.js",
12
12
  "types": "types/server/index.d.ts",
13
13
  "exports": {
14
14
  ".": {
15
- "import": "./server/esm/index.js",
16
- "require": "./server/cjs/index.cjs",
15
+ "import": "./esm/server/index.js",
16
+ "require": "./cjs/server/index.cjs",
17
17
  "types": "./types/server/index.d.ts"
18
18
  },
19
19
  "./client": {
20
- "import": "./client/esm/main.js",
21
- "require": "./client/cjs/main.cjs",
22
- "types": "./types/client/main.d.ts"
23
- },
24
- "./client?*": {
25
- "import": "./client/esm/main.js?*",
26
- "require": "./client/cjs/main.cjs?*",
27
- "types": "./types/client/main.d.ts"
28
- },
29
- "./events": {
30
- "import": "./client/esm/index.js",
31
- "require": "./client/cjs/index.cjs",
20
+ "import": "./esm/client/index.js",
21
+ "require": "./cjs/client/index.cjs",
32
22
  "types": "./types/client/index.d.ts"
33
23
  }
34
24
  },
@@ -38,12 +28,6 @@
38
28
  "./types/server/index.d.ts"
39
29
  ],
40
30
  "client": [
41
- "./types/client/main.d.ts"
42
- ],
43
- "client?*": [
44
- "./types/client/main.d.ts"
45
- ],
46
- "events": [
47
31
  "./types/client/index.d.ts"
48
32
  ]
49
33
  }
@@ -102,15 +86,16 @@
102
86
  "ws": "^8.16.0"
103
87
  },
104
88
  "devDependencies": {
89
+ "@rollup/plugin-replace": "^5.0.5",
105
90
  "@rollup/plugin-typescript": "^11.1.6",
106
91
  "@swc/core": "^1.4.11",
107
- "@swc/helpers": "^0.5.7",
92
+ "@swc/helpers": "^0.5.8",
108
93
  "@types/destroy": "^1.0.3",
109
94
  "@types/etag": "^1.8.3",
110
95
  "@types/koa-compose": "^3.2.8",
111
96
  "@types/node": "^20.11.30",
112
97
  "@types/range-parser": "^1.2.7",
113
- "@types/react": "^18.2.72",
98
+ "@types/react": "^18.2.73",
114
99
  "@types/react-dom": "^18.2.22",
115
100
  "css-loader": "^6.10.0",
116
101
  "html-webpack-plugin": "^5.6.0",
@@ -123,7 +108,7 @@
123
108
  "react": "^18.2.0",
124
109
  "react-dom": "^18.2.0",
125
110
  "rimraf": "^5.0.5",
126
- "rollup": "^4.13.0",
111
+ "rollup": "^4.13.1",
127
112
  "swc-loader": "^0.2.6",
128
113
  "tsc-alias": "^1.8.8",
129
114
  "typescript": "^5.4.3",
@@ -1,128 +0,0 @@
1
- /**
2
- * @package webpack-dev-service
3
- * @license MIT
4
- * @version 0.9.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 = () => {
27
- if (options.reload) {
28
- self.location.reload();
29
- } else {
30
- console.warn('Use fallback update but you turn off live reload, please reload by yourself.');
31
- }
32
- };
33
- const applyUpdateAsync = () => {
34
- updateTimer = self.setTimeout(() => {
35
- hot.applyUpdate(options.hmr, fallback);
36
- }, UPDATE_DELAY);
37
- };
38
- const onInvalid = () => {
39
- clearTimeout(updateTimer);
40
- if (options.progress) {
41
- progress$1.update(0);
42
- progress$1.show();
43
- }
44
- };
45
- const onProgress = ({ value }) => {
46
- if (options.progress) {
47
- progress$1.update(value);
48
- }
49
- };
50
- const onHash = ({ hash }) => {
51
- hot.setHash(hash);
52
- };
53
- const setIssues = (type, issues) => {
54
- if (options.overlay) {
55
- overlay$1.setIssues(type, issues);
56
- }
57
- const maps = {
58
- errors: ['\x1b[38;2;100;30;22m\x1b[48;2;255;95;88m ERROR \x1b[0m', 'error'],
59
- warnings: ['\x1b[38;2;32;39;35m\x1b[48;2;255;189;46m WARNING \x1b[0m', 'warn']
60
- };
61
- const [name, method] = maps[type];
62
- const debug = console[method];
63
- for (const { moduleName, chunkName, message } of issues) {
64
- const filename = moduleName || chunkName || 'unknown';
65
- debug(`${name} in ${filename}\n${message}`);
66
- }
67
- };
68
- const onIssues = ({ errors, warnings }) => {
69
- progress$1.hide();
70
- setIssues('errors', errors);
71
- setIssues('warnings', warnings);
72
- if (options.overlay) {
73
- overlay$1.show();
74
- }
75
- if (errors.length <= 0) {
76
- applyUpdateAsync();
77
- }
78
- };
79
- const onOk = () => {
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 (_a) {
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 'issues':
108
- onIssues(payload);
109
- break;
110
- case 'ok':
111
- onOk();
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.origin}${options.path}`);
126
- }
127
-
128
- module.exports = createClient;
@@ -1,64 +0,0 @@
1
- /**
2
- * @package webpack-dev-service
3
- * @license MIT
4
- * @version 0.9.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
- issues: [],
19
- invalid: [],
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;
@@ -1,111 +0,0 @@
1
- /**
2
- * @package webpack-dev-service
3
- * @license MIT
4
- * @version 0.9.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 (module.hot) {
48
- setStatus(module.hot.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 && module.hot) {
61
- switch (status) {
62
- case 'idle':
63
- // Set status.
64
- setStatus('check');
65
- // Auto check and apply updates.
66
- module.hot
67
- .check(true)
68
- .then(updated => {
69
- // Update status.
70
- setStatus(module.hot.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 = module.hot.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;
@@ -1,15 +0,0 @@
1
- /**
2
- * @package webpack-dev-service
3
- * @license MIT
4
- * @version 0.9.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;
@@ -1,59 +0,0 @@
1
- /**
2
- * @package webpack-dev-service
3
- * @license MIT
4
- * @version 0.9.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 getProtocol = (params, protocol) => {
27
- switch (params.get('wss')) {
28
- case 'true':
29
- return 'wss:';
30
- case 'false':
31
- return 'ws:';
32
- default:
33
- return isTLS(protocol) ? 'wss:' : 'ws:';
34
- }
35
- };
36
- const getOrigin = params => {
37
- const { location } = self;
38
- const script = getCurrentScript();
39
- if (script) {
40
- const url = new URL(script.src, location.href);
41
- const protocol = getProtocol(params, url.protocol);
42
- return `${protocol}//${url.host}`;
43
- }
44
- const protocol = getProtocol(params, location.protocol);
45
- return `${protocol}//${location.host}`;
46
- };
47
- const getOptions = () => {
48
- const params = new URLSearchParams(__resourceQuery);
49
- return {
50
- origin: getOrigin(params),
51
- hmr: params.get('hmr') !== 'false',
52
- path: params.get('path') || '/hot',
53
- name: params.get('name') || 'webpack',
54
- reload: params.get('reload') !== 'false',
55
- overlay: params.get('overlay') !== 'false',
56
- progress: params.get('progress') !== 'false'
57
- };
58
- };
59
- client(getOptions());
@@ -1,233 +0,0 @@
1
- /**
2
- * @package webpack-dev-service
3
- * @license MIT
4
- * @version 0.9.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 utils = require('./utils.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
- border-radius: 0 0 4px 4px;
85
- padding: 16px 48px 16px 16px;
86
- }
87
- .${OVERLAY}-name {
88
- font-weight: bold;
89
- font-style: normal;
90
- text-transform: uppercase;
91
- }
92
- .${OVERLAY}-errors-title,
93
- .${OVERLAY}-warnings-title {
94
- color: #ff5f58;
95
- padding-left: 8px;
96
- font-style: normal;
97
- }
98
- .${OVERLAY}-warnings-title {
99
- color: #ffbd2e;
100
- }
101
- .${OVERLAY}-issues {
102
- padding: 0 16px;
103
- overflow-y: auto;
104
- scrollbar-width: none;
105
- -ms-overflow-style: none;
106
- -ms-scroll-chaining: none;
107
- overscroll-behavior: contain;
108
- -webkit-overflow-scrolling: touch;
109
- }
110
- .${OVERLAY}-issues::-webkit-scrollbar {
111
- display: none;
112
- }
113
- .${OVERLAY}-errors,
114
- .${OVERLAY}-warnings {
115
- color: #ddd;
116
- padding: 16px;
117
- margin: 16px 0;
118
- display: block;
119
- line-height: 1.2;
120
- border-radius: 4px;
121
- background: #282d35;
122
- }
123
- .${OVERLAY}-errors > section + section,
124
- .${OVERLAY}-warnings > section + section {
125
- margin: 16px 0 0;
126
- }
127
- .${OVERLAY}-errors > section > em,
128
- .${OVERLAY}-warnings > section > em {
129
- line-height: 1;
130
- color: #641e16;
131
- padding: 4px 8px;
132
- font-style: normal;
133
- border-radius: 4px;
134
- font-weight: normal;
135
- background: #ff5f58;
136
- display: inline-block;
137
- text-transform: uppercase;
138
- }
139
- .${OVERLAY}-warnings > section > em {
140
- color: #3e2723;
141
- background: #ffbd2e;
142
- }
143
- .${OVERLAY}-errors > section > pre,
144
- .${OVERLAY}-warnings > section > pre {
145
- margin: 0;
146
- font-size: 14px;
147
- font-family: inherit;
148
- padding: 8px 0 0 16px;
149
- white-space: pre-wrap;
150
- overflow-wrap: anywhere;
151
- }
152
- .${OVERLAY}-errors > section > pre a,
153
- .${OVERLAY}-warnings > section > pre a,
154
- .${OVERLAY}-errors > section > pre span,
155
- .${OVERLAY}-warnings > section > pre span {
156
- display: inline-flex;
157
- }
158
- .${OVERLAY}-hidden {
159
- display: none;
160
- }
161
- `;
162
- const DEFAULT_NAME = 'webpack';
163
- const HTML = `
164
- <div class="${OVERLAY}">
165
- <i class="${OVERLAY}-close"></i>
166
- <div class="${OVERLAY}-title">
167
- <em class="${OVERLAY}-name"></em>
168
- <em class="${OVERLAY}-errors-title"></em>
169
- <em class="${OVERLAY}-warnings-title"></em>
170
- </div>
171
- <aside class="${OVERLAY}-issues">
172
- <article class="${OVERLAY}-errors ${OVERLAY}-hidden"></article>
173
- <article class="${OVERLAY}-warnings ${OVERLAY}-hidden"></article>
174
- </aside>
175
- </div>
176
- `;
177
- class Overlay {
178
- constructor(name) {
179
- this.hidden = true;
180
- const root = utils.getRootElement(OVERLAY);
181
- utils.injectCSS(CSS, root);
182
- const [dialog] = utils.appendHTML(HTML, root);
183
- this.dialog = dialog;
184
- this.name = dialog.querySelector(`.${OVERLAY}-name`);
185
- this.close = dialog.querySelector(`.${OVERLAY}-close`);
186
- this.errorsList = dialog.querySelector(`.${OVERLAY}-errors`);
187
- this.warningsList = dialog.querySelector(`.${OVERLAY}-warnings`);
188
- this.errorsTitle = dialog.querySelector(`.${OVERLAY}-errors-title`);
189
- this.warningsTitle = dialog.querySelector(`.${OVERLAY}-warnings-title`);
190
- this.name.innerHTML = `⭕ ${name || DEFAULT_NAME}`;
191
- this.close.addEventListener('click', () => {
192
- this.hide();
193
- });
194
- }
195
- setIssues(type, issues) {
196
- const count = issues.length;
197
- const hidden = `${OVERLAY}-hidden`;
198
- const problemMaps = {
199
- errors: ['Error', this.errorsTitle, this.errorsList],
200
- warnings: ['Warning', this.warningsTitle, this.warningsList]
201
- };
202
- const [name, problemTitle, problemList] = problemMaps[type];
203
- if (count > 0) {
204
- let html = '';
205
- problemTitle.innerText = `${count} ${name}(s)`;
206
- for (const { moduleName, chunkName, message } of issues) {
207
- const details = utils.ansiToHTML(message);
208
- const filename = moduleName || chunkName || 'unknown';
209
- html += `<section><em>${name}</em> in ${filename}<pre>${details}</pre></section>`;
210
- }
211
- problemList.innerHTML = html;
212
- problemList.classList.remove(hidden);
213
- problemTitle.classList.remove(hidden);
214
- } else {
215
- problemList.classList.add(hidden);
216
- problemTitle.classList.add(hidden);
217
- }
218
- }
219
- show() {
220
- if (this.hidden) {
221
- this.hidden = false;
222
- this.dialog.classList.add(`${OVERLAY}-show`);
223
- }
224
- }
225
- hide() {
226
- if (!this.hidden) {
227
- this.hidden = true;
228
- this.dialog.classList.remove(`${OVERLAY}-show`);
229
- }
230
- }
231
- }
232
-
233
- module.exports = Overlay;