webpack-dev-service 0.15.7 → 0.15.8

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 +1 -1
  7. package/cjs/client/ui/Progress.cjs +1 -1
  8. package/cjs/client/ui/images/webpack-logo.svg.cjs +1 -1
  9. package/cjs/client/ui/utils.cjs +1 -1
  10. package/cjs/server/compose.cjs +1 -1
  11. package/cjs/server/dev/ReadStream.cjs +39 -41
  12. package/cjs/server/dev/Service.cjs +1 -1
  13. package/cjs/server/dev/index.cjs +3 -2
  14. package/cjs/server/dev/middleware.cjs +1 -1
  15. package/cjs/server/dev/utils/fs.cjs +1 -1
  16. package/cjs/server/dev/utils/hash.cjs +1 -1
  17. package/cjs/server/dev/utils/http.cjs +1 -1
  18. package/cjs/server/dev/utils/http.d.cts +1 -1
  19. package/cjs/server/dev/utils/path.cjs +1 -1
  20. package/cjs/server/dev/utils/paths.cjs +3 -3
  21. package/cjs/server/dev/utils/ready.cjs +1 -1
  22. package/cjs/server/dev/utils/setupHooks.cjs +1 -1
  23. package/cjs/server/dev/utils/setupOutputFileSystem.cjs +1 -1
  24. package/cjs/server/dev/utils/setupWatching.cjs +1 -1
  25. package/cjs/server/dev/utils/setupWriteToDisk.cjs +1 -1
  26. package/cjs/server/hot/Socket.cjs +1 -1
  27. package/cjs/server/hot/index.cjs +1 -1
  28. package/cjs/server/hot/utils.cjs +1 -1
  29. package/cjs/server/index.cjs +1 -1
  30. package/cjs/server/schema.cjs +1 -1
  31. package/cjs/server/utils.cjs +10 -1
  32. package/cjs/server/utils.d.cts +1 -0
  33. package/esm/client/client.js +1 -1
  34. package/esm/client/events.js +1 -1
  35. package/esm/client/hot.js +1 -1
  36. package/esm/client/index.js +1 -1
  37. package/esm/client/main.js +1 -1
  38. package/esm/client/ui/Overlay.js +1 -1
  39. package/esm/client/ui/Progress.js +1 -1
  40. package/esm/client/ui/images/webpack-logo.svg.js +1 -1
  41. package/esm/client/ui/utils.js +1 -1
  42. package/esm/server/compose.js +1 -1
  43. package/esm/server/dev/ReadStream.js +39 -41
  44. package/esm/server/dev/Service.js +1 -1
  45. package/esm/server/dev/index.js +3 -2
  46. package/esm/server/dev/middleware.js +1 -1
  47. package/esm/server/dev/utils/fs.js +1 -1
  48. package/esm/server/dev/utils/hash.js +1 -1
  49. package/esm/server/dev/utils/http.d.ts +1 -1
  50. package/esm/server/dev/utils/http.js +1 -1
  51. package/esm/server/dev/utils/path.js +1 -1
  52. package/esm/server/dev/utils/paths.js +3 -3
  53. package/esm/server/dev/utils/ready.js +1 -1
  54. package/esm/server/dev/utils/setupHooks.js +1 -1
  55. package/esm/server/dev/utils/setupOutputFileSystem.js +1 -1
  56. package/esm/server/dev/utils/setupWatching.js +1 -1
  57. package/esm/server/dev/utils/setupWriteToDisk.js +1 -1
  58. package/esm/server/hot/Socket.js +1 -1
  59. package/esm/server/hot/index.js +1 -1
  60. package/esm/server/hot/utils.js +1 -1
  61. package/esm/server/index.js +1 -1
  62. package/esm/server/schema.js +1 -1
  63. package/esm/server/utils.d.ts +1 -0
  64. package/esm/server/utils.js +10 -2
  65. package/package.json +5 -5
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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
@@ -73,20 +73,19 @@ class ReadStream extends node_stream.Readable {
73
73
  }
