rspack-dev-middleware 0.4.0 → 0.4.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 (75) hide show
  1. package/cjs/client/HotUpdate.cjs +1 -1
  2. package/cjs/client/client.cjs +2 -2
  3. package/cjs/client/events.cjs +5 -5
  4. package/cjs/client/events.d.cts +3 -7
  5. package/cjs/client/index.cjs +1 -1
  6. package/cjs/client/main.cjs +3 -3
  7. package/cjs/client/ui/Overlay.cjs +4 -4
  8. package/cjs/client/ui/Progress.cjs +3 -3
  9. package/cjs/client/ui/images/rspack-logo.svg.cjs +1 -1
  10. package/cjs/client/ui/utils.cjs +16 -22
  11. package/cjs/client/ui/utils.d.cts +3 -10
  12. package/cjs/server/compose.cjs +2 -2
  13. package/cjs/server/dev/ReadStream.cjs +5 -5
  14. package/cjs/server/dev/Service.cjs +10 -21
  15. package/cjs/server/dev/index.cjs +7 -3
  16. package/cjs/server/dev/middleware.cjs +4 -5
  17. package/cjs/server/dev/utils/fs.cjs +1 -1
  18. package/cjs/server/dev/utils/http.cjs +56 -28
  19. package/cjs/server/dev/utils/http.d.cts +26 -1
  20. package/cjs/server/dev/utils/path.cjs +1 -1
  21. package/cjs/server/dev/utils/paths.cjs +1 -1
  22. package/cjs/server/dev/utils/setupHooks.cjs +3 -9
  23. package/cjs/server/dev/utils/setupOutputFileSystem.cjs +1 -1
  24. package/cjs/server/dev/utils/setupWatching.cjs +11 -16
  25. package/cjs/server/dev/utils/setupWriteToDisk.cjs +1 -1
  26. package/cjs/server/hot/Message.d.cts +16 -32
  27. package/cjs/server/hot/Socket.cjs +19 -20
  28. package/cjs/server/hot/index.cjs +1 -1
  29. package/cjs/server/hot/utils.cjs +2 -8
  30. package/cjs/server/index.cjs +1 -1
  31. package/cjs/server/schema.cjs +27 -6
  32. package/cjs/server/utils.cjs +12 -1
  33. package/cjs/server/utils.d.cts +1 -0
  34. package/esm/client/HotUpdate.js +1 -1
  35. package/esm/client/client.js +2 -2
  36. package/esm/client/events.d.ts +3 -7
  37. package/esm/client/events.js +5 -5
  38. package/esm/client/index.js +1 -1
  39. package/esm/client/main.js +3 -3
  40. package/esm/client/ui/Overlay.js +5 -5
  41. package/esm/client/ui/Progress.js +4 -4
  42. package/esm/client/ui/images/rspack-logo.svg.js +1 -1
  43. package/esm/client/ui/utils.d.ts +3 -10
  44. package/esm/client/ui/utils.js +15 -21
  45. package/esm/server/compose.js +2 -2
  46. package/esm/server/dev/ReadStream.js +5 -5
  47. package/esm/server/dev/Service.js +10 -15
  48. package/esm/server/dev/index.js +7 -3
  49. package/esm/server/dev/middleware.js +4 -5
  50. package/esm/server/dev/utils/fs.js +1 -1
  51. package/esm/server/dev/utils/http.d.ts +26 -1
  52. package/esm/server/dev/utils/http.js +62 -29
  53. package/esm/server/dev/utils/path.js +1 -1
  54. package/esm/server/dev/utils/paths.js +1 -1
  55. package/esm/server/dev/utils/setupHooks.js +4 -10
  56. package/esm/server/dev/utils/setupOutputFileSystem.js +1 -1
  57. package/esm/server/dev/utils/setupWatching.js +11 -16
  58. package/esm/server/dev/utils/setupWriteToDisk.js +1 -1
  59. package/esm/server/hot/Message.d.ts +16 -32
  60. package/esm/server/hot/Socket.js +16 -17
  61. package/esm/server/hot/index.js +1 -1
  62. package/esm/server/hot/utils.js +3 -9
  63. package/esm/server/index.js +1 -1
  64. package/esm/server/schema.js +27 -6
  65. package/esm/server/utils.d.ts +1 -0
  66. package/esm/server/utils.js +12 -2
  67. package/package.json +35 -37
  68. package/cjs/server/dev/utils/hash.cjs +0 -47
  69. package/cjs/server/dev/utils/hash.d.cts +0 -9
  70. package/cjs/server/dev/utils/ready.cjs +0 -24
  71. package/cjs/server/dev/utils/ready.d.cts +0 -5
  72. package/esm/server/dev/utils/hash.d.ts +0 -9
  73. package/esm/server/dev/utils/hash.js +0 -45
  74. package/esm/server/dev/utils/ready.d.ts +0 -5
  75. package/esm/server/dev/utils/ready.js +0 -22
