@rspack/dev-server 1.0.7 → 1.0.9

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.
package/client/index.js CHANGED
@@ -1,64 +1,61 @@
1
+ // @ts-nocheck
1
2
  function ownKeys(object, enumerableOnly) {
2
- var keys = Object.keys(object);
3
- if (Object.getOwnPropertySymbols) {
4
- var symbols = Object.getOwnPropertySymbols(object);
5
- enumerableOnly &&
6
- (symbols = symbols.filter(function (sym) {
7
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
8
- })),
9
- keys.push.apply(keys, symbols);
10
- }
11
- return keys;
3
+ var keys = Object.keys(object);
4
+ if (Object.getOwnPropertySymbols) {
5
+ var symbols = Object.getOwnPropertySymbols(object);
6
+ enumerableOnly &&
7
+ (symbols = symbols.filter(function (sym) {
8
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
9
+ })),
10
+ keys.push.apply(keys, symbols);
11
+ }
12
+ return keys;
12
13
  }
13
14
  function _objectSpread(target) {
14
- for (var i = 1; i < arguments.length; i++) {
15
- var source = null != arguments[i] ? arguments[i] : {};
16
- i % 2
17
- ? ownKeys(Object(source), !0).forEach(function (key) {
18
- _defineProperty(target, key, source[key]);
19
- })
20
- : Object.getOwnPropertyDescriptors
21
- ? Object.defineProperties(
22
- target,
23
- Object.getOwnPropertyDescriptors(source)
24
- )
25
- : ownKeys(Object(source)).forEach(function (key) {
26
- Object.defineProperty(
27
- target,
28
- key,
29
- Object.getOwnPropertyDescriptor(source, key)
30
- );
31
- });
32
- }
33
- return target;
15
+ for (var i = 1; i < arguments.length; i++) {
16
+ var source = null != arguments[i] ? arguments[i] : {};
17
+ i % 2
18
+ ? ownKeys(Object(source), !0).forEach(function (key) {
19
+ _defineProperty(target, key, source[key]);
20
+ })
21
+ : Object.getOwnPropertyDescriptors
22
+ ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source))
23
+ : ownKeys(Object(source)).forEach(function (key) {
24
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
25
+ });
26
+ }
27
+ return target;
34
28
  }
35
29
  function _defineProperty(obj, key, value) {
36
- key = _toPropertyKey(key);
37
- if (key in obj) {
38
- Object.defineProperty(obj, key, {
39
- value: value,
40
- enumerable: true,
41
- configurable: true,
42
- writable: true
43
- });
44
- } else {
45
- obj[key] = value;
46
- }
47
- return obj;
30
+ key = _toPropertyKey(key);
31
+ if (key in obj) {
32
+ Object.defineProperty(obj, key, {
33
+ value: value,
34
+ enumerable: true,
35
+ configurable: true,
36
+ writable: true
37
+ });
38
+ }
39
+ else {
40
+ obj[key] = value;
41
+ }
42
+ return obj;
48
43
  }
49
44
  function _toPropertyKey(arg) {
50
- var key = _toPrimitive(arg, "string");
51
- return typeof key === "symbol" ? key : String(key);
45
+ var key = _toPrimitive(arg, "string");
46
+ return typeof key === "symbol" ? key : String(key);
52
47
  }
53
48
  function _toPrimitive(input, hint) {
54
- if (typeof input !== "object" || input === null) return input;
55
- var prim = input[Symbol.toPrimitive];
56
- if (prim !== undefined) {
57
- var res = prim.call(input, hint || "default");
58
- if (typeof res !== "object") return res;
59
- throw new TypeError("@@toPrimitive must return a primitive value.");
60
- }
61
- return (hint === "string" ? String : Number)(input);
49
+ if (typeof input !== "object" || input === null)
50
+ return input;
51
+ var prim = input[Symbol.toPrimitive];
52
+ if (prim !== undefined) {
53
+ var res = prim.call(input, hint || "default");
54
+ if (typeof res !== "object")
55
+ return res;
56
+ throw new TypeError("@@toPrimitive must return a primitive value.");
57
+ }
58
+ return (hint === "string" ? String : Number)(input);
62
59
  }
63
60
  /* global __resourceQuery, __webpack_hash__ */
64
61
  /// <reference types="webpack/module" />
@@ -66,19 +63,11 @@ import webpackHotLog from "@rspack/core/hot/log.js";
66
63
  import stripAnsi from "webpack-dev-server/client/utils/stripAnsi.js";
67
64
  import parseURL from "webpack-dev-server/client/utils/parseURL.js";
68
65
  import socket from "webpack-dev-server/client/socket.js";
69
- import {
70
- formatProblem,
71
- createOverlay
72
- } from "webpack-dev-server/client/overlay.js";
73
- import {
74
- log,
75
- logEnabledFeatures,
76
- setLogLevel
77
- } from "webpack-dev-server/client/utils/log.js";
66
+ import { formatProblem, createOverlay } from "webpack-dev-server/client/overlay.js";
67
+ import { log, logEnabledFeatures, setLogLevel } from "webpack-dev-server/client/utils/log.js";
78
68
  import sendMessage from "webpack-dev-server/client/utils/sendMessage.js";
79
69
  import reloadApp from "./utils/reloadApp.js";
80
70
  import createSocketURL from "webpack-dev-server/client/utils/createSocketURL.js";
81
-
82
71
  /**
83
72
  * @typedef {Object} Options
84
73
  * @property {boolean} hot
@@ -88,335 +77,291 @@ import createSocketURL from "webpack-dev-server/client/utils/createSocketURL.js"
88
77
  * @property {string} [logging]
89
78
  * @property {number} [reconnect]
90
79
  */
91
-
92
80
  /**
93
81
  * @typedef {Object} Status
94
82
  * @property {boolean} isUnloading
95
83
  * @property {string} currentHash
96
84
  * @property {string} [previousHash]
97
85
  */
98
-
99
86
  /**
100
87
  * @type {Status}
101
88
  */
