@rspack/dev-server 1.0.0-beta.1 → 1.0.0-beta.3

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.
@@ -1,3 +1,14 @@
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
+ */
1
12
  interface AnsiHtmlTags {
2
13
  open: typeof _openTags;
3
14
  close: typeof _closeTags;
@@ -6,8 +17,8 @@ type Option<T> = T | null | undefined;
6
17
  type Match = {
7
18
  advance: (n: number) => void;
8
19
  } & Array<string>;
9
- declare var _openTags: Record<string, string | ((m: Match) => Option<string>)>;
10
- declare var _closeTags: Record<string, string | ((ansiCodes: Option<Array<string>>) => string)>;
20
+ declare const _openTags: Record<string, string | ((m: Match) => Option<string>)>;
21
+ declare const _closeTags: Record<string, string | ((ansiCodes: Option<Array<string>>) => string)>;
11
22
  /**
12
23
  * Converts text with ANSI color codes to HTML markup.
13
24
  */
package/dist/ansiHTML.js CHANGED
@@ -1,19 +1,8 @@
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
1
  "use strict";
13
2
  Object.defineProperty(exports, "__esModule", { value: true });
14
3
  // Reference to https://github.com/sindresorhus/ansi-regex
15
- var _regANSI = /(?:(?:\u001b\[)|\u009b)(?:(?:[0-9]{1,3})?(?:(?:;[0-9]{0,3})*)?[A-M|f-m])|\u001b[A-M]/;
16
- var _defColors = {
4
+ const _regANSI = /(?:(?:\u001b\[)|\u009b)(?:(?:[0-9]{1,3})?(?:(?:;[0-9]{0,3})*)?[A-M|f-m])|\u001b[A-M]/;
5
+ const _defColors = {
17
6
  reset: ["fff", "000"],
18
7
  black: "000",
19
8
  red: "ff0000",
@@ -25,7 +14,7 @@ var _defColors = {
25
14
  lightgrey: "f0f0f0",
26
15
  darkgrey: "888"
27
16
  };
28
- var _styles = {
17
+ const _styles = {
29
18
  30: "black",
30
19
  31: "red",
31
20
  32: "green",
@@ -35,10 +24,10 @@ var _styles = {
35
24
  36: "cyan",
36
25
  37: "lightgrey"
37
26
  };
38
- var _colorMode = {
27
+ const _colorMode = {
39
28
  2: "rgb"
40
29
  };
41
- var _openTags = {
30
+ const _openTags = {
42
31
  1: "font-weight:bold",
43
32
  2: "opacity:0.5",
44
33
  3: "<i>",
@@ -47,43 +36,42 @@ var _openTags = {
47
36
  9: "<del>",
48
37
  38: (match) => {
49
38
  // color
50
- var mode = _colorMode[match[0]];
39
+ const mode = _colorMode[match[0]];
51
40
  if (mode === "rgb") {
52
- var r, g, b;
53
- r = match[1];
54
- g = match[2];
55
- b = match[3];
41
+ const r = match[1];
42
+ const g = match[2];
43
+ const b = match[3];
56
44
  match.advance(4);
57
- return "color: rgb(" + r + "," + g + "," + b + ")";
45
+ return `color: rgb(${r},${g},${b})`;
58
46
  }
59
47
  },
60
48
  48: (match) => {
61
49
  // background color
62
- var mode = _colorMode[match[0]];
50
+ const mode = _colorMode[match[0]];
63
51
  if (mode === "rgb") {
64
- var r, g, b;
65
- r = match[1];
66
- g = match[2];
67
- b = match[3];
52
+ const r = match[1];
53
+ const g = match[2];
54
+ const b = match[3];
68
55
  match.advance(4);
69
- return "background-color: rgb(" + r + "," + g + "," + b + ")";
56
+ return `background-color: rgb(${r},${g},${b})`;
70
57
  }
71
58
  }
72
59
  };
73
- var _openTagToCloseTag = {
60
+ const _openTagToCloseTag = {
74
61
  3: "23",
75
62
  4: "24",
76
63
  9: "29"
77
64
  };
78
- var _closeTags = {
65
+ const _closeTags = {
79
66
  0: ansiCodes => {
80
67
  if (!ansiCodes)
81
68
  return "</span>";
82
69
  if (!ansiCodes.length)
83
70
  return "";
84
- var code, ret = "";
71
+ let code;
72
+ let ret = "";
85
73
  while ((code = ansiCodes.pop())) {
86
- var closeTag = _openTagToCloseTag[code];
74
+ const closeTag = _openTagToCloseTag[code];
87
75
  if (closeTag) {
88
76
  ret += _closeTags[closeTag];
89
77
  continue;
@@ -119,42 +107,42 @@ function ansiHTML(text) {
119
107
  return text;
120
108
  }
121
109
  // Cache opened sequence.
122
- var ansiCodes = [];
110
+ const ansiCodes = [];
123
111
  // Replace with markup.
124
112
  //@ts-ignore TS1487 error
125
- var ret = text.replace(/\033\[(?:[0-9]{1,3})?(?:(?:;[0-9]{0,3})*)?m/g, m => {
126
- var match = m.match(/(;?\d+)/g)?.map(normalizeSeq);
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);
127
115
  Object.defineProperty(match, "advance", {
128
116
  value: function (count) {
129
117
  this.splice(0, count);
130
118
  }
131
119
  });
132
- var seq, rep = "";
120
+ let seq;
121
+ let rep = "";
133
122
  while ((seq = match[0])) {
134
123
  match.advance(1);
135
124
  rep += applySeq(seq);
136
125
  }
137
126
  return rep;
138
127
  function applySeq(seq) {
139
- var other = _openTags[seq];
128
+ let other = _openTags[seq];
140
129
  if (other &&
141
130
  (other = typeof other === "function" ? other(match) : other)) {
142
131
  // If reset signal is encountered, we have to reset everything.
143
- var ret = "";
132
+ let ret = "";
144
133
  if (seq === "0") {
145
134
  ret += _closeTags[seq](ansiCodes);
146
135
  }
147
136
  // If current sequence has been opened, close it.
148
- if (!!~ansiCodes.indexOf(seq)) {
149
- // eslint-disable-line no-extra-boolean-cast
137
+ if (ansiCodes.indexOf(seq) !== -1) {
150
138
  ansiCodes.pop();
151
139
  return "</span>";
152
140
  }
153
141
  // Open tag.
154
142
  ansiCodes.push(seq);
155
- return (ret + (other[0] === "<" ? other : '<span style="' + other + ';">'));
143
+ return ret + (other[0] === "<" ? other : `<span style="${other};">`);
156
144
  }
157
- var ct = _closeTags[seq];
145
+ const ct = _closeTags[seq];
158
146
  if (typeof ct === "function") {
159
147
  return ct(ansiCodes);
160
148
  }
@@ -167,7 +155,7 @@ function ansiHTML(text) {
167
155
  }
168
156
  });
169
157
  // Make sure tags are closed.
170
- var l = ansiCodes.length;
158
+ const l = ansiCodes.length;
171
159
  l > 0 && (ret += Array(l + 1).join("</span>"));
172
160
  return ret;
173
161
  }
@@ -180,9 +168,9 @@ ansiHTML.setColors = (colors) => {
180
168
  if (typeof colors !== "object") {
181
169
  throw new Error("`colors` parameter must be an Object.");
182
170
  }
183
- var _finalColors = {};
184
- for (var key in _defColors) {
185
- var hex = colors.hasOwnProperty(key) ? colors[key] : null;
171
+ const _finalColors = {};
172
+ for (const key in _defColors) {
173
+ let hex = colors.hasOwnProperty(key) ? colors[key] : null;
186
174
  if (!hex) {
187
175
  _finalColors[key] = _defColors[key];
188
176
  continue;
@@ -194,11 +182,9 @@ ansiHTML.setColors = (colors) => {
194
182
  if (!Array.isArray(hex) ||
195
183
  hex.length === 0 ||
196
184
  hex.some(h => typeof h !== "string")) {
197
- throw new Error("The value of `" +
198
- key +
199
- "` property must be an Array and each item could only be a hex string, e.g.: FF0000");
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`);
200
186
  }
201
- var defHexColor = _defColors[key];
187
+ const defHexColor = _defColors[key];
202
188
  if (!hex[0]) {
203
189
  hex[0] = defHexColor[0];
204
190
  }
@@ -209,7 +195,7 @@ ansiHTML.setColors = (colors) => {
209
195
  hex = hex.slice(0, 2);
210
196
  }
211
197
  else if (typeof hex !== "string") {
212
- throw new Error("The value of `" + key + "` property must be a hex string, e.g.: FF0000");
198
+ throw new Error(`The value of \`${key}\` property must be a hex string, e.g.: FF0000`);
213
199
  }
214
200
  _finalColors[key] = hex;
215
201
  }
@@ -241,21 +227,17 @@ else {
241
227
  function _setTags(colors) {
242
228
  // reset all
243
229
  _openTags["0"] =
244
- "font-weight:normal;opacity:1;color:#" +
245
- colors.reset[0] +
246
- ";background:#" +
247
- colors.reset[1];
230
+ `font-weight:normal;opacity:1;color:#${colors.reset[0]};background:#${colors.reset[1]}`;
248
231
  // inverse
249
- _openTags["7"] =
250
- "color:#" + colors.reset[1] + ";background:#" + colors.reset[0];
232
+ _openTags["7"] = `color:#${colors.reset[1]};background:#${colors.reset[0]}`;
251
233
  // dark grey
252
- _openTags["90"] = "color:#" + colors.darkgrey;
253
- for (var code in _styles) {
254
- var color = _styles[code];
255
- var oriColor = colors[color] || "000";
256
- _openTags[code] = "color:#" + oriColor;
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}`;
257
239
  const codeInt = Number.parseInt(code);
258
- _openTags[(codeInt + 10).toString()] = "background:#" + oriColor;
240
+ _openTags[(codeInt + 10).toString()] = `background:#${oriColor}`;
259
241
  }
260
242
  }
261
243
  ansiHTML.reset();
@@ -19,9 +19,9 @@ function createPublicPathGetter(compiler) {
19
19
  return (compilation) => compilation ? compilation.getPath(raw) : raw({ hash: "XXXX" }, undefined);
20
20
  }
21
21
  if (/\[(hash|fullhash)[:\]]/.test(raw)) {
22
- return (compilation) => compilation ? compilation.getPath(raw) : raw.replace(/\/$/, "") + "/";
22
+ return (compilation) => compilation ? compilation.getPath(raw) : `${raw.replace(/\/$/, "")}/`;
23
23
  }
24
- return () => raw.replace(/\/$/, "") + "/";
24
+ return () => `${raw.replace(/\/$/, "")}/`;
25
25
  }
26
26
  function getRspackMemoryAssets(compiler, rdm) {
27
27
  const getPublicPath = createPublicPathGetter(compiler);
package/dist/server.d.ts CHANGED
@@ -17,6 +17,7 @@ export declare class RspackDevServer extends WebpackDevServer {
17
17
  /** @ts-ignore */
18
18
  compiler: Compiler | MultiCompiler;
19
19
  webSocketServer: WebpackDevServer.WebSocketServerImplementation | undefined;
20
+ static version: string;
20
21
  constructor(options: DevServer, compiler: Compiler | MultiCompiler);
21
22
  private getClientTransport;
22
23
  initialize(): Promise<void>;
package/dist/server.js CHANGED
@@ -17,6 +17,8 @@ const node_path_1 = __importDefault(require("node:path"));
17
17
  const core_1 = require("@rspack/core");
18
18
  const webpack_dev_middleware_1 = __importDefault(require("webpack-dev-middleware"));
19
19
  const webpack_dev_server_1 = __importDefault(require("webpack-dev-server"));
20
+ // @ts-ignore 'package.json' is not under 'rootDir'
21
+ const package_json_1 = require("../package.json");
20
22
  const patch_1 = require("./patch");
21
23
  (0, patch_1.applyDevServerPatch)();
22
24
  class RspackDevServer extends webpack_dev_server_1.default {
@@ -310,4 +312,5 @@ class RspackDevServer extends webpack_dev_server_1.default {
310
312
  }
311
313
  }
312
314
  }
315
+ RspackDevServer.version = package_json_1.version;
313
316
  exports.RspackDevServer = RspackDevServer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack/dev-server",
3
- "version": "1.0.0-beta.1",
3
+ "version": "1.0.0-beta.3",
4
4
  "license": "MIT",
5
5
  "description": "Development server for rspack",
6
6
  "main": "./dist/index.js",
@@ -35,9 +35,9 @@
35
35
  "@types/express": "4.17.21",
36
36
  "@types/mime-types": "2.1.4",
37
37
  "@types/ws": "8.5.10",
38
- "@rspack/core": "1.0.0-beta.1",
39
- "@rspack/dev-server": "1.0.0-beta.1",
40
- "@rspack/plugin-react-refresh": "1.0.0-beta.1"
38
+ "@rspack/core": "1.0.0-beta.3",
39
+ "@rspack/dev-server": "1.0.0-beta.3",
40
+ "@rspack/plugin-react-refresh": "1.0.0-beta.3"
41
41
  },
42
42
  "dependencies": {
43
43
  "chokidar": "^3.6.0",