@rspack/dev-server 1.2.1 → 2.0.0-beta.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 (47) hide show
  1. package/README.md +17 -17
  2. package/client/clients/WebSocketClient.d.ts +17 -0
  3. package/client/clients/WebSocketClient.js +28 -28
  4. package/client/index.d.ts +17 -0
  5. package/client/index.js +224 -363
  6. package/client/modules/logger/Logger.d.ts +40 -0
  7. package/client/modules/logger/Logger.js +123 -0
  8. package/client/modules/logger/createConsoleLogger.d.ts +12 -0
  9. package/client/modules/logger/createConsoleLogger.js +119 -0
  10. package/client/modules/logger/index.d.ts +18 -0
  11. package/client/modules/logger/index.js +20 -712
  12. package/client/modules/types.d.ts +45 -0
  13. package/client/modules/types.js +17 -0
  14. package/client/overlay.d.ts +44 -0
  15. package/client/overlay.js +243 -292
  16. package/client/progress.d.ts +11 -0
  17. package/client/progress.js +178 -111
  18. package/client/socket.d.ts +15 -0
  19. package/client/socket.js +19 -46
  20. package/client/utils/ansiHTML.d.ts +30 -0
  21. package/client/utils/ansiHTML.js +98 -145
  22. package/client/utils/log.d.ts +13 -0
  23. package/client/utils/log.js +7 -17
  24. package/{dist/servers/SockJSServer.d.ts → client/utils/sendMessage.d.ts} +2 -1
  25. package/client/utils/sendMessage.js +6 -15
  26. package/dist/0~launch-editor.js +618 -0
  27. package/dist/0~open.js +547 -0
  28. package/dist/0~p-retry.js +158 -0
  29. package/dist/131.js +1398 -0
  30. package/dist/config.d.ts +1 -3
  31. package/dist/getPort.d.ts +4 -1
  32. package/dist/index.js +1 -5
  33. package/dist/rslib-runtime.js +66 -0
  34. package/dist/server.d.ts +7 -18
  35. package/dist/servers/WebsocketServer.d.ts +8 -1
  36. package/dist/types.d.ts +14 -29
  37. package/package.json +74 -103
  38. package/client/clients/SockJSClient.js +0 -34
  39. package/client/modules/sockjs-client/index.js +0 -4506
  40. package/dist/config.js +0 -2
  41. package/dist/getPort.js +0 -131
  42. package/dist/options.json +0 -1034
  43. package/dist/server.js +0 -2222
  44. package/dist/servers/BaseServer.js +0 -20
  45. package/dist/servers/SockJSServer.js +0 -110
  46. package/dist/servers/WebsocketServer.js +0 -72
  47. package/dist/types.js +0 -5