74
74
  /**
75
75
  * @private
76
- * @method #readFilePadding
76
+ * @method #readPadding
77
77
  * @param fd The file descriptor.
78
78
  * @param range The current range.
79
79
  * @param size The number of bytes to read.
80
80
  */
81
- #readFilePadding(fd, range, size) {
81
+ #readPadding(fd, range, size) {
82
82
  let bytesRead = 0;
83
83
  const padding = this.#getPadding(range);
84
- const hasRangePadding = padding != null;
85
84
  // If padding exists.
86
- if (hasRangePadding) {
85
+ if (padding != null) {
87
86
  const { length } = padding;
88
87
  const begin = this.#bytesRead;
89
- if (length > 0 && begin < length) {
88
+ if (begin < length) {
90
89
  bytesRead = Math.min(size, length - begin);
91
90
  const end = begin + bytesRead;
92
91
  this.push(padding.subarray(begin, end));
@@ -94,14 +93,13 @@ class ReadStream extends node_stream.Readable {
94
93
  }
95
94
  }
96
95
  // If no padding or read completed.
97
- if (bytesRead <= 0) {
96
+ if (bytesRead < size) {
98
97
  this.#bytesRead = 0;
99
- const readState = this.#readState;
100
98
  // Change read state.
101
- switch (readState) {
99
+ switch (this.#readState) {
102
100
  case 0 /* ReadState.PREFIX */:
103
101
  this.#readState = 1 /* ReadState.RANGE */;
104
- this.#readFileRange(fd, range, size);
102
+ this.#readFileRange(fd, range, size - bytesRead);
105
103
  break;
106
104
  case 2 /* ReadState.SUFFIX */:
107
105
  this.#currentRangeIndex++;
@@ -110,7 +108,7 @@ class ReadStream extends node_stream.Readable {
110
108
  if (nextRange == null) {
111
109
  this.push(null);
112
110
  } else {
113
- this.#readFilePadding(fd, nextRange, size);
111
+ this.#readPadding(fd, nextRange, size - bytesRead);
114
112
  }
115
113
  break;
116
114
  }
@@ -124,39 +122,40 @@ class ReadStream extends node_stream.Readable {
124
122
  * @param size The number of bytes to read.
125
123
  */
126
124
  #readFileRange(fd, range, size) {
127
- this.#reading = true;
125
+ const { length } = range;
128
126
  const bytesRead = this.#bytesRead;
129
- const position = range.offset + bytesRead;
130
- const buffer = node_buffer.Buffer.allocUnsafeSlow(Math.min(size, range.length - bytesRead));
131
- // Read file range.
132
- this.#fs.read(fd, buffer, 0, buffer.length, position, (readError, bytesRead, buffer) => {
133
- this.#reading = false;
134
- // Tell ._destroy() that it's safe to close the fd now.
135
- if (this.destroyed) {
136
- this.emit(DISPOSE_EVENT, readError);
137
- } else {
138
- if (readError != null) {
139
- this.destroy(readError);
127
+ // File range not finished.
128
+ if (bytesRead < length) {
129
+ this.#reading = true;
130
+ const bytesToRead = Math.min(size, length - bytesRead);
131
+ const buffer = node_buffer.Buffer.allocUnsafeSlow(bytesToRead);
132
+ const position = range.offset + bytesRead;
133
+ // Read file range.
134
+ this.#fs.read(fd, buffer, 0, bytesToRead, position, (error, bytesRead, buffer) => {
135
+ this.#reading = false;
136
+ // Tell ._destroy() that it's safe to close the fd now.
137
+ if (this.destroyed) {
138
+ this.emit(DISPOSE_EVENT, error);
139
+ } else if (error != null) {
140
+ this.destroy(error);
141
+ } else if (bytesRead !== bytesToRead) {
142
+ this.destroy(new RangeError('invalid read operation'));
140
143
  } else {
141
- if (bytesRead > 0) {
142
- if (bytesRead !== buffer.length) {
143
- // Slow path. Shrink to fit.
144
- // Copy instead of slice so that we don't retain
145
- // large backing buffer for small reads.
146
- const chunk = node_buffer.Buffer.allocUnsafeSlow(bytesRead);
147
- buffer.copy(chunk, 0, 0, bytesRead);
148
- buffer = chunk;
149
- }
150
- this.push(buffer);
151
- this.#bytesRead += bytesRead;
152
- } else {
144
+ this.push(buffer);
145
+ this.#bytesRead += bytesRead;
146
+ // file range read completed.
147
+ if (bytesRead < size) {
153
148
  this.#bytesRead = 0;
154
149
  this.#readState = 2 /* ReadState.SUFFIX */;
155
- this.#readFilePadding(fd, range, size);
150
+ this.#readPadding(fd, range, size - bytesRead);
156
151
  }
157
152
  }
158
- }
159
- });
153
+ });
154
+ } else {
155
+ this.#bytesRead = 0;
156
+ this.#readState = 2 /* ReadState.SUFFIX */;
157
+ this.#readPadding(fd, range, size);
158
+ }
160
159
  }
161
160
  /**
162
161
  * @override
@@ -171,12 +170,11 @@ class ReadStream extends node_stream.Readable {
171
170
  if (fd == null || range == null) {
172
171
  this.push(null);
173
172
  } else {
174
- const readState = this.#readState;
175
173
  // Read bytes from range.
176
- switch (readState) {
174
+ switch (this.#readState) {
177
175
  case 0 /* ReadState.PREFIX */:
178
176
  case 2 /* ReadState.SUFFIX */:
179
- this.#readFilePadding(fd, range, size);
177
+ this.#readPadding(fd, range, size);
180
178
  break;
181
179
  case 1 /* ReadState.RANGE */:
182
180
  this.#readFileRange(fd, range, size);
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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
@@ -12,16 +12,17 @@
12
12
  const ready = require('./utils/ready.cjs');
13
13
  const fs = require('./utils/fs.cjs');
14
14
  const middleware = require('./middleware.cjs');
15
- const utils = require('../utils.cjs');
16
15
  const setupHooks = require('./utils/setupHooks.cjs');
17
16
  const setupWatching = require('./utils/setupWatching.cjs');
18
17
  const setupWriteToDisk = require('./utils/setupWriteToDisk.cjs');
18
+ const utils = require('../utils.cjs');
19
19
  const setupOutputFileSystem = require('./utils/setupOutputFileSystem.cjs');
20
20
 
21
21
  /**
22
22
  * @module index
23
23
  */
24
24
  function setup(compiler, options) {
25
+ utils.assertPublicPath(compiler);
25
26
  const context = {
26
27
  compiler,
27
28
  stats: null,
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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,4 +34,4 @@ export declare function isPreconditionFailed({ request, response }: Context): bo
34
34
  * @param context The koa context.
35
35
  * @param stats The file stats.
36
36
  */
37
- export declare function parseRanges(context: Context, stats: Stats): Range[] | -1 | -2;
37
+ export declare function parseRanges(context: Context, stats: Stats): -1 | -2 | Range[];
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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,13 +22,13 @@ function getStats(stats) {
22
22
  return [stats];
23
23
  }
24
24
  function getPublicPath(compilation) {
25
- const { publicPath } = compilation.outputOptions;
25
+ const { publicPath = '' } = compilation.outputOptions;
26
26
  // @see https://webpack.js.org/guides/public-path/#automatic-publicpath
27
27
  if (publicPath === 'auto') {
28
28
  return '/';
29
29
  }
30
30
  // Get public path.
31
- const path = compilation.getPath(publicPath ?? '');
31
+ const path = compilation.getPath(publicPath);
32
32
  // Get public path without protocol.
33
33
  return new node_url.URL(path, 'https://127.0.0.1').pathname;
34
34
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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
@@ -23,6 +23,14 @@ function isBoolean(value) {
23
23
  function isFunction(value) {
24
24
  return typeof value === 'function';
25
25
  }
26
+ function assertPublicPath(compiler) {
27
+ const compilers = getCompilers(compiler);
28
+ for (const { options } of compilers) {
29
+ if (isFunction(options.output.publicPath)) {
30
+ throw new TypeError('function type public path is not supported');
31
+ }
32
+ }
33
+ }
26
34
  function getCompilers(compiler) {
27
35
  if (isMultiCompiler(compiler)) {
28
36
  return compiler.compilers;
@@ -34,6 +42,7 @@ function isMultiCompiler(compiler) {
34
42
  }
35
43
 
36
44
  exports.PLUGIN_NAME = PLUGIN_NAME;
45
+ exports.assertPublicPath = assertPublicPath;
37
46
  exports.getCompilers = getCompilers;
38
47
  exports.isBoolean = isBoolean;
39
48
  exports.isFunction = isFunction;
@@ -7,5 +7,6 @@ export declare const PLUGIN_NAME: string;
7
7
  export declare function isString(value: unknown): value is string;
8
8
  export declare function isBoolean(value: unknown): value is boolean;
9
9
  export declare function isFunction(value: unknown): value is Function;
10
+ export declare function assertPublicPath(compiler: UnionCompiler): never | void;
10
11
  export declare function getCompilers(compiler: UnionCompiler): webpack.Compiler[];
11
12
  export declare function isMultiCompiler(compiler: UnionCompiler): compiler is webpack.MultiCompiler;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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
@@ -71,20 +71,19 @@ class ReadStream extends Readable {
71
71
  }
72
72
  /**
73
73
  * @private
74
- * @method #readFilePadding
74
+ * @method #readPadding
75
75
  * @param fd The file descriptor.
76
76
  * @param range The current range.
77
77
  * @param size The number of bytes to read.
78
78
  */
79
- #readFilePadding(fd, range, size) {
79
+ #readPadding(fd, range, size) {
80
80
  let bytesRead = 0;
81
81
  const padding = this.#getPadding(range);
82
- const hasRangePadding = padding != null;
83
82
  // If padding exists.
84
- if (hasRangePadding) {
83
+ if (padding != null) {
85
84
  const { length } = padding;
86
85
  const begin = this.#bytesRead;
87
- if (length > 0 && begin < length) {
86
+ if (begin < length) {
88
87
  bytesRead = Math.min(size, length - begin);
89
88
  const end = begin + bytesRead;
90
89
  this.push(padding.subarray(begin, end));
@@ -92,14 +91,13 @@ class ReadStream extends Readable {
92
91
  }
93
92
  }
94
93
  // If no padding or read completed.
95
- if (bytesRead <= 0) {
94
+ if (bytesRead < size) {
96
95
  this.#bytesRead = 0;
97
- const readState = this.#readState;
98
96
  // Change read state.
99
- switch (readState) {
97
+ switch (this.#readState) {
100
98
  case 0 /* ReadState.PREFIX */:
101
99
  this.#readState = 1 /* ReadState.RANGE */;
102
- this.#readFileRange(fd, range, size);
100
+ this.#readFileRange(fd, range, size - bytesRead);
103
101
  break;
104
102
  case 2 /* ReadState.SUFFIX */:
105
103
  this.#currentRangeIndex++;
@@ -108,7 +106,7 @@ class ReadStream extends Readable {
108
106
  if (nextRange == null) {
109
107
  this.push(null);
110
108
  } else {
111
- this.#readFilePadding(fd, nextRange, size);
109
+ this.#readPadding(fd, nextRange, size - bytesRead);
112
110
  }
113
111
  break;
114
112
  }
@@ -122,39 +120,40 @@ class ReadStream extends Readable {
122
120
  * @param size The number of bytes to read.
123
121
  */
124
122
  #readFileRange(fd, range, size) {
125
- this.#reading = true;
123
+ const { length } = range;
126
124
  const bytesRead = this.#bytesRead;
127
- const position = range.offset + bytesRead;
128
- const buffer = Buffer.allocUnsafeSlow(Math.min(size, range.length - bytesRead));
129
- // Read file range.
130
- this.#fs.read(fd, buffer, 0, buffer.length, position, (readError, bytesRead, buffer) => {
131
- this.#reading = false;
132
- // Tell ._destroy() that it's safe to close the fd now.
133
- if (this.destroyed) {
134
- this.emit(DISPOSE_EVENT, readError);
135
- } else {
136
- if (readError != null) {
137
- this.destroy(readError);
125
+ // File range not finished.
126
+ if (bytesRead < length) {
127
+ this.#reading = true;
128
+ const bytesToRead = Math.min(size, length - bytesRead);
129
+ const buffer = Buffer.allocUnsafeSlow(bytesToRead);
130
+ const position = range.offset + bytesRead;
131
+ // Read file range.
132
+ this.#fs.read(fd, buffer, 0, bytesToRead, position, (error, bytesRead, buffer) => {
133
+ this.#reading = false;
134
+ // Tell ._destroy() that it's safe to close the fd now.
135
+ if (this.destroyed) {
136
+ this.emit(DISPOSE_EVENT, error);
137
+ } else if (error != null) {
138
+ this.destroy(error);
139
+ } else if (bytesRead !== bytesToRead) {
140
+ this.destroy(new RangeError('invalid read operation'));
138
141
  } else {
139
- if (bytesRead > 0) {
140
- if (bytesRead !== buffer.length) {
141
- // Slow path. Shrink to fit.
142
- // Copy instead of slice so that we don't retain
143
- // large backing buffer for small reads.
144
- const chunk = Buffer.allocUnsafeSlow(bytesRead);
145
- buffer.copy(chunk, 0, 0, bytesRead);
146
- buffer = chunk;
147
- }
148
- this.push(buffer);
149
- this.#bytesRead += bytesRead;
150
- } else {
142
+ this.push(buffer);
143
+ this.#bytesRead += bytesRead;
144
+ // file range read completed.
145
+ if (bytesRead < size) {
151
146
  this.#bytesRead = 0;
152
147
  this.#readState = 2 /* ReadState.SUFFIX */;
153
- this.#readFilePadding(fd, range, size);
148
+ this.#readPadding(fd, range, size - bytesRead);
154
149
  }
155
150
  }
156
- }
157
- });
151
+ });
152
+ } else {
153
+ this.#bytesRead = 0;
154
+ this.#readState = 2 /* ReadState.SUFFIX */;
155
+ this.#readPadding(fd, range, size);
156
+ }
158
157
  }
159
158
  /**
160
159
  * @override
@@ -169,12 +168,11 @@ class ReadStream extends Readable {
169
168
  if (fd == null || range == null) {
170
169
  this.push(null);
171
170
  } else {
172
- const readState = this.#readState;
173
171
  // Read bytes from range.
174
- switch (readState) {
172
+ switch (this.#readState) {
175
173
  case 0 /* ReadState.PREFIX */:
176
174
  case 2 /* ReadState.SUFFIX */:
177
- this.#readFilePadding(fd, range, size);
175
+ this.#readPadding(fd, range, size);
178
176
  break;
179
177
  case 1 /* ReadState.RANGE */:
180
178
  this.#readFileRange(fd, range, size);
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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
@@ -10,16 +10,17 @@
10
10
  import { ready } from './utils/ready.js';
11
11
  import { createMemfs } from './utils/fs.js';
12
12
  import { middleware } from './middleware.js';
13
- import { PLUGIN_NAME } from '../utils.js';
14
13
  import { setupHooks } from './utils/setupHooks.js';
15
14
  import { setupWatching } from './utils/setupWatching.js';
16
15
  import { setupWriteToDisk } from './utils/setupWriteToDisk.js';
16
+ import { assertPublicPath, PLUGIN_NAME } from '../utils.js';
17
17
  import { setupOutputFileSystem } from './utils/setupOutputFileSystem.js';
18
18
 
19
19
  /**
20
20
  * @module index
21
21
  */
22
22
  function setup(compiler, options) {
23
+ assertPublicPath(compiler);
23
24
  const context = {
24
25
  compiler,
25
26
  stats: null,
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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,4 +34,4 @@ export declare function isPreconditionFailed({ request, response }: Context): bo
34
34
  * @param context The koa context.
35
35
  * @param stats The file stats.
36
36
  */
37
- export declare function parseRanges(context: Context, stats: Stats): Range[] | -1 | -2;
37
+ export declare function parseRanges(context: Context, stats: Stats): -1 | -2 | Range[];
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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,13 +20,13 @@ function getStats(stats) {
20
20
  return [stats];
21
21
  }
22
22
  function getPublicPath(compilation) {
23
- const { publicPath } = compilation.outputOptions;
23
+ const { publicPath = '' } = compilation.outputOptions;
24
24
  // @see https://webpack.js.org/guides/public-path/#automatic-publicpath
25
25
  if (publicPath === 'auto') {
26
26
  return '/';
27
27
  }
28
28
  // Get public path.
29
- const path = compilation.getPath(publicPath ?? '');
29
+ const path = compilation.getPath(publicPath);
30
30
  // Get public path without protocol.
31
31
  return new URL(path, 'https://127.0.0.1').pathname;
32
32
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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.15.7
4
+ * @version 0.15.8
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
@@ -7,5 +7,6 @@ export declare const PLUGIN_NAME: string;
7
7
  export declare function isString(value: unknown): value is string;
8
8
  export declare function isBoolean(value: unknown): value is boolean;
9
9
  export declare function isFunction(value: unknown): value is Function;
10
+ export declare function assertPublicPath(compiler: UnionCompiler): never | void;
10
11
  export declare function getCompilers(compiler: UnionCompiler): webpack.Compiler[];
11
12
  export declare function isMultiCompiler(compiler: UnionCompiler): compiler is webpack.MultiCompiler;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.15.7
4
+ * @version 0.15.8
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,6 +21,14 @@ function isBoolean(value) {
21
21
  function isFunction(value) {
22
22
  return typeof value === 'function';
23
23
  }
24
+ function assertPublicPath(compiler) {
25
+ const compilers = getCompilers(compiler);
26
+ for (const { options } of compilers) {
27
+ if (isFunction(options.output.publicPath)) {
28
+ throw new TypeError('function type public path is not supported');
29
+ }
30
+ }
31
+ }
24
32
  function getCompilers(compiler) {
25
33
  if (isMultiCompiler(compiler)) {
26
34
  return compiler.compilers;
@@ -31,4 +39,4 @@ function isMultiCompiler(compiler) {
31
39
  return 'compilers' in compiler;
32
40
  }
33
41
 
34
- export { PLUGIN_NAME, getCompilers, isBoolean, isFunction, isMultiCompiler, isString };
42
+ export { PLUGIN_NAME, assertPublicPath, getCompilers, isBoolean, isFunction, isMultiCompiler, isString };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpack-dev-service",
3
- "version": "0.15.7",
3
+ "version": "0.15.8",
4
4
  "description": "A koa 2 middleware for webpack development and hot reloading.",
5
5
  "type": "module",
6
6
  "sideEffects": [
@@ -66,10 +66,10 @@
66
66
  "@rollup/plugin-replace": "^6.0.2",
67
67
  "@rollup/plugin-typescript": "^12.1.4",
68
68
  "@rollup/plugin-url": "^8.0.2",
69
- "@swc/core": "^1.12.11",
69
+ "@swc/core": "^1.13.2",
70
70
  "@swc/helpers": "^0.5.17",
71
71
  "@types/etag": "^1.8.4",
72
- "@types/node": "^24.0.12",
72
+ "@types/node": "^24.1.0",
73
73
  "@types/range-parser": "^1.2.7",
74
74
  "@types/react": "^19.1.8",
75
75
  "@types/react-dom": "^19.1.6",
@@ -84,10 +84,10 @@
84
84
  "react": "^19.1.0",
85
85
  "react-dom": "^19.1.0",
86
86
  "rimraf": "^6.0.1",
87
- "rollup": "^4.44.2",
87
+ "rollup": "^4.45.1",
88
88
  "swc-loader": "^0.2.6",
89
89
  "typescript": "^5.8.3",
90
- "webpack": "^5.100.0"
90
+ "webpack": "^5.100.2"
91
91
  },
92
92
  "peerDependencies": {
93
93
  "koa": ">=2.0.0",