webpack-dev-service 0.5.2 → 0.5.3

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 (40) hide show
  1. package/client/cjs/client.cjs +111 -109
  2. package/client/cjs/events.cjs +33 -32
  3. package/client/cjs/hot.cjs +61 -60
  4. package/client/cjs/index.cjs +10 -8
  5. package/client/cjs/main.cjs +63 -60
  6. package/client/cjs/ui/overlay.cjs +64 -63
  7. package/client/cjs/ui/progress.cjs +35 -35
  8. package/client/cjs/ui/utils/ansi/index.cjs +439 -413
  9. package/client/cjs/ui/utils/ansi/regx.cjs +8 -8
  10. package/client/cjs/ui/utils/ansi/utils.cjs +14 -14
  11. package/client/cjs/ui/utils/index.cjs +99 -99
  12. package/client/esm/client.js +111 -109
  13. package/client/esm/events.js +33 -32
  14. package/client/esm/hot.js +61 -60
  15. package/client/esm/index.js +8 -8
  16. package/client/esm/main.js +63 -60
  17. package/client/esm/ui/overlay.js +64 -63
  18. package/client/esm/ui/progress.js +35 -35
  19. package/client/esm/ui/utils/ansi/index.js +439 -413
  20. package/client/esm/ui/utils/ansi/regx.js +8 -8
  21. package/client/esm/ui/utils/ansi/utils.js +14 -14
  22. package/client/esm/ui/utils/index.js +99 -99
  23. package/package.json +11 -11
  24. package/server/cjs/dev.cjs +30 -36
  25. package/server/cjs/hot.cjs +174 -177
  26. package/server/cjs/index.cjs +16 -17
  27. package/server/esm/dev.js +28 -32
  28. package/server/esm/hot.js +171 -172
  29. package/server/esm/index.js +14 -13
  30. package/types/client/client.d.ts +7 -7
  31. package/types/client/events.d.ts +10 -10
  32. package/types/client/message.d.ts +25 -25
  33. package/types/client/ui/overlay.d.ts +12 -12
  34. package/types/client/ui/progress.d.ts +8 -8
  35. package/types/client/ui/utils/ansi/enum.d.ts +7 -7
  36. package/types/client/ui/utils/ansi/index.d.ts +11 -11
  37. package/types/client/ui/utils/ansi/interface.d.ts +46 -42
  38. package/types/server/dev.d.ts +4 -4
  39. package/types/server/hot.d.ts +5 -5
  40. package/types/server/index.d.ts +2 -2
package/client/esm/hot.js CHANGED
@@ -1,12 +1,12 @@
1
1
  /**
2
- * @package webpack-dev-service
3
- * @license MIT
4
- * @version 0.5.2
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
-
2
+ * @package webpack-dev-service
3
+ * @license MIT
4
+ * @version 0.5.3
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
10
  /**
11
11
  * @module hot
12
12
  */
@@ -21,9 +21,9 @@ let status = 'idle';
21
21
  * @description Is there a newer version of this code available.
22
22
  */
23
23
  function isUpdateAvailable() {
24
- // __webpack_hash__ is the hash of the current compilation.
25
- // It's a global variable injected by webpack.
26
- return hash !== __webpack_hash__;
24
+ // __webpack_hash__ is the hash of the current compilation.
25
+ // It's a global variable injected by webpack.
26
+ return hash !== __webpack_hash__;
27
27
  }
28
28
  /**
29
29
  * @function setHash
@@ -31,7 +31,7 @@ function isUpdateAvailable() {
31
31
  * @param value - The new hash value.
32
32
  */
33
33
  function setHash(value) {
34
- hash = value;
34
+ hash = value;
35
35
  }
36
36
  /**
37
37
  * @function setStatus
@@ -39,11 +39,11 @@ function setHash(value) {
39
39
  * @param value The new status of the hot update.
40
40
  */
41
41
  function setStatus(value) {
42
- status = value;
42
+ status = value;
43
43
  }
44
44
  // Initialize status.
