webpack-dev-service 0.13.2 → 0.14.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 (148) hide show
  1. package/README.md +9 -8
  2. package/cjs/client/client.cjs +24 -9
  3. package/cjs/client/client.d.cts +14 -0
  4. package/cjs/client/events.cjs +1 -1
  5. package/cjs/client/events.d.cts +28 -0
  6. package/cjs/client/hot.cjs +19 -21
  7. package/cjs/client/hot.d.cts +16 -0
  8. package/cjs/client/index.cjs +1 -1
  9. package/cjs/client/index.d.cts +4 -0
  10. package/cjs/client/main.cjs +4 -3
  11. package/cjs/client/main.d.cts +4 -0
  12. package/cjs/client/ui/Overlay.cjs +1 -1
  13. package/cjs/client/ui/Overlay.d.cts +12 -0
  14. package/cjs/client/ui/Progress.cjs +1 -1
  15. package/cjs/client/ui/Progress.d.cts +12 -0
  16. package/cjs/client/ui/utils.cjs +1 -1
  17. package/cjs/client/ui/utils.d.cts +15 -0
  18. package/cjs/server/compose.cjs +13 -12
  19. package/cjs/server/compose.d.cts +18 -0
  20. package/cjs/server/dev/ReadStream.cjs +1 -1
  21. package/cjs/server/dev/ReadStream.d.cts +43 -0
  22. package/cjs/server/dev/Service.cjs +1 -1
  23. package/cjs/server/dev/Service.d.cts +48 -0
  24. package/cjs/server/dev/index.cjs +1 -1
  25. package/cjs/server/dev/index.d.cts +8 -0
  26. package/cjs/server/dev/interface.d.cts +38 -0
  27. package/cjs/server/dev/middleware.cjs +1 -1
  28. package/cjs/server/dev/middleware.d.cts +6 -0
  29. package/cjs/server/dev/utils/fs.cjs +1 -1
  30. package/cjs/server/dev/utils/fs.d.cts +24 -0
  31. package/cjs/server/dev/utils/hash.cjs +1 -1
  32. package/cjs/server/dev/utils/hash.d.cts +9 -0
  33. package/cjs/server/dev/utils/http.cjs +1 -1
  34. package/cjs/server/dev/utils/http.d.cts +37 -0
  35. package/cjs/server/dev/utils/path.cjs +1 -1
  36. package/cjs/server/dev/utils/path.d.cts +22 -0
  37. package/cjs/server/dev/utils/paths.cjs +1 -1
  38. package/cjs/server/dev/utils/paths.d.cts +7 -0
  39. package/cjs/server/dev/utils/ready.cjs +1 -1
  40. package/cjs/server/dev/utils/ready.d.cts +5 -0
  41. package/cjs/server/dev/utils/setupHooks.cjs +2 -5
  42. package/cjs/server/dev/utils/setupHooks.d.cts +5 -0
  43. package/cjs/server/dev/utils/setupOutputFileSystem.cjs +1 -1
  44. package/cjs/server/dev/utils/setupOutputFileSystem.d.cts +5 -0
  45. package/cjs/server/dev/utils/setupWatching.cjs +1 -1
  46. package/cjs/server/dev/utils/setupWatching.d.cts +5 -0
  47. package/cjs/server/dev/utils/setupWriteToDisk.cjs +2 -2
  48. package/cjs/server/dev/utils/setupWriteToDisk.d.cts +5 -0
  49. package/cjs/server/hot/Message.d.cts +49 -0
  50. package/cjs/server/hot/Socket.cjs +109 -97
  51. package/cjs/server/hot/Socket.d.cts +11 -0
  52. package/cjs/server/hot/index.cjs +3 -10
  53. package/cjs/server/hot/index.d.cts +8 -0
  54. package/cjs/server/hot/interface.d.cts +22 -0
  55. package/cjs/server/hot/utils.cjs +11 -36
  56. package/cjs/server/hot/utils.d.cts +12 -0
  57. package/cjs/server/index.cjs +8 -2
  58. package/cjs/server/index.d.cts +17 -0
  59. package/cjs/server/interface.d.cts +14 -0
  60. package/cjs/server/schema.cjs +1 -1
  61. package/cjs/server/schema.d.cts +7 -0
  62. package/cjs/server/utils.cjs +1 -5
  63. package/cjs/server/utils.d.cts +11 -0
  64. package/esm/client/client.d.ts +14 -0
  65. package/esm/client/client.js +25 -10
  66. package/esm/client/events.d.ts +28 -0
  67. package/esm/client/events.js +1 -1
  68. package/esm/client/hot.d.ts +16 -0
  69. package/esm/client/hot.js +19 -19
  70. package/esm/client/index.d.ts +4 -0
  71. package/esm/client/index.js +1 -1
  72. package/esm/client/main.d.ts +4 -0
  73. package/esm/client/main.js +4 -3
  74. package/esm/client/ui/Overlay.d.ts +12 -0
  75. package/esm/client/ui/Overlay.js +1 -1
  76. package/esm/client/ui/Progress.d.ts +12 -0
  77. package/esm/client/ui/Progress.js +1 -1
  78. package/esm/client/ui/utils.d.ts +15 -0
  79. package/esm/client/ui/utils.js +1 -1
  80. package/esm/server/compose.d.ts +18 -0
  81. package/esm/server/compose.js +13 -12
  82. package/esm/server/dev/ReadStream.d.ts +43 -0
  83. package/esm/server/dev/ReadStream.js +1 -1
  84. package/esm/server/dev/Service.d.ts +48 -0
  85. package/esm/server/dev/Service.js +1 -1
  86. package/esm/server/dev/index.d.ts +8 -0
  87. package/esm/server/dev/index.js +1 -1
  88. package/esm/server/dev/interface.d.ts +38 -0
  89. package/esm/server/dev/middleware.d.ts +6 -0
  90. package/esm/server/dev/middleware.js +1 -1
  91. package/esm/server/dev/utils/fs.d.ts +24 -0
  92. package/esm/server/dev/utils/fs.js +1 -1
  93. package/esm/server/dev/utils/hash.d.ts +9 -0
  94. package/esm/server/dev/utils/hash.js +1 -1
  95. package/esm/server/dev/utils/http.d.ts +37 -0
  96. package/esm/server/dev/utils/http.js +1 -1
  97. package/esm/server/dev/utils/path.d.ts +22 -0
  98. package/esm/server/dev/utils/path.js +1 -1
  99. package/esm/server/dev/utils/paths.d.ts +7 -0
  100. package/esm/server/dev/utils/paths.js +1 -1
  101. package/esm/server/dev/utils/ready.d.ts +5 -0
  102. package/esm/server/dev/utils/ready.js +1 -1
  103. package/esm/server/dev/utils/setupHooks.d.ts +5 -0
  104. package/esm/server/dev/utils/setupHooks.js +2 -5
  105. package/esm/server/dev/utils/setupOutputFileSystem.d.ts +5 -0
  106. package/esm/server/dev/utils/setupOutputFileSystem.js +1 -1
  107. package/esm/server/dev/utils/setupWatching.d.ts +5 -0
  108. package/esm/server/dev/utils/setupWatching.js +1 -1
  109. package/esm/server/dev/utils/setupWriteToDisk.d.ts +5 -0
  110. package/esm/server/dev/utils/setupWriteToDisk.js +2 -2
  111. package/{types/client → esm/server/hot}/Message.d.ts +15 -7
  112. package/esm/server/hot/Socket.d.ts +11 -0
  113. package/esm/server/hot/Socket.js +110 -98
  114. package/esm/server/hot/index.d.ts +8 -0
  115. package/esm/server/hot/index.js +3 -10
  116. package/esm/server/hot/interface.d.ts +22 -0
  117. package/esm/server/hot/utils.d.ts +12 -0
  118. package/esm/server/hot/utils.js +12 -38
  119. package/esm/server/index.d.ts +17 -0
  120. package/esm/server/index.js +8 -2
  121. package/esm/server/interface.d.ts +14 -0
  122. package/esm/server/schema.d.ts +7 -0
  123. package/esm/server/schema.js +1 -1
  124. package/esm/server/utils.d.ts +11 -0
  125. package/esm/server/utils.js +2 -5
  126. package/global.d.ts +2 -0
  127. package/package.json +20 -19
  128. package/types/client/client.d.ts +2 -1
  129. package/types/client/events.d.ts +2 -9
  130. package/types/client/hot.d.ts +3 -14
  131. package/types/server/compose.d.ts +2 -2
  132. package/types/server/dev/index.d.ts +1 -1
  133. package/types/server/dev/interface.d.ts +2 -2
  134. package/types/server/dev/utils/fs.d.ts +2 -4
  135. package/types/server/dev/utils/paths.d.ts +1 -1
  136. package/types/server/dev/utils/ready.d.ts +1 -1
  137. package/types/server/dev/utils/setupHooks.d.ts +1 -1
  138. package/types/server/dev/utils/setupOutputFileSystem.d.ts +1 -1
  139. package/types/server/dev/utils/setupWatching.d.ts +1 -1
  140. package/types/server/dev/utils/setupWriteToDisk.d.ts +1 -1
  141. package/types/server/hot/Message.d.ts +49 -0
  142. package/types/server/hot/Socket.d.ts +1 -4
  143. package/types/server/hot/index.d.ts +4 -4
  144. package/types/server/hot/interface.d.ts +8 -6
  145. package/types/server/hot/utils.d.ts +4 -4
  146. package/types/server/index.d.ts +6 -26
  147. package/types/server/interface.d.ts +3 -0
  148. package/types/server/utils.d.ts +0 -1
