@rspack/dev-server 1.1.5 → 1.2.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.
package/README.md CHANGED
@@ -107,7 +107,9 @@ server.startCallback(() => {
107
107
 
108
108
  ## Credits
109
109
 
110
- Thanks to the [webpack-dev-server](https://github.com/webpack/webpack-dev-server) project created by [@sokra](https://github.com/sokra)
110
+ This plugin is forked from [webpack-dev-server](https://github.com/webpack/webpack-dev-server), and is used to smooth out some differences between rspack and webpack, while also providing rspack-specific new features.
111
+
112
+ > Thanks to the [webpack-dev-server](https://github.com/webpack/webpack-dev-server) project created by [@sokra](https://github.com/sokra)
111
113
 
112
114
  ## License
113
115
 
@@ -0,0 +1,34 @@
1
+ /**
2
+ * The following code is modified based on
3
+ * https://github.com/webpack/webpack-dev-server
4
+ *
5
+ * MIT Licensed
6
+ * Author Tobias Koppers @sokra
7
+ * Copyright (c) JS Foundation and other contributors
8
+ * https://github.com/webpack/webpack-dev-server/blob/main/LICENSE
9
+ */
10
+ import SockJS from '../modules/sockjs-client/index.js';
11
+ import { log } from '../utils/log.js';
12
+ var SockJSClient = /** @class */ (function () {
13
+ function SockJSClient(url) {
14
+ // SockJS requires `http` and `https` protocols
15
+ this.sock = new SockJS(url.replace(/^ws:/i, 'http:').replace(/^wss:/i, 'https:'));
16
+ this.sock.onerror = function (error) {
17
+ log.error(error);
18
+ };
19
+ }
20
+ SockJSClient.prototype.onOpen = function (fn) {
21
+ this.sock.onopen = fn;
22
+ };
23
+ SockJSClient.prototype.onClose = function (fn) {
24
+ this.sock.onclose = fn;
25
+ };
26
+ // call f with the message string as the first argument
27
+ SockJSClient.prototype.onMessage = function (fn) {
28
+ this.sock.onmessage = function (err) {
29
+ fn(err.data);
30
+ };
31
+ };
32
+ return SockJSClient;
33
+ }());
34
+ export default SockJSClient;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * The following code is modified based on
3
+ * https://github.com/webpack/webpack-dev-server
4
+ *
5
+ * MIT Licensed
6
+ * Author Tobias Koppers @sokra
7
+ * Copyright (c) JS Foundation and other contributors
8
+ * https://github.com/webpack/webpack-dev-server/blob/main/LICENSE
9
+ */
10
+ import { log } from '../utils/log.js';
11
+ var WebSocketClient = /** @class */ (function () {
12
+ function WebSocketClient(url) {
13
+ this.client = new WebSocket(url);
14
+ this.client.onerror = function (error) {
15
+ log.error(error);
16
+ };
17
+ }
18
+ WebSocketClient.prototype.onOpen = function (fn) {
19
+ this.client.onopen = fn;
20
+ };
21
+ WebSocketClient.prototype.onClose = function (fn) {
22
+ this.client.onclose = fn;
23
+ };
24
+ // call fn with the message string as the first argument
25
+ WebSocketClient.prototype.onMessage = function (fn) {
26
+ this.client.onmessage = function (event) {
27
+ fn(event.data);
28
+ };
29
+ };
30
+ return WebSocketClient;
31
+ }());
32
+ export default WebSocketClient;
package/client/index.js CHANGED
@@ -1,4 +1,12 @@
1
- // @ts-nocheck
1
+ /**
2
+ * The following code is modified based on
3
+ * https://github.com/webpack/webpack-dev-server
4
+ *
5
+ * MIT Licensed
6
+ * Author Tobias Koppers @sokra
7
+ * Copyright (c) JS Foundation and other contributors
8
+ * https://github.com/webpack/webpack-dev-server/blob/main/LICENSE
9
+ */
2
10
  var __assign = (this && this.__assign) || function () {
3
11
  __assign = Object.assign || function(t) {
4
12
  for (var s, i = 1, n = arguments.length; i < n; i++) {
@@ -10,58 +18,27 @@ var __assign = (this && this.__assign) || function () {
10
18
  };
11
19
  return __assign.apply(this, arguments);
12
20
  };
21
+ // @ts-expect-error: No type definitions available for '@rspack/core/hot/emitter.js'
13
22
  import hotEmitter from '@rspack/core/hot/emitter.js';
14
- /* global __resourceQuery, __webpack_hash__ */
15
23
  /* Rspack dev server runtime client */
16
- /// <reference types="webpack/module" />
24
+ // @ts-expect-error: No type definitions available for '@rspack/core/hot/log.js'
17
25
  import webpackHotLog from '@rspack/core/hot/log.js';
18
- import { createOverlay, formatProblem, } from 'webpack-dev-server/client/overlay.js';
19
- import socket from 'webpack-dev-server/client/socket.js';
20
- import { defineProgressElement, isProgressSupported, } from 'webpack-dev-server/client/progress.js';
21
- import { log, setLogLevel } from 'webpack-dev-server/client/utils/log.js';
22
- import sendMessage from 'webpack-dev-server/client/utils/sendMessage.js';
23
- /**
24
- * @typedef {Object} OverlayOptions
25
- * @property {boolean | (error: Error) => boolean} [warnings]
26
- * @property {boolean | (error: Error) => boolean} [errors]
27
- * @property {boolean | (error: Error) => boolean} [runtimeErrors]
28
- * @property {string} [trustedTypesPolicyName]
29
- */
30
- /**
31
- * @typedef {Object} Options
32
- * @property {boolean} hot
33
- * @property {boolean} liveReload
34
- * @property {boolean} progress
35
- * @property {boolean | OverlayOptions} overlay
36
- * @property {string} [logging]
37
- * @property {number} [reconnect]
38
- */
39
- /**
40
- * @typedef {Object} Status
41
- * @property {boolean} isUnloading
42
- * @property {string} currentHash
43
- * @property {string} [previousHash]
44
- */
45
- /**
46
- * @param {boolean | { warnings?: boolean | string; errors?: boolean | string; runtimeErrors?: boolean | string; }} overlayOptions
47
- */
26
+ import { createOverlay, formatProblem } from './overlay.js';
27
+ import socket from './socket.js';
28
+ import { defineProgressElement, isProgressSupported } from './progress.js';
29
+ import { log, setLogLevel } from './utils/log.js';
30
+ import sendMessage from './utils/sendMessage.js';
48
31
  var decodeOverlayOptions = function (overlayOptions) {
49
32
  if (typeof overlayOptions === 'object') {
50
33
  ['warnings', 'errors', 'runtimeErrors'].forEach(function (property) {
51
34
  if (typeof overlayOptions[property] === 'string') {
52
35
  var overlayFilterFunctionString = decodeURIComponent(overlayOptions[property]);
53
- // eslint-disable-next-line no-new-func
54
36
  overlayOptions[property] = new Function('message', "var callback = ".concat(overlayFilterFunctionString, "\n\t\t\t\treturn callback(message)"));
55
37
  }
56
38
  });
57
39
  }
58
40
  };
59
- /**
60
- * @param {string} resourceQuery
61
- * @returns {{ [key: string]: string | boolean }}
62
- */
63
41
  var parseURL = function (resourceQuery) {
64
- /** @type {{ [key: string]: string }} */
65
42
  var result = {};
66
43
  if (typeof resourceQuery === 'string' && resourceQuery !== '') {
67
44
  var searchParams = resourceQuery.slice(1).split('&');
@@ -86,22 +63,15 @@ var parseURL = function (resourceQuery) {
86
63
  }
87
64
  if (scriptSourceURL) {
88
65
  result = scriptSourceURL;
89
- result.fromCurrentScript = true;
66
+ result['fromCurrentScript'] = 'true';
90
67
  }
91
68
  }
92
69
  return result;
93
70
  };
94
- /**
95
- * @type {Status}
96
- */
97
71
  var status = {
98
72
  isUnloading: false,
99
- // eslint-disable-next-line camelcase
100
73
  currentHash: __webpack_hash__,
101
74
  };
102
- /**
103
- * @returns {string}
104
- */
105
75
  var getCurrentScriptSource = function () {
106
76
  // `document.currentScript` is the most accurate way to find the current script,
107
77
  // but is not supported in all browsers.
@@ -125,7 +95,6 @@ var enabledFeatures = {
125
95
  Progress: false,
126
96
  Overlay: false,
127
97
  };
128
- /** @type {Options} */
129
98
  var options = {
130
99
  hot: false,
131
100
  liveReload: false,
@@ -164,9 +133,6 @@ if (parsedResourceQuery.logging) {
164
133
  if (typeof parsedResourceQuery.reconnect !== 'undefined') {
165
134
  options.reconnect = Number(parsedResourceQuery.reconnect);
166
135
  }
167
- /**
168
- * @param {string} level
169
- */
170
136
  var setAllLogLevel = function (level) {
171
137
  // This is needed because the HMR logger operate separately from dev server logger
172
138
  webpackHotLog.setLogLevel(level === 'verbose' || level === 'log' ? 'info' : level);
@@ -205,24 +171,16 @@ var overlay = typeof window !== 'undefined'
205
171
  catchRuntimeError: options.overlay,
206
172
  })
207
173
  : { send: function () { } };
208
- /**
209
- * @param {Options} options
210
- * @param {Status} currentStatus
211
- */
212
174
  var reloadApp = function (_a, currentStatus) {
213
175
  var hot = _a.hot, liveReload = _a.liveReload;
214
176
  if (currentStatus.isUnloading) {
215
177
  return;
216
178
  }
217
179
  var currentHash = currentStatus.currentHash, previousHash = currentStatus.previousHash;
218
- var isInitial = currentHash.indexOf(/** @type {string} */ (previousHash)) >= 0;
180
+ var isInitial = currentHash.indexOf(previousHash) >= 0;
219
181
  if (isInitial) {
220
182
  return;
221
183
  }
222
- /**
223
- * @param {Window} rootWindow
224
- * @param {number} intervalId
225
- */
226
184
  function applyReload(rootWindow, intervalId) {
227
185
  clearInterval(intervalId);
228
186
  log.info('App updated. Reloading...');
@@ -268,8 +226,6 @@ var ansiRegex = new RegExp([
268
226
  * Adapted from code originally released by Sindre Sorhus
269
227
  * Licensed the MIT License
270
228
  *
271
- * @param {string} string
272
- * @return {string}
273
229
  */
274
230
  var stripAnsi = function (string) {
275
231
  if (typeof string !== 'string') {
@@ -298,9 +254,6 @@ var onSocketMessage = {
298
254
  }
299
255
  sendMessage('Invalid');
300
256
  },
301
- /**
302
- * @param {string | undefined} hash
303
- */
304
257
  hash: function hash(_hash) {
305
258
  if (!_hash) {
306
259
  return;
@@ -309,9 +262,6 @@ var onSocketMessage = {
309
262
  status.currentHash = _hash;
310
263
  },
311
264
  logging: setAllLogLevel,
312
- /**
313
- * @param {boolean} value
314
- */
315
265
  overlay: function (value) {
316
266
  if (typeof document === 'undefined') {
317
267
  return;
@@ -319,24 +269,15 @@ var onSocketMessage = {
319
269
  options.overlay = value;
320
270
  decodeOverlayOptions(options.overlay);
321
271
  },
322
- /**
323
- * @param {number} value
324
- */
325
272
  reconnect: function (value) {
326
273
  if (parsedResourceQuery.reconnect === 'false') {
327
274
  return;
328
275
  }
329
276
  options.reconnect = value;
330
277
  },
331
- /**
332
- * @param {boolean} value
333
- */
334
278
  progress: function (value) {
335
279
  options.progress = value;
336
280
  },
337
- /**
338
- * @param {{ pluginName?: string, percent: number, msg: string }} data
339
- */
340
281
  'progress-update': function progressUpdate(data) {
341
282
  if (options.progress) {
342
283
  log.info("".concat(data.pluginName ? "[".concat(data.pluginName, "] ") : '').concat(data.percent, "% - ").concat(data.msg, "."));
@@ -349,7 +290,7 @@ var onSocketMessage = {
349
290
  progress = document.createElement('wds-progress');
350
291
  document.body.appendChild(progress);
351
292
  }
352
- progress.setAttribute('progress', data.percent);
293
+ progress.setAttribute('progress', data.percent.toString());
353
294
  progress.setAttribute('type', options.progress);
354
295
  }
355
296
  }
@@ -369,17 +310,10 @@ var onSocketMessage = {
369
310
  }
370
311
  reloadApp(options, status);
371
312
  },
372
- /**
373
- * @param {string} file
374
- */
375
313
  'static-changed': function staticChanged(file) {
376
314
  log.info("".concat(file ? "\"".concat(file, "\"") : 'Content', " from static directory was changed. Reloading..."));
377
315
  self.location.reload();
378
316
  },
379
- /**
380
- * @param {Error[]} warnings
381
- * @param {any} params
382
- */
383
317
  warnings: function (warnings, params) {
384
318
  log.warn('Warnings while compiling.');
385
319
  var printableWarnings = warnings.map(function (error) {
@@ -410,9 +344,6 @@ var onSocketMessage = {
410
344
  }
411
345
  reloadApp(options, status);
412
346
  },
413
- /**
414
- * @param {Error[]} errors
415
- */
416
347
  errors: function (errors) {
417
348
  log.error('Errors while compiling. Reload prevented.');
418
349
  var printableErrors = errors.map(function (error) {
@@ -439,9 +370,6 @@ var onSocketMessage = {
439
370
  }
440
371
  }
441
372
  },
442
- /**
443
- * @param {Error} error
444
- */
445
373
  error: function (error) {
446
374
  log.error(error);
447
375
  },
@@ -453,10 +381,6 @@ var onSocketMessage = {
453
381
  sendMessage('Close');
454
382
  },
455
383
  };
456
- /**
457
- * @param {{ protocol?: string, auth?: string, hostname?: string, port?: string, pathname?: string, search?: string, hash?: string, slashes?: boolean }} objURL
458
- * @returns {string}
459
- */
460
384
  var formatURL = function (objURL) {
461
385
  var protocol = objURL.protocol || '';
462
386
  if (protocol && protocol.substr(-1) !== ':') {
@@ -497,19 +421,12 @@ var formatURL = function (objURL) {
497
421
  if (hash && hash.charAt(0) !== '#') {
498
422
  hash = "#".concat(hash);
499
423
  }
500
- pathname = pathname.replace(/[?#]/g,
501
- /**
502
- * @param {string} match
503
- * @returns {string}
504
- */
505
- function (match) { return encodeURIComponent(match); });
424
+ pathname = pathname.replace(/[?#]/g, function (match) {
425
+ return encodeURIComponent(match);
426
+ });
506
427
  search = search.replace('#', '%23');
507
428
  return "".concat(protocol).concat(host).concat(pathname).concat(search).concat(hash);
508
429
  };
509
- /**
510
- * @param {URL & { fromCurrentScript?: boolean }} parsedURL
511
- * @returns {string}
512
- */
513
430
  var createSocketURL = function (parsedURL) {
514
431
  var hostname = parsedURL.hostname;
515
432
  // Node.js module parses it as `::`