webpack-dev-service 0.12.0 → 0.12.1

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 (58) 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 +36 -37
  11. package/cjs/server/dev/index.cjs +1 -1
  12. package/cjs/server/dev/middleware.cjs +8 -8
  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 +1 -1
  22. package/cjs/server/dev/utils/setupWriteToDisk.cjs +1 -1
  23. package/cjs/server/hot/Socket.cjs +1 -1
  24. package/cjs/server/hot/index.cjs +1 -1
  25. package/cjs/server/hot/utils.cjs +1 -1
  26. package/cjs/server/index.cjs +1 -1
  27. package/cjs/server/schema.cjs +1 -1
  28. package/cjs/server/utils.cjs +1 -1
  29. package/esm/client/client.js +1 -1
  30. package/esm/client/events.js +1 -1
  31. package/esm/client/hot.js +1 -1
  32. package/esm/client/index.js +1 -1
  33. package/esm/client/main.js +1 -1
  34. package/esm/client/ui/Overlay.js +1 -1
  35. package/esm/client/ui/Progress.js +1 -1
  36. package/esm/client/ui/utils.js +1 -1
  37. package/esm/server/compose.js +1 -1
  38. package/esm/server/dev/Service.js +35 -36
  39. package/esm/server/dev/index.js +1 -1
  40. package/esm/server/dev/middleware.js +8 -8
  41. package/esm/server/dev/utils/fs.js +1 -1
  42. package/esm/server/dev/utils/hash.js +1 -1
  43. package/esm/server/dev/utils/http.js +1 -1
  44. package/esm/server/dev/utils/path.js +1 -1
  45. package/esm/server/dev/utils/paths.js +1 -1
  46. package/esm/server/dev/utils/ready.js +1 -1
  47. package/esm/server/dev/utils/setupHooks.js +1 -1
  48. package/esm/server/dev/utils/setupOutputFileSystem.js +1 -1
  49. package/esm/server/dev/utils/setupWatching.js +1 -1
  50. package/esm/server/dev/utils/setupWriteToDisk.js +1 -1
  51. package/esm/server/hot/Socket.js +1 -1
  52. package/esm/server/hot/index.js +1 -1
  53. package/esm/server/hot/utils.js +1 -1
  54. package/esm/server/index.js +1 -1
  55. package/esm/server/schema.js +1 -1
  56. package/esm/server/utils.js +1 -1
  57. package/package.json +9 -9
  58. package/types/server/dev/Service.d.ts +22 -21
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.12.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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
@@ -9,7 +9,7 @@
9
9
 
10
10
  'use strict';
11
11
 
12
- const createEtag = require('etag');
12
+ const createETag = require('etag');
13
13
  const destroy = require('destroy');
14
14
  const stream = require('stream');
15
15
  const utils = require('../utils.cjs');
@@ -22,7 +22,7 @@ function _interopDefault(e) {
22
22
  return e && e.__esModule ? e : { default: e };
23
23
  }
24
24
 
25
- const createEtag__default = /*#__PURE__*/ _interopDefault(createEtag);
25
+ const createETag__default = /*#__PURE__*/ _interopDefault(createETag);
26
26
  const destroy__default = /*#__PURE__*/ _interopDefault(destroy);
27
27
 
28
28
  /**
@@ -37,8 +37,8 @@ class Service {
37
37
  /**
38
38
  * @constructor
39
39
  * @description Create file service.
40
- * @param root File service root.
41
- * @param options File service options.
40
+ * @param root The file service root.
41
+ * @param options The file service options.
42
42
  */