102
89
  var status = {
103
- isUnloading: false,
104
- // TODO Workaround for webpack v4, `__webpack_hash__` is not replaced without HotModuleReplacement
105
- // eslint-disable-next-line camelcase
106
- currentHash: typeof __webpack_hash__ !== "undefined" ? __webpack_hash__ : ""
90
+ isUnloading: false,
91
+ // TODO Workaround for webpack v4, `__webpack_hash__` is not replaced without HotModuleReplacement
92
+ // eslint-disable-next-line camelcase
93
+ currentHash: typeof __webpack_hash__ !== "undefined" ? __webpack_hash__ : ""
107
94
  };
108
-
109
95
  var decodeOverlayOptions = function decodeOverlayOptions(overlayOptions) {
110
- if (typeof overlayOptions === "object") {
111
- ["warnings", "errors", "runtimeErrors"].forEach(function (property) {
112
- if (typeof overlayOptions[property] === "string") {
113
- var overlayFilterFunctionString = decodeURIComponent(
114
- overlayOptions[property]
115
- );
116
-
117
- // eslint-disable-next-line no-new-func
118
- var overlayFilterFunction = new Function(
119
- "message",
120
- "var callback = ".concat(
121
- overlayFilterFunctionString,
122
- "\n return callback(message)"
123
- )
124
- );
125
- overlayOptions[property] = overlayFilterFunction;
126
- }
127
- });
128
- }
96
+ if (typeof overlayOptions === "object") {
97
+ ["warnings", "errors", "runtimeErrors"].forEach(function (property) {
98
+ if (typeof overlayOptions[property] === "string") {
99
+ var overlayFilterFunctionString = decodeURIComponent(overlayOptions[property]);
100
+ // eslint-disable-next-line no-new-func
101
+ var overlayFilterFunction = new Function("message", "var callback = ".concat(overlayFilterFunctionString, "\n return callback(message)"));
102
+ overlayOptions[property] = overlayFilterFunction;
103
+ }
104
+ });
105
+ }
129
106
  };
130
-
131
107
  /** @type {Options} */
132
108
  var options = {
133
- hot: false,
134
- liveReload: false,
135
- progress: false,
136
- overlay: false
109
+ hot: false,
110
+ liveReload: false,
111
+ progress: false,
112
+ overlay: false
137
113
  };
138
114
  var parsedResourceQuery = parseURL(__resourceQuery);
139
115
  var enabledFeatures = {
140
- "Hot Module Replacement": false,
141
- "Live Reloading": false,
142
- Progress: false,
143
- Overlay: false
116
+ "Hot Module Replacement": false,
117
+ "Live Reloading": false,
118
+ Progress: false,
119
+ Overlay: false
144
120
  };
145
121
  if (parsedResourceQuery.hot === "true") {
146
- options.hot = true;
147
- enabledFeatures["Hot Module Replacement"] = true;
122
+ options.hot = true;
123
+ enabledFeatures["Hot Module Replacement"] = true;
148
124
  }
149
125
  if (parsedResourceQuery["live-reload"] === "true") {
150
- options.liveReload = true;
151
- enabledFeatures["Live Reloading"] = true;
126
+ options.liveReload = true;
127
+ enabledFeatures["Live Reloading"] = true;
152
128
  }
153
129
  if (parsedResourceQuery.progress === "true") {
154
- options.progress = true;
155
- enabledFeatures.Progress = true;
130
+ options.progress = true;
131
+ enabledFeatures.Progress = true;
156
132
  }
157
-
158
133
  if (parsedResourceQuery.overlay) {
159
- try {
160
- options.overlay = JSON.parse(parsedResourceQuery.overlay);
161
- } catch (e) {
162
- log.error("Error parsing overlay options from resource query:", e);
163
- }
164
-
165
- // Fill in default "true" params for partially-specified objects.
166
- if (typeof options.overlay === "object") {
167
- options.overlay = _objectSpread(
168
- {
169
- errors: true,
170
- warnings: true,
171
- runtimeErrors: true
172
- },
173
- options.overlay
174
- );
175
- decodeOverlayOptions(options.overlay);
176
- }
177
- enabledFeatures.Overlay = true;
134
+ try {
135
+ options.overlay = JSON.parse(parsedResourceQuery.overlay);
136
+ }
137
+ catch (e) {
138
+ log.error("Error parsing overlay options from resource query:", e);
139
+ }
140
+ // Fill in default "true" params for partially-specified objects.
141
+ if (typeof options.overlay === "object") {
142
+ options.overlay = _objectSpread({
143
+ errors: true,
144
+ warnings: true,
145
+ runtimeErrors: true
146
+ }, options.overlay);
147
+ decodeOverlayOptions(options.overlay);
148
+ }
149
+ enabledFeatures.Overlay = true;
178
150
  }
179
151
  if (parsedResourceQuery.logging) {
180
- options.logging = parsedResourceQuery.logging;
152
+ options.logging = parsedResourceQuery.logging;
181
153
  }
182
154
  if (typeof parsedResourceQuery.reconnect !== "undefined") {
183
- options.reconnect = Number(parsedResourceQuery.reconnect);
155
+ options.reconnect = Number(parsedResourceQuery.reconnect);
184
156
  }
185
-
186
157
  /**
187
158
  * @param {string} level
188
159
  */
189
160
  function setAllLogLevel(level) {
190
- // This is needed because the HMR logger operate separately from dev server logger
191
- webpackHotLog.setLogLevel(
192
- level === "verbose" || level === "log" ? "info" : level
193
- );
194
- setLogLevel(level);
161
+ // This is needed because the HMR logger operate separately from dev server logger
162
+ webpackHotLog.setLogLevel(level === "verbose" || level === "log" ? "info" : level);
163
+ setLogLevel(level);
195
164
  }
196
165
  if (options.logging) {
197
- setAllLogLevel(options.logging);
166
+ setAllLogLevel(options.logging);
198
167
  }
199
168
  logEnabledFeatures(enabledFeatures);
200
169
  self.addEventListener("beforeunload", function () {
201
- status.isUnloading = true;
170
+ status.isUnloading = true;
202
171
  });