@@ -1,7 +1,9 @@
1
- // Reference to https://github.com/sindresorhus/ansi-regex
2
- var _regANSI = /(?:(?:\u001b\[)|\u009b)(?:(?:[0-9]{1,3})?(?:(?:;[0-9]{0,3})*)?[A-M|f-m])|\u001b[A-M]/;
3
- var _defColors = {
4
- reset: ['fff', '000'],
1
+ const _regANSI = /(?:(?:\u001b\[)|\u009b)(?:(?:[0-9]{1,3})?(?:(?:;[0-9]{0,3})*)?[A-M|f-m])|\u001b[A-M]/;
2
+ const _defColors = {
3
+ reset: [
4
+ 'fff',
5
+ '000'
6
+ ],
5
7
  black: '000',
6
8
  red: 'ff0000',
7
9
  green: '209805',
@@ -10,9 +12,9 @@ var _defColors = {
10
12
  magenta: 'ff00ff',
11
13
  cyan: '00ffee',
12
14
  lightgrey: 'f0f0f0',
13
- darkgrey: '888',
15
+ darkgrey: '888'
14
16
  };
15
- var _styles = {
17
+ const _styles = {
16
18
  30: 'black',
17
19
  31: 'red',
18
20
  32: 'green',
@@ -20,56 +22,52 @@ var _styles = {
20
22
  34: 'blue',
21
23
  35: 'magenta',
22
24
  36: 'cyan',
23
- 37: 'lightgrey',
25
+ 37: 'lightgrey'
24
26
  };
25
- var _colorMode = {
26
- 2: 'rgb',
27
+ const _colorMode = {
28
+ 2: 'rgb'
27
29
  };
28
- var _openTags = {
30
+ const _openTags = {
29
31
  1: 'font-weight:bold',
30
32
  2: 'opacity:0.5',
31
33
  3: '<i>',
32
34
  4: '<u>',
33
35
  8: 'display:none',
34
36
  9: '<del>',
35
- 38: function (match) {
36
- // color
37
- var mode = _colorMode[match[0]];
38
- if (mode === 'rgb') {
39
- var r = match[1];
40
- var g = match[2];
41
- var b = match[3];
37
+ 38: (match)=>{
38
+ const mode = _colorMode[match[0]];
39
+ if ('rgb' === mode) {
40
+ const r = match[1];
41
+ const g = match[2];
42
+ const b = match[3];
42
43
  match.advance(4);
43
- return "color: rgb(".concat(r, ",").concat(g, ",").concat(b, ")");
44
+ return `color: rgb(${r},${g},${b})`;
44
45
  }
45
46
  },
46
- 48: function (match) {
47
- // background color
48
- var mode = _colorMode[match[0]];
49
- if (mode === 'rgb') {
50
- var r = match[1];
51
- var g = match[2];
52
- var b = match[3];
47
+ 48: (match)=>{
48
+ const mode = _colorMode[match[0]];
49
+ if ('rgb' === mode) {
50
+ const r = match[1];
51
+ const g = match[2];
52
+ const b = match[3];
53
53
  match.advance(4);
54
- return "background-color: rgb(".concat(r, ",").concat(g, ",").concat(b, ")");
54
+ return `background-color: rgb(${r},${g},${b})`;
55
55
  }
56
- },
56
+ }
57
57
  };
58
- var _openTagToCloseTag = {
58
+ const _openTagToCloseTag = {
59
59
  3: '23',
60
60
  4: '24',
61
- 9: '29',
61
+ 9: '29'
62
62
  };
63
- var _closeTags = {
64
- 0: function (ansiCodes) {
65
- if (!ansiCodes)
66
- return '</span>';
67
- if (!ansiCodes.length)
68
- return '';
69
- var code;
70
- var ret = '';
71
- while ((code = ansiCodes.pop())) {
72
- var closeTag = _openTagToCloseTag[code];
63
+ const _closeTags = {
64
+ 0: (ansiCodes)=>{
65
+ if (!ansiCodes) return '</span>';
66
+ if (!ansiCodes.length) return '';
67
+ let code;
68
+ let ret = '';
69
+ while(code = ansiCodes.pop()){
70
+ const closeTag = _openTagToCloseTag[code];
73
71
  if (closeTag) {
74
72
  ret += _closeTags[closeTag];
75
73
  continue;
@@ -80,163 +78,118 @@ var _closeTags = {
80
78
  },
81
79
  23: '</i>',
82
80
  24: '</u>',
83
- 29: '</del>', // reset delete
81
+ 29: '</del>'
84
82
  };
85
- for (var _i = 0, _a = [21, 22, 27, 28, 39, 49]; _i < _a.length; _i++) {
86
- var n = _a[_i];
87
- _closeTags[n] = '</span>';
88
- }
89
- /**
90
- * Normalize ';<seq>' | '<seq>' -> '<seq>'
91
- */
83
+ for (const n of [
84
+ 21,
85
+ 22,
86
+ 27,
87
+ 28,
88
+ 39,
89
+ 49
90
+ ])_closeTags[n] = '</span>';
92
91
  function normalizeSeq(seq) {
93
- if (seq === null || seq === undefined)
94
- return null;
95
- if (seq.startsWith(';')) {
96
- return seq.slice(1);
97
- }
92
+ if (null == seq) return null;
93
+ if (seq.startsWith(';')) return seq.slice(1);
98
94
  return seq;
99
95
  }
100
- /**
101
- * Converts text with ANSI color codes to HTML markup.
102
- */
103
- export default function ansiHTML(text) {
104
- // Returns the text if the string has no ANSI escape code.
105
- if (!_regANSI.test(text)) {
106
- return text;
107
- }
108
- // Cache opened sequence.
109
- var ansiCodes = [];
110
- // Replace with markup.
111
- var ret = text.replace(
112
- //@ts-ignore TS1487 error
113
- /\033\[(?:[0-9]{1,3})?(?:(?:;[0-9]{0,3})*)?m/g, function (m) {
114
- var _a;
115
- var match = (_a = m.match(/(;?\d+)/g)) === null || _a === void 0 ? void 0 : _a.map(normalizeSeq);
96
+ function ansiHTML(text) {
97
+ if (!_regANSI.test(text)) return text;
98
+ const ansiCodes = [];
99
+ let ret = text.replace(/\033\[(?:[0-9]{1,3})?(?:(?:;[0-9]{0,3})*)?m/g, (m)=>{
100
+ var _m_match;
101
+ const match = null == (_m_match = m.match(/(;?\d+)/g)) ? void 0 : _m_match.map(normalizeSeq);
116
102
  Object.defineProperty(match, 'advance', {
117
- value: function (count) {
103
+ value: function(count) {
118
104
  this.splice(0, count);
119
- },
105
+ }
120
106
  });
121
- var rep = '';
122
- var seq;
123
- while ((seq = match[0])) {
107
+ let rep = '';
108
+ let seq;
109
+ while(seq = match[0]){
124
110
  match.advance(1);
125
111
  rep += applySeq(seq);
126
112
  }
127
113
  return rep;
128
114
  function applySeq(seq) {
129
- var other = _openTags[seq];
130
- if (other &&
131
- (other =
132
- typeof other === 'function' ? other(match) : other)) {
133
- // If reset signal is encountered, we have to reset everything.
134
- var ret_1 = '';
135
- if (seq === '0') {
136
- ret_1 += _closeTags[seq](ansiCodes);
137
- }
138
- // If current sequence has been opened, close it.
139
- if (ansiCodes.indexOf(seq) !== -1) {
115
+ let other = _openTags[seq];
116
+ if (other && (other = 'function' == typeof other ? other(match) : other)) {
117
+ let ret = '';
118
+ if ('0' === seq) ret += _closeTags[seq](ansiCodes);
119
+ if (-1 !== ansiCodes.indexOf(seq)) {
140
120
  ansiCodes.pop();
141
121
  return '</span>';
142
122
  }
143
- // Open tag.
144
123
  ansiCodes.push(seq);
145
- return ret_1 + (other[0] === '<' ? other : "<span style=\"".concat(other, ";\">"));
146
- }
147
- var ct = _closeTags[seq];
148
- if (typeof ct === 'function') {
149
- return ct(ansiCodes);
124
+ return ret + ('<' === other[0] ? other : `<span style="${other};">`);
150
125
  }
126
+ const ct = _closeTags[seq];
127
+ if ('function' == typeof ct) return ct(ansiCodes);
151
128
  if (ct) {
152
- // Pop sequence
153
129
  ansiCodes.pop();
154
130
  return ct;
155
131
  }
156
132
  return '';
157
133
  }
158
134
  });
159
- // Make sure tags are closed.
160
- var l = ansiCodes.length;
135
+ const l = ansiCodes.length;
161
136
  l > 0 && (ret += Array(l + 1).join('</span>'));
162
137
  return ret;
163
138
  }
164
- /**
165
- * Customize colors.
166
- */
167
- ansiHTML.setColors = function (colors) {
168
- if (typeof colors !== 'object') {
169
- throw new Error('`colors` parameter must be an Object.');
170
- }
171
- var _finalColors = {};
172
- for (var key in _defColors) {
173
- var hex = colors.hasOwnProperty(key) ? colors[key] : null;
139
+ ansiHTML.setColors = (colors)=>{
140
+ if ('object' != typeof colors) throw new Error('`colors` parameter must be an Object.');
141
+ const _finalColors = {};
142
+ for(const key in _defColors){
143
+ let hex = colors.hasOwnProperty(key) ? colors[key] : null;
174
144
  if (!hex) {
175
145
  _finalColors[key] = _defColors[key];
176
146
  continue;
177
147
  }
178
148
  if ('reset' === key) {
179
- if (typeof hex === 'string') {
180
- hex = [hex];
181
- }
182
- if (!Array.isArray(hex) ||
183
- hex.length === 0 ||
184
- hex.some(function (h) { return typeof h !== 'string'; })) {
185
- 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
- }
187
- var defHexColor = _defColors[key];
188
- if (!hex[0]) {
189
- hex[0] = defHexColor[0];
190
- }
191
- if (hex.length === 1 || !hex[1]) {
192
- hex = [hex[0]];
149
+ if ('string' == typeof hex) hex = [
150
+ hex
151
+ ];
152
+ if (!Array.isArray(hex) || 0 === hex.length || hex.some((h)=>'string' != typeof h)) throw new Error(`The value of \`${key}\` property must be an Array and each item could only be a hex string, e.g.: FF0000`);
153
+ const defHexColor = _defColors[key];
154
+ if (!hex[0]) hex[0] = defHexColor[0];
155
+ if (1 === hex.length || !hex[1]) {
156
+ hex = [
157
+ hex[0]
158
+ ];
193
159
  hex.push(defHexColor[1]);
194
160
  }
195
161
  hex = hex.slice(0, 2);
196
- }
197
- else if (typeof hex !== 'string') {
198
- throw new Error("The value of `".concat(key, "` property must be a hex string, e.g.: FF0000"));
199
- }
162
+ } else if ('string' != typeof hex) throw new Error(`The value of \`${key}\` property must be a hex string, e.g.: FF0000`);
200
163
  _finalColors[key] = hex;
201
164
  }
202
165
  _setTags(_finalColors);
203
166
  };
204
- /**
205
- * Reset colors.
206
- */
207
- ansiHTML.reset = function () {
167
+ ansiHTML.reset = ()=>{
208
168
  _setTags(_defColors);
209
169
  };
210
- /**
211
- * Expose tags, including open and close.
212
- */
213
170
  ansiHTML.tags = {};
214
171
  if (Object.defineProperty) {
215
172
  Object.defineProperty(ansiHTML.tags, 'open', {
216
- get: function () { return _openTags; },
173
+ get: ()=>_openTags
217
174
  });
218
175
  Object.defineProperty(ansiHTML.tags, 'close', {
219
- get: function () { return _closeTags; },
176
+ get: ()=>_closeTags
220
177
  });
221
- }
222
- else {
178
+ } else {
223
179
  ansiHTML.tags.open = _openTags;
224
180
  ansiHTML.tags.close = _closeTags;
225
181
  }
226
182
  function _setTags(colors) {
227
- // reset all
228
- _openTags['0'] =
229
- "font-weight:normal;opacity:1;color:#".concat(colors.reset[0], ";background:#").concat(colors.reset[1]);
230
- // inverse
231
- _openTags['7'] = "color:#".concat(colors.reset[1], ";background:#").concat(colors.reset[0]);
232
- // dark grey
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);
183
+ _openTags['0'] = `font-weight:normal;opacity:1;color:#${colors.reset[0]};background:#${colors.reset[1]}`;
184
+ _openTags['7'] = `color:#${colors.reset[1]};background:#${colors.reset[0]}`;
185
+ _openTags['90'] = `color:#${colors.darkgrey}`;
186
+ for(const code in _styles){
187
+ const color = _styles[code];
188
+ const oriColor = colors[color] || '000';
189
+ _openTags[code] = `color:#${oriColor}`;
190
+ const codeInt = Number.parseInt(code);
191
+ _openTags[(codeInt + 10).toString()] = `background:#${oriColor}`;
240
192
  }
241
193
  }
242
194
  ansiHTML.reset();
195
+ export { ansiHTML as default };
@@ -0,0 +1,13 @@
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 type { LogLevel } from '../type.js';
11
+ declare function setLogLevel(level: LogLevel): void;
12
+ declare const log: import("../modules/logger/Logger.js").Logger;
13
+ export { log, setLogLevel };
@@ -1,21 +1,11 @@
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 logger from '../modules/logger/index';
11
- var name = 'webpack-dev-server';
12
- // default level is set on the client side, so it does not need
13
- // to be set by the CLI or API
14
- var defaultLevel = 'info';
15
- // options new options, merge with old options
1
+ import { logger } from "../modules/logger/index.js";
2
+ const log_name = 'rspack-dev-server';
3
+ const defaultLevel = 'info';
16
4
  function setLogLevel(level) {
17
- logger.configureDefaultLogger({ level: level });
5
+ logger.configureDefaultLogger({
6
+ level
7
+ });
18
8
  }
19
9
  setLogLevel(defaultLevel);
20
- var log = logger.getLogger(name);
10
+ const log = logger.getLogger(log_name);
21
11
  export { log, setLogLevel };
@@ -7,4 +7,5 @@
7
7
  * Copyright (c) JS Foundation and other contributors
8
8
  * https://github.com/webpack/webpack-dev-server/blob/main/LICENSE
9
9
  */
10
- export {};
10
+ declare function sendMsg(type: string, data?: any): void;
11
+ export default sendMsg;
@@ -1,17 +1,8 @@
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
1
  function sendMsg(type, data) {
11
- if (typeof self !== 'undefined' &&
12
- (typeof WorkerGlobalScope === 'undefined' ||
13
- !(self instanceof WorkerGlobalScope))) {
14
- self.postMessage({ type: "webpack".concat(type), data: data }, '*');
15
- }
2
+ if ("u" > typeof self && ("u" < typeof WorkerGlobalScope || !(self instanceof WorkerGlobalScope))) self.postMessage({
3
+ type: `webpack${type}`,
4
+ data
5
+ }, '*');
16
6
  }
17
- export default sendMsg;
7
+ const sendMessage = sendMsg;
8
+ export { sendMessage as default };