webpack-dev-service 0.12.11 → 0.12.13

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 (65) hide show
  1. package/cjs/client/client.cjs +1 -1
  2. package/cjs/client/events.cjs +1 -1
  3. package/cjs/client/hot.cjs +1 -1
  4. package/cjs/client/index.cjs +1 -1
  5. package/cjs/client/main.cjs +1 -1
  6. package/cjs/client/ui/Overlay.cjs +28 -28
  7. package/cjs/client/ui/Progress.cjs +17 -17
  8. package/cjs/client/ui/utils.cjs +1 -1
  9. package/cjs/server/compose.cjs +1 -1
  10. package/cjs/server/dev/Service.cjs +18 -18
  11. package/cjs/server/dev/index.cjs +1 -1
  12. package/cjs/server/dev/middleware.cjs +1 -1
  13. package/cjs/server/dev/utils/fs.cjs +1 -1
  14. package/cjs/server/dev/utils/hash.cjs +1 -1
  15. package/cjs/server/dev/utils/http.cjs +1 -1
  16. package/cjs/server/dev/utils/path.cjs +1 -1
  17. package/cjs/server/dev/utils/paths.cjs +1 -1
  18. package/cjs/server/dev/utils/ready.cjs +1 -1
  19. package/cjs/server/dev/utils/setupHooks.cjs +1 -1
  20. package/cjs/server/dev/utils/setupOutputFileSystem.cjs +1 -1
  21. package/cjs/server/dev/utils/setupWatching.cjs +2 -2
  22. package/cjs/server/dev/utils/setupWriteToDisk.cjs +3 -3
  23. package/cjs/server/dev/utils/stream.cjs +59 -59
  24. package/cjs/server/hot/Socket.cjs +41 -36
  25. package/cjs/server/hot/index.cjs +1 -1
  26. package/cjs/server/hot/utils.cjs +1 -1
  27. package/cjs/server/index.cjs +1 -1
  28. package/cjs/server/schema.cjs +1 -1
  29. package/cjs/server/utils.cjs +1 -1
  30. package/esm/client/client.js +1 -1
  31. package/esm/client/events.js +1 -1
  32. package/esm/client/hot.js +1 -1
  33. package/esm/client/index.js +1 -1
  34. package/esm/client/main.js +1 -1
  35. package/esm/client/ui/Overlay.js +28 -28
  36. package/esm/client/ui/Progress.js +17 -17
  37. package/esm/client/ui/utils.js +1 -1
  38. package/esm/server/compose.js +1 -1
  39. package/esm/server/dev/Service.js +18 -18
  40. package/esm/server/dev/index.js +1 -1
  41. package/esm/server/dev/middleware.js +1 -1
  42. package/esm/server/dev/utils/fs.js +1 -1
  43. package/esm/server/dev/utils/hash.js +1 -1
  44. package/esm/server/dev/utils/http.js +1 -1
  45. package/esm/server/dev/utils/path.js +1 -1
  46. package/esm/server/dev/utils/paths.js +1 -1
  47. package/esm/server/dev/utils/ready.js +1 -1
  48. package/esm/server/dev/utils/setupHooks.js +1 -1
  49. package/esm/server/dev/utils/setupOutputFileSystem.js +1 -1
  50. package/esm/server/dev/utils/setupWatching.js +2 -2
  51. package/esm/server/dev/utils/setupWriteToDisk.js +3 -3
  52. package/esm/server/dev/utils/stream.js +59 -59
  53. package/esm/server/hot/Socket.js +41 -36
  54. package/esm/server/hot/index.js +1 -1
  55. package/esm/server/hot/utils.js +1 -1
  56. package/esm/server/index.js +1 -1
  57. package/esm/server/schema.js +1 -1
  58. package/esm/server/utils.js +1 -1
  59. package/package.json +3 -3
  60. package/types/client/ui/Overlay.d.ts +1 -8
  61. package/types/client/ui/Progress.d.ts +1 -4
  62. package/types/server/dev/Service.d.ts +1 -18
  63. package/types/server/dev/utils/fs.d.ts +2 -2
  64. package/types/server/dev/utils/stream.d.ts +2 -43
  65. package/types/server/hot/Socket.d.ts +1 -10
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.12.11
4
+ * @version 0.12.13
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
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.12.11
4
+ * @version 0.12.13
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
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.12.11
4
+ * @version 0.12.13
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
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.12.11
4
+ * @version 0.12.13
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
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.12.11
4
+ * @version 0.12.13
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
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.12.11
4
+ * @version 0.12.13
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
@@ -175,38 +175,38 @@ const HTML = `
175
175
  </div>
176
176
  `;