203
- var overlay =
204
- typeof window !== "undefined"
205
- ? createOverlay(
206
- typeof options.overlay === "object"
207
- ? {
208
- trustedTypesPolicyName: options.overlay.trustedTypesPolicyName,
209
- catchRuntimeError: options.overlay.runtimeErrors
210
- }
211
- : {
212
- trustedTypesPolicyName: false,
213
- catchRuntimeError: options.overlay
214
- }
215
- )
216
- : {
217
- send: function send() {}
218
- };
172
+ var overlay = typeof window !== "undefined"
173
+ ? createOverlay(typeof options.overlay === "object"
174
+ ? {
175
+ trustedTypesPolicyName: options.overlay.trustedTypesPolicyName,
176
+ catchRuntimeError: options.overlay.runtimeErrors
177
+ }
178
+ : {
179
+ trustedTypesPolicyName: false,
180
+ catchRuntimeError: options.overlay
181
+ })
182
+ : {
183
+ send: function send() { }
184
+ };
219
185
  /* Rspack dev server runtime client */
220
186
  var onSocketMessage = {
221
- hot: function hot() {
222
- if (parsedResourceQuery.hot === "false") {
223
- return;
224
- }
225
- options.hot = true;
226
- },
227
- liveReload: function liveReload() {
228
- if (parsedResourceQuery["live-reload"] === "false") {
229
- return;
230
- }
231
- options.liveReload = true;
232
- },
233
- invalid: function invalid() {
234
- log.info("App updated. Recompiling...");
235
-
236
- // Fixes #1042. overlay doesn't clear if errors are fixed but warnings remain.
237
- if (options.overlay) {
238
- overlay.send({
239
- type: "DISMISS"
240
- });
241
- }
242
- sendMessage("Invalid");
243
- },
244
- /**
245
- * @param {string} hash
246
- */
247
- hash: function hash(_hash) {
248
- status.previousHash = status.currentHash;
249
- status.currentHash = _hash;
250
- },
251
- logging: setAllLogLevel,
252
- /**
253
- * @param {boolean} value
254
- */
255
- overlay: function overlay(value) {
256
- if (typeof document === "undefined") {
257
- return;
258
- }
259
- options.overlay = value;
260
- decodeOverlayOptions(options.overlay);
261
- },
262
- /**
263
- * @param {number} value
264
- */
265
- reconnect: function reconnect(value) {
266
- if (parsedResourceQuery.reconnect === "false") {
267
- return;
268
- }
269
- options.reconnect = value;
270
- },
271
- /**
272
- * @param {boolean} value
273
- */
274
- progress: function progress(value) {
275
- options.progress = value;
276
- },
277
- /**
278
- * @param {{ pluginName?: string, percent: number, msg: string }} data
279
- */
280
- "progress-update": function progressUpdate(data) {
281
- if (options.progress) {
282
- log.info(
283
- ""
284
- .concat(data.pluginName ? "[".concat(data.pluginName, "] ") : "")
285
- .concat(data.percent, "% - ")
286
- .concat(data.msg, ".")
287
- );
288
- }
289
- sendMessage("Progress", data);
290
- },
291
- "still-ok": function stillOk() {
292
- log.info("Nothing changed.");
293
- if (options.overlay) {
294
- overlay.send({
295
- type: "DISMISS"
296
- });
297
- }
298
- sendMessage("StillOk");
299
- },
300
- ok: function ok() {
301
- sendMessage("Ok");
302
- if (options.overlay) {
303
- overlay.send({
304
- type: "DISMISS"
305
- });
306
- }
307
- reloadApp(options, status);
308
- },
309
- // TODO: remove in v5 in favor of 'static-changed'
310
- /**
311
- * @param {string} file
312
- */
313
- "content-changed": function contentChanged(file) {
314
- log.info(
315
- "".concat(
316
- file ? '"'.concat(file, '"') : "Content",
317
- " from static directory was changed. Reloading..."
318
- )
319
- );
320
- self.location.reload();
321
- },
322
- /**
323
- * @param {string} file
324
- */
325
- "static-changed": function staticChanged(file) {
326
- log.info(
327
- "".concat(
328
- file ? '"'.concat(file, '"') : "Content",
329
- " from static directory was changed. Reloading..."
330
- )
331
- );
332
- self.location.reload();
333
- },
334
- /**
335
- * @param {Error[]} warnings
336
- * @param {any} params
337
- */
338
- warnings: function warnings(_warnings, params) {
339
- log.warn("Warnings while compiling.");
340
- var printableWarnings = _warnings.map(function (error) {
341
- var _formatProblem = formatProblem("warning", error),
342
- header = _formatProblem.header,
343
- body = _formatProblem.body;
344
- return "".concat(header, "\n").concat(stripAnsi(body));
345
- });
346
- sendMessage("Warnings", printableWarnings);
347
- for (var i = 0; i < printableWarnings.length; i++) {
348
- log.warn(printableWarnings[i]);
349
- }
350
- var overlayWarningsSetting =
351
- typeof options.overlay === "boolean"
352
- ? options.overlay
353
- : options.overlay && options.overlay.warnings;
354
- if (overlayWarningsSetting) {
355
- var warningsToDisplay =
356
- typeof overlayWarningsSetting === "function"
357
- ? _warnings.filter(overlayWarningsSetting)
358
- : _warnings;
359
- if (warningsToDisplay.length) {
360
- overlay.send({
361
- type: "BUILD_ERROR",
362
- level: "warning",
363
- messages: _warnings
364
- });
365
- }
366
- }
367
- if (params && params.preventReloading) {
368
- return;
369
- }
370
- reloadApp(options, status);
371
- },
372
- /**
373
- * @param {Error[]} errors
374
- */
375
- errors: function errors(_errors) {
376
- log.error("Errors while compiling. Reload prevented.");
377
- var printableErrors = _errors.map(function (error) {
378
- var _formatProblem2 = formatProblem("error", error),
379
- header = _formatProblem2.header,
380
- body = _formatProblem2.body;
381
- return "".concat(header, "\n").concat(stripAnsi(body));
382
- });
383
- sendMessage("Errors", printableErrors);
384
- for (var i = 0; i < printableErrors.length; i++) {
385
- log.error(printableErrors[i]);
386
- }
387
- var overlayErrorsSettings =
388
- typeof options.overlay === "boolean"
389
- ? options.overlay
390
- : options.overlay && options.overlay.errors;
391
- if (overlayErrorsSettings) {
392
- var errorsToDisplay =
393
- typeof overlayErrorsSettings === "function"
394
- ? _errors.filter(overlayErrorsSettings)
395
- : _errors;
396
- if (errorsToDisplay.length) {
397
- overlay.send({
398
- type: "BUILD_ERROR",
399
- level: "error",
400
- messages: _errors
401
- });
402
- }
403
- }
404
- },
405
- /**
406
- * @param {Error} error
407
- */
408
- error: function error(_error) {
409
- log.error(_error);
410
- },
411
- close: function close() {
412
- log.info("Disconnected!");
413
- if (options.overlay) {
414
- overlay.send({
415
- type: "DISMISS"
416
- });
417
- }
418
- sendMessage("Close");
419
- }
187
+ hot: function hot() {
188
+ if (parsedResourceQuery.hot === "false") {
189
+ return;
190
+ }
191
+ options.hot = true;
192
+ },
193
+ liveReload: function liveReload() {
194
+ if (parsedResourceQuery["live-reload"] === "false") {
195
+ return;
196
+ }
197
+ options.liveReload = true;
198
+ },
199
+ invalid: function invalid() {
200
+ log.info("App updated. Recompiling...");
201
+ // Fixes #1042. overlay doesn't clear if errors are fixed but warnings remain.
202
+ if (options.overlay) {
203
+ overlay.send({
204
+ type: "DISMISS"
205
+ });
206
+ }
207
+ sendMessage("Invalid");
208
+ },
209
+ /**
210
+ * @param {string} hash
211
+ */
212
+ hash: function hash(_hash) {
213
+ status.previousHash = status.currentHash;
214
+ status.currentHash = _hash;
215
+ },
216
+ logging: setAllLogLevel,
217
+ /**
218
+ * @param {boolean} value
219
+ */
220
+ overlay: function overlay(value) {
221
+ if (typeof document === "undefined") {
222
+ return;
223
+ }
224
+ options.overlay = value;
225
+ decodeOverlayOptions(options.overlay);
226
+ },
227
+ /**
228
+ * @param {number} value
229
+ */
230
+ reconnect: function reconnect(value) {
231
+ if (parsedResourceQuery.reconnect === "false") {
232
+ return;
233
+ }
234
+ options.reconnect = value;
235
+ },
236
+ /**
237
+ * @param {boolean} value
238
+ */
239
+ progress: function progress(value) {
240
+ options.progress = value;
241
+ },
242
+ /**
243
+ * @param {{ pluginName?: string, percent: number, msg: string }} data
244
+ */
245
+ "progress-update": function progressUpdate(data) {
246
+ if (options.progress) {
247
+ log.info(""
248
+ .concat(data.pluginName ? "[".concat(data.pluginName, "] ") : "")
249
+ .concat(data.percent, "% - ")
250
+ .concat(data.msg, "."));
251
+ }
252
+ sendMessage("Progress", data);
253
+ },
254
+ "still-ok": function stillOk() {
255
+ log.info("Nothing changed.");
256
+ if (options.overlay) {
257
+ overlay.send({
258
+ type: "DISMISS"
259
+ });
260
+ }
261
+ sendMessage("StillOk");
262
+ },
263
+ ok: function ok() {
264
+ sendMessage("Ok");
265
+ if (options.overlay) {
266
+ overlay.send({
267
+ type: "DISMISS"
268
+ });
269
+ }
270
+ reloadApp(options, status);
271
+ },
272
+ // TODO: remove in v5 in favor of 'static-changed'
273
+ /**
274
+ * @param {string} file
275
+ */
276
+ "content-changed": function contentChanged(file) {
277
+ log.info("".concat(file ? '"'.concat(file, '"') : "Content", " from static directory was changed. Reloading..."));
278
+ self.location.reload();
279
+ },
280
+ /**
281
+ * @param {string} file
282
+ */
283
+ "static-changed": function staticChanged(file) {
284
+ log.info("".concat(file ? '"'.concat(file, '"') : "Content", " from static directory was changed. Reloading..."));
285
+ self.location.reload();
286
+ },
287
+ /**
288
+ * @param {Error[]} warnings
289
+ * @param {any} params
290
+ */
291
+ warnings: function warnings(_warnings, params) {
292
+ log.warn("Warnings while compiling.");
293
+ var printableWarnings = _warnings.map(function (error) {
294
+ var _formatProblem = formatProblem("warning", error), header = _formatProblem.header, body = _formatProblem.body;
295
+ return "".concat(header, "\n").concat(stripAnsi(body));
296
+ });
297
+ sendMessage("Warnings", printableWarnings);
298
+ for (var i = 0; i < printableWarnings.length; i++) {
299
+ log.warn(printableWarnings[i]);
300
+ }
301
+ var overlayWarningsSetting = typeof options.overlay === "boolean"
302
+ ? options.overlay
303
+ : options.overlay && options.overlay.warnings;
304
+ if (overlayWarningsSetting) {
305
+ var warningsToDisplay = typeof overlayWarningsSetting === "function"
306
+ ? _warnings.filter(overlayWarningsSetting)
307
+ : _warnings;
308
+ if (warningsToDisplay.length) {
309
+ overlay.send({
310
+ type: "BUILD_ERROR",
311
+ level: "warning",
312
+ messages: _warnings
313
+ });
314
+ }
315
+ }
316
+ if (params && params.preventReloading) {
317
+ return;
318
+ }
319
+ reloadApp(options, status);
320
+ },
321
+ /**
322
+ * @param {Error[]} errors
323
+ */
324
+ errors: function errors(_errors) {
325
+ log.error("Errors while compiling. Reload prevented.");
326
+ var printableErrors = _errors.map(function (error) {
327
+ var _formatProblem2 = formatProblem("error", error), header = _formatProblem2.header, body = _formatProblem2.body;
328
+ return "".concat(header, "\n").concat(stripAnsi(body));
329
+ });
330
+ sendMessage("Errors", printableErrors);
331
+ for (var i = 0; i < printableErrors.length; i++) {
332
+ log.error(printableErrors[i]);
333
+ }
334
+ var overlayErrorsSettings = typeof options.overlay === "boolean"
335
+ ? options.overlay
336
+ : options.overlay && options.overlay.errors;
337
+ if (overlayErrorsSettings) {
338
+ var errorsToDisplay = typeof overlayErrorsSettings === "function"
339
+ ? _errors.filter(overlayErrorsSettings)
340
+ : _errors;
341
+ if (errorsToDisplay.length) {
342
+ overlay.send({
343
+ type: "BUILD_ERROR",
344
+ level: "error",
345
+ messages: _errors
346
+ });
347
+ }
348
+ }
349
+ },
350
+ /**
351
+ * @param {Error} error
352
+ */
353
+ error: function error(_error) {
354
+ log.error(_error);
355
+ },
356
+ close: function close() {
357
+ log.info("Disconnected!");
358
+ if (options.overlay) {
359
+ overlay.send({
360
+ type: "DISMISS"
361
+ });
362
+ }
363
+ sendMessage("Close");
364
+ }
420
365
  };
