@rspack/dev-server 1.0.0-alpha.4 → 1.0.0-beta.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/dist/ansiHTML.d.ts +15 -14
- package/dist/ansiHTML.js +12 -16
- package/dist/middleware.js +18 -9
- package/dist/server.d.ts +2 -2
- package/dist/server.js +10 -10
- package/package.json +15 -13
package/dist/ansiHTML.d.ts
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
interface AnsiHtmlTags {
|
|
2
|
+
open: typeof _openTags;
|
|
3
|
+
close: typeof _closeTags;
|
|
4
|
+
}
|
|
5
|
+
type Option<T> = T | null | undefined;
|
|
6
|
+
type Match = {
|
|
7
|
+
advance: (n: number) => void;
|
|
8
|
+
} & 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)>;
|
|
2
11
|
/**
|
|
3
12
|
* Converts text with ANSI color codes to HTML markup.
|
|
4
|
-
* @param {String} text
|
|
5
|
-
* @returns {*}
|
|
6
13
|
*/
|
|
7
|
-
declare function ansiHTML(text: string):
|
|
14
|
+
declare function ansiHTML(text: string): string;
|
|
8
15
|
declare namespace ansiHTML {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
*/
|
|
13
|
-
function setColors(colors: Object): void;
|
|
14
|
-
/**
|
|
15
|
-
* Reset colors.
|
|
16
|
-
*/
|
|
17
|
-
function reset(): void;
|
|
18
|
-
const tags: Object;
|
|
16
|
+
var setColors: (colors: Record<string, string | string[]>) => void;
|
|
17
|
+
var reset: () => void;
|
|
18
|
+
var tags: AnsiHtmlTags;
|
|
19
19
|
}
|
|
20
|
+
export default ansiHTML;
|
package/dist/ansiHTML.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
// @ts-nocheck
|
|
3
1
|
/**
|
|
4
2
|
* The following code is modified based on
|
|
5
3
|
* https://github.com/mahdyar/ansi-html-community/blob/b86cc3f1fa1d118477877352f0eafe1a70fd20ab/index.js
|
|
@@ -12,7 +10,7 @@
|
|
|
12
10
|
* https://github.com/mahdyar/ansi-html-community/blob/master/LICENSE
|
|
13
11
|
*/
|
|
14
12
|
"use strict";
|
|
15
|
-
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
14
|
// Reference to https://github.com/sindresorhus/ansi-regex
|
|
17
15
|
var _regANSI = /(?:(?:\u001b\[)|\u009b)(?:(?:[0-9]{1,3})?(?:(?:;[0-9]{0,3})*)?[A-M|f-m])|\u001b[A-M]/;
|
|
18
16
|
var _defColors = {
|
|
@@ -47,7 +45,7 @@ var _openTags = {
|
|
|
47
45
|
4: "<u>",
|
|
48
46
|
8: "display:none",
|
|
49
47
|
9: "<del>",
|
|
50
|
-
38: match => {
|
|
48
|
+
38: (match) => {
|
|
51
49
|
// color
|
|
52
50
|
var mode = _colorMode[match[0]];
|
|
53
51
|
if (mode === "rgb") {
|
|
@@ -59,7 +57,7 @@ var _openTags = {
|
|
|
59
57
|
return "color: rgb(" + r + "," + g + "," + b + ")";
|
|
60
58
|
}
|
|
61
59
|
},
|
|
62
|
-
48: match => {
|
|
60
|
+
48: (match) => {
|
|
63
61
|
// background color
|
|
64
62
|
var mode = _colorMode[match[0]];
|
|
65
63
|
if (mode === "rgb") {
|
|
@@ -98,13 +96,11 @@ var _closeTags = {
|
|
|
98
96
|
24: "</u>",
|
|
99
97
|
29: "</del>" // reset delete
|
|
100
98
|
};
|
|
101
|
-
[21, 22, 27, 28, 39, 49]
|
|
99
|
+
for (const n of [21, 22, 27, 28, 39, 49]) {
|
|
102
100
|
_closeTags[n] = "</span>";
|
|
103
|
-
}
|
|
101
|
+
}
|
|
104
102
|
/**
|
|
105
103
|
* Normalize ';<seq>' | '<seq>' -> '<seq>'
|
|
106
|
-
* @param {string | null} seq
|
|
107
|
-
* @returns {null | string}
|
|
108
104
|
*/
|
|
109
105
|
function normalizeSeq(seq) {
|
|
110
106
|
if (seq === null || seq === undefined)
|
|
@@ -116,8 +112,6 @@ function normalizeSeq(seq) {
|
|
|
116
112
|
}
|
|
117
113
|
/**
|
|
118
114
|
* Converts text with ANSI color codes to HTML markup.
|
|
119
|
-
* @param {String} text
|
|
120
|
-
* @returns {*}
|
|
121
115
|
*/
|
|
122
116
|
function ansiHTML(text) {
|
|
123
117
|
// Returns the text if the string has no ANSI escape code.
|
|
@@ -127,8 +121,9 @@ function ansiHTML(text) {
|
|
|
127
121
|
// Cache opened sequence.
|
|
128
122
|
var ansiCodes = [];
|
|
129
123
|
// Replace with markup.
|
|
124
|
+
//@ts-ignore TS1487 error
|
|
130
125
|
var ret = text.replace(/\033\[(?:[0-9]{1,3})?(?:(?:;[0-9]{0,3})*)?m/g, m => {
|
|
131
|
-
var match = m.match(/(;?\d+)/g)
|
|
126
|
+
var match = m.match(/(;?\d+)/g)?.map(normalizeSeq);
|
|
132
127
|
Object.defineProperty(match, "advance", {
|
|
133
128
|
value: function (count) {
|
|
134
129
|
this.splice(0, count);
|
|
@@ -163,7 +158,7 @@ function ansiHTML(text) {
|
|
|
163
158
|
if (typeof ct === "function") {
|
|
164
159
|
return ct(ansiCodes);
|
|
165
160
|
}
|
|
166
|
-
|
|
161
|
+
if (ct) {
|
|
167
162
|
// Pop sequence
|
|
168
163
|
ansiCodes.pop();
|
|
169
164
|
return ct;
|
|
@@ -176,11 +171,12 @@ function ansiHTML(text) {
|
|
|
176
171
|
l > 0 && (ret += Array(l + 1).join("</span>"));
|
|
177
172
|
return ret;
|
|
178
173
|
}
|
|
174
|
+
exports.default = ansiHTML;
|
|
179
175
|
/**
|
|
180
176
|
* Customize colors.
|
|
181
177
|
* @param {Object} colors reference to _defColors
|
|
182
178
|
*/
|
|
183
|
-
ansiHTML.setColors = colors => {
|
|
179
|
+
ansiHTML.setColors = (colors) => {
|
|
184
180
|
if (typeof colors !== "object") {
|
|
185
181
|
throw new Error("`colors` parameter must be an Object.");
|
|
186
182
|
}
|
|
@@ -258,8 +254,8 @@ function _setTags(colors) {
|
|
|
258
254
|
var color = _styles[code];
|
|
259
255
|
var oriColor = colors[color] || "000";
|
|
260
256
|
_openTags[code] = "color:#" + oriColor;
|
|
261
|
-
|
|
262
|
-
_openTags[(
|
|
257
|
+
const codeInt = Number.parseInt(code);
|
|
258
|
+
_openTags[(codeInt + 10).toString()] = "background:#" + oriColor;
|
|
263
259
|
}
|
|
264
260
|
}
|
|
265
261
|
ansiHTML.reset();
|
package/dist/middleware.js
CHANGED
|
@@ -4,19 +4,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getRspackMemoryAssets = void 0;
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
7
|
+
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
8
|
+
const node_path_1 = require("node:path");
|
|
9
|
+
const node_url_1 = require("node:url");
|
|
10
10
|
const mime_types_1 = __importDefault(require("mime-types"));
|
|
11
11
|
function etag(buf) {
|
|
12
|
-
const hash =
|
|
12
|
+
const hash = node_crypto_1.default.createHash("sha256").update(buf).digest("hex");
|
|
13
13
|
const etag = hash;
|
|
14
14
|
return etag;
|
|
15
15
|
}
|
|
16
|
+
function createPublicPathGetter(compiler) {
|
|
17
|
+
const raw = compiler.options.output.publicPath || "/";
|
|
18
|
+
if (typeof raw === "function") {
|
|
19
|
+
return (compilation) => compilation ? compilation.getPath(raw) : raw({ hash: "XXXX" }, undefined);
|
|
20
|
+
}
|
|
21
|
+
if (/\[(hash|fullhash)[:\]]/.test(raw)) {
|
|
22
|
+
return (compilation) => compilation ? compilation.getPath(raw) : raw.replace(/\/$/, "") + "/";
|
|
23
|
+
}
|
|
24
|
+
return () => raw.replace(/\/$/, "") + "/";
|
|
25
|
+
}
|
|
16
26
|
function getRspackMemoryAssets(compiler, rdm) {
|
|
17
|
-
const
|
|
18
|
-
? compiler.options.output.publicPath.replace(/\/$/, "") + "/"
|
|
19
|
-
: "/";
|
|
27
|
+
const getPublicPath = createPublicPathGetter(compiler);
|
|
20
28
|
return (req, res, next) => {
|
|
21
29
|
const { method, url } = req;
|
|
22
30
|
if (method !== "GET") {
|
|
@@ -24,7 +32,8 @@ function getRspackMemoryAssets(compiler, rdm) {
|
|
|
24
32
|
}
|
|
25
33
|
// css hmr will append query string, so here need to remove query string
|
|
26
34
|
// @ts-expect-error
|
|
27
|
-
const path = (0,
|
|
35
|
+
const path = (0, node_url_1.parse)(url).pathname;
|
|
36
|
+
const publicPath = getPublicPath(compiler._lastCompilation);
|
|
28
37
|
// asset name is not start with /, so path need to slice 1
|
|
29
38
|
// @ts-expect-error
|
|
30
39
|
const filename = path.startsWith(publicPath)
|
|
@@ -50,7 +59,7 @@ function getRspackMemoryAssets(compiler, rdm) {
|
|
|
50
59
|
else {
|
|
51
60
|
contentType =
|
|
52
61
|
// @ts-expect-error
|
|
53
|
-
mime_types_1.default.contentType((0,
|
|
62
|
+
mime_types_1.default.contentType((0, node_path_1.extname)(path)) || "text/plain; charset=utf-8";
|
|
54
63
|
}
|
|
55
64
|
const calcEtag = etag(buffer);
|
|
56
65
|
const oldEtag = req.headers["if-none-match"];
|
package/dist/server.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
|
-
import type { Server } from "http";
|
|
4
|
-
import type { Socket } from "net";
|
|
3
|
+
import type { Server } from "node:http";
|
|
4
|
+
import type { Socket } from "node:net";
|
|
5
5
|
import { type Compiler, MultiCompiler } from "@rspack/core";
|
|
6
6
|
import type { FSWatcher } from "chokidar";
|
|
7
7
|
import WebpackDevServer from "webpack-dev-server";
|
package/dist/server.js
CHANGED
|
@@ -81,7 +81,7 @@ class RspackDevServer extends webpack_dev_server_1.default {
|
|
|
81
81
|
const compilers = this.compiler instanceof core_1.MultiCompiler
|
|
82
82
|
? this.compiler.compilers
|
|
83
83
|
: [this.compiler];
|
|
84
|
-
|
|
84
|
+
for (const compiler of compilers) {
|
|
85
85
|
const mode = compiler.options.mode || process.env.NODE_ENV;
|
|
86
86
|
if (this.options.hot) {
|
|
87
87
|
if (mode === "production") {
|
|
@@ -103,14 +103,14 @@ class RspackDevServer extends webpack_dev_server_1.default {
|
|
|
103
103
|
...compiler.options.resolve.alias
|
|
104
104
|
};
|
|
105
105
|
}
|
|
106
|
-
}
|
|
106
|
+
}
|
|
107
107
|
if (this.options.webSocketServer) {
|
|
108
|
-
|
|
108
|
+
for (const compiler of compilers) {
|
|
109
109
|
this.addAdditionalEntries(compiler);
|
|
110
110
|
new compiler.webpack.ProvidePlugin({
|
|
111
111
|
__webpack_dev_server_client__: this.getClientTransport()
|
|
112
112
|
}).apply(compiler);
|
|
113
|
-
}
|
|
113
|
+
}
|
|
114
114
|
}
|
|
115
115
|
// @ts-expect-error: `setupHooks` is private function in base class.
|
|
116
116
|
this.setupHooks();
|
|
@@ -131,7 +131,7 @@ class RspackDevServer extends webpack_dev_server_1.default {
|
|
|
131
131
|
if (this.options.setupExitSignals) {
|
|
132
132
|
const signals = ["SIGINT", "SIGTERM"];
|
|
133
133
|
let needForceShutdown = false;
|
|
134
|
-
|
|
134
|
+
for (const signal of signals) {
|
|
135
135
|
const listener = () => {
|
|
136
136
|
if (needForceShutdown) {
|
|
137
137
|
process.exit();
|
|
@@ -152,14 +152,14 @@ class RspackDevServer extends webpack_dev_server_1.default {
|
|
|
152
152
|
// @ts-expect-error: `listeners` is private function in base class.
|
|
153
153
|
this.listeners.push({ name: signal, listener });
|
|
154
154
|
process.on(signal, listener);
|
|
155
|
-
}
|
|
155
|
+
}
|
|
156
156
|
}
|
|
157
157
|
// Proxy WebSocket without the initial http request
|
|
158
158
|
// https://github.com/chimurai/http-proxy-middleware#external-websocket-upgrade
|
|
159
159
|
// @ts-expect-error: `webSocketProxies` is private function in base class.
|
|
160
|
-
this.webSocketProxies
|
|
160
|
+
for (const webSocketProxy of this.webSocketProxies) {
|
|
161
161
|
this.server.on("upgrade", webSocketProxy.upgrade);
|
|
162
|
-
}
|
|
162
|
+
}
|
|
163
163
|
}
|
|
164
164
|
setupDevMiddleware() {
|
|
165
165
|
// @ts-expect-error
|
|
@@ -167,7 +167,7 @@ class RspackDevServer extends webpack_dev_server_1.default {
|
|
|
167
167
|
}
|
|
168
168
|
setupMiddlewares() {
|
|
169
169
|
const middlewares = [];
|
|
170
|
-
|
|
170
|
+
for (const middleware of middlewares) {
|
|
171
171
|
if (typeof middleware === "function") {
|
|
172
172
|
// @ts-expect-error
|
|
173
173
|
this.app.use(middleware);
|
|
@@ -180,7 +180,7 @@ class RspackDevServer extends webpack_dev_server_1.default {
|
|
|
180
180
|
// @ts-expect-error
|
|
181
181
|
this.app.use(middleware.middleware);
|
|
182
182
|
}
|
|
183
|
-
}
|
|
183
|
+
}
|
|
184
184
|
// @ts-expect-error
|
|
185
185
|
super.setupMiddlewares();
|
|
186
186
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspack/dev-server",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-beta.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Development server for rspack",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -29,23 +29,25 @@
|
|
|
29
29
|
"directory": "packages/rspack-dev-server"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
+
"jest-serializer-path": "^0.1.15",
|
|
33
|
+
"typescript": "5.0.2",
|
|
32
34
|
"@types/connect-history-api-fallback": "1.5.4",
|
|
33
35
|
"@types/express": "4.17.21",
|
|
34
36
|
"@types/mime-types": "2.1.4",
|
|
35
37
|
"@types/ws": "8.5.10",
|
|
36
|
-
"@rspack/core": "1.0.0-
|
|
37
|
-
"@rspack/dev-server": "1.0.0-
|
|
38
|
-
"@rspack/plugin-react-refresh": "1.0.0-
|
|
38
|
+
"@rspack/core": "1.0.0-beta.0",
|
|
39
|
+
"@rspack/dev-server": "1.0.0-beta.0",
|
|
40
|
+
"@rspack/plugin-react-refresh": "1.0.0-beta.0"
|
|
39
41
|
},
|
|
40
42
|
"dependencies": {
|
|
41
|
-
"chokidar": "3.6.0",
|
|
42
|
-
"connect-history-api-fallback": "2.0.0",
|
|
43
|
-
"express": "4.19.2",
|
|
44
|
-
"http-proxy-middleware": "2.0.6",
|
|
45
|
-
"mime-types": "2.1.35",
|
|
46
|
-
"webpack-dev-middleware": "
|
|
47
|
-
"webpack-dev-server": "
|
|
48
|
-
"ws": "8.
|
|
43
|
+
"chokidar": "^3.6.0",
|
|
44
|
+
"connect-history-api-fallback": "^2.0.0",
|
|
45
|
+
"express": "^4.19.2",
|
|
46
|
+
"http-proxy-middleware": "^2.0.6",
|
|
47
|
+
"mime-types": "^2.1.35",
|
|
48
|
+
"webpack-dev-middleware": "^7.3.0",
|
|
49
|
+
"webpack-dev-server": "^5.0.4",
|
|
50
|
+
"ws": "^8.16.0"
|
|
49
51
|
},
|
|
50
52
|
"peerDependencies": {
|
|
51
53
|
"@rspack/core": "*"
|
|
@@ -53,7 +55,7 @@
|
|
|
53
55
|
"scripts": {
|
|
54
56
|
"build": "tsc -b ./tsconfig.build.json",
|
|
55
57
|
"dev": "tsc -w -b ./tsconfig.build.json",
|
|
56
|
-
"test": "rimraf .test-temp &&
|
|
58
|
+
"test": "rimraf .test-temp && cross-env NO_COLOR=1 node --expose-gc --max-old-space-size=8192 --experimental-vm-modules ../../node_modules/jest-cli/bin/jest --colors",
|
|
57
59
|
"api-extractor": "api-extractor run --verbose",
|
|
58
60
|
"api-extractor:ci": "api-extractor run --verbose || diff temp/api.md etc/api.md"
|
|
59
61
|
}
|