webpack-dev-service 0.15.16 → 0.16.0

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 (79) hide show
  1. package/README.md +35 -36
  2. package/cjs/client/HotUpdate.cjs +78 -0
  3. package/cjs/client/HotUpdate.d.cts +26 -0
  4. package/cjs/client/client.cjs +15 -17
  5. package/cjs/client/events.cjs +1 -1
  6. package/cjs/client/index.cjs +1 -1
  7. package/cjs/client/main.cjs +1 -1
  8. package/cjs/client/ui/Overlay.cjs +3 -3
  9. package/cjs/client/ui/Progress.cjs +5 -5
  10. package/cjs/client/ui/images/webpack-logo.svg.cjs +1 -1
  11. package/cjs/client/ui/utils.cjs +12 -11
  12. package/cjs/client/ui/utils.d.cts +6 -2
  13. package/cjs/server/compose.cjs +1 -1
  14. package/cjs/server/dev/ReadStream.cjs +1 -1
  15. package/cjs/server/dev/Service.cjs +1 -1
  16. package/cjs/server/dev/index.cjs +3 -10
  17. package/cjs/server/dev/index.d.cts +1 -1
  18. package/cjs/server/dev/interface.d.cts +0 -3
  19. package/cjs/server/dev/middleware.cjs +8 -15
  20. package/cjs/server/dev/middleware.d.cts +1 -1
  21. package/cjs/server/dev/utils/fs.cjs +1 -1
  22. package/cjs/server/dev/utils/hash.cjs +1 -1
  23. package/cjs/server/dev/utils/http.cjs +1 -1
  24. package/cjs/server/dev/utils/path.cjs +1 -1
  25. package/cjs/server/dev/utils/paths.cjs +1 -1
  26. package/cjs/server/dev/utils/ready.cjs +1 -1
  27. package/cjs/server/dev/utils/setupHooks.cjs +9 -6
  28. package/cjs/server/dev/utils/setupOutputFileSystem.cjs +1 -1
  29. package/cjs/server/dev/utils/setupWatching.cjs +1 -1
  30. package/cjs/server/dev/utils/setupWriteToDisk.cjs +1 -1
  31. package/cjs/server/hot/Socket.cjs +8 -1
  32. package/cjs/server/hot/index.cjs +3 -3
  33. package/cjs/server/hot/utils.cjs +1 -1
  34. package/cjs/server/index.cjs +4 -5
  35. package/cjs/server/index.d.cts +1 -1
  36. package/cjs/server/schema.cjs +1 -1
  37. package/cjs/server/utils.cjs +1 -1
  38. package/esm/client/HotUpdate.d.ts +26 -0
  39. package/esm/client/HotUpdate.js +76 -0
  40. package/esm/client/client.js +16 -18
  41. package/esm/client/events.js +1 -1
  42. package/esm/client/index.js +1 -1
  43. package/esm/client/main.js +1 -1
  44. package/esm/client/ui/Overlay.js +4 -4
  45. package/esm/client/ui/Progress.js +6 -6
  46. package/esm/client/ui/images/webpack-logo.svg.js +1 -1
  47. package/esm/client/ui/utils.d.ts +6 -2
  48. package/esm/client/ui/utils.js +11 -10
  49. package/esm/server/compose.js +1 -1
  50. package/esm/server/dev/ReadStream.js +1 -1
  51. package/esm/server/dev/Service.js +1 -1
  52. package/esm/server/dev/index.d.ts +1 -1
  53. package/esm/server/dev/index.js +3 -10
  54. package/esm/server/dev/interface.d.ts +0 -3
  55. package/esm/server/dev/middleware.d.ts +1 -1
  56. package/esm/server/dev/middleware.js +8 -15
  57. package/esm/server/dev/utils/fs.js +1 -1
  58. package/esm/server/dev/utils/hash.js +1 -1
  59. package/esm/server/dev/utils/http.js +1 -1
  60. package/esm/server/dev/utils/path.js +1 -1
  61. package/esm/server/dev/utils/paths.js +1 -1
  62. package/esm/server/dev/utils/ready.js +1 -1
  63. package/esm/server/dev/utils/setupHooks.js +9 -6
  64. package/esm/server/dev/utils/setupOutputFileSystem.js +1 -1
  65. package/esm/server/dev/utils/setupWatching.js +1 -1
  66. package/esm/server/dev/utils/setupWriteToDisk.js +1 -1
  67. package/esm/server/hot/Socket.js +8 -1
  68. package/esm/server/hot/index.js +3 -3
  69. package/esm/server/hot/utils.js +1 -1
  70. package/esm/server/index.d.ts +1 -1
  71. package/esm/server/index.js +4 -5
  72. package/esm/server/schema.js +1 -1
  73. package/esm/server/utils.js +1 -1
  74. package/global.d.ts +0 -2
  75. package/package.json +5 -5
  76. package/cjs/client/hot.cjs +0 -111
  77. package/cjs/client/hot.d.cts +0 -16
  78. package/esm/client/hot.d.ts +0 -16
  79. package/esm/client/hot.js +0 -108
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.15.16
4
+ * @version 0.16.0
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.16
4
+ * @version 0.16.0
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
@@ -87,11 +87,14 @@ function setupHooks(context) {
87
87
  onCompilationDone(stats, statsOptions);
88
88
  // Callbacks.
89
89
  const { callbacks } = context;
90
- // Clear callbacks.
91
- context.callbacks = [];
92
- // Call callbacks.
93
- for (const callback of callbacks) {
94
- callback(stats);
90
+ // Call callbacks if there are any.
91
+ if (callbacks.length > 0) {
92
+ // Clear callbacks.
93
+ context.callbacks = [];
94
+ // Call callbacks.
95
+ for (const callback of callbacks) {
96
+ callback(stats);
97
+ }
95
98
  }
96
99
  // Log compilation finished.
97
100
  context.logger.log('compilation finished');
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.15.16
4
+ * @version 0.16.0
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.16
4
+ * @version 0.16.0
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.16
4
+ * @version 0.16.0
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.16
4
+ * @version 0.16.0
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
@@ -53,11 +53,18 @@ class Socket {
53
53
  clients: new Set()
54
54
  };
55
55
  contexts.set(uuid$1, context);
56
+ this.#setupOutput(compiler, uuid$1);
56
57
  this.#setupHooks(compiler, context);
57
58
  this.#setupPlugins(compiler, context);
58
59
  }
59
60
  this.#setupWss(contexts);
60
61
  }