@@ -16,12 +16,37 @@ export interface Range {
16
16
  * @param URI The URI to decode.
17
17
  */
18
18
  export declare function decodeURI(URI: string): string | -1;
19
+ /**
20
+ * @function generateBoundary
21
+ * @description Generate a boundary string.
22
+ */
23
+ export declare function generateBoundary(): string;
19
24
  /**
20
25
  * @function isConditionalGET
21
26
  * @description Check if request is conditional GET.
22
27
  * @param context The koa context.
23
28
  */
24
29
  export declare function isConditionalGET({ request }: Context): boolean;
30
+ /**
31
+ * @function createETag
32
+ * @description Generate a weak entity tag from file stats.
33
+ * @param stats The file stats.
34
+ */
35
+ export declare function createETag(stats: Stats): string;
36
+ /**
37
+ * @function isETagMatch
38
+ * @see https://httpwg.org/specs/rfc9110.html
39
+ * @param match The match value.
40
+ * @param etag The etag value.
41
+ * @param isIfMatch The flag of if-match.
42
+ */
43
+ export declare function isETagMatch(match: string, etag: string, isIfMatch?: boolean): boolean;
44
+ /**
45
+ * @function isRangeFresh
46
+ * @description Check if request range fresh.
47
+ * @param context Koa context.
48
+ */
49
+ export declare function isRangeFresh({ request, response }: Context): boolean;
25
50
  /**
26
51
  * @function isPreconditionFailed
27
52
  * @description Check if request precondition failed.
@@ -34,4 +59,4 @@ export declare function isPreconditionFailed({ request, response }: Context): bo
34
59
  * @param context The koa context.
35
60
  * @param stats The file stats.
36
61
  */
37
- export declare function parseRanges(context: Context, stats: Stats): -1 | -2 | Range[];
62
+ export declare function parseRanges(context: Context, stats: Stats): -1 | Range[];
@@ -2,7 +2,7 @@
2
2
  * @module rspack-dev-middleware
3
3
  * @package rspack-dev-middleware
4
4
  * @license MIT
5
- * @version 0.4.0
5
+ * @version 0.4.2
6
6
  * @author nuintun <nuintun@qq.com>
7
7
  * @description A koa 2 middleware for rspack development and hot reloading.
8
8
  * @see https://github.com/nuintun/rspack-dev-middleware#readme
@@ -2,7 +2,7 @@
2
2
  * @module rspack-dev-middleware
3
3
  * @package rspack-dev-middleware
4
4
  * @license MIT
5
- * @version 0.4.0
5
+ * @version 0.4.2
6
6
  * @author nuintun <nuintun@qq.com>
7
7
  * @description A koa 2 middleware for rspack development and hot reloading.
8
8
  * @see https://github.com/nuintun/rspack-dev-middleware#readme
@@ -2,7 +2,7 @@
2
2
  * @module rspack-dev-middleware
3
3
  * @package rspack-dev-middleware
4
4
  * @license MIT
5
- * @version 0.4.0
5
+ * @version 0.4.2
6
6
  * @author nuintun <nuintun@qq.com>
7
7
  * @description A koa 2 middleware for rspack development and hot reloading.
8
8
  * @see https://github.com/nuintun/rspack-dev-middleware#readme
@@ -23,13 +23,7 @@ const supportsColor__default = /*#__PURE__*/ _interopDefault(supportsColor);
23
23
  * @module setupHooks
24
24
  */
25
25
  function normalizeStatsOptions(statsOptions) {
26
- if (statsOptions == null) {
27
- return { preset: 'normal' };
28
- } else if (utils.isString(statsOptions)) {
29
- return { preset: statsOptions };
30
- } else if (utils.isBoolean(statsOptions)) {
31
- return statsOptions ? { preset: 'normal' } : { preset: 'none' };
32
- }
26
+ statsOptions = utils.toStatsPreset(statsOptions);
33
27
  if (statsOptions.colors == null) {
34
28
  const { stdout, stderr } = supportsColor__default.default;
35
29
  statsOptions.colors = stdout !== false && stderr !== false;
@@ -83,7 +77,7 @@ function setupHooks(context) {
83
77
  process.nextTick(() => {
84
78
  const { stats } = context;
85
79
  // Check if still in valid state.
86
- if (stats) {
80
+ if (stats != null) {
87
81
  // Call onCompilationDone.
88
82
  onCompilationDone(stats, statsOptions);
89
83
  // Callbacks.
@@ -2,7 +2,7 @@
2
2
  * @module rspack-dev-middleware
3
3
  * @package rspack-dev-middleware
4
4
  * @license MIT
5
- * @version 0.4.0
5
+ * @version 0.4.2
6
6
  * @author nuintun <nuintun@qq.com>
7
7
  * @description A koa 2 middleware for rspack development and hot reloading.
8
8
  * @see https://github.com/nuintun/rspack-dev-middleware#readme
@@ -2,7 +2,7 @@
2
2
  * @module rspack-dev-middleware
3
3
  * @package rspack-dev-middleware
4
4
  * @license MIT
5
- * @version 0.4.0
5
+ * @version 0.4.2
6
6
  * @author nuintun <nuintun@qq.com>
7
7
  * @description A koa 2 middleware for rspack development and hot reloading.
8
8
  * @see https://github.com/nuintun/rspack-dev-middleware#readme
@@ -15,11 +15,8 @@ const utils = require('../../utils.cjs');
15
15
  /**
16
16
  * @module setupWatching
17
17
  */
18
- function getWatching({ compiler, logger }) {
19
- const isMulti = utils.isMultiCompiler(compiler);
20
- if (!isMulti && compiler.watching) {
21
- return compiler.watching;
22
- }
18
+ function setupWatching(context) {
19
+ const { compiler, logger } = context;
23
20
  const errorHandler = error => {
24
21
  if (error != null) {
25
22
  // For example - `writeToDisk` can throw an error and right now it is ends watching.
@@ -28,17 +25,15 @@ function getWatching({ compiler, logger }) {
28
25
  logger.error(error);
29
26
  }
30
27
  };
31
- if (!isMulti) {
32
- const { watchOptions } = compiler.options;
33
- return compiler.watch(watchOptions, errorHandler);
28
+ if (utils.isMultiCompiler(compiler)) {
29
+ const watchOptions = compiler.compilers.map(({ options }) => {
30
+ return options.watchOptions;
31
+ });
32
+ context.watching = compiler.watch(watchOptions, errorHandler);
33
+ } else {
34
+ // Reuse existing watching if present, otherwise start watching.
35
+ context.watching = compiler.watching ?? compiler.watch(compiler.options.watchOptions, errorHandler);
34
36
  }
35
- const watchOptions = compiler.compilers.map(({ options }) => {
36
- return options.watchOptions;
37
- });
38
- return compiler.watch(watchOptions, errorHandler);
39
- }
40
- function setupWatching(context) {
41
- context.watching = getWatching(context);
42
37
  }
43
38
 
44
39
  exports.setupWatching = setupWatching;
@@ -2,7 +2,7 @@
2
2
  * @module rspack-dev-middleware
3
3
  * @package rspack-dev-middleware
4
4
  * @license MIT
5
- * @version 0.4.0
5
+ * @version 0.4.2
6
6
  * @author nuintun <nuintun@qq.com>
7
7
  * @description A koa 2 middleware for rspack development and hot reloading.
8
8
  * @see https://github.com/nuintun/rspack-dev-middleware#readme
@@ -2,17 +2,19 @@
2
2
  * @module message
3
3
  */
4
4
  import * as rspack from '@rspack/core';
5
- import { GetProp } from '../interface.cjs';
6
- export interface Invalid {
7
- action: 'invalid';
8
- payload: {
5
+ export interface Messages {
6
+ ok: {
7
+ timestamp: number;
8
+ };
9
+ hash: {
10
+ hash: string;
11
+ timestamp: number;
12
+ };
13
+ invalid: {
9
14
  timestamp: number;
10
15
  path: string | null;
11
16
  };
12
- }
13
- export interface Progress {
14
- action: 'progress';
15
- payload: {
17
+ progress: {
16
18
  stage: string;
17
19
  percent: number;
18
20
  details: {
@@ -20,33 +22,15 @@ export interface Progress {
20
22
  moduleIdentifier?: string;
21
23
  };
22
24
  };
23
- }
24
- export interface Hash {
25
- action: 'hash';
26
- payload: {
27
- hash: string;
28
- timestamp: number;
29
- };
30
- }
31
- export interface Issues {
32
- action: 'issues';
33
- payload: {
25
+ issues: {
34
26
  timestamp: number;
35
27
  errors: rspack.StatsError[];
36
28
  warnings: rspack.StatsError[];
37
29
  };
38
30
  }
39
- export interface Ok {
40
- action: 'ok';
41
- payload: {
42
- timestamp: number;
31
+ export type Message = {
32
+ [A in keyof Messages]: {
33
+ action: A;
34
+ payload: Messages[A];
43
35
  };
44
- }
45
- export interface Messages {
46
- ok: GetProp<Ok, 'payload'>;
47
- hash: GetProp<Hash, 'payload'>;
48
- issues: GetProp<Issues, 'payload'>;
49
- invalid: GetProp<Invalid, 'payload'>;
50
- progress: GetProp<Progress, 'payload'>;
51
- }
52
- export type Message = Invalid | Progress | Hash | Issues | Ok;
36
+ }[keyof Messages];
@@ -2,7 +2,7 @@
2
2
  * @module rspack-dev-middleware
3
3
  * @package rspack-dev-middleware
4
4
  * @license MIT
5
- * @version 0.4.0
5
+ * @version 0.4.2
6
6
  * @author nuintun <nuintun@qq.com>
7
7
  * @description A koa 2 middleware for rspack development and hot reloading.
8
8
  * @see https://github.com/nuintun/rspack-dev-middleware#readme
@@ -10,10 +10,10 @@
10
10
 
11
11
  'use strict';
12
12
 
13
- const uuid = require('uuid');
14
13
  const node_buffer = require('node:buffer');
15
14
  const rspack = require('@rspack/core');
16
15
  require('node:url');
16
+ const node_crypto = require('node:crypto');
17
17
  const node_path = require('node:path');
18
18
  const WebSocket = require('ws');
19
19
  const utils$1 = require('../utils.cjs');
@@ -72,15 +72,15 @@ class Socket {
72
72
  const compilers = utils$1.getCompilers(compiler);
73
73
  const contexts = new Map();
74
74
  for (const compiler of compilers) {
75
- const uuid$1 = uuid.v7();
75
+ const uuid = node_crypto.randomUUID();
76
76
  const context = {
77
- uuid: uuid$1,
77
+ uuid,
78
78
  stats: null,
79
79
  percent: -1,
80
80
  clients: new Set()
81
81
  };
82
- contexts.set(uuid$1, context);
83
- this.#setupOutput(compiler, uuid$1);
82
+ contexts.set(uuid, context);
83
+ this.#setupOutput(compiler, uuid);
84
84
  this.#setupHooks(compiler, context);
85
85
  this.#setupPlugins(compiler, context);
86
86
  }
@@ -116,7 +116,7 @@ class Socket {
116
116
  process.nextTick(() => {
117
117
  const { stats } = context;
118
118
  // Broadcast stats.
119
- if (stats) {
119
+ if (stats != null && context.clients.size > 0) {
120
120
  this.#broadcastStats(context.clients, stats);
121
121
  }
122
122
  });
@@ -167,7 +167,7 @@ class Socket {
167
167
  const uuid = url.searchParams.get('uuid');
168
168
  if (uuid) {
169
169
  const context = contexts.get(uuid);
170
- if (context) {
170
+ if (context != null) {
171
171
  const { stats } = context;
172
172
  context.clients.add(client);
173
173
  logger.log('client connected');
@@ -175,9 +175,8 @@ class Socket {
175
175
  context.clients.delete(client);
176
176
  logger.log('client disconnected');
177
177
  });
178
- if (stats) {
179
- const clients = new Set([client]);
180
- this.#broadcastStats(clients, stats);
178
+ if (stats != null) {
179
+ this.#broadcastStats([client], stats);
181
180
  }
182
181
  } else {
183
182
  client.close(4001, 'compiler not found');
@@ -191,21 +190,21 @@ class Socket {
191
190
  });
192
191
  }
193
192
  #broadcast(clients, action, payload) {
193
+ // Serialize once, send to all.
194
+ const message = JSON.stringify({ action, payload });
194
195
  for (const client of clients) {
195
196
  if (client.readyState === WebSocket__default.default.OPEN) {
196
- client.send(JSON.stringify({ action, payload }));
197
+ client.send(message);
197
198
  }
198
199
  }
199
200
  }
200
201
  #broadcastStats(clients, stats) {
201
- if (clients.size > 0) {
202
- const { hash, errors, warnings, builtAt: timestamp } = stats;
203
- this.#broadcast(clients, 'hash', { hash, timestamp });
204
- if (utils.hasIssues(errors) || utils.hasIssues(warnings)) {
205
- this.#broadcast(clients, 'issues', { errors, warnings, timestamp });
206
- } else {
207
- this.#broadcast(clients, 'ok', { timestamp });
208
- }
202
+ const { hash, errors, warnings, builtAt: timestamp } = stats;
203
+ this.#broadcast(clients, 'hash', { hash, timestamp });
204
+ if (utils.hasIssues(errors) || utils.hasIssues(warnings)) {
205
+ this.#broadcast(clients, 'issues', { errors, warnings, timestamp });
206
+ } else {
207
+ this.#broadcast(clients, 'ok', { timestamp });
209
208
  }
210
209
  }
211
210
  upgrade(context) {
@@ -2,7 +2,7 @@
2
2
  * @module rspack-dev-middleware
3
3
  * @package rspack-dev-middleware
4
4
  * @license MIT
5
- * @version 0.4.0
5
+ * @version 0.4.2
6
6
  * @author nuintun <nuintun@qq.com>
7
7
  * @description A koa 2 middleware for rspack development and hot reloading.
8
8
  * @see https://github.com/nuintun/rspack-dev-middleware#readme
@@ -2,7 +2,7 @@
2
2
  * @module rspack-dev-middleware
3
3
  * @package rspack-dev-middleware
4
4
  * @license MIT
5
- * @version 0.4.0
5
+ * @version 0.4.2
6
6
  * @author nuintun <nuintun@qq.com>
7
7
  * @description A koa 2 middleware for rspack development and hot reloading.
8
8
  * @see https://github.com/nuintun/rspack-dev-middleware#readme
@@ -36,14 +36,8 @@ function hasIssues(issues) {
36
36
  return Array.isArray(issues) && issues.length > 0;
37
37
  }
38
38
  function getStatsOptions(compiler) {
39
- let statsOptions = compiler.options.stats;
40
- if (utils.isString(statsOptions)) {
41
- statsOptions = { preset: statsOptions };
42
- } else if (utils.isBoolean(statsOptions)) {
43
- statsOptions = statsOptions ? { preset: 'normal' } : { preset: 'none' };
44
- }
45
39
  return {
46
- ...statsOptions,
40
+ ...utils.toStatsPreset(compiler.options.stats),
47
41
  all: false,
48
42
  hash: true,
49
43
  colors: true,
@@ -2,7 +2,7 @@
2
2
  * @module rspack-dev-middleware
3
3
  * @package rspack-dev-middleware
4
4
  * @license MIT
5
- * @version 0.4.0
5
+ * @version 0.4.2
6
6
  * @author nuintun <nuintun@qq.com>
7
7
  * @description A koa 2 middleware for rspack development and hot reloading.
8
8
  * @see https://github.com/nuintun/rspack-dev-middleware#readme
@@ -2,7 +2,7 @@
2
2
  * @module rspack-dev-middleware
3
3
  * @package rspack-dev-middleware
4
4
  * @license MIT
5
- * @version 0.4.0
5
+ * @version 0.4.2
6
6
  * @author nuintun <nuintun@qq.com>
7
7
  * @description A koa 2 middleware for rspack development and hot reloading.
8
8
  * @see https://github.com/nuintun/rspack-dev-middleware#readme
@@ -17,7 +17,7 @@ const schema = {
17
17
  type: 'object',
18
18
  properties: {
19
19
  hot: {
20
- description: 'Enable or disable HMR server.',
20
+ description: 'Configure the HMR server, or set to false to disable.',
21
21
  anyOf: [
22
22
  {
23
23
  type: 'boolean',
@@ -40,7 +40,7 @@ const schema = {
40
40
  },
41
41
  reload: {
42
42
  type: 'boolean',
43
- description: 'Control whether the full page should be reloaded when HMR failure.'
43
+ description: 'Control whether the full page should be reloaded when HMR fails.'
44
44
  },
45
45
  overlay: {
46
46
  type: 'boolean',
@@ -101,9 +101,30 @@ const schema = {
101
101
  type: 'object',
102
102
  description: 'The output file system used by the dev server.'
103
103
  },
104
+ highWaterMark: {
105
+ description: 'The size of the read stream buffer.',
106
+ anyOf: [
107
+ {
108
+ type: 'number'
109
+ },
110
+ {
111
+ instanceof: 'Function'
112
+ }
113
+ ]
114
+ },
104
115
  stats: {
105
- type: 'object',
106
- description: 'Options for the statistics output.'
116
+ description: 'Options for the statistics output.',
117
+ anyOf: [
118
+ {
119
+ type: 'boolean'
120
+ },
121
+ {
122
+ type: 'string'
123
+ },
124
+ {
125
+ type: 'object'
126
+ }
127
+ ]
107
128
  },
108
129
  writeToDisk: {
109
130
  anyOf: [
@@ -119,7 +140,7 @@ const schema = {
119
140
  },
120
141
  onCompilationDone: {
121
142
  instanceof: 'Function',
122
- description: 'Callback function when the compilation is done, providing statistics and options.'
143
+ description: 'Callback function when the compilation is done, providing stats and stats options.'
123
144
  }
124
145
  },
125
146
  additionalProperties: false
@@ -2,7 +2,7 @@
2
2
  * @module rspack-dev-middleware
3
3
  * @package rspack-dev-middleware
4
4
  * @license MIT
5
- * @version 0.4.0
5
+ * @version 0.4.2
6
6
  * @author nuintun <nuintun@qq.com>
7
7
  * @description A koa 2 middleware for rspack development and hot reloading.
8
8
  * @see https://github.com/nuintun/rspack-dev-middleware#readme
@@ -38,6 +38,16 @@ function getCompilers(compiler) {
38
38
  }
39
39
  return [compiler];
40
40
  }
41
+ function toStatsPreset(stats) {
42
+ if (stats == null) {
43
+ return { preset: 'normal' };
44
+ } else if (isString(stats)) {
45
+ return { preset: stats };
46
+ } else if (isBoolean(stats)) {
47
+ return stats ? { preset: 'normal' } : { preset: 'none' };
48
+ }
49
+ return stats;
50
+ }
41
51
  function isMultiCompiler(compiler) {
42
52
  return 'compilers' in compiler;
43
53
  }
@@ -49,3 +59,4 @@ exports.isBoolean = isBoolean;
49
59
  exports.isFunction = isFunction;
50
60
  exports.isMultiCompiler = isMultiCompiler;
51
61
  exports.isString = isString;
62
+ exports.toStatsPreset = toStatsPreset;
@@ -9,4 +9,5 @@ export declare function isBoolean(value: unknown): value is boolean;
9
9
  export declare function isFunction(value: unknown): value is Function;
10
10
  export declare function assertPublicPath(compiler: UnionCompiler): never | void;
11
11
  export declare function getCompilers(compiler: UnionCompiler): rspack.Compiler[];
12
+ export declare function toStatsPreset(stats?: rspack.StatsValue): rspack.StatsOptions;
12
13
  export declare function isMultiCompiler(compiler: UnionCompiler): compiler is rspack.MultiCompiler;
@@ -2,7 +2,7 @@
2
2
  * @module rspack-dev-middleware
3
3
  * @package rspack-dev-middleware
4
4
  * @license MIT
5
- * @version 0.4.0
5
+ * @version 0.4.2
6
6
  * @author nuintun <nuintun@qq.com>
7
7
  * @description A koa 2 middleware for rspack development and hot reloading.
8
8
  * @see https://github.com/nuintun/rspack-dev-middleware#readme
@@ -2,7 +2,7 @@
2
2
  * @module rspack-dev-middleware
3
3
  * @package rspack-dev-middleware
4
4
  * @license MIT
5
- * @version 0.4.0
5
+ * @version 0.4.2
6
6
  * @author nuintun <nuintun@qq.com>
7
7
  * @description A koa 2 middleware for rspack development and hot reloading.
8
8
  * @see https://github.com/nuintun/rspack-dev-middleware#readme
@@ -91,7 +91,7 @@ function createClient(options) {
91
91
  const ws = new WebSocket(url);
92
92
  ws.onmessage = message => {
93
93
  const parsed = parseMessage(message);
94
- if (parsed) {
94
+ if (parsed != null) {
95
95
  const { action, payload } = parsed;
96
96
  switch (action) {
97
97
  case 'invalid':
@@ -4,13 +4,9 @@
4
4
  import { Options } from './client.js';
5
5
  import { GetProp } from '../server/interface.js';
6
6
  import { Messages } from '../server/hot/Message.js';
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
- }
7
+ export type Events = {
8
+ [E in keyof Messages]: (message: Messages[E], options: Options) => void;
9
+ };
14
10
  /**
15
11
  * @function on
16
12
  * @description Add an event listener callback.
@@ -2,7 +2,7 @@
2
2
  * @module rspack-dev-middleware
3
3
  * @package rspack-dev-middleware
4
4
  * @license MIT
5
- * @version 0.4.0
5
+ * @version 0.4.2
6
6
  * @author nuintun <nuintun@qq.com>
7
7
  * @description A koa 2 middleware for rspack development and hot reloading.
8
8
  * @see https://github.com/nuintun/rspack-dev-middleware#readme
@@ -26,7 +26,7 @@ const events = {
26
26
  */
27
27
  function on(event, callback) {
28
28
  const callbacks = events[event];
29
- if (callbacks) {
29
+ if (callbacks != null) {
30
30
  callbacks.push(callback);
31
31
  }
32
32
  }
@@ -38,8 +38,8 @@ function on(event, callback) {
38
38
  */
39
39
  function off(event, callback) {
40
40
  const callbacks = events[event];
41
- if (callbacks) {
42
- if (callback) {
41
+ if (callbacks != null) {
42
+ if (callback != null) {
43
43
  const index = callbacks.indexOf(callback);
44
44
  if (index >= 0) {
45
45
  callbacks.splice(index, 1);
@@ -51,7 +51,7 @@ function off(event, callback) {
51
51
  }
52
52
  function emit(event, message, options) {
53
53
  const callbacks = events[event];
54
- if (callbacks && callbacks.length > 0) {
54
+ if (callbacks != null && callbacks.length > 0) {
55
55
  for (const callback of callbacks) {
56
56
  callback(message, options);
57
57
  }
@@ -2,7 +2,7 @@
2
2
  * @module rspack-dev-middleware
3
3
  * @package rspack-dev-middleware
4
4
  * @license MIT
5
- * @version 0.4.0
5
+ * @version 0.4.2
6
6
  * @author nuintun <nuintun@qq.com>
7
7
  * @description A koa 2 middleware for rspack development and hot reloading.
8
8
  * @see https://github.com/nuintun/rspack-dev-middleware#readme
@@ -2,7 +2,7 @@
2
2
  * @module rspack-dev-middleware
3
3
  * @package rspack-dev-middleware
4
4
  * @license MIT
5
- * @version 0.4.0
5
+ * @version 0.4.2
6
6
  * @author nuintun <nuintun@qq.com>
7
7
  * @description A koa 2 middleware for rspack development and hot reloading.
8
8
  * @see https://github.com/nuintun/rspack-dev-middleware#readme
@@ -18,7 +18,7 @@ const isTLS = protocol => {
18
18
  };
19
19
  const getCurrentScript = () => {
20
20
  const { currentScript } = document;
21
- if (currentScript) {
21
+ if (currentScript != null) {
22
22
  return currentScript;
23
23
  }
24
24
  };
@@ -35,7 +35,7 @@ const getProtocol = (params, protocol) => {
35
35
  const getOrigin = params => {
36
36
  const { location } = self;
37
37
  const script = getCurrentScript();
38
- if (script) {
38
+ if (script != null) {
39
39
  const url = new URL(script.src, location.href);
40
40
  const protocol = getProtocol(params, url.protocol);
41
41
  return `${protocol}//${url.host}`;
@@ -2,13 +2,13 @@
2
2
  * @module rspack-dev-middleware
3
3
  * @package rspack-dev-middleware
4
4
  * @license MIT
5
- * @version 0.4.0
5
+ * @version 0.4.2
6
6
  * @author nuintun <nuintun@qq.com>
7
7
  * @description A koa 2 middleware for rspack development and hot reloading.
8
8
  * @see https://github.com/nuintun/rspack-dev-middleware#readme
9
9
  */
10
10
 
11
- import { getRootElement, insertCSSString, appendDOMString, ansiToHTML } from './utils.js';
11
+ import { getRootElement, appendStyleSheet, appendMarkup, ansiToHTML, escapeHTML } from './utils.js';
12
12
 
13
13
  /**
14
14
  * @module Overlay
@@ -184,8 +184,8 @@ class Overlay {
184
184
  #warningsTitle;
185
185
  constructor(name) {
186
186
  const root = getRootElement(OVERLAY);
187
- insertCSSString(CSS, root);
188
- const [dialog] = appendDOMString('text/html', HTML, root);
187
+ appendStyleSheet(CSS, root);
188
+ const dialog = appendMarkup('text/html', HTML, root);
189
189
  this.#dialog = dialog;
190
190
  this.#name = dialog.querySelector(`.${OVERLAY}-name`);
191
191
  this.#close = dialog.querySelector(`.${OVERLAY}-close`);
@@ -211,7 +211,7 @@ class Overlay {
211
211
  problemTitle.innerText = `${count} ${name}(s)`;
212
212
  for (const { moduleName, chunkName, message } of issues) {
213
213
  const details = ansiToHTML(message);
214
- const filename = moduleName || chunkName || 'unknown';
214
+ const filename = escapeHTML(moduleName || chunkName || 'unknown');
215
215
  html += `<section><em>${name}</em> in ${filename}<pre>${details}</pre></section>`;
216
216
  }
217
217
  problemList.innerHTML = html;