webpack-dev-service 0.11.0 → 0.11.2

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 +2 -2
  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 +9 -2
  7. package/cjs/client/ui/progress.cjs +5 -2
  8. package/cjs/client/ui/utils.cjs +1 -1
  9. package/cjs/server/compose.cjs +1 -1
  10. package/cjs/server/dev/Service.cjs +16 -6
  11. package/cjs/server/dev/index.cjs +1 -1
  12. package/cjs/server/dev/middleware.cjs +9 -16
  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 +2 -2
  16. package/cjs/server/dev/utils/path.cjs +1 -1
  17. package/cjs/server/dev/utils/paths.cjs +30 -19
  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 +7 -3
  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 +2 -2
  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 +9 -2
  35. package/esm/client/ui/progress.js +5 -2
  36. package/esm/client/ui/utils.js +1 -1
  37. package/esm/server/compose.js +1 -1
  38. package/esm/server/dev/Service.js +16 -6
  39. package/esm/server/dev/index.js +1 -1
  40. package/esm/server/dev/middleware.js +9 -16
  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 +2 -2
  44. package/esm/server/dev/utils/path.js +1 -1
  45. package/esm/server/dev/utils/paths.js +30 -19
  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 +7 -3
  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 +14 -13
  58. package/types/server/dev/Service.d.ts +2 -1
  59. package/types/server/dev/utils/paths.d.ts +2 -2
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.11.0
4
+ * @version 0.11.2
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
@@ -84,7 +84,7 @@ function createClient(options) {
84
84
  const parseMessage = message => {
85
85
  try {
86
86
  return JSON.parse(message.data);
87
- } catch (_a) {
87
+ } catch {
88
88
  return null;
89
89
  }
90
90
  };
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.11.0
4
+ * @version 0.11.2
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.11.0
4
+ * @version 0.11.2
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.11.0
4
+ * @version 0.11.2
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.11.0
4
+ * @version 0.11.2
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.11.0
4
+ * @version 0.11.2
5
5
  * @author nuintun <nuintun@qq.com>
6
6
  * @description A koa 2 middleware for webpack development and hot reloading.
7
7
  * @see https://github.com/nuintun/webpack-dev-service#readme
@@ -175,8 +175,15 @@ const HTML = `
175
175
  </div>
176
176
  `;
177
177
  class Overlay {
178
+ hidden = true;
179
+ name;
180
+ close;
181
+ dialog;
182
+ errorsList;
183
+ errorsTitle;
184
+ warningsList;
185
+ warningsTitle;
178
186
  constructor(name) {
179
- this.hidden = true;
180
187
  const root = utils.getRootElement(OVERLAY);
181
188
  utils.injectCSS(CSS, root);
182
189
  const [dialog] = utils.appendHTML(HTML, root);
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.11.0
4
+ * @version 0.11.2
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
@@ -60,8 +60,11 @@ const HTML = `
60
60
  </svg>
61
61
  `;
62
62
  class Progress {
63
+ timer;
64
+ hidden = true;
65
+ svg;
66
+ track;
63
67
  constructor() {
64
- this.hidden = true;
65
68
  const root = utils.getRootElement(PROGRESS);
66
69
  utils.injectCSS(CSS, root);
67
70
  [this.svg] = utils.appendHTML(HTML, root);
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.11.0
4
+ * @version 0.11.2
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.11.0
4
+ * @version 0.11.2
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.11.0
4
+ * @version 0.11.2
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
@@ -32,6 +32,8 @@ const destroy__default = /*#__PURE__*/ _interopDefault(destroy);
32
32
  * @class Service
33
33
  */
34
34
  class Service {
35
+ root;
36
+ options;
35
37
  /**
36
38
  * @constructor
37
39
  * @description Create file service.
@@ -189,15 +191,23 @@ class Service {
189
191
  * @method response
190
192
  * @description Response to koa context.
191
193
  * @param context Koa context.
194
+ * @param publicPath Public path.
192
195
  */
193
- async response(context) {
194
- const { root } = this;
195
- // Only support GET and HEAD (405).
196
- if (context.method !== 'GET' && context.method !== 'HEAD') {
196
+ async response(context, publicPath) {
197
+ // Get request pathname.
198
+ const pathname = context.path || '/';
199
+ // Check public path.
200
+ if (!pathname.startsWith(publicPath)) {
197
201
  return false;
198
202
  }
203
+ // Get root path.
204
+ const { root } = this;
205
+ // Slice length.
206
+ const { length } = publicPath;
207
+ // Real pathname.
208
+ const realpath = pathname.slice(length);
199
209
  // Get path of file.
200
- const path$2 = path.unixify(path$1.join(root, context.path));
210
+ const path$2 = path.unixify(path$1.join(root, realpath));
201
211
  // Malicious path (403).
202
212
  if (path.isOutRoot(path$2, root)) {
203
213
  return false;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.11.0
4
+ * @version 0.11.2
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.11.0
4
+ * @version 0.11.2
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
@@ -70,26 +70,19 @@ function middleware(context) {
70
70
  if (path === -1 || path.includes('\0')) {
71
71
  return ctx.throw(400);
72
72
  }
73
- // Is path respond.
74
- let respond = false;
75
- // Get the file services.
76
- const services = await getFileServicesAsync(context, path);
77
- // Try to respond.
78
- for (const [publicPath, service] of services) {
79
- if (path.startsWith(publicPath)) {
80
- ctx.path = path.slice(publicPath.length);
81
- respond = await service.response(ctx);
82
- if (respond) {
73
+ // Only support GET and HEAD (405).
74
+ if (ctx.method === 'GET' || ctx.method === 'HEAD') {
75
+ // Get the file services.
76
+ const services = await getFileServicesAsync(context, path);
77
+ // Try to respond.
78
+ for (const [publicPath, service] of services) {
79
+ if (await service.response(ctx, publicPath)) {
83
80
  return;
84
- } else {
85
- ctx.path = path;
86
81
  }
87
82
  }
88
83
  }
89
84
  // Not respond.
90
- if (!respond) {
91
- await next();
92
- }
85
+ await next();
93
86
  };
94
87
  }
95
88
 
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.11.0
4
+ * @version 0.11.2
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.11.0
4
+ * @version 0.11.2
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.11.0
4
+ * @version 0.11.2
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
@@ -101,7 +101,7 @@ function isETagFresh(match, etag) {
101
101
  function decodeURI(URI) {
102
102
  try {
103
103
  return decodeURIComponent(URI);
104
- } catch (_a) {
104
+ } catch {
105
105
  return -1;
106
106
  }
107
107
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.11.0
4
+ * @version 0.11.2
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.11.0
4
+ * @version 0.11.2
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,33 +10,46 @@
10
10
  'use strict';
11
11
 
12
12
  const url = require('url');
13
+ const path = require('./path.cjs');
13
14
 
14
15
  /**
15
16
  * @module paths
16
17
  */
18
+ function getStats(stats) {
19
+ if (isMultiStatsMode(stats)) {
20
+ return stats.stats;
21
+ }
22
+ // Return the stats.
23
+ return [stats];
24
+ }
25
+ function normalize(path$1) {
26
+ path$1 = path.unixify(path$1);
27
+ if (/^\//.test(path$1)) {
28
+ return path$1;
29
+ }
30
+ return `/${path$1}`;
31
+ }
17
32
  function getOutputPath(compilation) {
18
33
  // The `output.path` is always present and always absolute.
19
34
  const { path } = compilation.outputOptions;
20
35
  // Get the path.
21
- return compilation.getPath(path ? path : '');
36
+ return compilation.getPath(path ?? '');
22
37
  }
23
38
  function getPublicPath(compilation) {
24
39
  const { publicPath } = compilation.outputOptions;
25
- const path = compilation.getPath(publicPath ? publicPath : '');
26
- // Get the path.
40
+ // @see https://webpack.js.org/guides/public-path/#automatic-publicpath
41
+ if (publicPath === 'auto') {
42
+ return '/';
43
+ }
44
+ // Get public path.
45
+ const path = compilation.getPath(publicPath ?? '');
46
+ // Get public path without protocol.
27
47
  try {
28
48
  return new url.URL(path).pathname;
29
- } catch (_a) {
30
- return path;
49
+ } catch {
50
+ return normalize(path);
31
51
  }
32
52
  }
33
- function getStats(stats) {
34
- if (isMultiStatsMode(stats)) {
35
- return stats.stats;
36
- }
37
- // Return the stats.
38
- return [stats];
39
- }
40
53
  function isMultiStatsMode(stats) {
41
54
  return 'stats' in stats;
42
55
  }
@@ -45,12 +58,10 @@ function getPaths(stats) {
45
58
  const childStats = getStats(stats);
46
59
  // Get the paths.
47
60
  for (const { compilation } of childStats) {
48
- paths.push([
49
- // Output path.
50
- getOutputPath(compilation),
51
- // Public path.
52
- getPublicPath(compilation)
53
- ]);
61
+ const outputPath = getOutputPath(compilation);
62
+ const publicPath = getPublicPath(compilation);
63
+ // Cache paths.
64
+ paths.push([outputPath, publicPath]);
54
65
  }
55
66
  // Return the paths.
56
67
  return paths;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.11.0
4
+ * @version 0.11.2
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.11.0
4
+ * @version 0.11.2
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.11.0
4
+ * @version 0.11.2
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.11.0
4
+ * @version 0.11.2
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.11.0
4
+ * @version 0.11.2
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.11.0
4
+ * @version 0.11.2
5
5
  * @author nuintun <nuintun@qq.com>
6
6
  * @description A koa 2 middleware for webpack development and hot reloading.
7
7
  * @see https://github.com/nuintun/webpack-dev-service#readme
@@ -30,14 +30,18 @@ function entrypoint() {
30
30
  const filename = require.main.filename;
31
31
  try {
32
32
  return path.dirname(url.fileURLToPath(filename));
33
- } catch (_a) {
33
+ } catch {
34
34
  return path.dirname(filename);
35
35
  }
36
36
  }
37
37
  const client = path.resolve(entrypoint(), '../../client/main.cjs');
38
38
  class Socket {
39
+ logger;
40
+ compiler;
41
+ server;
42
+ options;
43
+ stats = null;
39
44
  constructor(compiler, options) {
40
- this.stats = null;
41
45
  this.compiler = compiler;
42
46
  this.options = utils.getOptions(options);
43
47
  this.logger = compiler.getInfrastructureLogger(utils$1.PLUGIN_NAME);
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.11.0
4
+ * @version 0.11.2
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.11.0
4
+ * @version 0.11.2
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.11.0
4
+ * @version 0.11.2
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.11.0
4
+ * @version 0.11.2
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.11.0
4
+ * @version 0.11.2
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.11.0
4
+ * @version 0.11.2
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
@@ -82,7 +82,7 @@ function createClient(options) {
82
82
  const parseMessage = message => {
83
83
  try {
84
84
  return JSON.parse(message.data);
85
- } catch (_a) {
85
+ } catch {
86
86
  return null;
87
87
  }
88
88
  };
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.11.0
4
+ * @version 0.11.2
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.11.0
4
+ * @version 0.11.2
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.11.0
4
+ * @version 0.11.2
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.11.0
4
+ * @version 0.11.2
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.11.0
4
+ * @version 0.11.2
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
@@ -173,8 +173,15 @@ const HTML = `
173
173
  </div>
174
174
  `;
175
175
  class Overlay {
176
+ hidden = true;
177
+ name;
178
+ close;
179
+ dialog;
180
+ errorsList;
181
+ errorsTitle;
182
+ warningsList;
183
+ warningsTitle;
176
184
  constructor(name) {
177
- this.hidden = true;
178
185
  const root = getRootElement(OVERLAY);
179
186
  injectCSS(CSS, root);
180
187
  const [dialog] = appendHTML(HTML, root);
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.11.0
4
+ * @version 0.11.2
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
@@ -58,8 +58,11 @@ const HTML = `
58
58
  </svg>
59
59
  `;
60
60
  class Progress {
61
+ timer;
62
+ hidden = true;
63
+ svg;
64
+ track;
61
65
  constructor() {
62
- this.hidden = true;
63
66
  const root = getRootElement(PROGRESS);
64
67
  injectCSS(CSS, root);
65
68
  [this.svg] = appendHTML(HTML, root);
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.11.0
4
+ * @version 0.11.2
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.11.0
4
+ * @version 0.11.2
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.11.0
4
+ * @version 0.11.2
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,8 @@ import { isConditionalGET, isPreconditionFailure, parseRanges } from './utils/ht
23
23
  * @class Service
24
24
  */
25
25
  class Service {
26
+ root;
27
+ options;
26
28
  /**
27
29
  * @constructor
28
30
  * @description Create file service.
@@ -180,15 +182,23 @@ class Service {
180
182
  * @method response
181
183
  * @description Response to koa context.
182
184
  * @param context Koa context.
185
+ * @param publicPath Public path.
183
186
  */
184
- async response(context) {
185
- const { root } = this;
186
- // Only support GET and HEAD (405).
187
- if (context.method !== 'GET' && context.method !== 'HEAD') {
187
+ async response(context, publicPath) {
188
+ // Get request pathname.
189
+ const pathname = context.path || '/';
190
+ // Check public path.
191
+ if (!pathname.startsWith(publicPath)) {
188
192
  return false;
189
193
  }
194
+ // Get root path.
195
+ const { root } = this;
196
+ // Slice length.
197
+ const { length } = publicPath;
198
+ // Real pathname.
199
+ const realpath = pathname.slice(length);
190
200
  // Get path of file.
191
- const path = unixify(join(root, context.path));
201
+ const path = unixify(join(root, realpath));
192
202
  // Malicious path (403).
193
203
  if (isOutRoot(path, root)) {
194
204
  return false;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.11.0
4
+ * @version 0.11.2
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.11.0
4
+ * @version 0.11.2
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
@@ -68,26 +68,19 @@ function middleware(context) {
68
68
  if (path === -1 || path.includes('\0')) {
69
69
  return ctx.throw(400);
70
70
  }
71
- // Is path respond.
72
- let respond = false;
73
- // Get the file services.
74
- const services = await getFileServicesAsync(context, path);
75
- // Try to respond.
76
- for (const [publicPath, service] of services) {
77
- if (path.startsWith(publicPath)) {
78
- ctx.path = path.slice(publicPath.length);
79
- respond = await service.response(ctx);
80
- if (respond) {
71
+ // Only support GET and HEAD (405).
72
+ if (ctx.method === 'GET' || ctx.method === 'HEAD') {
73
+ // Get the file services.
74
+ const services = await getFileServicesAsync(context, path);
75
+ // Try to respond.
76
+ for (const [publicPath, service] of services) {
77
+ if (await service.response(ctx, publicPath)) {
81
78
  return;
82
- } else {
83
- ctx.path = path;
84
79
  }
85
80
  }
86
81
  }
87
82
  // Not respond.
88
- if (!respond) {
89
- await next();
90
- }
83
+ await next();
91
84
  };
92
85
  }
93
86
 
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.11.0
4
+ * @version 0.11.2
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.11.0
4
+ * @version 0.11.2
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.11.0
4
+ * @version 0.11.2
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
@@ -93,7 +93,7 @@ function isETagFresh(match, etag) {
93
93
  function decodeURI(URI) {
94
94
  try {
95
95
  return decodeURIComponent(URI);
96
- } catch (_a) {
96
+ } catch {
97
97
  return -1;
98
98
  }
99
99
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.11.0
4
+ * @version 0.11.2
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,39 +1,52 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.11.0
4
+ * @version 0.11.2
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
10
  import { URL } from 'url';
11
+ import { unixify } from './path.js';
11
12
 
12
13
  /**
13
14
  * @module paths
14
15
  */
16
+ function getStats(stats) {
17
+ if (isMultiStatsMode(stats)) {
18
+ return stats.stats;
19
+ }
20
+ // Return the stats.
21
+ return [stats];
22
+ }
23
+ function normalize(path) {
24
+ path = unixify(path);
25
+ if (/^\//.test(path)) {
26
+ return path;
27
+ }
28
+ return `/${path}`;
29
+ }
15
30
  function getOutputPath(compilation) {
16
31
  // The `output.path` is always present and always absolute.
17
32
  const { path } = compilation.outputOptions;
18
33
  // Get the path.
19
- return compilation.getPath(path ? path : '');
34
+ return compilation.getPath(path ?? '');
20
35
  }
21
36
  function getPublicPath(compilation) {
22
37
  const { publicPath } = compilation.outputOptions;
23
- const path = compilation.getPath(publicPath ? publicPath : '');
24
- // Get the path.
38
+ // @see https://webpack.js.org/guides/public-path/#automatic-publicpath
39
+ if (publicPath === 'auto') {
40
+ return '/';
41
+ }
42
+ // Get public path.
43
+ const path = compilation.getPath(publicPath ?? '');
44
+ // Get public path without protocol.
25
45
  try {
26
46
  return new URL(path).pathname;
27
- } catch (_a) {
28
- return path;
29
- }
30
- }
31
- function getStats(stats) {
32
- if (isMultiStatsMode(stats)) {
33
- return stats.stats;
47
+ } catch {
48
+ return normalize(path);
34
49
  }
35
- // Return the stats.
36
- return [stats];
37
50
  }
38
51
  function isMultiStatsMode(stats) {
39
52
  return 'stats' in stats;
@@ -43,12 +56,10 @@ function getPaths(stats) {
43
56
  const childStats = getStats(stats);
44
57
  // Get the paths.
45
58
  for (const { compilation } of childStats) {
46
- paths.push([
47
- // Output path.
48
- getOutputPath(compilation),
49
- // Public path.
50
- getPublicPath(compilation)
51
- ]);
59
+ const outputPath = getOutputPath(compilation);
60
+ const publicPath = getPublicPath(compilation);
61
+ // Cache paths.
62
+ paths.push([outputPath, publicPath]);
52
63
  }
53
64
  // Return the paths.
54
65
  return paths;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.11.0
4
+ * @version 0.11.2
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.11.0
4
+ * @version 0.11.2
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.11.0
4
+ * @version 0.11.2
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.11.0
4
+ * @version 0.11.2
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.11.0
4
+ * @version 0.11.2
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.11.0
4
+ * @version 0.11.2
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,14 +21,18 @@ function entrypoint() {
21
21
  const filename = import.meta.url;
22
22
  try {
23
23
  return dirname(fileURLToPath(filename));
24
- } catch (_a) {
24
+ } catch {
25
25
  return dirname(filename);
26
26
  }
27
27
  }
28
28
  const client = resolve(entrypoint(), '../../client/main.js');
29
29
  class Socket {
30
+ logger;
31
+ compiler;
32
+ server;
33
+ options;
34
+ stats = null;
30
35
  constructor(compiler, options) {
31
- this.stats = null;
32
36
  this.compiler = compiler;
33
37
  this.options = getOptions(options);
34
38
  this.logger = compiler.getInfrastructureLogger(PLUGIN_NAME);
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.11.0
4
+ * @version 0.11.2
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.11.0
4
+ * @version 0.11.2
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.11.0
4
+ * @version 0.11.2
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.11.0
4
+ * @version 0.11.2
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.11.0
4
+ * @version 0.11.2
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.11.0",
3
+ "version": "0.11.2",
4
4
  "description": "A koa 2 middleware for webpack development and hot reloading.",
5
5
  "type": "module",
6
6
  "sideEffects": [
@@ -78,7 +78,7 @@
78
78
  "@types/ws": "^8.5.10",
79
79
  "destroy": "^1.2.0",
80
80
  "etag": "^1.8.1",
81
- "memfs": "^4.8.0",
81
+ "memfs": "^4.8.2",
82
82
  "range-parser": "^1.2.1",
83
83
  "schema-utils": "^4.2.0",
84
84
  "supports-color": "^9.4.0",
@@ -88,33 +88,34 @@
88
88
  "devDependencies": {
89
89
  "@rollup/plugin-replace": "^5.0.5",
90
90
  "@rollup/plugin-typescript": "^11.1.6",
91
- "@swc/core": "^1.4.11",
92
- "@swc/helpers": "^0.5.8",
91
+ "@swc/core": "^1.4.13",
92
+ "@swc/helpers": "^0.5.9",
93
93
  "@types/destroy": "^1.0.3",
94
94
  "@types/etag": "^1.8.3",
95
95
  "@types/koa-compose": "^3.2.8",
96
- "@types/node": "^20.11.30",
96
+ "@types/node": "^20.12.7",
97
97
  "@types/range-parser": "^1.2.7",
98
- "@types/react": "^18.2.73",
99
- "@types/react-dom": "^18.2.22",
100
- "css-loader": "^6.10.0",
98
+ "@types/react": "^18.2.78",
99
+ "@types/react-dom": "^18.2.25",
100
+ "css-loader": "^7.1.1",
101
101
  "html-webpack-plugin": "^5.6.0",
102
- "koa": "^2.15.2",
102
+ "koa": "^2.15.3",
103
103
  "koa-compress": "^5.1.1",
104
- "magic-string": "^0.30.8",
105
- "memfs": "^4.8.0",
104
+ "magic-string": "^0.30.9",
105
+ "memfs": "^4.8.2",
106
106
  "mini-css-extract-plugin": "^2.8.1",
107
107
  "prettier": "^3.2.5",
108
108
  "react": "^18.2.0",
109
109
  "react-dom": "^18.2.0",
110
110
  "rimraf": "^5.0.5",
111
- "rollup": "^4.13.1",
111
+ "rollup": "^4.14.2",
112
112
  "swc-loader": "^0.2.6",
113
113
  "tsc-alias": "^1.8.8",
114
- "typescript": "^5.4.3",
114
+ "typescript": "^5.4.5",
115
115
  "webpack": "^5.91.0"
116
116
  },
117
117
  "peerDependencies": {
118
+ "koa": ">=2.0.0",
118
119
  "webpack": ">=5.20.0"
119
120
  }
120
121
  }
@@ -76,7 +76,8 @@ export declare class Service {
76
76
  * @method response
77
77
  * @description Response to koa context.
78
78
  * @param context Koa context.
79
+ * @param publicPath Public path.
79
80
  */
80
- response(context: Context): Promise<boolean>;
81
+ response(context: Context, publicPath: string): Promise<boolean>;
81
82
  }
82
83
  export {};
@@ -2,6 +2,6 @@
2
2
  * @module paths
3
3
  */
4
4
  import { IStats } from '../../../server/interface';
5
- type Path = [outputPath: string, publicPath: string];
6
- export declare function getPaths(stats: IStats): Path[];
5
+ type PathsItem = [outputPath: string, publicPath: string];
6
+ export declare function getPaths(stats: IStats): PathsItem[];
7
7
  export {};