@rspack/dev-server 1.0.0-beta.0 → 1.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.
- package/dist/ansiHTML.d.ts +13 -2
- package/dist/ansiHTML.js +45 -63
- package/dist/middleware.js +2 -2
- package/package.json +4 -4
package/dist/ansiHTML.d.ts
CHANGED
|
@@ -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
|
|
10
|
-
declare
|
|
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
|
-
|
|
16
|
-
|
|
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
|
-
|
|
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
|
-
|
|
27
|
+
const _colorMode = {
|
|
39
28
|
2: "rgb"
|
|
40
29
|
};
|
|
41
|
-
|
|
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
|
-
|
|
39
|
+
const mode = _colorMode[match[0]];
|
|
51
40
|
if (mode === "rgb") {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
|
45
|
+
return `color: rgb(${r},${g},${b})`;
|
|
58
46
|
}
|
|
59
47
|
},
|
|
60
48
|
48: (match) => {
|
|
61
49
|
// background color
|
|
62
|
-
|
|
50
|
+
const mode = _colorMode[match[0]];
|
|
63
51
|
if (mode === "rgb") {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
|
56
|
+
return `background-color: rgb(${r},${g},${b})`;
|
|
70
57
|
}
|
|
71
58
|
}
|
|
72
59
|
};
|
|
73
|
-
|
|
60
|
+
const _openTagToCloseTag = {
|
|
74
61
|
3: "23",
|
|
75
62
|
4: "24",
|
|
76
63
|
9: "29"
|
|
77
64
|
};
|
|
78
|
-
|
|
65
|
+
const _closeTags = {
|
|
79
66
|
0: ansiCodes => {
|
|
80
67
|
if (!ansiCodes)
|
|
81
68
|
return "</span>";
|
|
82
69
|
if (!ansiCodes.length)
|
|
83
70
|
return "";
|
|
84
|
-
|
|
71
|
+
let code;
|
|
72
|
+
let ret = "";
|
|
85
73
|
while ((code = ansiCodes.pop())) {
|
|
86
|
-
|
|
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
|
-
|
|
110
|
+
const ansiCodes = [];
|
|
123
111
|
// Replace with markup.
|
|
124
112
|
//@ts-ignore TS1487 error
|
|
125
|
-
|
|
126
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 (
|
|
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
|
|
143
|
+
return ret + (other[0] === "<" ? other : `<span style="${other};">`);
|
|
156
144
|
}
|
|
157
|
-
|
|
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
|
-
|
|
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
|
-
|
|
184
|
-
for (
|
|
185
|
-
|
|
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(
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
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"] =
|
|
253
|
-
for (
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
_openTags[code] =
|
|
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()] =
|
|
240
|
+
_openTags[(codeInt + 10).toString()] = `background:#${oriColor}`;
|
|
259
241
|
}
|
|
260
242
|
}
|
|
261
243
|
ansiHTML.reset();
|
package/dist/middleware.js
CHANGED
|
@@ -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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspack/dev-server",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.2",
|
|
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/
|
|
39
|
-
"@rspack/
|
|
40
|
-
"@rspack/plugin-react-refresh": "1.0.0-beta.
|
|
38
|
+
"@rspack/dev-server": "1.0.0-beta.2",
|
|
39
|
+
"@rspack/core": "1.0.0-beta.2",
|
|
40
|
+
"@rspack/plugin-react-refresh": "1.0.0-beta.2"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"chokidar": "^3.6.0",
|