62
+ #setupOutput(compiler, uuid) {
63
+ const { output } = compiler.options;
64
+ // Override hot update filename.
65
+ output.hotUpdateChunkFilename = `[id].${uuid}.hot-update.js`;
66
+ output.hotUpdateMainFilename = `[runtime].${uuid}.hot-update.json`;
67
+ }
61
68
  #setupHooks(compiler, context) {
62
69
  const { hooks } = compiler;
63
70
  const statsOptions = utils.getStatsOptions(compiler);
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.15.16
4
+ * @version 0.16.0
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
@@ -17,8 +17,8 @@ const Socket = require('./Socket.cjs');
17
17
  function hot(compiler, options) {
18
18
  const socket = new Socket.Socket(compiler, options);
19
19
  // Middleware.
20
- return async (ctx, next) => {
21
- if (!socket.upgrade(ctx)) {
20
+ return async (context, next) => {
21
+ if (!socket.upgrade(context)) {
22
22
  await next();
23
23
  }
24
24
  };
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.15.16
4
+ * @version 0.16.0
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.16
4
+ * @version 0.16.0
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
@@ -25,7 +25,7 @@ const index = require('./dev/index.cjs');
25
25
  * @param compiler The rspack compiler instance.
26
26
  * @param options Options.
27
27
  */
28
- function server(compiler, options = {}) {
28
+ async function server(compiler, options = {}) {
29
29
  schemaUtils.validate(schema.schema, options, {
30
30
  name: utils.PLUGIN_NAME,
31
31
  baseDataPath: 'options'
@@ -37,9 +37,8 @@ function server(compiler, options = {}) {
37
37
  // All plugins must be initialized before watching.
38
38
  // Because dev will start watching, so call hot before dev.
39
39
  const hotMiddleware = index$1.hot(compiler, hotOptions);
40
- const devMiddleware = index.dev(compiler, options);
41
- const middleware = compose.compose(devMiddleware, hotMiddleware);
42
- return Object.assign(middleware, devMiddleware, hotMiddleware);
40
+ const devMiddleware = await index.dev(compiler, options);
41
+ return Object.assign(compose.compose(devMiddleware, hotMiddleware), devMiddleware);
43
42
  }
44
43
 
45
44
  exports.server = server;
@@ -14,4 +14,4 @@ export type Options = DevOptions & {
14
14
  * @param compiler The rspack compiler instance.
15
15
  * @param options Options.
16
16
  */
17
- export declare function server(compiler: UnionCompiler, options?: Options): Middleware & Expose;
17
+ export declare function server(compiler: UnionCompiler, options?: Options): Promise<Middleware & Expose>;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.15.16
4
+ * @version 0.16.0
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.16
4
+ * @version 0.16.0
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
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @module HotUpdate
3
+ */
4
+ export interface Fallback {
5
+ (error?: Error): Promise<void> | void;
6
+ }
7
+ export declare class HotUpdate {
8
+ #private;
9
+ /**
10
+ * @constructor
11
+ * @param hmr Whether to enable HMR hot update.
12
+ * @param fallback Fallback handler for update failures.
13
+ */
14
+ constructor(hmr: boolean | undefined, fallback: Fallback);
15
+ /**
16
+ * @method updateHash
17
+ * @description Update hash value.
18
+ * @param hash New hash value.
19
+ */
20
+ updateHash(hash: string): void;
21
+ /**
22
+ * @method performUpdate
23
+ * @description Execute update strategy.
24
+ */
25
+ performUpdate(): Promise<void>;
26
+ }
@@ -0,0 +1,76 @@
1
+ /**
2
+ * @package webpack-dev-service
3
+ * @license MIT
4
+ * @version 0.16.0
5
+ * @author nuintun <nuintun@qq.com>
6
+ * @description A koa 2 middleware for webpack development and hot reloading.
7
+ * @see https://github.com/nuintun/webpack-dev-service#readme
8
+ */
9
+
10
+ /**
11
+ * @module HotUpdate
12
+ */
13
+ class HotUpdate {
14
+ #hmr;
15
+ #fallback;
16
+ #pending = false;
17
+ #hash = __webpack_hash__;
18
+ #hot = import.meta.webpackHot;
19
+ /**
20
+ * @constructor
21
+ * @param hmr Whether to enable HMR hot update.
22
+ * @param fallback Fallback handler for update failures.
23
+ */
24
+ constructor(hmr = true, fallback) {
25
+ this.#hmr = hmr;
26
+ this.#fallback = fallback;
27
+ // Listen to status changes
28
+ this.#hot?.addStatusHandler(async status => {
29
+ if (this.#pending && status === 'idle') {
30
+ this.#pending = false;
31
+ await this.performUpdate();
32
+ }
33
+ });
34
+ }
35
+ /**
36
+ * @method updateHash
37
+ * @description Update hash value.
38
+ * @param hash New hash value.
39
+ */
40
+ updateHash(hash) {
41
+ this.#hash = hash;
42
+ }
43
+ /**
44
+ * @method #isUpdateAvailable
45
+ * @description Check if new updates are available.
46
+ */
47
+ #isUpdateAvailable() {
48
+ return this.#hash !== __webpack_hash__;
49
+ }
50
+ /**
51
+ * @method performUpdate
52
+ * @description Execute update strategy.
53
+ */
54
+ async performUpdate() {
55
+ if (this.#isUpdateAvailable()) {
56
+ if (!this.#hmr || !this.#hot) {
57
+ await this.#fallback();
58
+ } else if (this.#hot.status() === 'idle') {
59
+ try {
60
+ const outdated = await this.#hot.check(true);
61
+ if (this.#isUpdateAvailable()) {
62
+ if (outdated == null || outdated.length <= 0) {
63
+ await this.#fallback();
64
+ }
65
+ }
66
+ } catch (error) {
67
+ await this.#fallback(error);
68
+ }
69
+ } else {
70
+ this.#pending = true;
71
+ }
72
+ }
73
+ }
74
+ }
75
+
76
+ export { HotUpdate };
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.15.16
4
+ * @version 0.16.0
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,31 +10,29 @@
10
10
  import { emit } from './events.js';
11
11
  import { Overlay } from './ui/Overlay.js';
12
12
  import { Progress } from './ui/Progress.js';
13
- import { applyUpdate, updateHash } from './hot.js';
13
+ import { HotUpdate } from './HotUpdate.js';
14
14
 
15
15
  /**
16
16
  * @module client
17
17
  */
18
18
  function createClient(options) {
19
- let updateTimer;
20
- const UPDATE_DELAY = 128;
21
19
  const RETRY_INTERVAL = 3000;
22
20
  const progress = new Progress();
23
21
  const overlay = new Overlay(options.name);
24
22
  const fallback = () => {
25
- if (options.reload) {
26
- self.location.reload();
27
- } else {
28
- console.warn('Use fallback update but you turn off live reload, please reload by yourself.');
29
- }
30
- };
31
- const applyUpdateAsync = () => {
32
- updateTimer = self.setTimeout(() => {
33
- applyUpdate(options.hmr, fallback);
34
- }, UPDATE_DELAY);
23
+ return new Promise(resolve => {
24
+ queueMicrotask(() => {
25
+ if (options.reload) {
26
+ self.location.reload();
27
+ } else {
28
+ console.warn('[HMR] Hot update failed. Please reload the page manually.');
29
+ }
30
+ resolve();
31
+ });
32
+ });
35
33
  };
34
+ const hot = new HotUpdate(options.hmr, fallback);
36
35
  const onInvalid = () => {
37
- clearTimeout(updateTimer);
38
36
  if (options.progress) {
39
37
  progress.update(0);
40
38
  progress.show();
@@ -46,7 +44,7 @@ function createClient(options) {
46
44
  }
47
45
  };
48
46
  const onHash = ({ hash }) => {
49
- updateHash(hash);
47
+ hot.updateHash(hash);
50
48
  };
51
49
  const setIssues = (type, issues) => {
52
50
  if (options.overlay) {
@@ -72,14 +70,14 @@ function createClient(options) {
72
70
  overlay.show();
73
71
  }
74
72
  if (errors.length <= 0) {
75
- applyUpdateAsync();
73
+ hot.performUpdate();
76
74
  }
77
75
  };
78
76
  const onOk = () => {
79
77
  progress.update(1);
80
78
  progress.hide();
81
79
  overlay.hide();
82
- applyUpdateAsync();
80
+ hot.performUpdate();
83
81
  };
84
82
  const parseMessage = message => {
85
83
  try {
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.15.16
4
+ * @version 0.16.0
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.16
4
+ * @version 0.16.0
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.16
4
+ * @version 0.16.0
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.15.16
4
+ * @version 0.16.0
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 { getRootElement, injectCSS, appendHTML, ansiToHTML } from './utils.js';
10
+ import { getRootElement, insertCSSString, appendDOMString, ansiToHTML } from './utils.js';
11
11
 
12
12
  /**
13
13
  * @module overlay
@@ -183,8 +183,8 @@ class Overlay {
183
183
  #warningsTitle;
184
184
  constructor(name) {
185
185
  const root = getRootElement(OVERLAY);
186
- injectCSS(CSS, root);
187
- const [dialog] = appendHTML(HTML, root);
186
+ insertCSSString(CSS, root);
187
+ const [dialog] = appendDOMString('text/html', HTML, root);
188
188
  this.#dialog = dialog;
189
189
  this.#name = dialog.querySelector(`.${OVERLAY}-name`);
190
190
  this.#close = dialog.querySelector(`.${OVERLAY}-close`);
@@ -1,14 +1,14 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.15.16
4
+ * @version 0.16.0
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 logo from './images/webpack-logo.svg.js';
11
- import { getRootElement, injectCSS, appendHTML } from './utils.js';
11
+ import { getRootElement, insertCSSString, appendDOMString } from './utils.js';
12
12
 
13
13
  /**
14
14
  * @module progress
@@ -50,8 +50,8 @@ const CSS = `
50
50
  transform: matrix(0, -1, 1, 0, 0, 96) translateZ(0);
51
51
  }
52
52
  `;
53
- const HTML = `
54
- <svg class="${PROGRESS}" x="0" y="0" viewBox="0 0 96 96">
53
+ const SVG = `
54
+ <svg xmlns="http://www.w3.org/2000/svg" class="${PROGRESS}" x="0" y="0" viewBox="0 0 96 96">
55
55
  <circle fill="#101619" cx="50%" cy="50%" r="44" />
56
56
  <circle class="${PROGRESS}-track" cx="50%" cy="50%" r="44" />
57
57
  <image href="${logo}" x="16" y="16" width="64" height="64"/>
@@ -64,8 +64,8 @@ class Progress {
64
64
  #track;
65
65
  constructor() {
66
66
  const root = getRootElement(PROGRESS);
67
- injectCSS(CSS, root);
68
- [this.#svg] = appendHTML(HTML, root);
67
+ insertCSSString(CSS, root);
68
+ [this.#svg] = appendDOMString('image/svg+xml', SVG, root);
69
69
  this.#track = this.#svg.querySelector(`.${PROGRESS}-track`);
70
70
  }
71
71
  update(percentage) {
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.15.16
4
+ * @version 0.16.0
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,9 +7,13 @@ export declare function blockToHTML({ style, value, url }: AnsiBlock): string;
7
7
  export declare function ansiToHTML(text: string): string;
8
8
  export type RootElement = HTMLElement | ShadowRoot;
9
9
  export declare function getRootElement(tagName: string): ShadowRoot;
10
- export declare function injectCSS(
10
+ export declare function insertCSSString(
11
11
  css: string,
12
12
  root?: HTMLElement | ShadowRoot,
13
13
  styleElement?: HTMLStyleElement
14
14
  ): HTMLStyleElement;
15
- export declare function appendHTML(html: string, root?: RootElement): ChildNode[];
15
+ export declare function appendDOMString<T extends DOMParserSupportedType>(
16
+ type: T,
17
+ string: string,
18
+ root?: RootElement
19
+ ): (T extends 'image/svg+xml' ? SVGElement : HTMLElement)[];
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.15.16
4
+ * @version 0.16.0
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
@@ -97,27 +97,28 @@ function ansiToHTML(text) {
97
97
  }
98
98
  function getRootElement(tagName) {
99
99
  const stage = document.createElement(tagName);
100
- const root = stage.attachShadow({ mode: 'closed' });
100
+ const shadowRoot = stage.attachShadow({ mode: 'closed' });
101
101
  document.body.appendChild(stage);
102
- return root;
102
+ return shadowRoot;
103
103
  }
104
- function injectCSS(css, root = document.body, styleElement = document.createElement('style')) {
105
- styleElement.appendChild(document.createTextNode(css.trim()));
104
+ function insertCSSString(css, root = document.body, styleElement = document.createElement('style')) {
105
+ styleElement.appendChild(document.createTextNode(css));
106
106
  if (!root.contains(styleElement)) {
107
107
  root.appendChild(styleElement);
108
108
  }
109
109
  return styleElement;
110
110
  }
111
- function appendHTML(html, root = document.body) {
111
+ function appendDOMString(type, string, root = document.body) {
112
112
  const nodes = [];
113
113
  const parser = new DOMParser();
114
114
  const fragment = document.createDocumentFragment();
115
- const { body } = parser.parseFromString(html.trim(), 'text/html');
116
- while (body.firstChild) {
117
- nodes.push(fragment.appendChild(body.firstChild));
115
+ const { body, childNodes } = parser.parseFromString(string, type);
116
+ for (const node of body ? body.childNodes : childNodes) {
117
+ nodes.push(node);
118
+ fragment.appendChild(node);
118
119
  }
119
120
  root.appendChild(fragment);
120
121
  return nodes;
121
122
  }
122
123
 
123
- export { ansiToHTML, appendHTML, blockToHTML, escapeHTML, getRootElement, injectCSS };
124
+ export { ansiToHTML, appendDOMString, blockToHTML, escapeHTML, getRootElement, insertCSSString };
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.15.16
4
+ * @version 0.16.0
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.16
4
+ * @version 0.16.0
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.16
4
+ * @version 0.16.0
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
@@ -5,4 +5,4 @@ import { Middleware } from 'koa';
5
5
  import { UnionCompiler } from '../interface.js';
6
6
  import { Expose, Options } from './interface.js';
7
7
  export { Expose, Options };
8
- export declare function dev(compiler: UnionCompiler, options: Options): Middleware & Expose;
8
+ export declare function dev(compiler: UnionCompiler, options: Options): Promise<Middleware & Expose>;
@@ -1,13 +1,12 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.15.16
4
+ * @version 0.16.0
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 { ready } from './utils/ready.js';
11
10
  import { createMemfs } from './utils/fs.js';
12
11
  import { middleware } from './middleware.js';
13
12
  import { setupHooks } from './utils/setupHooks.js';
@@ -36,18 +35,12 @@ function setup(compiler, options) {
36
35
  setupWatching(context);
37
36
  return context;
38
37
  }
39
- function dev(compiler, options) {
38
+ async function dev(compiler, options) {
40
39
  const context = setup(compiler, options);
41
- return Object.assign(middleware(context), {
42
- get state() {
43
- return !!context.stats;
44
- },
40
+ return Object.assign(await middleware(context), {
45
41
  get logger() {
46
42
  return context.logger;
47
43
  },
48
- ready(callback) {
49
- ready(context, callback);
50
- },
51
44
  close(callback) {
52
45
  context.watching.close(callback);
53
46
  },
@@ -13,8 +13,6 @@ export interface ErrorCallback {
13
13
  }
14
14
  export interface Expose {
15
15
  readonly logger: Logger;
16
- readonly state: boolean;
17
- readonly ready: (callback: Callback) => void;
18
16
  readonly close: (callback: ErrorCallback) => void;
19
17
  readonly invalidate: (callback: ErrorCallback) => void;
20
18
  }
@@ -29,7 +27,6 @@ export interface Context {
29
27
  callbacks: Callback[];
30
28
  compiler: UnionCompiler;
31
29
  watching: UnionWatching;
32
- services?: FileService[];
33
30
  stats: UnionStats | null;
34
31
  options: Options & {
35
32
  fs: FileSystem;
@@ -3,4 +3,4 @@
3
3
  */
4
4
  import { Middleware } from 'koa';
5
5
  import { Context } from './interface.js';
6
- export declare function middleware(context: Context): Middleware;
6
+ export declare function middleware(context: Context): Promise<Middleware>;