webpack-dev-service 0.12.5 → 0.12.7

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 (59) 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 +1 -1
  7. package/cjs/client/ui/Progress.cjs +1 -1
  8. package/cjs/client/ui/utils.cjs +1 -1
  9. package/cjs/server/compose.cjs +1 -1
  10. package/cjs/server/dev/Service.cjs +1 -1
  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 +2 -2
  14. package/cjs/server/dev/utils/hash.cjs +1 -1
  15. package/cjs/server/dev/utils/http.cjs +14 -37
  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 +1 -1
  22. package/cjs/server/dev/utils/setupWriteToDisk.cjs +1 -1
  23. package/cjs/server/dev/utils/stream.cjs +27 -30
  24. package/cjs/server/hot/Socket.cjs +1 -1
  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 +1 -1
  36. package/esm/client/ui/Progress.js +1 -1
  37. package/esm/client/ui/utils.js +1 -1
  38. package/esm/server/compose.js +1 -1
  39. package/esm/server/dev/Service.js +1 -1
  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 +2 -2
  43. package/esm/server/dev/utils/hash.js +1 -1
  44. package/esm/server/dev/utils/http.js +14 -37
  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 +1 -1
  51. package/esm/server/dev/utils/setupWriteToDisk.js +1 -1
  52. package/esm/server/dev/utils/stream.js +27 -30
  53. package/esm/server/hot/Socket.js +1 -1
  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 +5 -5
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.12.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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
@@ -21,7 +21,7 @@
21
21
  function stat(fs, path) {
22
22
  return new Promise(resolve => {
23
23
  fs.stat(path, (error, stats) => {
24
- resolve(error ? null : stats);
24
+ resolve(error != null ? null : stats);
25
25
  });
26
26
  });
27
27
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.12.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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
@@ -22,6 +22,7 @@ const parseRange__default = /*#__PURE__*/ _interopDefault(parseRange);
22
22
  /**
23
23
  * @module http
24
24
  */
25
+ const TOKEN_SPLIT_REGEX = /\s*,\s*/;
25
26
  /**
26
27
  * @function isETag
27
28
  * @description Check if etag is valid.
@@ -36,31 +37,19 @@ function isETag(value) {
36
37
  * @param value The tokens value string.
37
38
  */
38
39
  function parseTokens(value) {
39
- let end = 0;
40
- let start = 0;
41
- let tokens = [];
42
- // Gather tokens.
43
- for (let i = 0, length = value.length; i < length; i++) {
44
- switch (value.charCodeAt(i)) {
45
- case 0x20:
46
- // ' '.
47
- if (start === end) {
48
- start = end = i + 1;
49
- }
50
- break;
51
- case 0x2c:
52
- // ','.
53
- tokens.push(value.substring(start, end));
54
- start = end = i + 1;
55
- break;
56
- default:
57
- end = i + 1;
58
- break;
59
- }
40
+ return value.trim().split(TOKEN_SPLIT_REGEX);
41
+ }
42
+ /**
43
+ * @function decodeURI
44
+ * @description Decode URI component.
45
+ * @param URI The URI to decode.
46
+ */
47
+ function decodeURI(URI) {
48
+ try {
49
+ return decodeURIComponent(URI);
50
+ } catch {
51
+ return -1;
60
52
  }
61
- // Final token.
62
- tokens.push(value.substring(start, end));
63
- return tokens;
64
53
  }
65
54
  /**
66
55
  * @function isRangeFresh
@@ -94,18 +83,6 @@ function isETagFresh(match, etag) {
94
83
  return match === etag || match === 'W/' + etag || 'W/' + match === etag;
95
84
  });
96
85
  }
97
- /**
98
- * @function decodeURI
99
- * @description Decode URI component.
100
- * @param URI The URI to decode.
101
- */
102
- function decodeURI(URI) {
103
- try {
104
- return decodeURIComponent(URI);
105
- } catch {
106
- return -1;
107
- }
108
- }
109
86
  /**
110
87
  * @function isConditionalGET
111
88
  * @description Check if request is conditional GET.
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.12.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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
@@ -44,7 +44,7 @@ class FileReadStream extends node_stream.Readable {
44
44
  */
45
45
  _construct(callback) {
46
46
  this.fs.open(this.path, 'r', (openError, fd) => {
47
- if (openError === null) {
47
+ if (openError == null) {
48
48
  this.fd = fd;
49
49
  }
50
50
  callback(openError);
@@ -81,34 +81,32 @@ class FileReadStream extends node_stream.Readable {
81
81
  let bytesRead = 0;
82
82
  const padding = this.getPadding(range);
83
83
  const hasRangePadding = padding != null;
84
- const length = hasRangePadding ? padding.length : 0;
85
- if (hasRangePadding && length > 0) {
84
+ if (hasRangePadding) {
85
+ const { length } = padding;
86
86
  const begin = this.bytesRead;
87
- bytesRead = Math.min(size, length - begin);
88
- const end = begin + bytesRead;
89
- this.push(padding.subarray(begin, end));
90
- this.bytesRead = end;
87
+ if (length > 0 && begin < length) {
88
+ bytesRead = Math.min(size, length - begin);
89
+ const end = begin + bytesRead;
90
+ this.push(padding.subarray(begin, end));
91
+ this.bytesRead = end;
92
+ }
91
93
  }
92
- if (!hasRangePadding || this.bytesRead >= length) {
94
+ if (bytesRead <= 0) {
93
95
  this.bytesRead = 0;
94
- const hasBytesRead = bytesRead > 0;
95
- switch (this.readState) {
96
+ const { readState } = this;
97
+ switch (readState) {
96
98
  case 0 /* ReadState.PREFIX */:
97
99
  this.readState = 1 /* ReadState.RANGE */;
98
- if (!hasBytesRead) {
99
- this.readFileRange(fd, range, size);
100
- }
100
+ this.readFileRange(fd, range, size);
101
101
  break;
102
102
  case 2 /* ReadState.SUFFIX */:
103
103
  this.currentRangeIndex++;
104
104
  this.readState = 0 /* ReadState.PREFIX */;
105
- if (!hasBytesRead) {
106
- const range = this.getRange();
107
- if (range == null) {
108
- this.push(null);
109
- } else {
110
- this.readFilePadding(fd, range, size);
111
- }
105
+ const nextRange = this.getRange();
106
+ if (nextRange == null) {
107
+ this.push(null);
108
+ } else {
109
+ this.readFilePadding(fd, nextRange, size);
112
110
  }
113
111
  break;
114
112
  }
@@ -127,7 +125,9 @@ class FileReadStream extends node_stream.Readable {
127
125
  const position = range.offset + bytesRead;
128
126
  const buffer = node_buffer.Buffer.alloc(Math.min(size, range.length - bytesRead));
129
127
  this.fs.read(fd, buffer, 0, buffer.length, position, (readError, bytesRead, buffer) => {
130
- if (readError === null) {
128
+ if (readError != null) {
129
+ this.destroy(readError);
130
+ } else {
131
131
  if (bytesRead > 0) {
132
132
  this.push(buffer.subarray(0, bytesRead));
133
133
  this.bytesRead += bytesRead;
@@ -136,8 +136,6 @@ class FileReadStream extends node_stream.Readable {
136
136
  this.readState = 2 /* ReadState.SUFFIX */;
137
137
  this.readFilePadding(fd, range, size);
138
138
  }
139
- } else {
140
- this.destroy(readError);
141
139
  }
142
140
  this.reading = false;
143
141
  });
@@ -151,8 +149,11 @@ class FileReadStream extends node_stream.Readable {
151
149
  if (!this.reading) {
152
150
  const { fd } = this;
153
151
  const range = this.getRange();
154
- if (fd != null && range != null) {
155
- switch (this.readState) {
152
+ if (fd == null || range == null) {
153
+ this.push(null);
154
+ } else {
155
+ const { readState } = this;
156
+ switch (readState) {
156
157
  case 0 /* ReadState.PREFIX */:
157
158
  case 2 /* ReadState.SUFFIX */:
158
159
  this.readFilePadding(fd, range, size);
@@ -160,11 +161,7 @@ class FileReadStream extends node_stream.Readable {
160
161
  case 1 /* ReadState.RANGE */:
161
162
  this.readFileRange(fd, range, size);
162
163
  break;
163
- default:
164
- throw new Error(`invalid read state: ${this.readState}`);
165
164
  }
166
- } else {
167
- this.push(null);
168
165
  }
169
166
  }
170
167
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.12.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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/esm/client/hot.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.12.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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
@@ -19,7 +19,7 @@
19
19
  function stat(fs, path) {
20
20
  return new Promise(resolve => {
21
21
  fs.stat(path, (error, stats) => {
22
- resolve(error ? null : stats);
22
+ resolve(error != null ? null : stats);
23
23
  });
24
24
  });
25
25
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.12.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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
@@ -14,6 +14,7 @@ import parseRange from 'range-parser';
14
14
  /**
15
15
  * @module http
16
16
  */
17
+ const TOKEN_SPLIT_REGEX = /\s*,\s*/;
17
18
  /**
18
19
  * @function isETag
19
20
  * @description Check if etag is valid.
@@ -28,31 +29,19 @@ function isETag(value) {
28
29
  * @param value The tokens value string.
29
30
  */
30
31
  function parseTokens(value) {
31
- let end = 0;
32
- let start = 0;
33
- let tokens = [];
34
- // Gather tokens.
35
- for (let i = 0, length = value.length; i < length; i++) {
36
- switch (value.charCodeAt(i)) {
37
- case 0x20:
38
- // ' '.
39
- if (start === end) {
40
- start = end = i + 1;
41
- }
42
- break;
43
- case 0x2c:
44
- // ','.
45
- tokens.push(value.substring(start, end));
46
- start = end = i + 1;
47
- break;
48
- default:
49
- end = i + 1;
50
- break;
51
- }
32
+ return value.trim().split(TOKEN_SPLIT_REGEX);
33
+ }
34
+ /**
35
+ * @function decodeURI
36
+ * @description Decode URI component.
37
+ * @param URI The URI to decode.
38
+ */
39
+ function decodeURI(URI) {
40
+ try {
41
+ return decodeURIComponent(URI);
42
+ } catch {
43
+ return -1;
52
44
  }
53
- // Final token.
54
- tokens.push(value.substring(start, end));
55
- return tokens;
56
45
  }
57
46
  /**
58
47
  * @function isRangeFresh
@@ -86,18 +75,6 @@ function isETagFresh(match, etag) {
86
75
  return match === etag || match === 'W/' + etag || 'W/' + match === etag;
87
76
  });
88
77
  }
89
- /**
90
- * @function decodeURI
91
- * @description Decode URI component.
92
- * @param URI The URI to decode.
93
- */
94
- function decodeURI(URI) {
95
- try {
96
- return decodeURIComponent(URI);
97
- } catch {
98
- return -1;
99
- }
100
- }
101
78
  /**
102
79
  * @function isConditionalGET
103
80
  * @description Check if request is conditional GET.
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.12.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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
@@ -42,7 +42,7 @@ class FileReadStream extends Readable {
42
42
  */
43
43
  _construct(callback) {
44
44
  this.fs.open(this.path, 'r', (openError, fd) => {
45
- if (openError === null) {
45
+ if (openError == null) {
46
46
  this.fd = fd;
47
47
  }
48
48
  callback(openError);
@@ -79,34 +79,32 @@ class FileReadStream extends Readable {
79
79
  let bytesRead = 0;
80
80
  const padding = this.getPadding(range);
81
81
  const hasRangePadding = padding != null;
82
- const length = hasRangePadding ? padding.length : 0;
83
- if (hasRangePadding && length > 0) {
82
+ if (hasRangePadding) {
83
+ const { length } = padding;
84
84
  const begin = this.bytesRead;
85
- bytesRead = Math.min(size, length - begin);
86
- const end = begin + bytesRead;
87
- this.push(padding.subarray(begin, end));
88
- this.bytesRead = end;
85
+ if (length > 0 && begin < length) {
86
+ bytesRead = Math.min(size, length - begin);
87
+ const end = begin + bytesRead;
88
+ this.push(padding.subarray(begin, end));
89
+ this.bytesRead = end;
90
+ }
89
91
  }
90
- if (!hasRangePadding || this.bytesRead >= length) {
92
+ if (bytesRead <= 0) {
91
93
  this.bytesRead = 0;
92
- const hasBytesRead = bytesRead > 0;
93
- switch (this.readState) {
94
+ const { readState } = this;
95
+ switch (readState) {
94
96
  case 0 /* ReadState.PREFIX */:
95
97
  this.readState = 1 /* ReadState.RANGE */;
96
- if (!hasBytesRead) {
97
- this.readFileRange(fd, range, size);
98
- }
98
+ this.readFileRange(fd, range, size);
99
99
  break;
100
100
  case 2 /* ReadState.SUFFIX */:
101
101
  this.currentRangeIndex++;
102
102
  this.readState = 0 /* ReadState.PREFIX */;
103
- if (!hasBytesRead) {
104
- const range = this.getRange();
105
- if (range == null) {
106
- this.push(null);
107
- } else {
108
- this.readFilePadding(fd, range, size);
109
- }
103
+ const nextRange = this.getRange();
104
+ if (nextRange == null) {
105
+ this.push(null);
106
+ } else {
107
+ this.readFilePadding(fd, nextRange, size);
110
108
  }
111
109
  break;
112
110
  }
@@ -125,7 +123,9 @@ class FileReadStream extends Readable {
125
123
  const position = range.offset + bytesRead;
126
124
  const buffer = Buffer.alloc(Math.min(size, range.length - bytesRead));
127
125
  this.fs.read(fd, buffer, 0, buffer.length, position, (readError, bytesRead, buffer) => {
128
- if (readError === null) {
126
+ if (readError != null) {
127
+ this.destroy(readError);
128
+ } else {
129
129
  if (bytesRead > 0) {
130
130
  this.push(buffer.subarray(0, bytesRead));
131
131
  this.bytesRead += bytesRead;
@@ -134,8 +134,6 @@ class FileReadStream extends Readable {
134
134
  this.readState = 2 /* ReadState.SUFFIX */;
135
135
  this.readFilePadding(fd, range, size);
136
136
  }
137
- } else {
138
- this.destroy(readError);
139
137
  }
140
138
  this.reading = false;
141
139
  });
@@ -149,8 +147,11 @@ class FileReadStream extends Readable {
149
147
  if (!this.reading) {
150
148
  const { fd } = this;
151
149
  const range = this.getRange();
152
- if (fd != null && range != null) {
153
- switch (this.readState) {
150
+ if (fd == null || range == null) {
151
+ this.push(null);
152
+ } else {
153
+ const { readState } = this;
154
+ switch (readState) {
154
155
  case 0 /* ReadState.PREFIX */:
155
156
  case 2 /* ReadState.SUFFIX */:
156
157
  this.readFilePadding(fd, range, size);
@@ -158,11 +159,7 @@ class FileReadStream extends Readable {
158
159
  case 1 /* ReadState.RANGE */:
159
160
  this.readFileRange(fd, range, size);
160
161
  break;
161
- default:
162
- throw new Error(`invalid read state: ${this.readState}`);
163
162
  }
164
- } else {
165
- this.push(null);
166
163
  }
167
164
  }
168
165
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.12.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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.5
4
+ * @version 0.12.7
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,6 +1,6 @@
1
1
  {
2
2
  "name": "webpack-dev-service",
3
- "version": "0.12.5",
3
+ "version": "0.12.7",
4
4
  "description": "A koa 2 middleware for webpack development and hot reloading.",
5
5
  "type": "module",
6
6
  "sideEffects": [
@@ -74,7 +74,7 @@
74
74
  "build:types": "tsc --declaration --emitDeclarationOnly --declarationDir types && node tools/fix-types.js"
75
75
  },
76
76
  "dependencies": {
77
- "@nuintun/ansi": "^0.0.9",
77
+ "@nuintun/ansi": "^0.1.0",
78
78
  "@types/koa": "^2.15.0",
79
79
  "@types/ws": "^8.5.12",
80
80
  "etag": "^1.8.1",
@@ -82,13 +82,13 @@
82
82
  "range-parser": "^1.2.1",
83
83
  "schema-utils": "^4.2.0",
84
84
  "supports-color": "^9.4.0",
85
- "tslib": "^2.7.0",
85
+ "tslib": "^2.8.0",
86
86
  "ws": "^8.18.0"
87
87
  },
88
88
  "devDependencies": {
89
89
  "@rollup/plugin-replace": "^6.0.1",
90
- "@rollup/plugin-typescript": "^12.1.0",
91
- "@swc/core": "^1.7.35",
90
+ "@rollup/plugin-typescript": "^12.1.1",
91
+ "@swc/core": "^1.7.36",
92
92
  "@swc/helpers": "^0.5.13",
93
93
  "@types/etag": "^1.8.3",
94
94
  "@types/node": "^22.7.5",