421
366
  var socketURL = createSocketURL(parsedResourceQuery);
422
367
  socket(socketURL, onSocketMessage, options.reconnect);
@@ -1,8 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
1
  // Reference to https://github.com/sindresorhus/ansi-regex
4
- const _regANSI = /(?:(?:\u001b\[)|\u009b)(?:(?:[0-9]{1,3})?(?:(?:;[0-9]{0,3})*)?[A-M|f-m])|\u001b[A-M]/;
5
- const _defColors = {
2
+ var _regANSI = /(?:(?:\u001b\[)|\u009b)(?:(?:[0-9]{1,3})?(?:(?:;[0-9]{0,3})*)?[A-M|f-m])|\u001b[A-M]/;
3
+ var _defColors = {
6
4
  reset: ["fff", "000"],
7
5
  black: "000",
8
6
  red: "ff0000",
@@ -14,7 +12,7 @@ const _defColors = {
14
12
  lightgrey: "f0f0f0",
15
13
  darkgrey: "888"
16
14
  };
17
- const _styles = {
15
+ var _styles = {
18
16
  30: "black",
19
17
  31: "red",
20
18
  32: "green",
@@ -24,54 +22,54 @@ const _styles = {
24
22
  36: "cyan",
25
23
  37: "lightgrey"
26
24
  };
27
- const _colorMode = {
25
+ var _colorMode = {
28
26
  2: "rgb"
29
27
  };
30
- const _openTags = {
28
+ var _openTags = {
31
29
  1: "font-weight:bold",
32
30
  2: "opacity:0.5",
33
31
  3: "<i>",
34
32
  4: "<u>",
35
33
  8: "display:none",
36
34
  9: "<del>",
37
- 38: (match) => {
35
+ 38: function (match) {
38
36
  // color
39
- const mode = _colorMode[match[0]];
37
+ var mode = _colorMode[match[0]];
40
38
  if (mode === "rgb") {
41
- const r = match[1];
42
- const g = match[2];
43
- const b = match[3];
39
+ var r = match[1];
40
+ var g = match[2];
41
+ var b = match[3];
44
42
  match.advance(4);
45
- return `color: rgb(${r},${g},${b})`;
43
+ return "color: rgb(".concat(r, ",").concat(g, ",").concat(b, ")");
46
44
  }
47
45
  },
48
- 48: (match) => {
46
+ 48: function (match) {
49
47
  // background color
50
- const mode = _colorMode[match[0]];
48
+ var mode = _colorMode[match[0]];
51
49
  if (mode === "rgb") {
52
- const r = match[1];
53
- const g = match[2];
54
- const b = match[3];
50
+ var r = match[1];
51
+ var g = match[2];
52
+ var b = match[3];
55
53
  match.advance(4);
56
- return `background-color: rgb(${r},${g},${b})`;
54
+ return "background-color: rgb(".concat(r, ",").concat(g, ",").concat(b, ")");
57
55
  }
58
56
  }
59
57
  };
60
- const _openTagToCloseTag = {
58
+ var _openTagToCloseTag = {
61
59
  3: "23",
62
60
  4: "24",
63
61
  9: "29"
64
62
  };
65
- const _closeTags = {
66
- 0: ansiCodes => {
63
+ var _closeTags = {
64
+ 0: function (ansiCodes) {
67
65
  if (!ansiCodes)
68
66
  return "</span>";
69
67
  if (!ansiCodes.length)
70
68
  return "";
71
- let code;
72
- let ret = "";
69
+ var code;
70
+ var ret = "";
73
71
  while ((code = ansiCodes.pop())) {
74
- const closeTag = _openTagToCloseTag[code];
72
+ var closeTag = _openTagToCloseTag[code];
75
73
  if (closeTag) {
76
74
  ret += _closeTags[closeTag];
77
75
  continue;
@@ -84,7 +82,8 @@ const _closeTags = {
84
82
  24: "</u>",
85
83
  29: "</del>" // reset delete
86
84
  };
87
- for (const n of [21, 22, 27, 28, 39, 49]) {
85
+ for (var _i = 0, _a = [21, 22, 27, 28, 39, 49]; _i < _a.length; _i++) {
86
+ var n = _a[_i];
88
87
  _closeTags[n] = "</span>";
89
88
  }
90
89
  /**
@@ -101,37 +100,38 @@ function normalizeSeq(seq) {
101
100
  /**
102
101
  * Converts text with ANSI color codes to HTML markup.
103
102
  */
104
- function ansiHTML(text) {
103
+ export default function ansiHTML(text) {
105
104
  // Returns the text if the string has no ANSI escape code.
106
105
  if (!_regANSI.test(text)) {
107
106
  return text;
108
107
  }
109
108
  // Cache opened sequence.
110
- const ansiCodes = [];
109
+ var ansiCodes = [];
111
110
  // Replace with markup.
112
111
  //@ts-ignore TS1487 error
113
- let ret = text.replace(/\033\[(?:[0-9]{1,3})?(?:(?:;[0-9]{0,3})*)?m/g, m => {
114
- const match = m.match(/(;?\d+)/g)?.map(normalizeSeq);
112
+ var ret = text.replace(/\033\[(?:[0-9]{1,3})?(?:(?:;[0-9]{0,3})*)?m/g, function (m) {
113
+ var _a;
114
+ var match = (_a = m.match(/(;?\d+)/g)) === null || _a === void 0 ? void 0 : _a.map(normalizeSeq);
115
115
  Object.defineProperty(match, "advance", {
116
116
  value: function (count) {
117
117
  this.splice(0, count);
118
118
  }
119
119
  });
120
- let rep = "";
121
- let seq;
120
+ var rep = "";
121
+ var seq;
122
122
  while ((seq = match[0])) {
123
123
  match.advance(1);
124
124
  rep += applySeq(seq);
125
125
  }
126
126
  return rep;
127
127
  function applySeq(seq) {
128
- let other = _openTags[seq];
128
+ var other = _openTags[seq];
129
129
  if (other &&
130
130
  (other = typeof other === "function" ? other(match) : other)) {
131
131
  // If reset signal is encountered, we have to reset everything.
132
- let ret = "";
132
+ var ret_1 = "";
133
133
  if (seq === "0") {
134
- ret += _closeTags[seq](ansiCodes);
134
+ ret_1 += _closeTags[seq](ansiCodes);
135
135
  }
136
136
  // If current sequence has been opened, close it.
137
137
  if (ansiCodes.indexOf(seq) !== -1) {
@@ -140,9 +140,9 @@ function ansiHTML(text) {
140
140
  }
141
141
  // Open tag.
142
142
  ansiCodes.push(seq);
143
- return ret + (other[0] === "<" ? other : `<span style="${other};">`);
143
+ return ret_1 + (other[0] === "<" ? other : "<span style=\"".concat(other, ";\">"));
144
144
  }
145
- const ct = _closeTags[seq];
145
+ var ct = _closeTags[seq];
146
146
  if (typeof ct === "function") {
147
147
  return ct(ansiCodes);
148
148
  }
@@ -155,22 +155,21 @@ function ansiHTML(text) {
155
155
  }
156
156
  });
157
157
  // Make sure tags are closed.
158
- const l = ansiCodes.length;
158
+ var l = ansiCodes.length;
159
159
  l > 0 && (ret += Array(l + 1).join("</span>"));
160
160
  return ret;
161
161
  }
162
- exports.default = ansiHTML;
163
162
  /**
164
163
  * Customize colors.
165
164
  * @param {Object} colors reference to _defColors
166
165
  */
167
- ansiHTML.setColors = (colors) => {
166
+ ansiHTML.setColors = function (colors) {
168
167
  if (typeof colors !== "object") {
169
168
  throw new Error("`colors` parameter must be an Object.");
170
169
  }
171
- const _finalColors = {};
172
- for (const key in _defColors) {
173
- let hex = colors.hasOwnProperty(key) ? colors[key] : null;
170
+ var _finalColors = {};
171
+ for (var key in _defColors) {
172
+ var hex = colors.hasOwnProperty(key) ? colors[key] : null;
174
173
  if (!hex) {
175
174
  _finalColors[key] = _defColors[key];
176
175
  continue;
@@ -181,10 +180,10 @@ ansiHTML.setColors = (colors) => {
181
180
  }
182
181
  if (!Array.isArray(hex) ||
183
182
  hex.length === 0 ||
184
- hex.some(h => typeof h !== "string")) {
185
- throw new Error(`The value of \`${key}\` property must be an Array and each item could only be a hex string, e.g.: FF0000`);
183
+ hex.some(function (h) { return typeof h !== "string"; })) {
184
+ throw new Error("The value of `".concat(key, "` property must be an Array and each item could only be a hex string, e.g.: FF0000"));
186
185
  }
187
- const defHexColor = _defColors[key];
186
+ var defHexColor = _defColors[key];
188
187
  if (!hex[0]) {
189
188
  hex[0] = defHexColor[0];
190
189
  }
@@ -195,7 +194,7 @@ ansiHTML.setColors = (colors) => {
195
194
  hex = hex.slice(0, 2);
196
195
  }
197
196
  else if (typeof hex !== "string") {
198
- throw new Error(`The value of \`${key}\` property must be a hex string, e.g.: FF0000`);
197
+ throw new Error("The value of `".concat(key, "` property must be a hex string, e.g.: FF0000"));
199
198
  }
200
199
  _finalColors[key] = hex;
201
200
  }
@@ -204,7 +203,7 @@ ansiHTML.setColors = (colors) => {
204
203
  /**
205
204
  * Reset colors.
206
205
  */
207
- ansiHTML.reset = () => {
206
+ ansiHTML.reset = function () {
208
207
  _setTags(_defColors);
209
208
  };
210
209
  /**
@@ -214,10 +213,10 @@ ansiHTML.reset = () => {
214
213
  ansiHTML.tags = {};
215
214
  if (Object.defineProperty) {
216
215
  Object.defineProperty(ansiHTML.tags, "open", {
217
- get: () => _openTags
216
+ get: function () { return _openTags; }
218
217
  });
219
218
  Object.defineProperty(ansiHTML.tags, "close", {
220
- get: () => _closeTags
219
+ get: function () { return _closeTags; }
221
220
  });
222
221
  }
223
222
  else {
@@ -227,17 +226,17 @@ else {
227
226
  function _setTags(colors) {
228
227
  // reset all
229
228
  _openTags["0"] =
230
- `font-weight:normal;opacity:1;color:#${colors.reset[0]};background:#${colors.reset[1]}`;
229
+ "font-weight:normal;opacity:1;color:#".concat(colors.reset[0], ";background:#").concat(colors.reset[1]);
231
230
  // inverse
232
- _openTags["7"] = `color:#${colors.reset[1]};background:#${colors.reset[0]}`;
231
+ _openTags["7"] = "color:#".concat(colors.reset[1], ";background:#").concat(colors.reset[0]);
233
232
  // dark grey
234
- _openTags["90"] = `color:#${colors.darkgrey}`;
235
- for (const code in _styles) {
236
- const color = _styles[code];
237
- const oriColor = colors[color] || "000";
238
- _openTags[code] = `color:#${oriColor}`;
239
- const codeInt = Number.parseInt(code);
240
- _openTags[(codeInt + 10).toString()] = `background:#${oriColor}`;
233
+ _openTags["90"] = "color:#".concat(colors.darkgrey);
234
+ for (var code in _styles) {
235
+ var color = _styles[code];
236
+ var oriColor = colors[color] || "000";
237
+ _openTags[code] = "color:#".concat(oriColor);
238
+ var codeInt = Number.parseInt(code);
239
+ _openTags[(codeInt + 10).toString()] = "background:#".concat(oriColor);
241
240
  }
242
241
  }
243
242
  ansiHTML.reset();
@@ -1,6 +1,6 @@
1
+ // @ts-nocheck
1
2
  import hotEmitter from "@rspack/core/hot/emitter.js";
2
3
  import { log } from "webpack-dev-server/client/utils/log.js";
3
-
4
4
  /** @typedef {import("../index").Options} Options
5
5
  /** @typedef {import("../index").Status} Status
6
6
 
@@ -9,56 +9,52 @@ import { log } from "webpack-dev-server/client/utils/log.js";
9
9
  * @param {Status} status
10
10
  */
11
11
  function reloadApp(_ref, status) {
12
- var hot = _ref.hot,
13
- liveReload = _ref.liveReload;
14
- if (status.isUnloading) {
15
- return;
16
- }
17
- var currentHash = status.currentHash,
18
- previousHash = status.previousHash;
19
- var isInitial = currentHash.indexOf(/** @type {string} */ previousHash) >= 0;
20
- if (isInitial) {
21
- return;
22
- }
23
-
24
- /**
25
- * @param {Window} rootWindow
26
- * @param {number} intervalId
27
- */
28
- function applyReload(rootWindow, intervalId) {
29
- clearInterval(intervalId);
30
- log.info("App updated. Reloading...");
31
- rootWindow.location.reload();
32
- }
33
- var search = self.location.search.toLowerCase();
34
- var allowToHot = search.indexOf("webpack-dev-server-hot=false") === -1;
35
- var allowToLiveReload =
36
- search.indexOf("webpack-dev-server-live-reload=false") === -1;
37
- if (hot && allowToHot) {
38
- log.info("App hot update...");
39
- hotEmitter.emit("webpackHotUpdate", status.currentHash);
40
- if (typeof self !== "undefined" && self.window) {
41
- // broadcast update to window
42
- self.postMessage("webpackHotUpdate".concat(status.currentHash), "*");
43
- }
44
- }
45
- // allow refreshing the page only if liveReload isn't disabled
46
- else if (liveReload && allowToLiveReload) {
47
- var rootWindow = self;
48
-
49
- // use parent window for reload (in case we're in an iframe with no valid src)
50
- var intervalId = self.setInterval(function () {
51
- if (rootWindow.location.protocol !== "about:") {
52
- // reload immediately if protocol is valid
53
- applyReload(rootWindow, intervalId);
54
- } else {
55
- rootWindow = rootWindow.parent;
56
- if (rootWindow.parent === rootWindow) {
57
- // if parent equals current window we've reached the root which would continue forever, so trigger a reload anyways
58
- applyReload(rootWindow, intervalId);
59
- }
60
- }
61
- });
62
- }
12
+ var hot = _ref.hot, liveReload = _ref.liveReload;
13
+ if (status.isUnloading) {
14
+ return;
15
+ }
16
+ var currentHash = status.currentHash, previousHash = status.previousHash;
17
+ var isInitial = currentHash.indexOf(/** @type {string} */ previousHash) >= 0;
18
+ if (isInitial) {
19
+ return;
20
+ }
21
+ /**
22
+ * @param {Window} rootWindow
23
+ * @param {number} intervalId
24
+ */
25
+ function applyReload(rootWindow, intervalId) {
26
+ clearInterval(intervalId);
27
+ log.info("App updated. Reloading...");
28
+ rootWindow.location.reload();
29
+ }
30
+ var search = self.location.search.toLowerCase();
31
+ var allowToHot = search.indexOf("webpack-dev-server-hot=false") === -1;
32
+ var allowToLiveReload = search.indexOf("webpack-dev-server-live-reload=false") === -1;
33
+ if (hot && allowToHot) {
34
+ log.info("App hot update...");
35
+ hotEmitter.emit("webpackHotUpdate", status.currentHash);
36
+ if (typeof self !== "undefined" && self.window) {
37
+ // broadcast update to window
38
+ self.postMessage("webpackHotUpdate".concat(status.currentHash), "*");
39
+ }
40
+ }
41
+ // allow refreshing the page only if liveReload isn't disabled
42
+ else if (liveReload && allowToLiveReload) {
43
+ var rootWindow = self;
44
+ // use parent window for reload (in case we're in an iframe with no valid src)
45
+ var intervalId = self.setInterval(function () {
46
+ if (rootWindow.location.protocol !== "about:") {
47
+ // reload immediately if protocol is valid
48
+ applyReload(rootWindow, intervalId);
49
+ }
50
+ else {
51
+ rootWindow = rootWindow.parent;
52
+ if (rootWindow.parent === rootWindow) {
53
+ // if parent equals current window we've reached the root which would continue forever, so trigger a reload anyways
54
+ applyReload(rootWindow, intervalId);
55
+ }
56
+ }
57
+ });
58
+ }
63
59
  }
64
60
  export default reloadApp;
package/dist/alias.js CHANGED
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.removeResolveAlias = exports.addResolveAlias = void 0;
4
- const Module = require("module");
4
+ const Module = require("node:module");
5
5
  const MODULE_MAP = {};
6
6
  const RESOLVER_MAP = {};
7
7
  const addResolveAlias = (name, aliasMap) => {
8
8
  const modulePath = require.resolve(name);
9
- if (RESOLVER_MAP[modulePath]) {
9
+ if (modulePath in RESOLVER_MAP) {
10
10
  throw new Error(`Should not add resolve alias to ${name} again.`);
11
11
  }
12
12
  const m = require.cache[modulePath];
@@ -14,13 +14,14 @@ const addResolveAlias = (name, aliasMap) => {
14
14
  throw new Error("Failed to resolve webpack-dev-server.");
15
15
  }
16
16
  RESOLVER_MAP[modulePath] = m.require.resolve;
17
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
17
18
  m.require.resolve = ((id, options) => aliasMap[id] ||
18
19
  RESOLVER_MAP[modulePath].apply(m.require, [
19
20
  id,
20
- options
21
+ options,
21
22
  ]));
22
23
  MODULE_MAP[modulePath] = Module._resolveFilename;
23
- Module._resolveFilename = Module._resolveFilename = (request, mod, ...args) => {
24
+ Module._resolveFilename = (request, mod, ...args) => {
24
25
  if (mod.filename === modulePath && aliasMap[request]) {
25
26
  return aliasMap[request];
26
27
  }
@@ -30,17 +31,15 @@ const addResolveAlias = (name, aliasMap) => {
30
31
  exports.addResolveAlias = addResolveAlias;
31
32
  const removeResolveAlias = (name) => {
32
33
  const modulePath = require.resolve(name);
33
- if (!RESOLVER_MAP[modulePath]) {
34
+ if (!(modulePath in RESOLVER_MAP)) {
34
35
  return;
35
36
  }
36
37
  const m = require.cache[modulePath];
37
38
  if (!m) {
38
39
  throw new Error("Failed to resolve webpack-dev-server");
39
40
  }
40
- if (RESOLVER_MAP[modulePath]) {
41
- Module._resolveFilename = RESOLVER_MAP[modulePath];
42
- m.require.resolve = RESOLVER_MAP[modulePath];
43
- delete RESOLVER_MAP[modulePath];
44
- }
41
+ Module._resolveFilename = MODULE_MAP[modulePath];
42
+ m.require.resolve = RESOLVER_MAP[modulePath];
43
+ delete RESOLVER_MAP[modulePath];
45
44
  };
46
45
  exports.removeResolveAlias = removeResolveAlias;
package/dist/server.d.ts CHANGED
@@ -1,5 +1,14 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
+ /**
4
+ * The following code is modified based on
5
+ * https://github.com/webpack/webpack-dev-server/blob/b0f15ace0123c125d5870609ef4691c141a6d187/lib/Server.js
6
+ *
7
+ * MIT Licensed
8
+ * Author Tobias Koppers @sokra
9
+ * Copyright (c) JS Foundation and other contributors
10
+ * https://github.com/webpack/webpack-dev-server/blob/b0f15ace0123c125d5870609ef4691c141a6d187/LICENSE
11
+ */
3
12
  import type { Server } from "node:http";
4
13
  import type { Socket } from "node:net";
5
14
  import { type Compiler, MultiCompiler } from "@rspack/core";
package/dist/server.js CHANGED
@@ -4,16 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.RspackDevServer = void 0;
7
- /**
8
- * The following code is modified based on
9
- * https://github.com/webpack/webpack-dev-server/blob/b0f15ace0123c125d5870609ef4691c141a6d187/lib/Server.js
10
- *
11
- * MIT Licensed
12
- * Author Tobias Koppers @sokra
13
- * Copyright (c) JS Foundation and other contributors
14
- * https://github.com/webpack/webpack-dev-server/blob/b0f15ace0123c125d5870609ef4691c141a6d187/LICENSE
15
- */
16
- const node_path_1 = __importDefault(require("node:path"));
17
7
  const core_1 = require("@rspack/core");
18
8
  const webpack_dev_server_1 = __importDefault(require("webpack-dev-server"));
19
9
  // @ts-ignore 'package.json' is not under 'rootDir'
@@ -57,7 +47,7 @@ class RspackDevServer extends webpack_dev_server_1.default {
57
47
  "Make sure to disable HMR for production by setting `devServer.hot` to `false` in the configuration.");
58
48
  }
59
49
  compiler.options.resolve.alias = {
60
- "ansi-html-community": node_path_1.default.resolve(__dirname, "./ansiHTML"),
50
+ "ansi-html-community": require.resolve("@rspack/dev-server/client/utils/ansiHTML"),
61
51
  ...compiler.options.resolve.alias
62
52
  };
63
53
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack/dev-server",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "license": "MIT",
5
5
  "description": "Development server for rspack",
6
6
  "main": "./dist/index.js",
@@ -91,7 +91,9 @@
91
91
  "@rspack/core": "*"
92
92
  },
93
93
  "scripts": {
94
- "build": "tsc -b ./tsconfig.build.json",
94
+ "build": "pnpm run build:server && pnpm run build:client",
95
+ "build:server": "tsc -b ./tsconfig.build.json",
96
+ "build:client": "tsc -b ./tsconfig.client.json",
95
97
  "dev": "tsc -b -w",
96
98
  "lint": "biome check .",
97
99
  "lint:write": "biome check . --write",
@@ -1,31 +0,0 @@
1
- /**
2
- * The following code is modified based on
3
- * https://github.com/mahdyar/ansi-html-community/blob/b86cc3f1fa1d118477877352f0eafe1a70fd20ab/index.js
4
- *
5
- * Supported:
6
- * - added support for 24-bit RGB colors.
7
- *
8
- * Apache 2.0 Licensed
9
- * Author @Tjatse
10
- * https://github.com/mahdyar/ansi-html-community/blob/master/LICENSE
11
- */
12
- interface AnsiHtmlTags {
13
- open: typeof _openTags;
14
- close: typeof _closeTags;
15
- }
16
- type Option<T> = T | null | undefined;
17
- type Match = {
18
- advance: (n: number) => void;
19
- } & Array<string>;
20
- declare const _openTags: Record<string, string | ((m: Match) => Option<string>)>;
21
- declare const _closeTags: Record<string, string | ((ansiCodes: Option<Array<string>>) => string)>;
22
- /**
23
- * Converts text with ANSI color codes to HTML markup.
24
- */
25
- declare function ansiHTML(text: string): string;
26
- declare namespace ansiHTML {
27
- var setColors: (colors: Record<string, string | string[]>) => void;
28
- var reset: () => void;
29
- var tags: AnsiHtmlTags;
30
- }
31
- export default ansiHTML;