43
43
  constructor(root, options) {
44
44
  this.options = options;
@@ -48,7 +48,7 @@ class Service {
48
48
  * @private
49
49
  * @method isIgnore
50
50
  * @description Check if path is ignore.
51
- * @param path File path.
51
+ * @param path The path to check.
52
52
  */
53
53
  isIgnore(path) {
54
54
  const { ignore } = this.options;
@@ -57,10 +57,10 @@ class Service {
57
57
  /**
58
58
  * @private
59
59
  * @method setupHeaders
60
- * @description Setup headers
61
- * @param context Koa context
62
- * @param path File path
63
- * @param stats File stats
60
+ * @description Setup headers.
61
+ * @param context The koa context.
62
+ * @param path The file path.
63
+ * @param stats The file stats.
64
64
  */
65
65
  setupHeaders(context, path, stats) {
66
66
  const { options } = this;
@@ -83,7 +83,7 @@ class Service {
83
83
  context.remove('ETag');
84
84
  } else {
85
85
  // Set ETag.
86
- context.set('ETag', createEtag__default.default(stats));
86
+ context.set('ETag', createETag__default.default(stats));
87
87
  }
88
88
  // Last-Modified.
89
89
  if (options.lastModified === false) {
@@ -107,14 +107,14 @@ class Service {
107
107
  }
108
108
  /**
109
109
  * @private
110
- * @method write
111
- * @description Write file to stream.
112
- * @param stream Destination stream.
110
+ * @method read
111
+ * @description Read file with range.
113
112
  * @param path The file path to read.
114
113
  * @param range The range to read.
115
- * @param end Is destory destination stream after read complete.
114
+ * @param stream The destination stream.
115
+ * @param end The end flag after pipe to stream.
116
116
  */
117
- write(stream, path, range, end) {
117
+ read(path, range, stream, end) {
118
118
  const { fs } = this.options;
119
119
  return new Promise(resolve => {
120
120
  // Range prefix and suffix.
@@ -162,24 +162,18 @@ class Service {
162
162
  /**
163
163
  * @private
164
164
  * @method send
165
- * @description Send file.
166
- * @param context Koa context.
167
- * @param path File path.
168
- * @param ranges Read ranges.
165
+ * @description Send file with ranges.
166
+ * @param path The file path to send.
167
+ * @param ranges The ranges to send.
168
+ * @param stream The destination stream.
169
169
  */
170
- async send(context, path, ranges) {
171
- // Set stream body, highWaterMark 64kb.
172
- const stream$1 = new stream.PassThrough({
173
- highWaterMark: 65536
174
- });
175
- // Set response body.
176
- context.body = stream$1;
170
+ async send(path, ranges, stream) {
177
171
  // Ranges length.
178
172
  let { length } = ranges;
179
173
  // Write ranges to stream.
180
174
  for (const range of ranges) {
181
175
  // Write range.
182
- const passed = await this.write(stream$1, path, range, --length === 0);
176
+ const passed = await this.read(path, range, stream, --length === 0);
183
177
  // If not passed, break.
184
178
  if (!passed) {
185
179
  break;
@@ -188,14 +182,13 @@ class Service {
188
182
  }
189
183
  /**
190
184
  * @public
191
- * @method response
192
- * @description Response to koa context.
193
- * @param context Koa context.
194
- * @param publicPath Public path.
185
+ * @method respond
186
+ * @description Respond file.
187
+ * @param pathname The pathname.
188
+ * @param context The koa context.
189
+ * @param publicPath The public path.
195
190
  */
196
- async response(context, publicPath) {
197
- // Get request pathname.
198
- const pathname = context.path || '/';
191
+ async respond(pathname, context, publicPath) {
199
192
  // Check public path.
200
193
  if (!pathname.startsWith(publicPath)) {
201
194
  return false;
@@ -269,8 +262,14 @@ class Service {
269
262
  if (ranges === -2) {
270
263
  return context.throw(400);
271
264
  }
272
- // Send file.
273
- this.send(context, path$2, ranges);
265
+ // Set stream body, highWaterMark 64kb.
266
+ const stream$1 = new stream.PassThrough({
267
+ highWaterMark: 65536
268
+ });
269
+ // Send file with ranges.
270
+ this.send(path$2, ranges, stream$1);
271
+ // Set response body.
272
+ context.body = stream$1;
274
273
  // File found.
275
274
  return true;
276
275
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.12.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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
@@ -46,7 +46,7 @@ function getFileServices(context, stats) {
46
46
  // Return services.
47
47
  return services;
48
48
  }
49
- function getFileServicesAsync(context, path) {
49
+ function getFileServicesAsync(context, pathname) {
50
50
  return new Promise(resolve => {
51
51
  const { stats } = context;
52
52
  // If stats exists, resolve immediately.
@@ -54,7 +54,7 @@ function getFileServicesAsync(context, path) {
54
54
  resolve(getFileServices(context, stats));
55
55
  } else {
56
56
  // Log waiting info.
57
- context.logger.info(`wait until bundle finished: ${path}`);
57
+ context.logger.info(`wait until bundle finished: ${pathname}`);
58
58
  // Otherwise, wait until bundle finished.
59
59
  ready.ready(context, stats => {
60
60
  resolve(getFileServices(context, stats));
@@ -65,18 +65,18 @@ function getFileServicesAsync(context, path) {
65
65
  function middleware(context) {
66
66
  // Middleware.
67
67
  return async (ctx, next) => {
68
- const path = http.decodeURI(ctx.path);
69
- // Path -1 or null byte(s).
70
- if (path === -1 || path.includes('\0')) {
68
+ const pathname = http.decodeURI(ctx.path);
69
+ // Pathname decode failed or includes null byte(s).
70
+ if (pathname === -1 || pathname.includes('\0')) {
71
71
  return ctx.throw(400);
72
72
  }
73
73
  // Only support GET and HEAD (405).
74
74
  if (ctx.method === 'GET' || ctx.method === 'HEAD') {
75
75
  // Get the file services.
76
- const services = await getFileServicesAsync(context, path);
76
+ const services = await getFileServicesAsync(context, pathname);
77
77
  // Try to respond.
78
78
  for (const [publicPath, service] of services) {
79
- if (await service.response(ctx, publicPath)) {
79
+ if (await service.respond(pathname, ctx, publicPath)) {
80
80
  return;
81
81
  }
82
82
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.12.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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,13 +1,13 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.12.0
4
+ * @version 0.12.1
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
8
8
  */
9
9
 
10
- import createEtag from 'etag';
10
+ import createETag from 'etag';
11
11
  import destroy from 'destroy';
12
12
  import { PassThrough } from 'stream';
13
13
  import { isFunction } from '../utils.js';
@@ -28,8 +28,8 @@ class Service {
28
28
  /**
29
29
  * @constructor
30
30
  * @description Create file service.
31
- * @param root File service root.
32
- * @param options File service options.
31
+ * @param root The file service root.
32
+ * @param options The file service options.
33
33
  */
34
34
  constructor(root, options) {
35
35
  this.options = options;
@@ -39,7 +39,7 @@ class Service {
39
39
  * @private
40
40
  * @method isIgnore
41
41
  * @description Check if path is ignore.
42
- * @param path File path.
42
+ * @param path The path to check.
43
43
  */
44
44
  isIgnore(path) {
45
45
  const { ignore } = this.options;
@@ -48,10 +48,10 @@ class Service {
48
48
  /**
49
49
  * @private
50
50
  * @method setupHeaders
51
- * @description Setup headers
52
- * @param context Koa context
53
- * @param path File path
54
- * @param stats File stats
51
+ * @description Setup headers.
52
+ * @param context The koa context.
53
+ * @param path The file path.
54
+ * @param stats The file stats.
55
55
  */
56
56
  setupHeaders(context, path, stats) {
57
57
  const { options } = this;
@@ -74,7 +74,7 @@ class Service {
74
74
  context.remove('ETag');
75
75
  } else {
76
76
  // Set ETag.
77
- context.set('ETag', createEtag(stats));
77
+ context.set('ETag', createETag(stats));
78
78
  }
79
79
  // Last-Modified.
80
80
  if (options.lastModified === false) {
@@ -98,14 +98,14 @@ class Service {
98
98
  }
99
99
  /**
100
100
  * @private
101
- * @method write
102
- * @description Write file to stream.
103
- * @param stream Destination stream.
101
+ * @method read
102
+ * @description Read file with range.
104
103
  * @param path The file path to read.
105
104
  * @param range The range to read.
106
- * @param end Is destory destination stream after read complete.
105
+ * @param stream The destination stream.
106
+ * @param end The end flag after pipe to stream.
107
107
  */
108
- write(stream, path, range, end) {
108
+ read(path, range, stream, end) {
109
109
  const { fs } = this.options;
110
110
  return new Promise(resolve => {
111
111
  // Range prefix and suffix.
@@ -153,24 +153,18 @@ class Service {
153
153
  /**
154
154
  * @private
155
155
  * @method send
156
- * @description Send file.
157
- * @param context Koa context.
158
- * @param path File path.
159
- * @param ranges Read ranges.
156
+ * @description Send file with ranges.
157
+ * @param path The file path to send.
158
+ * @param ranges The ranges to send.
159
+ * @param stream The destination stream.
160
160
  */
161
- async send(context, path, ranges) {
162
- // Set stream body, highWaterMark 64kb.
163
- const stream = new PassThrough({
164
- highWaterMark: 65536
165
- });
166
- // Set response body.
167
- context.body = stream;
161
+ async send(path, ranges, stream) {
168
162
  // Ranges length.
169
163
  let { length } = ranges;
170
164
  // Write ranges to stream.
171
165
  for (const range of ranges) {
172
166
  // Write range.
173
- const passed = await this.write(stream, path, range, --length === 0);
167
+ const passed = await this.read(path, range, stream, --length === 0);
174
168
  // If not passed, break.
175
169
  if (!passed) {
176
170
  break;
@@ -179,14 +173,13 @@ class Service {
179
173
  }
180
174
  /**
181
175
  * @public
182
- * @method response
183
- * @description Response to koa context.
184
- * @param context Koa context.
185
- * @param publicPath Public path.
176
+ * @method respond
177
+ * @description Respond file.
178
+ * @param pathname The pathname.
179
+ * @param context The koa context.
180
+ * @param publicPath The public path.
186
181
  */
187
- async response(context, publicPath) {
188
- // Get request pathname.
189
- const pathname = context.path || '/';
182
+ async respond(pathname, context, publicPath) {
190
183
  // Check public path.
191
184
  if (!pathname.startsWith(publicPath)) {
192
185
  return false;
@@ -260,8 +253,14 @@ class Service {
260
253
  if (ranges === -2) {
261
254
  return context.throw(400);
262
255
  }
263
- // Send file.
264
- this.send(context, path, ranges);
256
+ // Set stream body, highWaterMark 64kb.
257
+ const stream = new PassThrough({
258
+ highWaterMark: 65536
259
+ });
260
+ // Send file with ranges.
261
+ this.send(path, ranges, stream);
262
+ // Set response body.
263
+ context.body = stream;
265
264
  // File found.
266
265
  return true;
267
266
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.12.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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 @@ function getFileServices(context, stats) {
44
44
  // Return services.
45
45
  return services;
46
46
  }
47
- function getFileServicesAsync(context, path) {
47
+ function getFileServicesAsync(context, pathname) {
48
48
  return new Promise(resolve => {
49
49
  const { stats } = context;
50
50
  // If stats exists, resolve immediately.
@@ -52,7 +52,7 @@ function getFileServicesAsync(context, path) {
52
52
  resolve(getFileServices(context, stats));
53
53
  } else {
54
54
  // Log waiting info.
55
- context.logger.info(`wait until bundle finished: ${path}`);
55
+ context.logger.info(`wait until bundle finished: ${pathname}`);
56
56
  // Otherwise, wait until bundle finished.
57
57
  ready(context, stats => {
58
58
  resolve(getFileServices(context, stats));
@@ -63,18 +63,18 @@ function getFileServicesAsync(context, path) {
63
63
  function middleware(context) {
64
64
  // Middleware.
65
65
  return async (ctx, next) => {
66
- const path = decodeURI(ctx.path);
67
- // Path -1 or null byte(s).
68
- if (path === -1 || path.includes('\0')) {
66
+ const pathname = decodeURI(ctx.path);
67
+ // Pathname decode failed or includes null byte(s).
68
+ if (pathname === -1 || pathname.includes('\0')) {
69
69
  return ctx.throw(400);
70
70
  }
71
71
  // Only support GET and HEAD (405).
72
72
  if (ctx.method === 'GET' || ctx.method === 'HEAD') {
73
73
  // Get the file services.
74
- const services = await getFileServicesAsync(context, path);
74
+ const services = await getFileServicesAsync(context, pathname);
75
75
  // Try to respond.
76
76
  for (const [publicPath, service] of services) {
77
- if (await service.response(ctx, publicPath)) {
77
+ if (await service.respond(pathname, ctx, publicPath)) {
78
78
  return;
79
79
  }
80
80
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.12.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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.0
4
+ * @version 0.12.1
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.0",
3
+ "version": "0.12.1",
4
4
  "description": "A koa 2 middleware for webpack development and hot reloading.",
5
5
  "type": "module",
6
6
  "sideEffects": [
@@ -79,7 +79,7 @@
79
79
  "@types/ws": "^8.5.12",
80
80
  "destroy": "^1.2.0",
81
81
  "etag": "^1.8.1",
82
- "memfs": "^4.12.0",
82
+ "memfs": "^4.13.0",
83
83
  "range-parser": "^1.2.1",
84
84
  "schema-utils": "^4.2.0",
85
85
  "supports-color": "^9.4.0",
@@ -89,30 +89,30 @@
89
89
  "devDependencies": {
90
90
  "@rollup/plugin-replace": "^6.0.1",
91
91
  "@rollup/plugin-typescript": "^12.1.0",
92
- "@swc/core": "^1.7.28",
92
+ "@swc/core": "^1.7.35",
93
93
  "@swc/helpers": "^0.5.13",
94
94
  "@types/destroy": "^1.0.3",
95
95
  "@types/etag": "^1.8.3",
96
96
  "@types/koa-compose": "^3.2.8",
97
- "@types/node": "^22.7.0",
97
+ "@types/node": "^22.7.5",
98
98
  "@types/range-parser": "^1.2.7",
99
- "@types/react": "^18.3.9",
99
+ "@types/react": "^18.3.11",
100
100
  "@types/react-dom": "^18.3.0",
101
101
  "css-loader": "^7.1.2",
102
102
  "html-webpack-plugin": "^5.6.0",
103
103
  "koa": "^2.15.3",
104
104
  "koa-compress": "^5.1.1",
105
- "magic-string": "^0.30.11",
105
+ "magic-string": "^0.30.12",
106
106
  "mini-css-extract-plugin": "^2.9.1",
107
107
  "prettier": "^3.3.3",
108
108
  "react": "^18.3.1",
109
109
  "react-dom": "^18.3.1",
110
110
  "rimraf": "^6.0.1",
111
- "rollup": "^4.22.4",
111
+ "rollup": "^4.24.0",
112
112
  "swc-loader": "^0.2.6",
113
113
  "tsc-alias": "^1.8.10",
114
- "typescript": "^5.6.2",
115
- "webpack": "^5.94.0"
114
+ "typescript": "^5.6.3",
115
+ "webpack": "^5.95.0"
116
116
  },
117
117
  "peerDependencies": {
118
118
  "koa": ">=2.0.0",
@@ -31,52 +31,53 @@ export declare class Service {
31
31
  /**
32
32
  * @constructor
33
33
  * @description Create file service.
34
- * @param root File service root.
35
- * @param options File service options.
34
+ * @param root The file service root.
35
+ * @param options The file service options.
36
36
  */
37
37
  constructor(root: string, options: Options);
38
38
  /**
39
39
  * @private
40
40
  * @method isIgnore
41
41
  * @description Check if path is ignore.
42
- * @param path File path.
42
+ * @param path The path to check.
43
43
  */
44
44
  private isIgnore;
45
45
  /**
46
46
  * @private
47
47
  * @method setupHeaders
48
- * @description Setup headers
49
- * @param context Koa context
50
- * @param path File path
51
- * @param stats File stats
48
+ * @description Setup headers.
49
+ * @param context The koa context.
50
+ * @param path The file path.
51
+ * @param stats The file stats.
52
52
  */
53
53
  private setupHeaders;
54
54
  /**
55
55
  * @private
56
- * @method write
57
- * @description Write file to stream.
58
- * @param stream Destination stream.
56
+ * @method read
57
+ * @description Read file with range.
59
58
  * @param path The file path to read.
60
59
  * @param range The range to read.
61
- * @param end Is destory destination stream after read complete.
60
+ * @param stream The destination stream.
61
+ * @param end The end flag after pipe to stream.
62
62
  */
63
- private write;
63
+ private read;
64
64
  /**
65
65
  * @private
66
66
  * @method send
67
- * @description Send file.
68
- * @param context Koa context.
69
- * @param path File path.
70
- * @param ranges Read ranges.
67
+ * @description Send file with ranges.
68
+ * @param path The file path to send.
69
+ * @param ranges The ranges to send.
70
+ * @param stream The destination stream.
71
71
  */
72
72
  private send;
73
73
  /**
74
74
  * @public
75
- * @method response
76
- * @description Response to koa context.
77
- * @param context Koa context.
78
- * @param publicPath Public path.
75
+ * @method respond
76
+ * @description Respond file.
77
+ * @param pathname The pathname.
78
+ * @param context The koa context.
79
+ * @param publicPath The public path.
79
80
  */
80
- response(context: Context, publicPath: string): Promise<boolean>;
81
+ respond(pathname: string, context: Context, publicPath: string): Promise<boolean>;
81
82
  }
82
83
  export {};