177
177
  class Overlay {
178
- hidden = true;
179
- name;
180
- close;
181
- dialog;
182
- errorsList;
183
- errorsTitle;
184
- warningsList;
185
- warningsTitle;
178
+ #hidden = true;
179
+ #name;
180
+ #close;
181
+ #dialog;
182
+ #errorsList;
183
+ #errorsTitle;
184
+ #warningsList;
185
+ #warningsTitle;
186
186
  constructor(name) {
187
187
  const root = utils.getRootElement(OVERLAY);
188
188
  utils.injectCSS(CSS, root);
189
189
  const [dialog] = utils.appendHTML(HTML, root);
190
- this.dialog = dialog;
191
- this.name = dialog.querySelector(`.${OVERLAY}-name`);
192
- this.close = dialog.querySelector(`.${OVERLAY}-close`);
193
- this.errorsList = dialog.querySelector(`.${OVERLAY}-errors`);
194
- this.warningsList = dialog.querySelector(`.${OVERLAY}-warnings`);
195
- this.errorsTitle = dialog.querySelector(`.${OVERLAY}-errors-title`);
196
- this.warningsTitle = dialog.querySelector(`.${OVERLAY}-warnings-title`);
197
- this.name.innerHTML = `⭕ ${name || DEFAULT_NAME}`;
198
- this.close.addEventListener('click', () => {
190
+ this.#dialog = dialog;
191
+ this.#name = dialog.querySelector(`.${OVERLAY}-name`);
192
+ this.#close = dialog.querySelector(`.${OVERLAY}-close`);
193
+ this.#errorsList = dialog.querySelector(`.${OVERLAY}-errors`);
194
+ this.#warningsList = dialog.querySelector(`.${OVERLAY}-warnings`);
195
+ this.#errorsTitle = dialog.querySelector(`.${OVERLAY}-errors-title`);
196
+ this.#warningsTitle = dialog.querySelector(`.${OVERLAY}-warnings-title`);
197
+ this.#name.innerHTML = `⭕ ${name || DEFAULT_NAME}`;
198
+ this.#close.addEventListener('click', () => {
199
199
  this.hide();
200
200
  });
201
201
  }
202
202
  setIssues(type, issues) {
203
203
  const count = issues.length;
204
204
  const hidden = `${OVERLAY}-hidden`;
205
- const problemMaps = {
206
- errors: ['Error', this.errorsTitle, this.errorsList],
207
- warnings: ['Warning', this.warningsTitle, this.warningsList]
205
+ const problems = {
206
+ errors: ['Error', this.#errorsTitle, this.#errorsList],
207
+ warnings: ['Warning', this.#warningsTitle, this.#warningsList]
208
208
  };
209
- const [name, problemTitle, problemList] = problemMaps[type];
209
+ const [name, problemTitle, problemList] = problems[type];
210
210
  if (count > 0) {
211
211
  let html = '';
212
212
  problemTitle.innerText = `${count} ${name}(s)`;
@@ -224,15 +224,15 @@ class Overlay {
224
224
  }
225
225
  }
226
226
  show() {
227
- if (this.hidden) {
228
- this.hidden = false;
229
- this.dialog.classList.add(`${OVERLAY}-show`);
227
+ if (this.#hidden) {
228
+ this.#hidden = false;
229
+ this.#dialog.classList.add(`${OVERLAY}-show`);
230
230
  }
231
231
  }
232
232
  hide() {
233
- if (!this.hidden) {
234
- this.hidden = true;
235
- this.dialog.classList.remove(`${OVERLAY}-show`);
233
+ if (!this.#hidden) {
234
+ this.#hidden = true;
235
+ this.#dialog.classList.remove(`${OVERLAY}-show`);
236
236
  }
237
237
  }
238
238
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.12.11
4
+ * @version 0.12.13
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
@@ -61,37 +61,37 @@ const HTML = `
61
61
  </svg>
62
62
  `;
63
63
  class Progress {
64
- timer;
65
- hidden = true;
66
- svg;
67
- track;
64
+ #timer;
65
+ #hidden = true;
66
+ #svg;
67
+ #track;
68
68
  constructor() {
69
69
  const root = utils.getRootElement(PROGRESS);
70
70
  utils.injectCSS(CSS, root);
71
- [this.svg] = utils.appendHTML(HTML, root);
72
- this.track = this.svg.querySelector(`.${PROGRESS}-track`);
71
+ [this.#svg] = utils.appendHTML(HTML, root);
72
+ this.#track = this.#svg.querySelector(`.${PROGRESS}-track`);
73
73
  }
74
74
  update(percentage) {
75
75
  percentage = 1 - Math.max(0, Math.min(1, percentage));
76
- this.track.style.strokeDashoffset = `${PERIMETER * percentage}`;
76
+ this.#track.style.strokeDashoffset = `${PERIMETER * percentage}`;
77
77
  }
78
78
  show() {
79
- if (this.hidden) {
80
- this.hidden = false;
81
- clearTimeout(this.timer);
82
- this.svg.classList.add(`${PROGRESS}-show`);
79
+ if (this.#hidden) {
80
+ this.#hidden = false;
81
+ clearTimeout(this.#timer);
82
+ this.#svg.classList.add(`${PROGRESS}-show`);
83
83
  }
84
84
  }
85
85
  hide() {
86
- if (this.hidden) {
86
+ if (this.#hidden) {
87
87
  this.update(0);
88
88
  } else {
89
- this.hidden = true;
90
- this.timer = self.setTimeout(() => {
91
- this.timer = self.setTimeout(() => {
89
+ this.#hidden = true;
90
+ this.#timer = self.setTimeout(() => {
91
+ this.#timer = self.setTimeout(() => {
92
92
  this.update(0);
93
93
  }, DURATION);
94
- this.svg.classList.remove(`${PROGRESS}-show`);
94
+ this.#svg.classList.remove(`${PROGRESS}-show`);
95
95
  }, DURATION);
96
96
  }
97
97
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.12.11
4
+ * @version 0.12.13
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
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.12.11
4
+ * @version 0.12.13
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
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.12.11
4
+ * @version 0.12.13
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
@@ -30,8 +30,8 @@ const createETag__default = /*#__PURE__*/ _interopDefault(createETag);
30
30
  * @class Service
31
31
  */
32
32
  class Service {
33
- root;
34
- options;
33
+ #root;
34
+ #options;
35
35
  /**
36
36
  * @constructor
37
37
  * @description Create file service.
@@ -39,29 +39,29 @@ class Service {
39
39
  * @param options The file service options.
40
40
  */
41
41
  constructor(root, options) {
42
- this.options = options;
43
- this.root = path.unixify(node_path.resolve(root));
42
+ this.#options = options;
43
+ this.#root = path.unixify(node_path.resolve(root));
44
44
  }
45
45
  /**
46
46
  * @private
47
- * @method isIgnore
47
+ * @method #isIgnore
48
48
  * @description Check if path is ignore.
49
49
  * @param path The path to check.
50
50
  */
51
- isIgnore(path) {
52
- const { ignore } = this.options;
51
+ #isIgnore(path) {
52
+ const { ignore } = this.#options;
53
53
  return (utils.isFunction(ignore) ? ignore(path) : false) === true;
54
54
  }
55
55
  /**
56
56
  * @private
57
- * @method setupHeaders
57
+ * @method #setupHeaders
58
58
  * @description Setup headers.
59
59
  * @param context The koa context.
60
60
  * @param path The file path.
61
61
  * @param stats The file stats.
62
62
  */
63
- setupHeaders(context, path, stats) {
64
- const { options } = this;
63
+ #setupHeaders(context, path, stats) {
64
+ const options = this.#options;
65
65
  const { headers, etag } = options;
66
66
  // Set status.
67
67
  context.status = 200;
@@ -117,7 +117,7 @@ class Service {
117
117
  return false;
118
118
  }
119
119
  // Get root path.
120
- const { root } = this;
120
+ const root = this.#root;
121
121
  // Slice length.
122
122
  const { length } = publicPath;
123
123
  // Real pathname.
@@ -129,11 +129,13 @@ class Service {
129
129
  return false;
130
130
  }
131
131
  // Is ignore path or file (403).
132
- if (this.isIgnore(path$1)) {
132
+ if (this.#isIgnore(path$1)) {
133
133
  return false;
134
134
  }
135
+ // Get options.
136
+ const options = this.#options;
135
137
  // File stats.
136
- const stats = await fs.stat(this.options.fs, path$1);
138
+ const stats = await fs.stat(options.fs, path$1);
137
139
  // Check file stats.
138
140
  if (
139
141
  // File not exist (404 | 500).
@@ -146,7 +148,7 @@ class Service {
146
148
  return false;
147
149
  }
148
150
  // Setup headers.
149
- this.setupHeaders(context, path$1, stats);
151
+ this.#setupHeaders(context, path$1, stats);
150
152
  // Conditional get support.
151
153
  if (http.isConditionalGET(context)) {
152
154
  // Request precondition failure.
@@ -185,10 +187,8 @@ class Service {
185
187
  if (ranges === -2) {
186
188
  return context.throw(400);
187
189
  }
188
- // Get stream options.
189
- const { fs: fs$1, highWaterMark } = this.options;
190
190
  // Set response body.
191
- context.body = new stream.FileReadStream(path$1, ranges, { fs: fs$1, highWaterMark });
191
+ context.body = new stream.FileReadStream(path$1, ranges, options);
192
192
  // File found.
193
193
  return true;
194
194
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.12.11
4
+ * @version 0.12.13
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
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.12.11
4
+ * @version 0.12.13
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
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.12.11
4
+ * @version 0.12.13
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
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.12.11
4
+ * @version 0.12.13
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
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.12.11
4
+ * @version 0.12.13
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
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.12.11
4
+ * @version 0.12.13
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
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.12.11
4
+ * @version 0.12.13
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
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.12.11
4
+ * @version 0.12.13
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
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.12.11
4
+ * @version 0.12.13
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
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.12.11
4
+ * @version 0.12.13
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
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.12.11
4
+ * @version 0.12.13
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
@@ -20,7 +20,7 @@ function getWatching({ compiler, logger }) {
20
20
  return compiler.watching;
21
21
  }
22
22
  const errorHandler = error => {
23
- if (error) {
23
+ if (error != null) {
24
24
  // For example - `writeToDisk` can throw an error and right now it is ends watching.
25
25
  // We can improve that and keep watching active, but it is require API on webpack side.
26
26
  // Let's implement that in webpack@5 because it is rare case.
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.12.11
4
+ * @version 0.12.13
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
@@ -34,12 +34,12 @@ function setupWriteToDisk(context) {
34
34
  const dir = node_path.dirname(targetPath);
35
35
  const name = getCompilerName(compiler);
36
36
  return node_fs.mkdir(dir, { recursive: true }, error => {
37
- if (error) {
37
+ if (error != null) {
38
38
  logger.error(`${name}unable to write "${dir}" directory to disk:\n${error}`);
39
39
  return callback(error);
40
40
  }
41
41
  node_fs.writeFile(targetPath, content, error => {
42
- if (error) {
42
+ if (error != null) {
43
43
  logger.error(`${name}unable to write "${targetPath}" asset to disk:\n${error}`);
44
44
  return callback(error);
45
45
  }