package/README.md CHANGED
@@ -15,28 +15,28 @@
15
15
  ```ts
16
16
  /**
17
17
  * @module webpack
18
- * @description Webpack config
18
+ * @description Webpack config.
19
19
  */
20
20
 
21
21
  import Koa from 'koa';
22
- import path from 'path';
23
22
  import memfs from 'memfs';
23
+ import path from 'node:path';
24
24
  import webpack from 'webpack';
25
25
  import compress from 'koa-compress';
26
- import dev from 'webpack-dev-service';
27
26
  import HtmlWebpackPlugin from 'html-webpack-plugin';
27
+ import { server as dev } from 'webpack-dev-service';
28
28
  import MiniCssExtractPlugin from 'mini-css-extract-plugin';
29
29
 
30
30
  const progress = {
31
31
  percentBy: 'entries'
32
32
  };
33
33
 
34
- const entryHTML = path.resolve('public/index.html');
34
+ const entryHTML = path.resolve('wwwroot/index.html');
35
35
 
36
36
  const html = {
37
37
  xhtml: true,
38
38
  minify: false,
39
- title: 'React',
39
+ title: 'Webpack',
40
40
  filename: entryHTML,
41
41
  templateParameters: { lang: 'en' },
42
42
  template: path.resolve('index.ejs'),
@@ -56,15 +56,15 @@ function httpError(error) {
56
56
  }
57
57
 
58
58
  const compiler = webpack({
59
- name: 'react',
59
+ name: 'React',
60
60
  mode: 'development',
61
61
  context: path.resolve('src'),
62
62
  entry: path.resolve('src/index.tsx'),
63
63
  output: {
64
64
  publicPath: '/public/',
65
65
  filename: `js/[name].js`,
66
- path: path.resolve('public'),
67
66
  chunkFilename: `js/[name].js`,
67
+ path: path.resolve('wwwroot/public'),
68
68
  assetModuleFilename: `[path][name][ext]`
69
69
  },
70
70
  devtool: 'eval-cheap-module-source-map',
@@ -136,8 +136,9 @@ const compiler = webpack({
136
136
  esModule: true,
137
137
  modules: {
138
138
  auto: true,
139
+ namedExport: false,
139
140
  localIdentName: '[local]-[hash:8]',
140
- exportLocalsConvention: 'camelCaseOnly'
141
+ exportLocalsConvention: 'camel-case-only'
141
142
  }
142
143
  }
143
144
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.13.2
4
+ * @version 0.14.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
@@ -9,9 +9,9 @@
9
9
 
10
10
  'use strict';
11
11
 
12
+ const events = require('./events.cjs');
12
13
  const Overlay = require('./ui/Overlay.cjs');
13
14
  const Progress = require('./ui/Progress.cjs');
14
- const events = require('./events.cjs');
15
15
  const hot = require('./hot.cjs');
16
16
 
17
17
  /**
@@ -48,7 +48,7 @@ function createClient(options) {
48
48
  }
49
49
  };
50
50
  const onHash = ({ hash }) => {
51
- hot.setHash(hash);
51
+ hot.updateHash(hash);
52
52
  };
53
53
  const setIssues = (type, issues) => {
54
54
  if (options.overlay) {
@@ -116,15 +116,30 @@ function createClient(options) {
116
116
  events.emit(action, payload, options);
117
117
  }
118
118
  };
119
- ws.onclose = () => {
119
+ ws.onclose = event => {
120
120
  overlay.hide();
121
121
  progress.hide();
122
- setTimeout(() => {
123
- createWebSocket(url);
124
- }, RETRY_INTERVAL);
122
+ switch (event.code) {
123
+ case 4000:
124
+ case 4001:
125
+ fallback();
126
+ break;
127
+ default:
128
+ if (!event.wasClean) {
129
+ setTimeout(() => {
130
+ createWebSocket(url);
131
+ }, RETRY_INTERVAL);
132
+ }
133
+ break;
134
+ }
125
135
  };
126
136
  };
127
- createWebSocket(`${options.origin}${options.path}`);
137
+ const { uuid } = options;
138
+ const input = new URL(`${options.origin}${options.path}`);
139
+ if (uuid) {
140
+ input.searchParams.set('uuid', uuid);
141
+ }
142
+ createWebSocket(input.href);
128
143
  }
129
144
 
130
- module.exports = createClient;
145
+ exports.createClient = createClient;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @module client
3
+ */
4
+ export interface Options {
5
+ readonly hmr: boolean;
6
+ readonly name: string;
7
+ readonly path: string;
8
+ readonly origin: string;
9
+ readonly reload: boolean;
10
+ readonly overlay: boolean;
11
+ readonly progress: boolean;
12
+ readonly uuid: string | null;
13
+ }
14
+ export declare function createClient(options: Options): void;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.13.2
4
+ * @version 0.14.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,28 @@
1
+ /**
2
+ * @module events
3
+ */
4
+ import { Options } from './client.cjs';
5
+ import { GetProp } from '../server/interface.cjs';
6
+ import { Messages } from '../server/hot/Message.cjs';
7
+ export interface Events {
8
+ ok(message: GetProp<Messages, 'ok'>, options: Options): void;
9
+ hash(message: GetProp<Messages, 'hash'>, options: Options): void;
10
+ issues(message: GetProp<Messages, 'issues'>, options: Options): void;
11
+ invalid(message: GetProp<Messages, 'invalid'>, options: Options): void;
12
+ progress(message: GetProp<Messages, 'progress'>, options: Options): void;
13
+ }
14
+ /**
15
+ * @function on
16
+ * @description Add an event listener callback.
17
+ * @param event Event name.
18
+ * @param callback Event listener callback.
19
+ */
20
+ export declare function on<E extends keyof Events>(event: E, callback: GetProp<Events, E>): void;
21
+ /**
22
+ * @function off
23
+ * @description Remove an event listener callback.
24
+ * @param event Event name.
25
+ * @param callback Event listener callback.
26
+ */
27
+ export declare function off<E extends keyof Events>(event: E, callback?: GetProp<Events, E>): void;
28
+ export declare function emit<E extends keyof Events>(event: E, message: GetProp<Messages, E>, options: Options): void;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.13.2
4
+ * @version 0.14.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
@@ -28,24 +28,24 @@ function isUpdateAvailable() {
28
28
  return hash !== __webpack_hash__;
29
29
  }
30
30
  /**
31
- * @function setHash
32
- * @description Set webpack hash.
33
- * @param value The new hash value.
34
- */
35
- function setHash(value) {
36
- hash = value;
37
- }
38
- /**
39
- * @function setStatus
40
- * @description Set hot status.
31
+ * @function updateStatus
32
+ * @description Update hot status.
41
33
  * @param value The new status of the hot update.
42
34
  */
43
- function setStatus(value) {
35
+ function updateStatus(value) {
44
36
  status = value;
45
37
  }
46
38
  // Initialize status.
47
39
  if (module.hot) {
48
- setStatus(module.hot.status());
40
+ updateStatus(module.hot.status());
41
+ }
42
+ /**
43
+ * @function updateHash
44
+ * @description Update webpack hash.
45
+ * @param value The new hash value.
46
+ */
47
+ function updateHash(value) {
48
+ hash = value;
49
49
  }
50
50
  /**
51
51
  * @function applyUpdate
@@ -60,14 +60,14 @@ function applyUpdate(hmr, fallback) {
60
60
  if (hmr && module.hot) {
61
61
  switch (status) {
62
62
  case 'idle':
63
- // Set status.
64
- setStatus('check');
63
+ // Update status.
64
+ updateStatus('check');
65
65
  // Auto check and apply updates.
66
66
  module.hot
67
67
  .check(true)
68
68
  .then(updated => {
69
69
  // Update status.
70
- setStatus(module.hot.status());
70
+ updateStatus(module.hot.status());
71
71
  // When updated modules is available,
72
72
  // it indicates server is ready to serve new bundle.
73
73
  if (updated) {
@@ -82,9 +82,9 @@ function applyUpdate(hmr, fallback) {
82
82
  switch (status) {
83
83
  case 'fail':
84
84
  case 'abort':
85
- setStatus(status);
85
+ updateStatus(status);
86
86
  default:
87
- setStatus('fail');
87
+ updateStatus('fail');
88
88
  }
89
89
  // Cache error.
90
90
  error = exception;
@@ -106,6 +106,4 @@ function applyUpdate(hmr, fallback) {
106
106
  }
107
107
 
108
108
  exports.applyUpdate = applyUpdate;
109
- exports.isUpdateAvailable = isUpdateAvailable;
110
- exports.setHash = setHash;
111
- exports.setStatus = setStatus;
109
+ exports.updateHash = updateHash;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @module hot
3
+ */
4
+ /**
5
+ * @function updateHash
6
+ * @description Update webpack hash.
7
+ * @param value The new hash value.
8
+ */
9
+ export declare function updateHash(value: string): void;
10
+ /**
11
+ * @function applyUpdate
12
+ * @description Apply update.
13
+ * @param hmr Whether to enable HMR.
14
+ * @param fallback Fallback function when HMR fail.
15
+ */
16
+ export declare function applyUpdate(hmr: boolean, fallback: (error?: Error) => void): void;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.13.2
4
+ * @version 0.14.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,4 @@
1
+ /**
2
+ * @module index
3
+ */
4
+ export { off, on } from './events.cjs';
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.13.2
4
+ * @version 0.14.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
@@ -47,13 +47,14 @@ const getOrigin = params => {
47
47
  const getOptions = () => {
48
48
  const params = new URLSearchParams(__resourceQuery);
49
49
  return {
50
+ uuid: params.get('uuid'),
50
51
  origin: getOrigin(params),
51
52
  hmr: params.get('hmr') !== 'false',
52
53
  path: params.get('path') || '/hot',
53
- name: params.get('name') || 'webpack',
54
+ name: params.get('name') || 'rspack',
54
55
  reload: params.get('reload') !== 'false',
55
56
  overlay: params.get('overlay') !== 'false',
56
57
  progress: params.get('progress') !== 'false'
57
58
  };
58
59
  };
59
- client(getOptions());
60
+ client.createClient(getOptions());
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @module main
3
+ */
4
+ export {};
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.13.2
4
+ * @version 0.14.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,12 @@
1
+ /**
2
+ * @module overlay
3
+ * @see https://github.com/shellscape/webpack-plugin-serve
4
+ */
5
+ import webpack from 'webpack';
6
+ export declare class Overlay {
7
+ #private;
8
+ constructor(name: string);
9
+ setIssues(type: 'errors' | 'warnings', issues: webpack.StatsError[]): void;
10
+ show(): void;
11
+ hide(): void;
12
+ }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.13.2
4
+ * @version 0.14.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,12 @@
1
+ /**
2
+ * @module progress
3
+ * @see https://github.com/shellscape/webpack-plugin-serve
4
+ * @see https://www.zhangxinxu.com/wordpress/2015/07/svg-circle-loading
5
+ */
6
+ export declare class Progress {
7
+ #private;
8
+ constructor();
9
+ update(percentage: number): void;
10
+ show(): void;
11
+ hide(): void;
12
+ }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.13.2
4
+ * @version 0.14.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,15 @@
1
+ /**
2
+ * @module utils
3
+ */
4
+ import { AnsiBlock } from '@nuintun/ansi';
5
+ export declare function escapeHTML(text: string): string;
6
+ export declare function blockToHTML({ style, value, url }: AnsiBlock): string;
7
+ export declare function ansiToHTML(text: string): string;
8
+ export type RootElement = HTMLElement | ShadowRoot;
9
+ export declare function getRootElement(tagName: string): ShadowRoot;
10
+ export declare function injectCSS(
11
+ css: string,
12
+ root?: HTMLElement | ShadowRoot,
13
+ styleElement?: HTMLStyleElement
14
+ ): HTMLStyleElement;
15
+ export declare function appendHTML(html: string, root?: RootElement): ChildNode[];
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.13.2
4
+ * @version 0.14.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
@@ -14,11 +14,12 @@
14
14
  */
15
15
  /**
16
16
  * @function dispatch
17
- * @param middlewares 中间件数组
18
- * @param index 要执行的中间件索引
19
- * @param stack 调用栈信息
20
- * @param context 执行上下文
21
- * @param [next] 下一个中间件
17
+ * @description Dispatch middlewares.
18
+ * @param middlewares The middlewares list.
19
+ * @param index The current middleware index.
20
+ * @param stack The call stack.
21
+ * @param context The execution context.
22
+ * @param next The next middleware.
22
23
  */
23
24
  async function dispatch(middlewares, index, stack, context, next) {
24
25
  if (index <= stack.index) {
@@ -37,15 +38,15 @@ async function dispatch(middlewares, index, stack, context, next) {
37
38
  }
38
39
  /**
39
40
  * @function compose
40
- * @description 生成融合中间件
41
- * @param middlewares 中间件数组
41
+ * @description Compose middlewares.
42
+ * @param middlewares The middlewares list.
42
43
  */
43
44
  function compose(...middlewares) {
44
45
  /**
45
- * @function middleware
46
- * @description 融合中间件
47
- * @param context 执行上下文
48
- * @param [next] 下一个中间件
46
+ * @function compose
47
+ * @description Compose middlewares.
48
+ * @param context The execution context.
49
+ * @param next The next middleware.
49
50
  */
50
51
  return (context, next) => {
51
52
  const stack = { index: -1 };
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @module compose
3
+ */
4
+ export interface Next {
5
+ (): Promise<void>;
6
+ }
7
+ export interface Composed<C> {
8
+ (context: C, next?: Next): Promise<void>;
9
+ }
10
+ export interface Middleware<C> {
11
+ (context: C, next: Next): Promise<void> | void;
12
+ }
13
+ /**
14
+ * @function compose
15
+ * @description Compose middlewares.
16
+ * @param middlewares The middlewares list.
17
+ */
18
+ export declare function compose<C>(...middlewares: Middleware<C>[]): Composed<C>;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.13.2
4
+ * @version 0.14.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,43 @@
1
+ /**
2
+ * @module ReadStream
3
+ */
4
+ import { PathLike } from 'node:fs';
5
+ import { Range } from './utils/http.cjs';
6
+ import { FileSystem } from './utils/fs.cjs';
7
+ import { Readable, ReadableOptions } from 'node:stream';
8
+ export interface Options extends Pick<ReadableOptions, 'highWaterMark'> {
9
+ fs: FileSystem;
10
+ }
11
+ interface Callback {
12
+ (error?: Error | null): void;
13
+ }
14
+ export declare class ReadStream extends Readable {
15
+ #private;
16
+ /**
17
+ * @constructor
18
+ * @param path The file path.
19
+ * @param ranges The ranges to read.
20
+ * @param options The stream options.
21
+ */
22
+ constructor(path: PathLike, ranges: Range[], options: Options);
23
+ /**
24
+ * @override
25
+ * @method _construct
26
+ * @param callback The callback.
27
+ */
28
+ _construct(callback: Callback): void;
29
+ /**
30
+ * @override
31
+ * @method _read
32
+ * @param size The number of bytes to read.
33
+ */
34
+ _read(size: number): void;
35
+ /**
36
+ * @override
37
+ * @method _destroy
38
+ * @param error The error.
39
+ * @param callback The callback.
40
+ */
41
+ _destroy(error: Error | null, callback: Callback): void;
42
+ }
43
+ export {};
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.13.2
4
+ * @version 0.14.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,48 @@
1
+ /**
2
+ * @module Service
3
+ */
4
+ import { Context } from 'koa';
5
+ import { Stats } from 'node:fs';
6
+ import { FileSystem } from './utils/fs.cjs';
7
+ interface IgnoreFunction {
8
+ (path: string): boolean;
9
+ }
10
+ interface Headers {
11
+ [key: string]: string | string[];
12
+ }
13
+ type FileStats = Stats | null | undefined;
14
+ interface HeadersFunction {
15
+ (path: string, stats: FileStats): Promise<Headers | void> | Headers | void;
16
+ }
17
+ export interface Options {
18
+ fs: FileSystem;
19
+ etag?: boolean;
20
+ acceptRanges?: boolean;
21
+ lastModified?: boolean;
22
+ highWaterMark?: number;
23
+ ignore?: IgnoreFunction;
24
+ headers?: Headers | HeadersFunction;
25
+ }
26
+ /**
27
+ * @class Service
28
+ */
29
+ export declare class Service {
30
+ #private;
31
+ /**
32
+ * @constructor
33
+ * @description Create file service.
34
+ * @param root The file service root.
35
+ * @param options The file service options.
36
+ */
37
+ constructor(root: string, options: Options);
38
+ /**
39
+ * @public
40
+ * @method respond
41
+ * @description Respond file.
42
+ * @param pathname The pathname.
43
+ * @param context The koa context.
44
+ * @param publicPath The public path.
45
+ */
46
+ respond(pathname: string, context: Context, publicPath: string): Promise<boolean>;
47
+ }
48
+ export {};
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.13.2
4
+ * @version 0.14.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,8 @@
1
+ /**
2
+ * @module index
3
+ */
4
+ import { Middleware } from 'koa';
5
+ import { UnionCompiler } from '../interface.cjs';
6
+ import { Expose, Options } from './interface.cjs';
7
+ export { Expose, Options };
8
+ export declare function dev(compiler: UnionCompiler, options: Options): Middleware & Expose;
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @module interface
3
+ */
4
+ import webpack from 'webpack';
5
+ import { FileSystem } from './utils/fs.cjs';
6
+ import { Options as ServiceOptions, Service } from './Service.cjs';
7
+ import { Logger, Optional, StatsOptions, UnionCompiler, UnionStats, UnionWatching } from '../interface.cjs';
8
+ export interface Callback {
9
+ (stats: UnionStats): void;
10
+ }
11
+ export interface ErrorCallback {
12
+ (error?: Error | null): void;
13
+ }
14
+ export interface Expose {
15
+ readonly logger: Logger;
16
+ readonly state: boolean;
17
+ readonly ready: (callback: Callback) => void;
18
+ readonly close: (callback: ErrorCallback) => void;
19
+ readonly invalidate: (callback: ErrorCallback) => void;
20
+ }
21
+ export type FileService = [publicPath: string, service: Service];
22
+ export interface Options extends Optional<ServiceOptions, 'fs'> {
23
+ stats?: StatsOptions;
24
+ writeToDisk?: boolean | ((targetPath: string) => boolean);
25
+ onCompilationDone?: (stats: UnionStats, statsOptions: Readonly<webpack.StatsOptions>) => void;
26
+ }
27
+ export interface Context {
28
+ logger: Logger;
29
+ callbacks: Callback[];
30
+ compiler: UnionCompiler;
31
+ watching: UnionWatching;
32
+ services?: FileService[];
33
+ stats: UnionStats | null;
34
+ options: Options & {
35
+ fs: FileSystem;
36
+ };
37
+ }
38
+ export type InitialContext = Optional<Context, 'watching'>;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.13.2
4
+ * @version 0.14.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,6 @@
1
+ /**
2
+ * @module middleware
3
+ */
4
+ import { Middleware } from 'koa';
5
+ import { Context } from './interface.cjs';
6
+ export declare function middleware(context: Context): Middleware;