45
45
  if (import.meta.webpackHot) {
46
- setStatus(import.meta.webpackHot.status());
46
+ setStatus(import.meta.webpackHot.status());
47
47
  }
48
48
  /**
49
49
  * @function applyUpdate
@@ -52,55 +52,56 @@ if (import.meta.webpackHot) {
52
52
  * @param fallback Fallback function when HMR fail.
53
53
  */
54
54
  function applyUpdate(hmr, fallback) {
55
- // Update available.
56
- if (isUpdateAvailable()) {
57
- // HMR enabled.
58
- if (hmr && import.meta.webpackHot) {
59
- switch (status) {
60
- case 'idle':
61
- // Set status.
62
- setStatus('check');
63
- // Auto check and apply updates.
64
- import.meta.webpackHot
65
- .check(true)
66
- .then(updated => {
67
- // Update status.
68
- setStatus(import.meta.webpackHot.status());
69
- // When updated modules is available,
70
- // it indicates server is ready to serve new bundle.
71
- if (updated) {
72
- // While update completed, do it again until no update available.
73
- applyUpdate(hmr, fallback);
74
- }
75
- })
76
- .catch(exception => {
77
- // Get status.
78
- const status = import.meta.webpackHot.status();
79
- // Update status.
80
- switch (status) {
55
+ // Update available.
56
+ if (isUpdateAvailable()) {
57
+ // HMR enabled.
58
+ if (hmr && import.meta.webpackHot) {
59
+ switch (status) {
60
+ case 'idle':
61
+ // Set status.
62
+ setStatus('check');
63
+ // Auto check and apply updates.
64
+ import.meta.webpackHot
65
+ .check(true)
66
+ .then(updated => {
67
+ // Update status.
68
+ setStatus(import.meta.webpackHot.status());
69
+ // When updated modules is available,
70
+ // it indicates server is ready to serve new bundle.
71
+ if (updated) {
72
+ // While update completed, do it again until no update available.
73
+ applyUpdate(hmr, fallback);
74
+ }
75
+ })
76
+ .catch((exception) => {
77
+ // Get status.
78
+ const status = import.meta.webpackHot.status();
79
+ // Update status.
80
+ switch (status) {
81
+ case 'fail':
82
+ case 'abort':
83
+ setStatus(status);
84
+ default:
85
+ setStatus('fail');
86
+ }
87
+ // Cache error.
88
+ error = exception;
89
+ // Call fallback.
90
+ fallback(error);
91
+ });
92
+ break;
81
93
  case 'fail':
82
94
  case 'abort':
83
- setStatus(status);
84
- default:
85
- setStatus('fail');
86
- }
87
- // Cache error.
88
- error = exception;
89
- // Call fallback.
90
- fallback(error);
91
- });
92
- break;
93
- case 'fail':
94
- case 'abort':
95
- // Call fallback.
96
- fallback(error);
97
- break;
98
- }
99
- } else {
100
- // HMR disabled.
101
- fallback();
95
+ // Call fallback.
96
+ fallback(error);
97
+ break;
98
+ }
99
+ }
100
+ else {
101
+ // HMR disabled.
102
+ fallback();
103
+ }
102
104
  }
103
- }
104
105
  }
105
106
 
106
107
  export { applyUpdate, isUpdateAvailable, setHash, setStatus };
@@ -1,10 +1,10 @@
1
1
  /**
2
- * @package webpack-dev-service
3
- * @license MIT
4
- * @version 0.5.2
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
-
2
+ * @package webpack-dev-service
3
+ * @license MIT
4
+ * @version 0.5.3
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
10
  export { off, on } from './events.js';
@@ -1,76 +1,79 @@
1
1
  /**
2
- * @package webpack-dev-service
3
- * @license MIT
4
- * @version 0.5.2
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
-
2
+ * @package webpack-dev-service
3
+ * @license MIT
4
+ * @version 0.5.3
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
10
  import createClient from './client.js';
11
11
 
12
12
  /**
13
13
  * @module main
14
14
  */
15
- const isTLS = protocol => {
16
- return protocol === 'https:';
15
+ const isTLS = (protocol) => {
16
+ return protocol === 'https:';
17
17
  };
18
18
  const getCurrentScript = () => {
19
- const { currentScript } = document;
20
- if (currentScript) {
21
- return currentScript;
22
- }
19
+ const { currentScript } = document;
20
+ if (currentScript) {
21
+ return currentScript;
22
+ }
23
23
  };
24
24
  const resolveProtocol = (params, protocol) => {
25
- switch (params.get('tls')) {
26
- case 'true':
27
- return 'wss:';
28
- case 'false':
29
- return 'ws:';
30
- default:
31
- return isTLS(protocol) ? 'wss:' : 'ws:';
32
- }
25
+ switch (params.get('tls')) {
26
+ case 'true':
27
+ return 'wss:';
28
+ case 'false':
29
+ return 'ws:';
30
+ default:
31
+ return isTLS(protocol) ? 'wss:' : 'ws:';
32
+ }
33
33
  };
34
- const resolveOrigin = params => {
35
- const { location } = self;
36
- let host = params.get('host');
37
- let protocol;
38
- if (host) {
39
- protocol = resolveProtocol(params, location.protocol);
40
- } else {
41
- const script = getCurrentScript();
42
- if (script) {
43
- const { src } = script;
44
- const url = new URL(src, location.href);
45
- host = url.host;
46
- protocol = resolveProtocol(params, url.protocol);
47
- } else {
48
- host = location.host;
49
- protocol = resolveProtocol(params, location.protocol);
34
+ const resolveOrigin = (params) => {
35
+ const { location } = self;
36
+ let host = params.get('host');
37
+ let protocol;
38
+ if (host) {
39
+ protocol = resolveProtocol(params, location.protocol);
50
40
  }
51
- }
52
- return `${protocol}//${host}`;
41
+ else {
42
+ const script = getCurrentScript();
43
+ if (script) {
44
+ const { src } = script;
45
+ const url = new URL(src, location.href);
46
+ host = url.host;
47
+ protocol = resolveProtocol(params, url.protocol);
48
+ }
49
+ else {
50
+ host = location.host;
51
+ protocol = resolveProtocol(params, location.protocol);
52
+ }
53
+ }
54
+ return `${protocol}//${host}`;
53
55
  };
54
56
  const resolveOptions = () => {
55
- const params = new URLSearchParams(__resourceQuery);
56
- const origin = resolveOrigin(params);
57
- const hmr = params.get('hmr') !== 'false';
58
- const live = params.get('live') !== 'false';
59
- const overlay = params.get('overlay') !== 'false';
60
- const progress = params.get('progress') !== 'false';
61
- try {
62
- const options = __WDS_HOT_OPTIONS__;
63
- return {
64
- live,
65
- origin,
66
- overlay,
67
- name: options.name,
68
- path: options.path,
69
- hmr: options.hmr === false ? false : hmr,
70
- progress: options.progress === false ? false : progress
71
- };
72
- } catch {
73
- throw new Error('Imported the hot client but the hot server is not enabled.');
74
- }
57
+ const params = new URLSearchParams(__resourceQuery);
58
+ const origin = resolveOrigin(params);
59
+ const hmr = params.get('hmr') !== 'false';
60
+ const live = params.get('live') !== 'false';
61
+ const overlay = params.get('overlay') !== 'false';
62
+ const progress = params.get('progress') !== 'false';
63
+ try {
64
+ const options = __WDS_HOT_OPTIONS__;
65
+ return {
66
+ live,
67
+ origin,
68
+ overlay,
69
+ name: options.name,
70
+ path: options.path,
71
+ hmr: options.hmr === false ? false : hmr,
72
+ progress: options.progress === false ? false : progress
73
+ };
74
+ }
75
+ catch {
76
+ throw new Error('Imported the hot client but the hot server is not enabled.');
77
+ }
75
78
  };
76
79
  createClient(resolveOptions());
@@ -1,12 +1,12 @@
1
1
  /**
2
- * @package webpack-dev-service
3
- * @license MIT
4
- * @version 0.5.2
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
-
2
+ * @package webpack-dev-service
3
+ * @license MIT
4
+ * @version 0.5.3
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
10
  import { injectCSS, appendHTML, ansiToHTML } from './utils/index.js';
11
11
 
12
12
  /**
@@ -171,64 +171,65 @@ const HTML = `
171
171
  </aside>
172
172
  `;
173
173
  class Overlay {
174
- hidden = true;
175
- name;
176
- close;
177
- aside;
178
- errorsList;
179
- errorsTitle;
180
- warningsList;
181
- warningsTitle;
182
- constructor(name) {
183
- injectCSS(CSS);
184
- [this.aside] = appendHTML(HTML);
185
- this.name = this.aside.querySelector(`.${OVERLAY}-name`);
186
- this.close = this.aside.querySelector(`.${OVERLAY}-close`);
187
- this.errorsList = this.aside.querySelector(`.${OVERLAY}-errors`);
188
- this.warningsList = this.aside.querySelector(`.${OVERLAY}-warnings`);
189
- this.errorsTitle = this.aside.querySelector(`.${OVERLAY}-errors-title`);
190
- this.warningsTitle = this.aside.querySelector(`.${OVERLAY}-warnings-title`);
191
- this.name.innerHTML = `⭕ ${name || DEFAULT_NAME}`;
192
- this.close.addEventListener('click', () => {
193
- this.hide();
194
- });
195
- }
196
- setProblems(type, problems) {
197
- const count = problems.length;
198
- const hidden = `${OVERLAY}-hidden`;
199
- const problemMaps = {
200
- errors: ['Error', this.errorsTitle, this.errorsList],
201
- warnings: ['Warning', this.warningsTitle, this.warningsList]
202
- };
203
- const [name, problemTitle, problemList] = problemMaps[type];
204
- if (count > 0) {
205
- let html = '';
206
- problemTitle.innerText = `${count} ${name}(s)`;
207
- for (const { moduleName = 'unknown', message } of problems) {
208
- const src = ansiToHTML(moduleName);
209
- const details = ansiToHTML(message);
210
- html += `<div><em>${name}</em> in ${src}<div>${details}</div></div>`;
211
- }
212
- problemList.innerHTML = html;
213
- problemList.classList.remove(hidden);
214
- problemTitle.classList.remove(hidden);
215
- } else {
216
- problemList.classList.add(hidden);
217
- problemTitle.classList.add(hidden);
174
+ hidden = true;
175
+ name;
176
+ close;
177
+ aside;
178
+ errorsList;
179
+ errorsTitle;
180
+ warningsList;
181
+ warningsTitle;
182
+ constructor(name) {
183
+ injectCSS(CSS);
184
+ [this.aside] = appendHTML(HTML);
185
+ this.name = this.aside.querySelector(`.${OVERLAY}-name`);
186
+ this.close = this.aside.querySelector(`.${OVERLAY}-close`);
187
+ this.errorsList = this.aside.querySelector(`.${OVERLAY}-errors`);
188
+ this.warningsList = this.aside.querySelector(`.${OVERLAY}-warnings`);
189
+ this.errorsTitle = this.aside.querySelector(`.${OVERLAY}-errors-title`);
190
+ this.warningsTitle = this.aside.querySelector(`.${OVERLAY}-warnings-title`);
191
+ this.name.innerHTML = `⭕ ${name || DEFAULT_NAME}`;
192
+ this.close.addEventListener('click', () => {
193
+ this.hide();
194
+ });
195
+ }
196
+ setProblems(type, problems) {
197
+ const count = problems.length;
198
+ const hidden = `${OVERLAY}-hidden`;
199
+ const problemMaps = {
200
+ errors: ['Error', this.errorsTitle, this.errorsList],
201
+ warnings: ['Warning', this.warningsTitle, this.warningsList]
202
+ };
203
+ const [name, problemTitle, problemList] = problemMaps[type];
204
+ if (count > 0) {
205
+ let html = '';
206
+ problemTitle.innerText = `${count} ${name}(s)`;
207
+ for (const { moduleName = 'unknown', message } of problems) {
208
+ const src = ansiToHTML(moduleName);
209
+ const details = ansiToHTML(message);
210
+ html += `<div><em>${name}</em> in ${src}<div>${details}</div></div>`;
211
+ }
212
+ problemList.innerHTML = html;
213
+ problemList.classList.remove(hidden);
214
+ problemTitle.classList.remove(hidden);
215
+ }
216
+ else {
217
+ problemList.classList.add(hidden);
218
+ problemTitle.classList.add(hidden);
219
+ }
218
220
  }
219
- }
220
- show() {
221
- if (this.hidden) {
222
- this.hidden = false;
223
- this.aside.classList.add(`${OVERLAY}-show`);
221
+ show() {
222
+ if (this.hidden) {
223
+ this.hidden = false;
224
+ this.aside.classList.add(`${OVERLAY}-show`);
225
+ }
224
226
  }
225
- }
226
- hide() {
227
- if (!this.hidden) {
228
- this.hidden = true;
229
- this.aside.classList.remove(`${OVERLAY}-show`);
227
+ hide() {
228
+ if (!this.hidden) {
229
+ this.hidden = true;
230
+ this.aside.classList.remove(`${OVERLAY}-show`);
231
+ }
230
232
  }
231
- }
232
233
  }
233
234
 
234
235
  export { Overlay as default };
@@ -1,12 +1,12 @@
1
1
  /**
2
- * @package webpack-dev-service
3
- * @license MIT
4
- * @version 0.5.2
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
-
2
+ * @package webpack-dev-service
3
+ * @license MIT
4
+ * @version 0.5.3
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
10
  import { injectCSS, appendHTML } from './utils/index.js';
11
11
 
12
12
  /**
@@ -58,35 +58,35 @@ const HTML = `
58
58
  </svg>
59
59
  `;
60
60
  class Progress {
61
- timer;
62
- hidden = true;
63
- svg;
64
- track;
65
- constructor() {
66
- injectCSS(CSS);
67
- [this.svg] = appendHTML(HTML);
68
- this.track = this.svg.querySelector(`.${PROGRESS}-track`);
69
- }
70
- update(value) {
71
- value = Math.max(0, Math.min(100, value));
72
- this.track.style.strokeDashoffset = (((100 - value) / 100) * PERIMETER).toString();
73
- }
74
- show() {
75
- if (this.hidden) {
76
- this.hidden = false;
77
- clearTimeout(this.timer);
78
- this.svg.classList.add(`${PROGRESS}-show`);
61
+ timer;
62
+ hidden = true;
63
+ svg;
64
+ track;
65
+ constructor() {
66
+ injectCSS(CSS);
67
+ [this.svg] = appendHTML(HTML);
68
+ this.track = this.svg.querySelector(`.${PROGRESS}-track`);
69
+ }
70
+ update(value) {
71
+ value = Math.max(0, Math.min(100, value));
72
+ this.track.style.strokeDashoffset = (((100 - value) / 100) * PERIMETER).toString();
73
+ }
74
+ show() {
75
+ if (this.hidden) {
76
+ this.hidden = false;
77
+ clearTimeout(this.timer);
78
+ this.svg.classList.add(`${PROGRESS}-show`);
79
+ }
79
80
  }
80
- }
81
- hide() {
82
- if (!this.hidden) {
83
- this.hidden = true;
84
- this.timer = self.setTimeout(() => {
85
- this.update(0);
86
- this.svg.classList.remove(`${PROGRESS}-show`);
87
- }, 300);
81
+ hide() {
82
+ if (!this.hidden) {
83
+ this.hidden = true;
84
+ this.timer = self.setTimeout(() => {
85
+ this.update(0);
86
+ this.svg.classList.remove(`${PROGRESS}-show`);
87
+ }, 300);
88
+ }
88
89
  }
89
- }
90
90
  }
91
91
 
92
92
  export { Progress as default };